File: HOWTO-framebuffer.html

package info (click to toggle)
qt-embedded 2.3.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 68,608 kB
  • ctags: 45,998
  • sloc: cpp: 276,654; ansic: 71,987; makefile: 29,074; sh: 12,305; yacc: 2,465; python: 1,863; perl: 481; lex: 480; xml: 68; lisp: 15
file content (226 lines) | stat: -rw-r--r-- 7,635 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit -  Enabling the Linux framebuffer</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style></head><body bgcolor="#ffffff">
<p>
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center> Enabling the Linux framebuffer</h1><br clear="all">
<h1>How to enable framebuffer support in the Linux kernel</h1>
<p>
This is only a short guide.
See <a href="file:/usr/src/linux/README"><tt>/usr/src/linux/README</tt></a> and
<a href="file:/usr/src/linux/Documentation/fb/"><tt>/usr/src/linux/Documentation/fb/</tt></a>
for detailed information.
There is also a detailed explanation at:
<a href="http://www.linuxdoc.org/HOWTO/Framebuffer-HOWTO.html">
http://www.linuxdoc.org/HOWTO/Framebuffer-HOWTO.html</a>
<p>
<ol>
<li> Make sure that you have the Linux kernel source code in
<a href="file:/usr/src/linux/">/usr/src/linux/</a>. 
<li> Log in as root and cd /usr/src/linux
<li> Configure the kernel:
<p>
   Run:
<pre>
        make menuconfig
</pre>
<p>
   Select "Code maturity level options" and set "Prompt for
   development and/or incomplete code/drivers".
<p>
   Then select "Console drivers" set "Support for frame buffer
   devices" to built-in (even if it says EXPERIMENTAL). Then configure
   the driver. Most modern graphics cards can use the "VESA VGA
   graphics console"; use that or a driver that specifically matches
   your video card. Finally enable "Advanced low level driver options"
   and make sure that 16 and 32 bpp packed pixel support are enabled. 
<p>
   When you are finished, chose exit and save.
<li> Compile the kernel
<p>
   First do:
<pre>
        make dep
</pre>
   then:
<pre>
        make bzImage
</pre>
<p>
  The new kernel should now be in <tt>arch/i386/boot/bzImage</tt>
<li> Copy the kernel to the boot directory:
<pre>
        cp arch/i386/boot/bzImage /boot/linux.vesafb
</pre>
<li> Edit <tt>/etc/lilo.conf</tt>
<p>
<i>
  IMPORTANT: Keep a backup of /etc/lilo.conf, and have a rescue disk
  available. If you make a mistake at this stage, the machine may not
  boot.
</i>
<p>
   The file /etc/lilo.conf specifies how the system boots. The precise
   contents of the file varies from system to system, this is one example:
<pre>
boot = /dev/hda3
delay = 30 
image = /boot/vmlinuz
  root = /dev/hda3
  label = Linux
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking
other=/dev/hda1
        label=nt
        table=/dev/hda
</pre>
<p>
<i>
  IMPORTANT: Keep a backup of /etc/lilo.conf, and have a rescue disk
  available. If you make a mistake here, the machine may not boot.
</i>
<p>
  Make a new "image" section that is a copy of the first one, but with
  image = /boot/linux.vesafb and label = Linux-vesafb. Place it just
  above the first image section.
<p>
  Add a line before the image section saying 'vga = 791'. (Meaning
  1024x768, 16 bpp.) 
<p>
  With the above example, lilo.conf would now be:
<pre>
boot = /dev/hda3
delay = 30 
vga = 791
image = /boot/linux.vesafb
  root = /dev/hda3
  label = Linux-vesafb
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking
image = /boot/vmlinuz
  root = /dev/hda3
  label = Linux
  read-only # Non-UMSDOS filesystems should be mounted read-only for checking
other=/dev/hda1
        label=nt
        table=/dev/hda
</pre>
<p>
Do not change any lines in the file; just add new ones.
<li> Run lilo
<p>
   To make the new changes take effect, run the lilo program:
<pre>
        lilo
</pre>
<li> Reboot the system
<p>
   You should now see a penguin logo while the system is booting.
   (Or more than one on a multi-processor machine.)
<li> Error recovery
<p>
   If it does not boot properly with the new kernel, you can boot with
   the old kernel by entering the label of the old image section at
   the LILO prompt. (with the example lilo.conf file, the old label is
   Linux.)
<p>
   If that does not work (probably because of an error in lilo.conf),
   boot the machine using your rescue disk, restore /etc/lilo.conf from
   backup and re-run lilo.
<li> Testing
<p>
   Here's a short C program that opens the frame buffer and draws a
   gradient-filled red square.
<pre>
<p>
int main()
{
    int fbfd = 0;
    struct fb_var_screeninfo vinfo;
    struct fb_fix_screeninfo finfo;
    long int screensize = 0;
    char *fbp = 0;
    int x = 0, y = 0;
    long int location = 0;
<p>
    // Open the file for reading and writing
    fbfd = open("/dev/fb0", O_RDWR);
    if (fbfd < 0) {
        printf("Error: cannot open framebuffer device.\n");
        exit(1);
    }
    printf("The framebuffer device was opened successfully.\n");
<p>
    // Get fixed screen information
    if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
        printf("Error reading fixed information.\n");
        exit(2);
    }
<p>
    // Get variable screen information
    if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
        printf("Error reading variable information.\n");
        exit(3);
    }
<p>
    printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );
<p>
    // Figure out the size of the screen in bytes
    screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
<p>
    // Map the device to memory
    fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
                       fbfd, 0);
    if ((int)fbp == -1) {
        printf("Error: failed to map framebuffer device to memory.\n");
        exit(4);
    }
    printf("The framebuffer device was mapped to memory successfully.\n");
<p>
    x = 100; y = 100;       // Where we are going to put the pixel
<p>
    // Figure out where in memory to put the pixel
    for ( y = 100; y < 300; y++ )
        for ( x = 100; x < 300; x++ ) {
<p>
            location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) +
                       (y+vinfo.yoffset) * finfo.line_length;
<p>
            if ( vinfo.bits_per_pixel == 32 ) {
                *(fbp + location) = 100;        // Some blue
                *(fbp + location + 1) = 15+(x-100)/2;     // A little green
                *(fbp + location + 2) = 200-(y-100)/5;    // A lot of red
                *(fbp + location + 3) = 0;      // No transparency
            } else  { //assume 16bpp
                int b = 10;
                int g = (x-100)/6;     // A little green
                int r = 31-(y-100)/16;    // A lot of red
                unsigned short int t = r<<11 | g << 5 | b;
                *((unsigned short int*)(fbp + location)) = t;
            }
<p>
        }
    munmap(fbp, screensize);
    close(fbfd);
    return 0;
}
</pre>

<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright  2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>