kexec and framebuffer
Hello,
Kexec skips video initialization code and because of that framebuffer does not work with relocated kernels.
Like Eric W. Biederman pointed out in
http://www.ussg.iu.edu/hypermail/linux/kernel/0508.0/1674.html , screen_info structure from include/linux/tty.h must be passed along to maintain current video mode.
I made some testing and it's enough to dump screen_info structure from running kernel and overwrite this info in kexec' x86-linux-setup.c.
I am wondering what would be the preferred method to extract screen_info from running kernel. Should this be made available from sysfs or maybe a new system call be created?
Signature · 1 line
Kalev Lember
Hi,
Quoted 3 lines
I am wondering what would be the preferred method to extract
screen_infofrom running kernel. Should this be made available from sysfs or maybe a new system call be created?
Simply ask /dev/fb0?
Patch for kexec tools attached.
cheers,
Gerd
Signature · 2 lines
Gerd Hoffmann <[email protected]> http://www.suse.de/~kraxel/julika-dora.jpeg
kexec/arch/i386/x86-linux-setup.c +53 -0
@@ -24,6 +24,8 @@#include <sys/stat.h> #include <sys/mman.h> #include <fcntl.h> +#include <sys/ioctl.h> +#include <linux/fb.h> #include <unistd.h> #include <x86/x86-linux.h> #include "../../kexec.h"
@@ -94,6 +96,56 @@ void setup_linux_bootloader_parameters( cmdline_ptr[cmdline_len -1 ] ='\0' ; } +int setup_linux_vesafb (struct x86_linux_param_header *real_mode) +{ +struct fb_fix_screeninfo fix; +struct fb_var_screeninfo var; +int fd; + + fd =open ("/dev/fb0" ,O_RDONLY ); +if (-1 == fd) +return -1 ; + +if (-1 ==ioctl (fd,FBIOGET_FSCREENINFO , &fix)) + goto out; +if (-1 ==ioctl (fd,FBIOGET_VSCREENINFO , &var)) + goto out; +if (0 !=strcmp (fix.id,"vesafb" )) + goto out; +close (fd); + + real_mode->orig_video_isVGA =0x23 /* VIDEO_TYPE_VLFB */ ; + real_mode->lfb_width = var.xres; + real_mode->lfb_height = var.yres; + real_mode->lfb_depth = var.bits_per_pixel; + real_mode->lfb_base = fix.smem_start; + real_mode->lfb_linelength = fix.line_length; + real_mode->vesapm_seg =0 ; + +/* fixme: better get size from /proc/iomem */ + real_mode->lfb_size = (fix.smem_len +65535 ) /65536 ; + real_mode->pages = (fix.smem_len +4095 ) /4096 ; + +if (var.bits_per_pixel >8 ) { + real_mode->red_pos = var.red.offset; + real_mode->red_size = var.red.length; + real_mode->green_pos = var.green.offset; + real_mode->green_size = var.green.length; + real_mode->blue_pos = var.blue.offset; + real_mode->blue_size = var.blue.length; + real_mode->rsvd_pos = var.transp.offset; + real_mode->rsvd_size = var.transp.length; + } +fprintf (stderr,"%s: %dx%dx%d @ %lx +%lx\n" , __FUNCTION__, + var.xres, var.yres, var.bits_per_pixel, + fix.smem_start, fix.smem_len); +return 0 ; + + out: +close (fd); +return -1 ; +} +void setup_linux_system_parameters (struct x86_linux_param_header *real_mode,unsigned long kexec_flags) {
@@ -111,6 +163,7 @@ void setup_linux_system_parameters(struc real_mode->orig_video_ega_bx =0 ; real_mode->orig_video_isVGA =1 ; real_mode->orig_video_points =16 ; +setup_linux_vesafb (real_mode);/* Fill in the memsize later */ real_mode->ext_mem_k =0 ;
Quoted 8 lines · Gerd Hoffmann
Quoted 4 lines
I am wondering what would be the preferred method to extract
screen_infofrom running kernel. Should this be made available from sysfs or maybe a new system call be created?Simply ask
/dev/fb0?
Patch for kexec tools attached.
Thank you, this was really helpful.
kexec/arch/i386/x86-linux-setup.c void setup_linux_bootloader_parameters( · line 114
Quoted 2 lines
kexec/arch/i386/x86-linux-setup.c +2
-0+if (0 !=strcmp (fix.id,"vesafb" )) + goto out;
I think this check should be removed so that other framebuffer drivers besides vesafb would also work. Additionally the fix.id is "VESA VGA", not "vesafb".
Could you please submit this for inclusion in kexec-tools or do you want me to do it?
Signature · 1 line
Kalev Lember
Quoted 5 lines · Kalev Lember
Quoted 4 lines · Gerd Hoffmann
Quoted 4 lines
I am wondering what would be the preferred method to extract
screen_infofrom running kernel. Should this be made available from sysfs or maybe a new system call be created?
Quoted 8 lines
Quoted 3 lines
Simply ask
/dev/fb0?
Patch for kexec tools attached.Thank you, this was really helpful.
kexec/arch/i386/x86-linux-setup.c void setup_linux_bootloader_parameters( · line 114
Quoted 2 lines
kexec/arch/i386/x86-linux-setup.c +2
-0+if (0 !=strcmp (fix.id,"vesafb" )) + goto out;I think this check should be removed so that other framebuffer drivers besides vesafb would also work.
I think having the check is correct, only vesafb relies totally on screen_info. If you remove the check, you can get the wrong information from other framebuffer drivers.
kexec/arch/i386/x86-linux-setup.c void setup_linux_bootloader_parameters( · line 127
Quoted 3 lines
kexec/arch/i386/x86-linux-setup.c +3
-0+/* fixme: better get size from /proc/iomem */ + real_mode->lfb_size = (fix.smem_len +65535 ) /65536 ; + real_mode->pages = (fix.smem_len +4095 ) /4096 ;
Note that fix.smem_len is the size of the remapped memory which can be smaller than the actual framebuffer length. But there's a fixme comment there so you probably know about this.
Quoted 2 lines
Additionally the fix.id is "VESA VGA",
not "vesafb".
Yes.
Tony
Quoted 10 lines · Antonino A. Daplas
Quoted 5 lines · Kalev Lember
Thank you, this was really helpful.
kexec/arch/i386/x86-linux-setup.c void setup_linux_bootloader_parameters( · line 114
Quoted 2 lines
kexec/arch/i386/x86-linux-setup.c +2
-0+if (0 !=strcmp (fix.id,"vesafb" )) + goto out;I think this check should be removed so that other framebuffer drivers besides vesafb would also work.
I think having the check is correct, only vesafb relies totally on
screen_info. If you remove the check, you can get the wrong information from other framebuffer drivers.
Exactly.
Quoted 7 lines
kexec/arch/i386/x86-linux-setup.c void setup_linux_bootloader_parameters( · line 127
Quoted 3 lines
kexec/arch/i386/x86-linux-setup.c +3
-0+/* fixme: better get size from /proc/iomem */ + real_mode->lfb_size = (fix.smem_len +65535 ) /65536 ; + real_mode->pages = (fix.smem_len +4095 ) /4096 ;Note that fix.smem_len is the size of the remapped memory which can be smaller than the actual framebuffer length. But there's a fixme comment there so you probably know about this.
Yep, that is the reason for the fixme. kexec-tools already parse /proc/iomem, but keep the info private in some other source file, so I decided to solve it this way for the first cut. Shouln't be that hard to fix it up though.
I've mailed it some time ago to the maintainer, no feedback. Feel free to polish the patch a bit and try submitting it again ...
cheers,
Gerd
Signature · 2 lines
Gerd Hoffmann <[email protected]> http://www.suse.de/~kraxel/julika-dora.jpeg