diff options
author | Nicolas Boichat <drinkcat@google.com> | 2017-04-13 09:32:22 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-04-15 04:08:07 -0700 |
commit | 2b460c9830670070152a4509ab38b24aa80ed304 (patch) | |
tree | 8b5691b01c6bd23eec510861df344ff73f1d866d | |
parent | 2f5e46cef48ec0671fd014bbdb38b060339db998 (diff) | |
download | chrome-ec-2b460c9830670070152a4509ab38b24aa80ed304.tar.gz |
common/update_fw: Remove board-specific rw_sections
rw_sections is defined in the exact same way on all common code
boards, let's remove it, and hard-code the values in update_fw.c
instead.
Take this as an opportunity to fold set_valid_section in
fw_update_start (this will be useful later on, as we also
want to return the inactive region version).
BRANCH=none
BUG=b:35587171
TEST=make buildall -j
TEST=Can update hammer over USB using usb_updater2
Change-Id: I4dd3224f17f89c1851c379255f1195dc54528b3d
Reviewed-on: https://chromium-review.googlesource.com/476451
Commit-Ready: Nicolas Boichat <drinkcat@chromium.org>
Tested-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-by: Nick Sanders <nsanders@chromium.org>
Reviewed-by: Nicolas Boichat <drinkcat@chromium.org>
-rw-r--r-- | board/hammer/board.c | 19 | ||||
-rw-r--r-- | board/polyberry/board.c | 19 | ||||
-rw-r--r-- | board/servo_micro/board.c | 21 | ||||
-rw-r--r-- | board/servo_v4/board.c | 20 | ||||
-rw-r--r-- | board/sweetberry/board.c | 19 | ||||
-rw-r--r-- | board/tigertail/board.c | 21 | ||||
-rw-r--r-- | common/update_fw.c | 72 | ||||
-rw-r--r-- | include/update_fw.h | 19 |
8 files changed, 27 insertions, 183 deletions
diff --git a/board/hammer/board.c b/board/hammer/board.c index baf7b41f08..01f077d91e 100644 --- a/board/hammer/board.c +++ b/board/hammer/board.c @@ -62,25 +62,6 @@ int usb_i2c_board_enable(void) { return EC_SUCCESS; } void usb_i2c_board_disable(void) {} /****************************************************************************** - * Support firmware upgrade over USB. We can update whichever section is not - * the current section. - */ - -/* - * This array defines possible sections available for the firmware update. - * The section which does not map the current executing code is picked as the - * valid update area. The values are offsets into the flash space. - */ -const struct section_descriptor board_rw_sections[] = { - {CONFIG_RO_MEM_OFF, - CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE}, - {CONFIG_RW_MEM_OFF, - CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE}, -}; -const struct section_descriptor * const rw_sections = board_rw_sections; -const int num_rw_sections = ARRAY_SIZE(board_rw_sections); - -/****************************************************************************** * Initialize board. */ static void board_init(void) diff --git a/board/polyberry/board.c b/board/polyberry/board.c index d270498809..65039abd86 100644 --- a/board/polyberry/board.c +++ b/board/polyberry/board.c @@ -47,25 +47,6 @@ struct dwc_usb usb_ctl = { .irq = STM32_IRQ_OTG_HS, }; -/****************************************************************************** - * Support firmware upgrade over USB. We can update whichever section is not - * the current section. - */ - -/* - * This array defines possible sections available for the firmware update. - * The section which does not map the current executing code is picked as the - * valid update area. The values are offsets into the flash space. - */ -const struct section_descriptor board_rw_sections[] = { - {CONFIG_RO_MEM_OFF, - CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE}, - {CONFIG_RW_MEM_OFF, - CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE}, -}; -const struct section_descriptor * const rw_sections = board_rw_sections; -const int num_rw_sections = ARRAY_SIZE(board_rw_sections); - #define GPIO_SET_HS(bank, number) \ (STM32_GPIO_OSPEEDR(GPIO_##bank) |= (0x3 << ((number) * 2))) diff --git a/board/servo_micro/board.c b/board/servo_micro/board.c index 1307ef08ba..dedfcfdd7a 100644 --- a/board/servo_micro/board.c +++ b/board/servo_micro/board.c @@ -200,27 +200,6 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); - -/****************************************************************************** - * Support firmware upgrade over USB. We can update whichever section is not - * the current section. - */ - -/* - * This array defines possible sections available for the firmware update. - * The section which does not map the current executing code is picked as the - * valid update area. The values are offsets into the flash space. - */ -const struct section_descriptor board_rw_sections[] = { - {CONFIG_RO_MEM_OFF, - CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE}, - {CONFIG_RW_MEM_OFF, - CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE}, -}; -const struct section_descriptor * const rw_sections = board_rw_sections; -const int num_rw_sections = ARRAY_SIZE(board_rw_sections); - - /****************************************************************************** * Initialize board. */ diff --git a/board/servo_v4/board.c b/board/servo_v4/board.c index 61271508e7..ce2a647bb8 100644 --- a/board/servo_v4/board.c +++ b/board/servo_v4/board.c @@ -239,26 +239,6 @@ const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); /****************************************************************************** - * Support firmware upgrade over USB. We can update whichever section is not - * the current section. - */ - -/* - * This array defines possible sections available for the firmware update. - * The section which does not map the current executing code is picked as the - * valid update area. The values are offsets into the flash space. - */ -const struct section_descriptor board_rw_sections[] = { - {CONFIG_RO_MEM_OFF, - CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE}, - {CONFIG_RW_MEM_OFF, - CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE}, -}; -const struct section_descriptor * const rw_sections = board_rw_sections; -const int num_rw_sections = ARRAY_SIZE(board_rw_sections); - - -/****************************************************************************** * Initialize board. */ diff --git a/board/sweetberry/board.c b/board/sweetberry/board.c index 2bb97fde39..d05bb70bf4 100644 --- a/board/sweetberry/board.c +++ b/board/sweetberry/board.c @@ -67,25 +67,6 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); -/****************************************************************************** - * Support firmware upgrade over USB. We can update whichever section is not - * the current section. - */ - -/* - * This array defines possible sections available for the firmware update. - * The section which does not map the current executing code is picked as the - * valid update area. The values are offsets into the flash space. - */ -const struct section_descriptor board_rw_sections[] = { - {CONFIG_RO_MEM_OFF, - CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE}, - {CONFIG_RW_MEM_OFF, - CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE}, -}; -const struct section_descriptor * const rw_sections = board_rw_sections; -const int num_rw_sections = ARRAY_SIZE(board_rw_sections); - #define GPIO_SET_HS(bank, number) \ (STM32_GPIO_OSPEEDR(GPIO_##bank) |= (0x3 << ((number) * 2))) diff --git a/board/tigertail/board.c b/board/tigertail/board.c index 4a574e7fad..7db4618fcd 100644 --- a/board/tigertail/board.c +++ b/board/tigertail/board.c @@ -114,27 +114,6 @@ void usb_i2c_board_disable(void) {} /****************************************************************************** - * Support firmware upgrade over USB. We can update whichever section is not - * the current section. - */ - -/* - * This array defines possible sections available for the firmware update. - * The section which does not map the current executing code is picked as the - * valid update area. The values are offsets into the flash space. - */ -const struct section_descriptor board_rw_sections[] = { - {CONFIG_RO_MEM_OFF, - CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE}, - {CONFIG_RW_MEM_OFF, - CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE}, -}; -const struct section_descriptor * const rw_sections = board_rw_sections; -const int num_rw_sections = ARRAY_SIZE(board_rw_sections); - - - -/****************************************************************************** * Console commands. */ diff --git a/common/update_fw.c b/common/update_fw.c index 585977f774..8135370b7c 100644 --- a/common/update_fw.c +++ b/common/update_fw.c @@ -9,39 +9,18 @@ #include "flash.h" #include "hooks.h" #include "include/compile_time_macros.h" +#include "system.h" #include "uart.h" #include "update_fw.h" #include "util.h" #define CPRINTF(format, args...) cprintf(CC_USB, format, ## args) -const struct section_descriptor *valid_section; - -/* - * Pick the section where updates can go to based on current code address. - * - * TODO(b/36375666): Each board/chip should be able to re-define this. - */ -static int set_valid_section(void) -{ - int i; - uint32_t run_time_offs = (uint32_t) set_valid_section - - CONFIG_PROGRAM_MEMORY_BASE; - valid_section = rw_sections; - - for (i = 0; i < num_rw_sections; i++) { - if ((run_time_offs > rw_sections[i].sect_base_offset) && - (run_time_offs < rw_sections[i].sect_top_offset)) - continue; - valid_section = rw_sections + i; - break; - } - if (i == num_rw_sections) { - CPRINTF("%s:%d No valid section found!\n", __func__, __LINE__); - return EC_ERROR_INVAL; - } - return EC_SUCCESS; -} +/* Section to be updated (i.e. not the current section). */ +struct { + uint32_t base_offset; + uint32_t top_offset; +} update_section; /* * Verify that the passed in block fits into the valid area. If it does, and @@ -58,13 +37,13 @@ static uint8_t check_update_chunk(uint32_t block_offset, size_t body_size) uint32_t size; /* Is this an RW chunk? */ - if (valid_section && - (block_offset >= valid_section->sect_base_offset) && - ((block_offset + body_size) <= valid_section->sect_top_offset)) { + if (update_section.base_offset != update_section.top_offset && + (block_offset >= update_section.base_offset) && + ((block_offset + body_size) <= update_section.top_offset)) { - base = valid_section->sect_base_offset; - size = valid_section->sect_top_offset - - valid_section->sect_base_offset; + base = update_section.base_offset; + size = update_section.top_offset - + update_section.base_offset; /* * If this is the first chunk for this section, it needs to * be erased. @@ -83,8 +62,8 @@ static uint8_t check_update_chunk(uint32_t block_offset, size_t body_size) CPRINTF("%s:%d %x, %d section base %x top %x\n", __func__, __LINE__, block_offset, body_size, - valid_section->sect_base_offset, - valid_section->sect_top_offset); + update_section.base_offset, + update_section.top_offset); return UPDATE_BAD_ADDR; @@ -116,19 +95,22 @@ static int contents_allowed(uint32_t block_offset, * * Assumes rpdu is already prefilled with 0, and that version has already * been set. May set a return_value != 0 on error. - * - * TODO(b/36375666): Each board/chip should be able to re-define this. */ void fw_update_start(struct first_response_pdu *rpdu) { /* Determine the valid update section. */ - set_valid_section(); - - /* - * If there have been any problems when determining the valid - * section offsets/sizes - return an error code. - */ - if (!valid_section) { + switch (system_get_image_copy()) { + case SYSTEM_IMAGE_RO: + /* RO running, so update RW */ + update_section.base_offset = CONFIG_RW_MEM_OFF; + update_section.top_offset = CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE; + break; + case SYSTEM_IMAGE_RW: + /* RW running, so update RO */ + update_section.base_offset = CONFIG_RO_MEM_OFF; + update_section.top_offset = CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE; + break; + default: CPRINTF("%s:%d\n", __func__, __LINE__); rpdu->return_value = htobe32(UPDATE_GEN_ERROR); return; @@ -140,7 +122,7 @@ void fw_update_start(struct first_response_pdu *rpdu) * switch to a board-specific response packet (at least common vs * cr50-specific). */ - rpdu->backup_ro_offset = htobe32(valid_section->sect_base_offset); + rpdu->backup_ro_offset = htobe32(update_section.base_offset); rpdu->backup_rw_offset = 0x0; /* RO header information. */ diff --git a/include/update_fw.h b/include/update_fw.h index 8f7148f6ed..09d72e19d1 100644 --- a/include/update_fw.h +++ b/include/update_fw.h @@ -149,23 +149,4 @@ enum { */ #define UPDATE_PDU_SIZE 1024 -/* TODO(b/36375666): The structures below might not belong in this file. */ - -/* - * This array defines possible sections available for the firmare update. - * The section which does not map the current execting code is picked as the - * valid update area. The values are offsets into the flash space. - * - * This should be defined in board.c, with each entry containing: - * {CONFIG_RW_MEM_OFF, CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE} - * for its relevant section. - */ -struct section_descriptor { - uint32_t sect_base_offset; - uint32_t sect_top_offset; -}; - -extern const struct section_descriptor * const rw_sections; -extern const int num_rw_sections; - #endif /* ! __CROS_EC_UPDATE_FW_H */ |