Denis Carikli (GNUtoo@no-log.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3549
-gerrit
commit 5b51373d79139461b992f4ebcca9efcd381023b0 Author: Denis 'GNUtoo' Carikli GNUtoo@no-log.org Date: Fri Jun 21 23:32:19 2013 +0200
Add a new and safer bootblock implementation.
The drawback is that it requires cooperation from something that is run after coreboot (like the OS or the payload).
To understand how to use it, refer to the Kconfig help of that option.
Thanks a lot to kmalkki on #coreboot Freenode IRC channel for pointers on how to simplify the implementation.
Change-Id: I1109c49c7c84461bb056b36ee5d07391c2392176 Signed-off-by: Denis 'GNUtoo' Carikli GNUtoo@no-log.org --- src/arch/x86/Kconfig | 13 +++++++++++++ src/drivers/pc80/mc146818rtc_early.c | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
diff --git a/src/arch/x86/Kconfig b/src/arch/x86/Kconfig index 69cdc8a..3bb6547 100644 --- a/src/arch/x86/Kconfig +++ b/src/arch/x86/Kconfig @@ -54,12 +54,25 @@ config X86_BOOTBLOCK_SIMPLE config X86_BOOTBLOCK_NORMAL bool "Switch to normal if CMOS says so"
+config X86_BOOTBLOCK_FAILBOOT + bool "Switch to Fallback if it fails to boot" + help + Switch to Fallback after failing to boot. + Coreboot will reset boot_option to Fallback + as early as possible, If the user has + a Fallback and a Normal image in cbfs, + and wants to boot on the Normal image, + he must reset the boot_option to Normal + after successfully booting (like trough the OS + boot scripts that would run something like: + "nvramtool -w boot_option=Normal". endchoice
config BOOTBLOCK_SOURCE string default "bootblock_simple.c" if X86_BOOTBLOCK_SIMPLE default "bootblock_normal.c" if X86_BOOTBLOCK_NORMAL + default "bootblock_normal.c" if X86_BOOTBLOCK_FAILBOOT
config UPDATE_IMAGE bool "Update existing coreboot.rom image" diff --git a/src/drivers/pc80/mc146818rtc_early.c b/src/drivers/pc80/mc146818rtc_early.c index 0652f27..2b2fc77 100644 --- a/src/drivers/pc80/mc146818rtc_early.c +++ b/src/drivers/pc80/mc146818rtc_early.c @@ -42,13 +42,49 @@ static int cmos_chksum_valid(void) }
+#if CONFIG_X86_BOOTBLOCK_FAILBOOT +static inline int last_boot_normal(void) +{ + unsigned char byte; + byte = cmos_read(RTC_BOOT_BYTE); + return (byte & (1 << 0)); +} +#else static inline int last_boot_normal(void) { unsigned char byte; byte = cmos_read(RTC_BOOT_BYTE); return (byte & (1 << 1)); } +#endif
+#if CONFIG_X86_BOOTBLOCK_FAILBOOT +static inline int do_normal_boot(void) +{ + unsigned char old_byte, write_byte; + + if (cmos_error() || !cmos_chksum_valid()) { + /* There are no impossible values, no checksums so just + * trust whatever value we have in the the cmos, + * but clear the fallback bit. + */ + write_byte = cmos_read(RTC_BOOT_BYTE); + write_byte &= 0x0c; + cmos_write(write_byte, RTC_BOOT_BYTE); + } + + /* The RTC_BOOT_BYTE is now o.k. see where to go. */ + write_byte = old_byte = cmos_read(RTC_BOOT_BYTE); + + /* Reset boot_option to Fallback */ + write_byte &= ~(1<<0); + + /* Save the boot byte */ + cmos_write(write_byte, RTC_BOOT_BYTE); + + return (old_byte & (1<<0)); +} +#else static inline int do_normal_boot(void) { unsigned char byte; @@ -91,6 +127,7 @@ static inline int do_normal_boot(void)
return (byte & (1<<1)); } +#endif
unsigned read_option_lowlevel(unsigned start, unsigned size, unsigned def) {