diff options
author | Divya Jyothi <divya.jyothi@intel.com> | 2015-02-04 17:35:58 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-02-09 18:34:02 +0000 |
commit | ce8266fd558425807226884068931fd66b0ed009 (patch) | |
tree | 0cd6781d914c0f2cd050e26bd417c549419bad1c | |
parent | b9c7de0f76d772645123ee11478659e3f68138a6 (diff) | |
download | chrome-ec-ce8266fd558425807226884068931fd66b0ed009.tar.gz |
Strago: Version string from SPI Flash
- Strago has its RO/RW images in external flash.support added to
to get the version string from external flash
BUG=None
TEST=make -j buildall
BRANCH=strago-mec
Change-Id: Id3d8738a5901f691ec9b2cb180f6fb45df516efc
Signed-off-by: Divya Jyothi <divya.jyothi@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/246212
Reviewed-by: Shawn N <shawnn@chromium.org>
Commit-Queue: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | common/flash.c | 3 | ||||
-rw-r--r-- | common/flash_internal.c | 21 | ||||
-rw-r--r-- | common/system.c | 50 | ||||
-rw-r--r-- | include/flash.h | 4 | ||||
-rw-r--r-- | include/system.h | 18 |
5 files changed, 70 insertions, 26 deletions
diff --git a/common/flash.c b/common/flash.c index e3419d53e2..cb7d6199de 100644 --- a/common/flash.c +++ b/common/flash.c @@ -23,9 +23,6 @@ #define CONFIG_FLASH_ERASED_VALUE32 (-1U) #endif -/* Flags for persist_state.flags */ -/* Protect persist state and RO firmware at boot */ -#define PERSIST_FLAG_PROTECT_RO 0x02 int flash_dataptr(int offset, int size_req, int align, const char **ptrp) { diff --git a/common/flash_internal.c b/common/flash_internal.c index 89a5508b5f..b6368dd36c 100644 --- a/common/flash_internal.c +++ b/common/flash_internal.c @@ -15,6 +15,27 @@ #include "util.h" #include "vboot_hash.h" +uint32_t flash_get_image_used_internal(enum system_image_copy_t copy) +{ + const uint8_t *image; + int size = 0; + + image = (const uint8_t *)system_get_image_base(copy); + size = system_get_image_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. + */ + for (size--; size > 0 && image[size] != 0xea; size--) + ; + return size ? size + 1 : 0; /* 0xea byte IS part of the image */ +} + /** * Get the physical memory address of a flash offset * diff --git a/common/system.c b/common/system.c index cdb940c77b..8bc3dd8f80 100644 --- a/common/system.c +++ b/common/system.c @@ -24,6 +24,7 @@ #include "usb_pd.h" #include "util.h" #include "version.h" +#include "watchdog.h" /* Console output macros */ #define CPUTS(outstr) cputs(CC_SYSTEM, outstr) @@ -91,10 +92,13 @@ static enum ec_reboot_cmd reboot_at_shutdown; /* On-going actions preventing going into deep-sleep mode */ uint32_t sleep_mask; +#ifdef CONFIG_FLASH_SPI +static uint8_t flash_data_ver[sizeof(version_data)]; +#endif /** * Return the base pointer for the image copy, or 0xffffffff if error. */ -static uintptr_t get_base(enum system_image_copy_t copy) +uintptr_t system_get_image_base(enum system_image_copy_t copy) { switch (copy) { case SYSTEM_IMAGE_RO: @@ -109,7 +113,7 @@ static uintptr_t get_base(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) +uint32_t system_get_image_size(enum system_image_copy_t copy) { switch (copy) { case SYSTEM_IMAGE_RO: @@ -331,23 +335,12 @@ test_mockable enum system_image_copy_t system_get_image_copy(void) int system_get_image_used(enum system_image_copy_t copy) { - const uint8_t *image; - int size = 0; - - image = (const uint8_t *)get_base(copy); - size = get_size(copy); - - if (size <= 0) - return 0; +#ifdef CONFIG_FLASH_SPI + return flash_get_image_used_spi(copy); +#else + return flash_get_image_used_internal(copy); +#endif - /* - * 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. - */ - for (size--; size > 0 && image[size] != 0xea; size--) - ; - 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) @@ -473,7 +466,7 @@ int system_run_image_copy(enum system_image_copy_t copy) } /* Load the appropriate reset vector */ - base = get_base(copy); + base = system_get_image_base(copy); if (base == 0xffffffff) return EC_ERROR_INVAL; @@ -484,7 +477,7 @@ int system_run_image_copy(enum system_image_copy_t copy) /* Make sure the reset vector is inside the destination image */ init_addr = *(uintptr_t *)(base + 4); #ifndef EMU_BUILD - if (init_addr < base || init_addr >= base + get_size(copy)) + if (init_addr < base || init_addr >= base + system_get_image_size(copy)) return EC_ERROR_UNKNOWN; #endif #endif @@ -500,24 +493,35 @@ int system_run_image_copy(enum system_image_copy_t copy) const char *system_get_version(enum system_image_copy_t copy) { uintptr_t addr; + uint32_t version_offset; const struct version_struct *v; /* Handle version of current image */ if (copy == system_get_image_copy() || copy == SYSTEM_IMAGE_UNKNOWN) return &RO(version_data).version[0]; - addr = get_base(copy); + addr = system_get_image_base(copy); if (addr == 0xffffffff) return ""; /* The version string is always located after the reset vectors, so * it's the same as in the current image. */ #ifdef CONFIG_CODERAM_ARCH /* TODO: (ML) we run FW in Code RAM */ - addr += ((uintptr_t)&version_data - CONFIG_CDRAM_BASE); + version_offset = ((uintptr_t)&version_data - CONFIG_CDRAM_BASE); #else - addr += ((uintptr_t)&version_data - get_base(system_get_image_copy())); + version_offset = ((uintptr_t)&version_data - + system_get_image_base(system_get_image_copy())); #endif + +#ifdef CONFIG_FLASH_SPI + flash_physical_read(flash_get_image_base_spi(copy) + + version_offset, sizeof(version_data), + (uint8_t *)flash_data_ver); + addr = (uintptr_t)flash_data_ver; +#else + addr += version_offset; +#endif /* Make sure the version struct cookies match before returning the * version string. */ v = (const struct version_struct *)addr; diff --git a/include/flash.h b/include/flash.h index b5ea1afa89..926beba070 100644 --- a/include/flash.h +++ b/include/flash.h @@ -45,6 +45,10 @@ struct persist_state { #define PERSIST_STATE_VERSION 2 /* Expected persist_state.version */ +/* Flags for persist_state.flags */ +/* Protect persist state and RO firmware at boot */ +#define PERSIST_FLAG_PROTECT_RO 0x02 + #ifdef CONFIG_FLASH_SPI /** * Get the memory address of a SPI flash offset where code is loaded diff --git a/include/system.h b/include/system.h index 259e34fc92..0cd026055b 100644 --- a/include/system.h +++ b/include/system.h @@ -151,6 +151,24 @@ const char *system_get_image_copy_string(void); */ const char *system_image_copy_t_to_string(enum system_image_copy_t copy); +/*****************************************************************************/ +/* For use by system level functions. */ +/** + * Get the memory address of a flash offset where code starts executing + * + * @param copy system image type + * @return pointer to flash address offset, if ok, else 0xffffffff + */ +uintptr_t system_get_image_base(enum system_image_copy_t copy); + +/** + * Get the MAX size if the image in the flash + * + * @param offset Flash offset to get address of + * @return size of he image in the flash memory , if ok, else 0 + */ +uint32_t system_get_image_size(enum system_image_copy_t copy); + /** * Return the number of bytes used in the specified image. * |