diff options
author | Tim Lin <tim2.lin@ite.corp-partner.google.com> | 2021-06-04 14:11:25 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-09 18:54:47 +0000 |
commit | 670bd7e258d352a2ea197e055e46b60690935afc (patch) | |
tree | 9a223dbbdde5e822f63475fdb0a39c0dc1300112 | |
parent | 3bf7cf9dfe738f1f156d6b9dc5ade87290d1d78e (diff) | |
download | chrome-ec-670bd7e258d352a2ea197e055e46b60690935afc.tar.gz |
include/flash: rename the APIs
The names conflict when enabling both Zephyr's flash driver and
CONFIG_FLASH_CROS option. Rename all the APIs in include/flash.h
BUG=b:187192628
BRANCH=none
TEST=make buildall -j4
Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
Change-Id: If1fd0ea28fa9f5cec1c1daa8f72f63eb7a0e6500
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2931749
Commit-Queue: Keith Short <keithshort@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
37 files changed, 396 insertions, 382 deletions
diff --git a/board/zinger/hardware.c b/board/zinger/hardware.c index 7e1f29da38..2aceb801e4 100644 --- a/board/zinger/hardware.c +++ b/board/zinger/hardware.c @@ -302,7 +302,7 @@ int adc_disable_watchdog(void) #define CR_LOCK BIT(7) #define OPTWRE BIT(9) -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { uint16_t *address = (uint16_t *)(CONFIG_PROGRAM_MEMORY_BASE + offset); int res = EC_SUCCESS; @@ -354,7 +354,7 @@ exit_wr: return res; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int res = EC_SUCCESS; diff --git a/chip/host/flash.c b/chip/host/flash.c index 95d46d9f34..75212737e0 100644 --- a/chip/host/flash.c +++ b/chip/host/flash.c @@ -67,7 +67,7 @@ static void flash_get_persistent(void) release_persistent_storage(f); } -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { ASSERT((size & (CONFIG_FLASH_WRITE_SIZE - 1)) == 0); @@ -83,7 +83,7 @@ int flash_physical_write(int offset, int size, const char *data) return EC_SUCCESS; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { ASSERT((size & (CONFIG_FLASH_ERASE_SIZE - 1)) == 0); @@ -99,12 +99,12 @@ int flash_physical_erase(int offset, int size) return EC_SUCCESS; } -int flash_physical_get_protect(int bank) +int crec_flash_physical_get_protect(int bank) { return __host_flash_protect[bank]; } -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { int i; uint32_t flags = EC_FLASH_PROTECT_ALL_NOW; @@ -116,20 +116,20 @@ uint32_t flash_physical_get_protect_flags(void) return flags; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { memset(__host_flash_protect, 1, all ? PHYSICAL_BANKS : WP_BANK_COUNT); return EC_SUCCESS; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; @@ -148,13 +148,13 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) return ret; } -int flash_pre_init(void) +int crec_flash_pre_init(void) { uint32_t prot_flags; flash_get_persistent(); - prot_flags = flash_get_protect(); + prot_flags = crec_flash_get_protect(); if (prot_flags & EC_FLASH_PROTECT_GPIO_ASSERTED) { /* @@ -163,13 +163,13 @@ int flash_pre_init(void) */ if ((prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT) && !(prot_flags & EC_FLASH_PROTECT_RO_NOW)) { - int rv = flash_set_protect(EC_FLASH_PROTECT_RO_NOW, + int rv = crec_flash_set_protect(EC_FLASH_PROTECT_RO_NOW, EC_FLASH_PROTECT_RO_NOW); if (rv) return rv; /* Re-read flags */ - prot_flags = flash_get_protect(); + prot_flags = crec_flash_get_protect(); } } diff --git a/chip/ish/flash.c b/chip/ish/flash.c index 8ef4d1a73c..2a1b9c0793 100644 --- a/chip/ish/flash.c +++ b/chip/ish/flash.c @@ -12,7 +12,7 @@ * * Applies at-boot protection settings if necessary. */ -int flash_pre_init(void) +int crec_flash_pre_init(void) { return EC_SUCCESS; } diff --git a/chip/it83xx/flash.c b/chip/it83xx/flash.c index aa1e280159..46a833afdb 100644 --- a/chip/it83xx/flash.c +++ b/chip/it83xx/flash.c @@ -411,7 +411,7 @@ static void flash_protect_banks(int start_bank, } } -int FLASH_DMA_CODE flash_physical_read(int offset, int size, char *data) +int FLASH_DMA_CODE crec_flash_physical_read(int offset, int size, char *data) { int i; @@ -432,7 +432,8 @@ int FLASH_DMA_CODE flash_physical_read(int offset, int size, char *data) * @param size Number of bytes to write. * @param data Data to write to flash. Must be 32-bit aligned. */ -int FLASH_DMA_CODE flash_physical_write(int offset, int size, const char *data) +int FLASH_DMA_CODE crec_flash_physical_write(int offset, int size, + const char *data) { int ret = EC_ERROR_UNKNOWN; @@ -479,7 +480,7 @@ int FLASH_DMA_CODE flash_physical_write(int offset, int size, const char *data) * @param offset Flash offset to erase. * @param size Number of bytes to erase. */ -int FLASH_DMA_CODE flash_physical_erase(int offset, int size) +int FLASH_DMA_CODE crec_flash_physical_erase(int offset, int size) { int v_size = size, v_addr = offset, ret = EC_ERROR_UNKNOWN; @@ -539,7 +540,7 @@ int FLASH_DMA_CODE flash_physical_erase(int offset, int size) * @param bank Bank index to check. * @return non-zero if bank is protected until reboot. */ -int flash_physical_get_protect(int bank) +int crec_flash_physical_get_protect(int bank) { return IT83XX_GCTRL_EWPR0PFEC(FWP_REG(bank)) & FWP_MASK(bank); } @@ -550,7 +551,7 @@ int flash_physical_get_protect(int bank) * @param all Protect all (=1) or just read-only and pstate (=0). * @return non-zero if error. */ -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { if (all) { /* Protect the entire flash */ @@ -584,7 +585,7 @@ int flash_physical_protect_now(int all) * * Uses the EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -609,7 +610,7 @@ uint32_t flash_physical_get_protect_flags(void) * * @return A combination of EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | @@ -622,7 +623,7 @@ uint32_t flash_physical_get_valid_flags(void) * @param cur_flags The current flash protect flags. * @return A combination of EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; @@ -726,7 +727,7 @@ static void flash_code_static_dma(void) * * Applies at-boot protection settings if necessary. */ -int flash_pre_init(void) +int crec_flash_pre_init(void) { int32_t reset_flags, prot_flags, unwanted_prot_flags; @@ -742,7 +743,7 @@ int flash_pre_init(void) flash_enable_second_ilm(); reset_flags = system_get_reset_flags(); - prot_flags = flash_get_protect(); + prot_flags = crec_flash_get_protect(); unwanted_prot_flags = EC_FLASH_PROTECT_ALL_NOW | EC_FLASH_PROTECT_ERROR_INCONSISTENT; @@ -768,13 +769,13 @@ int flash_pre_init(void) */ if ((prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT) && !(prot_flags & EC_FLASH_PROTECT_RO_NOW)) { - int rv = flash_set_protect(EC_FLASH_PROTECT_RO_NOW, + int rv = crec_flash_set_protect(EC_FLASH_PROTECT_RO_NOW, EC_FLASH_PROTECT_RO_NOW); if (rv) return rv; /* Re-read flags */ - prot_flags = flash_get_protect(); + prot_flags = crec_flash_get_protect(); } } else { /* Don't want RO flash protected */ diff --git a/chip/it83xx/system.c b/chip/it83xx/system.c index 7281977e44..a85cbe7c0f 100644 --- a/chip/it83xx/system.c +++ b/chip/it83xx/system.c @@ -312,9 +312,9 @@ void system_reset(int flags) #if defined(CONFIG_PRESERVE_LOGS) && defined(CONFIG_IT83XX_HARD_RESET_BY_GPG1) /* Saving EC logs into flash before reset. */ - flash_physical_erase(CHIP_FLASH_PRESERVE_LOGS_BASE, + crec_flash_physical_erase(CHIP_FLASH_PRESERVE_LOGS_BASE, CHIP_FLASH_PRESERVE_LOGS_SIZE); - flash_physical_write(CHIP_FLASH_PRESERVE_LOGS_BASE, + crec_flash_physical_write(CHIP_FLASH_PRESERVE_LOGS_BASE, (uintptr_t)__preserved_logs_size, __preserved_logs_start); BRAM_EC_LOG_STATUS = EC_LOG_SAVED_IN_FLASH; #endif diff --git a/chip/lm4/flash.c b/chip/lm4/flash.c index 5e0c6510f3..5b61874984 100644 --- a/chip/lm4/flash.c +++ b/chip/lm4/flash.c @@ -87,7 +87,7 @@ static int write_buffer(void) /*****************************************************************************/ /* Physical layer APIs */ -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { const uint32_t *data32 = (const uint32_t *)data; int rv; @@ -125,7 +125,7 @@ int flash_physical_write(int offset, int size, const char *data) return EC_SUCCESS; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { if (all_protected) return EC_ERROR_ACCESS_DENIED; @@ -137,7 +137,7 @@ int flash_physical_erase(int offset, int size) int t; /* Do nothing if already erased */ - if (flash_is_erased(offset, CONFIG_FLASH_ERASE_SIZE)) + if (crec_flash_is_erased(offset, CONFIG_FLASH_ERASE_SIZE)) continue; LM4_FLASH_FMA = offset; @@ -168,12 +168,12 @@ int flash_physical_erase(int offset, int size) return EC_SUCCESS; } -int flash_physical_get_protect(int bank) +int crec_flash_physical_get_protect(int bank) { return (LM4_FLASH_FMPPE[F_BANK(bank)] & F_BIT(bank)) ? 0 : 1; } -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -188,7 +188,7 @@ uint32_t flash_physical_get_protect_flags(void) return flags; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { if (all) { /* Protect the entire flash */ @@ -202,14 +202,14 @@ int flash_physical_protect_now(int all) return EC_SUCCESS; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; @@ -232,10 +232,10 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) /*****************************************************************************/ /* High-level APIs */ -int flash_pre_init(void) +int crec_flash_pre_init(void) { uint32_t reset_flags = system_get_reset_flags(); - uint32_t prot_flags = flash_get_protect(); + uint32_t prot_flags = crec_flash_get_protect(); uint32_t unwanted_prot_flags = EC_FLASH_PROTECT_ALL_NOW | EC_FLASH_PROTECT_ERROR_INCONSISTENT; @@ -253,13 +253,13 @@ int flash_pre_init(void) */ if ((prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT) && !(prot_flags & EC_FLASH_PROTECT_RO_NOW)) { - int rv = flash_set_protect(EC_FLASH_PROTECT_RO_NOW, + int rv = crec_flash_set_protect(EC_FLASH_PROTECT_RO_NOW, EC_FLASH_PROTECT_RO_NOW); if (rv) return rv; /* Re-read flags */ - prot_flags = flash_get_protect(); + prot_flags = crec_flash_get_protect(); } /* Update all-now flag if all flash is protected */ diff --git a/chip/max32660/flash_chip.c b/chip/max32660/flash_chip.c index ace87294a7..747d7dcc58 100644 --- a/chip/max32660/flash_chip.c +++ b/chip/max32660/flash_chip.c @@ -108,7 +108,7 @@ static int flash_device_page_erase(uint32_t address) return EC_SUCCESS; } -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { int err; uint32_t bytes_written; @@ -232,7 +232,7 @@ int flash_physical_write(int offset, int size, const char *data) /*****************************************************************************/ /* Physical layer APIs */ -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int i; int pages; @@ -255,38 +255,38 @@ int flash_physical_erase(int offset, int size) return EC_SUCCESS; } -int flash_physical_get_protect(int bank) +int crec_flash_physical_get_protect(int bank) { /* Not protected */ return 0; } -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { /* no flags set */ return 0; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { /* These are the flags we're going to pay attention to */ return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { /* no flags writable */ return 0; } -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { /* nothing to do here */ return EC_SUCCESS; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { /* nothing to do here */ return EC_SUCCESS; @@ -295,7 +295,7 @@ int flash_physical_protect_now(int all) /*****************************************************************************/ /* High-level APIs */ -int flash_pre_init(void) +int crec_flash_pre_init(void) { return EC_SUCCESS; } @@ -330,10 +330,10 @@ static int command_flash_test1(int argc, char **argv) /* * erase page */ - error_status = flash_physical_erase(flash_address, + error_status = crec_flash_physical_erase(flash_address, CONFIG_FLASH_ERASE_SIZE); if (error_status != EC_SUCCESS) { - CPRINTS("Error with flash_physical_erase\n"); + CPRINTS("Error with crec_flash_physical_erase\n"); return EC_ERROR_UNKNOWN; } @@ -356,10 +356,10 @@ static int command_flash_test1(int argc, char **argv) for (i = 0; i < BUFFER_SIZE; i++) { buffer[i] = i + page; } - error_status = flash_physical_write(flash_address, BUFFER_SIZE, - buffer); + error_status = crec_flash_physical_write(flash_address, + BUFFER_SIZE, buffer); if (error_status != EC_SUCCESS) { - CPRINTS("Error with flash_physical_write\n"); + CPRINTS("Error with crec_flash_physical_write\n"); return EC_ERROR_UNKNOWN; } } @@ -389,10 +389,10 @@ static int command_flash_test1(int argc, char **argv) */ for (page = PAGE_START; page <= PAGE_END; page++) { flash_address = page * CONFIG_FLASH_ERASE_SIZE; - error_status = flash_physical_erase(flash_address, + error_status = crec_flash_physical_erase(flash_address, CONFIG_FLASH_ERASE_SIZE); if (error_status != EC_SUCCESS) { - CPRINTS("Error with flash_physical_erase\n"); + CPRINTS("Error with crec_flash_physical_erase\n"); return EC_ERROR_UNKNOWN; } } diff --git a/chip/mchp/flash.c b/chip/mchp/flash.c index 043e2b268f..1679cf92cb 100644 --- a/chip/mchp/flash.c +++ b/chip/mchp/flash.c @@ -35,7 +35,7 @@ struct flash_wp_state { * @param size Number of bytes to write. * @param data Destination buffer for data. */ -int flash_physical_read(int offset, int size, char *data) +int crec_flash_physical_read(int offset, int size, char *data) { trace13(0, FLASH, 0, "flash_phys_read: offset=0x%08X size=0x%08X dataptr=0x%08X", @@ -52,7 +52,7 @@ int flash_physical_read(int offset, int size, char *data) * @param size Number of bytes to write. * @param data Data to write to flash. Must be 32-bit aligned. */ -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { int ret = EC_SUCCESS; int i, write_size; @@ -87,7 +87,7 @@ int flash_physical_write(int offset, int size, const char *data) * @param offset Flash offset to erase. * @param size Number of bytes to erase. */ -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int ret; @@ -107,7 +107,7 @@ int flash_physical_erase(int offset, int size) * @param bank Bank index to check. * @return non-zero if bank is protected until reboot. */ -int flash_physical_get_protect(int bank) +int crec_flash_physical_get_protect(int bank) { return spi_flash_check_protect(bank * CONFIG_FLASH_BANK_SIZE, CONFIG_FLASH_BANK_SIZE); @@ -121,7 +121,7 @@ int flash_physical_get_protect(int bank) * @param all Protect all (=1) or just read-only * @return non-zero if error. */ -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { if (all) entire_flash_locked = 1; @@ -142,7 +142,7 @@ int flash_physical_protect_now(int all) * * Uses the EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -162,7 +162,7 @@ uint32_t flash_physical_get_protect_flags(void) * * @return A combination of EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | @@ -175,7 +175,7 @@ uint32_t flash_physical_get_valid_flags(void) * @param cur_flags The current flash protect flags. * @return A combination of EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; enum spi_flash_wp wp_status = SPI_WP_NONE; @@ -204,7 +204,7 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) * @param range The range to protect. * @return EC_SUCCESS, or nonzero if error. */ -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { int offset, size, ret; enum spi_flash_wp flashwp = SPI_WP_NONE; @@ -234,13 +234,13 @@ int flash_physical_protect_at_boot(uint32_t new_flags) * * Applies at-boot protection settings if necessary. */ -int flash_pre_init(void) +int crec_flash_pre_init(void) { - flash_physical_restore_state(); + crec_flash_physical_restore_state(); return EC_SUCCESS; } -int flash_physical_restore_state(void) +int crec_flash_physical_restore_state(void) { uint32_t reset_flags = system_get_reset_flags(); int version, size; diff --git a/chip/mec1322/flash.c b/chip/mec1322/flash.c index b6ab76113b..fac5b08d8f 100644 --- a/chip/mec1322/flash.c +++ b/chip/mec1322/flash.c @@ -34,7 +34,7 @@ struct flash_wp_state { * @param size Number of bytes to write. * @param data Destination buffer for data. */ -int flash_physical_read(int offset, int size, char *data) +int crec_flash_physical_read(int offset, int size, char *data) { return spi_flash_read(data, offset, size); } @@ -48,7 +48,7 @@ int flash_physical_read(int offset, int size, char *data) * @param size Number of bytes to write. * @param data Data to write to flash. Must be 32-bit aligned. */ -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { int ret = EC_SUCCESS; int i, write_size; @@ -79,7 +79,7 @@ int flash_physical_write(int offset, int size, const char *data) * @param offset Flash offset to erase. * @param size Number of bytes to erase. */ -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int ret; @@ -96,7 +96,7 @@ int flash_physical_erase(int offset, int size) * @param bank Bank index to check. * @return non-zero if bank is protected until reboot. */ -int flash_physical_get_protect(int bank) +int crec_flash_physical_get_protect(int bank) { return spi_flash_check_protect(bank * CONFIG_FLASH_BANK_SIZE, CONFIG_FLASH_BANK_SIZE); @@ -110,7 +110,7 @@ int flash_physical_get_protect(int bank) * @param all Protect all (=1) or just read-only * @return non-zero if error. */ -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { if (all) entire_flash_locked = 1; @@ -131,7 +131,7 @@ int flash_physical_protect_now(int all) * * Uses the EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -151,7 +151,7 @@ uint32_t flash_physical_get_protect_flags(void) * * @return A combination of EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | @@ -164,7 +164,7 @@ uint32_t flash_physical_get_valid_flags(void) * @param cur_flags The current flash protect flags. * @return A combination of EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; enum spi_flash_wp wp_status = SPI_WP_NONE; @@ -195,7 +195,7 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) * taken care of) * @return EC_SUCCESS, or nonzero if error. */ -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { int offset, size, ret; enum spi_flash_wp flashwp = SPI_WP_NONE; @@ -225,13 +225,13 @@ int flash_physical_protect_at_boot(uint32_t new_flags) * * Applies at-boot protection settings if necessary. */ -int flash_pre_init(void) +int crec_flash_pre_init(void) { - flash_physical_restore_state(); + crec_flash_physical_restore_state(); return EC_SUCCESS; } -int flash_physical_restore_state(void) +int crec_flash_physical_restore_state(void) { uint32_t reset_flags = system_get_reset_flags(); int version, size; diff --git a/chip/npcx/flash.c b/chip/npcx/flash.c index a5f656f8ca..507b83714c 100644 --- a/chip/npcx/flash.c +++ b/chip/npcx/flash.c @@ -153,7 +153,7 @@ static uint8_t flash_get_status1(void) return saved_sr1; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); /* Disable tri-state */ TRISTATE_FLASH(0); @@ -165,7 +165,7 @@ static uint8_t flash_get_status1(void) ret = NPCX_UMA_DB0; /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return ret; } @@ -178,7 +178,7 @@ static uint8_t flash_get_status2(void) return saved_sr2; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); /* Disable tri-state */ TRISTATE_FLASH(0); @@ -190,7 +190,7 @@ static uint8_t flash_get_status2(void) ret = NPCX_UMA_DB0; /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return ret; } @@ -217,7 +217,7 @@ static void flash_protect_int_flash(int enable) void flash_get_mfr_dev_id(uint8_t *dest) { /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); /* Disable tri-state */ TRISTATE_FLASH(0); @@ -232,7 +232,7 @@ void flash_get_mfr_dev_id(uint8_t *dest) dest[1] = NPCX_UMA_DB1; /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); } #endif /* CONFIG_HOSTCMD_FLASH_SPI_INFO */ @@ -240,7 +240,7 @@ void flash_get_mfr_dev_id(uint8_t *dest) void flash_get_jedec_id(uint8_t *dest) { /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); /* Disable tri-state */ TRISTATE_FLASH(0); @@ -254,7 +254,7 @@ void flash_get_jedec_id(uint8_t *dest) dest[2] = NPCX_UMA_DB2; /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); } static void flash_uma_lock(int enable) @@ -284,7 +284,7 @@ static int flash_set_status_for_prot(int reg1, int reg2) return EC_ERROR_ACCESS_DENIED; #endif - if (flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) + if (crec_flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) return EC_ERROR_ACCESS_DENIED; flash_uma_lock(0); } @@ -302,7 +302,7 @@ static int flash_set_status_for_prot(int reg1, int reg2) #endif /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); /* Disable tri-state */ TRISTATE_FLASH(0); @@ -318,7 +318,7 @@ static int flash_set_status_for_prot(int reg1, int reg2) TRISTATE_FLASH(1); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); spi_flash_reg_to_protect(reg1, reg2, &addr_prot_start, &addr_prot_length); @@ -452,13 +452,13 @@ static int flash_program_bytes(uint32_t offset, uint32_t bytes, /*****************************************************************************/ -int flash_physical_read(int offset, int size, char *data) +int crec_flash_physical_read(int offset, int size, char *data) { int dest_addr = offset; uint32_t idx; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); /* Disable tri-state */ TRISTATE_FLASH(0); @@ -487,12 +487,12 @@ int flash_physical_read(int offset, int size, char *data) TRISTATE_FLASH(1); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return EC_SUCCESS; } -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { int dest_addr = offset; int write_len; @@ -508,7 +508,7 @@ int flash_physical_write(int offset, int size, const char *data) return EC_ERROR_ACCESS_DENIED; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); /* Disable tri-state */ TRISTATE_FLASH(0); @@ -537,12 +537,12 @@ int flash_physical_write(int offset, int size, const char *data) TRISTATE_FLASH(1); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return rv; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int rv = EC_SUCCESS; /* check protection */ @@ -550,7 +550,7 @@ int flash_physical_erase(int offset, int size) return EC_ERROR_ACCESS_DENIED; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); /* Disable tri-state */ TRISTATE_FLASH(0); @@ -591,19 +591,19 @@ int flash_physical_erase(int offset, int size) TRISTATE_FLASH(1); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return rv; } -int flash_physical_get_protect(int bank) +int crec_flash_physical_get_protect(int bank) { uint32_t addr = bank * CONFIG_FLASH_BANK_SIZE; return flash_check_prot_reg(addr, CONFIG_FLASH_BANK_SIZE); } -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -626,7 +626,7 @@ uint32_t flash_physical_get_protect_flags(void) return flags; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { if (all) { /* @@ -642,7 +642,7 @@ int flash_physical_protect_now(int all) } -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { int ret; @@ -666,14 +666,14 @@ int flash_physical_protect_at_boot(uint32_t new_flags) return ret; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; @@ -695,7 +695,7 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) /*****************************************************************************/ /* High-level APIs */ -int flash_pre_init(void) +int crec_flash_pre_init(void) { /* * Protect status registers of internal spi-flash if WP# is active @@ -724,7 +724,7 @@ int flash_pre_init(void) return EC_SUCCESS; } -void flash_lock_mapped_storage(int lock) +void crec_flash_lock_mapped_storage(int lock) { if (lock) mutex_lock(&flash_lock); diff --git a/chip/stm32/flash-f.c b/chip/stm32/flash-f.c index b192d44255..9e35a2c689 100644 --- a/chip/stm32/flash-f.c +++ b/chip/stm32/flash-f.c @@ -341,7 +341,7 @@ bool is_flash_rdp_enabled(void) /*****************************************************************************/ /* Physical layer APIs */ -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { #if CONFIG_FLASH_WRITE_SIZE == 1 uint8_t *address = (uint8_t *)(CONFIG_PROGRAM_MEMORY_BASE + offset); @@ -420,15 +420,15 @@ exit_wr: return res; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int res = EC_SUCCESS; int sector_size; int timeout_us; #ifdef CHIP_FAMILY_STM32F4 - int sector = flash_bank_index(offset); + int sector = crec_flash_bank_index(offset); /* we take advantage of sector_size == erase_size */ - if ((sector < 0) || (flash_bank_index(offset + size) < 0)) + if ((sector < 0) || (crec_flash_bank_index(offset + size) < 0)) return EC_ERROR_INVAL; /* Invalid range */ #endif @@ -444,7 +444,7 @@ int flash_physical_erase(int offset, int size) while (size > 0) { timestamp_t deadline; #ifdef CHIP_FAMILY_STM32F4 - sector_size = flash_bank_size(sector); + sector_size = crec_flash_bank_size(sector); /* Timeout: from spec, proportional to the size * inversely proportional to the write size. */ @@ -454,7 +454,7 @@ int flash_physical_erase(int offset, int size) timeout_us = FLASH_ERASE_TIMEOUT_US; #endif /* Do nothing if already erased */ - if (flash_is_erased(offset, sector_size)) + if (crec_flash_is_erased(offset, sector_size)) goto next_sector; #ifdef CHIP_FAMILY_STM32F4 /* select page to erase */ @@ -533,7 +533,7 @@ static int flash_physical_protect_at_boot_update_rdp_pstate(uint32_t new_flags) #endif } -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { int block; int original_val, val; @@ -580,7 +580,7 @@ static int flash_physical_get_protect_at_boot(int block) return (!(val & (1 << (block % 8)))) ? 1 : 0; } -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { int block; int i; @@ -646,7 +646,7 @@ static void unprotect_all_blocks(void) */ static int registers_need_reset(void) { - uint32_t flags = flash_get_protect(); + uint32_t flags = crec_flash_get_protect(); int i; int ro_at_boot = (flags & EC_FLASH_PROTECT_RO_AT_BOOT) ? 1 : 0; int ro_wp_region_start = WP_BANK_OFFSET; @@ -723,10 +723,10 @@ enum flash_rdp_level flash_physical_get_rdp_level(void) /*****************************************************************************/ /* High-level APIs */ -int flash_pre_init(void) +int crec_flash_pre_init(void) { uint32_t reset_flags = system_get_reset_flags(); - uint32_t prot_flags = flash_get_protect(); + uint32_t prot_flags = crec_flash_get_protect(); int need_reset = 0; @@ -738,7 +738,7 @@ int flash_pre_init(void) STM32_FLASH_CR_PSIZE_OFFSET; lock(); #endif - if (flash_physical_restore_state()) + if (crec_flash_physical_restore_state()) return EC_SUCCESS; /* @@ -751,7 +751,7 @@ int flash_pre_init(void) if (prot_flags & EC_FLASH_PROTECT_GPIO_ASSERTED) { if (prot_flags & EC_FLASH_PROTECT_RO_NOW) { /* Enable physical protection for RO (0 means RO). */ - flash_physical_protect_now(0); + crec_flash_physical_protect_now(0); } if ((prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT) && @@ -762,7 +762,7 @@ int flash_pre_init(void) * update to the write protect register and reboot so * it takes effect. */ - flash_physical_protect_at_boot( + crec_flash_physical_protect_at_boot( EC_FLASH_PROTECT_RO_AT_BOOT); need_reset = 1; } @@ -776,7 +776,7 @@ int flash_pre_init(void) * to the check above. One of them should be able to * go away. */ - flash_protect_at_boot( + crec_flash_protect_at_boot( prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT); need_reset = 1; } @@ -791,7 +791,8 @@ int flash_pre_init(void) } } - if ((flash_physical_get_valid_flags() & EC_FLASH_PROTECT_ALL_AT_BOOT) && + if ((crec_flash_physical_get_valid_flags() & + EC_FLASH_PROTECT_ALL_AT_BOOT) && (!!(prot_flags & EC_FLASH_PROTECT_ALL_AT_BOOT) != !!(prot_flags & EC_FLASH_PROTECT_ALL_NOW))) { /* @@ -806,7 +807,8 @@ int flash_pre_init(void) } #ifdef CONFIG_FLASH_PROTECT_RW - if ((flash_physical_get_valid_flags() & EC_FLASH_PROTECT_RW_AT_BOOT) && + if ((crec_flash_physical_get_valid_flags() & + EC_FLASH_PROTECT_RW_AT_BOOT) && (!!(prot_flags & EC_FLASH_PROTECT_RW_AT_BOOT) != !!(prot_flags & EC_FLASH_PROTECT_RW_NOW))) { /* RW_AT_BOOT and RW_NOW do not match. */ @@ -815,7 +817,8 @@ int flash_pre_init(void) #endif #ifdef CONFIG_ROLLBACK - if ((flash_physical_get_valid_flags() & EC_FLASH_PROTECT_ROLLBACK_AT_BOOT) && + if ((crec_flash_physical_get_valid_flags() & + EC_FLASH_PROTECT_ROLLBACK_AT_BOOT) && (!!(prot_flags & EC_FLASH_PROTECT_ROLLBACK_AT_BOOT) != !!(prot_flags & EC_FLASH_PROTECT_ROLLBACK_NOW))) { /* ROLLBACK_AT_BOOT and ROLLBACK_NOW do not match. */ diff --git a/chip/stm32/flash-stm32f0.c b/chip/stm32/flash-stm32f0.c index a0aef5fe3f..f790a657c8 100644 --- a/chip/stm32/flash-stm32f0.c +++ b/chip/stm32/flash-stm32f0.c @@ -13,7 +13,7 @@ /*****************************************************************************/ /* Physical layer APIs */ -int flash_physical_get_protect(int block) +int crec_flash_physical_get_protect(int block) { return !(STM32_FLASH_WRPR & BIT(block)); } @@ -22,7 +22,7 @@ int flash_physical_get_protect(int block) * Note: This does not need to update _NOW flags, as get_protect_flags * in common code already does so. */ -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; uint32_t wrp01 = REG32(STM32_OPTB_BASE + STM32_OPTB_WRP01); @@ -114,18 +114,18 @@ uint32_t flash_physical_get_protect_flags(void) return flags; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { return EC_ERROR_INVAL; } -int flash_physical_restore_state(void) +int crec_flash_physical_restore_state(void) { /* Nothing to restore */ return 0; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | @@ -141,7 +141,7 @@ uint32_t flash_physical_get_valid_flags(void) EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; diff --git a/chip/stm32/flash-stm32f3.c b/chip/stm32/flash-stm32f3.c index 563190b252..138e690fcc 100644 --- a/chip/stm32/flash-stm32f3.c +++ b/chip/stm32/flash-stm32f3.c @@ -94,7 +94,7 @@ struct flash_wp_state { /*****************************************************************************/ /* Physical layer APIs */ -int flash_physical_get_protect(int block) +int crec_flash_physical_get_protect(int block) { return (entire_flash_locked || #if defined(CHIP_FAMILY_STM32F3) @@ -105,7 +105,7 @@ int flash_physical_get_protect(int block) ); } -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -121,7 +121,7 @@ uint32_t flash_physical_get_protect_flags(void) return flags; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { if (all) { disable_flash_control_register(); @@ -135,14 +135,14 @@ int flash_physical_protect_now(int all) return EC_SUCCESS; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; @@ -161,7 +161,7 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) return ret; } -int flash_physical_restore_state(void) +int crec_flash_physical_restore_state(void) { uint32_t reset_flags = system_get_reset_flags(); int version, size; diff --git a/chip/stm32/flash-stm32g4-l4.c b/chip/stm32/flash-stm32g4-l4.c index c04c17bb3b..ff8ca34b52 100644 --- a/chip/stm32/flash-stm32g4-l4.c +++ b/chip/stm32/flash-stm32g4-l4.c @@ -330,7 +330,7 @@ static void unprotect_all_blocks(void) commit_optb(); } -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { struct wrp_info wrp_ro; struct wrp_info wrp_rw; @@ -411,7 +411,7 @@ int flash_physical_protect_at_boot(uint32_t new_flags) */ static int registers_need_reset(void) { - uint32_t flags = flash_get_protect(); + uint32_t flags = crec_flash_get_protect(); int ro_at_boot = (flags & EC_FLASH_PROTECT_RO_AT_BOOT) ? 1 : 0; /* The RO region is write-protected by the WRP1AR range. */ uint32_t wrp1ar = STM32_OPTB_WRP1AR; @@ -426,7 +426,7 @@ static int registers_need_reset(void) /*****************************************************************************/ /* Physical layer APIs */ -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { uint32_t *address = (void *)(CONFIG_PROGRAM_MEMORY_BASE + offset); int res = EC_SUCCESS; @@ -501,7 +501,7 @@ exit_wr: return res; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int res = EC_SUCCESS; int pg; @@ -560,7 +560,7 @@ exit_er: return res; } -int flash_physical_get_protect(int block) +int crec_flash_physical_get_protect(int block) { struct wrp_info wrp_ro; struct wrp_info wrp_rw; @@ -576,7 +576,7 @@ int flash_physical_get_protect(int block) * Note: This does not need to update _NOW flags, as get_protect_flags * in common code already does so. */ -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; struct wrp_info wrp_ro; @@ -610,12 +610,12 @@ uint32_t flash_physical_get_protect_flags(void) return flags; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { return EC_ERROR_INVAL; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | @@ -631,7 +631,7 @@ uint32_t flash_physical_get_valid_flags(void) EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; @@ -662,10 +662,10 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) return ret; } -int flash_pre_init(void) +int crec_flash_pre_init(void) { uint32_t reset_flags = system_get_reset_flags(); - uint32_t prot_flags = flash_get_protect(); + uint32_t prot_flags = crec_flash_get_protect(); int need_reset = 0; /* @@ -684,7 +684,7 @@ int flash_pre_init(void) * update to the write protect register and reboot so * it takes effect. */ - flash_physical_protect_at_boot( + crec_flash_physical_protect_at_boot( EC_FLASH_PROTECT_RO_AT_BOOT); need_reset = 1; } @@ -698,7 +698,7 @@ int flash_pre_init(void) * to the check above. One of them should be able to * go away. */ - flash_protect_at_boot( + crec_flash_protect_at_boot( prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT); need_reset = 1; } @@ -713,7 +713,8 @@ int flash_pre_init(void) } } - if ((flash_physical_get_valid_flags() & EC_FLASH_PROTECT_ALL_AT_BOOT) && + if ((crec_flash_physical_get_valid_flags() & + EC_FLASH_PROTECT_ALL_AT_BOOT) && (!!(prot_flags & EC_FLASH_PROTECT_ALL_AT_BOOT) != !!(prot_flags & EC_FLASH_PROTECT_ALL_NOW))) { /* @@ -728,7 +729,8 @@ int flash_pre_init(void) } #ifdef CONFIG_FLASH_PROTECT_RW - if ((flash_physical_get_valid_flags() & EC_FLASH_PROTECT_RW_AT_BOOT) && + if ((crec_flash_physical_get_valid_flags() & + EC_FLASH_PROTECT_RW_AT_BOOT) && (!!(prot_flags & EC_FLASH_PROTECT_RW_AT_BOOT) != !!(prot_flags & EC_FLASH_PROTECT_RW_NOW))) { /* RW_AT_BOOT and RW_NOW do not match. */ @@ -737,7 +739,7 @@ int flash_pre_init(void) #endif #ifdef CONFIG_ROLLBACK - if ((flash_physical_get_valid_flags() & + if ((crec_flash_physical_get_valid_flags() & EC_FLASH_PROTECT_ROLLBACK_AT_BOOT) && (!!(prot_flags & EC_FLASH_PROTECT_ROLLBACK_AT_BOOT) != !!(prot_flags & EC_FLASH_PROTECT_ROLLBACK_NOW))) { diff --git a/chip/stm32/flash-stm32h7.c b/chip/stm32/flash-stm32h7.c index e020e1af1d..6c8c797c41 100644 --- a/chip/stm32/flash-stm32h7.c +++ b/chip/stm32/flash-stm32h7.c @@ -287,7 +287,7 @@ static int set_wp(int enabled) /*****************************************************************************/ /* Physical layer APIs */ -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { int res = EC_SUCCESS; int bank = offset / HWBANK_SIZE; @@ -365,7 +365,7 @@ exit_wr: return res; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int res = EC_SUCCESS; int bank = offset / HWBANK_SIZE; @@ -441,7 +441,7 @@ exit_er: return res; } -int flash_physical_get_protect(int block) +int crec_flash_physical_get_protect(int block) { int bank = block / BLOCKS_PER_HWBANK; int index = block % BLOCKS_PER_HWBANK; @@ -453,7 +453,7 @@ int flash_physical_get_protect(int block) * Note: This does not need to update _NOW flags, as flash_get_protect * in common code already does so. */ -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -473,7 +473,7 @@ uint32_t flash_physical_get_protect_flags(void) #define WP_RANGE(start, count) (((1 << (count)) - 1) << (start)) #define RO_WP_RANGE WP_RANGE(WP_BANK_OFFSET, WP_BANK_COUNT) -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { protect_blocks(RO_WP_RANGE); @@ -499,7 +499,7 @@ int flash_physical_protect_now(int all) return EC_SUCCESS; } -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { int new_wp_enable = !!(new_flags & EC_FLASH_PROTECT_RO_AT_BOOT); @@ -509,14 +509,14 @@ int flash_physical_protect_at_boot(uint32_t new_flags) return EC_SUCCESS; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; @@ -535,7 +535,7 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) return ret; } -int flash_physical_restore_state(void) +int crec_flash_physical_restore_state(void) { uint32_t reset_flags = system_get_reset_flags(); int version, size; @@ -561,14 +561,14 @@ int flash_physical_restore_state(void) return 0; } -int flash_pre_init(void) +int crec_flash_pre_init(void) { uint32_t reset_flags = system_get_reset_flags(); - uint32_t prot_flags = flash_get_protect(); + uint32_t prot_flags = crec_flash_get_protect(); uint32_t unwanted_prot_flags = EC_FLASH_PROTECT_ALL_NOW | EC_FLASH_PROTECT_ERROR_INCONSISTENT; - if (flash_physical_restore_state()) + if (crec_flash_physical_restore_state()) return EC_SUCCESS; /* @@ -587,13 +587,13 @@ int flash_pre_init(void) !(prot_flags & EC_FLASH_PROTECT_RO_NOW)) { int rv; - rv = flash_set_protect(EC_FLASH_PROTECT_RO_NOW, - EC_FLASH_PROTECT_RO_NOW); + rv = crec_flash_set_protect(EC_FLASH_PROTECT_RO_NOW, + EC_FLASH_PROTECT_RO_NOW); if (rv) return rv; /* Re-read flags */ - prot_flags = flash_get_protect(); + prot_flags = crec_flash_get_protect(); } } else { /* Don't want RO flash protected */ diff --git a/chip/stm32/flash-stm32l.c b/chip/stm32/flash-stm32l.c index a151a26cf8..f34200219a 100644 --- a/chip/stm32/flash-stm32l.c +++ b/chip/stm32/flash-stm32l.c @@ -158,7 +158,7 @@ void __attribute__((section(".iram.text"))) STM32_FLASH_PECR &= ~(STM32_FLASH_PECR_PROG | STM32_FLASH_PECR_FPRG); } -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { uint32_t *data32 = (uint32_t *)data; uint32_t *address = (uint32_t *)(CONFIG_PROGRAM_MEMORY_BASE + offset); @@ -240,7 +240,7 @@ exit_wr: return res; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { uint32_t *address; int res = EC_SUCCESS; @@ -261,7 +261,7 @@ int flash_physical_erase(int offset, int size) timestamp_t deadline; /* Do nothing if already erased */ - if (flash_is_erased((uint32_t)address - + if (crec_flash_is_erased((uint32_t)address - CONFIG_PROGRAM_MEMORY_BASE, CONFIG_FLASH_ERASE_SIZE)) continue; @@ -304,20 +304,20 @@ exit_er: return res; } -int flash_physical_get_protect(int block) +int crec_flash_physical_get_protect(int block) { /* * If the entire flash interface is locked, then all blocks are * protected until reboot. */ - if (flash_physical_get_protect_flags() & EC_FLASH_PROTECT_ALL_NOW) + if (crec_flash_physical_get_protect_flags() & EC_FLASH_PROTECT_ALL_NOW) return 1; /* Check the active write protect status */ return STM32_FLASH_WRPR & BIT(block); } -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { uint32_t prot; uint32_t mask = (BIT(WP_BANK_COUNT) - 1) << WP_BANK_OFFSET; @@ -352,7 +352,7 @@ int flash_physical_protect_at_boot(uint32_t new_flags) return EC_SUCCESS; } -int flash_physical_force_reload(void) +int crec_flash_physical_force_reload(void) { int rv = unlock(STM32_FLASH_PECR_OPT_LOCK); @@ -367,7 +367,7 @@ int flash_physical_force_reload(void) return EC_ERROR_UNKNOWN; } -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -382,7 +382,7 @@ uint32_t flash_physical_get_protect_flags(void) return flags; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { if (all) { /* Re-lock the registers if they're unlocked */ @@ -400,14 +400,14 @@ int flash_physical_protect_now(int all) } } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; @@ -426,10 +426,10 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) return ret; } -int flash_pre_init(void) +int crec_flash_pre_init(void) { uint32_t reset_flags = system_get_reset_flags(); - uint32_t prot_flags = flash_get_protect(); + uint32_t prot_flags = crec_flash_get_protect(); int need_reset = 0; /* @@ -448,7 +448,7 @@ int flash_pre_init(void) * update to the write protect register and reboot so * it takes effect. */ - flash_protect_at_boot(EC_FLASH_PROTECT_RO_AT_BOOT); + crec_flash_protect_at_boot(EC_FLASH_PROTECT_RO_AT_BOOT); need_reset = 1; } @@ -457,7 +457,7 @@ int flash_pre_init(void) * Write protect register was in an inconsistent state. * Set it back to a good state and reboot. */ - flash_protect_at_boot(prot_flags & + crec_flash_protect_at_boot(prot_flags & EC_FLASH_PROTECT_RO_AT_BOOT); need_reset = 1; } diff --git a/chip/stm32/otp-stm32f4.c b/chip/stm32/otp-stm32f4.c index a993af7042..45ce38d159 100644 --- a/chip/stm32/otp-stm32f4.c +++ b/chip/stm32/otp-stm32f4.c @@ -39,9 +39,9 @@ static int otp_write(uint8_t block, int size, const char *data) return EC_ERROR_PARAM1; if (size >= STM32_OTP_BLOCK_SIZE) return EC_ERROR_PARAM2; - return flash_physical_write(STM32_OTP_BLOCK_DATA(block, 0) - - CONFIG_PROGRAM_MEMORY_BASE, - size * sizeof(uint32_t), data); + return crec_flash_physical_write(STM32_OTP_BLOCK_DATA(block, 0) - + CONFIG_PROGRAM_MEMORY_BASE, + size * sizeof(uint32_t), data); } /* @@ -73,9 +73,9 @@ static int otp_set_protect(uint8_t block) lock = REG32(STM32_OTP_LOCK(block)); lock &= ~STM32_OPT_LOCK_MASK(block); - rv = flash_physical_write(STM32_OTP_LOCK(block) - - CONFIG_PROGRAM_MEMORY_BASE, - sizeof(uint32_t), (char *)&lock); + rv = crec_flash_physical_write(STM32_OTP_LOCK(block) - + CONFIG_PROGRAM_MEMORY_BASE, + sizeof(uint32_t), (char *)&lock); if (rv) return rv; else diff --git a/chip/stm32/system.c b/chip/stm32/system.c index 8367ae2a12..1a9da8c3a4 100644 --- a/chip/stm32/system.c +++ b/chip/stm32/system.c @@ -393,7 +393,7 @@ void system_reset(int flags) * Ask the flash module to reboot, so that we reload the * option bytes. */ - flash_physical_force_reload(); + crec_flash_physical_force_reload(); /* Fall through to watchdog if that fails */ #endif diff --git a/common/flash.c b/common/flash.c index f2f402c156..779fbe24db 100644 --- a/common/flash.c +++ b/common/flash.c @@ -133,7 +133,7 @@ const struct ec_flash_bank *flash_bank_info(int bank) return NULL; } -int flash_bank_size(int bank) +int crec_flash_bank_size(int bank) { int rv; const struct ec_flash_bank *info = flash_bank_info(bank); @@ -146,7 +146,7 @@ int flash_bank_size(int bank) return rv; } -int flash_bank_erase_size(int bank) +int crec_flash_bank_erase_size(int bank) { int rv; const struct ec_flash_bank *info = flash_bank_info(bank); @@ -159,7 +159,7 @@ int flash_bank_erase_size(int bank) return rv; } -int flash_bank_index(int offset) +int crec_flash_bank_index(int offset) { int bank_offset = 0, i; @@ -183,17 +183,17 @@ int flash_bank_index(int offset) return bank_offset; } -int flash_bank_count(int offset, int size) +int crec_flash_bank_count(int offset, int size) { - int begin = flash_bank_index(offset); - int end = flash_bank_index(offset + size); + int begin = crec_flash_bank_index(offset); + int end = crec_flash_bank_index(offset + size); if (begin == -1 || end == -1) return -1; return end - begin; } -int flash_bank_start_offset(int bank) +int crec_flash_bank_start_offset(int bank) { int i; int offset; @@ -204,7 +204,7 @@ int flash_bank_start_offset(int bank) offset = 0; for (i = 0; i < bank; i++) { - bank_size = flash_bank_size(i); + bank_size = crec_flash_bank_size(i); if (bank_size < 0) return -1; offset += bank_size; @@ -244,7 +244,7 @@ static const char *flash_physical_dataptr(int offset) return (char *)((uintptr_t)CONFIG_MAPPED_STORAGE_BASE + offset); } -int flash_dataptr(int offset, int size_req, int align, const char **ptrp) +int crec_flash_dataptr(int offset, int size_req, int align, const char **ptrp) { if (!flash_range_ok(offset, size_req, align)) return -1; /* Invalid range */ @@ -293,8 +293,8 @@ static int flash_write_pstate_data(struct persist_state *newpstate) int rv; /* Erase pstate */ - rv = flash_physical_erase(CONFIG_FW_PSTATE_OFF, - CONFIG_FW_PSTATE_SIZE); + rv = crec_flash_physical_erase(CONFIG_FW_PSTATE_OFF, + CONFIG_FW_PSTATE_SIZE); if (rv) return rv; @@ -305,8 +305,9 @@ static int flash_write_pstate_data(struct persist_state *newpstate) */ /* Write the updated pstate */ - return flash_physical_write(CONFIG_FW_PSTATE_OFF, sizeof(*newpstate), - (const char *)newpstate); + return crec_flash_physical_write(CONFIG_FW_PSTATE_OFF, + sizeof(*newpstate), + (const char *)newpstate); } @@ -364,7 +365,7 @@ static int flash_write_pstate(uint32_t flags) /** * Read and return persistent serial number. */ -const char *flash_read_pstate_serial(void) +const char *crec_flash_read_pstate_serial(void) { const struct persist_state *pstate = (const struct persist_state *) @@ -384,7 +385,7 @@ const char *flash_read_pstate_serial(void) * @param serialno New ascii serial number to set in pstate. * @return EC_SUCCESS, or nonzero if error. */ -int flash_write_pstate_serial(const char *serialno) +int crec_flash_write_pstate_serial(const char *serialno) { int length; struct persist_state newpstate; @@ -424,7 +425,7 @@ int flash_write_pstate_serial(const char *serialno) /** * Read and return persistent MAC address. */ -const char *flash_read_pstate_mac_addr(void) +const char *crec_flash_read_pstate_mac_addr(void) { const struct persist_state *pstate = (const struct persist_state *) @@ -444,7 +445,7 @@ const char *flash_read_pstate_mac_addr(void) * @param mac_addr New ascii MAC address to set in pstate. * @return EC_SUCCESS, or nonzero if error. */ -int flash_write_pstate_mac_addr(const char *mac_addr) +int crec_flash_write_pstate_mac_addr(const char *mac_addr) { int length; struct persist_state newpstate; @@ -554,33 +555,33 @@ static int flash_write_pstate(uint32_t flags) * Write a new pstate. We can overwrite the existing value, because * we're only moving bits from the erased state to the unerased state. */ - return flash_physical_write(get_pstate_addr() - - CONFIG_PROGRAM_MEMORY_BASE, - sizeof(new_pstate), - (const char *)&new_pstate); + return crec_flash_physical_write(get_pstate_addr() - + CONFIG_PROGRAM_MEMORY_BASE, + sizeof(new_pstate), + (const char *)&new_pstate); } #endif /* !CONFIG_FLASH_PSTATE_BANK */ #endif /* CONFIG_FLASH_PSTATE */ -int flash_is_erased(uint32_t offset, int size) +int crec_flash_is_erased(uint32_t offset, int size) { const uint32_t *ptr; #ifdef CONFIG_MAPPED_STORAGE /* Use pointer directly to flash */ - if (flash_dataptr(offset, size, sizeof(uint32_t), + if (crec_flash_dataptr(offset, size, sizeof(uint32_t), (const char **)&ptr) < 0) return 0; - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); for (size /= sizeof(uint32_t); size > 0; size--, ptr++) if (*ptr != CONFIG_FLASH_ERASED_VALUE32) { - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return 0; } - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); #else /* Read flash a chunk at a time */ uint32_t buf[8]; @@ -589,7 +590,7 @@ int flash_is_erased(uint32_t offset, int size) while (size) { bsize = MIN(size, sizeof(buf)); - if (flash_read(offset, bsize, (char *)buf)) + if (crec_flash_read(offset, bsize, (char *)buf)) return 0; size -= bsize; @@ -606,20 +607,20 @@ int flash_is_erased(uint32_t offset, int size) return 1; } -int flash_read(int offset, int size, char *data) +int crec_flash_read(int offset, int size, char *data) { #ifdef CONFIG_MAPPED_STORAGE const char *src; - if (flash_dataptr(offset, size, 1, &src) < 0) + if (crec_flash_dataptr(offset, size, 1, &src) < 0) return EC_ERROR_INVAL; - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); memcpy(data, src, size); - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return EC_SUCCESS; #else - return flash_physical_read(offset, size, data); + return crec_flash_physical_read(offset, size, data); #endif } @@ -661,17 +662,17 @@ static void flash_abort_or_invalidate_hash(int offset, int size) #endif } -int flash_write(int offset, int size, const char *data) +int crec_flash_write(int offset, int size, const char *data) { if (!flash_range_ok(offset, size, CONFIG_FLASH_WRITE_SIZE)) return EC_ERROR_INVAL; /* Invalid range */ flash_abort_or_invalidate_hash(offset, size); - return flash_physical_write(offset, size, data); + return crec_flash_physical_write(offset, size, data); } -int flash_erase(int offset, int size) +int crec_flash_erase(int offset, int size) { #ifndef CONFIG_FLASH_MULTIPLE_REGION if (!flash_range_ok(offset, size, CONFIG_FLASH_ERASE_SIZE)) @@ -680,10 +681,10 @@ int flash_erase(int offset, int size) flash_abort_or_invalidate_hash(offset, size); - return flash_physical_erase(offset, size); + return crec_flash_physical_erase(offset, size); } -int flash_protect_at_boot(uint32_t new_flags) +int crec_flash_protect_at_boot(uint32_t new_flags) { #ifdef CONFIG_FLASH_PSTATE uint32_t new_pstate_flags = new_flags & EC_FLASH_PROTECT_RO_AT_BOOT; @@ -695,7 +696,7 @@ int flash_protect_at_boot(uint32_t new_flags) #ifdef CONFIG_FLASH_PSTATE_BANK /* Fail if write protect block is already locked */ - if (flash_physical_get_protect(PSTATE_BANK)) + if (crec_flash_physical_get_protect(PSTATE_BANK)) return EC_ERROR_ACCESS_DENIED; #endif @@ -717,16 +718,16 @@ int flash_protect_at_boot(uint32_t new_flags) * This assumes PSTATE immediately follows RO, which it does on * all STM32 platforms (which are the only ones with this config). */ - flash_physical_protect_at_boot(new_flags); + crec_flash_physical_protect_at_boot(new_flags); #endif return EC_SUCCESS; #else - return flash_physical_protect_at_boot(new_flags); + return crec_flash_physical_protect_at_boot(new_flags); #endif } -uint32_t flash_get_protect(void) +uint32_t crec_flash_get_protect(void) { uint32_t flags = 0; int i; @@ -775,7 +776,7 @@ uint32_t flash_get_protect(void) } #endif - if (flash_physical_get_protect(i)) { + if (crec_flash_physical_get_protect(i)) { /* At least one bank in the region is protected */ flags |= bank_flag; if (not_protected[region]) @@ -808,7 +809,7 @@ uint32_t flash_get_protect(void) #endif /* Add in flags from physical layer */ - return flags | flash_physical_get_protect_flags(); + return flags | crec_flash_physical_get_protect_flags(); } /* @@ -822,11 +823,11 @@ uint32_t flash_get_protect(void) * 4. Commit RO_NOW. * 5. Commit ALL_NOW. */ -int flash_set_protect(uint32_t mask, uint32_t flags) +int crec_flash_set_protect(uint32_t mask, uint32_t flags) { int retval = EC_SUCCESS; int rv; - int old_flags_at_boot = flash_get_protect() & + int old_flags_at_boot = crec_flash_get_protect() & (EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RW_AT_BOOT | EC_FLASH_PROTECT_ROLLBACK_AT_BOOT | EC_FLASH_PROTECT_ALL_AT_BOOT); @@ -899,7 +900,7 @@ int flash_set_protect(uint32_t mask, uint32_t flags) /* 1.f - Commit *_AT_BOOT "clears" (and RO "set" 1.b). */ if (new_flags_at_boot != old_flags_at_boot) { - rv = flash_protect_at_boot(new_flags_at_boot); + rv = crec_flash_protect_at_boot(new_flags_at_boot); if (rv) retval = rv; old_flags_at_boot = new_flags_at_boot; @@ -910,7 +911,7 @@ int flash_set_protect(uint32_t mask, uint32_t flags) * All subsequent flags only work if write protect is enabled (that is, * hardware WP flag) *and* RO is protected at boot (software WP flag). */ - if ((~flash_get_protect()) & (EC_FLASH_PROTECT_GPIO_ASSERTED | + if ((~crec_flash_get_protect()) & (EC_FLASH_PROTECT_GPIO_ASSERTED | EC_FLASH_PROTECT_RO_AT_BOOT)) return retval; @@ -934,21 +935,21 @@ int flash_set_protect(uint32_t mask, uint32_t flags) /* 3.d - Commit *_AT_BOOT "sets". */ if (new_flags_at_boot != old_flags_at_boot) { - rv = flash_protect_at_boot(new_flags_at_boot); + rv = crec_flash_protect_at_boot(new_flags_at_boot); if (rv) retval = rv; } /* 4 - Commit RO_NOW. */ if (flags & EC_FLASH_PROTECT_RO_NOW) { - rv = flash_physical_protect_now(0); + rv = crec_flash_physical_protect_now(0); if (rv) retval = rv; } /* 5 - Commit ALL_NOW. */ if (flags & EC_FLASH_PROTECT_ALL_NOW) { - rv = flash_physical_protect_now(1); + rv = crec_flash_physical_protect_now(1); if (rv) retval = rv; } @@ -963,7 +964,7 @@ static struct ec_params_flash_erase_v1 erase_info; static void flash_erase_deferred(void) { erase_rc = EC_RES_BUSY; - if (flash_erase(erase_info.params.offset, erase_info.params.size)) + if (crec_flash_erase(erase_info.params.offset, erase_info.params.size)) erase_rc = EC_RES_ERROR; else erase_rc = EC_RES_SUCCESS; @@ -999,7 +1000,7 @@ static int command_flash_info(int argc, char **argv) CONFIG_FLASH_ERASED_VALUE32 ? 1 : 0); ccprintf("Protect: %4d B\n", CONFIG_FLASH_BANK_SIZE); #endif - flags = flash_get_protect(); + flags = crec_flash_get_protect(); ccprintf("Flags: "); if (flags & EC_FLASH_PROTECT_GPIO_ASSERTED) ccputs(" wp_gpio_asserted"); @@ -1035,7 +1036,7 @@ static int command_flash_info(int argc, char **argv) ccputs("\n "); else if (!(i & 7)) ccputs(" "); - ccputs(flash_physical_get_protect(i) ? "Y" : "."); + ccputs(crec_flash_physical_get_protect(i) ? "Y" : "."); } ccputs("\n"); return EC_SUCCESS; @@ -1052,7 +1053,7 @@ static int command_flash_erase(int argc, char **argv) int size = -1; int rv; - if (flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) + if (crec_flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) return EC_ERROR_ACCESS_DENIED; rv = parse_offset_size(argc, argv, 1, &offset, &size); @@ -1060,7 +1061,7 @@ static int command_flash_erase(int argc, char **argv) return rv; ccprintf("Erasing %d bytes at 0x%x...\n", size, offset); - return flash_erase(offset, size); + return crec_flash_erase(offset, size); } DECLARE_CONSOLE_COMMAND(flasherase, command_flash_erase, "offset size", @@ -1074,7 +1075,7 @@ static int command_flash_write(int argc, char **argv) char *data; int i; - if (flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) + if (crec_flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) return EC_ERROR_ACCESS_DENIED; rv = parse_offset_size(argc, argv, 1, &offset, &size); @@ -1096,7 +1097,7 @@ static int command_flash_write(int argc, char **argv) data[i] = i; ccprintf("Writing %d bytes to 0x%x...\n", size, offset); - rv = flash_write(offset, size, data); + rv = crec_flash_write(offset, size, data); /* Free the buffer */ shared_mem_release(data); @@ -1130,7 +1131,7 @@ static int command_flash_read(int argc, char **argv) } /* Read the data */ - if (flash_read(offset, size, data)) { + if (crec_flash_read(offset, size, data)) { shared_mem_release(data); return EC_ERROR_INVAL; } @@ -1165,33 +1166,35 @@ static int command_flash_wp(int argc, char **argv) return EC_ERROR_PARAM_COUNT; if (!strcasecmp(argv[1], "now")) - return flash_set_protect(EC_FLASH_PROTECT_ALL_NOW, -1); + return crec_flash_set_protect(EC_FLASH_PROTECT_ALL_NOW, -1); if (!strcasecmp(argv[1], "all")) - return flash_set_protect(EC_FLASH_PROTECT_ALL_AT_BOOT, -1); + return crec_flash_set_protect(EC_FLASH_PROTECT_ALL_AT_BOOT, -1); if (!strcasecmp(argv[1], "noall")) - return flash_set_protect(EC_FLASH_PROTECT_ALL_AT_BOOT, 0); + return crec_flash_set_protect(EC_FLASH_PROTECT_ALL_AT_BOOT, 0); #ifdef CONFIG_FLASH_PROTECT_RW if (!strcasecmp(argv[1], "rw")) - return flash_set_protect(EC_FLASH_PROTECT_RW_AT_BOOT, -1); + return crec_flash_set_protect(EC_FLASH_PROTECT_RW_AT_BOOT, -1); if (!strcasecmp(argv[1], "norw")) - return flash_set_protect(EC_FLASH_PROTECT_RW_AT_BOOT, 0); + return crec_flash_set_protect(EC_FLASH_PROTECT_RW_AT_BOOT, 0); #endif #ifdef CONFIG_ROLLBACK if (!strcasecmp(argv[1], "rb")) - return flash_set_protect(EC_FLASH_PROTECT_ROLLBACK_AT_BOOT, -1); + return crec_flash_set_protect(EC_FLASH_PROTECT_ROLLBACK_AT_BOOT, + -1); if (!strcasecmp(argv[1], "norb")) - return flash_set_protect(EC_FLASH_PROTECT_ROLLBACK_AT_BOOT, 0); + return crec_flash_set_protect(EC_FLASH_PROTECT_ROLLBACK_AT_BOOT, + 0); #endif /* Do this last, since anything starting with 'n' means "no" */ if (parse_bool(argv[1], &val)) - return flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, + return crec_flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, val ? -1 : 0); return EC_ERROR_PARAM1; @@ -1327,7 +1330,7 @@ static enum ec_status flash_command_read(struct host_cmd_handler_args *args) if (p->size > args->response_max) return EC_RES_OVERFLOW; - if (flash_read(offset, p->size, args->response)) + if (crec_flash_read(offset, p->size, args->response)) return EC_RES_ERROR; args->response_size = p->size; @@ -1349,7 +1352,7 @@ static enum ec_status 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) + if (crec_flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) return EC_RES_ACCESS_DENIED; if (p->size + sizeof(*p) > args->params_size) @@ -1360,7 +1363,7 @@ static enum ec_status flash_command_write(struct host_cmd_handler_args *args) return EC_RES_ACCESS_DENIED; #endif - if (flash_write(offset, p->size, (const uint8_t *)(p + 1))) + if (crec_flash_write(offset, p->size, (const uint8_t *)(p + 1))) return EC_RES_ERROR; return EC_RES_SUCCESS; @@ -1396,7 +1399,7 @@ static enum ec_status flash_command_erase(struct host_cmd_handler_args *args) #endif offset = p->offset + EC_FLASH_REGION_START; - if (flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) + if (crec_flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) return EC_RES_ACCESS_DENIED; #ifdef CONFIG_INTERNAL_STORAGE @@ -1410,7 +1413,7 @@ static enum ec_status flash_command_erase(struct host_cmd_handler_args *args) args->result = EC_RES_IN_PROGRESS; host_send_response(args); #endif - if (flash_erase(offset, p->size)) + if (crec_flash_erase(offset, p->size)) return EC_RES_ERROR; break; @@ -1462,7 +1465,7 @@ static enum ec_status flash_command_protect(struct host_cmd_handler_args *args) * wouldn't get the response.) */ if (p->mask) - flash_set_protect(p->mask, p->flags); + crec_flash_set_protect(p->mask, p->flags); /* * Retrieve the current flags. The caller can use this to determine @@ -1470,15 +1473,15 @@ static enum ec_status flash_command_protect(struct host_cmd_handler_args *args) * simply returning error, because it provides information to the * caller about the actual result. */ - r->flags = flash_get_protect(); + r->flags = crec_flash_get_protect(); /* Indicate which flags are valid on this platform */ r->valid_flags = EC_FLASH_PROTECT_GPIO_ASSERTED | EC_FLASH_PROTECT_ERROR_STUCK | EC_FLASH_PROTECT_ERROR_INCONSISTENT | - flash_physical_get_valid_flags(); - r->writable_flags = flash_physical_get_writable_flags(r->flags); + crec_flash_physical_get_valid_flags(); + r->writable_flags = crec_flash_physical_get_writable_flags(r->flags); args->response_size = sizeof(*r); @@ -1540,7 +1543,7 @@ static enum ec_status flash_command_select(struct host_cmd_handler_args *args) { const struct ec_params_flash_select *p = args->params; - return board_flash_select(p->select); + return crec_board_flash_select(p->select); } DECLARE_HOST_COMMAND(EC_CMD_FLASH_SELECT, flash_command_select, diff --git a/common/init_rom.c b/common/init_rom.c index fd796f7fe9..320849c008 100644 --- a/common/init_rom.c +++ b/common/init_rom.c @@ -43,11 +43,11 @@ const void *init_rom_map(const void *addr, int size) /* * Convert flash offset to memory mapped address */ - if (flash_dataptr((int)offset, size, 1, &src) < 0) + if (crec_flash_dataptr((int)offset, size, 1, &src) < 0) return NULL; /* Once the flash offset is validated, lock the flash for the caller */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); return src; } @@ -59,11 +59,11 @@ const void *init_rom_map(const void *addr, int size) void init_rom_unmap(const void *addr, int size) { if (IS_ENABLED(CONFIG_CHIP_INIT_ROM_REGION)) - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); } int init_rom_copy(int offset, int size, char *data) { - return flash_read(offset, size, data); + return crec_flash_read(offset, size, data); } diff --git a/common/main.c b/common/main.c index 75df57066c..5564100b31 100644 --- a/common/main.c +++ b/common/main.c @@ -109,7 +109,7 @@ test_mockable __keep int main(void) * Initialize flash and apply write protect if necessary. Requires * the reset flags calculated by system initialization. */ - flash_pre_init(); + crec_flash_pre_init(); #endif /* Set the CPU clocks / PLLs. System is now running at full speed. */ diff --git a/common/rollback.c b/common/rollback.c index d4f206b2b6..984058c49a 100644 --- a/common/rollback.c +++ b/common/rollback.c @@ -34,9 +34,9 @@ static int get_rollback_offset(int region) { #ifdef CONFIG_FLASH_MULTIPLE_REGION int rv; - int rollback_start_bank = flash_bank_index(CONFIG_ROLLBACK_OFF); + int rollback_start_bank = crec_flash_bank_index(CONFIG_ROLLBACK_OFF); - rv = flash_bank_start_offset(rollback_start_bank + region); + rv = crec_flash_bank_start_offset(rollback_start_bank + region); ASSERT(rv >= 0); return rv; #else @@ -52,9 +52,9 @@ static int get_rollback_erase_size_bytes(int region) #ifndef CONFIG_FLASH_MULTIPLE_REGION erase_size = CONFIG_FLASH_ERASE_SIZE; #else - int rollback_start_bank = flash_bank_index(CONFIG_ROLLBACK_OFF); + int rollback_start_bank = crec_flash_bank_index(CONFIG_ROLLBACK_OFF); - erase_size = flash_bank_erase_size(rollback_start_bank + region); + erase_size = crec_flash_bank_erase_size(rollback_start_bank + region); #endif ASSERT(erase_size > 0); ASSERT(ROLLBACK_REGIONS * erase_size <= CONFIG_ROLLBACK_SIZE); @@ -98,7 +98,7 @@ int read_rollback(int region, struct rollback_data *data) offset = get_rollback_offset(region); unlock_rollback(); - if (flash_read(offset, sizeof(*data), (char *)data)) + if (crec_flash_read(offset, sizeof(*data), (char *)data)) ret = EC_ERROR_UNKNOWN; lock_rollback(); @@ -254,7 +254,7 @@ static int rollback_update(int32_t next_min_version, BUILD_ASSERT(sizeof(block) >= sizeof(*data)); int erase_size, offset, region, ret; - if (flash_get_protect() & EC_FLASH_PROTECT_ROLLBACK_NOW) { + if (crec_flash_get_protect() & EC_FLASH_PROTECT_ROLLBACK_NOW) { ret = EC_ERROR_ACCESS_DENIED; goto out; } @@ -325,13 +325,13 @@ static int rollback_update(int32_t next_min_version, } unlock_rollback(); - if (flash_erase(offset, erase_size)) { + if (crec_flash_erase(offset, erase_size)) { ret = EC_ERROR_UNKNOWN; lock_rollback(); goto out; } - ret = flash_write(offset, sizeof(block), block); + ret = crec_flash_write(offset, sizeof(block), block); lock_rollback(); out: diff --git a/common/rwsig.c b/common/rwsig.c index 3a5bcd98d8..418a69c1a1 100644 --- a/common/rwsig.c +++ b/common/rwsig.c @@ -42,18 +42,18 @@ void rwsig_jump_now(void) /* Protect all flash before jumping to RW. */ /* This may do nothing if WP is not enabled, RO is not protected. */ - flash_set_protect(EC_FLASH_PROTECT_ALL_NOW, -1); + crec_flash_set_protect(EC_FLASH_PROTECT_ALL_NOW, -1); /* * For chips that does not support EC_FLASH_PROTECT_ALL_NOW, use * EC_FLASH_PROTECT_ALL_AT_BOOT. */ if (system_is_locked() && - !(flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW)) { - flash_set_protect(EC_FLASH_PROTECT_ALL_AT_BOOT, -1); + !(crec_flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW)) { + crec_flash_set_protect(EC_FLASH_PROTECT_ALL_AT_BOOT, -1); - if (!(flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) && - flash_get_protect() & EC_FLASH_PROTECT_ALL_AT_BOOT) { + if (!(crec_flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) && + crec_flash_get_protect() & EC_FLASH_PROTECT_ALL_AT_BOOT) { /* * If flash protection is still not enabled (some chips * may be able to enable it immediately), reboot. @@ -66,7 +66,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) + crec_flash_get_protect() & EC_FLASH_PROTECT_ALL_NOW) system_run_image_copy(EC_IMAGE_RW); } @@ -208,7 +208,8 @@ int rwsig_check_signature(void) if (rw_rollback_version != min_rollback_version #ifdef CONFIG_FLASH_PROTECT_RW && ((!system_is_locked() || - flash_get_protect() & EC_FLASH_PROTECT_RW_NOW)) + crec_flash_get_protect() & + EC_FLASH_PROTECT_RW_NOW)) #endif ) { /* diff --git a/common/spi_flash.c b/common/spi_flash.c index 3487c9a581..1ee39e78d8 100644 --- a/common/spi_flash.c +++ b/common/spi_flash.c @@ -114,7 +114,8 @@ int spi_flash_set_status(int reg1, int reg2) /* fail if both HW pin is asserted and SRP(s) is 1 */ if (spi_flash_check_wp() != SPI_WP_NONE && - (flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) != 0) + (crec_flash_get_protect() & + EC_FLASH_PROTECT_GPIO_ASSERTED) != 0) return EC_ERROR_ACCESS_DENIED; /* Enable writing to SPI flash */ diff --git a/common/switch.c b/common/switch.c index 5dc0fc6a35..2c1ea804a8 100644 --- a/common/switch.c +++ b/common/switch.c @@ -48,7 +48,7 @@ static void switch_update(void) else *memmap_switches &= ~EC_SWITCH_LID_OPEN; - if ((flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) == 0) + if ((crec_flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) == 0) *memmap_switches |= EC_SWITCH_WRITE_PROTECT_DISABLED; else *memmap_switches &= ~EC_SWITCH_WRITE_PROTECT_DISABLED; diff --git a/common/system.c b/common/system.c index e2c48278c8..eaaa9c664b 100644 --- a/common/system.c +++ b/common/system.c @@ -182,7 +182,7 @@ int system_is_locked(void) * is not protected. */ if ((EC_FLASH_PROTECT_GPIO_ASSERTED | EC_FLASH_PROTECT_RO_NOW) & - ~flash_get_protect()) { + ~crec_flash_get_protect()) { is_locked = 0; return 0; } @@ -753,12 +753,12 @@ const struct image_data *system_get_image_data(enum ec_image copy) #ifdef CONFIG_MAPPED_STORAGE addr += CONFIG_MAPPED_STORAGE_BASE; - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); memcpy(&data, (const void *)addr, sizeof(data)); - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); #else /* Read the version struct from flash into a buffer. */ - if (flash_read(addr, sizeof(data), (char *)&data)) + if (crec_flash_read(addr, sizeof(data), (char *)&data)) return NULL; #endif @@ -1687,7 +1687,7 @@ __overridable const char *board_read_serial(void) { if (IS_ENABLED(CONFIG_FLASH_PSTATE) && IS_ENABLED(CONFIG_FLASH_PSTATE_BANK)) - return flash_read_pstate_serial(); + return crec_flash_read_pstate_serial(); else if (IS_ENABLED(CONFIG_OTP)) return otp_read_serial(); else @@ -1698,7 +1698,7 @@ __overridable int board_write_serial(const char *serialno) { if (IS_ENABLED(CONFIG_FLASH_PSTATE) && IS_ENABLED(CONFIG_FLASH_PSTATE_BANK)) - return flash_write_pstate_serial(serialno); + return crec_flash_write_pstate_serial(serialno); else if (IS_ENABLED(CONFIG_OTP)) return otp_write_serial(serialno); else @@ -1712,7 +1712,7 @@ __overridable const char *board_read_mac_addr(void) { if (IS_ENABLED(CONFIG_FLASH_PSTATE) && IS_ENABLED(CONFIG_FLASH_PSTATE_BANK)) - return flash_read_pstate_mac_addr(); + return crec_flash_read_pstate_mac_addr(); else return ""; } @@ -1722,7 +1722,7 @@ __overridable int board_write_mac_addr(const char *mac_addr) { if (IS_ENABLED(CONFIG_FLASH_PSTATE) && IS_ENABLED(CONFIG_FLASH_PSTATE_BANK)) - return flash_write_pstate_mac_addr(mac_addr); + return crec_flash_write_pstate_mac_addr(mac_addr); else return EC_ERROR_UNIMPLEMENTED; } diff --git a/common/update_fw.c b/common/update_fw.c index bdb432acd6..068758e7b0 100644 --- a/common/update_fw.c +++ b/common/update_fw.c @@ -80,7 +80,8 @@ static uint8_t check_update_chunk(uint32_t block_offset, size_t body_size) * be erased. */ if (block_offset == base) { - if (flash_physical_erase(base, size) != EC_SUCCESS) { + if (crec_flash_physical_erase(base, size) != + EC_SUCCESS) { CPRINTF("%s:%d erase failure of 0x%x..+0x%x\n", __func__, __LINE__, base, size); return UPDATE_ERASE_FAILURE; @@ -189,7 +190,7 @@ void fw_update_start(struct first_response_pdu *rpdu) } rpdu->common.maximum_pdu_size = htobe32(CONFIG_UPDATE_PDU_SIZE); - rpdu->common.flash_protection = htobe32(flash_get_protect()); + rpdu->common.flash_protection = htobe32(crec_flash_get_protect()); rpdu->common.offset = htobe32(update_section.base_offset); if (version) memcpy(rpdu->common.version, version, @@ -300,7 +301,7 @@ void fw_update_command_handler(void *body, #endif CPRINTF("update: 0x%x\n", block_offset + CONFIG_PROGRAM_MEMORY_BASE); - if (flash_physical_write(block_offset, body_size, update_data) + if (crec_flash_physical_write(block_offset, body_size, update_data) != EC_SUCCESS) { *error_code = UPDATE_WRITE_FAILURE; CPRINTF("%s:%d update write error\n", __func__, __LINE__); diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index f79da52863..3ba2ea0c5c 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -917,9 +917,9 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload) pd_log_event(PD_EVENT_ACC_RW_ERASE, 0, 0, NULL); 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); + crec_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: @@ -928,7 +928,7 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload) (flash_offset < CONFIG_EC_WRITABLE_STORAGE_OFF + CONFIG_RW_STORAGE_OFF)) break; - flash_physical_write(flash_offset, 4 * (cnt - 1), + crec_flash_physical_write(flash_offset, 4 * (cnt - 1), (const char *)(payload + 1)); flash_offset += 4 * (cnt - 1); rw_flash_changed = 1; @@ -941,7 +941,7 @@ int pd_custom_flash_vdm(int port, int cnt, uint32_t *payload) /* zeroes the area containing the RSA signature */ for (offset = FW_RW_END - RSANUMBYTES; offset < FW_RW_END; offset += 4) - flash_physical_write(offset, 4, + crec_flash_physical_write(offset, 4, (const char *)&zero); } break; diff --git a/common/usb_update.c b/common/usb_update.c index cc443163ba..3b307ede9a 100644 --- a/common/usb_update.c +++ b/common/usb_update.c @@ -262,12 +262,13 @@ static int try_vendor_command(struct consumer const *consumer, size_t count) break; #endif case UPDATE_EXTRA_CMD_UNLOCK_RW: - flash_set_protect(EC_FLASH_PROTECT_RW_AT_BOOT, 0); + crec_flash_set_protect(EC_FLASH_PROTECT_RW_AT_BOOT, 0); response = EC_RES_SUCCESS; break; #ifdef CONFIG_ROLLBACK case UPDATE_EXTRA_CMD_UNLOCK_ROLLBACK: - flash_set_protect(EC_FLASH_PROTECT_ROLLBACK_AT_BOOT, 0); + crec_flash_set_protect(EC_FLASH_PROTECT_ROLLBACK_AT_BOOT + , 0); response = EC_RES_SUCCESS; break; #ifdef CONFIG_ROLLBACK_SECRET_SIZE diff --git a/common/vboot/vboot.c b/common/vboot/vboot.c index 1cf9cf7d80..910156335d 100644 --- a/common/vboot/vboot.c +++ b/common/vboot/vboot.c @@ -187,7 +187,7 @@ void vboot_main(void) return; } - if (!(flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED)) { + if (!(crec_flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED)) { /* * If hardware WP is disabled, PD communication is enabled. * We can return and wait for more power. diff --git a/common/vboot_hash.c b/common/vboot_hash.c index 04e3ae5f7f..ea32bbe680 100644 --- a/common/vboot_hash.c +++ b/common/vboot_hash.c @@ -94,7 +94,7 @@ static int read_and_hash_chunk(int offset, int size) return rv; } - rv = flash_read(offset, size, buf); + rv = crec_flash_read(offset, size, buf); if (rv == EC_SUCCESS) SHA256_update(&ctx, (const uint8_t *)buf, size); else @@ -115,10 +115,10 @@ static int read_and_hash_chunk(int offset, int size) static void hash_next_chunk(size_t size) { #ifdef CONFIG_MAPPED_STORAGE - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); SHA256_update(&ctx, (const uint8_t *)(CONFIG_MAPPED_STORAGE_BASE + data_offset + curr_pos), size); - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); #else if (read_and_hash_chunk(data_offset + curr_pos, size) != EC_SUCCESS) return; diff --git a/core/host/main.c b/core/host/main.c index e773713b2a..ed7032eb63 100644 --- a/core/host/main.c +++ b/core/host/main.c @@ -40,7 +40,7 @@ static int test_main(void) register_test_end_hook(); - flash_pre_init(); + crec_flash_pre_init(); system_pre_init(); system_common_pre_init(); diff --git a/include/flash.h b/include/flash.h index 5fc6ae1055..240ab0369b 100644 --- a/include/flash.h +++ b/include/flash.h @@ -19,7 +19,7 @@ extern struct ec_flash_bank const flash_bank_array[ * Return the bank the offset is in. * Return -1 if the offset is not at the beginning of that bank. */ -int flash_bank_index(int offset); +int crec_flash_bank_index(int offset); /* * Number of banks between offset and offset+size. @@ -38,25 +38,25 @@ int flash_bank_index(int offset); * begin = 0, end = -1.... * The idea is to prevent erasing more than you think. */ -int flash_bank_count(int offset, int size); +int crec_flash_bank_count(int offset, int size); /* * Return the size of the specified bank in bytes. * Return -1 if the bank is too large. */ -int flash_bank_size(int bank); +int crec_flash_bank_size(int bank); -int flash_bank_start_offset(int bank); +int crec_flash_bank_start_offset(int bank); -int flash_bank_erase_size(int bank); +int crec_flash_bank_erase_size(int bank); /* Number of physical flash banks */ #define PHYSICAL_BANKS CONFIG_FLASH_MULTIPLE_REGION /* WP region offset and size in units of flash banks */ -#define WP_BANK_OFFSET flash_bank_index(CONFIG_WP_STORAGE_OFF) +#define WP_BANK_OFFSET crec_flash_bank_index(CONFIG_WP_STORAGE_OFF) #define WP_BANK_COUNT \ - (flash_bank_count(CONFIG_WP_STORAGE_OFF, CONFIG_WP_STORAGE_SIZE)) + (crec_flash_bank_count(CONFIG_WP_STORAGE_OFF, CONFIG_WP_STORAGE_SIZE)) #else /* CONFIG_FLASH_MULTIPLE_REGION */ /* Number of physical flash banks */ @@ -101,9 +101,9 @@ int flash_bank_erase_size(int bank); * ROLLBACK region offset and size in units of flash banks. */ #ifdef CONFIG_FLASH_MULTIPLE_REGION -#define ROLLBACK_BANK_OFFSET flash_bank_index(CONFIG_ROLLBACK_OFF) +#define ROLLBACK_BANK_OFFSET crec_flash_bank_index(CONFIG_ROLLBACK_OFF) #define ROLLBACK_BANK_COUNT \ - flash_bank_count(CONFIG_ROLLBACK_OFF, CONFIG_ROLLBACK_SIZE) + crec_flash_bank_count(CONFIG_ROLLBACK_OFF, CONFIG_ROLLBACK_SIZE) #else #define ROLLBACK_BANK_OFFSET (CONFIG_ROLLBACK_OFF / CONFIG_FLASH_BANK_SIZE) #define ROLLBACK_BANK_COUNT (CONFIG_ROLLBACK_SIZE / CONFIG_FLASH_BANK_SIZE) @@ -130,7 +130,7 @@ enum flash_region { * @param size Number of bytes to write. * @param data Destination buffer for data. Must be 32-bit aligned. */ -int flash_physical_read(int offset, int size, char *data); +int crec_flash_physical_read(int offset, int size, char *data); /** * Write to physical flash. @@ -141,7 +141,7 @@ int flash_physical_read(int offset, int size, char *data); * @param size Number of bytes to write. * @param data Data to write to flash. Must be 32-bit aligned. */ -int flash_physical_write(int offset, int size, const char *data); +int crec_flash_physical_write(int offset, int size, const char *data); /** * Erase physical flash. @@ -151,7 +151,7 @@ int flash_physical_write(int offset, int size, const char *data); * @param offset Flash offset to erase. * @param size Number of bytes to erase. */ -int flash_physical_erase(int offset, int size); +int crec_flash_physical_erase(int offset, int size); /** * Read physical write protect setting for a flash bank. @@ -159,7 +159,7 @@ int flash_physical_erase(int offset, int size); * @param bank Bank index to check. * @return non-zero if bank is protected until reboot. */ -int flash_physical_get_protect(int bank); +int crec_flash_physical_get_protect(int bank); /** * Return flash protect state flags from the physical layer. @@ -168,7 +168,7 @@ int flash_physical_get_protect(int bank); * * Uses the EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_protect_flags(void); +uint32_t crec_flash_physical_get_protect_flags(void); /** * Enable/disable protecting firmware/pstate at boot. @@ -177,7 +177,7 @@ uint32_t flash_physical_get_protect_flags(void); * taken care of) * @return non-zero if error. */ -int flash_physical_protect_at_boot(uint32_t new_flags); +int crec_flash_physical_protect_at_boot(uint32_t new_flags); /** * Protect flash now. @@ -185,7 +185,7 @@ int flash_physical_protect_at_boot(uint32_t new_flags); * @param all Protect all (=1) or just read-only and pstate (=0). * @return non-zero if error. */ -int flash_physical_protect_now(int all); +int crec_flash_physical_protect_now(int all); /** * Force reload of flash protection bits. @@ -196,21 +196,21 @@ int flash_physical_protect_now(int all); * * Only returns (with EC_ERROR_ACCESS_DENIED) if the command is locked. */ -int flash_physical_force_reload(void); +int crec_flash_physical_force_reload(void); /** * Restore flash physical layer state after sysjump. * * @return non-zero if restored. */ -int flash_physical_restore_state(void); +int crec_flash_physical_restore_state(void); /** * Return the valid flash protect flags. * * @return a combination of EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_valid_flags(void); +uint32_t crec_flash_physical_get_valid_flags(void); /** * Return the writable flash protect flags. @@ -218,7 +218,7 @@ uint32_t flash_physical_get_valid_flags(void); * @param cur_flags The current flash protect flags. * @return a combination of EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags); +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags); /*****************************************************************************/ /* Low-level common code for use by flash modules. */ @@ -232,7 +232,7 @@ uint32_t flash_physical_get_writable_flags(uint32_t cur_flags); * @param size Number of bytes to check (word-aligned) * @return 1 if erased, 0 if not erased */ -int flash_is_erased(uint32_t offset, int size); +int crec_flash_is_erased(uint32_t offset, int size); /** * Enable write protect for the specified range. @@ -246,7 +246,7 @@ int flash_is_erased(uint32_t offset, int size); * taken care of) * @return EC_SUCCESS, or nonzero if error. */ -int flash_protect_at_boot(uint32_t new_flags); +int crec_flash_protect_at_boot(uint32_t new_flags); /*****************************************************************************/ /* High-level interface for use by other modules. */ @@ -256,13 +256,13 @@ int flash_protect_at_boot(uint32_t new_flags); * * Applies at-boot protection settings if necessary. */ -int flash_pre_init(void); +int crec_flash_pre_init(void); /** * Return the usable size of flash in bytes. Note that this may be smaller * than the physical flash size. */ -int flash_get_size(void); +int crec_flash_get_size(void); /** * Get the physical memory address of a flash offset @@ -283,7 +283,7 @@ int flash_get_size(void); * in memory, unless function fails, iwc it is unset. * @return size of flash region available at *ptrp, or -1 on error */ -int flash_dataptr(int offset, int size_req, int align, const char **ptrp); +int crec_flash_dataptr(int offset, int size_req, int align, const char **ptrp); /** * Read from flash. @@ -296,7 +296,7 @@ int flash_dataptr(int offset, int size_req, int align, const char **ptrp); * @param size Number of bytes to write. * @param data Destination buffer for data. Must be 32-bit aligned. */ -int flash_read(int offset, int size, char *data); +int crec_flash_read(int offset, int size, char *data); /** * Write to flash. @@ -307,7 +307,7 @@ int flash_read(int offset, int size, char *data); * @param size Number of bytes to write. * @param data Data to write to flash. Must be 32-bit aligned. */ -int flash_write(int offset, int size, const char *data); +int crec_flash_write(int offset, int size, const char *data); /** * Erase flash. @@ -317,14 +317,14 @@ int flash_write(int offset, int size, const char *data); * @param offset Flash offset to erase. * @param size Number of bytes to erase. */ -int flash_erase(int offset, int size); +int crec_flash_erase(int offset, int size); /** * Return the flash protect state. * * Uses the EC_FLASH_PROTECT_* flags from ec_commands.h */ -uint32_t flash_get_protect(void); +uint32_t crec_flash_get_protect(void); /** * Set the flash protect state. @@ -332,7 +332,7 @@ uint32_t flash_get_protect(void); * @param mask Bits in flags to apply. * @param flags New values for flags. */ -int flash_set_protect(uint32_t mask, uint32_t flags); +int crec_flash_set_protect(uint32_t mask, uint32_t flags); /** * Get the serial number from flash. @@ -340,7 +340,7 @@ int flash_set_protect(uint32_t mask, uint32_t flags); * @return char * ascii serial number string. * NULL if error. */ -const char *flash_read_pstate_serial(void); +const char *crec_flash_read_pstate_serial(void); /** * Set the serial number in flash. @@ -349,7 +349,7 @@ const char *flash_read_pstate_serial(void); * * @return success status. */ -int flash_write_pstate_serial(const char *serialno); +int crec_flash_write_pstate_serial(const char *serialno); /** * Get the MAC address from flash. @@ -358,7 +358,7 @@ int flash_write_pstate_serial(const char *serialno); * Format: "01:23:45:67:89:AB" * NULL if error. */ -const char *flash_read_pstate_mac_addr(void); +const char *crec_flash_read_pstate_mac_addr(void); /** * Set the MAC address in flash. @@ -368,7 +368,7 @@ const char *flash_read_pstate_mac_addr(void); * * @return success status. */ -int flash_write_pstate_mac_addr(const char *mac_addr); +int crec_flash_write_pstate_mac_addr(const char *mac_addr); /** * Lock or unlock HW necessary for mapped storage read. @@ -376,9 +376,9 @@ int flash_write_pstate_mac_addr(const char *mac_addr); * @param lock 1 to lock, 0 to unlock. */ #ifdef CONFIG_EXTERNAL_STORAGE -void flash_lock_mapped_storage(int lock); +void crec_flash_lock_mapped_storage(int lock); #else -static inline void flash_lock_mapped_storage(int lock) { }; +static inline void crec_flash_lock_mapped_storage(int lock) { }; #endif /* CONFIG_EXTERNAL_STORAGE */ /** @@ -388,6 +388,6 @@ static inline void flash_lock_mapped_storage(int lock) { }; * @param select 1 to select flash, 0 to deselect (disable). * @return EC_RES_* status code. */ -int board_flash_select(int select); +int crec_board_flash_select(int select); #endif /* __CROS_EC_FLASH_H */ diff --git a/test/flash.c b/test/flash.c index 1b55d236d9..4f9ca74016 100644 --- a/test/flash.c +++ b/test/flash.c @@ -253,7 +253,7 @@ static int test_read(void) #endif /* The first few bytes in the flash should always contain some code */ - TEST_ASSERT(!flash_is_erased(0, sizeof(buf))); + TEST_ASSERT(!crec_flash_is_erased(0, sizeof(buf))); TEST_ASSERT(host_command_read(0, sizeof(buf), buf) == EC_RES_SUCCESS); TEST_ASSERT_ARRAY_EQ(buf, (char *)CONFIG_PROGRAM_MEMORY_BASE, @@ -268,11 +268,11 @@ static int test_is_erased(void) #ifdef EMU_BUILD memset(__host_flash, 0xff, 1024); - TEST_ASSERT(flash_is_erased(0, 1024)); + TEST_ASSERT(crec_flash_is_erased(0, 1024)); for (i = 0; i < 1024; ++i) { __host_flash[i] = 0xec; - TEST_ASSERT(!flash_is_erased(0, 1024)); + TEST_ASSERT(!crec_flash_is_erased(0, 1024)); __host_flash[i] = 0xff; } #else @@ -400,9 +400,9 @@ static int test_write_protect(void) ASSERT_WP_FLAGS(EC_FLASH_PROTECT_ALL_NOW | EC_FLASH_PROTECT_RO_AT_BOOT); /* Check we cannot erase anything */ - TEST_ASSERT(flash_physical_erase(CONFIG_RO_STORAGE_OFF, + TEST_ASSERT(crec_flash_physical_erase(CONFIG_RO_STORAGE_OFF, CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS); - TEST_ASSERT(flash_physical_erase(CONFIG_RW_STORAGE_OFF, + TEST_ASSERT(crec_flash_physical_erase(CONFIG_RW_STORAGE_OFF, CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS); /* We should not even try to write/erase */ @@ -418,7 +418,7 @@ static int test_boot_write_protect(void) { /* Check write protect state persists through reboot */ ASSERT_WP_FLAGS(EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_RO_AT_BOOT); - TEST_ASSERT(flash_physical_erase(CONFIG_RO_STORAGE_OFF, + TEST_ASSERT(crec_flash_physical_erase(CONFIG_RO_STORAGE_OFF, CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS); return EC_SUCCESS; diff --git a/test/flash_write_protect.c b/test/flash_write_protect.c index 2b69484e93..2bf801c9b0 100644 --- a/test/flash_write_protect.c +++ b/test/flash_write_protect.c @@ -42,8 +42,8 @@ test_static int test_flash_write_protect_enable(void) TEST_EQ(check_image_and_hardware_write_protect(), EC_SUCCESS, "%d"); /* Equivalent of ectool --name=cros_fp flashprotect enable */ - rv = flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, - EC_FLASH_PROTECT_RO_AT_BOOT); + rv = crec_flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, + EC_FLASH_PROTECT_RO_AT_BOOT); return rv; } @@ -55,7 +55,7 @@ test_static int test_flash_write_protect_disable(void) TEST_EQ(check_image_and_hardware_write_protect(), EC_SUCCESS, "%d"); /* Equivalent of ectool --name=cros_fp flashprotect disable */ - rv = flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, 0); + rv = crec_flash_set_protect(EC_FLASH_PROTECT_RO_AT_BOOT, 0); TEST_NE(rv, EC_SUCCESS, "%d"); return EC_SUCCESS; diff --git a/test/rollback.c b/test/rollback.c index 50c65e876d..2038333311 100644 --- a/test/rollback.c +++ b/test/rollback.c @@ -46,7 +46,8 @@ test_static int read_rollback_region(const struct rollback_info *info, info->region_1_offset; for (i = 0; i < info->region_size_bytes; i++) { - if (flash_read(offset + i, sizeof(data), &data) == EC_SUCCESS) + if (crec_flash_read(offset + i, sizeof(data), &data) == + EC_SUCCESS) bytes_read++; } diff --git a/zephyr/shim/src/flash.c b/zephyr/shim/src/flash.c index 064067a2bc..3c8de4f4d4 100644 --- a/zephyr/shim/src/flash.c +++ b/zephyr/shim/src/flash.c @@ -40,12 +40,12 @@ static int flash_get_status1(void) return saved_sr1; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); cros_flash_get_status_reg(cros_flash_dev, CMD_READ_STATUS_REG, ®); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return reg; } @@ -58,12 +58,12 @@ static int flash_get_status2(void) return saved_sr1; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); cros_flash_get_status_reg(cros_flash_dev, CMD_READ_STATUS_REG2, ®); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return reg; } @@ -115,7 +115,7 @@ static int flash_set_status_for_prot(int reg1, int reg2) if (is_int_flash_protected()) return EC_ERROR_ACCESS_DENIED; - if (flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) + if (crec_flash_get_protect() & EC_FLASH_PROTECT_GPIO_ASSERTED) return EC_ERROR_ACCESS_DENIED; flash_uma_lock(0); } @@ -131,14 +131,14 @@ static int flash_set_status_for_prot(int reg1, int reg2) #endif /*_CONFIG_WP_ACTIVE_HIGH_*/ /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); regs[0] = reg1; regs[1] = reg2; flash_write_status_reg(regs); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); spi_flash_reg_to_protect(reg1, reg2, &addr_prot_start, &addr_prot_length); @@ -220,7 +220,7 @@ static int flash_write_prot_reg(unsigned int offset, unsigned int bytes, /* TODO(b/174873770): Add calls to Zephyr code here */ #ifdef CONFIG_EXTERNAL_STORAGE -void flash_lock_mapped_storage(int lock) +void crec_flash_lock_mapped_storage(int lock) { if (lock) mutex_lock(&flash_lock); @@ -229,7 +229,7 @@ void flash_lock_mapped_storage(int lock) } #endif -int flash_physical_write(int offset, int size, const char *data) +int crec_flash_physical_write(int offset, int size, const char *data) { int rv; @@ -247,17 +247,17 @@ int flash_physical_write(int offset, int size, const char *data) return EC_ERROR_ACCESS_DENIED; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); rv = cros_flash_physical_write(cros_flash_dev, offset, size, data); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return rv; } -int flash_physical_erase(int offset, int size) +int crec_flash_physical_erase(int offset, int size) { int rv; @@ -270,24 +270,24 @@ int flash_physical_erase(int offset, int size) return EC_ERROR_ACCESS_DENIED; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); rv = cros_flash_physical_erase(cros_flash_dev, offset, size); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return rv; } -int flash_physical_get_protect(int bank) +int crec_flash_physical_get_protect(int bank) { uint32_t addr = bank * CONFIG_FLASH_BANK_SIZE; return flash_check_prot_reg(addr, CONFIG_FLASH_BANK_SIZE); } -uint32_t flash_physical_get_protect_flags(void) +uint32_t crec_flash_physical_get_protect_flags(void) { uint32_t flags = 0; @@ -310,7 +310,7 @@ uint32_t flash_physical_get_protect_flags(void) return flags; } -int flash_physical_protect_at_boot(uint32_t new_flags) +int crec_flash_physical_protect_at_boot(uint32_t new_flags) { int ret; @@ -333,7 +333,7 @@ int flash_physical_protect_at_boot(uint32_t new_flags) return ret; } -int flash_physical_protect_now(int all) +int crec_flash_physical_protect_now(int all) { if (all) { /* @@ -348,16 +348,16 @@ int flash_physical_protect_now(int all) return EC_SUCCESS; } -int flash_physical_read(int offset, int size, char *data) +int crec_flash_physical_read(int offset, int size, char *data) { int rv; /* Lock physical flash operations */ - flash_lock_mapped_storage(1); + crec_flash_lock_mapped_storage(1); rv = cros_flash_physical_read(cros_flash_dev, offset, size, data); /* Unlock physical flash operations */ - flash_lock_mapped_storage(0); + crec_flash_lock_mapped_storage(0); return rv; } @@ -389,13 +389,13 @@ static int flash_dev_init(const struct device *unused) return 0; } -uint32_t flash_physical_get_valid_flags(void) +uint32_t crec_flash_physical_get_valid_flags(void) { return EC_FLASH_PROTECT_RO_AT_BOOT | EC_FLASH_PROTECT_RO_NOW | EC_FLASH_PROTECT_ALL_NOW; } -uint32_t flash_physical_get_writable_flags(uint32_t cur_flags) +uint32_t crec_flash_physical_get_writable_flags(uint32_t cur_flags) { uint32_t ret = 0; |