[coreboot-gerrit] Patch set updated for coreboot: 3848aed Add a new and safer bootblock implementation.

Denis Carikli (GNUtoo@no-log.org) gerrit at coreboot.org
Sun Jul 7 20:54:12 CEST 2013


Denis Carikli (GNUtoo at no-log.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3549

-gerrit

commit 3848aedf936040ec0630368a85b67d8fa73cccdc
Author: Denis 'GNUtoo' Carikli <GNUtoo at 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 at no-log.org>
---
 src/arch/x86/Kconfig                 | 13 +++++++++++++
 src/drivers/pc80/mc146818rtc_early.c | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 47 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..717c514 100644
--- a/src/drivers/pc80/mc146818rtc_early.c
+++ b/src/drivers/pc80/mc146818rtc_early.c
@@ -49,6 +49,39 @@ static inline int last_boot_normal(void)
 	return (byte & (1 << 1));
 }
 
+#if CONFIG_X86_BOOTBLOCK_FAILBOOT
+static inline int do_normal_boot(void)
+{
+	unsigned char 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.
+		 */
+		byte = cmos_read(RTC_BOOT_BYTE);
+		byte &= 0x0c;
+		cmos_write(byte, RTC_BOOT_BYTE);
+	}
+
+	byte = cmos_read(RTC_BOOT_BYTE);
+
+	/* Copy boot_option to last_boot */
+	if (byte & (1<<0))
+		byte |= (1<<1);
+	else
+		byte &= ~(1<<1);
+
+	/* Reset boot_option to Fallback */
+	byte &= ~(1<<0);
+
+	/* Write back the modified content to the nvram */
+	cmos_write(byte, RTC_BOOT_BYTE);
+
+	/* Return the saved boot_option */
+	return (byte & (1<<1));
+}
+#else
 static inline int do_normal_boot(void)
 {
 	unsigned char byte;
@@ -91,6 +124,7 @@ static inline int do_normal_boot(void)
 
 	return (byte & (1<<1));
 }
+#endif
 
 unsigned read_option_lowlevel(unsigned start, unsigned size, unsigned def)
 {



More information about the coreboot-gerrit mailing list