[SeaBIOS] [PATCH 4/9] Read bootorder file into memory.
Kevin O'Connor
kevin at koconnor.net
Fri Dec 24 17:21:36 CET 2010
On Thu, Dec 23, 2010 at 11:29:38AM +0200, Gleb Natapov wrote:
> Read bootorder file, parse it and put it into array for easy
> consumption.
>
> Signed-off-by: Gleb Natapov <gleb at redhat.com>
I applied this. I'd like to apply two patches on top of it as a
cleanup.
I've also changed the code so that the bootorder file doesn't need to
be null-terminated (seabios will tack on a trailing null itself).
-Kevin
-------------- next part --------------
commit f9b0930ab9efe5f340edbb61f3a5269dbff8c663
Author: Kevin O'Connor <kevin at koconnor.net>
Date: Fri Dec 24 11:15:26 2010 -0500
Add romfile_loadfile() helper function.
Add function to find, malloc, and copy a romfile. Use it in the
bootsplash and bootorder code.
diff --git a/src/boot.c b/src/boot.c
index 9c37023..4fb73ac 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -68,24 +68,10 @@ boot_setup(void)
IPL.checkfloppysig = 1;
}
- u32 file = romfile_find("bootorder");
- if (!file)
+ char *f = romfile_loadfile("bootorder", NULL);
+ if (!f)
return;
- int filesize = romfile_size(file);
- dprintf(3, "bootorder file found (len %d)\n", filesize);
-
- if (filesize == 0)
- return;
-
- char *f = malloc_tmphigh(filesize);
-
- if (!f) {
- warn_noalloc();
- return;
- }
-
- romfile_copy(file, f, filesize);
int i;
IPL.fw_bootorder_count = 1;
while(f[i]) {
diff --git a/src/bootsplash.c b/src/bootsplash.c
index 8f42dfd..cf1a603 100644
--- a/src/bootsplash.c
+++ b/src/bootsplash.c
@@ -149,17 +149,16 @@ enable_bootsplash(void)
if (!CONFIG_BOOTSPLASH)
return;
dprintf(3, "Checking for bootsplash\n");
- u32 file = romfile_find("bootsplash.jpg");
- if (!file)
+ int filesize;
+ u8 *filedata = romfile_loadfile("bootsplash.jpg", &filesize);
+ if (!filedata)
return;
- int filesize = romfile_size(file);
u8 *picture = NULL;
- u8 *filedata = malloc_tmphigh(filesize);
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();
- if (!filedata || !jpeg || !vesa_info || !mode_info) {
+ if (!jpeg || !vesa_info || !mode_info) {
warn_noalloc();
goto done;
}
@@ -186,8 +185,6 @@ enable_bootsplash(void)
vendor, product);
// Parse jpeg and get image size.
- dprintf(5, "Copying bootsplash.jpg\n");
- romfile_copy(file, filedata, filesize);
dprintf(5, "Decoding bootsplash.jpg\n");
int ret = jpeg_decode(jpeg, filedata);
if (ret) {
diff --git a/src/paravirt.c b/src/paravirt.c
index 308c809..74d3743 100644
--- a/src/paravirt.c
+++ b/src/paravirt.c
@@ -365,3 +365,30 @@ int qemu_cfg_read_file(u32 select, void *dst, u32 maxlen)
qemu_cfg_read_entry(dst, select, len);
return len;
}
+
+// Helper function to find, malloc_tmphigh, and copy a romfile. This
+// function adds a trailing zero to the malloc'd copy.
+void *
+romfile_loadfile(const char *name, int *psize)
+{
+ u32 file = romfile_find(name);
+ if (!file)
+ return NULL;
+
+ int filesize = romfile_size(file);
+ if (!filesize)
+ return NULL;
+
+ char *data = malloc_tmphigh(filesize+1);
+ if (!data) {
+ warn_noalloc();
+ return NULL;
+ }
+
+ dprintf(5, "Copying romfile '%s' (len %d)\n", name, filesize);
+ romfile_copy(file, data, filesize);
+ if (psize)
+ *psize = filesize;
+ data[filesize] = '\0';
+ return data;
+}
diff --git a/src/paravirt.h b/src/paravirt.h
index 99c473b..7bf34b1 100644
--- a/src/paravirt.h
+++ b/src/paravirt.h
@@ -100,6 +100,7 @@ static inline const char* romfile_name(u32 fileid) {
return cbfs_filename((void*)fileid);
return qemu_cfg_name_file(fileid);
}
+void *romfile_loadfile(const char *name, int *psize);
u32 qemu_cfg_e820_entries(void);
void* qemu_cfg_e820_load_next(void *addr);
-------------- next part --------------
commit d1a1746c5c8610041a706aa8f4819cea794dd5af
Author: Kevin O'Connor <kevin at koconnor.net>
Date: Fri Dec 24 11:17:03 2010 -0500
Breakup boot_setup() bootorder code into its own function.
diff --git a/src/boot.c b/src/boot.c
index 4fb73ac..5137345 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -18,9 +18,44 @@ struct ipl_s IPL;
/****************************************************************
- * IPL and BCV handlers
+ * Boot setup
****************************************************************/
+static void
+loadBootOrder(void)
+{
+ char *f = romfile_loadfile("bootorder", NULL);
+ if (!f)
+ return;
+
+ int i;
+ IPL.fw_bootorder_count = 1;
+ while (f[i]) {
+ if (f[i] == '\n')
+ IPL.fw_bootorder_count++;
+ i++;
+ }
+ IPL.fw_bootorder = malloc_tmphigh(IPL.fw_bootorder_count*sizeof(char*));
+ if (!IPL.fw_bootorder) {
+ warn_noalloc();
+ free(f);
+ return;
+ }
+
+ dprintf(3, "boot order:\n");
+ i = 0;
+ do {
+ IPL.fw_bootorder[i] = f;
+ f = strchr(f, '\n');
+ if (f) {
+ *f = '\0';
+ f++;
+ dprintf(3, "%d: %s\n", i, IPL.fw_bootorder[i]);
+ i++;
+ }
+ } while(f);
+}
+
void
boot_setup(void)
{
@@ -68,37 +103,13 @@ boot_setup(void)
IPL.checkfloppysig = 1;
}
- char *f = romfile_loadfile("bootorder", NULL);
- if (!f)
- return;
+ loadBootOrder();
+}
- int i;
- IPL.fw_bootorder_count = 1;
- while(f[i]) {
- if (f[i] == '\n')
- IPL.fw_bootorder_count++;
- i++;
- }
- IPL.fw_bootorder = malloc_tmphigh(IPL.fw_bootorder_count*sizeof(char*));
- if (!IPL.fw_bootorder) {
- warn_noalloc();
- free(f);
- return;
- }
- dprintf(3, "boot order:\n");
- i = 0;
- do {
- IPL.fw_bootorder[i] = f;
- f = strchr(f, '\n');
- if (f) {
- *f = '\0';
- f++;
- dprintf(3, "%d: %s\n", i, IPL.fw_bootorder[i]);
- i++;
- }
- } while(f);
-}
+/****************************************************************
+ * IPL and BCV handlers
+ ****************************************************************/
// Add a BEV vector for a given pnp compatible option rom.
void
More information about the SeaBIOS
mailing list