【原创】配置UBUTNU启用帧缓存
0赞如何配置UBUTNU启用帧缓存,是一个很好的应用实例,今天我写写这个问题
设置开机进入文本模式
(1)、修改启动菜单配置文件
# vi /etc/default/grub
修改
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
为:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash text vga=0x311"
注释:
这里text表示进入文本模式,vga=0x311表示使用Framebuffer显示驱动,
0x311是指示色深和分辨率的参数
| 640x480 800x600 1024x768 1280x1024
------+-----------------------------------------------------
256 | 0x301 0x303 0x305 0x307
32k | 0x310 0x313 0x316 0x319
16bpp | 0x311 0x314 0x317 0x31A
16M | 0x312 0x315 0x318 0x31B
(2)、更新启动菜单
$ sudo update-grub
写入到/boot/grub/grub.cfg
(3)、修改initramfs
$ sudo gedit /etc/initramfs-tools/modules
添加:
vesafb
(4)、
$ sudo gedit /etc/modprobe.d/blacklist-framebuffer.conf
用#注释以下行
# blacklist vesafb
(5)、更新initramfs
$ sudo update-initramfs -u
(生成新的initrd)
(6)、
然后重启机器,即可进入Framebuffer
如果要切换回X11,可以输入:
$ startx
(7)、图形界面切换到字符界面
A、atl+ctrl+shift+F1
B、ctrl+c
以下是帧缓存的测试程序。
#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 (0 > fbfd) {
printf("Error: cannot open framebuffer device.\n");
exit(1);
}
printf("The framebuffer device was opened successfully.\n");
// Get variable screen information
if (0 > 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);
// Figure out the size of the screen in bytes
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
// Map the device to memory
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED,
fbfd, 0);
if ( fbp == MAP_FAILED) {
printf("Error: failed to map framebuffer device to memory.\n");
exit(4);
}
printf("The framebuffer device was mapped to memory successfully.\n");
unsigned short *lcd = (unsigned short *)fbp;
// Figure out where in memory to put the pixel
for (int x = 0; x < vinfo.xres; x++)
{
for (int y = 0; y < vinfo.yres; y++)
{
*lcd++ = (0x1F << 11);
//*lcd++ = (0x3F << 5);
//*lcd++ = (0x1F);
}
}
munmap(fbp, screensize);
printf("The framebuffer device was munmapped to memory successfully.\n");
close(fbfd);
printf("The framebuffer device was closed successfully.\n");
return 0;
}
看到成功了吗,大家可以试一下。