关于作者

用户名:merfesyt
笔名:merfesyt
地区: 北京-北京
行业:其他

日历  

快速登录

+ 用户名:
+ 密 码:

在线留言



访问统计:
文章个数:151
评论个数:16
留言条数:4




Powered by BlogDriver 2.1

氧气的小木屋

 

时间冲淡所有的一切 回忆的画面记录的语言 这里的点滴记录下年少的梦想和奋斗,曾经的轻狂与不羁 ---欢迎来到氧气的木屋,坦率的心灵交流,分享彼此的心情与感受

文章

在阿尔卑斯山留下足迹

811日,到德国的第九天,在德国同事的邀请下,怀着一份新奇和喜悦,我们一同前往位于奥地利的阿尔卑斯山游玩。驱车3个半小时的路程,我们来到了baudsee湖,湖的对岸就是奥地利。与同事沿着湖岸闲逛,用相机记录下美丽的湖光山水,大约两个小时后,淅淅沥沥下起了雨,冒着雨,我们还登上了位于湖岸的铁塔,为此淋了个湿透。趁着躲雨的间隙,游走在湖边小镇的商店和街市中,游客和当地的居民大都坐在街边,享受啤酒或咖啡,让我们充分感受到那份雨中特有的悠闲和舒适。下午2点左右,我们离开湖边,驱车赶往阿尔卑斯群山中。德国同事是位登山爱好者,二十余年来和他当年大学里的朋友们遵守着一份约定,即每年会选择一处高山去登攀。于是乎,自己也很荣幸地参与了此次活动。而目的地就是位于阿尔卑斯群山中的海拔2245米的Göppinger hütte, 途中需要翻越2400多米的山峰。对于平日里在国内也就是爬爬香山这类休闲娱乐为主的小山,却从未真正攀登过高山的我来说,着实是个挑战。八月的天气,山谷中却让人瑟瑟发抖,加上阵雨不停,路滑,给登山增添了几分困难。将车停在位于zug的山谷中,在同事带领下,我们用了大约1个小时翻越了一座小山脊,来到了Freiburger Hütte。这里是事先定好的集合地点,我们和几位非常有趣的德国朋友碰了头,大家一起闲聊,玩牌,畅谈到晚上10点多。这个木质结构的山间旅馆有着70多年的历史,陈设古朴精致,门前正对着秀美的Fromarinsee湖,湖水湛蓝清澈,让人留恋往返。在旅馆休息了一晚之后,我们补充了装备,一大早就向着群山进发。于是持续6个半小时的登山行程拉开序幕,沿着山脊,一路曲曲折折爬过很多山头,接近20多公里的行程。期间不乏危险的道路,由于道路狭窄,坡度较大,甚至需要借助固定在岩石边的缆绳来攀登,需要特别谨慎和小心,有些地段真的是用爬的。到了海拔大概1500米的时候,下起了雪,呵呵,想想此时还是8月份,上海大概还是38°左右的高温。!◎#¥,道路变得更加湿滑,行进的速度也受到一定影响,到了海拔2400多米的一座山顶时,积雪已完全覆盖了这里。终于,在下午三点多来到了Göppinger hütte,这个旅馆年代更久远,建造自1913年,现在貌似是由欧洲一个登山协会接管,作为非盈利性组织,为广大登山爱好者提供方便,好像每年只在稍微暖和的夏季营业4个月,之后撤离。爬了六个小时已是非常疲惫,来到温暖的旅馆,总算有种如释重负的感觉,那一夜睡的很香。周日我们沿另一条较为平缓的山路下山,有了前一天tough的铺垫,接下来三个半小时的行程就轻松了许多,沿途欣赏着奥地利的青山绿水......下午2点我们来到山谷,驱车离开zug,还经过了欧洲著名的旅游山庄lech,据说那里大多是一些欧洲贵族和俄罗斯石油大亨们每年去烧钱的地方,hoho...

        结束了为期三天的游玩,自己也已身心疲惫,膝盖至今隐隐作痛。但是的确是段美好的记忆,除了领略到秀美的湖光山水和独特的欧洲风情外,步行总行程接近20多公里,这也应该算是自己真正意义上的一次爬山,一共拍了300多张照片,整理了几张帖上来,立此存照。Bye 阿尔卑斯,我会回来的:)后会有期!

- 作者: merfesyt 2006年08月16日, 星期三 20:34  回复(0) |  引用(1) 加入博采

Linux Framebuffer Driver writing HOWTO(ZZ)

今天找到的一篇有关framebuffer驱动的文章,转载一下,虽然某些内容有些过时,但是思想还是值得借鉴的。

James Simmons, jsimmons@edgeglobal.com
v1.00, 9 October 1999

This document describes how to support a framebuffer video card for Linux.
It lists the supported video hardware, describes how to program the kernel
drivers, and answers frequently asked questions. The goal is to bring
current framebuffer driver writers as well as new ones up to speed on the
new developments accuring in the graphics system for linux.

______________________________________________________________________

Table of Contents

1. Introduction

1.1 Acknowledgments
1.2 Revision History
1.3 New versions of this document
1.4 Feedback
1.5 Distribution Policy

2. Framebuffer Video Card Technology

2.1 Monitor
2.2 Video Card

3. Setting a video mode

3.1 Fixed Frequency Monitors
3.2 Multi Frequency Monitors
3.3 Receipe for multisync monitors
3.4 Receipe for Monosync
3.5 Clocks
3.5.1 DCLK
3.5.2 MCLK
3.5.3 PLL
3.6 CRTC registers   
3.7 Colors

4. Framebuffer internal API

4.1 Data Structures
4.2 Driver layout

5. Answers To Frequently Asked Questions

5.1 Does fbdev support accels?

6. References

______________________________________________________________________

1. Introduction

This is the Linux Framebuffer driver HOWTO. It is intended as a quick
reference covering everything you need to know to write a framebuffer
video driver under Linux. Frequently asked questions about video mode
setting under Linux are answered, and references are given to some other
sources of information on a variety of topics related to computer
graphics. Also read this document not once, not twice but three times if
you are not familiar with video hardware.

The scope is limited to the aspects of writing a mode setting video card
framebuffer driver pertaining to Linux. See the other documents listed in
the References section for more general information on how to setup
framebuffer cards and setting up the XFB_Dev X server.

1.1. Acknowledgments

Much of this information came from the new framebuffer internal API being
developed by me for the upcoming next series of kernels. Originally this
was based on a patch by Fabrice Bellard. I learned of this patch and
was impressed by it. Later I took over development and improved it even
more. Much thanks goes to Fabrice for getting the ball rolling. This API is
a natural extension of the original API developed by Martin Schaller and
now maintained by Geert Uytterhoeven (geert@linux-m68k.org). Thanks
to you and the many others who developed the Linux framebuffer system,
drivers and utilities. A great amount of thanks goes to Andreas Beck of
the GGI project for helping me write this document and teaching me about
mode setting. Thanks also goes out to those who have supported my work.

Thanks to the SGML Tools package, this HOWTO is available in several
formats, all generated from a common source file.

1.2. Revision History

Version 1.0
first version; posted to fbdev mailing list only

1.3. New versions of this document

New versions of this document will be periodically posted to the
comp.os.linux.answers newsgroup. They will also be uploaded to various
anonymous ftp sites that archive such information including
<ftp://metalabs.unc.edu/pub/Linux/docs/HOWTO/>.

Hypertext versions of this and other Linux HOWTOs are available on
many World-Wide-Web sites, including <http://metalab.unc.edu/LDP/>.
Most Linux CD-ROM distributions include the HOWTOs, often under the
/usr/doc directory, and you can also buy printed copies from several
vendors. Sometimes the HOWTOs available from CD-ROM vendors, ftp
sites, and printed format are out of date. If the date on this HOWTO
is more than six months in the past, then a newer copy is probably
available on the Internet.

Most translations of this and other Linux HOWTOs can also be found at
<http://sunsite.unc.edu/pub/Linux/docs/HOWTO/translations/> and
<ftp://sunsite.unc.edu/pub/Linux/docs/HOWTO/translations/>.

If you make a translation of this document into another language, let
me know and I'll include a reference to it here. As of yet there are no
translations.

1.4. Feedback

I rely on you, the reader, to make this HOWTO useful. If you have any
suggestions, corrections, or comments, please send them to me,
jsimmons@edgeglobal.com, and I will try to incorporate them in the next
revision.

I am also willing to answer general questions on video cards and fbcon
under Linux, as best I can. Before doing so, please read all of the
information in this HOWTO, and send me detailed information about the
problem. Please do not ask me about using framebuffer cards under
operating systems other than Linux.

If you publish this document on a CD-ROM or in hardcopy form, a
complimentary copy would be appreciated. Mail me for my postal
address. Also consider making a donation to the Linux Documentation
Project to help support free documentation for Linux. Contact the
Linux HOWTO coordinator, Tim Bynum <mailto:linux-howto@sunsite.unc.edu>,
for more information.

1.5. Distribution Policy

Copyright (c) 1999 by James Simmons. This document may be
distributed under the terms set forth in the LDP license at
<http://sunsite.unc.edu/LDP/COPYRIGHT.html>.

2. Framebuffer Card Technology

This section gives a very cursory overview of graphics cards that have
accessible framebuffer technology, in order to help you understand the
concepts used later in the document. If you are considering writing a
driver for a video card please contact the manufacturer for documentation
on the card. Also please consider reading some books on video hardware in
order to learn more.

The way framebuffer devices behave under linux is something very similar
to /dev/mem. /dev/fb is in fact viewed as a memory device except in this case
the memory is video ram. Fbdev mmaps this memory to userspace for direct
access. This model is of course simplified for purpose of making programing
the frame buffer much easier as well as making it device and platform
independent. Since we are interested in building a driver we need to
userstand how exactly the video card itself works.

2.1 Monitor

First lets discribe one of the biggest but often overlooked components,
the monitor. Today there are many types of monitors. Flat screen to LED
and so on. For all the many types the basic principle behind the monitor is
the same. Basically a monitor builds an image sequentially from the data it
gets on its input lines. To achieve this a beam scans over the screen in a
kind of "zig-zag" pattern that covers the whole visible part of the screen
once per frame. It happens so fast the eye can't see this happening. Well we
hope. So which way does this beam go? All monitors have chosen to always
go left to right with a quick jump back to the far left when we hit the
right boundary of the monitor. Same for the top to bottom approach but at a
much slower pace since most of our time is used to move left to right for
every single line. Obviously, the displayed data needs to be synchronized
with the current position of the beam to be able to build a steady picture.
This is what those HSYNC and VSYNC you see in your monitor manual are for.
These two lines that say "hey move the beam to the left now" and "move the
ray to the top now". Now some systems encode this information for example in
the green channel, which is called sync on green, but that doesn't change
the principle. All a monitor knows about a mode is what it gets that's
contained in the frequencies with which those signals return. These
frequencies are called the horizontal and vertical frequency (aka refresh
rate), as it determines how often per second a whole image is drawn. So a
monitor knows nothing about depth, clocks, borders. If two modes have the
same frequencies they will be the same to the monitor. This is why different
centering data for e.g. 640x480x16 and 640x480x32 are not stored in the
monitor. The monitor can't distinguish between those modes. Between two
HSYNC we get the RGB signals.

HSYNC __/~~~\______________________________________________/~~~\___
RGB ___________datadatadatadatadatadatadatadatadatad_____________
time 1 2 3 4 5

At 1, the HSYNC pulse gets raised. The beam will now quickly move to the
left. During that time, the rgb lines should be black (ray off), as
otherwise it would leave a noticeable trace while moving, which would look
ugly.

At 2, the HSYNC pulse ends. This point isn't of much interest, as you cannot
tell if the ray is already at the left edge. The only thing important
about point 2 is, that the time between point 1 and 2 must be sufficiently
high for the monitor to detect the HSYNC signal. Usually the HSYNC pulse can
be made very small.

At some point after 1, the ray will start flying to the right again. When
point 3 comes, it will actually start to display data. Point 3 can thus be
adjusted to change the left border location. If you wait longer until you
start sending data, the left border will move to the right.

When you have sent all data you reach point 4. As a HSYNC pulse should then
be sent, to start a new line, we set the RGB lines to black again.
At point 5 we have completed a cycle and start the next line.

2.2 Video card

Next we look at the video card point of view. The video card could send out
a steady stream of data to the monitor except for one thing. The monitor
needs time for retracing so the video card will be put into some "delay"
at specific times. To be precise between point 4 and point on the NEXT line)
on the previous diagram. For the video card the "natural" coordinate system
starts at point 3, when it starts emitting data. This point usually causes
some confusion with modeline-calculation:

HSYNC __/~~~\______________________________________________/~~~\___
RGB ___________datadatadatadatadatadatadatadatadatad_____________
time 1 2 3 4 5 6
grc SS SE 0 W SS SE

From the graphics card point of view (grc) a line starts at "0". From that
point onward, it will output the data in its video ram. There is a counter
that will limit the number of pixels that are put on one line. This is what
we call the width of the mode. On a 640x480 standard VESA mode, this is 640
pixels.

Now we will usually want a small right border to allow the monitor to
prepare for the following SYNC pulse we will generate. The aforementioned
counter will run on (but data output from video RAM will be suppressed)
until we reach the point SS (SyncStart). On a 640x480 standard VGA mode,
this happens at 664 pixels. That is, we left a border of 24 pixels.

Now we raise the HSYNC to tell the monitor to go left. This signal remains
asserted until we reach the point SE (SyncEnd). (760 pixels on VGA -
i.e. 96 pixels of sync pulse. This is pretty long, but VGA monitors weren't
very quick.)

We will also want some left border, so we wait until we reach the next "0"
point before starting to generate a signal again. On standard VGA this
happens at 800 pixels (40 pixels left border). At that point, we reset the
counter to 0 and start over. This point is usually called the "total"
for this reason.

Now let us look at how we can change the picture's appearance by changing
values in such a modeline.

Moving SE should not cause any difference at all, except if you make the
sync pulse too small for the monitor to recognize.

Moving SS and SE together will move the location of the sync pulse within
the picture. Let us assume we move them both to the "left", i.e. we
decrease their startpoints. What happens is, that we decrease the distance
W-SS (which determines the right border) and increase 0-SE (the left
border). As a result, the picture moves to the right.

Now what happens, if you change W ? You get extra pixels at the right
border. As usually borders are pretty large for standard VGA modes,
you can usually display something like 648x486 without a problem on a
standard VGA monitor. You will not be able to see the difference.

Of course there are limits to this: If you go too far, you will produce
pixels beyond the visiable area of the monitor which is useless, or
interfere with the retrace; that gives ugly stripes from the retracing
CRT ray.

Now let's shed some light on a few remaining terms:

Blankstart BS and blankend BE. Between SE and 0, you can put a BE point on
many graphics cards. At that point, the RGB lines are no longer clamped to
black (to avoid interfering with the retrace), but can be programmed to a
border color. The same goes for BS, which can be placed between W and SS.
Usually one doesn't use that feature nowadays, as we have tuneable monitors
that allow to stretch the mode to the physical limits of the monitor.

On old monitors, one used large borders to ensure the data was always
visible. There the border color made some sense as kind of eye candy.

Pixelclock. That is the rate at which pixels are output to the RGB lines.
It is usually the basic unit for all timing values in a graphics card.

3. Actually calculating a mode

If you look at the fbdev driver you think yikes. Yes it's complex but not as
much as you think. A side note about standard modes. It's a common
misconception that graphics cards cannot do anything but the VGA/VESA
induced "standard" modes like 640x480, 800x600, 1024x768, 1280x960, ...
With most cards, about any resolution can be programmed, though many
accelerators have been optimized for the abovementioned modes, so that it
is usually NOT wise to use other widths, as one might need to turn OFF
accelerator support. So if you write a driver, don't cling to these modes.
If the card can handle it, allow any mode.

Here the type of monitor has a big impact on what kind of modes we can have.
There are two basic types of monitors, fixed frequency (they usually can do
multiple vertical frequencies, though, which are much less critical, as they
are much lower) and multifrequency.

3.1 Fixed frequency monitors

The monitor manual says the horizontal frequency (hfreq) is 31.5 kHz.

And we want to display a given mode, say 640x480.

We can now already determine the absolute minimum dotclock we need, as

dotclock = horiz_total * hfreq

and

horiz_total = width + right_border + sync + left_border > width

The minimum dotclock computes to 20.16 MHz. We will probably need
something around 20% "slack" for borders and sync, so let's say we need
about a 24MHz clock. Now we look at the next higher clock our card can
handle, which is 25.175 MHz, as we assume we have a VGA compatible card.

Now we can compute the horizontal total:

horiz_total = dotclock / hfreq = 799.2

We can only program this as multiples of 8, so we round to 800.
Now we still need to determine the length and placement of the sync pulse,
which will give all remaining parameters.

There is no clean mathematical requirement for those. Technically, the sync
must be long enough to be detected, and placed in a way that the mode is
centered. The centering issue is not very pressing anymore, as digitally
controlled monitors are common, which allow to control that externally.
Generally you should place the sync pulse early (i.e. keep right_border
small), as this will usually not cause artifacts that would arise from
turning on the output again too early, when the sync pulse is placed too
late.

So if we as a "rule-of-thumb" use a half of the blanking period for the sync
and divide the rest as 1/3 right-border, 2/3 left border, we get a modeline
of

"640x480" 25.175 640 664 744 800 ??? ??? ??? ???

While this is not perfectly the same as a standard VGA timing, it should run
as well on VGA monitors. The sync is a bit shorter, but that shouldn't be a
real problem.

Now for the vertical timing. At 480 lines, a VGA monitor uses 60Hz.

hfreq = vfreq * vert_total

which yields vert_total=525. The vertical timings usually use much less
overhead than the horizontal ones, as here we count whole _lines_, which
means much longer delays than just pixels. 10% overhead suffice here, and
we again split the borders 1/3 : 2/3, with only a few lines (say 2) for
the sync pulse, as this is already much longer than a HSYNC and thus easily
detectable.

"640x480" 25.175 640 664 744 800 480 495 497 525

let us compare that to an XF86 Modeline that claims to be standard VGA:

Modeline "640x480" 25.175 640 664 760 800 480 491 493 525

Not much difference - right ? They should both work well, just a little
shifted against each other vertically.

3.2 multiscan monitor

Here we will consider a theorical monitor that can do hfreq 31-95kHz and
vfreq 50-130Hz. Now let's look at a 640x480 mode. Our heuristics say,
that we will need about 768x528 (20% and 10% more) for borders and sync.
We as well want maximum refresh rate, so let's look what limits the mode:

hfreq = vfreq * vtotal = 130 * 528 = 68.6 kHz

Oh - we cannot use the full hfreq of our monitor ... well no problem. What
counts is the vfreq, as it determines how much flicker we see.

O.K. - what pixelclock will we need ?

pixclock = hfreq * htotal.

The calculation yields 52.7MHz.

Now we look what the card can do. Say we have a fixed set of clocks. We look
what clocks we have close by. Assume the card can do 50 and 60 MHz.

Now we have the choice: We can either use a lower clock, thus scaling down
the refresh rate a bit (by 5% ... so what ...): This is what one usually
does.

Or we can use a higher clock, but this would exceed the monitor
specifications. That can be countered by adding more border, but this is
usually not done, as it is a waste of space on the screen
However keep it in mind as a trick for displaying 320x200, when you do not
have doubling features. It will display in a tiny window in the middle of
the screen, but it will display.

O.K. - what will our calculation yield ?

"640x480" 50 640 664 728 768 480 496 498 528 # 65kHz 123Hz

I just mentioned doubling features. This is how VGA does 320x200. It
displays each pixel twice in both directions. Thus it effectively is a
640x400 mode. If this would not be done, you would need a pixelclock of
12.59MHz and you would still have the problem of needing a 140Hz refresh, if
hsync should stay at 31.5kHz.

A horizontal doubling feature allows to use the 25.175MHz clock intended
for 640, and a line doubling feature keeps the vsync the same as 400 lines.
Actually the line-doubler is programmable, so you can as well use modes as
sick as 640x50.

O.K. - another example. Same monitor, 1280x1024.

Now we need about 1536x1126 total (same rule of thumb).
That yields 130Hz*1126lines = 146 kHz. We would exceed the hfreq with that,
so now the hfreq is the limit and we can only reach a refresh rate of about
(95kHz/1126) 84 Hz anymore.

The required clock is now 146MHz. That would yield:

"1280x1024" 146 1280 1320 1448 1536 1024 1058 1060 1126 # 95kHz 84Hz

Now the clock might be programmable, but keep in mind, that there may be
limits to the clock. DO NOT OVERCLOCK a graphics card. This will result in
the RAMDAC producing blurry images (as it cannot cope with the high speed),
and more importantly, the RAMDAC will OVERHEAT and might be destroyed.

Another issue is memory bandwidth. The video memory can only give a certain
amount of data per time unit. This often limits the maximum clock at modes
with high color depth (i.e. much data per pixel). In the case of my card it
limits the clock to 130MHz at 16 bit depth, what would produce:

"1280x1024" 130 1280 1320 1448 1536 1024 1058 1060 1126 # 85kHz 75Hz

which is pretty much, what my monitor shows now, if I ask it.

3.3 Recipe for multisync monitors

a) Determine the totals by calculating htotal = width*1.2 and
vtotal = height*1.1 .
b) Check what limits the refresh by calculating vfreq2 = hfreqmax/vtotal.
If that exceeds vfreqmax, the limit is on the vfreq side, and we use
vfre = vfreqmax and hfreq = vfreqmax*vtotal. If it doesn't, the mode is
limited by hfreq and we have to use vfreq = vfreq2.
Note, that if this is smaller than vfreqmin, the mode cannot be displayed.
In the vfreq-limited case, you might exceed hfreqmin, which can be
countered by using linedoubling facilities, if available. You can also
add extra blank lines (increase vtotal) as a last-resort alternative.
c) Now that you have hfreq and vfreq, calculate the pixel clock using
pixclock=hfreq*htotal. Use the next lower pixel clock. If you are below
the lowest clock, you might want to try horizontal doubling features or
you will have to pad the mode by increasing htotal.
d) Again check the monitor limits. You might be violating lower bounds now
... In that case you might need to resort to choosing a higher clock
and padding as well.
e) You now have pixclock, width, height, htotal and vtotal. Calculate the
sync start positions: hss=width+(htotal-width)/2/3 ;
vss=height+(vtotal-height)/3; Make sure to properly align them as
required by the video card hardware hss usually has to be a multiple of
8.
f) SyncEnd is calculated similarly: hse=hss+(htotal-width)/2 and vse=vss+2.

3.4 Receipe for Monosync:
a) Calculate the number of lines. As hfreq and vfreq are given, vtotal is
fixed: vtotal=hfreq/vfreq. If there are multiple vfreqs allowed, choose
them according to your desired vtotal (i.e. one that gives the lowest
vtotal above what you really need).
b) Calculate the pixelclock. pixclock=hfreq*htotal. htotal starts at the
same estimate (width*1.2) we used above.
c) Adjust the pixelclock to hardware-limits. Adjust _UP_. Now recalculate
the htotal=pixclock/hfreq.
d) Go to 3.3. e)

A important final word. Most video card documentations gives you the exact
equations needed to set a mode. Here we give approached values. Use the
exact values given in the documents.

3.5 Clocks

Clocks on a video card ensure that different parts of the video hardware
happen at the correct time and in the correct order. For those not familiar
with computer clocks they work by generating a pulse at regular intervals
like what is shown below. You will something similar in your video
documentation.
___ ___ -  
| | | | V The period (T) represents the time between two
___| |___| |___ _ "ticks" of thee clock, and the frequency of the
clock is how many clock ticks happen per second.
| T |

The height of the pulse (V) is the difference in the voltage. This means
for T/2 units of time the voltage is at V1 then for the next T/2 it goes
to another voltage. Normally you don't have to worry about the amplitude
(height) of the pulse except for some cards that allow you to set the
height for powersaving mode. Normally you just want to change the frequency.
The hardware uses a clock for every part of the hardware except the bus
clock which is apart of the motherboard. No need to worry about that one.
Their exist many types of clocks. For video cards you can come across two
types of clocks. The first type you might come across are fixed clock
generators which are used in older video cards. The second type of clock
used in modern vidoe cards are called PLL (Phase Lock Loop).

In the documentation you might see terms about edge triggered devices. The
different types of edge triggers can be:

3.5.1 PLL
  
A PLL is composed of a multipler and a divider. They multiple a reference
frequency by a integer mulitplier, and then divide it by a integer divider.
Of course a PLL has a low


3.5.2 DCLK

3.5.3 MCLK



3.6 CRTC registers   

3.7 Colors

There is an endless number of colors but colors have a special property.
If you take two colors and mix them together you get a different color.
There are many models to represent colors but fbdev is based on what is
known as the RGB color model. Out of all the colors there are three colors
in this model which when mixed in different amounts can produce any color.
These colors are known as primary colors. There is a physical limit
to mixing colors. If you mix red, green, and blue in equal amounts
you get gray. Now if you make each color component equally brighter the final
color will become white. Now there is a point where making each component
brighter and brighter you will still end up with white. You can increase the
intensity of a color component by any amount from some inital value up to
this physical limit. This is where the image depth comes in. As you know on
most cards you can have an image depth from one bit to 32 bits. Image depth
is independent of the mapping from the pixel to the color components. It
also is independent of the memory layout to pixel mapping. Note some cards
have a complex mapping from the pixel values to the color components (red,
blue, green) as well as video memory to pixel mapping. If this is the case
you will have to consult your documentation on your video card to see what
the mapping exactly is. Here are the mappings defined from top to bottom in
fbdev starting with the value of the color components.

{red,blue,green}
|
FB_VISUAL_MONO01
FB_VISUAL_MONO10
FB_VISUAL_TRUECOLOR
FB_VISUAL_PSEUDOCOLOR
FB_VISUAL_DIRECTCOLOR
FB_VISUAL_STATIC_PSEUDOCOLOR
|
pixel value
FB_TYPE_PACKED_PIXELS
FB_TYPE_PLANES
FB_TYPE_INTERLEAVED_PLANES
FB_TYPE_TEXT
FB_TYPE_VGA_PLANES
|
value in video memory

The way fbdev tells what this video memory to pixel mapping is, is with
the type field in fb_fix_screeninfo. Here I'm going to describe the
FB_TYPE_PACKED_PIXELS layout since it is the most common. Here there is
a direct mapping from video memory to pixel value. If you place a 5 in video
memory then the pixel value at that position will be 5. This is important
when you have memory mapped the video memory to userland. Next we consider
the mapping from a pixel value to the colors. This is represented in the
fbdev API by the visual field in fb_fix_screeninfo. As you can see from the
above diagram this mapping is independent from the mapping from video memory
to pixel value. This means a FB_TYPE_PLANES could have FB_VISUAL_MONO01 just
like FB_TYPE_PACKED_PIXELS can. To understand visuals we have to go back to
the first types of video hardware. In the begining there was just monochrome
monitors. Here we could only display 2 colors. The foreground and background
color. Traditionally these colors are black and white but if you are old
enough you would remember the old green monitors. In fbdev API we define two
types of monochrome modes. The difference between the two is that the
foreground and background colors are swapped. Then computers began to
support color. The only problem was they could only display a small number of
colors at one time. What if you wanted to have an application display a
certain set of colors. Well the way that was developed to get around this
was the idea of a color map. A color map translated a pixel value to the
colors needed. If your application needs a specific set of colors it would
switch the color maps and you would get the needed colors. Of course this
also switches the other colors in the applications. That was the trade off.
This became what was known as pseudocolor mode. In fbdev API there are two
types of pseudocolor mappings. A static one and a dynamic one.
FB_VISUAL_STATIC_PSEUDOCOLOR defines a video card that has a non programmable
color map. What colors you get are what you are stuck with. The other type
of color map can be changed. Video cards in time started to support more
colors but this required having a larger color map. Also video memory prices
started to drop and video cards begain to sell with more of it. To properly
support 256 color intensity levels for each color component you would need a
color map of 16 million colors. So new mappings were developed in which
specific fields of a pixel were directly proportional to the intensity of a
color component. Two types of mappings were developed. One was truecolor
and the other directcolor. In truecolor you cannot change the mappings from
the pixel value to color intensities. Setting a value of 64 to the red
component of the pixel will result in a red intensity of 64. How bright of a
red this is depends on the image depth. For directcolor you can control this.
You could make a pixel value in the red field of 64 equal 128 for the
intensity. Also some cards support an alpha value which is used in higher
graphics which for fbdev is of little importance than it should always be
set to the highest value it can have. For most cards alpha shows up for 15
bit modes where each color compenent can have up to 32 intensity levels (2^5)
and one bit represents the alpha component. It also shows up for 32 bit
modes where each component red, blue, green, and alpha are given 256
intensity levels (2^8). 24 bit mode is like 32 bit mode except it lacks the
alpha component. A important note is that some cards only support 24 bit
mode on certain architectures.

4. Framebuffer internal API

Now that we understand the basic ideas behind video card technology and mode
setting we can now look at how the framebuffer devices abstract them. Also
we will see that fbdev actually handles most of the mode setting issues for
you to make life much easier. In the older API the console code was heavily
linked to the framebuffer devices. The newer API has now moved nearly all
console handling code into fbcon itself. Now fbcon is a true wrapper around
the video card's abilities. This allowed for massive code reduction and
easier driver developement. A good example of a framebuffer driver is vfb.
The vfb driver is not a true framebuffer driver. All it does is map a chunk
of memory to userspace. It's used for demonstration purposes and testing.

4.1 Data Structures

The framebuffer drivers depend heavily on four data structures. These
structures are declared in fb.h. They are fb_var_screeninfo,
fb_fix_screeninfo, fb_monospecs, and fb_info. The first three can be made
available to and from userland. First let me describe what each means and
how they are used. Fb_var_screeninfo is used to describe the features of
a video card you normally can set. It's with fb_var_screeninfo you can define
such things as depth and the resolution you want. The next structure is
fb_fix_screeninfo. This defines the properties of a card that are created
when you set a mode and can't be changed otherwise. A good example is the
start of the framebuffer memory. This can depend on what mode is set. Now
while using that mode you don't want to have the memory position change on
you. In this case the video hardware tells you the memory location and you
have no say about it. The third structure is fb_monospecs. In the old API
the importance of fb_monospecs was very little. This allowed for forbidden
things such as setting a mode of 800x600 on a fixed-frequency monitor. With
the new API fb_monospecs prevents such things and if used correctly can
prevent a monitor from being cooked. The final data structure is fb_info.
This defines the current state of the video card. Fb_info is only visible
from the kernel. Inside of fb_info there is a fb_ops which is a collection
of needed functions to make fbdev and fbcon work.

4.2 Driver layout

Here I discribe a clean way to code your drivers. A good example of the
basic layout is in vfb.c. In the example driver we first present our data
structures in the begining of the file. Note there is no fb_monospecs since
this is handled by code in fbmon.c. This can be done since monitors are
independent in behavior from video cards. First we define our three basic
data structures. For all the data structures I defined them static and
declare the default values. The reason I do this is that it's less memory
intensive than allocating a piece of memory and filling in the default
values. Note for drivers that support multihead on the same card
the fb_info should be dynamically allocated for each card present. For
fb_var_screeninfo and fb_fix_screeninfo they still are declared static
since all the cards can be set to the same mode.

4.3 Initialization and boot time parameter handling

There are two functions that handle the video card at boot time.

int xxfb_init(void);
int xxfb_setup(char*);

In the example driver as with most drivers these functions are placed at
the end of the driver. Both are very card specific. In order to link
your driver directly into the kernel both of these functions you must add
the above definition with extern in front to fbmem.c. Then add these
functions to the following in fbmem.c

static struct {
const char *name;
int (*init)(void);
int (*setup)(char*);
} fb_drivers[] __initdata = {
#ifdef CONFIG_FB_YOURCARD
{ "driver_name", xxxfb_init, xxxfb_setup },
#endif
...

Setup is used to pass card specific options from the boot prompt of your
favorite boot loader. A good example is boot:video=matrox:vesa:443. The
basic setup function is

int __init xxxfb_setup(char *options)
{
char *this_opt;

if (!options || !*options)
return 0;

for (this_opt = strtok(options, ","); this_opt;
this_opt = strtok(NULL, ","))
if (!strcmp(this_opt, "my_option")) {
/* Do your stuff. Usually set some static flags that
the driver later uses */
} else if (!strncmp(this_opt, "Other_option:", 5))
strcpy(some_flag_driver_uese, this_opt+5);
} else ....
}

The xxxfb_init function sets the inital state of the video card. This
function has to consider bus and platform handling since today most cards
can exist on many platforms. For bus types we have to deal with there are
PCI, ISA, zorro. Also some platforms offer firmware that returns information
about the video card. In these cases we often don't need to deal with the
bus unless we need more control over the card. Let's look at Open Firmware
that's available on PowerPCs. If you are going to use Open Firmware to
initalize your card you need to add the following to offb.c.

#ifdef CONFIG_FB_YOUR_CARD
extern void xxxfb_of_init(struct device_node *dp);
#endif /* CONFIG_FB_YOUR_CARD */

Then in the function offb_init_driver you add something similar to the
following.

#ifdef CONFIG_FB_YOUR_CARD
if (!strncmp(dp->name,"Open Firmware number of your card ",size_of_name)) {
xxxfb_of_init(dp);
return 1;
}
#endif /* CONFIG_FB_YOUR_CARD */

If Open Firmware doesn't detect your card then Open Firmware sets up a
generic video mode for you. Now in your driver you really need two
initalization functions.

The next major part of the driver is declaring the functions of fb_ops
declared in fb_info for the driver.

The first two functions xxfb_open and xxfb_release can be called from both
fbcon and fbdev. In fact that's the use of the user flag. If user equals zero
then fbcon wants to access this device else it's an explicit open of the
framebuffer device. This way you can handle the framebuffer device for the
console in a special way for a particular video card. For most drivers this
function just does a MOD_INC_USE_COUNT or MOD_DEC_USE_COUNT.


These are the functions at the heart of mode setting. There are a
few cards that don't support mode changing. For these we have this function
return a -EINVAL to let the user know he/she can't set the mode. Actually
set_var does more than just set modes. It can check them as well. In
fb_var_screeninfo there is a flag called activate. This flag can take on
the the following values. FB_ACTIVATE_NOW,FB_ACTIVATE_NXTOPEN, and
FB_ACTIVATE_TEST. FB_ACTIVATE_TEST tells us if the hardware can handle what
the user requested. FB_ACTIVATE_NXTOPEN sets the values wanted on the next
explicit open of fbdev. The final one FB_ACTIVATE_NOW checks the mode to see
if it can be done and then sets the mode. You MUST check the mode before all
things. Note this function is very card specific but I attempt to give you
the most general layout.. The basic layout then for xxxfb_set_var is

static int vfb_set_var(struct fb_var_screeninfo *var, struct fb_info *info)
{
int line_length;

/* Basic setup test. Here we look at what the user passed in that he/she
wants. For example to test the fb_var_screeninfo field vmode like is
done in vfb.c. Here we see if the user has FB_VMODE_YWARP. Also we
should look to see if the user tried to pass in invalid values like 17
bpp (bits per pixel) */

/* Remember the above discussion on how monitors see a mode. They don't
care about bit depth. So you can divide the checking into two parts.
One is to see if the user changed a mode from say 640x480 at 8 bpp to
640x480 at 32 bpp. Remember the var in fb_info represents the current
video mode. Before we actually change any resolutions we have to make
sure the card has enough memory for the new mode. Discovering how much
memory a video card has varies from card to card. Also finding out how
much memory we have is done in xxxfb_init since this never changes
unless you add more memory to your card which requires a reboot of the
machine anyway. You might have to do other tests depending on the make of
your card. Note the par filed in fb_info. This is used to store card
specific data. This data can effect set_var. Also it is present to
allow other possible drivers that could affect the framebuffer device
such as a special driver for an accel engine or memory mapping the z
buffer on a card */

/* Summary. First look at any var fields to see if they are valid. Next
test hardware with these fields without setting the hardware. An
example of one is find what the line_lenght would be for the new
mode. Then test the following */

if ((line_length * var->yres_virtual) > info->fix.smem_len)
return -ENOMEM;

if (info->var.xres != var->xres || info->var.yres != var->yres ||
info->var.xres_virtual != var->xres_virtual ||
info->var.yres_vitual != var->yres_virtual) {
/* Resolution changed !!! */

/* Next you must check to see if the monitor can handle this mode.
Don't want to fry your monitor or mess up the display really
badly */
if (fbmon_valid_timings(u_int pixclock, u_int htotal, u_int vtotal,
      const struct fb_info *fb_info))
/* Can't handle these timings. */
return -EINVAL;

/* Timings are okay. Next we see if we really want to change
this mode */
if ((activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
/* Now let's program the clocks on this card. Here the code is
very card specific. Remember to change any fields for fix in
info that might be effected by the changing of the resolution.
*/
...
info->fix.line_length = line_length;
...

/* Now that we have dealt with the possible changing resolutions
let's handle a possible change of bit depth. */
if (info->var.bits_per_pixel != var->bits_per_pixel) {
if ((err = fb_alloc_cmap(&info->cmap, 0, 0)))
return err;
}
}

/* We have shown that the monitor and video card can handle this mode or
have actually set the mode. Next the fb_bitfield structure in
fb_var_screeninfo is filled in. Even if you don't set the mode you get
a feel of the mode before you really set it. These are typical values
but may be different for your card. For truecolor modes all the fields
matter. For pseudocolor modes only the length matters. Thus all the
lengths should be the same (=bpp). */

switch (var->bits_per_pixel) {
case 1:
case 8:
/* Pseudocolor mode example */
var->red.offset = 0;
var->red.length = 8;
var->green.offset = 0;
var->green.length = 8;
var->blue.offset = 0;
var->blue.length = 8;
var->transp.offset = 0;
var->transp.length = 0;
break;
case 16: /* RGB 565 */
var->red.offset = 0;
var->red.length = 5;
var->green.offset = 5;
var->green.length = 6;
var->blue.offset = 11;
var->blue.length = 5;
var->transp.offset = 0;
var->transp.length = 0;
break;
case 24: /* RGB 888 */
var->red.offset = 0;
var->red.length = 8;
var->green.offset = 8;
var->green.length = 8;
var->blue.offset = 16;
var->blue.length = 8;
var->transp.offset = 0;
var->transp.length = 0;
break;
case 32: /* RGBA 8888 */
var->red.offset = 0;
var->red.length = 8;
var->green.offset = 8;
var->green.length = 8;
var->blue.offset = 16;
var->blue.length = 8;
var->transp.offset = 24;
var->transp.length = 8;
break;
}
/* Yeah. We are done !!! */
}


The function xxxfb_setcolreg is used to set a single color register for a
video card. To use this properly you must understand colors which is
discribed above. This routine sets a color map entry. The regno passed into
the routine represents the color map index which is equal to the color that's
composed of the amount of red, green, blue, and even alpha that are also
passed into the function. For psuedocolor modes this color map index (regno)
represents the pixel value. So if you place a pixel value of regno in video
memory you get the color that's made of the red, green, blue that you passed
into xxxfb_setcolreg. Now for truecolor and directcolor mode it's a little
different. In this case we simulate a psuedo color map. The reason for this
is the console system always has a color map which has 16 entries. In fb_info
there is the pseudo_palette which gives a mapping from a non color map
mode to a color map based system. The pseudo_palette always has 17 entries.
The first 16 for the console colors and the last one for the cursor. So if
we wanted to display the 4 entry in the color map of the console we would
placed the value of info->psuedo_palette[4] directly into the video memory.
This is of course taken care of by fbcon. You just need to code the
"formula" that does this translation. A example follows for 32 bit mode.

red >>= 8;
green >>= 8;
blue >>= 8;
info->pseudo_palette[regno] =
(red << info->var.red.offset) |
(green << info->var.green.offset) |
(blue << info->var.blue.offset);

Here we first scale down the color components. Each color passed to
set_colreg are 16 bits in size. For 32 bit mode each color is 8 bits in size.
Then we or the colors together after we offseted them. The offset is used
because the pixel layout in 32 bits could be RBGA, ARGBA etc. In setcol_reg
of vfb.c is the standard way to deal with packed pixel format of various
image depths. Regno is the index to get this particular color.

That does it for required functions besides the set of needed accel
functions which has not been discussed yet. If the video card doesn't
support the function then we just place a NULL in fb_ops. The next fuction
in fb_ops is xxxfb_blank. This function provides support for hardware
blanking. For xxxfb_blank the first parameter represents the blanking modes
available. They are VESA_NO_BLANKING, VESA_VSYNC_SUSPEND, VESA_HSYNC_SUSPEND,
and VESA_POWERDOWN. VESA_NO_BLANKING powers up the display again.
VESA_POWERDOWN turns off the display. This is great power saving feature on
a laptop.

The next optional function is xxxfb_pan_display. This function enables
panning. Panning is often used for scrolling.

The ioctl function gives you the power to take advantage of special features
other cards don't have. If your card is nothing special then just give this
fb_ops function a NULL pointer. The sky is the limit for defining your ioctl
calls.

There is a default memory map function for fbdev but sometimes it just
doesn't have the power you truly need. A good example of this is video
cards that work in sparc workstations. Those need their own mmap functions because
sparcs handle memory differently from other platforms. This is
true even for sparcs with PCI buses.

Now here is the next class of functions which are optional. The
xxxfb_accel_init and xxfb_accel_done. xxxfb_accel_init really depends on
the card. It is intended to initialize the engine or set the accel engine into
a state which you can use the acceleration engine. It also ensures that the
framebuffer is not accessed at the same time as the accel engine. This
can lock a system. Uusally there is a bit to test to see if an accel
engine is idle or the card generates an interrupt. For cards that used the
old fb_rasterimg this function replaces it. Some cards have a separate state
for 3D and 2D. This function insures that the card goes into a 2D state,
just in case a previous application set the accel engine into a 3D state
or made the accel engine very unhappy. The next function that encomposses
this set is xxxfb_accel_done. This function sets the video card in a state
such that you can write to the framebuffer again. You should provide both
functions if your driver uses even one hardware accelerated function. The
reason is to ensure that the framebuffer is not accessed at the same
time as the framebuffer.

Finally the third class of fb_op functions. Like the first they are required.
If your card does not support any of these accelerated functions there are
default functions for packed pixel framebuffer formats. They are
cfba_fillrect, cfba_copyarea, cfba_imgblit. If you supports some but not
all of the accels available you can still use some of these software emulated
accels. Each software emulated accel is stored in a seperate file. Now let's
describe each accel function. Before we discuss these functions we need to
note not to draw in areas past the video boundries. If it does you need to
adjust the width and height of the ares to avoid this problem. The first
function just fills in a rectangle starting at x1 and y1 of some width and
height with a pixel value of packed pixel format. If the video memory mapping
is not a direct mapping from the pixel value (not FB_TYPE_PACKED_PIXEL) you
will have to do some translating. There are two ways to fill in the
rectangle, FBA_ROP_COPY and FBA_ROP_XOR. FBA_ROP_XOR exclusive ors the pixel
value with the current pixel value. This allows things like quickly erasing
a rectangular area. The other function just directly copies the data. The
next function is xxxfb_copyarea. It just copies one area of the framebuffer
at source x and source y of some width and height to some destination x and
y. The final function is xxxfb_imageblt. This function copies an image from
system memory to video memory. You can get really fancy here but this is
fbdev which has the purpose of mode setting only. All the image blit
function does is draw bitmaps, images made of a foregound and background
color, and a color image of the same color depth as the framebuffer. The
second part is used to draw the little penguins. The drawing of bitmaps is
used to draw our fonts. That does it for the functions. Now you should be
set for writing your driver.

- 作者: merfesyt 2006年05月15日, 星期一 20:25  回复(0) |  引用(1) 加入博采

已锁定
此日志的浏览权限已被作者锁定,请同作者联系,发送短消息,如果你的身份符合作者的要求,点击此处可以进行浏览

- 作者: merfesyt 2006年05月13日, 星期六 10:50  回复(0) |  引用(1) 加入博采

酒还没醒
晚上在实验室,碰巧顺子也在工物馆做试验。10点半的时候,本邀我一同回宿舍,不想被我敲他bg!本是句玩笑话,没想到他爽快的答应了,还幽幽的说:走吧,西门鸡翅!反正你马上也要滚蛋了,鲜有机会一起喝酒了。几句话,却说得我突然一阵心酸。像往常一样,我们之间总是少不了几句调侃,接下来就是互相挖苦。这个习惯大体上从初中时候就保留了。记得从那时候开始,我俩坐同桌得时候吧?就开始习惯这样的游戏,极尽之所能,用最尖酸的话语挖苦着对方,哈哈,虽然大家都心知肚明本是些玩笑话,但是却都乐此不疲,并常常擦出搞笑的火花。寒暄完之后,继续着彼此所谓的课题,论文之类的无聊话题,接下来就入正题,喝酒!在我印象中,他是很能喝酒的哥们,以至于我在他面前总是逊了那么一点,啤酒在他看来就像水一样悠然下肚,而且面不改色,而我则“喜形于色”。我总调侃到:你总是那么深不可测,连喝酒都是那么深藏不露。他反击到:那是你太不能喝了!还总是教育我:应该练的海量一点,否则出去怎么混啊,此时,我每每做出一副受教的姿态:是啊,是啊,得向前辈学习啊。
谈着逐渐话题转向了未来,转向了分别。是啊,就要离开学校了,可能两年的分别,甚至更久,自此天各一方。总觉得我俩很有缘,一起念初中,高中,一起坐同桌,一起拌嘴,一起打架,甚至现在一起在清华园里读书,一起常常在大厅广众之下操着家乡话大声聊天。彼此之间还是那样的坦率,总觉得倍感亲切......未来会是什么样的呢?
回到宿舍,感觉喝的有点高,晕乎乎的。可能是喝得有点急的缘故,还是不太习惯他这种喝酒的快节奏,太豪迈了!已经快1点了,睡不着,听着李健的《中学时代》,突然很多以前中学时代的记忆涌上心头。单纯,快乐,无忧无虑。
即将分别的日子,祝愿顺子一切快乐,顺利,以后的日子依然那么聪明,那么才华横溢,我永远坚信你是最优秀的!也祝愿自己一路走好......

- 作者: merfesyt 2006年04月14日, 星期五 01:01  回复(0) |  引用(1) 加入博采

Time after time

 从我的msn-space上转过来一篇,平时大都在space上更新一些东西,也相对方便一些,渐渐的也较少来这里了。

在朋友的Blog上看见对Journey South这首专辑的介绍,美国乡村音乐。虽然对Andy and Carl Pemberton这两兄弟的组合很是陌生,还是静下心来听了整张专辑。记得曾经看到过,美国乡村音乐歌手似乎都有一个共同的特点,那就是认为“快乐就像生活一样,永远是不安全的”。正因为如此,他们的歌中总是带有一种冷淡或忧愁。恩,最喜欢整张专辑的Time after time和It must have been love 这两首。
 

                   Time after time

Lying in my bed I hear the clock tick,
And think of you
Caught up in circles confusion
Is nothing new
Flashback
warm nights
Almost left behind
Suitcases of memories,
Time after time
Sometimes you picture me
I'm walking too far ahead
You're calling to me, I can't hear
What you've said
Then you say go slow
I fall behind
The second hand unwinds
If you're lost you can lookand you will find me
Time after time
If you fall I will catch you I'll be waiting
Time after time
After my picture fades and darkness has
Turned to gray
Watching through windows you're wondering
If I'm OK
Secrets stolen from deep inside
The drum beats out of time
You said go slow
I fall behind
The second hand unwinds
...time after time
time after time
time after time
time after time

 

- 作者: merfesyt 2006年04月13日, 星期四 12:52  回复(0) |  引用(1) 加入博采

去罗胖子的窝看了看
今天把罗胖子的blog加进了我msn-space的链接。想必,罗胖子何须人也,不需再做过多解释,自称新东方一傻逼老愤青是也。最常用的口头禅就是骂人sb。在我们这个讲究友善礼貌,有着五千年光辉灿烂历史的优秀民族来说,这种人被广大学子所推崇,的确是有点另类。但是万事存在即有道理,至少在我看来,我还是非常欣赏这种口无遮拦的愤青的。最早听说他是从上新东方GRE班的同学那里,真正亲自领略他这种彪悍的人生态度则是从听老罗语录开始。记得去年冬天翻来覆去把可以搜到的所有语录听了两遍,最大感触是胖子嬉笑怒骂间骂的是酣畅淋漓。只可惜自己没有考过GRE,不能亲自领略他的彪悍。提到这里,不觉感到有些遗憾,周围的同学,尤其是本科时候的,不管最终去了美立坚合众国的,没有出去的,即将打算出去的,或是曾经打算出去而现在又不愿出去的,大都考过GRE。而我没有考,算是人生不完整吧,在朋友当中也算是一另类吧。因此也就没有机会接触罗永浩这样的奇人+神人。想必以后也不再有机会了。
无意在网上搜到了罗胖子的blog,选了一个,加了进来。btw,现在的名人博客真多。但大都是新浪,搜狐这种媚俗的八卦网站用这些名人,给自己增添点击率的,我甚至怀疑是否本人在维护自己的博客......
为什么一切美好的东西,到了我们这个文明古国就变味了呢?套用罗胖子的话来评论:我对这一切感到非常的恶心。
呵呵,已经过了愤青的年龄,偶尔还是可以去老罗的博客转转,有时候还是有点启发的,彪悍的人生不需要解释!hoho

- 作者: merfesyt 2006年04月6日, 星期四 22:18  回复(0) |  引用(1) 加入博采

将LINUX的控制台定向到串口终端(转载)- -
 利用串口终端作为Linux控制台,可以免去额外的键盘,显示卡和显示器,同时可将Linux主机作为一个任意用途的嵌入式黑匣。将串口终端连接到计算机的串口上并不困难,可以参考Linux的HOWTO文档和以及inittab和agetty的帮助信息。这里扼要地说一下。
  首先,准备好一根null modem 电缆.
  其次,在文件/etc/inittab 增加下面一行。[注:如果你不采用 agetty程序,采用其他的程序如like getty_ps ,应用正确的命令语法]
   ID:RUNLEVELS:respawn:/sbin/agetty -L SPEED TTY TERM
  这里: ID =两字母的标识符,如s1或s2。
  RUNLEVELS = 终端激活的运行级别
  SPEED = 串口端口速率
  TTY = 串口的设备名
  TERM = TERM环境变量
  范例如下:
  s2:12345:respawn:/sbin/agetty -L 9600 ttyS1 vt100
  表示串口 /dev/ttyS1 (COM2 )速率为 9600 bps,终端模式为vt100。
  最后,重新启动机器。
  如正确地按照上述三步进行,则就可以在终端屏幕上出现Login: 的提示符。你可以登录进系统,并能象在实际的控制台上或从远程Telnet登录一样进行工作。
  下面简单介绍一下如何终端设置成控制台,主要涉及内核信息、启动脚本信息和LILO信息。

一、内核信息
  系统在启动时显示的信息总是输出到主控制台(tty1)。打开机器后,你只有等待Login: 出现在终端屏幕上,这意味着所有启动信息都无法获悉。你只有登录后用dmesg命令查看,但通常是想在login shell起来前看到这些信息。
  还有其他信息出现在控制台上:/etc/rc.d目录下脚本命令执行时,启动和终止机器时运行的脚本命令等输出的信息。如果信息没有出现在屏幕上,怎样真正地知道"系统已终止"呢?
  你必须修改源码/usr/src/linux/drivers/char/console.c[必须已安装了内核源码],这不是一个复杂得内核修改,按照下面三步进行:
  首先,在程序前定义CONFIG_SERIAL_ECHO
  #define CONFIG_SERIAL_ECHO
  其次,修改串口地址 (仅当你使用得端口不同于默认定义的才有必要修改)。
  #define SERIAL_ECHO_PORT 0x3f8 /* COM1 */
  或者:
  #define SERIAL_ECHO_PORT 0x2f8 /* COM2 */
   第三,重新编译内核[请参考相应的手册],启动机器。在系统检测硬件设备时,你应该在终端屏幕上看到信息。
   请注意 :console.c 补丁除了Alpha平台外,对所有的Linux 端口都是必要的。在Alpha平台上它是在运行make config ,选择下面的选项完成的:
   Echo console messages on /dev/ttyS1

二、/etc/rc.d/rc.*启动脚本信息
  为了将这些信息显示在终端上,可以将这些文件中含有echo命令的行追加" > TTY "。 TTY 是终端的串口(与/etc/inittab 中串口终端行的一样)。

三、 LILO 配置
  如果想选择两个内核之一启动,你必须修改LILO 配置文件,/etc/lilo.conf。 配置LILO,使提示信息出现在终端上,可以参考/usr/doc/lilo/README 文件 (查看SERIAL选项)。 这里给出两步正确设置的步骤:
  首先,编辑/etc/lilo.conf file ,在BOOT选项行后,插入一个SERIAL选项 。
serial=SERIAL_LINE,SPEED PARITY BITS
  这里:
  SERIAL_LINE = 0 (串口1)
          1 (串口2)
         2 (串口3)
         3 (串口4)
  SPEED = 串口速度
  PARITY = n (=无)
       o (= 奇校验)
       e (= 偶校验)
  BITS = 数据位(8 or 7)
  请注意:在SPEED, PARITY 和BITS参数间没有空格。这些参数必须与在terminal 设置时的参数一样。下面是LILO 配置的示例:
  serial=1,9600n8
  这一行表示COM2 ,速率9600bps,无校验位,数据位8。
  第二,运行lilo 命令,刷新系统配置。
  利用SERIAL 选项, LILO 在启动默认内核前,设置了2秒的延迟 。在这期间,你可以 在终端上按"SHIFT"键发送一个终止信号,终止boot进程,并取得LILO提示信息。
  完成上述配置后,你的终端就可以作为一个控制台了。有一件事不能做的是用CTRL-ALT-DEL 重启动系统。

- 作者: merfesyt 2006年04月4日, 星期二 12:10  回复(0) |  引用(1) 加入博采

那首MTV

晚饭时遇见了alopha,好久不见了,遂相约一起去吃饭。想来这个学期还没有去西门鸡翅店腐败过,于是一同前往。想想一年前,那里还有雅克西可是我们经常光顾的地方。一晃,自己也即将毕业,这个学期,都把自己搞得很忙的样子,鲜有机会一起喝酒,一起聊天。

还是老味道,可能只顾着喝酒,我竟然感觉不出以前的那种鸡翅香味,只是机械的往嘴里丢着东西,聊的话题,无非还是什么狗屁前途,所谓的未来。我只能一遍遍地鼓励着alopha,毕竟他还小,他还有很多条路等他去选择,更大的挑战等待着他。其实,一直把他当弟弟看待,很不愿看到他郁闷的表情。其实,只想告诉他,努力了就可以了,不要给自己留下什么遗憾。嗯,也许自己也是在逐渐的经历一些事情之后,逐步认识到这些简单而直白的道理。曾几何时,自己曾经对这些所谓的道理是嗤之以鼻。但是现实告诉我们,我们不可能看清所有的未来。对于一切的未知,我们也许都应该怀着一份新奇和勇敢的态度去迎接,努力了,争取了,不再给自己留下什么遗憾。

晚上回来,翻看以前的一些东西,随手点开了那个经典的MV,裴勇俊主演的,已经珍藏快两年了,经常拿出来看看。也经常和朋友们分享它。本身是个凄美的爱情故事,结局也不免韩国MTV所特有的煽情俗套。但是这首MTV一直给我特别的感觉,男女主角淡淡的,含蓄的相爱着,缘起自一辆单车,也结束在这辆单车上。男主角执着的寻找着那辆自己丢失的单车,即使自己遭到毒打,其实寓意着对自己向往的事物的那份追求,永不舍弃。结局让人感到有些扼腕,女主角骑着自己为他买来的心爱的单车,却被呼啸而过的汽车带过...

他依然坐在黄昏下,列车轨边,玩着硬币,幸福的期待着他心爱的人和那辆单车...

从朋友的blog里看见一句话,突然有些感触,改了改,帖出来:

享受属于自己的哪怕是微小的幸福,这一生会很快的过完,来不及悲伤......

- 作者: merfesyt 2006年04月3日, 星期一 22:57  回复(0) |  引用(1) 加入博采

已锁定
此日志的浏览权限已被作者锁定,请同作者联系,发送短消息,如果你的身份符合作者的要求,点击此处可以进行浏览

- 作者: merfesyt 2006年04月2日, 星期日 00:56  回复(0) |  引用(1) 加入博采

慵懒的傍晚

这几天情绪老是因一些事情波动起伏,论文导师还迟迟没有给回复意见,也就有了一份精力和时间去不务正业。总是去怀念一些东西,翻看一些曾经的记录,去感伤一些事情。

静不下心来,任凭电脑里的音量开到最大,放着一首首许巍的歌曲,沉浸在他低吟叙事的声音中。好久不抽烟了,只有在特别烦闷的时候会点一支,但是要点却不在享受那个过程,而是享受那种排解郁闷的方式。

同屋的兄弟递过来了一支,点了,思绪随烟雾越飘越远...

同他一起步行去桃李院吃麻辣烫。步行,于我来说,实在是件罕见的事情。出门便以车代步,习惯了,却很少有这种悠闲去感受清华园里另一份静谧与安详。自己实际不忙,单平时却总是把自己搞得很忙的样子,事实上我在逃避一些东西,一些我自己也说不清的东西,也许若干年后回头看这段时光,也许会有所感悟,但这就是生活。一时的兴起,让我享受了这个慵懒的傍晚。

电脑里依然放着齐秦的《往事随风》,是呀,往事随风,又何必让飘过的风去影响自己的心情呢?随风一起感受那份美好的回忆,收拾心情...

- 作者: merfesyt 2006年03月29日, 星期三 19:40  回复(0) |  引用(1) 加入博采