diff options
author | Tom Hughes <tomhughes@chromium.org> | 2020-01-31 14:37:08 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-28 03:43:09 +0000 |
commit | 78d1ed61d6b7d3e3af631f4c9b17af340e6f7c05 (patch) | |
tree | fa625607d9f0012b06268a4a3bb203c6356bd8f8 | |
parent | c9f2a4db18e0c38a2cf1934a2d69043922866d3b (diff) | |
download | chrome-ec-78d1ed61d6b7d3e3af631f4c9b17af340e6f7c05.tar.gz |
common/system: Unify ec_current_image and system_image_copy_t
"enum ec_current_image" is exposed in ec_commands.h (and used by non-EC
code, such as biod).
We also have an "enum system_image_copy_t" that is the exact same thing
(though has a few more definitions).
A followup CL (I714b6bd8c0d7192386404c25a831e38438fa5238) adds the
"sysinfo" host command, so we want to be able to expose all the
potential image variants. Rather than maintain two enums that can
potentially get out of sync, unify the code to use a single enum. We
choose to keep the "enum ec_current_image", since external code depends
on it.
To verify that this change results in no changes to the generated
binaries:
./util/compare_build.sh --board all
BRANCH=none
BUG=b:146447208
TEST=./util/compare_build.sh --board=all
Change-Id: I13776bc3fd6e6ad635980476a35571c52b1767ac
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2036599
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Namyoon Woo <namyoon@chromium.org>
41 files changed, 254 insertions, 257 deletions
diff --git a/board/chell/usb_pd_policy.c b/board/chell/usb_pd_policy.c index 5a1dada9e2..478f656de2 100644 --- a/board/chell/usb_pd_policy.c +++ b/board/chell/usb_pd_policy.c @@ -182,7 +182,7 @@ int pd_custom_vdm(int port, int cnt, uint32_t *payload, } else if (cnt == 6) { /* really old devices don't have last byte */ pd_dev_store_rw_hash(port, dev_id, payload + 1, - SYSTEM_IMAGE_UNKNOWN); + EC_IMAGE_UNKNOWN); } break; case VDO_CMD_CURRENT: diff --git a/board/cr50/board.c b/board/cr50/board.c index ac1e640e47..41163edf2a 100644 --- a/board/cr50/board.c +++ b/board/cr50/board.c @@ -184,12 +184,12 @@ int board_tpm_mode_change_allowed(void) /* Get header address of the backup RW copy. */ const struct SignedHeader *get_other_rw_addr(void) { - if (system_get_image_copy() == SYSTEM_IMAGE_RW) + if (system_get_image_copy() == EC_IMAGE_RW) return (const struct SignedHeader *) - get_program_memory_addr(SYSTEM_IMAGE_RW_B); + get_program_memory_addr(EC_IMAGE_RW_B); return (const struct SignedHeader *) - get_program_memory_addr(SYSTEM_IMAGE_RW); + get_program_memory_addr(EC_IMAGE_RW); } /* Return true if the other RW is not ready to run. */ @@ -857,7 +857,7 @@ int flash_regions_to_enable(struct g_flash_region *regions, return 0; /* Enable access to the other RW image... */ - if (system_get_image_copy() == SYSTEM_IMAGE_RW) + if (system_get_image_copy() == EC_IMAGE_RW) /* Running RW_A, enable RW_B */ regions[0].reg_base = CONFIG_MAPPED_STORAGE_BASE + CONFIG_RW_B_MEM_OFF; @@ -1469,7 +1469,7 @@ void i2cs_set_pinmux(void) static int command_sysinfo(int argc, char **argv) { - enum system_image_copy_t active; + enum ec_image active; uintptr_t vaddr; const struct SignedHeader *h; int reset_count = GREG32(PMU, LONG_LIFE_SCRATCH0); @@ -1533,7 +1533,7 @@ static enum vendor_cmd_rc vc_sysinfo(enum vendor_cmd_cc code, size_t input_size, size_t *response_size) { - enum system_image_copy_t active; + enum ec_image active; uintptr_t vaddr; const struct SignedHeader *h; struct sysinfo_s *sysinfo = buf; diff --git a/board/cr50/factory_mode.c b/board/cr50/factory_mode.c index 520105c241..9597b1b440 100644 --- a/board/cr50/factory_mode.c +++ b/board/cr50/factory_mode.c @@ -35,13 +35,13 @@ static int board_id_is_erased(void) static int inactive_image_is_guc_image(void) { - enum system_image_copy_t inactive_copy; + enum ec_image inactive_copy; const struct SignedHeader *other; - if (system_get_image_copy() == SYSTEM_IMAGE_RW) - inactive_copy = SYSTEM_IMAGE_RW_B; + if (system_get_image_copy() == EC_IMAGE_RW) + inactive_copy = EC_IMAGE_RW_B; else - inactive_copy = SYSTEM_IMAGE_RW; + inactive_copy = EC_IMAGE_RW; other = (struct SignedHeader *) get_program_memory_addr( inactive_copy); /* diff --git a/board/twinkie/injector.c b/board/twinkie/injector.c index cddbb8f86b..cae1d3557f 100644 --- a/board/twinkie/injector.c +++ b/board/twinkie/injector.c @@ -543,7 +543,7 @@ static int cmd_sink(int argc, char **argv) * Jump to the RW section which should contain a firmware acting * as a USB PD sink */ - system_run_image_copy(SYSTEM_IMAGE_RW); + system_run_image_copy(EC_IMAGE_RW); return EC_SUCCESS; } diff --git a/board/zinger/runtime.c b/board/zinger/runtime.c index 25c68f9df3..1400fd6cc7 100644 --- a/board/zinger/runtime.c +++ b/board/zinger/runtime.c @@ -277,12 +277,12 @@ void panic_reboot(void) cpu_reset(); } -enum system_image_copy_t system_get_image_copy(void) +enum ec_image system_get_image_copy(void) { if (is_ro_mode()) - return SYSTEM_IMAGE_RO; + return EC_IMAGE_RO; else - return SYSTEM_IMAGE_RW; + return EC_IMAGE_RW; } /* --- stubs --- */ diff --git a/chip/g/system.c b/chip/g/system.c index d68da094f2..86c3f52b5d 100644 --- a/chip/g/system.c +++ b/chip/g/system.c @@ -287,7 +287,7 @@ int system_set_bbram(enum system_bbram_idx idx, uint8_t value) return 0; } -enum system_image_copy_t system_get_ro_image_copy(void) +enum ec_image system_get_ro_image_copy(void) { /* * The bootrom protects the selected bootloader with REGION0, @@ -296,12 +296,12 @@ enum system_image_copy_t system_get_ro_image_copy(void) */ switch (GREG32(GLOBALSEC, FLASH_REGION0_BASE_ADDR)) { case CONFIG_PROGRAM_MEMORY_BASE + CONFIG_RO_MEM_OFF: - return SYSTEM_IMAGE_RO; + return EC_IMAGE_RO; case CONFIG_PROGRAM_MEMORY_BASE + CHIP_RO_B_MEM_OFF: - return SYSTEM_IMAGE_RO_B; + return EC_IMAGE_RO_B; } - return SYSTEM_IMAGE_UNKNOWN; + return EC_IMAGE_UNKNOWN; } /* @@ -324,19 +324,19 @@ struct version_struct_deprecated { #define MAX_RO_VER_LEN 48 static char vers_str[MAX_RO_VER_LEN]; -const char *system_get_version(enum system_image_copy_t copy) +const char *system_get_version(enum ec_image copy) { const struct image_data *data; const struct version_struct_deprecated *data_deprecated; const char *version; const struct SignedHeader *h; - enum system_image_copy_t this_copy; + enum ec_image this_copy; uintptr_t vaddr, delta; switch (copy) { - case SYSTEM_IMAGE_RO: - case SYSTEM_IMAGE_RO_B: + case EC_IMAGE_RO: + case EC_IMAGE_RO_B: /* The RO header is the first thing in each flash half */ vaddr = get_program_memory_addr(copy); if (vaddr == INVALID_ADDR) @@ -347,8 +347,8 @@ const char *system_get_version(enum system_image_copy_t copy) h->epoch_, h->major_, h->minor_, h->img_chk_); return vers_str; - case SYSTEM_IMAGE_RW: - case SYSTEM_IMAGE_RW_B: + case EC_IMAGE_RW: + case EC_IMAGE_RW_B: /* * This function isn't part of any RO image, so we must be in a * RW image. If the current image is the one we're asked for, @@ -499,16 +499,16 @@ static int current_image_is_newer(struct SignedHeader **newer_image) { struct SignedHeader *me, *other; - if (system_get_image_copy() == SYSTEM_IMAGE_RW) { + if (system_get_image_copy() == EC_IMAGE_RW) { me = (struct SignedHeader *) - get_program_memory_addr(SYSTEM_IMAGE_RW); + get_program_memory_addr(EC_IMAGE_RW); other = (struct SignedHeader *) - get_program_memory_addr(SYSTEM_IMAGE_RW_B); + get_program_memory_addr(EC_IMAGE_RW_B); } else { me = (struct SignedHeader *) - get_program_memory_addr(SYSTEM_IMAGE_RW_B); + get_program_memory_addr(EC_IMAGE_RW_B); other = (struct SignedHeader *) - get_program_memory_addr(SYSTEM_IMAGE_RW); + get_program_memory_addr(EC_IMAGE_RW); } if (a_is_newer_than_b(me, other)) @@ -710,11 +710,11 @@ void system_update_rollback_mask_with_active_img(void) void system_update_rollback_mask_with_both_imgs(void) { - update_rollback_mask(get_program_memory_addr(SYSTEM_IMAGE_RO), - get_program_memory_addr(SYSTEM_IMAGE_RO_B), + update_rollback_mask(get_program_memory_addr(EC_IMAGE_RO), + get_program_memory_addr(EC_IMAGE_RO_B), INFO_RO_MAP_OFFSET); - update_rollback_mask(get_program_memory_addr(SYSTEM_IMAGE_RW), - get_program_memory_addr(SYSTEM_IMAGE_RW_B), + update_rollback_mask(get_program_memory_addr(EC_IMAGE_RW), + get_program_memory_addr(EC_IMAGE_RW_B), INFO_RW_MAP_OFFSET); } @@ -727,9 +727,9 @@ void system_get_rollback_bits(char *value, size_t value_size) uint32_t image_types[2]; } headers[] = { { .info_map_offset = INFO_RO_MAP_OFFSET, - .image_types = { SYSTEM_IMAGE_RO, SYSTEM_IMAGE_RO_B } }, + .image_types = { EC_IMAGE_RO, EC_IMAGE_RO_B } }, { .info_map_offset = INFO_RW_MAP_OFFSET, - .image_types = { SYSTEM_IMAGE_RW, SYSTEM_IMAGE_RW_B } } + .image_types = { EC_IMAGE_RW, EC_IMAGE_RW_B } } }; for (i = 0; i < ARRAY_SIZE(headers); i++) { @@ -774,8 +774,8 @@ void system_print_extended_version_info(void) { int i; struct board_id bid; - enum system_image_copy_t rw_images[] = { - SYSTEM_IMAGE_RW, SYSTEM_IMAGE_RW_B + enum ec_image rw_images[] = { + EC_IMAGE_RW, EC_IMAGE_RW_B }; if (read_board_id(&bid) != EC_SUCCESS) { diff --git a/chip/g/upgrade.c b/chip/g/upgrade.c index 03c6a0450a..e7c6120615 100644 --- a/chip/g/upgrade.c +++ b/chip/g/upgrade.c @@ -75,13 +75,13 @@ static uint8_t headers_restored(void) uint8_t total_restored; /* Examine the RW first. */ - if (system_get_image_copy() == SYSTEM_IMAGE_RW) + if (system_get_image_copy() == EC_IMAGE_RW) total_restored = header_restored(CONFIG_RW_B_MEM_OFF); else total_restored = header_restored(CONFIG_RW_MEM_OFF); /* Now the RO */ - if (system_get_ro_image_copy() == SYSTEM_IMAGE_RO) + if (system_get_ro_image_copy() == EC_IMAGE_RO) total_restored += header_restored(CHIP_RO_B_MEM_OFF); else total_restored += header_restored(CONFIG_RO_MEM_OFF); diff --git a/chip/g/upgrade_fw.c b/chip/g/upgrade_fw.c index 276eac8f92..1afadbc280 100644 --- a/chip/g/upgrade_fw.c +++ b/chip/g/upgrade_fw.c @@ -38,23 +38,23 @@ struct { /* Pick sections where updates can go to based on current code addresses. */ static void set_valid_sections(void) { - switch (system_get_ro_image_copy()) { - case SYSTEM_IMAGE_RO: - valid_sections.ro_base_offset = CHIP_RO_B_MEM_OFF; - break; - case SYSTEM_IMAGE_RO_B: - valid_sections.ro_base_offset = CONFIG_RO_MEM_OFF; - break; - default: - CPRINTF("Failed to set RO image offsets\n"); - return; - } + switch (system_get_ro_image_copy()) { + case EC_IMAGE_RO: + valid_sections.ro_base_offset = CHIP_RO_B_MEM_OFF; + break; + case EC_IMAGE_RO_B: + valid_sections.ro_base_offset = CONFIG_RO_MEM_OFF; + break; + default: + CPRINTF("Failed to set RO image offsets\n"); + return; + } switch (system_get_image_copy()) { - case SYSTEM_IMAGE_RW: + case EC_IMAGE_RW: valid_sections.rw_base_offset = CONFIG_RW_B_MEM_OFF; break; - case SYSTEM_IMAGE_RW_B: + case EC_IMAGE_RW_B: valid_sections.rw_base_offset = CONFIG_RW_MEM_OFF; break; default: diff --git a/chip/host/system.c b/chip/host/system.c index b1654911ab..adbf656ba8 100644 --- a/chip/host/system.c +++ b/chip/host/system.c @@ -24,7 +24,7 @@ uint8_t __shared_mem_buf[SHARED_MEM_SIZE + RAM_DATA_SIZE]; static char *__ram_data = __shared_mem_buf + SHARED_MEM_SIZE; -static enum system_image_copy_t __running_copy; +static enum ec_image __running_copy; static void ramdata_set_persistent(void) { @@ -77,7 +77,7 @@ static uint32_t get_image_copy(void) uint32_t ret; if (f == NULL) - return SYSTEM_IMAGE_UNKNOWN; + return EC_IMAGE_UNKNOWN; fread(&ret, sizeof(ret), 1, f); release_persistent_storage(f); remove_persistent_storage("image_copy"); @@ -177,7 +177,7 @@ test_mockable int system_is_locked(void) #ifdef TEST_FUZZ /* When fuzzing, do not allow sysjumps. */ -int system_run_image_copy(enum system_image_copy_t copy) +int system_run_image_copy(enum ec_image copy) { ccprints("Emulator would sysjump here. Fuzzing: doing nothing."); return EC_ERROR_UNKNOWN; @@ -209,7 +209,7 @@ int system_set_bbram(enum system_bbram_idx idx, uint8_t value) return EC_ERROR_UNIMPLEMENTED; } -enum system_image_copy_t system_get_image_copy(void) +enum ec_image system_get_image_copy(void) { return __running_copy; } @@ -251,13 +251,13 @@ static void __jump_resetvec(void) static void __ro_jump_resetvec(void) { - set_image_copy(SYSTEM_IMAGE_RO); + set_image_copy(EC_IMAGE_RO); __jump_resetvec(); } static void __rw_jump_resetvec(void) { - set_image_copy(SYSTEM_IMAGE_RW); + set_image_copy(EC_IMAGE_RW); __jump_resetvec(); } @@ -270,8 +270,8 @@ void system_pre_init(void) ramdata_get_persistent(); __running_copy = get_image_copy(); - if (__running_copy == SYSTEM_IMAGE_UNKNOWN) { - __running_copy = SYSTEM_IMAGE_RO; + if (__running_copy == EC_IMAGE_UNKNOWN) { + __running_copy = EC_IMAGE_RO; system_set_reset_flags(load_reset_flags()); } diff --git a/chip/ish/system.c b/chip/ish/system.c index c26026dcb8..caa5e15255 100644 --- a/chip/ish/system.c +++ b/chip/ish/system.c @@ -161,7 +161,7 @@ void htimer_interrupt(void) /* Time to wake up */ } -enum system_image_copy_t system_get_shrspi_image_copy(void) +enum ec_image system_get_shrspi_image_copy(void) { return 0; } @@ -171,7 +171,7 @@ uint32_t system_get_lfw_address(void) return 0; } -void system_set_image_copy(enum system_image_copy_t copy) +void system_set_image_copy(enum ec_image copy) { } diff --git a/chip/mchp/lfw/ec_lfw.c b/chip/mchp/lfw/ec_lfw.c index 111e753d3b..edd945037c 100644 --- a/chip/mchp/lfw/ec_lfw.c +++ b/chip/mchp/lfw/ec_lfw.c @@ -327,10 +327,10 @@ void system_init(void) if (rst_sts || wdt_sts) MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX) - = SYSTEM_IMAGE_UNKNOWN; + = EC_IMAGE_UNKNOWN; } -enum system_image_copy_t system_get_image_copy(void) +enum ec_image system_get_image_copy(void) { return MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX); } @@ -343,8 +343,8 @@ enum system_image_copy_t system_get_image_copy(void) * LFW checks reset type: * VTR POR, chip reset, WDT reset then set VBAT Load type to Unknown. * LFW reads VBAT Load type: - * SYSTEM_IMAGE_RO then read EC_RO from SPI flash and jump into it. - * SYSTEM_IMAGE_RO then read EC_RW from SPI flash and jump into it. + * EC_IMAGE_RO then read EC_RO from SPI flash and jump into it. + * EC_IMAGE_RO then read EC_RW from SPI flash and jump into it. * Other then jump into EC image loaded by Boot-ROM. */ void lfw_main(void) @@ -388,7 +388,7 @@ void lfw_main(void) uart_puts("\n"); switch (system_get_image_copy()) { - case SYSTEM_IMAGE_RW: + case EC_IMAGE_RW: trace0(0, LFW, 0, "LFW EC_RW Load"); uart_puts("lfw-RW load\n"); @@ -396,7 +396,7 @@ void lfw_main(void) spi_image_load(CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF); break; - case SYSTEM_IMAGE_RO: + case EC_IMAGE_RO: trace0(0, LFW, 0, "LFW EC_RO Load"); uart_puts("lfw-RO load\n"); @@ -408,8 +408,7 @@ void lfw_main(void) trace0(0, LFW, 0, "LFW default: use EC_RO loaded by BootROM"); uart_puts("lfw-default case\n"); - MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX) = - SYSTEM_IMAGE_RO; + MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX) = EC_IMAGE_RO; init_addr = CONFIG_RO_MEM_OFF + CONFIG_PROGRAM_MEMORY_BASE; } diff --git a/chip/mchp/system.c b/chip/mchp/system.c index c19db25759..8b62490c4a 100644 --- a/chip/mchp/system.c +++ b/chip/mchp/system.c @@ -454,7 +454,7 @@ void htimer_interrupt(void) } DECLARE_IRQ(MCHP_IRQ_HTIMER0, htimer_interrupt, 1); -enum system_image_copy_t system_get_shrspi_image_copy(void) +enum ec_image system_get_shrspi_image_copy(void) { return MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX); } @@ -467,9 +467,9 @@ uint32_t system_get_lfw_address(void) return *(lfw_vector + 1); } -void system_set_image_copy(enum system_image_copy_t copy) +void system_set_image_copy(enum ec_image copy) { - MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX) = (copy == SYSTEM_IMAGE_RW) ? - SYSTEM_IMAGE_RW : SYSTEM_IMAGE_RO; + MCHP_VBAT_RAM(MCHP_IMAGETYPE_IDX) = (copy == EC_IMAGE_RW) ? + EC_IMAGE_RW : EC_IMAGE_RO; } diff --git a/chip/mec1322/lfw/ec_lfw.c b/chip/mec1322/lfw/ec_lfw.c index 7dacfc3077..39f4e378ae 100644 --- a/chip/mec1322/lfw/ec_lfw.c +++ b/chip/mec1322/lfw/ec_lfw.c @@ -218,11 +218,10 @@ void system_init(void) MEC1322_PWR_RST_STS_VCC1; if (rst_sts || wdt_sts) - MEC1322_VBAT_RAM(MEC1322_IMAGETYPE_IDX) - = SYSTEM_IMAGE_RO; + MEC1322_VBAT_RAM(MEC1322_IMAGETYPE_IDX) = EC_IMAGE_RO; } -enum system_image_copy_t system_get_image_copy(void) +enum ec_image system_get_image_copy(void) { return MEC1322_VBAT_RAM(MEC1322_IMAGETYPE_IDX); } @@ -260,20 +259,19 @@ void lfw_main() uart_puts("\n"); switch (system_get_image_copy()) { - case SYSTEM_IMAGE_RW: + case EC_IMAGE_RW: uart_puts("lfw-RW load\n"); init_addr = CONFIG_RW_MEM_OFF + CONFIG_PROGRAM_MEMORY_BASE; spi_image_load(CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF); break; - case SYSTEM_IMAGE_RO: + case EC_IMAGE_RO: uart_puts("lfw-RO load\n"); spi_image_load(CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF); /* fall through */ default: - MEC1322_VBAT_RAM(MEC1322_IMAGETYPE_IDX) = - SYSTEM_IMAGE_RO; + MEC1322_VBAT_RAM(MEC1322_IMAGETYPE_IDX) = EC_IMAGE_RO; init_addr = CONFIG_RO_MEM_OFF + CONFIG_PROGRAM_MEMORY_BASE; } diff --git a/chip/mec1322/system.c b/chip/mec1322/system.c index 6dac6abfc6..9104bc17b1 100644 --- a/chip/mec1322/system.c +++ b/chip/mec1322/system.c @@ -373,7 +373,7 @@ void htimer_interrupt(void) } DECLARE_IRQ(MEC1322_IRQ_HTIMER, htimer_interrupt, 1); -enum system_image_copy_t system_get_shrspi_image_copy(void) +enum ec_image system_get_shrspi_image_copy(void) { return MEC1322_VBAT_RAM(MEC1322_IMAGETYPE_IDX); } @@ -386,8 +386,8 @@ uint32_t system_get_lfw_address(void) return *(lfw_vector + 1); } -void system_set_image_copy(enum system_image_copy_t copy) +void system_set_image_copy(enum ec_image copy) { - MEC1322_VBAT_RAM(MEC1322_IMAGETYPE_IDX) = (copy == SYSTEM_IMAGE_RW) ? - SYSTEM_IMAGE_RW : SYSTEM_IMAGE_RO; + MEC1322_VBAT_RAM(MEC1322_IMAGETYPE_IDX) = (copy == EC_IMAGE_RW) ? + EC_IMAGE_RW : EC_IMAGE_RO; } diff --git a/chip/mt_scp/ipi.c b/chip/mt_scp/ipi.c index f165031501..db371f02b4 100644 --- a/chip/mt_scp/ipi.c +++ b/chip/mt_scp/ipi.c @@ -245,7 +245,7 @@ void ipi_inform_ap(void) #endif scp_run.signaled = 1; - strncpy(scp_run.fw_ver, system_get_version(SYSTEM_IMAGE_RW), + strncpy(scp_run.fw_ver, system_get_version(EC_IMAGE_RW), SCP_FW_VERSION_LEN); scp_run.dec_capability = VCODEC_CAPABILITY_4K_DISABLED; scp_run.enc_capability = 0; diff --git a/chip/npcx/system.c b/chip/npcx/system.c index 9ba374a857..48422902e0 100644 --- a/chip/npcx/system.c +++ b/chip/npcx/system.c @@ -1059,19 +1059,19 @@ void system_jump_to_booter(void) * Both of them need 16-bytes alignment since GDMA burst mode. */ switch (system_get_shrspi_image_copy()) { - case SYSTEM_IMAGE_RW: + case EC_IMAGE_RW: flash_offset = CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF; flash_used = CONFIG_RW_SIZE; break; #ifdef CONFIG_RW_B - case SYSTEM_IMAGE_RW_B: + case EC_IMAGE_RW_B: flash_offset = CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_B_STORAGE_OFF; flash_used = CONFIG_RW_SIZE; break; #endif - case SYSTEM_IMAGE_RO: + case EC_IMAGE_RO: default: /* Jump to RO by default */ flash_offset = CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF; @@ -1125,47 +1125,47 @@ uint32_t system_get_lfw_address() * NPCX_FWCTRL_RO_REGION: 1 - RO, 0 - RW * NPCX_FWCTRL_FW_SLOT: 1 - SLOT_A, 0 - SLOT_B */ -void system_set_image_copy(enum system_image_copy_t copy) +void system_set_image_copy(enum ec_image copy) { switch (copy) { - case SYSTEM_IMAGE_RW: + case EC_IMAGE_RW: CLEAR_BIT(NPCX_FWCTRL, NPCX_FWCTRL_RO_REGION); SET_BIT(NPCX_FWCTRL, NPCX_FWCTRL_FW_SLOT); break; #ifdef CONFIG_RW_B - case SYSTEM_IMAGE_RW_B: + case EC_IMAGE_RW_B: CLEAR_BIT(NPCX_FWCTRL, NPCX_FWCTRL_RO_REGION); CLEAR_BIT(NPCX_FWCTRL, NPCX_FWCTRL_FW_SLOT); break; #endif default: CPRINTS("Invalid copy (%d) is requested as a jump destination. " - "Change it to %d.", copy, SYSTEM_IMAGE_RO); - /* Fall through to SYSTEM_IMAGE_RO */ - case SYSTEM_IMAGE_RO: + "Change it to %d.", copy, EC_IMAGE_RO); + /* Fall through to EC_IMAGE_RO */ + case EC_IMAGE_RO: SET_BIT(NPCX_FWCTRL, NPCX_FWCTRL_RO_REGION); SET_BIT(NPCX_FWCTRL, NPCX_FWCTRL_FW_SLOT); break; } } -enum system_image_copy_t system_get_shrspi_image_copy(void) +enum ec_image system_get_shrspi_image_copy(void) { if (IS_BIT_SET(NPCX_FWCTRL, NPCX_FWCTRL_RO_REGION)) { /* RO image */ #ifdef CHIP_HAS_RO_B if (!IS_BIT_SET(NPCX_FWCTRL, NPCX_FWCTRL_FW_SLOT)) - return SYSTEM_IMAGE_RO_B; + return EC_IMAGE_RO_B; #endif - return SYSTEM_IMAGE_RO; + return EC_IMAGE_RO; } else { #ifdef CONFIG_RW_B /* RW image */ if (!IS_BIT_SET(NPCX_FWCTRL, NPCX_FWCTRL_FW_SLOT)) /* Slot A */ - return SYSTEM_IMAGE_RW_B; + return EC_IMAGE_RW_B; #endif - return SYSTEM_IMAGE_RW; + return EC_IMAGE_RW; } } diff --git a/common/charge_manager.c b/common/charge_manager.c index 9f2ee4132f..1dbd197264 100644 --- a/common/charge_manager.c +++ b/common/charge_manager.c @@ -195,7 +195,7 @@ static int is_connected(int port) */ static int charge_manager_spoof_dualrole_capability(void) { - return (system_get_image_copy() == SYSTEM_IMAGE_RO && + return (system_get_image_copy() == EC_IMAGE_RO && system_is_locked()) || !left_safe_mode; } diff --git a/common/main.c b/common/main.c index bc67ea62b7..00bae7534c 100644 --- a/common/main.c +++ b/common/main.c @@ -215,7 +215,7 @@ test_mockable __keep int main(void) * * Only the Read-Only firmware needs to do the signature check. */ - if (system_get_image_copy() == SYSTEM_IMAGE_RO) { + if (system_get_image_copy() == EC_IMAGE_RO) { #if defined(CONFIG_RWSIG_DONT_CHECK_ON_PIN_RESET) /* * If system was reset by reset-pin, do not jump and wait for diff --git a/common/rollback.c b/common/rollback.c index 2b13787e58..e310aa904b 100644 --- a/common/rollback.c +++ b/common/rollback.c @@ -469,7 +469,7 @@ static int command_rollback_info(int argc, char **argv) if (min_region < 0) goto failed; - rw_rollback_version = system_get_rollback_version(SYSTEM_IMAGE_RW); + rw_rollback_version = system_get_rollback_version(EC_IMAGE_RW); ccprintf("rollback minimum version: %d\n", data.rollback_min_version); ccprintf("RW rollback version: %d\n", rw_rollback_version); @@ -518,7 +518,7 @@ host_command_rollback_info(struct host_cmd_handler_args *args) r->id = data.id; r->rollback_min_version = data.rollback_min_version; - r->rw_rollback_version = system_get_rollback_version(SYSTEM_IMAGE_RW); + r->rw_rollback_version = system_get_rollback_version(EC_IMAGE_RW); args->response_size = sizeof(*r); ret = EC_RES_SUCCESS; diff --git a/common/rwsig.c b/common/rwsig.c index 0d0a8e765c..1af7189cc0 100644 --- a/common/rwsig.c +++ b/common/rwsig.c @@ -67,7 +67,7 @@ void rwsig_jump_now(void) /* When system is locked, only boot to RW if all flash is protected. */ if (!system_is_locked() || flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) - system_run_image_copy(SYSTEM_IMAGE_RW); + system_run_image_copy(EC_IMAGE_RW); } /* @@ -120,7 +120,7 @@ int rwsig_check_signature(void) CPRINTS("Verifying RW image..."); #ifdef CONFIG_ROLLBACK - rw_rollback_version = system_get_rollback_version(SYSTEM_IMAGE_RW); + rw_rollback_version = system_get_rollback_version(EC_IMAGE_RW); min_rollback_version = rollback_get_minimum_version(); if (rw_rollback_version < 0 || min_rollback_version < 0 || @@ -266,7 +266,7 @@ void rwsig_task(void *u) { uint32_t evt; - if (system_get_image_copy() != SYSTEM_IMAGE_RO) + if (system_get_image_copy() != EC_IMAGE_RO) goto exit; rwsig_status = RWSIG_IN_PROGRESS; diff --git a/common/system.c b/common/system.c index 7b50f57a1f..b2416c5a65 100644 --- a/common/system.c +++ b/common/system.c @@ -121,19 +121,19 @@ DECLARE_HOOK(HOOK_INIT, ap_sku_id_restore_state, HOOK_PRIO_DEFAULT); * begin. In the case of external storage, the image may or may not currently * reside at the location returned. */ -uintptr_t get_program_memory_addr(enum system_image_copy_t copy) +uintptr_t get_program_memory_addr(enum ec_image copy) { switch (copy) { - case SYSTEM_IMAGE_RO: + case EC_IMAGE_RO: return CONFIG_PROGRAM_MEMORY_BASE + CONFIG_RO_MEM_OFF; - case SYSTEM_IMAGE_RW: + case EC_IMAGE_RW: return CONFIG_PROGRAM_MEMORY_BASE + CONFIG_RW_MEM_OFF; #ifdef CHIP_HAS_RO_B - case SYSTEM_IMAGE_RO_B: + case EC_IMAGE_RO_B: return CONFIG_PROGRAM_MEMORY_BASE + CHIP_RO_B_MEM_OFF; #endif #ifdef CONFIG_RW_B - case SYSTEM_IMAGE_RW_B: + case EC_IMAGE_RW_B: return CONFIG_PROGRAM_MEMORY_BASE + CONFIG_RW_B_MEM_OFF; #endif default: @@ -144,18 +144,18 @@ uintptr_t get_program_memory_addr(enum system_image_copy_t copy) /** * Return the size of the image copy, or 0 if error. */ -static uint32_t __attribute__((unused)) get_size(enum system_image_copy_t copy) +static uint32_t __attribute__((unused)) get_size(enum ec_image copy) { /* Ensure we return aligned sizes. */ BUILD_ASSERT(CONFIG_RO_SIZE % SPI_FLASH_MAX_WRITE_SIZE == 0); BUILD_ASSERT(CONFIG_RW_SIZE % SPI_FLASH_MAX_WRITE_SIZE == 0); switch (copy) { - case SYSTEM_IMAGE_RO: - case SYSTEM_IMAGE_RO_B: + case EC_IMAGE_RO: + case EC_IMAGE_RO_B: return CONFIG_RO_SIZE; - case SYSTEM_IMAGE_RW: - case SYSTEM_IMAGE_RW_B: + case EC_IMAGE_RW: + case EC_IMAGE_RW_B: return CONFIG_RW_SIZE; default: return 0; @@ -329,7 +329,7 @@ void system_disable_jump(void) #ifdef CONFIG_MPU if (system_is_locked()) { int ret; - enum system_image_copy_t __attribute__((unused)) copy; + enum ec_image __attribute__((unused)) copy; CPRINTS("MPU type: %08x", mpu_get_type()); /* @@ -362,24 +362,24 @@ void system_disable_jump(void) * from code execution. */ switch (system_get_image_copy()) { - case SYSTEM_IMAGE_RO: + case EC_IMAGE_RO: ret = mpu_lock_rw_flash(); - copy = SYSTEM_IMAGE_RW; + copy = EC_IMAGE_RW; break; - case SYSTEM_IMAGE_RW: + case EC_IMAGE_RW: ret = mpu_lock_ro_flash(); - copy = SYSTEM_IMAGE_RO; + copy = EC_IMAGE_RO; break; default: - copy = SYSTEM_IMAGE_UNKNOWN; + copy = EC_IMAGE_UNKNOWN; ret = !EC_SUCCESS; } if (ret == EC_SUCCESS) { CPRINTS("%s image locked", - system_image_copy_t_to_string(copy)); + ec_image_to_string(copy)); } else { CPRINTS("Failed to lock %s image (%d)", - system_image_copy_t_to_string(copy), ret); + ec_image_to_string(copy), ret); return; } #endif /* !CONFIG_EXTERNAL_STORAGE */ @@ -392,7 +392,7 @@ void system_disable_jump(void) #endif /* CONFIG_MPU */ } -test_mockable enum system_image_copy_t system_get_image_copy(void) +test_mockable enum ec_image system_get_image_copy(void) { #ifdef CONFIG_EXTERNAL_STORAGE /* Return which region is used in program memory */ @@ -403,25 +403,25 @@ test_mockable enum system_image_copy_t system_get_image_copy(void) if (my_addr >= CONFIG_RO_MEM_OFF && my_addr < (CONFIG_RO_MEM_OFF + CONFIG_RO_SIZE)) - return SYSTEM_IMAGE_RO; + return EC_IMAGE_RO; if (my_addr >= CONFIG_RW_MEM_OFF && my_addr < (CONFIG_RW_MEM_OFF + CONFIG_RW_SIZE)) - return SYSTEM_IMAGE_RW; + return EC_IMAGE_RW; #ifdef CHIP_HAS_RO_B if (my_addr >= CHIP_RO_B_MEM_OFF && my_addr < (CHIP_RO_B_MEM_OFF + CONFIG_RO_SIZE)) - return SYSTEM_IMAGE_RO_B; + return EC_IMAGE_RO_B; #endif #ifdef CONFIG_RW_B if (my_addr >= CONFIG_RW_B_MEM_OFF && my_addr < (CONFIG_RW_B_MEM_OFF + CONFIG_RW_SIZE)) - return SYSTEM_IMAGE_RW_B; + return EC_IMAGE_RW_B; #endif - return SYSTEM_IMAGE_UNKNOWN; + return EC_IMAGE_UNKNOWN; #endif } @@ -429,14 +429,14 @@ test_mockable int system_unsafe_to_overwrite(uint32_t offset, uint32_t size) { uint32_t r_offset; uint32_t r_size; - enum system_image_copy_t copy = system_get_image_copy(); + enum ec_image copy = system_get_image_copy(); switch (copy) { - case SYSTEM_IMAGE_RO: + case EC_IMAGE_RO: r_size = CONFIG_RO_SIZE; break; - case SYSTEM_IMAGE_RW: - case SYSTEM_IMAGE_RW_B: + case EC_IMAGE_RW: + case EC_IMAGE_RW_B: r_size = CONFIG_RW_SIZE; #ifdef CONFIG_RWSIG /* Allow RW sig to be overwritten */ @@ -457,10 +457,10 @@ test_mockable int system_unsafe_to_overwrite(uint32_t offset, uint32_t size) const char *system_get_image_copy_string(void) { - return system_image_copy_t_to_string(system_get_image_copy()); + return ec_image_to_string(system_get_image_copy()); } -const char *system_image_copy_t_to_string(enum system_image_copy_t copy) +const char *ec_image_to_string(enum ec_image copy) { static const char * const image_names[] = { "unknown", "RO", "RW", "RO_B", "RW_B" @@ -529,9 +529,9 @@ static void jump_to_image(uintptr_t init_addr) resetvec(); } -static int is_rw_image(enum system_image_copy_t copy) +static int is_rw_image(enum ec_image copy) { - return copy == SYSTEM_IMAGE_RW || copy == SYSTEM_IMAGE_RW_B; + return copy == EC_IMAGE_RW || copy == EC_IMAGE_RW_B; } int system_is_in_rw(void) @@ -539,7 +539,7 @@ int system_is_in_rw(void) return is_rw_image(system_get_image_copy()); } -test_mockable int system_run_image_copy(enum system_image_copy_t copy) +test_mockable int system_run_image_copy(enum ec_image copy) { uintptr_t base; uintptr_t init_addr; @@ -553,7 +553,7 @@ test_mockable int system_run_image_copy(enum system_image_copy_t copy) * this is the initial jump from RO to RW code. */ /* Must currently be running the RO image */ - if (system_get_image_copy() != SYSTEM_IMAGE_RO) + if (system_get_image_copy() != EC_IMAGE_RO) return EC_ERROR_ACCESS_DENIED; /* Target image must be RW image */ @@ -581,7 +581,7 @@ test_mockable int system_run_image_copy(enum system_image_copy_t copy) uintptr_t init = base + 4; /* Skip any head room in the RO image */ - if (copy == SYSTEM_IMAGE_RO) + if (copy == EC_IMAGE_RO) init += CONFIG_RO_HEAD_ROOM; init_addr = *(uintptr_t *)(init); @@ -592,7 +592,7 @@ test_mockable int system_run_image_copy(enum system_image_copy_t copy) return EC_ERROR_UNKNOWN; } - CPRINTS("Jumping to image %s", system_image_copy_t_to_string(copy)); + CPRINTS("Jumping to image %s", ec_image_to_string(copy)); jump_to_image(init_addr); @@ -600,27 +600,27 @@ test_mockable int system_run_image_copy(enum system_image_copy_t copy) return EC_ERROR_UNKNOWN; } -enum system_image_copy_t system_get_active_copy(void) +enum ec_image system_get_active_copy(void) { uint8_t slot; if (system_get_bbram(SYSTEM_BBRAM_IDX_TRY_SLOT, &slot)) - slot = SYSTEM_IMAGE_RW_A; + slot = EC_IMAGE_RW_A; /* This makes it return RW_A by default. For example, this happens when * BBRAM isn't initialized. */ - return slot == SYSTEM_IMAGE_RW_B ? slot : SYSTEM_IMAGE_RW_A; + return slot == EC_IMAGE_RW_B ? slot : EC_IMAGE_RW_A; } -enum system_image_copy_t system_get_update_copy(void) +enum ec_image system_get_update_copy(void) { #ifdef CONFIG_VBOOT_EFS /* Not needed for EFS2, which is single-slot. */ - return system_get_active_copy() == SYSTEM_IMAGE_RW_A ? - SYSTEM_IMAGE_RW_B : SYSTEM_IMAGE_RW_A; + return system_get_active_copy() == EC_IMAGE_RW_A ? + EC_IMAGE_RW_B : EC_IMAGE_RW_A; #else - return SYSTEM_IMAGE_RW_A; + return EC_IMAGE_RW_A; #endif } -int system_set_active_copy(enum system_image_copy_t copy) +int system_set_active_copy(enum ec_image copy) { return system_set_bbram(SYSTEM_BBRAM_IDX_TRY_SLOT, copy); } @@ -629,10 +629,10 @@ int system_set_active_copy(enum system_image_copy_t copy) * This is defined in system.c instead of flash.c because it's called even * on the boards which don't include flash.o. (e.g. hadoken, stm32l476g-eval) */ -uint32_t flash_get_rw_offset(enum system_image_copy_t copy) +uint32_t flash_get_rw_offset(enum ec_image copy) { #ifdef CONFIG_VBOOT_EFS - if (copy == SYSTEM_IMAGE_RW_B) + if (copy == EC_IMAGE_RW_B) return CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_B_STORAGE_OFF; #endif if (is_rw_image(copy)) @@ -641,17 +641,17 @@ uint32_t flash_get_rw_offset(enum system_image_copy_t copy) return CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF; } -const struct image_data *system_get_image_data(enum system_image_copy_t copy) +const struct image_data *system_get_image_data(enum ec_image copy) { static struct image_data data; uintptr_t addr; - enum system_image_copy_t active_copy = system_get_image_copy(); + enum ec_image active_copy = system_get_image_copy(); /* Handle version of current image */ - if (copy == active_copy || copy == SYSTEM_IMAGE_UNKNOWN) + if (copy == active_copy || copy == EC_IMAGE_UNKNOWN) return ¤t_image_data; - if (active_copy == SYSTEM_IMAGE_UNKNOWN) + if (active_copy == EC_IMAGE_UNKNOWN) return NULL; /* @@ -688,7 +688,7 @@ const struct image_data *system_get_image_data(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) +const char *system_get_version(enum ec_image copy) { const struct image_data *data = system_get_image_data(copy); @@ -696,7 +696,7 @@ const char *system_get_version(enum system_image_copy_t copy) } #ifdef CONFIG_ROLLBACK -int32_t system_get_rollback_version(enum system_image_copy_t copy) +int32_t system_get_rollback_version(enum ec_image copy) { const struct image_data *data = system_get_image_data(copy); @@ -704,7 +704,7 @@ int32_t system_get_rollback_version(enum system_image_copy_t copy) } #endif -int system_get_image_used(enum system_image_copy_t copy) +int system_get_image_used(enum ec_image copy) { const struct image_data *data = system_get_image_data(copy); @@ -843,7 +843,7 @@ static int handle_pending_reboot(enum ec_reboot_cmd cmd) case EC_REBOOT_CANCEL: return EC_SUCCESS; case EC_REBOOT_JUMP_RO: - return system_run_image_copy(SYSTEM_IMAGE_RO); + return system_run_image_copy(EC_IMAGE_RO); case EC_REBOOT_JUMP_RW: return system_run_image_copy(system_get_active_copy()); case EC_REBOOT_COLD: @@ -1069,33 +1069,33 @@ static int command_version(int argc, char **argv) #ifdef CHIP_HAS_RO_B { - enum system_image_copy_t active; + enum ec_image active; active = system_get_ro_image_copy(); ccprintf("RO_A: %c %s\n", - (active == SYSTEM_IMAGE_RO ? '*' : ' '), - system_get_version(SYSTEM_IMAGE_RO)); + (active == EC_IMAGE_RO ? '*' : ' '), + system_get_version(EC_IMAGE_RO)); ccprintf("RO_B: %c %s\n", - (active == SYSTEM_IMAGE_RO_B ? '*' : ' '), - system_get_version(SYSTEM_IMAGE_RO_B)); + (active == EC_IMAGE_RO_B ? '*' : ' '), + system_get_version(EC_IMAGE_RO_B)); } #else - ccprintf("RO: %s\n", system_get_version(SYSTEM_IMAGE_RO)); + ccprintf("RO: %s\n", system_get_version(EC_IMAGE_RO)); #endif #ifdef CONFIG_RW_B { - enum system_image_copy_t active; + enum ec_image active; active = system_get_image_copy(); ccprintf("RW_A: %c %s\n", - (active == SYSTEM_IMAGE_RW ? '*' : ' '), - system_get_version(SYSTEM_IMAGE_RW)); + (active == EC_IMAGE_RW ? '*' : ' '), + system_get_version(EC_IMAGE_RW)); ccprintf("RW_B: %c %s\n", - (active == SYSTEM_IMAGE_RW_B ? '*' : ' '), - system_get_version(SYSTEM_IMAGE_RW_B)); + (active == EC_IMAGE_RW_B ? '*' : ' '), + system_get_version(EC_IMAGE_RW_B)); } #else - ccprintf("RW: %s\n", system_get_version(SYSTEM_IMAGE_RW)); + ccprintf("RW: %s\n", system_get_version(EC_IMAGE_RW)); #endif system_print_extended_version_info(); @@ -1118,12 +1118,12 @@ static int command_sysjump(int argc, char **argv) /* Handle named images */ if (!strcasecmp(argv[1], "RO")) - return system_run_image_copy(SYSTEM_IMAGE_RO); + return system_run_image_copy(EC_IMAGE_RO); else if (!strcasecmp(argv[1], "RW") || !strcasecmp(argv[1], "A")) - return system_run_image_copy(SYSTEM_IMAGE_RW); + return system_run_image_copy(EC_IMAGE_RW); else if (!strcasecmp(argv[1], "B")) { #ifdef CONFIG_RW_B - return system_run_image_copy(SYSTEM_IMAGE_RW_B); + return system_run_image_copy(EC_IMAGE_RW_B); #else return EC_ERROR_PARAM1; #endif @@ -1289,20 +1289,20 @@ static enum ec_status host_command_get_version(struct host_cmd_handler_args *args) { struct ec_response_get_version *r = args->response; - enum system_image_copy_t active_slot = system_get_active_copy(); + enum ec_image active_slot = system_get_active_copy(); - strzcpy(r->version_string_ro, system_get_version(SYSTEM_IMAGE_RO), + strzcpy(r->version_string_ro, system_get_version(EC_IMAGE_RO), sizeof(r->version_string_ro)); strzcpy(r->version_string_rw, system_get_version(active_slot), sizeof(r->version_string_rw)); switch (system_get_image_copy()) { - case SYSTEM_IMAGE_RO: + case EC_IMAGE_RO: r->current_image = EC_IMAGE_RO; break; - case SYSTEM_IMAGE_RW: - case SYSTEM_IMAGE_RW_B: + case EC_IMAGE_RW: + case EC_IMAGE_RW_B: r->current_image = EC_IMAGE_RW; break; default: diff --git a/common/tpm_registers.c b/common/tpm_registers.c index cd50c8574a..cd1afcd244 100644 --- a/common/tpm_registers.c +++ b/common/tpm_registers.c @@ -166,7 +166,7 @@ static uint8_t tpm_fw_ver[80] __attribute__((section(".bss.Tpm2_common"))); */ static void set_version_string(void) { - enum system_image_copy_t active_ro, active_rw; + enum ec_image active_ro, active_rw; size_t offset; active_ro = system_get_ro_image_copy(); @@ -175,7 +175,7 @@ static void set_version_string(void) snprintf(tpm_fw_ver, sizeof(tpm_fw_ver), "%s:%d RO_%c:%s", system_get_chip_revision(), system_get_board_version(), - (active_ro == SYSTEM_IMAGE_RO ? 'A' : 'B'), + (active_ro == EC_IMAGE_RO ? 'A' : 'B'), system_get_version(active_ro)); offset = strlen(tpm_fw_ver); if (offset == sizeof(tpm_fw_ver) - 1) @@ -183,7 +183,7 @@ static void set_version_string(void) snprintf(tpm_fw_ver + offset, sizeof(tpm_fw_ver) - offset, " RW_%c:%s", - (active_rw == SYSTEM_IMAGE_RW ? 'A' : 'B'), + (active_rw == EC_IMAGE_RW ? 'A' : 'B'), system_get_version(active_rw)); } diff --git a/common/update_fw.c b/common/update_fw.c index f9927fec9d..d0cb35e697 100644 --- a/common/update_fw.c +++ b/common/update_fw.c @@ -172,17 +172,17 @@ void fw_update_start(struct first_response_pdu *rpdu) /* Determine the valid update section. */ switch (system_get_image_copy()) { - case SYSTEM_IMAGE_RO: + case EC_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; - version = system_get_version(SYSTEM_IMAGE_RW); + version = system_get_version(EC_IMAGE_RW); break; - case SYSTEM_IMAGE_RW: + case EC_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; - version = system_get_version(SYSTEM_IMAGE_RO); + version = system_get_version(EC_IMAGE_RO); break; default: CPRINTF("%s:%d\n", __func__, __LINE__); diff --git a/common/usb_common.c b/common/usb_common.c index eb344cc279..4859d440e1 100644 --- a/common/usb_common.c +++ b/common/usb_common.c @@ -621,12 +621,9 @@ __overridable int pd_custom_vdm(int port, int cnt, uint32_t *payload, dev_id = VDO_INFO_HW_DEV_ID(payload[6]); is_rw = VDO_INFO_IS_RW(payload[6]); - is_latest = pd_dev_store_rw_hash(port, - dev_id, - payload + 1, - is_rw ? - SYSTEM_IMAGE_RW : - SYSTEM_IMAGE_RO); + is_latest = pd_dev_store_rw_hash( + port, dev_id, payload + 1, + is_rw ? EC_IMAGE_RW : EC_IMAGE_RO); /* * Send update host event unless our RW hash is @@ -643,7 +640,7 @@ __overridable int pd_custom_vdm(int port, int cnt, uint32_t *payload, } else if (cnt == 6) { /* really old devices don't have last byte */ pd_dev_store_rw_hash(port, dev_id, payload + 1, - SYSTEM_IMAGE_UNKNOWN); + EC_IMAGE_UNKNOWN); } break; case VDO_CMD_CURRENT: diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index 98ef076953..f3417a36a6 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -1129,7 +1129,7 @@ void pd_get_info(uint32_t *info_data) info_data[5] = VDO_INFO(CONFIG_USB_PD_HW_DEV_ID_BOARD_MAJOR, CONFIG_USB_PD_HW_DEV_ID_BOARD_MINOR, ver_get_num_commits(system_get_image_copy()), - (system_get_image_copy() != SYSTEM_IMAGE_RO)); + (system_get_image_copy() != EC_IMAGE_RO)); #else info_data[5] = 0; #endif @@ -1157,7 +1157,7 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload) break; case VDO_CMD_FLASH_ERASE: /* do not kill the code under our feet */ - if (system_get_image_copy() != SYSTEM_IMAGE_RO) + if (system_get_image_copy() != EC_IMAGE_RO) break; pd_log_event(PD_EVENT_ACC_RW_ERASE, 0, 0, NULL); flash_offset = CONFIG_EC_WRITABLE_STORAGE_OFF + @@ -1168,7 +1168,7 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload) break; case VDO_CMD_FLASH_WRITE: /* do not kill the code under our feet */ - if ((system_get_image_copy() != SYSTEM_IMAGE_RO) || + if ((system_get_image_copy() != EC_IMAGE_RO) || (flash_offset < CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF)) break; diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index e1b1b8e27b..4023026469 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -258,7 +258,7 @@ static struct pd_protocol { /* Attached ChromeOS device id, RW hash, and current RO / RW image */ uint16_t dev_id; uint32_t dev_rw_hash[PD_RW_HASH_SIZE/4]; - enum ec_current_image current_image; + enum ec_image current_image; #ifdef CONFIG_USB_PD_REV30 /* protocol revision */ uint8_t rev; @@ -5183,8 +5183,8 @@ static int command_pd(int argc, char **argv) ccprintf("Hash "); for (i = 0; i < PD_RW_HASH_SIZE / 4; i++) ccprintf("%08x ", pd[port].dev_rw_hash[i]); - ccprintf("\nImage %s\n", system_image_copy_t_to_string( - (enum system_image_copy_t)pd[port].current_image)); + ccprintf("\nImage %s\n", + ec_image_to_string(pd[port].current_image)); } else if (!strncasecmp(argv[2], "soft", 4)) { set_state(port, PD_STATE_SOFT_RESET); task_wake(PD_PORT_TO_TASK_ID(port)); diff --git a/common/usb_update.c b/common/usb_update.c index 64875fd798..23b3ed4512 100644 --- a/common/usb_update.c +++ b/common/usb_update.c @@ -253,7 +253,7 @@ static int try_vendor_command(struct consumer const *consumer, size_t count) response = EC_RES_ERROR; } #else - system_run_image_copy(SYSTEM_IMAGE_RW); + system_run_image_copy(EC_IMAGE_RW); #endif break; #ifdef CONFIG_RWSIG diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 524abde7b6..b1dfff731b 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -253,7 +253,7 @@ static struct type_c { /* Attached ChromeOS device id, RW hash, and current RO / RW image */ uint16_t dev_id; uint32_t dev_rw_hash[PD_RW_HASH_SIZE/4]; - enum ec_current_image current_image; + enum ec_image current_image; } tc[CONFIG_USB_PD_PORT_MAX_COUNT]; /* Port dual-role state */ @@ -573,8 +573,8 @@ void tc_print_dev_info(int port) for (i = 0; i < PD_RW_HASH_SIZE / 4; i++) ccprintf("%08x ", tc[port].dev_rw_hash[i]); - ccprintf("\nImage %s\n", system_image_copy_t_to_string( - (enum system_image_copy_t)tc[port].current_image)); + ccprintf("\nImage %s\n", ec_image_to_string( + tc[port].current_image)); } int tc_is_attached_src(int port) diff --git a/common/vboot/vboot.c b/common/vboot/vboot.c index 93557e7529..38924f4b3e 100644 --- a/common/vboot/vboot.c +++ b/common/vboot/vboot.c @@ -33,7 +33,7 @@ static int has_matrix_keyboard(void) return 0; } -static int verify_slot(enum system_image_copy_t slot) +static int verify_slot(enum ec_image slot) { const struct vb21_packed_key *vb21_key; const struct vb21_signature *vb21_sig; @@ -43,7 +43,7 @@ static int verify_slot(enum system_image_copy_t slot) int len; int rv; - CPRINTS("Verifying %s", system_image_copy_t_to_string(slot)); + CPRINTS("Verifying %s", ec_image_to_string(slot)); vb21_key = (const struct vb21_packed_key *)( CONFIG_MAPPED_STORAGE_BASE + @@ -57,7 +57,7 @@ static int verify_slot(enum system_image_copy_t slot) key = (const struct rsa_public_key *) ((const uint8_t *)vb21_key + vb21_key->key_offset); - if (slot == SYSTEM_IMAGE_RW_A) { + if (slot == EC_IMAGE_RW_A) { data = (const uint8_t *)(CONFIG_MAPPED_STORAGE_BASE + CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_A_STORAGE_OFF); @@ -95,7 +95,7 @@ static int verify_slot(enum system_image_copy_t slot) return EC_ERROR_INVAL; } - CPRINTS("Verified %s", system_image_copy_t_to_string(slot)); + CPRINTS("Verified %s", ec_image_to_string(slot)); return EC_SUCCESS; } @@ -103,7 +103,7 @@ static int verify_slot(enum system_image_copy_t slot) static enum ec_status hc_verify_slot(struct host_cmd_handler_args *args) { const struct ec_params_efs_verify *p = args->params; - enum system_image_copy_t slot; + enum ec_image slot; switch (p->region) { case EC_FLASH_REGION_ACTIVE: @@ -121,7 +121,7 @@ DECLARE_HOST_COMMAND(EC_CMD_EFS_VERIFY, hc_verify_slot, EC_VER_MASK(0)); static int verify_and_jump(void) { - enum system_image_copy_t slot; + enum ec_image slot; int rv; /* 1. Decide which slot to try */ @@ -144,7 +144,7 @@ static int verify_and_jump(void) * will catch it and request recovery after a few attempts. */ if (system_set_active_copy(slot)) CPRINTS("Failed to activate %s", - system_image_copy_t_to_string(slot)); + ec_image_to_string(slot)); } /* 3. Jump (and reboot) */ diff --git a/common/vboot_hash.c b/common/vboot_hash.c index 0387040670..10de58fcac 100644 --- a/common/vboot_hash.c +++ b/common/vboot_hash.c @@ -273,7 +273,7 @@ static uint32_t get_rw_size(void) * verifies only the used image size. */ return CONFIG_RW_SIZE; #else - return system_get_image_used(SYSTEM_IMAGE_RW); + return system_get_image_used(EC_IMAGE_RW); #endif } @@ -397,7 +397,7 @@ static int command_hash(int argc, char **argv) return vboot_hash_start( CONFIG_EC_PROTECTED_STORAGE_OFF + CONFIG_RO_STORAGE_OFF, - system_get_image_used(SYSTEM_IMAGE_RO), + system_get_image_used(EC_IMAGE_RO), NULL, 0, VBOOT_HASH_DEFERRED); } return EC_ERROR_PARAM2; @@ -471,7 +471,7 @@ static int host_start_hash(const struct ec_params_vboot_hash *p) /* Handle special offset values */ if (offset == EC_VBOOT_HASH_OFFSET_RO) - size = system_get_image_used(SYSTEM_IMAGE_RO); + size = system_get_image_used(EC_IMAGE_RO); else if ((offset == EC_VBOOT_HASH_OFFSET_ACTIVE) || (offset == EC_VBOOT_HASH_OFFSET_UPDATE)) size = get_rw_size(); diff --git a/common/version.c b/common/version.c index 412faff94f..1888fc0aef 100644 --- a/common/version.c +++ b/common/version.c @@ -8,6 +8,7 @@ #include <stdint.h> #include "common.h" #include "compile_time_macros.h" +#include "ec_commands.h" #include "ec_version.h" #include "stddef.h" #include "system.h" @@ -62,7 +63,7 @@ static int get_num_commits(const struct image_data *data) } -int ver_get_num_commits(enum system_image_copy_t copy) +int ver_get_num_commits(enum ec_image copy) { const struct image_data *data; if (IS_ENABLED(CONFIG_COMMON_RUNTIME)) diff --git a/include/ec_commands.h b/include/ec_commands.h index b9b8d95847..7e3c784e49 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1050,10 +1050,22 @@ struct ec_response_hello { /* Get version number */ #define EC_CMD_GET_VERSION 0x0002 -enum ec_current_image { +#ifndef CHROMIUM_EC +/* + * enum ec_current_image is deprecated and replaced by enum ec_image. This + * macro exists for backwards compatibility of external projects until they + * have been updated: b/149987779. + */ +#define ec_current_image ec_image +#endif + +enum ec_image { EC_IMAGE_UNKNOWN = 0, EC_IMAGE_RO, - EC_IMAGE_RW + EC_IMAGE_RW, + EC_IMAGE_RW_A = EC_IMAGE_RW, + EC_IMAGE_RO_B, + EC_IMAGE_RW_B }; /** @@ -1061,7 +1073,7 @@ enum ec_current_image { * @version_string_ro: Null-terminated RO firmware version string. * @version_string_rw: Null-terminated RW firmware version string. * @reserved: Unused bytes; was previously RW-B firmware version string. - * @current_image: One of ec_current_image. + * @current_image: One of ec_image. */ struct ec_response_get_version { char version_string_ro[32]; @@ -5368,7 +5380,7 @@ struct ec_params_usb_pd_rw_hash_entry { * TODO(rspangler) but it's not aligned! * Should have been reserved[2]. */ - uint32_t current_image; /* One of ec_current_image */ + uint32_t current_image; /* One of ec_image */ } __ec_align1; /* Read USB-PD Accessory info */ diff --git a/include/system.h b/include/system.h index 249ab58bf4..af9fafb088 100644 --- a/include/system.h +++ b/include/system.h @@ -12,23 +12,13 @@ #include "common.h" #include "compile_time_macros.h" #include "console.h" +#include "ec_commands.h" #include "timer.h" /* Per chip implementation to save/read raw EC_RESET_FLAG_ flags. */ void chip_save_reset_flags(uint32_t flags); uint32_t chip_read_reset_flags(void); -/* System images */ -enum system_image_copy_t { - SYSTEM_IMAGE_UNKNOWN = 0, - SYSTEM_IMAGE_RO, - SYSTEM_IMAGE_RW, - SYSTEM_IMAGE_RW_A = SYSTEM_IMAGE_RW, - /* Some systems may have these too */ - SYSTEM_IMAGE_RO_B, - SYSTEM_IMAGE_RW_B, -}; - /** * Checks if running image is RW or not * @@ -110,13 +100,13 @@ void system_disable_jump(void); /** * Return the image copy which is currently running. */ -enum system_image_copy_t system_get_image_copy(void); +enum ec_image system_get_image_copy(void); /** * Return the active RO image copy so that if we're in RW, we can know how we * got there. Only needed when there are multiple RO images. */ -enum system_image_copy_t system_get_ro_image_copy(void); +enum ec_image system_get_ro_image_copy(void); /** * Return the program memory address where the image copy begins or should @@ -124,7 +114,7 @@ enum system_image_copy_t system_get_ro_image_copy(void); * reside at the location returned. Returns INVALID_ADDR if the image copy is * not supported. */ -uintptr_t get_program_memory_addr(enum system_image_copy_t copy); +uintptr_t get_program_memory_addr(enum ec_image copy); #define INVALID_ADDR ((uintptr_t)0xffffffff) /** @@ -179,7 +169,7 @@ const char *system_get_image_copy_string(void); /** * Return a text description of the passed image copy parameter. */ -const char *system_image_copy_t_to_string(enum system_image_copy_t copy); +const char *ec_image_to_string(enum ec_image copy); /** * Return the number of bytes used in the specified image. @@ -190,12 +180,12 @@ const char *system_image_copy_t_to_string(enum system_image_copy_t copy); * @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); +int system_get_image_used(enum ec_image copy); /** * Jump to the specified image copy. */ -int system_run_image_copy(enum system_image_copy_t copy); +int system_run_image_copy(enum ec_image copy); /** * Get the rollback version for an image @@ -204,7 +194,7 @@ int system_run_image_copy(enum system_image_copy_t copy); * to get the version for the currently running image. * @return The rollback version, negative value on error. */ -int32_t system_get_rollback_version(enum system_image_copy_t copy); +int32_t system_get_rollback_version(enum ec_image copy); /** * Get the image data of an image @@ -212,7 +202,7 @@ int32_t system_get_rollback_version(enum system_image_copy_t copy); * @param copy Image copy to get the version of. * @return Image data */ -const struct image_data *system_get_image_data(enum system_image_copy_t copy); +const struct image_data *system_get_image_data(enum ec_image copy); /** * Get the version string for an image @@ -222,7 +212,7 @@ const struct image_data *system_get_image_data(enum system_image_copy_t copy); * @return The version string for the image copy, or an empty string if * error. */ -const char *system_get_version(enum system_image_copy_t copy); +const char *system_get_version(enum ec_image copy); /** * Get the SKU ID for a device @@ -576,7 +566,7 @@ uint32_t system_get_lfw_address(void); * * @param copy Region - (RO/RW) to use in code ram */ -void system_set_image_copy(enum system_image_copy_t copy); +void system_set_image_copy(enum ec_image copy); /** * Return which region is used in Code RAM @@ -584,7 +574,7 @@ void system_set_image_copy(enum system_image_copy_t copy); * Note: This feature is used for code ram arch * */ -enum system_image_copy_t system_get_shrspi_image_copy(void); +enum ec_image system_get_shrspi_image_copy(void); /** * Determine reset vector will be jumped to the assigned address. @@ -623,14 +613,14 @@ int system_can_boot_ap(void); * * @return Active copy index */ -enum system_image_copy_t system_get_active_copy(void); +enum ec_image system_get_active_copy(void); /** * Get updatable (non-active) image copy * * @return Updatable copy index */ -enum system_image_copy_t system_get_update_copy(void); +enum ec_image system_get_update_copy(void); /** * Set active image copy @@ -638,7 +628,7 @@ enum system_image_copy_t system_get_update_copy(void); * @param copy Copy id to be activated. * @return Non-zero if error. */ -int system_set_active_copy(enum system_image_copy_t copy); +int system_set_active_copy(enum ec_image copy); /** * Get flash offset of a RW copy @@ -646,6 +636,6 @@ int system_set_active_copy(enum system_image_copy_t copy); * @param copy Copy index to get the flash offset of. * @return Flash offset of the slot storing <copy> */ -uint32_t flash_get_rw_offset(enum system_image_copy_t copy); +uint32_t flash_get_rw_offset(enum ec_image copy); #endif /* __CROS_EC_SYSTEM_H */ diff --git a/include/usb_pd.h b/include/usb_pd.h index 3b9e75a636..1cb1e42f57 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -1946,7 +1946,7 @@ __override_proto bool board_is_tbt_usb4_port(int port); * in our table, false otherwise */ int pd_dev_store_rw_hash(int port, uint16_t dev_id, uint32_t *rw_hash, - uint32_t ec_current_image); + uint32_t ec_image); /** * Get Device ID & RW hash of device diff --git a/include/version.h b/include/version.h index 71e215c8e2..0d3e777dc5 100644 --- a/include/version.h +++ b/include/version.h @@ -32,5 +32,5 @@ extern const void *__image_size; * * @return Number of commits in integer or 0 on error */ -int ver_get_num_commits(enum system_image_copy_t copy); +int ver_get_num_commits(enum ec_image copy); #endif /* __CROS_EC_VERSION_H */ diff --git a/power/mt8183.c b/power/mt8183.c index 08789f09f2..7efbd15e44 100644 --- a/power/mt8183.c +++ b/power/mt8183.c @@ -385,7 +385,7 @@ enum power_state power_handle_state(enum power_state state) } /* If EC is in RW, or has already booted once, reboot to RO. */ - if (system_get_image_copy() != SYSTEM_IMAGE_RO || booted) { + if (system_get_image_copy() != EC_IMAGE_RO || booted) { /* * TODO(b:109850749): How quickly does the EC come back * up? Would IN_PGOOD_PMIC be ready by the time we are diff --git a/test/fake_usbc.c b/test/fake_usbc.c index d8ed1d42f9..c9163f1cfe 100644 --- a/test/fake_usbc.c +++ b/test/fake_usbc.c @@ -127,7 +127,7 @@ __overridable void tc_snk_power_off(int port) {} int pd_dev_store_rw_hash(int port, uint16_t dev_id, uint32_t *rw_hash, - uint32_t ec_current_image) + uint32_t ec_image) { return 0; } diff --git a/test/flash.c b/test/flash.c index 7fcb672f29..fef33ffd17 100644 --- a/test/flash.c +++ b/test/flash.c @@ -287,7 +287,7 @@ static int test_overwrite_current(void) uint32_t offset, size; /* Test that we cannot overwrite current image */ - if (system_get_image_copy() == SYSTEM_IMAGE_RO) { + if (system_get_image_copy() == EC_IMAGE_RO) { offset = CONFIG_RO_STORAGE_OFF; size = CONFIG_RO_SIZE; } else { diff --git a/test/kb_8042.c b/test/kb_8042.c index ab28df544c..a34c6d8513 100644 --- a/test/kb_8042.c +++ b/test/kb_8042.c @@ -232,7 +232,7 @@ static int test_sysjump(void) set_scancode(2); enable_keystroke(1); - system_run_image_copy(SYSTEM_IMAGE_RW); + system_run_image_copy(EC_IMAGE_RW); /* Shouldn't reach here */ return EC_ERROR_UNKNOWN; @@ -260,7 +260,7 @@ void run_test(void) test_reset(); wait_for_task_started(); - if (system_get_image_copy() == SYSTEM_IMAGE_RO) { + if (system_get_image_copy() == EC_IMAGE_RO) { RUN_TEST(test_single_key_press); RUN_TEST(test_disable_keystroke); RUN_TEST(test_typematic); diff --git a/util/ectool.c b/util/ectool.c index 50f64e8ab2..bf7f11ce65 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -324,7 +324,7 @@ const char help_str[] = " Enable/disable WLAN/Bluetooth radio\n" ""; -/* Note: depends on enum system_image_copy_t */ +/* Note: depends on enum ec_image */ static const char * const image_names[] = {"unknown", "RO", "RW"}; /* Note: depends on enum ec_led_colors */ diff --git a/util/genvif.c b/util/genvif.c index 796384aee0..66640a8a03 100644 --- a/util/genvif.c +++ b/util/genvif.c @@ -42,9 +42,9 @@ char *yes_no(int val) return val ? "YES" : "NO"; } -enum system_image_copy_t system_get_image_copy(void) +enum ec_image system_get_image_copy(void) { - return SYSTEM_IMAGE_RW; + return EC_IMAGE_RW; } static void write_title(FILE *vif) |