[coreboot] New patch to review: acf0475 Add nvram command

Patrick Georgi (patrick@georgi-clan.de) gerrit at coreboot.org
Mon Sep 5 13:40:15 CEST 2011


Patrick Georgi (patrick at georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/196

-gerrit

commit acf04759bf35be686f264011154f562df813a228
Author: Stefan Reinauer <stefan.reinauer at coresystems.de>
Date:   Fri Jun 4 09:25:50 2010 +0200

    Add nvram command
    
    Change-Id: Ib95ee0d4fa8dcaf002ffe2b18d4975e301d00a6a
    Signed-off-by: Patrick Georgi <patrick.georgi at secunet.com>
---
 main/grub/builtins.c |   67 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/main/grub/builtins.c b/main/grub/builtins.c
index 79d237e..df14cf1 100644
--- a/main/grub/builtins.c
+++ b/main/grub/builtins.c
@@ -1098,6 +1098,70 @@ static struct builtin builtin_md5crypt = {
 };
 #endif				/* CONFIG_USE_MD5_PASSWORDS */
 
+#if CONFIG_DEVELOPER_TOOLS
+/* nvram */
+static int nvram_func(char *arg, int flags)
+{
+#define RTC_BOOT_BYTE 48 // Hard coded in coreboot
+	u8 rtc_boot_byte;
+	// bit len  name
+	//  0   1   boot_option
+	//  1   1   last_boot
+	//  4   4   reboot_bits
+
+	rtc_boot_byte = nvram_read(RTC_BOOT_BYTE);
+
+	if (memcmp(arg, "normal", 6) == 0) {
+		rtc_boot_byte &= 0x03;	// drop reboot_bits
+		rtc_boot_byte |= 1;	// normal
+		nvram_write(rtc_boot_byte, RTC_BOOT_BYTE);
+		return 0;
+	}
+
+	if (memcmp(arg, "fallback", 8) == 0) {
+		rtc_boot_byte &= 0x03;	// drop reboot_bits
+		rtc_boot_byte &= ~1;	// fallback
+		nvram_write(rtc_boot_byte, RTC_BOOT_BYTE);
+		return 0;
+	}
+
+	// TODO not really default, but rather "null everything out and fix the
+	// checksum"
+	if (memcmp(arg, "default", 7) == 0) {
+		int i;
+		int range_start = lib_sysinfo.cmos_range_start / 8;
+		int range_end = lib_sysinfo.cmos_range_end / 8;
+		for (i= range_start; i<range_end; i++)
+			nvram_write(0, i);
+		fix_options_checksum();
+		return 0;
+	}
+
+
+	if (!strlen(arg)) {
+		grub_printf("NVRAM Settings:\n");
+		grub_printf("  boot option: %s\n", 
+			(rtc_boot_byte & (1 << 0)) ? "Normal" : "Fallback");
+		grub_printf("  last boot:   %s\n", 
+			(rtc_boot_byte & (1 << 1)) ? "Normal" : "Fallback");
+		grub_printf("  reboot_bits: %d\n", (rtc_boot_byte >> 4));
+		return 0;
+	}
+
+	errnum = ERR_BAD_ARGUMENT;
+	return 1;
+}
+
+static struct builtin builtin_nvram = {
+	"nvram",
+	nvram_func,
+	BUILTIN_MENU | BUILTIN_CMDLINE | BUILTIN_NO_ECHO,
+	"nvram [normal|fallback]",
+	"Change the coreboot nvram to boot the normal or fallback"
+	    "image on the next boot."
+};
+#endif
+
 /* password */
 static int password_func(char *arg, int flags)
 {
@@ -1786,6 +1850,9 @@ struct builtin *builtin_table[] = {
 #ifdef CONFIG_USE_MD5_PASSWORDS
 	&builtin_md5crypt,
 #endif
+#ifdef CONFIG_DEVELOPER_TOOLS
+	&builtin_nvram,
+#endif
 	&builtin_password,
 	&builtin_pause,
 	&builtin_poweroff,




More information about the coreboot mailing list