From 7adcc60e6f5f6db081b9ad6e02288335502a0d77 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Fri, 24 Jun 2011 16:11:45 -0700 Subject: Vboot wrapper API - crossystem and header files Header file changes for wrapper API implementation Crossystem support for reading recovery reason from VbSharedData, and explicit support for version 1 VbSharedData structs. BUG=chromium-os:16970 TEST=make && make runtests; run crossystem on Alex and make sure it still reports recovery_reason in recovery mode. Change-Id: I15195b899583e425d3c9e8df09842d764528e2cb Reviewed-on: http://gerrit.chromium.org/gerrit/3203 Reviewed-by: Tom Wai-Hong Tam Reviewed-by: Che-Liang Chiou Tested-by: Randall Spangler --- host/arch/x86/lib/crossystem_arch.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (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 8b320e4b..25867e12 100644 --- a/host/arch/x86/lib/crossystem_arch.c +++ b/host/arch/x86/lib/crossystem_arch.c @@ -156,8 +156,7 @@ int VbWriteNvStorage(VbNvContext* vnc) { * deallocating the pointer, this will take care of both the structure * and the buffer. Null in case of error. */ -static uint8_t* VbGetBuffer(const char* filename, int* buffer_size) -{ +static uint8_t* VbGetBuffer(const char* filename, int* buffer_size) { FILE* f = NULL; char* file_buffer = NULL; uint8_t* output_buffer = NULL; @@ -240,14 +239,24 @@ static uint8_t* VbGetBuffer(const char* filename, int* buffer_size) VbSharedDataHeader* VbSharedDataRead(void) { - VbSharedDataHeader* sh; int got_size = 0; + int expect_size; sh = (VbSharedDataHeader*)VbGetBuffer(ACPI_VDAT_PATH, &got_size); if (!sh) return NULL; - if (got_size < sizeof(VbSharedDataHeader)) { + + /* Make sure the size is sufficient for the struct version we got. + * Check supported old versions first. */ + if (1 == sh->struct_version) + expect_size = VB_SHARED_DATA_HEADER_SIZE_V1; + else { + /* There'd better be enough data for the current header size. */ + expect_size = sizeof(VbSharedDataHeader); + } + + if (got_size < expect_size) { Free(sh); return NULL; } @@ -371,7 +380,18 @@ static const char* VbReadMainFwType(char* dest, int size) { /* Read the recovery reason. Returns the reason code or -1 if error. */ static int VbGetRecoveryReason(void) { - int value; + VbSharedDataHeader* sh; + int value = -1; + + /* Try reading from VbSharedData first */ + sh = VbSharedDataRead(); + if (sh) { + if (sh->struct_version >= 2) + value = sh->recovery_reason; + Free(sh); + if (-1 != value) + return value; + } /* Try reading type from BINF.4 */ value = ReadFileInt(ACPI_BINF_PATH ".4"); -- cgit v1.2.1