[SeaBIOS] [PATCH] Boot up with a splash picture configurable by qemu

Wayne Xia xiawenc at linux.vnet.ibm.com
Thu Jun 16 11:00:04 CEST 2011


From: Wayne Xia <xiawenc at cn.ibm.com>

---
 Makefile         |    4 +-
 src/bmp.c        |   69 ++++++++++++++++++++++++++++++++++
 src/bmp.h        |   51 +++++++++++++++++++++++++
 src/boot.c       |   37 ++++++++++++++++--
 src/bootsplash.c |  109 +++++++++++++++++++++++++++++++++++++++++------------
 5 files changed, 239 insertions(+), 31 deletions(-)
 create mode 100644 src/bmp.c
 create mode 100644 src/bmp.h

diff --git a/Makefile b/Makefile
index d17f85a..214fe80 100644
--- a/Makefile
+++ b/Makefile
@@ -15,12 +15,12 @@ SRCBOTH=misc.c pmm.c stacks.c output.c util.c block.c floppy.c ata.c mouse.c \
         kbd.c pci.c serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \
         pnpbios.c pirtable.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \
         usb.c usb-uhci.c usb-ohci.c usb-ehci.c usb-hid.c usb-msc.c \
-        virtio-ring.c virtio-pci.c virtio-blk.c apm.c ahci.c
+        virtio-ring.c virtio-pci.c virtio-blk.c apm.c ahci.c bmp.c
 SRC16=$(SRCBOTH) system.c disk.c font.c
 SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \
       acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \
       lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c dev-i440fx.c \
-      pci_region.c
+      pci_region.c bmp.c
 SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c
 
 cc-option = $(shell if test -z "`$(1) $(2) -S -o /dev/null -xc \
diff --git a/src/bmp.c b/src/bmp.c
new file mode 100644
index 0000000..b2a2333
--- /dev/null
+++ b/src/bmp.c
@@ -0,0 +1,69 @@
+//BMP data process and raw graphic data process functions
+#include "bmp.h"
+
+void bmp_data_format_proc_24bpp(u8* src, u8* dest, int width,int height,int bytes_per_line_src, int bytes_per_line_dest ,u8 switch_flag)
+{
+	int cy=height;
+	u8 *pd,*ps,*pd_valid,*ps_lastline;
+	u8 t;
+	u8 rgb_switch_flag = switch_flag & SWITCH_RGB;
+	u8 line_switch_flag = switch_flag & SWITCH_LINE;
+	while (cy>0)
+	{
+		ps=bytes_per_line_src*cy+src-1;
+		if (line_switch_flag) {
+			pd=bytes_per_line_dest*(height-cy+1)+dest-1;
+		}
+		else {
+			pd=bytes_per_line_dest*cy+dest-1;
+		}
+		ps_lastline=ps-bytes_per_line_src;
+		pd_valid=pd-(bytes_per_line_dest-bytes_per_line_src);
+		while (pd>pd_valid)
+		{
+			*pd=0;
+			pd--;
+		}
+		while (ps>ps_lastline)
+		{
+			if (rgb_switch_flag)
+			{
+				t=*ps;
+				*ps=*(ps-2);
+				*(ps-2)=t;
+			}
+			*(pd--)=*(ps--);
+			*(pd--)=*(ps--);
+			*(pd--)=*(ps--);
+		}
+		cy--;
+	}
+}
+
+int bmp_get_info(u8* data, int data_size, int* width_p, int* height_p, int* bpp_p, int* offset_p)
+{
+	if (data_size<54)
+	{
+		return 1;
+	}
+
+	u16 bmp_filehead =bmp_load2byte(data+0);
+	if (bmp_filehead != 0x4d42)
+	{
+		return 2;
+	}
+	u32 bmp_recordsize =bmp_load4byte(data+2);
+	if (bmp_recordsize != data_size)
+	{
+		return 3;
+	}
+	u32 bmp_dataoffset =bmp_load4byte(data+10);
+	u32 bmp_width =bmp_load4byte(data+18);
+	u32 bmp_height =bmp_load4byte(data+22);
+	u32 bmp_bpp =bmp_load2byte(data+28);
+	*width_p =bmp_width;
+	*height_p =bmp_height;
+	*bpp_p =bmp_bpp;
+	*offset_p =bmp_dataoffset;
+	return 0;
+}
diff --git a/src/bmp.h b/src/bmp.h
new file mode 100644
index 0000000..60045f9
--- /dev/null
+++ b/src/bmp.h
@@ -0,0 +1,51 @@
+#ifndef BMP_H
+#define BMP_H
+#include "types.h"
+
+#define WIDTHBYTES(bits) (((bits)+31)/32*4)
+
+typedef u8 BYTE;
+typedef u32 BYTE4;
+
+
+typedef struct tagBITMAPFILEHEADER {
+BYTE bfType[2];
+BYTE bfSize[4];
+BYTE bfReserved1[2];
+BYTE bfReserved2[2];
+BYTE bfOffBits[4];
+} BITMAPFILEHEADER,tagBITMAPFILEHEADER;
+
+typedef struct tagBITMAPINFOHEADER{
+BYTE biSize[4];
+BYTE biWidth[4];
+BYTE biHeight[4];
+BYTE biPlanes[2];
+BYTE biBitCount[2];
+BYTE biCompression[4];
+BYTE biSizeImage[4];
+BYTE biXPelsPerMeter[4];
+BYTE biYPelsPerMeter[4];
+BYTE biClrUsed[4];
+BYTE biClrImportant[4];
+} BITMAPINFOHEADER,tagBITMAPINFOHEADER;
+
+typedef struct tagRGBQUAD {
+BYTE rgbBlue;
+BYTE rgbGreen;
+BYTE rgbRed;
+BYTE rgbReserved;
+} RGBQUAD,tagRGBQUAD;
+
+#define bmp_load4byte(addr) (addr)[0]+((addr)[1]<<8)+((addr)[2]<<16)+((addr)[3]<<24)
+#define bmp_load2byte(addr) (addr)[0]+((addr)[1]<<8)
+
+#define SWITCH_RGB 0x01
+#define SWITCH_LINE 0x02
+
+//src can be equal to dest, if do not need to switch the lines from bottom to top
+//bytes_per_line_src must be less or eqaul than bytes_per_line_dest
+void bmp_data_format_proc_24bpp(u8* src, u8* dest, int width,int height,int bytes_per_line_src, int bytes_per_line_dest ,u8 switch_flag);
+
+int bmp_get_info(u8* data, int data_size, int* width_p, int* height_p, int* bpp_p, int* offset_p);
+#endif
diff --git a/src/boot.c b/src/boot.c
index 9a67916..676c522 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -372,16 +372,45 @@ boot_add_cbfs(void *data, const char *desc, int prio)
 static void
 interactive_bootmenu(void)
 {
-    if (! CONFIG_BOOTMENU || ! qemu_cfg_show_boot_menu())
-        return;
+    int filecfg_size;
+    u8 *filecfg_p = romfile_loadfile("bootsplash.cfg", &filecfg_size);
+    u8 showflag_normal;
+    u16 splash_time;
+
+    if (filecfg_p != NULL && filecfg_size>=4) {
+	showflag_normal =*filecfg_p;
+	splash_time =*(filecfg_p+2)+(*(filecfg_p+3)<<8); //little endian
+	free (filecfg_p);
+    }
+    else {
+        showflag_normal =0;
+	splash_time =CONFIG_BOOTMENU_WAIT;
+    }
+
+    if (! qemu_cfg_show_boot_menu()) { //the user do not want to show the menu, so normally bootup
+        if (showflag_normal) {
+		while (get_keystroke(0) >= 0)
+		;
+		enable_bootsplash();
+		get_keystroke(splash_time);
+		disable_bootsplash();
+
+	}
+	return;
+    }
+    else {
+	if (! CONFIG_BOOTMENU) //user want to show menu, check the if the bios config allow it
+		return;
+    }
+
 
     while (get_keystroke(0) >= 0)
-        ;
+    ;
 
     printf("Press F12 for boot menu.\n\n");
 
     enable_bootsplash();
-    int scan_code = get_keystroke(CONFIG_BOOTMENU_WAIT);
+    int scan_code = get_keystroke(splash_time);
     disable_bootsplash();
     if (scan_code != 0x86)
         /* not F12 */
diff --git a/src/bootsplash.c b/src/bootsplash.c
index cf1a603..0adef01 100644
--- a/src/bootsplash.c
+++ b/src/bootsplash.c
@@ -12,7 +12,7 @@
 #include "jpeg.h" // splash
 #include "biosvar.h" // SET_EBDA
 #include "paravirt.h" // romfile_find
-
+#include "bmp.h"
 
 /****************************************************************
  * VESA structures
@@ -109,7 +109,7 @@ enable_vga_console(void)
 
 static int
 find_videomode(struct vesa_info *vesa_info, struct vesa_mode_info *mode_info
-               , int width, int height)
+               , int width, int height, int bpp_req)
 {
     dprintf(3, "Finding vesa mode with dimensions %d/%d\n", width, height);
     u16 *videomodes = SEGOFF_TO_FLATPTR(vesa_info->video_mode_ptr);
@@ -135,8 +135,14 @@ find_videomode(struct vesa_info *vesa_info, struct vesa_mode_info *mode_info
             || mode_info->y_resolution != height)
             continue;
         u8 depth = mode_info->bits_per_pixel;
-        if (depth != 16 && depth != 24 && depth != 32)
-            continue;
+	if (bpp_req == 0) {
+	    if (depth != 16 && depth != 24 && depth != 32)
+	    continue;
+	}
+	else {
+            if (depth != bpp_req)
+	    continue;
+	}
         return videomode;
     }
 }
@@ -149,12 +155,20 @@ enable_bootsplash(void)
     if (!CONFIG_BOOTSPLASH)
         return;
     dprintf(3, "Checking for bootsplash\n");
+    u8 type=0;//0 means jpg, 1 means bmp, default is 0=jpg
     int filesize;
     u8 *filedata = romfile_loadfile("bootsplash.jpg", &filesize);
-    if (!filedata)
-        return;
+    if (!filedata) {
+	filedata = romfile_loadfile("bootsplash.bmp", &filesize);
+	if (!filedata) {
+		return;
+	}
+	type =1;
+    }
+    //dprintf(3, "start showing bootsplash\n");
 
-    u8 *picture = NULL;
+    u8 *picture = NULL; //data buff used to be flushded to the video buff
+    u8 *picture_post = NULL; //another buff, used to do some post process, such as line sequence reverse
     struct vesa_info *vesa_info = malloc_tmplow(sizeof(*vesa_info));
     struct vesa_mode_info *mode_info = malloc_tmplow(sizeof(*mode_info));
     struct jpeg_decdata *jpeg = jpeg_alloc();
@@ -184,20 +198,43 @@ enable_bootsplash(void)
             vesa_info->vesa_version>>8, vesa_info->vesa_version&0xff,
             vendor, product);
 
-    // Parse jpeg and get image size.
-    dprintf(5, "Decoding bootsplash.jpg\n");
-    int ret = jpeg_decode(jpeg, filedata);
-    if (ret) {
-        dprintf(1, "jpeg_decode failed with return code %d...\n", ret);
-        goto done;
+     int ret, width, height;
+     int bpp_require=0;
+     int data_offset=0;
+     u8 post_flag=0;
+     if (type == 0) {
+	// Parse jpeg and get image size.
+	dprintf(5, "Decoding bootsplash.jpg\n");
+	ret = jpeg_decode(jpeg, filedata);
+	if (ret) {
+		dprintf(1, "jpeg_decode failed with return code %d...\n", ret);
+		goto done;
+	}
+	jpeg_get_size(jpeg, &width, &height);
+	bpp_require =24;//for better vision effect, although there are 16 bpp mode exist
+    }
+    else {
+	// Parse jpeg and get image size.
+	dprintf(5, "retrieve information of bootsplash.bmp file\n");
+	int bpp_src;
+	ret=bmp_get_info(filedata, filesize, &width, &height, &bpp_src, &data_offset);
+	if (ret) {
+		dprintf(1, "retrieve information from bmp file failed with return code %d...\n", ret);
+		goto done;
+	}
+	if (bpp_src != 24) {
+		dprintf(1, "only support 24bpp color, now the bmp file's bpp is %d...\n", bpp_src);
+		goto done;
+	}
+	bpp_require =24;
     }
-    int width, height;
-    jpeg_get_size(jpeg, &width, &height);
 
     // Try to find a graphics mode with the corresponding dimensions.
-    int videomode = find_videomode(vesa_info, mode_info, width, height);
-    if (videomode < 0)
-        goto done;
+    int videomode = find_videomode(vesa_info, mode_info, width, height, bpp_require);
+    if (videomode < 0) {
+        dprintf(1, "failed to find a videomode with %dx%d %dbpp (0 means any).\n", width, height, bpp_require);
+	goto done;
+    }
     void *framebuffer = mode_info->phys_base_ptr;
     int depth = mode_info->bits_per_pixel;
     dprintf(3, "mode: %04x\n", videomode);
@@ -206,17 +243,39 @@ enable_bootsplash(void)
     dprintf(3, "bits per pixel: %d\n", depth);
 
     // Allocate space for image and decompress it.
-    int imagesize = width * height * (depth / 8);
+    int imagesize = height * mode_info->bytes_per_scanline;
     picture = malloc_tmphigh(imagesize);
     if (!picture) {
         warn_noalloc();
         goto done;
     }
-    dprintf(5, "Decompressing bootsplash.jpg\n");
-    ret = jpeg_show(jpeg, picture, width, height, depth);
-    if (ret) {
-        dprintf(1, "jpeg_show failed with return code %d...\n", ret);
-        goto done;
+
+    if (type == 0) {
+	dprintf(5, "Decompressing bootsplash.data\n");
+	ret = jpeg_show(jpeg, picture, width, height, depth);
+	if (ret) {
+		dprintf(1, "jpeg_show failed with return code %d...\n", ret);
+		goto done;
+	}
+	picture_post=picture;
+	post_flag |= SWITCH_RGB;
+	if ( depth==24 && mode_info->bytes_per_scanline >= width * 24 /8){
+		bmp_data_format_proc_24bpp(picture_post, picture, width, height, width * 24 /8, mode_info->bytes_per_scanline, post_flag);
+	}
+    }
+    else {
+	picture_post = malloc_tmphigh(imagesize);
+	if (!picture_post) {
+		warn_noalloc();
+		goto done;
+	}
+
+	memcpy(picture_post, filedata+data_offset,filesize-data_offset);
+	post_flag |= SWITCH_LINE;
+	if ( depth==24 && mode_info->bytes_per_scanline >= width * 24 /8){
+		bmp_data_format_proc_24bpp(picture_post, picture, width, height, width * 24 /8, mode_info->bytes_per_scanline, post_flag);
+	}
+	free(picture_post);
     }
 
     /* Switch to graphics mode */
@@ -231,7 +290,7 @@ enable_bootsplash(void)
     }
 
     /* Show the picture */
-    dprintf(5, "Showing bootsplash.jpg\n");
+    dprintf(5, "Showing bootsplash picture\n");
     iomemcpy(framebuffer, picture, imagesize);
     dprintf(5, "Bootsplash copy complete\n");
     BootsplashActive = 1;
-- 
1.7.1




More information about the SeaBIOS mailing list