summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-09-23 23:57:21 +0800
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-09-24 21:00:25 +0000
commit1e08d488bdf680adc20094aec4e58c065b208b82 (patch)
tree6667f5f14dc9199f037f8ff27b4e87eeb4d7daf7 /chip
parent03cc4b422d28459fca60d29d830078bd8d6f1db1 (diff)
downloadchrome-ec-1e08d488bdf680adc20094aec4e58c065b208b82.tar.gz
Mock flash erase/write function at physical layer
This moves the mock function from common layer down to physical layer to complete the test of common layer. Also disable flash test for hardware tests, as this is only testing common layer. BUG=chrome-os-partner:19236 TEST=util/make_all.sh BRANCH=None Change-Id: Idd1c2c44591952894486f84d428872cfbf2cfdad Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/170297 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/host/config_chip.h2
-rw-r--r--chip/host/flash.c16
2 files changed, 15 insertions, 3 deletions
diff --git a/chip/host/config_chip.h b/chip/host/config_chip.h
index 0c9a350617..9aa51f6108 100644
--- a/chip/host/config_chip.h
+++ b/chip/host/config_chip.h
@@ -15,7 +15,7 @@ extern char __host_flash[CONFIG_FLASH_PHYSICAL_SIZE];
#define CONFIG_FLASH_BASE ((uintptr_t)__host_flash)
#define CONFIG_FLASH_BANK_SIZE 0x1000
-#define CONFIG_FLASH_ERASE_SIZE 0x0400 /* erase bank size */
+#define CONFIG_FLASH_ERASE_SIZE 0x0010 /* erase bank size */
#define CONFIG_FLASH_WRITE_SIZE 0x0002 /* minimum write size */
#define CONFIG_FLASH_WRITE_IDEAL_SIZE 0x0080 /* ideal write size */
#define CONFIG_RAM_BASE 0x0 /* Not supported */
diff --git a/chip/host/flash.c b/chip/host/flash.c
index fac8620b38..892e4067a9 100644
--- a/chip/host/flash.c
+++ b/chip/host/flash.c
@@ -15,14 +15,20 @@
char __host_flash[CONFIG_FLASH_PHYSICAL_SIZE];
uint8_t __host_flash_protect[PHYSICAL_BANKS];
+/* Override this function to make flash erase/write operation fail */
+test_mockable int flash_pre_op(void)
+{
+ return EC_SUCCESS;
+}
+
static int flash_check_protect(int offset, int size)
{
int first_bank = offset / CONFIG_FLASH_BANK_SIZE;
- int last_bank = DIV_ROUND_UP(offset + size + 1,
+ int last_bank = DIV_ROUND_UP(offset + size,
CONFIG_FLASH_BANK_SIZE);
int bank;
- for (bank = first_bank; bank <= last_bank; ++bank)
+ for (bank = first_bank; bank < last_bank; ++bank)
if (__host_flash_protect[bank])
return 1;
return 0;
@@ -61,6 +67,9 @@ int flash_physical_write(int offset, int size, const char *data)
{
ASSERT((size & (CONFIG_FLASH_WRITE_SIZE - 1)) == 0);
+ if (flash_pre_op() != EC_SUCCESS)
+ return EC_ERROR_UNKNOWN;
+
if (flash_check_protect(offset, size))
return EC_ERROR_ACCESS_DENIED;
@@ -74,6 +83,9 @@ int flash_physical_erase(int offset, int size)
{
ASSERT((size & (CONFIG_FLASH_ERASE_SIZE - 1)) == 0);
+ if (flash_pre_op() != EC_SUCCESS)
+ return EC_ERROR_UNKNOWN;
+
if (flash_check_protect(offset, size))
return EC_ERROR_ACCESS_DENIED;