Sunday, February 13, 2005

fbtest.c

ok i am currently running mandrake 9.2 and
it looks like it has frame buffer support.

maybe i can

take a look at page:
http://lists.trolltech.com/qt-interest/2002-12/msg01247.html
this dumps some pixels to the framebuffer
this can be good so instead i shortend
the program and just had it return
the current frame buffer size.

#include
#include
#include
#include
#include

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;

// Open the file for reading and writing
fbfd = open("/dev/fb0", O_RDWR);
if (!fbfd) {
printf("Error: cannot open framebuffer device.\n");
exit(1);
}
printf("The framebuffer device was opened successfully.\n");

// Get fixed screen information
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
printf("Error reading fixed information.\n");
exit(2);
}

// Get variable screen information
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
printf("Error reading variable information.\n");
exit(3);
}

printf("%dx%d, %dbpp\n", vinfo.xres, vinfo.yres, vinfo.bits_per_pixel );


munmap(fbp, screensize);
close(fbfd);
return 0;
}

what i get is
800x600
which is funny because the current
screen setting i have 1240 by 1024
interesting.

but lets concentrate on building the frame buffer support.

again i should go back over my notes:
here is one of the starting place of this work:

http://www.geocities.com/potato.geo/bootlinuxcd.html
and he says:

Framebuffer

One of my experimental aims is to have an X windows environment on a boot CD. To achieve the widest possible compatibility, I've chosen to enable the Framebuffer console mode and to use the XF86_FBDev X server (its just the one from Slackware 7.1 at the moment). Note: Even though I am aiming for wide compatibility just so I can run X, Framebuffer mode doesn't work with pre VESA 2.0 video cards which means you may not want to add in Framebuffer if all you really need is a console prompt. To activate Framebuffer console mode you need to make sure some things are compiled into the kernel, typically this includes:

[*] VGA text console
[*] Video mode selection support
[*] Support for frame buffer devices (EXPERIMENTAL)
[*] VESA VGA graphics console
[*] Advanced low level driver options
<*> 8 bpp packed pixels support
<*> 16 bpp packed pixels support
<*> 24 bpp packed pixels support
<*> 32 bpp packed pixels support
<*> VGA characters/attributes support
[*] Select compiled-in fonts
[*] VGA 8x8 font
[*] VGA 8x16 font

The other thing that I didn't realise until later is you have to make sure you set a graphical mode for the console when it boots in order to use the X server in default mode. This means putting a specific vga= setting appended to the kernel at boot time. Specifically, you need to change the /isolinux/isolinux.cfg file on the CD so it looks something like:

label linux
kernel vmlinuz
append initrd=initrd.gz vga=791

The '791' means to start up in 1024x768x16bit colour mode. Hard coding the display resolution is fine if you know for certain that your video card/monitor can handle it, but what I've done is to let the user choose a display option at boot time. My isolinux.cfg looks like this:

timeout 30
prompt 1
display menu.txt
default 1
label 1
kernel vmlinuz
append initrd=initrd.gz

label 2
kernel vmlinuz
append initrd=initrd.gz vga=788

label 3
kernel vmlinuz
append initrd=initrd.gz vga=791

menu.txt is a simple text file that looks like:

1) Text Mode
2) 800x600 x 16bit colour
3) 1024x768 x 16bit colour

The user just enters '1' if they want text mode, 2 for 800x600 and so on.

No comments: