From 07f34845e1a20a420e84d74d26521d3cdbe27a8b Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Mon, 11 Apr 2011 13:35:06 -0700 Subject: Add Mario support for fwupdate_tries Change-Id: I1c4240ebe5783ca923c310061e2a76947aa6601b R=reinauer@chromium.org BUG=chromium-os:14030 TEST=manual On a Mario: crossystem fwupdate_tries=3 crossystem fwupdate_tries # should be 3 cat /mnt/stateful_partition/.need_firmware_update # should be 3 crossystem fwupdate_tries=0 crossystem fwupdate_tries # should be 0 cat /mnt/stateful_partition/.need_firmware_update # should complain file doesn't exist On a newer platform: crossystem fwupdate_tries=3 crossystem fwupdate_tries # should be 3 cat /mnt/stateful_partition/.need_firmware_update # should complain file doesn't exist crossystem fwupdate_tries=0 crossystem fwupdate_tries # should be 0 cat /mnt/stateful_partition/.need_firmware_update # should complain file doesn't exist Review URL: http://codereview.chromium.org/6825047 --- host/arch/x86/lib/crossystem_arch.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'host/arch/x86/lib/crossystem_arch.c') diff --git a/host/arch/x86/lib/crossystem_arch.c b/host/arch/x86/lib/crossystem_arch.c index b8e6add5..2b5654b8 100644 --- a/host/arch/x86/lib/crossystem_arch.c +++ b/host/arch/x86/lib/crossystem_arch.c @@ -84,6 +84,9 @@ /* Filename for NVRAM file */ #define NVRAM_PATH "/dev/nvram" +/* Filename for legacy firmware update tries */ +#define NEED_FWUPDATE_PATH "/mnt/stateful_partition/.need_firmware_update" + int VbReadNvStorage(VbNvContext* vnc) { FILE* f; @@ -522,6 +525,19 @@ int VbGetArchPropertyInt(const char* name) { if (-1 == value) value = VbGetCmosRebootField(CMOSRF_TRY_B); } + /* Firmware update tries is now stored in the kernel field. On + * older systems where it's not, it was stored in a file in the + * stateful partition. */ + else if (!strcasecmp(name,"fwupdate_tries")) { + if (-1 != VbGetNvStorage(VBNV_KERNEL_FIELD)) + return -1; /* NvStorage supported; fail through arch-specific + * implementation to normal implementation. */ + + /* Read value from file; missing file means value=0. */ + value = ReadFileInt(NEED_FWUPDATE_PATH); + if (-1 == value) + value = 0; + } return value; } @@ -581,6 +597,24 @@ int VbSetArchPropertyInt(const char* name, int value) { return 0; return VbSetCmosRebootField(CMOSRF_TRY_B, value); } + /* Firmware update tries is now stored in the kernel field. On + * older systems where it's not, it was stored in a file in the + * stateful partition. */ + else if (!strcasecmp(name,"fwupdate_tries")) { + if (-1 != VbGetNvStorage(VBNV_KERNEL_FIELD)) + return -1; /* NvStorage supported; fail through arch-specific + * implementation to normal implementation */ + + if (value) { + char buf[32]; + snprintf(buf, sizeof(buf), "%d", value); + return WriteFile(NEED_FWUPDATE_PATH, buf, strlen(buf)); + } else { + /* No update tries, so remove file if it exists. */ + unlink(NEED_FWUPDATE_PATH); + return 0; + } + } return -1; } -- cgit v1.2.1