From 319d433d6864945c19103f0a779467f66d599c67 Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Tue, 24 Jul 2012 09:14:43 -0700 Subject: Calculate the hash only of the actual RW code No need to hash a bunch of 0xff's at the end. We explicitly set a 0xea byte after the end of the code in firmware_image.lds.S. BUG=chrome-os-partner:11087 TEST=look for the hash start line in the EC debug output: [0.011543 hash start 0x00014000 0x00011590] The second number is the code size. It should be the same size as ec.RW.bin, instead of 0x14000. Change-Id: Ibc94851dc1a09eb46cad46bb97dc5762f9c521f0 Signed-off-by: Randall Spangler Reviewed-on: https://gerrit.chromium.org/gerrit/28300 --- common/system_common.c | 35 ++++++++++++++++++++++++++++++----- common/vboot_hash.c | 3 ++- include/system.h | 13 ++++++++++++- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/common/system_common.c b/common/system_common.c index 22e42272c2..2fd978d6cd 100644 --- a/common/system_common.c +++ b/common/system_common.c @@ -31,7 +31,6 @@ struct jump_tag { uint8_t data_version; }; - /* * Data passed between the current image and the next one when jumping between * images. @@ -230,6 +229,32 @@ enum system_image_copy_t system_get_image_copy(void) return SYSTEM_IMAGE_UNKNOWN; } +int system_get_image_used(enum system_image_copy_t copy) +{ + const uint8_t *image; + int size = 0; + + if (copy == SYSTEM_IMAGE_RO) { + image = (const uint8_t *)CONFIG_SECTION_RO_OFF; + size = CONFIG_SECTION_RO_SIZE; + } else if (copy == SYSTEM_IMAGE_RW) { + image = (const uint8_t *)CONFIG_SECTION_RW_OFF; + size = CONFIG_SECTION_RW_SIZE; + } + + if (size <= 0) + return 0; + + /* If the last byte isn't 0xff, the image is completely full */ + if (image[size - 1] != 0xff) + return size; + + /* Scan backwards looking for 0xea byte */ + for (size--; size > 0 && image[size] != 0xea; size--) + ; + + return size; +} /* Returns true if the given range is overlapped with the active image. * @@ -606,11 +631,11 @@ DECLARE_CONSOLE_COMMAND(hibernate, command_hibernate, static int command_version(int argc, char **argv) { - ccprintf("Chip: %s %s %s\n", system_get_chip_vendor(), + ccprintf("Chip: %s %s %s\n", system_get_chip_vendor(), system_get_chip_name(), system_get_chip_revision()); - ccprintf("Board: %d\n", system_get_board_version()); - ccprintf("RO: %s\n", system_get_version(SYSTEM_IMAGE_RO)); - ccprintf("RW: %s\n", system_get_version(SYSTEM_IMAGE_RW)); + ccprintf("Board: %d\n", system_get_board_version()); + ccprintf("RO: %s\n", system_get_version(SYSTEM_IMAGE_RO)); + ccprintf("RW: %s\n", system_get_version(SYSTEM_IMAGE_RW)); ccprintf("Build: %s\n", system_get_build_info()); return EC_SUCCESS; } diff --git a/common/vboot_hash.c b/common/vboot_hash.c index c8afce6efe..49e3e4797b 100644 --- a/common/vboot_hash.c +++ b/common/vboot_hash.c @@ -114,7 +114,8 @@ static void vboot_hash_init(void) } else { /* Start computing the hash of firmware A */ vboot_hash_start(CONFIG_FW_RW_OFF - CONFIG_FLASH_BASE, - CONFIG_FW_RW_SIZE, NULL, 0); + system_get_image_used(SYSTEM_IMAGE_RW), + NULL, 0); } } diff --git a/include/system.h b/include/system.h index 4bcde16aae..d1975c9fed 100644 --- a/include/system.h +++ b/include/system.h @@ -104,12 +104,23 @@ const uint8_t *system_get_jump_tag(uint16_t tag, int *version, int *size); /* Return the address just past the last usable byte in RAM. */ int system_usable_ram_end(void); -/* Returns true if the given range is overlapped with the active image. */ +/* Return true if the given range is overlapped with the active image. */ int system_unsafe_to_overwrite(uint32_t offset, uint32_t size); /* Return a text description of the image copy which is currently running. */ const char *system_get_image_copy_string(void); +/** + * Return the number of bytes used in the specified image. + * + * This is the actual size of code+data in the image, as opposed to the + * amount of space reserved in flash for that image. + * + * @return actual image size in bytes, 0 if the image contains no content or + * error. + */ +int system_get_image_used(enum system_image_copy_t copy); + /* Jump to the specified image copy. */ int system_run_image_copy(enum system_image_copy_t copy); -- cgit v1.2.1