[Qemu-devel] [PATCH v3] showing a splash picture when start

2011-06-27 Thread Wayne Xia
Made an option to let qemu pass a picture to bios, let the bios show it as a 
logo. By default it is off, enable it as following
-boot splash_time=N,splash_filename=P
N have a max value of 0x, unit is ms. P is the a file name or a absolute 
path.
Currently a trial version of sea-bios could be used to test it.

Signed-off-by: Wayne Xia xiaw...@linux.vnet.ibm.com
---
 hw/fw_cfg.c   |  141 -
 qemu-config.c |   27 +++
 sysemu.h  |3 +
 vl.c  |   17 +++-
 4 files changed, 186 insertions(+), 2 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index 85c8c3c..b22ff0a 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -26,6 +26,7 @@
 #include isa.h
 #include fw_cfg.h
 #include sysbus.h
+#include qemu-error.h
 
 /* debug firmware config */
 //#define DEBUG_FW_CFG
@@ -56,6 +57,144 @@ struct FWCfgState {
 Notifier machine_ready;
 };
 
+#define JPG_FILE 0
+#define BMP_FILE 1
+
+static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
+{
+FILE *fp = NULL;
+int fop_ret;
+int file_size;
+int file_type = -1;
+unsigned char buf[2] = {0, 0};
+unsigned int filehead_value = 0;
+int bmp_bpp;
+
+fp = fopen(filename, rb);
+if (fp == NULL) {
+error_report(failed to open file '%s'., filename);
+return fp;
+}
+/* check file size */
+fseek(fp, 0L, SEEK_END);
+file_size = ftell(fp);
+if (file_size  2) {
+error_report(file size is less than 2 bytes '%s'., filename);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check magic ID */
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+filehead_value = (buf[0] + (buf[1]  8))  0x;
+if (filehead_value == 0xd8ff) {
+file_type = JPG_FILE;
+} else {
+if (filehead_value == 0x4d42) {
+file_type = BMP_FILE;
+}
+}
+if (file_type  0) {
+error_report('%s' not jpg/bmp file,head:0x%x.,
+ filename, filehead_value);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+/* check BMP bpp */
+if (file_type == BMP_FILE) {
+fseek(fp, 28, SEEK_SET);
+fop_ret = fread(buf, 1, 2, fp);
+bmp_bpp = (buf[0] + (buf[1]  8))  0x;
+if (bmp_bpp != 24) {
+error_report(only 24bpp bmp file is supported.);
+fclose(fp);
+fp = NULL;
+return fp;
+}
+}
+/* return values */
+*file_sizep = file_size;
+*file_typep = file_type;
+return fp;
+}
+
+static void fw_cfg_bootsplash(FWCfgState *s)
+{
+int boot_splash_time = 0; /* default is off */
+const char *boot_splash_filename = bootsplash.bmp;
+char *p;
+char *filename;
+FILE *fp;
+int fop_ret;
+int file_size;
+int file_type = -1;
+const char *temp;
+
+/* get user configuration */
+QemuOptsList *plist = qemu_find_opts(bootsplash);
+QemuOpts *opts = QTAILQ_FIRST(plist-head);
+if (opts != NULL) {
+temp = qemu_opt_get(opts, splash_time);
+if (temp != NULL) {
+p = (char *)temp;
+boot_splash_time = strtol(p, (char **)p, 10);
+}
+temp = qemu_opt_get(opts, splash_filename);
+if (temp != NULL) {
+boot_splash_filename = temp;
+}
+}
+
+/* check user configuration */
+if (boot_splash_time = 0) {
+/* do nothing, directly return */
+return;
+}
+if (boot_splash_time  0x) {
+error_report(splash time is big than 65535, force it to 65535.);
+boot_splash_time = 65535;
+}
+filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, boot_splash_filename);
+if (filename == NULL) {
+error_report(failed to find file '%s'., boot_splash_filename);
+return;
+}
+
+/* probing the file */
+fp = probe_splashfile(filename, file_size, file_type);
+if (fp == NULL) {
+qemu_free(filename);
+return;
+}
+
+/* loading file data */
+if (boot_splash_filedata != NULL) {
+qemu_free(boot_splash_filedata);
+}
+boot_splash_filedata = qemu_malloc(file_size);
+boot_splash_filedata_size = file_size;
+fseek(fp, 0L, SEEK_SET);
+fop_ret = fread(boot_splash_filedata, 1, file_size, fp);
+fclose(fp);
+
+/* insert data */
+if (file_type == JPG_FILE) {
+fw_cfg_add_file(s, bootsplash.jpg,
+boot_splash_filedata, boot_splash_filedata_size);
+} else {
+fw_cfg_add_file(s, bootsplash.bmp,
+boot_splash_filedata, boot_splash_filedata_size);
+}
+/* use little endian format */
+qemu_extra_params_fw[0] = (uint8_t)(boot_splash_time  0xff);
+qemu_extra_params_fw[1] = (uint8_t)((boot_splash_time  8)  0xff);
+fw_cfg_add_file(s, qemu_extra_params_fw.cfg, qemu_extra_params_fw, 4);
+qemu_free(filename);
+}
+
+
 static void 

Re: [Qemu-devel] [PATCH v3] showing a splash picture when start

2011-06-27 Thread Jan Kiszka
On 2011-06-27 08:53, Wayne Xia wrote:
 Made an option to let qemu pass a picture to bios, let the bios show it as a 
 logo. By default it is off, enable it as following

That's better. :)

 -boot splash_time=N,splash_filename=P
 N have a max value of 0x, unit is ms. P is the a file name or a absolute 
 path.
 Currently a trial version of sea-bios could be used to test it.
 
 Signed-off-by: Wayne Xia xiaw...@linux.vnet.ibm.com
 ---

...

 index c63741c..6f93b10 100644
 --- a/qemu-config.c
 +++ b/qemu-config.c
 @@ -469,6 +469,32 @@ static QemuOptsList qemu_machine_opts = {
  },
  };
  
 +QemuOptsList qemu_bootsplash_opts = {
 +.name = bootsplash,
 +.head = QTAILQ_HEAD_INITIALIZER(qemu_bootsplash_opts.head),
 +.desc = {
 +/* the three names below are not used now */
 +{
 +.name = order,
 +.type = QEMU_OPT_STRING,
 +}, {
 +.name = once,
 +.type = QEMU_OPT_STRING,
 +}, {
 +.name = menu,
 +.type = QEMU_OPT_STRING,
 +/* following are really used */
 +}, {
 +.name = splash_time,
 +.type = QEMU_OPT_STRING,
 +}, {
 +.name = splash_filename,
 +.type = QEMU_OPT_STRING,
 +},
 +{ /*End of list */ }
 +},
 +};
 +

This is describing the boot option that also controls the splash.
Naming should reflect this.

Jan



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH v3] showing a splash picture when start

2011-06-27 Thread Wayne Xia

On 2011-06-27 08:53, Wayne Xia wrote:

Made an option to let qemu pass a picture to bios, let the bios show it as a
logo. By default it is off, enable it as following


That's better. :)


 -boot splash_time=N,splash_filename=P
N have a max value of 0x, unit is ms. P is the a file name or a absolute
path.
Currently a trial version of sea-bios could be used to test it.

Signed-off-by: Wayne Xiaxiaw...@linux.vnet.ibm.com
---


...

I think making the splash time configurable would be better, maybe
we could pass the configuration like following:
-boot splash=P,splash_time=N
only if splash=P was specified, the splash shows. In this
situation, if splash_time was not specified, then show it with a
predefined period, such as 2.5 seconds.



index c63741c..6f93b10 100644
--- a/qemu-config.c
+++ b/qemu-config.c
@@ -469,6 +469,32 @@ static QemuOptsList qemu_machine_opts = {
  },
  };

+QemuOptsList qemu_bootsplash_opts = {
+.name = bootsplash,
+.head = QTAILQ_HEAD_INITIALIZER(qemu_bootsplash_opts.head),
+.desc = {
+/* the three names below are not used now */
+{
+.name = order,
+.type = QEMU_OPT_STRING,
+}, {
+.name = once,
+.type = QEMU_OPT_STRING,
+}, {
+.name = menu,
+.type = QEMU_OPT_STRING,
+/* following are really used */
+}, {
+.name = splash_time,
+.type = QEMU_OPT_STRING,
+}, {
+.name = splash_filename,
+.type = QEMU_OPT_STRING,
+},
+{ /*End of list */ }
+},
+};
+


This is describing the boot option that also controls the splash.
Naming should reflect this.

yeah, agree with you.


Jan




--
Best Regards

Wayne Xia
mail:xiaw...@linux.vnet.ibm.com
tel:86-010-82450803



Re: [Qemu-devel] [PATCH v3] showing a splash picture when start

2011-06-27 Thread Stefan Hajnoczi
On Mon, Jun 27, 2011 at 7:53 AM, Wayne Xia xiaw...@linux.vnet.ibm.com wrote:
 Made an option to let qemu pass a picture to bios, let the bios show it as a
 logo. By default it is off, enable it as following
    -boot splash_time=N,splash_filename=P

It's a shame qemu-config.c has some options that use this_syntax and
some that use this-syntax.  There are more that use hyphen ('-') so I
think splash-time and splash-filename would be better.  Otherwise we
head closer to a 50/50 split of confusion when it comes to '-' vs '_'
syntax :).

Stefan