diff options
author | Vic Yang <victoryang@chromium.org> | 2013-04-20 20:59:57 +0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-04-21 23:02:03 -0700 |
commit | 8f00a3beee8cae1da4c56714bb9693e1ea3178db (patch) | |
tree | 8519f073647e622ce0238fc0dc3d6e086ba173d2 | |
parent | 9c38f433585a4fc07873bf4ceb8df774c8faa4ea (diff) | |
download | chrome-ec-8f00a3beee8cae1da4c56714bb9693e1ea3178db.tar.gz |
Add more flash test
This adds write protect status check across reboots.
BUG=chrome-os-partner:18598
TEST=Run on Spring
BRANCH=None
Change-Id: Iba0c5d6f906c64af4216aaecac35b87c1392a873
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/48752
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | test/flash.c | 113 | ||||
-rw-r--r-- | test/flash.tasklist | 3 |
2 files changed, 104 insertions, 12 deletions
diff --git a/test/flash.c b/test/flash.c index 52a4ec625f..67ee61ec27 100644 --- a/test/flash.c +++ b/test/flash.c @@ -8,6 +8,7 @@ #include "board.h" #include "console.h" #include "ec_commands.h" +#include "flash.h" #include "gpio.h" #include "hooks.h" #include "host_command.h" @@ -24,7 +25,16 @@ static char last_write_data[64]; static int last_erase_offset; static int last_erase_size; -static int mock_wp; +static int mock_wp = -1; + +#define TEST_STATE_CLEAN_UP (1 << 0) +#define TEST_STATE_STEP_2 (1 << 1) +#define TEST_STATE_STEP_3 (1 << 2) +#define TEST_STATE_BOOT_WP_ON (1 << 3) +#define TEST_STATE_PASSED (1 << 4) + +#define CLEAN_UP_FLAG_PASSED TEST_STATE_PASSED +#define CLEAN_UP_FLAG_FAILED 0 /*****************************************************************************/ /* Mock functions */ @@ -52,6 +62,9 @@ int gpio_get_level(enum gpio_signal signal) { const char *name = gpio_list[signal].name; + if (mock_wp == -1) + mock_wp = !!(system_get_scratchpad() & TEST_STATE_BOOT_WP_ON); + if (strcasecmp(name, "WRITE_PROTECTn") == 0 || strcasecmp(name, "WP_L") == 0) return !mock_wp; @@ -293,24 +306,61 @@ static int test_write_protect(void) SET_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT, 1); SET_WP_FLAGS(EC_FLASH_PROTECT_ALL_NOW, 1); SET_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT, 0); + SET_WP_FLAGS(EC_FLASH_PROTECT_ALL_NOW, 0); 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_SECTION_RO_OFF, + CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS); + TEST_ASSERT(flash_physical_erase(CONFIG_SECTION_RW_OFF, + CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS); + + return EC_SUCCESS; +} + +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_SECTION_RO_OFF, + CONFIG_FLASH_ERASE_SIZE) != EC_SUCCESS); + + return EC_SUCCESS; +} + +static int test_boot_no_write_protect(void) +{ + /* Check write protect is not enabled if WP GPIO is deasserted */ + ASSERT_WP_NO_FLAGS(EC_FLASH_PROTECT_RO_NOW); + ASSERT_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT); + return EC_SUCCESS; } -static int clear_wp(void) +static int clean_up(void) { + system_set_scratchpad(0); SET_WP_FLAGS(EC_FLASH_PROTECT_RO_AT_BOOT, 0); return EC_SUCCESS; } -static void test_setup(void) +static void reboot_to_clean_up(uint32_t flags) { - clear_wp(); + ccprintf("Rebooting to clear WP...\n"); + cflush(); + system_set_scratchpad(TEST_STATE_CLEAN_UP | flags); + system_reset(SYSTEM_RESET_HARD); } -DECLARE_HOOK(HOOK_INIT, test_setup, HOOK_PRIO_LAST); -static int command_run_test(int argc, char **argv) +static void reboot_to_next_step(uint32_t step) +{ + ccprintf("Rebooting to next test step...\n"); + cflush(); + system_set_scratchpad(step); + system_reset(SYSTEM_RESET_HARD); +} + +static void run_test_step1(void) { error_count = 0; mock_wp = 0; @@ -321,15 +371,56 @@ static int command_run_test(int argc, char **argv) if (error_count) { ccprintf("Failed %d tests!\n", error_count); + reboot_to_clean_up(CLEAN_UP_FLAG_FAILED); } else { - ccprintf("Pass!\n"); + reboot_to_next_step(TEST_STATE_STEP_2 | TEST_STATE_BOOT_WP_ON); } +} - ccprintf("Rebooting to clear WP...\n"); - cflush(); - system_reset(SYSTEM_RESET_HARD); +static void run_test_step2(void) +{ + RUN_TEST(test_boot_write_protect); + + if (error_count) { + ccprintf("Failed %d tests!\n", error_count); + reboot_to_clean_up(CLEAN_UP_FLAG_FAILED); + } else { + reboot_to_next_step(TEST_STATE_STEP_3); + } +} + +static void run_test_step3(void) +{ + RUN_TEST(test_boot_no_write_protect); + + if (error_count) { + ccprintf("Failed %d tests!\n", error_count); + reboot_to_clean_up(CLEAN_UP_FLAG_FAILED); + } else { + reboot_to_clean_up(CLEAN_UP_FLAG_PASSED); + } +} + +int TaskTest(void *data) +{ + uint32_t state = system_get_scratchpad(); + + if (state & TEST_STATE_PASSED) + ccprintf("Pass!\n"); - /* Never reaches here */ + if (state & TEST_STATE_STEP_2) + run_test_step2(); + else if (state & TEST_STATE_STEP_3) + run_test_step3(); + else if (state & TEST_STATE_CLEAN_UP) + clean_up(); + + return EC_SUCCESS; +} + +static int command_run_test(int argc, char **argv) +{ + run_test_step1(); /* Never returns */ return EC_ERROR_UNKNOWN; } DECLARE_CONSOLE_COMMAND(runtest, command_run_test, diff --git a/test/flash.tasklist b/test/flash.tasklist index 26cfc53453..98ba7a6c83 100644 --- a/test/flash.tasklist +++ b/test/flash.tasklist @@ -14,4 +14,5 @@ * 'd' in an opaque parameter passed to the routine at startup * 's' is the stack size in bytes; must be a multiple of 8 */ -#define CONFIG_TEST_TASK_LIST /* No test task */ +#define CONFIG_TEST_TASK_LIST \ + TASK_TEST(TEST, TaskTest, NULL, TASK_STACK_SIZE) |