diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2017-01-12 11:16:06 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-01-30 16:48:41 -0800 |
commit | 93951a491dd00e20addc1ff99c2896bb9752e665 (patch) | |
tree | 557f38dafa66f01afde512970495af7005fe7826 /common | |
parent | 7cbb815732d7434f5985d3b50a869aa71ba5c507 (diff) | |
download | chrome-ec-93951a491dd00e20addc1ff99c2896bb9752e665.tar.gz |
system: Use stored size in image_data for determining image_used
Image used size is now part of the image_data struct present in all
images at a fixed offset, so use it rather than scanning from the end of
the image.
BUG=chromium:577915
TEST=Verify on kevin + lars + lars_pd that system_get_image_used() returns
the same value as the old implementation, for both RO and RW images.
BRANCH=None
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Change-Id: Ic8db5c706d82f7ca2ded2e90129747e7fbefdb38
Reviewed-on: https://chromium-review.googlesource.com/427959
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/system.c | 85 |
1 files changed, 23 insertions, 62 deletions
diff --git a/common/system.c b/common/system.c index 28d846c0c5..5386075979 100644 --- a/common/system.c +++ b/common/system.c @@ -126,7 +126,7 @@ uintptr_t get_program_memory_addr(enum system_image_copy_t copy) /** * Return the size of the image copy, or 0 if error. */ -static uint32_t get_size(enum system_image_copy_t copy) +static uint32_t __attribute__((unused)) get_size(enum system_image_copy_t copy) { /* Ensure we return aligned sizes. */ BUILD_ASSERT(CONFIG_RO_SIZE % SPI_FLASH_MAX_WRITE_SIZE == 0); @@ -364,59 +364,6 @@ test_mockable enum system_image_copy_t system_get_image_copy(void) #endif } -/* - * TODO(crbug.com/577915): Store image used size at build time and simply - * read it back. - */ -int system_get_image_used(enum system_image_copy_t copy) -{ -#ifdef CONFIG_EXTERNAL_STORAGE - static uint8_t buf[SPI_FLASH_MAX_WRITE_SIZE]; -#endif - int image_offset; - const uint8_t *image; - int size; - size = get_size(copy); - if (size <= 0) - return 0; - - /* - * Scan backwards looking for 0xea byte, which is by definition the - * last byte of the image. See ec.lds.S for how this is inserted at - * the end of the image. - */ - image_offset = (copy == SYSTEM_IMAGE_RW) ? - CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF : - CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF; -#ifdef CONFIG_EXTERNAL_STORAGE - image = buf; - - do { - if (image == buf) { - /* No valid image found? */ - if (size < SPI_FLASH_MAX_WRITE_SIZE) - return 0; - - flash_read(image_offset + size - - SPI_FLASH_MAX_WRITE_SIZE, - SPI_FLASH_MAX_WRITE_SIZE, buf); - image = buf + SPI_FLASH_MAX_WRITE_SIZE; - } - - image--, size--; - - } while (*image != 0xea); -#else - image = (const uint8_t *)(image_offset + CONFIG_MAPPED_STORAGE_BASE); - flash_lock_mapped_storage(1); - for (size--; size > 0 && image[size] != 0xea; size--) - ; - flash_lock_mapped_storage(0); -#endif - - return size ? size + 1 : 0; /* 0xea byte IS part of the image */ -} - test_mockable int system_unsafe_to_overwrite(uint32_t offset, uint32_t size) { uint32_t r_offset; @@ -613,8 +560,8 @@ int system_run_image_copy(enum system_image_copy_t copy) return EC_ERROR_UNKNOWN; } -__attribute__((weak)) /* Weird chips may need their own implementations */ -const char *system_get_version(enum system_image_copy_t copy) +static const struct image_data *system_get_image_data( + enum system_image_copy_t copy) { static struct image_data data; @@ -623,10 +570,9 @@ const char *system_get_version(enum system_image_copy_t copy) /* Handle version of current image */ if (copy == active_copy || copy == SYSTEM_IMAGE_UNKNOWN) - return ¤t_image_data.version[0]; - + return ¤t_image_data; if (active_copy == SYSTEM_IMAGE_UNKNOWN) - return ""; + return NULL; /* * The version string is always located after the reset vectors, so @@ -651,16 +597,31 @@ const char *system_get_version(enum system_image_copy_t copy) #else /* Read the version struct from flash into a buffer. */ if (flash_read(addr, sizeof(data), (char *)&data)) - return ""; + return NULL; #endif /* Make sure the version struct cookies match before returning the * version string. */ if (data.cookie1 == current_image_data.cookie1 && data.cookie2 == current_image_data.cookie2) - return data.version; + return &data; + + return NULL; +} + +__attribute__((weak)) /* Weird chips may need their own implementations */ +const char *system_get_version(enum system_image_copy_t copy) +{ + const struct image_data *data = system_get_image_data(copy); + + return data ? data->version : ""; +} + +int system_get_image_used(enum system_image_copy_t copy) +{ + const struct image_data *data = system_get_image_data(copy); - return ""; + return data ? MAX((int)data->size, 0) : 0; } int system_get_board_version(void) |