[LinuxBIOS] [PATCH] v3: convert stage2 to multi-segment LAR

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Tue Nov 27 03:55:01 CET 2007

This is on top of the patch I sent 50 minutes ago titled: "Re:
[LinuxBIOS] patch: prepare v3 tree for new way of doing initram".

Convert stage2 handling from binary blob to multi-segment LAR which is
created by parsing the ELF file linuxbios.stage2.o. That way, we avoid
manual specification of the entry point for stage2 code. A few LAR
functions are now unused and can be removed in a following cleanup session.
Another suggested cleanup would be factoring out a load_all_segments
function, resulting in less code duplication.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

diff -ur LinuxBIOSv3-testron/arch/x86/Makefile LinuxBIOSv3-testron-withstage2/arch/x86/Makefile
--- LinuxBIOSv3-testron/arch/x86/Makefile	2007-11-27 02:44:39.000000000 +0100
+++ LinuxBIOSv3-testron-withstage2/arch/x86/Makefile	2007-11-27 03:24:21.000000000 +0100
@@ -36,7 +36,7 @@
 ROM_SIZE := $(shell expr $(CONFIG_LINUXBIOS_ROMSIZE_KB) \* 1024)
-LARFILES := nocompress:normal/initram.o normal/stage2 nocompress:normal/option_table
+LARFILES := nocompress:normal/initram.o normal/stage2.o nocompress:normal/option_table
 LARFILES += normal/payload
@@ -57,12 +57,12 @@
-$(obj)/linuxbios.rom $(obj)/linuxbios.map: $(obj)/linuxbios.bootblock $(obj)/util/lar/lar lzma nrv2b $(obj)/linuxbios.initram.o $(obj)/linuxbios.stage2 $(obj)/option_table
+$(obj)/linuxbios.rom $(obj)/linuxbios.map: $(obj)/linuxbios.bootblock $(obj)/util/lar/lar lzma nrv2b $(obj)/linuxbios.initram.o $(obj)/linuxbios.stage2.o $(obj)/option_table
 	$(Q)rm -rf $(obj)/lar.tmp
 	$(Q)mkdir $(obj)/lar.tmp
 	$(Q)mkdir $(obj)/lar.tmp/normal
 	$(Q)cp $(obj)/linuxbios.initram.o $(obj)/lar.tmp/normal/initram.o
-	$(Q)cp $(obj)/linuxbios.stage2 $(obj)/lar.tmp/normal/stage2
+	$(Q)cp $(obj)/linuxbios.stage2.o $(obj)/lar.tmp/normal/stage2.o
 	$(Q)cp $(obj)/option_table $(obj)/lar.tmp/normal/option_table
 	$(Q)printf "  PAYLOAD none (as specified by user)\n"
@@ -198,13 +198,11 @@
 STAGE2_OBJ += $(obj)/util/x86emu/libx86emu.a $(LIBGCC_FILE_NAME)
-$(obj)/linuxbios.stage2 $(obj)/linuxbios.stage2.map: $(obj)/stage0.init $(STAGE2_OBJ)
+$(obj)/linuxbios.stage2.o $(obj)/linuxbios.stage2.map: $(obj)/stage0.init $(STAGE2_OBJ)
 	$(Q)# leave a .o with full symbols in it for debugging.
 	$(Q)printf "  LD      $(subst $(shell pwd)/,,$(@))\n"
 	$(Q)$(LD) -R $(obj)/stage0.o -Ttext 0x1000 --entry=stage2 \
 		  -o $(obj)/linuxbios.stage2.o $(STAGE2_OBJ)
-	$(Q)printf "  OBJCOPY $(subst $(shell pwd)/,,$(@))\n"
-	$(Q)$(OBJCOPY) -O binary $(obj)/linuxbios.stage2.o $(obj)/linuxbios.stage2
 	$(Q)$(NM) $(obj)/linuxbios.stage2.o | sort -u > $(obj)/linuxbios.stage2.map
diff -ur LinuxBIOSv3-testron/arch/x86/stage1.c LinuxBIOSv3-testron-withstage2/arch/x86/stage1.c
--- LinuxBIOSv3-testron/arch/x86/stage1.c	2007-11-27 03:03:17.000000000 +0100
+++ LinuxBIOSv3-testron-withstage2/arch/x86/stage1.c	2007-11-27 03:41:08.000000000 +0100
@@ -161,7 +161,12 @@
 	/* Turn off Cache-As-Ram */
-	ret = run_file(&archive, "normal/stage2", (void *)0x1000);
+	entry = load_file(&archive, "normal/stage2.o/segment0");
+	if (entry == (void *)-1)
+		die("FATAL: Failed loading stage2 segment0.");
+	if (load_file(&archive, "normal/stage2.o/segment1") == (void *)-1)
+		die("FATAL: Failed loading stage2 segment1.");
+	ret = run_address(entry);
 	if (ret)
 		die("FATAL: Failed in stage2 code.");

More information about the coreboot mailing list