summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2020-05-18 14:49:43 -0700
committerCommit Bot <commit-bot@chromium.org>2020-05-30 05:16:45 +0000
commit5a2c16ee17339b96eef8351157673253738b461b (patch)
tree20c58304edca68e7ef2edda3b43bec402d49d725
parenta832f50a83e6d897cf22f306b4e01da4ee40fe4e (diff)
downloadchrome-ec-5a2c16ee17339b96eef8351157673253738b461b.tar.gz
test: Add test for flash write protection
This test demonstrates the inconsistency between STM32H743 (dartmonkey) and STM32F412 (bloonchipper). BRANCH=none BUG=b:155897971 TEST=On bloonchipper after flashing flash_write_protect.bin test: * Enable HW WP: dut-control fw_wp_en:on * Reboot to RO: reboot ro * Enable flash protection: runtest 1 => PASS * Reboot to RO: reboot ro * Try to disable flash protection: runtest 2 => FAIL TEST=On dartmonkey after flashing flash_write_protect.bin test: * Enable HW WP: dut-control fw_wp_en:on * Reboot to RO: reboot ro * Enable flash protection: runtest 1 => PASS * Reboot to RO: reboot ro * Try to disable flash protection: runtest 2 => PASS Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I6eb69257f84f79a6609984efbdad7dd37803c8f6 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2209419 Commit-Queue: Yicheng Li <yichengli@chromium.org> Tested-by: Yicheng Li <yichengli@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r--board/hatch_fp/build.mk1
-rw-r--r--board/nocturne_fp/build.mk1
-rw-r--r--board/nucleo-f412zg/build.mk1
-rw-r--r--board/nucleo-h743zi/build.mk1
-rw-r--r--test/build.mk1
-rw-r--r--test/flash_write_protect.c80
-rw-r--r--test/flash_write_protect.tasklist9
7 files changed, 94 insertions, 0 deletions
diff --git a/board/hatch_fp/build.mk b/board/hatch_fp/build.mk
index eb5b8906c1..d2dc627789 100644
--- a/board/hatch_fp/build.mk
+++ b/board/hatch_fp/build.mk
@@ -16,6 +16,7 @@ test-list-y=\
compile_time_macros \
crc32 \
flash_physical \
+ flash_write_protect \
mpu \
mutex \
pingpong \
diff --git a/board/nocturne_fp/build.mk b/board/nocturne_fp/build.mk
index b1ea0d27a2..a5a3f9d417 100644
--- a/board/nocturne_fp/build.mk
+++ b/board/nocturne_fp/build.mk
@@ -17,6 +17,7 @@ test-list-y=\
compile_time_macros \
crc32 \
flash_physical \
+ flash_write_protect \
mpu \
mutex \
pingpong \
diff --git a/board/nucleo-f412zg/build.mk b/board/nucleo-f412zg/build.mk
index ed320938b0..e3923e4b91 100644
--- a/board/nucleo-f412zg/build.mk
+++ b/board/nucleo-f412zg/build.mk
@@ -14,6 +14,7 @@ test-list-y=\
compile_time_macros \
crc32 \
flash_physical \
+ flash_write_protect \
mpu \
mutex \
pingpong \
diff --git a/board/nucleo-h743zi/build.mk b/board/nucleo-h743zi/build.mk
index dae28a73a4..0583db6260 100644
--- a/board/nucleo-h743zi/build.mk
+++ b/board/nucleo-h743zi/build.mk
@@ -14,6 +14,7 @@ test-list-y=\
compile_time_macros \
crc32 \
flash_physical \
+ flash_write_protect \
mpu \
mutex \
pingpong \
diff --git a/test/build.mk b/test/build.mk
index af5ed3355e..8db465dedc 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -129,6 +129,7 @@ extpwr_gpio-y=extpwr_gpio.o
fan-y=fan.o
flash-y=flash.o
flash_physical-y=flash_physical.o
+flash_write_protect-y=flash_write_protect.o
fpsensor-y=fpsensor.o
fpsensor_crypto-y=fpsensor_crypto.o
fpsensor_state-y=fpsensor_state.o
diff --git a/test/flash_write_protect.c b/test/flash_write_protect.c
new file mode 100644
index 0000000000..a75188e1cb
--- /dev/null
+++ b/test/flash_write_protect.c
@@ -0,0 +1,80 @@
+/* Copyright 2020 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.
+ */
+
+#include "flash.h"
+#include "gpio.h"
+#include "string.h"
+#include "system.h"
+#include "test_util.h"
+
+test_static int check_image_and_hardware_write_protect(void)
+{
+ if (system_get_image_copy() != EC_IMAGE_RO) {
+ ccprintf("This test is only works when running RO\n");
+ return EC_ERROR_UNKNOWN;
+ }
+
+ if (gpio_get_level(GPIO_WP) != 1) {
+ ccprintf("Hardware write protect (GPIO_WP) must be enabled\n");
+ return EC_ERROR_UNKNOWN;
+ }
+
+ return EC_SUCCESS;
+}
+
+test_static int test_flash_write_protect_enable(void)
+{
+ int rv;
+
+ 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);
+
+ return rv;
+}
+
+test_static int test_flash_write_protect_disable(void)
+{
+ int rv;
+
+ 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);
+ TEST_NE(rv, EC_SUCCESS, "%d");
+
+ return EC_SUCCESS;
+}
+
+test_static void run_test_step1(void)
+{
+ ccprintf("Step 1: Flash write protect test\n");
+ RUN_TEST(test_flash_write_protect_enable);
+}
+
+test_static void run_test_step2(void)
+{
+ ccprintf("Step 2: Flash write protect test\n");
+ RUN_TEST(test_flash_write_protect_disable);
+}
+
+void run_test(int argc, char **argv)
+{
+ if (argc < 2) {
+ ccprintf("usage: runtest <test_step_number>\n");
+ return;
+ }
+
+ /*
+ * TODO(157059753): replace with test_run_multistep when scratchpad
+ * works.
+ */
+ if (strncmp(argv[1], "1", 1) == 0)
+ run_test_step1();
+ else if (strncmp(argv[1], "2", 1) == 0)
+ run_test_step2();
+}
diff --git a/test/flash_write_protect.tasklist b/test/flash_write_protect.tasklist
new file mode 100644
index 0000000000..51734f058d
--- /dev/null
+++ b/test/flash_write_protect.tasklist
@@ -0,0 +1,9 @@
+/* Copyright 2020 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.
+ */
+
+/**
+ * See CONFIG_TASK_LIST in config.h for details.
+ */
+#define CONFIG_TEST_TASK_LIST /* no tasks */