[LinuxBIOS] [PATCH] v3: big arch/x86/stage1.c and lib/lar.c cleanup
Carl-Daniel Hailfinger
c-d.hailfinger.devel.2006 at gmx.net
Thu Nov 29 23:48:04 CET 2007
Remove ".o" suffix from parsed ELF files in the LAR.
Build tested and runtime tested in Qemu.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Index: LinuxBIOSv3-betterparsedelfnaming/lib/lar.c
===================================================================
--- LinuxBIOSv3-betterparsedelfnaming/lib/lar.c (Revision 532)
+++ LinuxBIOSv3-betterparsedelfnaming/lib/lar.c (Arbeitskopie)
@@ -141,7 +141,7 @@
walk += (ntohl(header->offset) + ntohl(header->len) - 1)
& 0xfffffff0;
}
- printk(BIOS_SPEW, "LAR: NO FILE FOUND!\n");
+ printk(BIOS_SPEW, "LAR: File not found!\n");
return 1;
}
Index: LinuxBIOSv3-betterparsedelfnaming/util/lar/stream.c
===================================================================
--- LinuxBIOSv3-betterparsedelfnaming/util/lar/stream.c (Revision 532)
+++ LinuxBIOSv3-betterparsedelfnaming/util/lar/stream.c (Arbeitskopie)
@@ -63,7 +63,7 @@
/**
* Output all the ELF segments for a given file
- * @param lar The LAR Archoe
+ * @param lar The LAR archive
* @param name The LAR name
* @param filebuf The ELF file
* @param filelen Size of the ELF file
@@ -82,15 +82,20 @@
int segment = 0;
char *header;
char ename[64];
+ char *strippedname;
int headers;
char *temp;
enum compalgo thisalgo;
u32 complen;
/* Allocate a temporary buffer to compress into - this is unavoidable,
- because we need to make sure that the compressed data will fit in
- the LAR, and we won't know the size of the compressed data until
- we actually compress it */
+ * because we need to make sure that the compressed data will fit in
+ * the LAR, and we won't know the size of the compressed data until
+ * we actually compress it.
+ * FIXME: In case the compressed file is bigger than the original,
+ * we corrupt memory. Compute maximum size increase and allocate that
+ * on top of the file length.
+ */
temp = calloc(filelen, 1);
@@ -99,6 +104,15 @@
return -1;
}
+ strippedname = strdup(name);
+ if (strippedname == NULL) {
+ err("Out of memory.\n");
+ return -1;
+ }
+ /* Check if name ends in ".o" and strip that. */
+ if (!strcmp(strippedname + strlen(strippedname) - 2, ".o"))
+ strippedname[strlen(strippedname) - 2] = '\0';
+
/* validate elf header */
ehdr = (Elf32_Ehdr *)filebuf;
headers = ehdr->e_phnum;
@@ -154,13 +168,15 @@
entry, phdr[i].p_paddr);
}
/* ok, copy it out */
- sprintf(ename, "%s/segment%d", name, segment++);
+ sprintf(ename, "%s/segment%d", strippedname, segment++);
complen = lar_compress(&header[phdr[i].p_offset], size, temp, &thisalgo);
ret = lar_add_entry(lar, ename, temp, complen, size,
phdr[i].p_paddr, entry, thisalgo);
}
+ free(strippedname);
return 0;
out:
+ free(strippedname);
return -1;
}
Index: LinuxBIOSv3-betterparsedelfnaming/arch/x86/stage1.c
===================================================================
--- LinuxBIOSv3-betterparsedelfnaming/arch/x86/stage1.c (Revision 532)
+++ LinuxBIOSv3-betterparsedelfnaming/arch/x86/stage1.c (Arbeitskopie)
@@ -137,17 +137,17 @@
// find first initram
if (check_normal_boot_flag()) {
printk(BIOS_DEBUG, "Choosing normal boot.\n");
- ret = execute_in_place(&archive, "normal/initram.o/segment0");
+ ret = execute_in_place(&archive, "normal/initram/segment0");
} else {
printk(BIOS_DEBUG, "Choosing fallback boot.\n");
- ret = execute_in_place(&archive, "fallback/initram.o/segment0");
+ ret = execute_in_place(&archive, "fallback/initram/segment0");
/* Try a normal boot if fallback doesn't exist in the lar.
* TODO: There are other ways to do this.
* It could be ifdef or the boot flag could be forced.
*/
if (ret) {
printk(BIOS_DEBUG, "Fallback failed. Try normal boot\n");
- ret = execute_in_place(&archive, "normal/initram.o/segment0");
+ ret = execute_in_place(&archive, "normal/initram/segment0");
}
}
@@ -160,7 +160,7 @@
/* Turn off Cache-As-Ram */
disable_car();
- entry = load_file_segments(&archive, "normal/stage2.o");
+ entry = load_file_segments(&archive, "normal/stage2");
if (entry == (void *)-1)
die("FATAL: Failed loading stage2.");
ret = run_address(entry);
More information about the coreboot
mailing list