start_framebuffer

来源:互联网 发布:ubuntu搜狗输入法 使用 编辑:程序博客网 时间:2024/06/05 20:29

  提要:通过用   framebuffer   驱动,让console模式看上去更舒服一些; 
  
  正文; 
  
  在console模式(也就上文本显示,也是text模式),说直接一点,就是全屏是黑色的,象DOS那样的界面的,在桌面环境下,按CTRL+ALT+F2   或者F3   等,就进入console模式了。就是完全文本命令操作的那种非图形桌面环境。 
  
  用   framebuffer   驱动及配置,主要是能让text模式下找到更适合的观感。 
  
  一、让console   模式下分辨率起作用的主要配置文件是   lilo.conf   或者   grub.conf   ,   lilo.conf   是lilo系统引导管理器的配置文件,如果您用这个来引导系统,就要配置   lilo.conf文件;grub.conf   是另一个系统引导管理器grub的配置文件。这两个系统引导管理器,其作用是一样的,只是实现的方法不太一样。这两个管理器不能同时使用。 
  
  二、framebuffer   console的参数如下,主要是分辨率; 
  
  #   Colours   640x480   800x600   1024x768   1280x1024   1600x1200 
  #   --------+--------------------------------------------- 
  #   256   |   769   771   773   775   796 
  #   32,768   |   784   787   790   793   797 
  #   65,536   |   785   788   791   794   798 
  #   16.8M   |   786   789   792   795   799 
  
  如果看不懂上面的这个,就看下面的这个,对照着看吧 
  
  #   Normal   VGA   console 
  #   vga   =   normal 
  #   VESA   framebuffer   console   @   1024x768x64k 
  #   vga=791 
  #   VESA   framebuffer   console   @   1024x768x32k 
  #   vga=790 
  #   VESA   framebuffer   console   @   1024x768x256 
  #   vga=773 
  #   VESA   framebuffer   console   @   800x600x64k 
  #   vga=788 
  #   VESA   framebuffer   console   @   800x600x32k 
  #   vga=787 
  #   VESA   framebuffer   console   @   800x600x256 
  #   vga=771 
  #   VESA   framebuffer   console   @   640x480x64k 
  #   vga=785 
  #   VESA   framebuffer   console   @   640x480x32k 
  #   vga=784 
  #   VESA   framebuffer   console   @   640x480x256 
  #   vga=769 
  
  三、配置[对于大多数Linux发行版,如果您是用系统自带的内核,内核是支持   framebuffer   驱动的。您可以用直接用下面的方法来做] 
  
  1.对于grub系统引导管理器的配置方法; 
  
  如果您用   grub来引导,要修改   /etc/grub.conf   或者   /boot/grub/menu.lst   ,其实这两个文件都是一样的,因为   grub.conf   是   menu.lst的链接。 
  
  比如我没有修改过的grub.conf   是这样的: 
  
  说明一下:我的机器目前安装了三个操作系统,一个是xp   另一个是Fedora   core   4.0   ,还有一个是   Slackware   10.1 
  
  代码: 
  
  default=1 
  timeout=5 
  splashimage=(hd0,7)/boot/grub/splash.xpm.gz 
  #hiddenmenu 
  
  title   Fedora   Core   (2.6.11-1.1369_FC4) 
                  root   (hd0,7) 
                  kernel   /boot/vmlinuz-2.6.11-1.1369_FC4   ro   root=LABEL=/1   rhgb   quiet     
                  initrd   /boot/initrd-2.6.11-1.1369_FC4.img 
  
  title   Slack 
                  root   (hd0,8) 
                  kernel   /boot/vmlinuz   ro   root=/dev/hda9     
  
  title   WinXp 
                  rootnoverify   (hd0,0) 
                  chainloader   +1   
  
  
  
  我们要参照上面的参数表,对照看着在您要改变的   Linux   的   console分辨率的那个   kernel   一行的后面加上   vga=xxx   ,这里的   xxx,就是通过上面的参数表中查出来的。 
  
  比如我是   15寸的液晶显示器,我看看一下   1024x768x256是不是适合,所以我就在   kernel   那行的后面打一个空格后,加上了   vga=773 
  
  代码: 
  
  default=1 
  timeout=5 
  splashimage=(hd0,7)/boot/grub/splash.xpm.gz 
  #hiddenmenu 
  
  title   Fedora   Core   (2.6.11-1.1369_FC4) 
                  root   (hd0,7) 
                  kernel   /boot/vmlinuz-2.6.11-1.1369_FC4   ro   root=LABEL=/1   rhgb   quiet   vga=773 
                  initrd   /boot/initrd-2.6.11-1.1369_FC4.img 
  
  title   Slack 
                  root   (hd0,8) 
                  kernel   /boot/vmlinuz   ro   root=/dev/hda9   vga=773 
  
  title   WinXp 
                  rootnoverify   (hd0,0) 
                  chainloader   +1 
  
  
  
  这样改过保存后,重启系统,进入相应的   Linux   ,就知道是不是起作用了。比如发现   vga=773对我来说有点不适合。可以再找上面的参数来改一下就行了。 
  
  2.对于   lilo引导管理器的配置方法; 
  
  我们要改   /etc/lilo.conf这个文件;lilo的配置比较简单,因为vga=xxx是独立的一行。并且lilo.conf中有详细的配置参数,也就是我上面列出的那些,就是来自   lilo.conf的。想打开哪个参数,就把vga=xxx前面的#号去掉就行,当然不能同时打开多个。 
  
  注意的是:如果改了lilo.conf后,得执行   lilo   -v 
  
  
  四、对于自编译内核的,需要注意以下几点。 
  
  1.在编内核时,要选中如下的选项;以加入   framebuffer   驱动的支持; 
  [*]   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 
  
  
  
  2,我们还要知道自己所用的显示卡,也有   framebuffer的驱动,所以也要一并选中,比如 
  <*>   nVidia   Framebuffer   Support 
  <*>   ATI   Radeon   display   support 
  
  在查看内核选项是,用   shift键+?号的组合键,就能看到详细情况; 
  
  
  后记:我对   framebuffer原理不明白,以我的水平也根本懂不了;我写的东西可能在句法中不通或者说是一点也不对。我只能以我应用的来说明,仅此而已;一切都是为了应用; 
  
  请弟兄们补充和订正,谢谢~ 
  
  参考资料: 
  lilo说明文档,内核说明文档;grub说明文档等;




// 固定屏幕信息,由硬件和驱动的能力决定的
struct fb_fix_screeninfo {
    char id[16];            /* identification string eg "TT Builtin" */
    unsigned long smem_start;    /* Start of frame buffer mem */
                    /* (physical address) */
    // 显存起始物理地址
    __u32 smem_len;            /* Length of frame buffer mem */
    // frame buffer 设备大小(显存)
    __u32 type;            /* see FB_TYPE_*        */
    __u32 type_aux;            /* Interleave for interleaved Planes */
    __u32 visual;            /* see FB_VISUAL_*        */
    __u16 xpanstep;            /* zero if no hardware panning  */
    __u16 ypanstep;            /* zero if no hardware panning  */
    __u16 ywrapstep;        /* zero if no hardware ywrap    */
    __u32 line_length;        /* length of a line in bytes    */
    // 行跨度
    unsigned long mmio_start;    /* Start of Memory Mapped I/O   */
                    /* (physical address) */
    __u32 mmio_len;            /* Length of Memory Mapped I/O  */
    __u32 accel;            /* Indicate to driver which    */
                    /*  specific chip/card we have    */
    __u16 reserved[3];        /* Reserved for future compatibility */
};
// 可变屏幕信息,由硬件当前的状态决定的
struct fb_var_screeninfo {
    __u32 xres;            /* visible resolution        */
    __u32 yres;
    // 屏幕上可见的分辨率
    __u32 xres_virtual;        /* virtual resolution        */
    __u32 yres_virtual;
    // 构建屏幕时视频卡读取屏幕的方式,当实际垂直分辨率为400时,虚拟垂直分辨率可以为800。这意味着800行数据被保存在屏幕内存区中。因为只有400行可以显示,决定从哪一行开始显示就是你的事情了,可以用*offset来实现,给yoffset为0时将显示[0-399]行,给yoffset为35时,将显示[35-434]行,这个非常有用,他可以用来作双缓冲,双缓冲就是你的程序分配了可以填充两个屏幕的内存。将offset设为0,将显示前400行(假设是标准的vga),同时可以秘密的在400行到799行构建另一个屏幕,当构建结束时,将yoffset设为400,新的屏幕将立刻显示出来。现在将开始在第一块内存区中构建下一个屏幕的数据,如此继续。这在动画中十分有用.还可以平滑滚动屏幕。
    __u32 xoffset;            /* offset from virtual to visible */
    __u32 yoffset;            /* resolution            */

    __u32 bits_per_pixel;        /* guess what            */
    //设为1,2,4,8,16,24或32来改变颜色深度(color depth)。不是所有的视频卡和驱动都支持全部颜色深度。
    __u32 grayscale;        /* != 0 Graylevels instead of colors */

    struct fb_bitfield red;        /* bitfield in fb mem if true color, */
    struct fb_bitfield green;    /* else only length is significant */
    struct fb_bitfield blue;
    struct fb_bitfield transp;    /* transparency            */   

    __u32 nonstd;            /* != 0 Non standard pixel format */

    __u32 activate;            /* see FB_ACTIVATE_*        */

    __u32 height;            /* height of picture in mm    */
    __u32 width;            /* width of picture in mm     */

    __u32 accel_flags;        /* (OBSOLETE) see fb_info.flags */

    /* Timing: All values in pixclocks, except pixclock (of course) */
    __u32 pixclock;            /* pixel clock in ps (pico seconds) */
    __u32 left_margin;        /* time from sync to picture    */
    __u32 right_margin;        /* time from picture to sync    */
    __u32 upper_margin;        /* time from sync to picture    */
    __u32 lower_margin;
    __u32 hsync_len;        /* length of horizontal sync    */
    __u32 vsync_len;        /* length of vertical sync    */
    __u32 sync;            /* see FB_SYNC_*        */
    __u32 vmode;            /* see FB_VMODE_*        */
    __u32 rotate;            /* angle we rotate counter clockwise */
    __u32 reserved[5];        /* Reserved for future compatibility */
};

------------------------------------------------------------------------------------
ubuntu 打开framebuffer的方法
1.  编辑 /etc/initramfs-tools/modules,在其中加入:
fbcon
vesafb
vga16fb

2. 编辑 /etc/modprobe.d/blacklist-framebuffer,注释掉以下两行:
blacklist vesafb
blacklist vga16fb

3. 修改/boot/grub/ 内的menu.lst ,找到类似如下几行代码,在kernel一行结尾加入fb分辨率参数:
例如:
title        Ubuntu 8.10, kernel 2.6.27-9-generic
uuid        328eed5f-0f89-41b8-b021-730ae3f167d1
kernel        /boot/vmlinuz-2.6.27-9-generic root=UUID=328eed5f-0f89-41b8-b021-730ae3f167d1 ro quiet splash vga=0x314
initrd        /boot/initrd.img-2.6.27-9-generic
quiet

注:vga=0×314 即为800*600 16位
终端的分辨率可以用fbset设置。
       |640x480 800x600 1024x768 1280x1024
       ----+-------------------------------------
       256 | 0x301  0x303   0x305    0x307
       32k | 0x310  0x313   0x316    0x319
       64k | 0x311  0x314   0x317    0x31A
       16M | 0x312  0x315   0x318    0x31B

       4. 刷新并重新启动
       sudo update-initramfs -u

       5.如何判断buffer是否启用
       首先确认内核是否支持 buffer ,查看 /proc/fb 文件是否存在,存在则说明支持,否则,说明不支持。其次查看 buffer 设备是否已激活,若 /dev/fb0 文件存在,则说明已经激活;否则说明没有激活。

       6.安装zhcon显示中文
       如果源里有该软件可以直接终端输入下面命令安装:
       $sudo apt-get install zhcon
       启动zhcon:
       zhcon --utf8 --drv=fb

       附:在控制台下播放电影
       mplayer abc.mov -vo fbdev
       视频输出用fbdev2也可以。

原创粉丝点击