summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2017-01-12 09:40:10 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-03-16 00:11:41 -0700
commit3c4c83b8c3ec35af3a7ba19116e8467e9a09cc80 (patch)
tree3dc05b0e24a6c7840ce93d3069d4c998eaed08c3
parent2a1cbf87821f311d98dd5d75707877b92b1d6df2 (diff)
downloadchrome-ec-3c4c83b8c3ec35af3a7ba19116e8467e9a09cc80.tar.gz
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: I7b8dc3ac8cf2df3184d0701a0e0ec8032de8d81b Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/450858 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
-rw-r--r--board/plankton/usb_pd_policy.c2
-rw-r--r--chip/g/system.c15
-rw-r--r--chip/mec1322/lfw/ec_lfw.c2
-rw-r--r--chip/mec1322/lfw/ec_lfw.ld2
-rw-r--r--common/fmap.c14
-rw-r--r--common/system.c16
-rw-r--r--common/usb_pd_policy.c2
-rw-r--r--common/version.c18
-rw-r--r--core/cortex-m/ec.lds.S8
-rw-r--r--core/cortex-m0/ec.lds.S4
-rw-r--r--core/nds32/ec.lds.S2
-rw-r--r--include/version.h12
12 files changed, 56 insertions, 41 deletions
diff --git a/board/plankton/usb_pd_policy.c b/board/plankton/usb_pd_policy.c
index d1f0a8487e..6db20d33cb 100644
--- a/board/plankton/usb_pd_policy.c
+++ b/board/plankton/usb_pd_policy.c
@@ -289,7 +289,7 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload, uint32_t **rpayload)
*rpayload = payload;
switch (cmd) {
case VDO_CMD_VERSION:
- memcpy(payload + 1, &version_data.version, 24);
+ memcpy(payload + 1, &current_image_data.version, 24);
rsize = 7;
break;
default:
diff --git a/chip/g/system.c b/chip/g/system.c
index e92899a58c..0e33bcef00 100644
--- a/chip/g/system.c
+++ b/chip/g/system.c
@@ -267,7 +267,7 @@ static char vers_str[MAX_RO_VER_LEN];
const char *system_get_version(enum system_image_copy_t copy)
{
- const struct version_struct *v;
+ const struct image_data *data;
const struct SignedHeader *h;
enum system_image_copy_t this_copy;
uintptr_t vaddr, delta;
@@ -298,7 +298,7 @@ const char *system_get_version(enum system_image_copy_t copy)
if (copy == this_copy) {
snprintf(vers_str, sizeof(vers_str), "%d.%d.%d/%s",
h->epoch_, h->major_, h->minor_,
- version_data.version);
+ current_image_data.version);
return vers_str;
}
@@ -307,7 +307,7 @@ const char *system_get_version(enum system_image_copy_t copy)
* puts the version string right after the reset vectors, so
* it's at the same relative offset. Measure that offset here.
*/
- delta = (uintptr_t)&version_data - vaddr;
+ delta = (uintptr_t)&current_image_data - vaddr;
/* Now look at that offset in the requested image */
vaddr = get_program_memory_addr(copy);
@@ -315,17 +315,18 @@ const char *system_get_version(enum system_image_copy_t copy)
break;
h = (const struct SignedHeader *)vaddr;
vaddr += delta;
- v = (const struct version_struct *)vaddr;
+ data = (const struct image_data *)vaddr;
/*
* Make sure the version struct cookies match before returning
* the version string.
*/
- if (v->cookie1 == version_data.cookie1 &&
- v->cookie2 == version_data.cookie2 &&
+ if (data->cookie1 == current_image_data.cookie1 &&
+ data->cookie2 == current_image_data.cookie2 &&
h->magic) { /* Corrupted header's magic is set to zero. */
snprintf(vers_str, sizeof(vers_str), "%d.%d.%d/%s",
- h->epoch_, h->major_, h->minor_, v->version);
+ h->epoch_, h->major_, h->minor_,
+ data->version);
return vers_str;
}
default:
diff --git a/chip/mec1322/lfw/ec_lfw.c b/chip/mec1322/lfw/ec_lfw.c
index 6824d10686..b99d33d011 100644
--- a/chip/mec1322/lfw/ec_lfw.c
+++ b/chip/mec1322/lfw/ec_lfw.c
@@ -256,7 +256,7 @@ void lfw_main()
spi_enable(CONFIG_SPI_FLASH_PORT, 1);
uart_puts("littlefw ");
- uart_puts(version_data.version);
+ uart_puts(current_image_data.version);
uart_puts("\n");
switch (system_get_image_copy()) {
diff --git a/chip/mec1322/lfw/ec_lfw.ld b/chip/mec1322/lfw/ec_lfw.ld
index 55b5fda390..adb8b30bba 100644
--- a/chip/mec1322/lfw/ec_lfw.ld
+++ b/chip/mec1322/lfw/ec_lfw.ld
@@ -53,4 +53,6 @@ SECTIONS
. = ORIGIN(SRAM) + LENGTH(SRAM) - 1;
BYTE(0xFF); /* emit at least a byte to make linker happy */
}
+
+ __image_size = LOADADDR(.text) + SIZEOF(.text) - ORIGIN(VECTOR);
}
diff --git a/common/fmap.c b/common/fmap.c
index f46b29b68e..c86d28b5ca 100644
--- a/common/fmap.c
+++ b/common/fmap.c
@@ -114,9 +114,9 @@ const struct _ec_fmap {
.area_name = "RO_FRID",
.area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
FMAP_REGION_START + CONFIG_RO_STORAGE_OFF +
- RELATIVE_RO((uint32_t)__version_struct_offset) +
- offsetof(struct version_struct, version),
- .area_size = sizeof(version_data.version),
+ RELATIVE_RO((uint32_t)__image_data_offset) +
+ offsetof(struct image_data, version),
+ .area_size = sizeof(current_image_data.version),
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -167,15 +167,15 @@ const struct _ec_fmap {
* RW firmware version ID. Must be NULL terminated
* ASCII, and padded with \0.
* TODO: Get the relative offset of
- * __version_struct_offset within our RW image to
+ * __image_data_offset within our RW image to
* accommodate image asymmetry.
*/
.area_name = "RW_FWID",
.area_offset = CONFIG_EC_WRITABLE_STORAGE_OFF -
FMAP_REGION_START + CONFIG_RW_STORAGE_OFF +
- RELATIVE_RO((uint32_t)__version_struct_offset) +
- offsetof(struct version_struct, version),
- .area_size = sizeof(version_data.version),
+ RELATIVE_RO((uint32_t)__image_data_offset) +
+ offsetof(struct image_data, version),
+ .area_size = sizeof(current_image_data.version),
.area_flags = FMAP_AREA_STATIC,
},
#ifdef CONFIG_RWSIG_TYPE_RWSIG
diff --git a/common/system.c b/common/system.c
index 02be2e81a0..4caf7b799d 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 &current_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)&current_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 "";
}
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index 0f2ab48d08..6c33d48f58 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -959,7 +959,7 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload)
switch (PD_VDO_CMD(payload[0])) {
case VDO_CMD_VERSION:
- memcpy(payload + 1, &version_data.version, 24);
+ memcpy(payload + 1, &current_image_data.version, 24);
rsize = 7;
break;
case VDO_CMD_REBOOT:
diff --git a/common/version.c b/common/version.c
index 3757c9d5b4..ff8207bf2c 100644
--- a/common/version.c
+++ b/common/version.c
@@ -10,11 +10,14 @@
#include "ec_version.h"
#include "version.h"
-const struct version_struct __keep version_data
+const struct image_data __keep current_image_data
__attribute__((section(".rodata.ver"))) = {
- CROS_EC_VERSION_COOKIE1,
- CROS_EC_VERSION32,
- CROS_EC_VERSION_COOKIE2
+ .cookie1 = CROS_EC_IMAGE_DATA_COOKIE1,
+ .version = CROS_EC_VERSION32,
+#ifndef TEST_BUILD
+ .size = (const uintptr_t)&__image_size,
+#endif
+ .cookie2 = CROS_EC_IMAGE_DATA_COOKIE2,
};
const char build_info[] __keep __attribute__((section(".rodata.buildinfo"))) =
@@ -32,7 +35,7 @@ uint32_t ver_get_numcommits(void)
* we want to return the numcommits as an int.
*/
for (i = 0; i < 32; i++) {
- if (version_data.version[i] == '.') {
+ if (current_image_data.version[i] == '.') {
numperiods++;
if (numperiods == 2)
break;
@@ -41,12 +44,11 @@ uint32_t ver_get_numcommits(void)
i++;
for (; i < 32; i++) {
- if (version_data.version[i] == '-')
+ if (current_image_data.version[i] == '-')
break;
ret *= 10;
- ret += version_data.version[i] - '0';
+ ret += current_image_data.version[i] - '0';
}
return (i == 32 ? 0 : ret);
}
-
diff --git a/core/cortex-m/ec.lds.S b/core/cortex-m/ec.lds.S
index 84071097ca..77db031076 100644
--- a/core/cortex-m/ec.lds.S
+++ b/core/cortex-m/ec.lds.S
@@ -79,7 +79,7 @@ SECTIONS
#endif
STRINGIFY(OUTDIR/core/CORE/init.o) (.text.vecttable)
. = ALIGN(4);
- __version_struct_offset = .;
+ __image_data_offset = .;
KEEP(*(.rodata.ver))
. = ALIGN(4);
@@ -353,6 +353,12 @@ SECTIONS
) >= (LOADADDR(.data) + SIZEOF(.data) - FW_OFF(SECTION)),
"No room left in the flash")
+#if defined(SECTION_IS_RO) && defined(NPCX_RO_HEADER)
+ __image_size = __hey_flash_used - FW_SIZE(RO_HDR);
+#else
+ __image_size = __hey_flash_used;
+#endif
+
#ifdef CONFIG_USB_RAM_SIZE
.usb_ram (NOLOAD) : {
__usb_ram_start = .;
diff --git a/core/cortex-m0/ec.lds.S b/core/cortex-m0/ec.lds.S
index e9cd726d7a..98840266e4 100644
--- a/core/cortex-m0/ec.lds.S
+++ b/core/cortex-m0/ec.lds.S
@@ -41,7 +41,7 @@ SECTIONS
.text : {
STRINGIFY(OUTDIR/core/CORE/init.o) (.text.vecttable)
. = ALIGN(4);
- __version_struct_offset = .;
+ __image_data_offset = .;
KEEP(*(.rodata.ver))
. = ALIGN(4);
@@ -240,6 +240,8 @@ SECTIONS
) >= (LOADADDR(.data) + SIZEOF(.data) - FW_OFF(SECTION)),
"No room left in the flash")
+ __image_size = __hey_flash_used;
+
#ifdef CONFIG_USB_RAM_SIZE
.usb_ram (NOLOAD) : {
__usb_ram_start = .;
diff --git a/core/nds32/ec.lds.S b/core/nds32/ec.lds.S
index d497099169..0557cbca38 100644
--- a/core/nds32/ec.lds.S
+++ b/core/nds32/ec.lds.S
@@ -36,7 +36,7 @@ SECTIONS
"__flash_dma_start has to be 4k-byte aligned");
KEEP(STRINGIFY(OUTDIR/core/CORE/init.o) (.text.vecttable))
. = ALIGN(4);
- __version_struct_offset = .;
+ __image_data_offset = .;
KEEP(*(.rodata.ver))
. = ALIGN(4);
KEEP(STRINGIFY(OUTDIR/core/CORE/init.o) (.text.vectirq))
diff --git a/include/version.h b/include/version.h
index 8853d76561..94e8dd9ed5 100644
--- a/include/version.h
+++ b/include/version.h
@@ -10,18 +10,20 @@
#include "common.h"
-#define CROS_EC_VERSION_COOKIE1 0xce112233
-#define CROS_EC_VERSION_COOKIE2 0xce445566
+#define CROS_EC_IMAGE_DATA_COOKIE1 0xce778899
+#define CROS_EC_IMAGE_DATA_COOKIE2 0xceaabbcc
-struct version_struct {
+struct image_data {
uint32_t cookie1;
char version[32];
+ uint32_t size;
uint32_t cookie2;
} __packed;
-extern const struct version_struct version_data;
+extern const struct image_data current_image_data;
extern const char build_info[];
-extern const char __version_struct_offset[];
+extern const char __image_data_offset[];
+extern const void *__image_size;
/**
* Get the number of commits field from version string.