summaryrefslogtreecommitdiff
path: root/zephyr/shim/src/flash.c
diff options
context:
space:
mode:
authorTim Lin <tim2.lin@ite.corp-partner.google.com>2021-06-29 17:00:32 +0800
committerCommit Bot <commit-bot@chromium.org>2021-07-01 15:01:02 +0000
commit7e023660225971dc0b9edb4889a7ed6dc70b59e8 (patch)
tree641c10020b477181c3413d662aaaf26b7f0dc043 /zephyr/shim/src/flash.c
parent300daebbb748a7b5f51bf411adfb985b83c085a4 (diff)
downloadchrome-ec-7e023660225971dc0b9edb4889a7ed6dc70b59e8.tar.gz
zephyr/drivers: npcx: reorganizes the flash driver(3)
Move NPCX specific code crec_flash_physical_get_protect(), crec_flash_physical_get_protect_flags(), crec_flash_physical_protect_at_boot(), and crec_flash_physical_protect_now() from shim/flash.c to cros_flash/cros_flash_npcx.c. BUG=b:187192628 BRANCH=none TEST=zmake -lDEBUG configure -b -B zephyr/build_volteer \ zephyr/projects/volteer/volteer/ Cq-Depend: chromium:2994430 Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com> Change-Id: Id6ed382ad4578969838339c9eb874b323390c485 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2891674 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org> Tested-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr/shim/src/flash.c')
-rw-r--r--zephyr/shim/src/flash.c60
1 files changed, 4 insertions, 56 deletions
diff --git a/zephyr/shim/src/flash.c b/zephyr/shim/src/flash.c
index ce74a34398..b72d7b5763 100644
--- a/zephyr/shim/src/flash.c
+++ b/zephyr/shim/src/flash.c
@@ -9,9 +9,7 @@
#include "console.h"
#include "drivers/cros_flash.h"
-#include "gpio.h"
#include "registers.h"
-#include "spi_flash_reg.h"
#include "task.h"
#include "util.h"
@@ -20,8 +18,6 @@ LOG_MODULE_REGISTER(shim_flash, LOG_LEVEL_ERR);
#define CROS_FLASH_DEV DT_LABEL(DT_NODELABEL(fiu0))
static const struct device *cros_flash_dev;
-static uint8_t flag_prot_inconsistent;
-
K_MUTEX_DEFINE(flash_lock);
/* TODO(b/174873770): Add calls to Zephyr code here */
@@ -72,70 +68,22 @@ int crec_flash_physical_erase(int offset, int size)
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);
+ return cros_flash_physical_get_protect(cros_flash_dev, bank);
}
uint32_t crec_flash_physical_get_protect_flags(void)
{
- uint32_t flags = 0;
-
- /* Check if WP region is protected in status register */
- if (flash_check_prot_reg(WP_BANK_OFFSET * CONFIG_FLASH_BANK_SIZE,
- WP_BANK_COUNT * CONFIG_FLASH_BANK_SIZE))
- flags |= EC_FLASH_PROTECT_RO_AT_BOOT;
-
- /*
- * TODO: If status register protects a range, but SRP0 is not set,
- * flags should indicate EC_FLASH_PROTECT_ERROR_INCONSISTENT.
- */
- if (flag_prot_inconsistent)
- flags |= EC_FLASH_PROTECT_ERROR_INCONSISTENT;
-
- /* Read all-protected state from our shadow copy */
- if (all_protected)
- flags |= EC_FLASH_PROTECT_ALL_NOW;
-
- return flags;
+ return cros_flash_physical_get_protect_flags(cros_flash_dev);
}
int crec_flash_physical_protect_at_boot(uint32_t new_flags)
{
- int ret;
-
- if ((new_flags & (EC_FLASH_PROTECT_RO_AT_BOOT |
- EC_FLASH_PROTECT_ALL_AT_BOOT)) == 0) {
- /* Clear protection bits in status register */
- return flash_set_status_for_prot(0, 0);
- }
-
- ret = flash_write_prot_reg(CONFIG_WP_STORAGE_OFF,
- CONFIG_WP_STORAGE_SIZE, 1);
-
- /*
- * Set UMA_LOCK bit for locking all UMA transaction.
- * But we still can read directly from flash mapping address
- */
- if (new_flags & EC_FLASH_PROTECT_ALL_AT_BOOT)
- flash_uma_lock(1);
-
- return ret;
+ return cros_flash_physical_protect_at_boot(cros_flash_dev, new_flags);
}
int crec_flash_physical_protect_now(int all)
{
- if (all) {
- /*
- * Set UMA_LOCK bit for locking all UMA transaction.
- * But we still can read directly from flash mapping address
- */
- flash_uma_lock(1);
- } else {
- /* TODO: Implement RO "now" protection */
- }
-
- return EC_SUCCESS;
+ return cros_flash_physical_protect_now(cros_flash_dev, all);
}
int crec_flash_physical_read(int offset, int size, char *data)