From patchwork Mon Feb 22 13:28:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: fallback/normal switch for Kconfig Date: Mon, 22 Feb 2010 13:28:00 -0000 From: Patrick Georgi X-Patchwork-Id: 953 Message-Id: <4B828660.8060602@georgi-clan.de> To: coreboot@coreboot.org Hi, attached patch provides a working fallback/normal switch mechanism. It only works with "tiny bootblock" style builds and allows for more bootblock-level decision code to be added to the tree (eg. select based on GPIO, CPUID, etc.), without duplicating that stuff in every single of our mainboard directories. It also renames the tinybootblock-related files to just "bootblock", as this model should be the longterm goal in my opinion. Given that I had to shuffle files around for this commit, this seemed the right opportunity to do it. Various Kconfig labels that refer to TINY_BOOTBLOCK still exist, but it's not such a big impact to change these like file renames. Also there are more things to clean up, eg. FALLBACK_PAYLOAD_FILE. To apply the patch, src/arch/i386/init/bootblock.c must be copied to src/arch/i386/include/bootblock_common.h src/arch/i386/init/bootblock_normal.c src/arch/i386/init/bootblock_simple.c and bootblock.c itself be removed (the patch does that, but your patch(1) might not delete the file properly). To build a full fallback/normal image, two build steps are necessary, as done by this script: make distclean cp fallback-config .config make oldconfig make || exit make clean-for-update cp normal-config .config make oldconfig make fallback-config and normal-config can be configured as similar or different to each other as you want, but at a minimum, the following is necessary: fallback-config: CONFIG_CBFS_PREFIX="fallback" # CONFIG_UPDATE_IMAGE is not set normal-config: CONFIG_CBFS_PREFIX="normal" CONFIG_UPDATE_IMAGE=y Signed-off-by: Patrick Georgi Index: src/arch/i386/Kconfig =================================================================== --- src/arch/i386/Kconfig (revision 5144) +++ src/arch/i386/Kconfig (working copy) @@ -49,6 +49,24 @@ default n if TINY_BOOTBLOCK default y +choice + prompt "Bootblock behaviour" + default BOOTBLOCK_SIMPLE + depends on TINY_BOOTBLOCK + +config BOOTBLOCK_SIMPLE + bool "Always load fallback" + +config BOOTBLOCK_NORMAL + bool "Switch to normal if CMOS says so" + +endchoice + +config BOOTBLOCK_SOURCE + string + default "bootblock_simple.c" if BOOTBLOCK_SIMPLE + default "bootblock_normal.c" if BOOTBLOCK_NORMAL + config UPDATE_IMAGE bool "Update existing coreboot.rom image" default n Index: src/arch/i386/Makefile.bootblock.inc =================================================================== --- src/arch/i386/Makefile.bootblock.inc (revision 5144) +++ src/arch/i386/Makefile.bootblock.inc (working copy) @@ -63,7 +63,7 @@ $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.s: $(obj)/bootblock/bootblock.c $(CC) -x assembler-with-cpp -DASSEMBLY -E -I$(src)/include -I$(src)/arch/i386/include -I$(obj) -I$(obj)/bootblock -include $(obj)/config.h -I. -I$(src) $< > $@.new && mv $@.new $@ -$(obj)/mainboard/$(MAINBOARDDIR)/bootblock.inc: $(src)/arch/i386/init/bootblock.c $(obj)/romcc +$(obj)/mainboard/$(MAINBOARDDIR)/bootblock.inc: $(src)/arch/i386/init/$(subst ",,$(CONFIG_BOOTBLOCK_SOURCE)) $(obj)/romcc $(obj)/romcc $(bootblock_romccflags) -O2 $(ROMCCFLAGS) $(INCLUDES) $< -o $@ $(obj)/bootblock.elf: $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.o $(obj)/bootblock/ldscript.ld Index: src/arch/i386/include/bootblock_common.h =================================================================== --- src/arch/i386/include/bootblock_common.h (revision 5144) +++ src/arch/i386/include/bootblock_common.h (working copy) @@ -1,3 +1,4 @@ +#define ASSEMBLY 1 #define __PRE_RAM__ #if CONFIG_LOGICAL_CPUS && \ (defined(CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT) || defined(CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT)) @@ -31,17 +32,3 @@ { asm volatile ("jmp *%0\n\t" : : "r" (addr), "a" (bist)); } - -static void main(unsigned long bist) -{ - if (boot_cpu()) { - bootblock_northbridge_init(); - bootblock_southbridge_init(); - } - const char* target1 = "fallback/romstage"; - unsigned long entry; - entry = findstage(target1); - if (entry) call(entry, bist); - asm volatile ("1:\n\thlt\n\tjmp 1b\n\t"); -} - Index: src/arch/i386/init/bootblock.c =================================================================== --- src/arch/i386/init/bootblock.c (revision 5144) +++ src/arch/i386/init/bootblock.c (working copy) @@ -1,47 +0,0 @@ -#define __PRE_RAM__ -#if CONFIG_LOGICAL_CPUS && \ - (defined(CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT) || defined(CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT)) -#include -#else -#define boot_cpu(x) 1 -#endif - -#ifdef CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT -#include CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT -#else -static void bootblock_northbridge_init(void) { } -#endif -#ifdef CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT -#include CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT -#else -static void bootblock_southbridge_init(void) { } -#endif - -static unsigned long findstage(char* target) -{ - unsigned long entry; - asm volatile ( - "mov $1f, %%esp\n\t" - "jmp walkcbfs\n\t" - "1:\n\t" : "=a" (entry) : "S" (target) : "ebx", "ecx", "edi", "esp"); - return entry; -} - -static void call(unsigned long addr, unsigned long bist) -{ - asm volatile ("jmp *%0\n\t" : : "r" (addr), "a" (bist)); -} - -static void main(unsigned long bist) -{ - if (boot_cpu()) { - bootblock_northbridge_init(); - bootblock_southbridge_init(); - } - const char* target1 = "fallback/romstage"; - unsigned long entry; - entry = findstage(target1); - if (entry) call(entry, bist); - asm volatile ("1:\n\thlt\n\tjmp 1b\n\t"); -} - Index: src/arch/i386/init/bootblock_normal.c =================================================================== --- src/arch/i386/init/bootblock_normal.c (revision 5144) +++ src/arch/i386/init/bootblock_normal.c (working copy) @@ -1,47 +1,29 @@ -#define __PRE_RAM__ -#if CONFIG_LOGICAL_CPUS && \ - (defined(CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT) || defined(CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT)) -#include -#else -#define boot_cpu(x) 1 -#endif +#include -#ifdef CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT -#include CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT -#else -static void bootblock_northbridge_init(void) { } -#endif -#ifdef CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT -#include CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT -#else -static void bootblock_southbridge_init(void) { } -#endif +#include +#include "arch/romcc_io.h" +#include "pc80/mc146818rtc_early.c" -static unsigned long findstage(char* target) -{ - unsigned long entry; - asm volatile ( - "mov $1f, %%esp\n\t" - "jmp walkcbfs\n\t" - "1:\n\t" : "=a" (entry) : "S" (target) : "ebx", "ecx", "edi", "esp"); - return entry; -} - -static void call(unsigned long addr, unsigned long bist) -{ - asm volatile ("jmp *%0\n\t" : : "r" (addr), "a" (bist)); -} - static void main(unsigned long bist) { if (boot_cpu()) { bootblock_northbridge_init(); bootblock_southbridge_init(); } - const char* target1 = "fallback/romstage"; + unsigned long entry; - entry = findstage(target1); + if (do_normal_boot()) + entry = findstage("normal/romstage"); + else + entry = findstage("fallback/romstage"); + if (entry) call(entry, bist); + + /* run fallback if normal can't be found */ + entry = findstage("fallback/romstage"); + if (entry) call(entry, bist); + + /* duh. we're stuck */ asm volatile ("1:\n\thlt\n\tjmp 1b\n\t"); } Index: src/arch/i386/init/bootblock_simple.c =================================================================== --- src/arch/i386/init/bootblock_simple.c (revision 5144) +++ src/arch/i386/init/bootblock_simple.c (working copy) @@ -1,37 +1,5 @@ -#define __PRE_RAM__ -#if CONFIG_LOGICAL_CPUS && \ - (defined(CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT) || defined(CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT)) -#include -#else -#define boot_cpu(x) 1 -#endif +#include -#ifdef CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT -#include CONFIG_BOOTBLOCK_NORTHBRIDGE_INIT -#else -static void bootblock_northbridge_init(void) { } -#endif -#ifdef CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT -#include CONFIG_BOOTBLOCK_SOUTHBRIDGE_INIT -#else -static void bootblock_southbridge_init(void) { } -#endif - -static unsigned long findstage(char* target) -{ - unsigned long entry; - asm volatile ( - "mov $1f, %%esp\n\t" - "jmp walkcbfs\n\t" - "1:\n\t" : "=a" (entry) : "S" (target) : "ebx", "ecx", "edi", "esp"); - return entry; -} - -static void call(unsigned long addr, unsigned long bist) -{ - asm volatile ("jmp *%0\n\t" : : "r" (addr), "a" (bist)); -} - static void main(unsigned long bist) { if (boot_cpu()) { Index: src/arch/i386/Makefile.inc =================================================================== --- src/arch/i386/Makefile.inc (revision 5144) +++ src/arch/i386/Makefile.inc (working copy) @@ -95,7 +95,7 @@ endif ifeq ($(CONFIG_TINY_BOOTBLOCK),y) -include $(src)/arch/i386/Makefile.tinybootblock.inc +include $(src)/arch/i386/Makefile.bootblock.inc else include $(src)/arch/i386/Makefile.bigbootblock.inc endif Index: src/arch/i386/Makefile.tinybootblock.inc =================================================================== --- src/arch/i386/Makefile.tinybootblock.inc (revision 5144) +++ src/arch/i386/Makefile.tinybootblock.inc (working copy) @@ -1,104 +0,0 @@ -ifdef POST_EVALUATION - -####################################################################### -# Build the final rom image - -ifneq ($(CONFIG_UPDATE_IMAGE),y) -$(obj)/coreboot.pre1: $(obj)/coreboot.bootblock $(CBFSTOOL) - rm -f $@ - $(CBFSTOOL) $@ create $(CONFIG_COREBOOT_ROMSIZE_KB)K $(obj)/coreboot.bootblock -else -$(obj)/coreboot.pre1: $(CBFSTOOL) - mv $(obj)/coreboot.rom $@ -endif - -$(obj)/coreboot.pre: $(obj)/coreboot.romstage $(obj)/coreboot.pre1 $(CBFSTOOL) - rm -f $@ - cp $(obj)/coreboot.pre1 $@ - $(CBFSTOOL) $@ add-stage $(obj)/romstage.elf $(CONFIG_CBFS_PREFIX)/romstage x 0x$(shell cat $(obj)/location.txt) -#FIXME: location.txt might require an offset of header size - -####################################################################### -# Build the bootblock - -$(obj)/coreboot.bootblock: $(obj)/bootblock.elf - @printf " OBJCOPY $(subst $(obj)/,,$(@))\n" - $(OBJCOPY) -O binary $< $@ - -bootblock_lds := $(src)/arch/i386/init/ldscript_failover.lb -bootblock_lds += $(src)/cpu/x86/16bit/entry16.lds -bootblock_lds += $(src)/cpu/x86/16bit/reset16.lds -bootblock_lds += $(src)/arch/i386/lib/id.lds -bootblock_lds += $(chipset_bootblock_lds) - -bootblock_inc := $(src)/arch/i386/init/bootblock_prologue.c -bootblock_inc += $(src)/cpu/x86/16bit/entry16.inc -bootblock_inc += $(src)/cpu/x86/16bit/reset16.inc -bootblock_inc += $(src)/cpu/x86/32bit/entry32.inc -bootblock_inc += $(src)/arch/i386/lib/id.inc -bootblock_inc += $(chipset_bootblock_inc) - -ifeq ($(CONFIG_SSE),y) -bootblock_inc += $(src)/cpu/x86/sse_enable.inc -endif -bootblock_inc += $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.inc -bootblock_inc += $(src)/arch/i386/lib/walkcbfs.S - -bootblock_romccflags := -mcpu=i386 -ifeq ($(CONFIG_SSE),y) -bootblock_romccflags := -mcpu=k7 -msse -endif - -$(obj)/bootblock/ldscript.ld: $(bootblock_ldscripts) $(obj)/ldoptions - mkdir -p $(obj)/bootblock - printf '$(foreach ldscript,ldoptions $(bootblock_lds),INCLUDE "$(ldscript)"\n)' > $@ - -$(obj)/bootblock/bootblock.c: $(bootblock_inc) - mkdir -p $(obj)/bootblock - printf '$(foreach crt0,config.h $(bootblock_inc),#include "$(crt0)"\n)' > $@ - -$(obj)/mainboard/$(MAINBOARDDIR)/bootblock.o: $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.s - $(CC) -I$(obj) -Wa,-acdlns -c -o $@ $< > $(dir $@)/crt0.disasm - -$(obj)/mainboard/$(MAINBOARDDIR)/bootblock.s: $(obj)/bootblock/bootblock.c - $(CC) -x assembler-with-cpp -DASSEMBLY -E -I$(src)/include -I$(src)/arch/i386/include -I$(obj) -I$(obj)/bootblock -include $(obj)/config.h -I. -I$(src) $< > $@.new && mv $@.new $@ - -$(obj)/mainboard/$(MAINBOARDDIR)/bootblock.inc: $(src)/arch/i386/init/bootblock.c $(obj)/romcc - $(obj)/romcc $(bootblock_romccflags) -O2 $(ROMCCFLAGS) $(INCLUDES) $< -o $@ - -$(obj)/bootblock.elf: $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.o $(obj)/bootblock/ldscript.ld - @printf " LINK $(subst $(obj)/,,$(@))\n" - $(CC) -nostdlib -nostartfiles -static -o $@ -L$(obj) -T $(obj)/bootblock/ldscript.ld $< - $(NM) -n $(obj)/bootblock.elf | sort > $(obj)/bootblock.map - -####################################################################### -# Build the romstage -$(obj)/coreboot.romstage: $(obj)/coreboot.pre1 $(initobjs) $(obj)/romstage/ldscript.ld - @printf " LINK $(subst $(obj)/,,$(@))\n" - printf "CONFIG_ROMBASE = 0x0;\nAUTO_XIP_ROM_BASE = 0x0;\n" > $(obj)/location.ld - $(CC) -nostdlib -nostartfiles -static -o $(obj)/romstage.elf -L$(obj) -T $(obj)/romstage/ldscript.ld $(initobjs) - $(OBJCOPY) -O binary $(obj)/romstage.elf $(obj)/romstage.bin - printf "CONFIG_ROMBASE = 0x" > $(obj)/location.ld - $(CBFSTOOL) $(obj)/coreboot.pre1 locate $(obj)/romstage.bin $(CONFIG_CBFS_PREFIX)/romstage $(CONFIG_XIP_ROM_SIZE) > $(obj)/location.txt - cat $(obj)/location.txt >> $(obj)/location.ld - printf ';\nAUTO_XIP_ROM_BASE = CONFIG_ROMBASE & ~(CONFIG_XIP_ROM_SIZE - 1);\n' >> $(obj)/location.ld - $(CC) -nostdlib -nostartfiles -static -o $(obj)/romstage.elf -L$(obj) -T $(obj)/romstage/ldscript.ld $(initobjs) - $(NM) -n $(obj)/romstage.elf | sort > $(obj)/romstage.map - $(OBJCOPY) -O binary $(obj)/romstage.elf $@ - -$(obj)/romstage/ldscript.ld: $(ldscripts) $(obj)/ldoptions - mkdir -p $(obj)/romstage - printf '$(foreach ldscript,ldoptions location.ld $(ldscripts),INCLUDE "$(ldscript:$(obj)/%=%)"\n)' > $@ - -$(obj)/romstage/crt0_includes.h: $(crt0s) - @printf " GEN $(subst $(obj)/,,$(@))\n" - mkdir -p $(obj)/romstage - printf '$(foreach crt0,config.h $(crt0s),#include "$(crt0:$(obj)/%=%)"\n)' > $@ - -$(obj)/mainboard/$(MAINBOARDDIR)/crt0.o: $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s - $(CC) -I$(obj) -Wa,-acdlns -c -o $@ $< > $(dir $@)/crt0.disasm - -$(obj)/mainboard/$(MAINBOARDDIR)/crt0.s: $(src)/arch/i386/init/crt0.S.lb $(obj)/romstage/crt0_includes.h - $(CC) -x assembler-with-cpp -DASSEMBLY -E -I$(src)/include -I$(src)/arch/i386/include -I$(obj) -I$(obj)/romstage -include $(obj)/config.h -I. -I$(src) $< > $@.new && mv $@.new $@ - -endif