summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hughes <tomhughes@chromium.org>2020-05-08 11:42:37 -0700
committerCommit Bot <commit-bot@chromium.org>2020-05-13 03:03:54 +0000
commit0b034696389e0c6a9aa8b1397a49cf8548ccee05 (patch)
tree523c81aacf058fa7e40f0c2aee07881bb79e1f88
parent287478e7db8bd5a21a0c257574b4461e3518163f (diff)
downloadchrome-ec-0b034696389e0c6a9aa8b1397a49cf8548ccee05.tar.gz
test: Add rollback unit test
This test only runs on device and requires manual verification that a memory access violation occurred. Note that bloonchipper region 1 on dragonclaw fails as indicated in tests below. BRANCH=none BUG=b:155229277, b:151105339 TEST=Compile and flash bloonchipper on dragonclaw with region 0 "runtest" on console => Reboots with "Data access violation, mfar = 8020000" => PASS TEST=Compile and flash bloonchipper on dragonclaw with region 1 "runtest" on console => Memory is successfully read => FAIL TEST=Compile and flash dartmonkey on dragontalon with region 0 "runtest" on console => Reboots with "Data access violation, mfar = 80c0000" => PASS TEST=Compile and flash dartmonkey on dragontalon with region 1 "runtest" on console => Reboots with "Data access violation, mfar = 80e0000" => PASS Signed-off-by: Tom Hughes <tomhughes@chromium.org> Change-Id: I3e9cc568a0b16c6091d96c4373798fe4de4ab65b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2190829 Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> Commit-Queue: Nicolas Boichat <drinkcat@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/rollback.c121
-rw-r--r--test/rollback.tasklist9
7 files changed, 135 insertions, 0 deletions
diff --git a/board/hatch_fp/build.mk b/board/hatch_fp/build.mk
index 4ba4410e27..a7d717fc7d 100644
--- a/board/hatch_fp/build.mk
+++ b/board/hatch_fp/build.mk
@@ -17,6 +17,7 @@ test-list-y=\
crc32 \
mutex \
pingpong \
+ rollback \
rtc \
sha256 \
sha256_unrolled \
diff --git a/board/nocturne_fp/build.mk b/board/nocturne_fp/build.mk
index 8bb7855fcd..9c053ec31b 100644
--- a/board/nocturne_fp/build.mk
+++ b/board/nocturne_fp/build.mk
@@ -18,6 +18,7 @@ test-list-y=\
crc32 \
mutex \
pingpong \
+ rollback \
rtc \
sha256 \
sha256_unrolled \
diff --git a/board/nucleo-f412zg/build.mk b/board/nucleo-f412zg/build.mk
index 9b2f59c7d9..923acd1b23 100644
--- a/board/nucleo-f412zg/build.mk
+++ b/board/nucleo-f412zg/build.mk
@@ -15,6 +15,7 @@ test-list-y=\
crc32 \
mutex \
pingpong \
+ rollback \
rtc \
sha256 \
sha256_unrolled \
diff --git a/board/nucleo-h743zi/build.mk b/board/nucleo-h743zi/build.mk
index bdf068d328..c3d098e811 100644
--- a/board/nucleo-h743zi/build.mk
+++ b/board/nucleo-h743zi/build.mk
@@ -15,6 +15,7 @@ test-list-y=\
crc32 \
mutex \
pingpong \
+ rollback \
rtc \
sha256 \
sha256_unrolled \
diff --git a/test/build.mk b/test/build.mk
index 850b48c4cf..58094802cd 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -157,6 +157,7 @@ power_button-y=power_button.o
powerdemo-y=powerdemo.o
printf-y=printf.o
queue-y=queue.o
+rollback-y=rollback.o
rsa-y=rsa.o
rsa3-y=rsa.o
rtc-y=rtc.o
diff --git a/test/rollback.c b/test/rollback.c
new file mode 100644
index 0000000000..cd74f4e367
--- /dev/null
+++ b/test/rollback.c
@@ -0,0 +1,121 @@
+/* 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 <stdbool.h>
+#include "flash.h"
+#include "mpu.h"
+#include "test_util.h"
+
+struct rollback_info {
+ int region_0_offset;
+ int region_1_offset;
+ uint32_t region_size_bytes;
+};
+
+/* These values are intentionally hardcoded here instead of using the chip
+ * config headers, so that if the headers are accidentally changed we can catch
+ * it.
+ */
+#if defined(CHIP_VARIANT_STM32F412)
+struct rollback_info rollback_info = {
+ .region_0_offset = 0x20000,
+ .region_1_offset = 0x40000,
+ .region_size_bytes = 128 * 1024,
+};
+#elif defined(CHIP_VARIANT_STM32H7X3)
+struct rollback_info rollback_info = {
+ .region_0_offset = 0xC0000,
+ .region_1_offset = 0xE0000,
+ .region_size_bytes = 128 * 1024,
+};
+#else
+#error "Rollback info not defined for this chip. Please add it."
+#endif
+
+test_static int read_rollback_region(const struct rollback_info *info,
+ int region)
+{
+ int i;
+ char data;
+ uint32_t bytes_read = 0;
+
+ int offset = region == 0 ? info->region_0_offset :
+ info->region_1_offset;
+
+ for (i = 0; i < info->region_size_bytes; i++) {
+ if (flash_read(offset + i, sizeof(data), &data) == EC_SUCCESS)
+ bytes_read++;
+ }
+
+ return bytes_read;
+}
+
+test_static int _test_lock_rollback(const struct rollback_info *info,
+ int region)
+{
+ int rv;
+
+ mpu_enable();
+
+ rv = mpu_lock_rollback(0);
+ TEST_EQ(rv, EC_SUCCESS, "%d");
+
+ /* unlocked we should be able to read both regions */
+ rv = read_rollback_region(info, 0);
+ TEST_EQ(rv, rollback_info.region_size_bytes, "%d");
+
+ rv = read_rollback_region(info, 1);
+ TEST_EQ(rv, rollback_info.region_size_bytes, "%d");
+
+ rv = mpu_lock_rollback(1);
+ TEST_EQ(rv, EC_SUCCESS, "%d");
+
+ /* TODO(b/156112448): Validate that it actually reboots with the correct
+ * data access violation.
+ */
+ read_rollback_region(info, region);
+
+ /* Should not get here. Should reboot with:
+ *
+ * Data access violation, mfar = XXX
+ *
+ * where XXX = start of rollback
+ */
+ TEST_ASSERT(false);
+
+ return EC_ERROR_UNKNOWN;
+}
+
+test_static int test_lock_rollback_region_0(void)
+{
+ return _test_lock_rollback(&rollback_info, 0);
+}
+
+test_static int test_lock_rollback_region_1(void)
+{
+ return _test_lock_rollback(&rollback_info, 1);
+}
+
+test_static int test_lock_rollback(void)
+{
+ /* This call should never return due to panic.
+ * TODO(b/156112448): For now you have to manually test each region
+ * by itself.
+ */
+ test_lock_rollback_region_0();
+
+#if 0
+ test_lock_rollback_region_1();
+#endif
+
+ return EC_ERROR_UNKNOWN;
+}
+
+void run_test(void)
+{
+ ccprintf("Running rollback test\n");
+ RUN_TEST(test_lock_rollback);
+ test_print_result();
+}
diff --git a/test/rollback.tasklist b/test/rollback.tasklist
new file mode 100644
index 0000000000..51734f058d
--- /dev/null
+++ b/test/rollback.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 */