summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-09-07 13:47:48 -0700
committerchrome-bot <chrome-bot@chromium.org>2015-09-16 14:49:32 -0700
commit1167cad6a88e45bbf6a5599f19d018cd6a8b5233 (patch)
treeeaff44a061fa989b49a5c52fc58ef14f3ccb48c3 /common
parent558c465165acf494905fa59c822c7190b4646899 (diff)
downloadchrome-ec-1167cad6a88e45bbf6a5599f19d018cd6a8b5233.tar.gz
cleanup: Change meaning of storage offset CONFIGs
In order to support architectures with non-contiguous writable and protected regions, change storage offsets to be relative to writable and protected regions, rather than relative to "the start of the region of storage belonging to the EC". Spec doc available at https://goo.gl/fnzTvr. BRANCH=None BUG=chrome-os-partner:23796 TEST=With entire patch series, on both Samus and Glados: - Verify 'version' EC console command is correct - Verify 'flashrom -p ec -r read.bin' reads back EC image - Verify software sync correctly flashes both EC and PD RW images Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Change-Id: I796f8e7305a6336495bd256a78774595cb16a2e4 Reviewed-on: https://chromium-review.googlesource.com/297823 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common')
-rw-r--r--common/flash.c41
-rw-r--r--common/fmap.c41
-rw-r--r--common/system.c17
-rw-r--r--common/usb_pd_policy.c12
-rw-r--r--common/vboot_hash.c13
5 files changed, 91 insertions, 33 deletions
diff --git a/common/flash.c b/common/flash.c
index b2c3847e60..72dbe35843 100644
--- a/common/flash.c
+++ b/common/flash.c
@@ -722,11 +722,24 @@ DECLARE_CONSOLE_COMMAND(flashwp, command_flash_wp,
/*****************************************************************************/
/* Host commands */
+/*
+ * All internal EC code assumes that offsets are provided relative to
+ * physical address zero of storage. In some cases, the region of storage
+ * belonging to the EC is not physical address zero - a non-zero fmap_base
+ * indicates so. Since fmap_base is not yet handled correctly by external
+ * code, we must perform the adjustment in our host command handlers -
+ * adjust all offsets so they are relative to the beginning of the storage
+ * region belonging to the EC. TODO(crbug.com/529365): Handle fmap_base
+ * correctly in flashrom, dump_fmap, etc. and remove EC_FLASH_REGION_START.
+ */
+#define EC_FLASH_REGION_START MIN(CONFIG_EC_PROTECTED_STORAGE_OFF, \
+ CONFIG_EC_WRITABLE_STORAGE_OFF)
+
static int flash_command_get_info(struct host_cmd_handler_args *args)
{
struct ec_response_flash_info_1 *r = args->response;
- r->flash_size = CONFIG_FLASH_SIZE;
+ r->flash_size = CONFIG_FLASH_SIZE - EC_FLASH_REGION_START;
r->write_block_size = CONFIG_FLASH_WRITE_SIZE;
r->erase_block_size = CONFIG_FLASH_ERASE_SIZE;
r->protect_block_size = CONFIG_FLASH_BANK_SIZE;
@@ -772,11 +785,12 @@ DECLARE_HOST_COMMAND(EC_CMD_FLASH_INFO,
static int flash_command_read(struct host_cmd_handler_args *args)
{
const struct ec_params_flash_read *p = args->params;
+ uint32_t offset = p->offset + EC_FLASH_REGION_START;
if (p->size > args->response_max)
return EC_RES_OVERFLOW;
- if (flash_read(p->offset, p->size, args->response))
+ if (flash_read(offset, p->size, args->response))
return EC_RES_ERROR;
args->response_size = p->size;
@@ -796,6 +810,7 @@ DECLARE_HOST_COMMAND(EC_CMD_FLASH_READ,
static int flash_command_write(struct host_cmd_handler_args *args)
{
const struct ec_params_flash_write *p = args->params;
+ uint32_t offset = p->offset + EC_FLASH_REGION_START;
if (flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW)
return EC_RES_ACCESS_DENIED;
@@ -803,10 +818,10 @@ static int flash_command_write(struct host_cmd_handler_args *args)
if (p->size + sizeof(*p) > args->params_size)
return EC_RES_INVALID_PARAM;
- if (system_unsafe_to_overwrite(p->offset, p->size))
+ if (system_unsafe_to_overwrite(offset, p->size))
return EC_RES_ACCESS_DENIED;
- if (flash_write(p->offset, p->size, (const uint8_t *)(p + 1)))
+ if (flash_write(offset, p->size, (const uint8_t *)(p + 1)))
return EC_RES_ERROR;
return EC_RES_SUCCESS;
@@ -818,11 +833,12 @@ DECLARE_HOST_COMMAND(EC_CMD_FLASH_WRITE,
static int flash_command_erase(struct host_cmd_handler_args *args)
{
const struct ec_params_flash_erase *p = args->params;
+ uint32_t offset = p->offset + EC_FLASH_REGION_START;
if (flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW)
return EC_RES_ACCESS_DENIED;
- if (system_unsafe_to_overwrite(p->offset, p->size))
+ if (system_unsafe_to_overwrite(offset, p->size))
return EC_RES_ACCESS_DENIED;
/* Indicate that we might be a while */
@@ -830,7 +846,7 @@ static int flash_command_erase(struct host_cmd_handler_args *args)
args->result = EC_RES_IN_PROGRESS;
host_send_response(args);
#endif
- if (flash_erase(p->offset, p->size))
+ if (flash_erase(offset, p->size))
return EC_RES_ERROR;
return EC_RES_SUCCESS;
@@ -890,16 +906,21 @@ static int flash_command_region_info(struct host_cmd_handler_args *args)
switch (p->region) {
case EC_FLASH_REGION_RO:
- r->offset = CONFIG_RO_STORAGE_OFF;
+ r->offset = CONFIG_EC_PROTECTED_STORAGE_OFF +
+ CONFIG_RO_STORAGE_OFF -
+ EC_FLASH_REGION_START;
r->size = CONFIG_RO_SIZE;
break;
case EC_FLASH_REGION_RW:
- r->offset = CONFIG_RW_STORAGE_OFF;
+ r->offset = CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_STORAGE_OFF -
+ EC_FLASH_REGION_START;
r->size = CONFIG_RW_SIZE;
break;
case EC_FLASH_REGION_WP_RO:
- r->offset = CONFIG_WP_OFF;
- r->size = CONFIG_WP_SIZE;
+ r->offset = CONFIG_WP_STORAGE_OFF -
+ EC_FLASH_REGION_START;
+ r->size = CONFIG_WP_STORAGE_SIZE;
break;
default:
return EC_RES_INVALID_PARAM;
diff --git a/common/fmap.c b/common/fmap.c
index 4fbafe6f91..35111c6d1d 100644
--- a/common/fmap.c
+++ b/common/fmap.c
@@ -7,6 +7,7 @@
#include <stddef.h>
#include "common.h"
+#include "util.h"
#include "version.h"
/* FMAP structs. See http://code.google.com/p/flashmap/wiki/FmapSpec */
@@ -20,10 +21,25 @@
* For address containing CONFIG_PROGRAM_MEMORY_BASE (symbols in *.RO.lds.S and
* variable), this computes the offset to the start of the image on flash.
*/
-
#define RELATIVE_RO(addr) ((addr) - CONFIG_PROGRAM_MEMORY_BASE - \
CONFIG_RO_MEM_OFF)
+/*
+ * All internal EC code assumes that offsets are provided relative to
+ * physical address zero of storage. In some cases, the region of storage
+ * belonging to the EC is not physical address zero - a non-zero fmap_base
+ * indicates so. Since fmap_base is not yet handled correctly by external
+ * code, we must perform the adjustment in our host command handlers -
+ * adjust all offsets so they are relative to the beginning of the storage
+ * region belonging to the EC. TODO(crbug.com/529365): Handle fmap_base
+ * correctly in flashrom, dump_fmap, etc. and remove EC_FLASH_REGION_START.
+ */
+#if CONFIG_EC_WRITABLE_STORAGE_OFF < CONFIG_EC_PROTECTED_STORAGE_OFF
+#define FMAP_REGION_START CONFIG_EC_WRITABLE_STORAGE_OFF
+#else
+#define FMAP_REGION_START CONFIG_EC_PROTECTED_STORAGE_OFF
+#endif
+
struct fmap_header {
char fmap_signature[FMAP_SIGNATURE_SIZE];
uint8_t fmap_ver_major;
@@ -71,14 +87,16 @@ const struct _ec_fmap {
* volatile data (ex, calibration results).
*/
.area_name = "EC_RO",
- .area_offset = CONFIG_RO_STORAGE_OFF,
+ .area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
+ FMAP_REGION_START + CONFIG_RO_STORAGE_OFF,
.area_size = CONFIG_RO_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
{
/* (Optional) RO firmware code. */
.area_name = "FR_MAIN",
- .area_offset = CONFIG_RO_STORAGE_OFF,
+ .area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
+ FMAP_REGION_START + CONFIG_RO_STORAGE_OFF,
.area_size = CONFIG_RO_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -88,7 +106,8 @@ const struct _ec_fmap {
* ASCII, and padded with \0.
*/
.area_name = "RO_FRID",
- .area_offset = CONFIG_RO_STORAGE_OFF +
+ .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),
@@ -98,7 +117,8 @@ const struct _ec_fmap {
/* Other RO stuff: FMAP, WP, KEYS, etc. */
{
.area_name = "FMAP",
- .area_offset = CONFIG_RO_STORAGE_OFF +
+ .area_offset = CONFIG_EC_PROTECTED_STORAGE_OFF -
+ FMAP_REGION_START + CONFIG_RO_STORAGE_OFF +
RELATIVE_RO((uint32_t)&ec_fmap),
.area_size = sizeof(ec_fmap),
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
@@ -110,8 +130,9 @@ const struct _ec_fmap {
* EC_RO and aligned to hardware specification.
*/
.area_name = "WP_RO",
- .area_offset = CONFIG_WP_OFF,
- .area_size = CONFIG_WP_SIZE,
+ .area_offset = CONFIG_WP_STORAGE_OFF -
+ FMAP_REGION_START,
+ .area_size = CONFIG_WP_STORAGE_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -119,7 +140,8 @@ const struct _ec_fmap {
{
/* The range of RW firmware to be auto-updated. */
.area_name = "EC_RW",
- .area_offset = CONFIG_RW_STORAGE_OFF,
+ .area_offset = CONFIG_EC_WRITABLE_STORAGE_OFF -
+ FMAP_REGION_START + CONFIG_RW_STORAGE_OFF,
.area_size = CONFIG_RW_SIZE,
.area_flags = FMAP_AREA_STATIC | FMAP_AREA_RO,
},
@@ -132,7 +154,8 @@ const struct _ec_fmap {
* accomodate image asymmetry.
*/
.area_name = "RW_FWID",
- .area_offset = CONFIG_RW_STORAGE_OFF +
+ .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),
diff --git a/common/system.c b/common/system.c
index 690403a94f..3d3d3d24cd 100644
--- a/common/system.c
+++ b/common/system.c
@@ -351,8 +351,9 @@ int system_get_image_used(enum system_image_copy_t copy)
* the end of the image.
*/
#ifndef CONFIG_MAPPED_STORAGE
- image_offset = (copy == SYSTEM_IMAGE_RW) ? CONFIG_RW_STORAGE_OFF :
- CONFIG_RO_STORAGE_OFF;
+ image_offset = (copy == SYSTEM_IMAGE_RW) ?
+ CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF :
+ CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF;
image = buf;
do {
@@ -382,11 +383,13 @@ test_mockable int system_unsafe_to_overwrite(uint32_t offset, uint32_t size)
switch (system_get_image_copy()) {
case SYSTEM_IMAGE_RO:
- r_offset = CONFIG_RO_STORAGE_OFF;
+ r_offset = CONFIG_EC_PROTECTED_STORAGE_OFF +
+ CONFIG_RO_STORAGE_OFF;
r_size = CONFIG_RO_SIZE;
break;
case SYSTEM_IMAGE_RW:
- r_offset = CONFIG_RW_STORAGE_OFF;
+ r_offset = CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_STORAGE_OFF;
r_size = CONFIG_RW_SIZE;
break;
default:
@@ -564,10 +567,12 @@ const char *system_get_version(enum system_image_copy_t copy)
* Read the version information from the proper location
* on storage.
*/
- addr += (copy == SYSTEM_IMAGE_RW) ? CONFIG_RW_STORAGE_OFF :
- CONFIG_RO_STORAGE_OFF;
+ addr += (copy == SYSTEM_IMAGE_RW) ?
+ CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF :
+ CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF;
#ifdef CONFIG_MAPPED_STORAGE
+ addr += CONFIG_MAPPED_STORAGE_BASE;
v = (const struct version_struct *)addr;
#else
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index e628e6e556..0cd4160614 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -816,7 +816,8 @@ DECLARE_HOST_COMMAND(EC_CMD_USB_PD_GET_AMODE,
#endif
-#define FW_RW_END (CONFIG_RW_STORAGE_OFF + CONFIG_RW_SIZE)
+#define FW_RW_END (CONFIG_EC_WRITABLE_STORAGE_OFF + \
+ CONFIG_RW_STORAGE_OFF + CONFIG_RW_SIZE)
uint8_t *flash_hash_rw(void)
{
@@ -878,14 +879,17 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload)
if (system_get_image_copy() != SYSTEM_IMAGE_RO)
break;
pd_log_event(PD_EVENT_ACC_RW_ERASE, 0, 0, NULL);
- flash_offset = CONFIG_RW_STORAGE_OFF;
- flash_physical_erase(CONFIG_RW_STORAGE_OFF, CONFIG_RW_SIZE);
+ flash_offset = CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_STORAGE_OFF;
+ flash_physical_erase(CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_STORAGE_OFF, CONFIG_RW_SIZE);
rw_flash_changed = 1;
break;
case VDO_CMD_FLASH_WRITE:
/* do not kill the code under our feet */
if ((system_get_image_copy() != SYSTEM_IMAGE_RO) ||
- (flash_offset < CONFIG_RW_STORAGE_OFF))
+ (flash_offset < CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_STORAGE_OFF))
break;
flash_physical_write(flash_offset, 4*(cnt - 1),
(const char *)(payload+1));
diff --git a/common/vboot_hash.c b/common/vboot_hash.c
index 7726ef7043..e90fe50b07 100644
--- a/common/vboot_hash.c
+++ b/common/vboot_hash.c
@@ -222,7 +222,8 @@ static void vboot_hash_init(void)
#endif
{
/* Start computing the hash of RW firmware */
- vboot_hash_start(CONFIG_RW_STORAGE_OFF,
+ vboot_hash_start(CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_STORAGE_OFF,
system_get_image_used(SYSTEM_IMAGE_RW),
NULL, 0);
}
@@ -256,7 +257,8 @@ DECLARE_HOOK(HOOK_SYSJUMP, vboot_hash_preserve_state, HOOK_PRIO_DEFAULT);
#ifdef CONFIG_CMD_HASH
static int command_hash(int argc, char **argv)
{
- uint32_t offset = CONFIG_RW_STORAGE_OFF;
+ uint32_t offset = CONFIG_EC_WRITABLE_STORAGE_OFF +
+ CONFIG_RW_STORAGE_OFF;
uint32_t size = CONFIG_RW_SIZE;
char *e;
@@ -282,11 +284,13 @@ static int command_hash(int argc, char **argv)
return EC_SUCCESS;
} else if (!strcasecmp(argv[1], "rw")) {
return vboot_hash_start(
+ CONFIG_EC_WRITABLE_STORAGE_OFF +
CONFIG_RW_STORAGE_OFF,
system_get_image_used(SYSTEM_IMAGE_RW),
NULL, 0);
} else if (!strcasecmp(argv[1], "ro")) {
return vboot_hash_start(
+ CONFIG_EC_PROTECTED_STORAGE_OFF +
CONFIG_RO_STORAGE_OFF,
system_get_image_used(SYSTEM_IMAGE_RO),
NULL, 0);
@@ -359,10 +363,11 @@ static int host_start_hash(const struct ec_params_vboot_hash *p)
/* Handle special offset values */
if (offset == EC_VBOOT_HASH_OFFSET_RO) {
- offset = CONFIG_RO_STORAGE_OFF;
+ offset = CONFIG_EC_PROTECTED_STORAGE_OFF +
+ CONFIG_RO_STORAGE_OFF;
size = system_get_image_used(SYSTEM_IMAGE_RO);
} else if (p->offset == EC_VBOOT_HASH_OFFSET_RW) {
- offset = CONFIG_RW_STORAGE_OFF;
+ offset = CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF;
size = system_get_image_used(SYSTEM_IMAGE_RW);
}