summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2012-07-11 17:23:19 +0800
committerGerrit <chrome-bot@google.com>2012-07-13 01:13:20 -0700
commit1bd61468929bdd4907d02d56b9144d654b6ad272 (patch)
tree60aedd1514f33865d5bceeb2bb0a607301d8fb5b
parent23d031343f00b88a900c701aa59636ea3b64aa33 (diff)
downloadchrome-ec-1bd61468929bdd4907d02d56b9144d654b6ad272.tar.gz
Add a test of flash read/write/erase test
This test checks physical read/write/erase functions are called correctly. BUG=chrome-os-partner:10261 TEST=Test passed. Change-Id: Iff58f352bd732a0da9b7b7fe68c4bf87c84906a8 Reviewed-on: https://gerrit.chromium.org/gerrit/27144 Reviewed-by: Yung-Chieh Lo <yjlou%chromium.org@gtempaccount.com> Tested-by: Vic Yang <victoryang@chromium.org> Commit-Ready: Vic Yang <victoryang@chromium.org>
-rw-r--r--test/build.mk6
-rw-r--r--test/flash.c8
-rw-r--r--test/flash_rw_erase.py29
-rw-r--r--test/flash_rw_erase.tasklist20
-rw-r--r--test/flash_test_util.py14
5 files changed, 72 insertions, 5 deletions
diff --git a/test/build.mk b/test/build.mk
index 9736ec26f2..a38cce29e8 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -8,7 +8,7 @@
test-list=hello pingpong timer_calib timer_dos timer_jump mutex thermal
test-list+=power_button kb_deghost kb_debounce scancode typematic charging
-test-list+=flash_overwrite
+test-list+=flash_overwrite flash_rw_erase
#disable: powerdemo
pingpong-y=pingpong.o
@@ -17,6 +17,7 @@ timer_calib-y=timer_calib.o
timer_dos-y=timer_dos.o
mutex-y=mutex.o
flash_overwrite-y=flash.o
+flash_rw_erase-y=flash.o
# Mock modules for 'thermal'
chip-mock-thermal-lpc.o=mock_lpc.o
@@ -55,3 +56,6 @@ common-mock-charging-charger_bq24725.o=mock_charger.o
# Mock modules for 'flash_overwrite'
chip-mock-flash_overwrite-flash.o=mock_flash.o
chip-mock-flash_overwrite-gpio.o=mock_gpio.o
+
+# Mock modules for 'flash_rw_erase'
+chip-mock-flash_rw_erase-flash.o=mock_flash.o
diff --git a/test/flash.c b/test/flash.c
index c7e8d94365..6f822d88ec 100644
--- a/test/flash.c
+++ b/test/flash.c
@@ -30,7 +30,7 @@ static int hc_flash_info(int argc, char **argv)
struct ec_response_flash_info *r =
(struct ec_response_flash_info *)data;
- res = host_command_process(0, EC_CMD_FLASH_INFO, data, &resp_size);
+ res = host_command_process(EC_CMD_FLASH_INFO, data, &resp_size);
if (res != EC_RES_SUCCESS)
return EC_ERROR_UNKNOWN;
uart_printf("flash_size = %d\n", r->flash_size);
@@ -66,7 +66,7 @@ static int hc_flash_read(int argc, char **argv)
if (*e)
return EC_ERROR_PARAM2;
- res = host_command_process(0, EC_CMD_FLASH_READ, data, &resp_size);
+ res = host_command_process(EC_CMD_FLASH_READ, data, &resp_size);
if (res != EC_RES_SUCCESS)
return EC_ERROR_UNKNOWN;
for (i = 0; i < size; ++i) {
@@ -115,7 +115,7 @@ static int hc_flash_write(int argc, char **argv)
seed = seed * mult + add;
}
- res = host_command_process(0, EC_CMD_FLASH_WRITE, data, &resp_size);
+ res = host_command_process(EC_CMD_FLASH_WRITE, data, &resp_size);
if (res != EC_RES_SUCCESS)
return EC_ERROR_UNKNOWN;
return EC_SUCCESS;
@@ -144,7 +144,7 @@ static int hc_flash_erase(int argc, char **argv)
if (*e)
return EC_ERROR_PARAM2;
- res = host_command_process(0, EC_CMD_FLASH_ERASE, data, &resp_size);
+ res = host_command_process(EC_CMD_FLASH_ERASE, data, &resp_size);
if (res != EC_RES_SUCCESS)
return EC_ERROR_UNKNOWN;
return EC_SUCCESS;
diff --git a/test/flash_rw_erase.py b/test/flash_rw_erase.py
new file mode 100644
index 0000000000..0ee8e774c0
--- /dev/null
+++ b/test/flash_rw_erase.py
@@ -0,0 +1,29 @@
+# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+#
+# Flash read/write/erase test
+#
+
+from flash_test_util import test_erase
+from flash_test_util import test_read
+from flash_test_util import test_write
+import time
+
+def test(helper):
+ helper.wait_output("--- UART initialized")
+
+ # Jump to RW-A
+ helper.ec_command("sysjump a")
+ helper.wait_output("idle task started") # jump completed
+ time.sleep(0.5)
+
+ # We are in RW now. Read/write/erase on RO should all succeed.
+ test_erase(helper, 0, 0x1000)
+ test_erase(helper, 0x1000, 0x2000)
+ test_read(helper, 0, 0x40)
+ test_read(helper, 0x130, 0x40)
+ test_write(helper, 0, 0x30)
+ test_write(helper, 0x130, 0x30)
+
+ return True
diff --git a/test/flash_rw_erase.tasklist b/test/flash_rw_erase.tasklist
new file mode 100644
index 0000000000..65a15ac498
--- /dev/null
+++ b/test/flash_rw_erase.tasklist
@@ -0,0 +1,20 @@
+/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/**
+ * List of enabled tasks in the priority order
+ *
+ * The first one has the lowest priority.
+ *
+ * For each task, use the macro TASK(n, r, d) where :
+ * 'n' in the name of the task
+ * 'r' in the main routine of the task
+ * 'd' in an opaque parameter passed to the routine at startup
+ */
+#define CONFIG_TASK_LIST \
+ TASK(WATCHDOG, watchdog_task, NULL) \
+ TASK(VBOOTHASH, vboot_hash_task, NULL) \
+ TASK(HOSTCMD, host_command_task, NULL) \
+ TASK(CONSOLE, console_task, NULL)
diff --git a/test/flash_test_util.py b/test/flash_test_util.py
index c0194a3a6e..476f3b2d09 100644
--- a/test/flash_test_util.py
+++ b/test/flash_test_util.py
@@ -26,6 +26,20 @@ def xor_sum(size, seed, mult, add):
seed = seed * mult + add
return ret
+def test_erase(helper, offset, size):
+ helper.ec_command("hcflasherase %d %d" % (offset, size))
+ helper.wait_output("Flash erase at %x size %x" % (offset, size))
+
+def test_read(helper, offset, size):
+ helper.ec_command("hcflashread %d %d" % (offset, size))
+ while size > 0:
+ cur_size = size if size <= 32 else 32
+ expect_str = ''.join([("%02x" % (x & 0xff)) for x in
+ range(offset, offset + cur_size)])
+ helper.wait_output(expect_str)
+ offset = offset + cur_size
+ size = size - cur_size
+
def test_write(helper, offset, size, expect_fail=False):
seed = random.randint(2, 10000)
mult = random.randint(2, 10000)