From 398a7048590742e85c3b2d4bf82c172ddfcd192f Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Fri, 10 May 2013 00:42:14 -0500 Subject: [PATCH] BACKPORT: chromeos: use cache-as-ram migration API for vbnv It's possible that the vbnv global variables may be accessed in romstage after cache-as-ram is torn down. Therefore use the cache-as-ram migration API. Wrappers were written to wrap the API to keep the existing code as close as possible. BUG=chrome-os-partner:19342 BRANCH=none TEST=Built and booted. Noted that CAR values are not read incorrectly. Change-Id: I00fa4128fd2f197f238f38814b158ffc3387ea48 Signed-off-by: Aaron Durbin Reviewed-on: https://gerrit.chromium.org/gerrit/51388 Reviewed-by: Stefan Reinauer --- src/vendorcode/google/chromeos/vbnv.c | 32 +++++++++++++++++++++------ 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/vendorcode/google/chromeos/vbnv.c b/src/vendorcode/google/chromeos/vbnv.c index 424005ad38..d98f650404 100644 --- a/src/vendorcode/google/chromeos/vbnv.c +++ b/src/vendorcode/google/chromeos/vbnv.c @@ -53,7 +53,25 @@ #define CRC_OFFSET 15 static int vbnv_initialized CAR_GLOBAL; -uint8_t vbnv[CONFIG_VBNV_SIZE] CAR_GLOBAL; +static uint8_t vbnv[CONFIG_VBNV_SIZE] CAR_GLOBAL; + +/* Wrappers for accessing the variables marked as CAR_GLOBAL. */ +static inline int is_vbnv_initialized(void) +{ + return car_get_var(vbnv_initialized); +} + +static inline uint8_t *vbnv_data_addr(int index) +{ + uint8_t *vbnv_arr = car_get_var_ptr(vbnv); + + return &vbnv_arr[index]; +} + +static inline uint8_t vbnv_data(int index) +{ + return *vbnv_data_addr(index); +} /* Return CRC-8 of the data, using x^8 + x^2 + x + 1 polynomial. A * table-based algorithm would be faster, but for only 15 bytes isn't @@ -109,21 +127,21 @@ void save_vbnv(const uint8_t *vbnv_copy) static void vbnv_setup(void) { - read_vbnv(vbnv); - vbnv_initialized = 1; + read_vbnv(vbnv_data_addr(0)); + car_set_var(vbnv_initialized, 1); } int get_recovery_mode_from_vbnv(void) { - if (!vbnv_initialized) + if (!is_vbnv_initialized()) vbnv_setup(); - return vbnv[RECOVERY_OFFSET]; + return vbnv_data(RECOVERY_OFFSET); } int vboot_wants_oprom(void) { - if (!vbnv_initialized) + if (!is_vbnv_initialized()) vbnv_setup(); - return (vbnv[BOOT_OFFSET] & BOOT_OPROM_NEEDED) ? 1 : 0; + return (vbnv_data(BOOT_OFFSET) & BOOT_OPROM_NEEDED) ? 1 : 0; }