From 7cbb815732d7434f5985d3b50a869aa71ba5c507 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Thu, 12 Jan 2017 09:40:10 -0800 Subject: version: Store image size data in version struct Store our image size (known at build time) in our version struct (now renamed to image_data). This will allow us to more efficiently determine the size of an image in a follow-up CL. Note that compatibility is broken for old ROs that do not include this CL. BUG=chromium:577915 TEST=Verify on kevin + lars + lars_pd that stored image size matches output of system_get_image_used() for both RO and RW images. BRANCH=None Change-Id: I49ea5fc27a7f11f66daba485a87d0dfe7d0c770f Signed-off-by: Shawn Nematbakhsh Reviewed-on: https://chromium-review.googlesource.com/427408 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Randall Spangler --- common/system.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'common/system.c') diff --git a/common/system.c b/common/system.c index ddabe3aa3c..28d846c0c5 100644 --- a/common/system.c +++ b/common/system.c @@ -616,14 +616,14 @@ int system_run_image_copy(enum system_image_copy_t copy) __attribute__((weak)) /* Weird chips may need their own implementations */ const char *system_get_version(enum system_image_copy_t copy) { - static struct version_struct v; + static struct image_data data; uintptr_t addr; enum system_image_copy_t active_copy = system_get_image_copy(); /* Handle version of current image */ if (copy == active_copy || copy == SYSTEM_IMAGE_UNKNOWN) - return &version_data.version[0]; + return ¤t_image_data.version[0]; if (active_copy == SYSTEM_IMAGE_UNKNOWN) return ""; @@ -632,7 +632,7 @@ const char *system_get_version(enum system_image_copy_t copy) * The version string is always located after the reset vectors, so * it's the same offset as in the current image. Find that offset. */ - addr = ((uintptr_t)&version_data - + addr = ((uintptr_t)¤t_image_data - get_program_memory_addr(active_copy)); /* @@ -646,19 +646,19 @@ const char *system_get_version(enum system_image_copy_t copy) #ifdef CONFIG_MAPPED_STORAGE addr += CONFIG_MAPPED_STORAGE_BASE; flash_lock_mapped_storage(1); - memcpy(&v, (const void *)addr, sizeof(v)); + memcpy(&data, (const void *)addr, sizeof(data)); flash_lock_mapped_storage(0); #else /* Read the version struct from flash into a buffer. */ - if (flash_read(addr, sizeof(v), (char *)&v)) + if (flash_read(addr, sizeof(data), (char *)&data)) return ""; #endif /* Make sure the version struct cookies match before returning the * version string. */ - if (v.cookie1 == version_data.cookie1 && - v.cookie2 == version_data.cookie2) - return v.version; + if (data.cookie1 == current_image_data.cookie1 && + data.cookie2 == current_image_data.cookie2) + return data.version; return ""; } -- cgit v1.2.1