[test ROM] rewrite reset_info to reset_reason like the Mask ROM
This builds but should cause tests that examine reset_info to fail
Signed-off-by: Drew Macrae <drewmacrae@google.com>
diff --git a/sw/device/lib/testing/BUILD b/sw/device/lib/testing/BUILD
index acb05ec..ec512ce 100644
--- a/sw/device/lib/testing/BUILD
+++ b/sw/device/lib/testing/BUILD
@@ -226,6 +226,7 @@
deps = [
"//sw/device/lib/dif:rstmgr",
"//sw/device/lib/testing/test_framework:check",
+ "//sw/device/silicon_creator/lib/drivers:retention_sram",
],
)
diff --git a/sw/device/lib/testing/rstmgr_testutils.c b/sw/device/lib/testing/rstmgr_testutils.c
index f233b50..d95cfbb 100644
--- a/sw/device/lib/testing/rstmgr_testutils.c
+++ b/sw/device/lib/testing/rstmgr_testutils.c
@@ -10,6 +10,7 @@
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_rstmgr.h"
#include "sw/device/lib/testing/test_framework/check.h"
+#include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
bool rstmgr_testutils_is_reset_info(const dif_rstmgr_t *rstmgr,
dif_rstmgr_reset_info_bitfield_t info) {
@@ -81,3 +82,12 @@
rstmgr_testutils_compare_cpu_info(rstmgr, expected_cpu_dump, cpu_dump_size);
}
}
+
+void rstmgr_testutils_reset_reason(const dif_rstmgr_t *rstmgr,
+ dif_rstmgr_reset_info_bitfield_t *reason) {
+ *reason = retention_sram_get()->reset_reasons;
+}
+
+void rstmgr_testutils_reset_reason_clear(const dif_rstmgr_t *rstmgr) {
+ retention_sram_get()->reset_reasons = 0;
+}
diff --git a/sw/device/lib/testing/rstmgr_testutils.h b/sw/device/lib/testing/rstmgr_testutils.h
index 08a4466..6c0e5d9 100644
--- a/sw/device/lib/testing/rstmgr_testutils.h
+++ b/sw/device/lib/testing/rstmgr_testutils.h
@@ -93,4 +93,20 @@
dif_rstmgr_cpu_info_dump_segment_t *expected_cpu_dump,
size_t cpu_dump_size);
+/**
+ * Gets the reason for a reset in retention SRAM.
+ *
+ * @param rstmgr A reset manager handle
+ * @param reason pointer to write the reset_reason
+ */
+void rstmgr_testutils_reset_reason(const dif_rstmgr_t *handle,
+ dif_rstmgr_reset_info_bitfield_t *reason);
+
+/**
+ * Clears the reset information in Retention SRAM
+ *
+ * @param handle A Reset Manager handle.
+ */
+void rstmgr_testutils_reset_reason_clear(const dif_rstmgr_t *handle);
+
#endif // OPENTITAN_SW_DEVICE_LIB_TESTING_RSTMGR_TESTUTILS_H_
diff --git a/sw/device/lib/testing/test_rom/BUILD b/sw/device/lib/testing/test_rom/BUILD
index a2910a1..aaa8ab6 100644
--- a/sw/device/lib/testing/test_rom/BUILD
+++ b/sw/device/lib/testing/test_rom/BUILD
@@ -112,7 +112,6 @@
"//hw/ip/csrng/data:csrng_regs",
"//hw/ip/edn/data:edn_regs",
"//hw/ip/entropy_src/data:entropy_src_regs",
- "//hw/ip/otp_ctrl/data:otp_ctrl_regs",
"//hw/ip/sram_ctrl/data:sram_ctrl_regs",
"//hw/top_earlgrey/ip/ast/data:ast_regs",
"//hw/top_earlgrey/ip/sensor_ctrl/data:sensor_ctrl_regs",
@@ -134,6 +133,7 @@
"//sw/device/lib/testing:pinmux_testutils",
"//sw/device/lib/testing/test_framework:check",
"//sw/device/lib/testing/test_framework:status",
+ "//sw/device/silicon_creator/lib/drivers:retention_sram",
],
)
diff --git a/sw/device/lib/testing/test_rom/test_rom.c b/sw/device/lib/testing/test_rom/test_rom.c
index 7bc8468..9a63e2b 100644
--- a/sw/device/lib/testing/test_rom/test_rom.c
+++ b/sw/device/lib/testing/test_rom/test_rom.c
@@ -19,6 +19,8 @@
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/status.h"
#include "sw/device/lib/testing/test_rom/chip_info.h" // Generated.
+#include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
+#include "sw/device/silicon_creator/lib/drivers/rstmgr.h"
#include "sw/device/silicon_creator/lib/manifest.h"
#include "sw/device/silicon_creator/mask_rom/bootstrap.h"
@@ -80,6 +82,13 @@
// Print the chip version information
LOG_INFO("%s", chip_info);
+ // Skip sram_init for test_rom
+ uint32_t reset_reasons = rstmgr_reason_get();
+
+ // Store the reset reason in retention RAM and clear the register.
+ retention_sram_get()->reset_reasons = reset_reasons;
+ rstmgr_reason_clear(reset_reasons);
+
// Print the FPGA version-id.
// This is guaranteed to be zero on all non-FPGA implementations.
uint32_t fpga = fpga_version();
diff --git a/sw/device/tests/BUILD b/sw/device/tests/BUILD
index 7cfa908..f87c5fc 100644
--- a/sw/device/tests/BUILD
+++ b/sw/device/tests/BUILD
@@ -1042,6 +1042,7 @@
"//sw/device/lib/base:mmio",
"//sw/device/lib/dif:rstmgr",
"//sw/device/lib/runtime:log",
+ "//sw/device/lib/testing:rstmgr_testutils",
"//sw/device/lib/testing/test_framework:ottf_main",
],
)
diff --git a/sw/device/tests/rstmgr_sw_req_test.c b/sw/device/tests/rstmgr_sw_req_test.c
index 10a599f..1bc10ce 100644
--- a/sw/device/tests/rstmgr_sw_req_test.c
+++ b/sw/device/tests/rstmgr_sw_req_test.c
@@ -5,6 +5,7 @@
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_rstmgr.h"
#include "sw/device/lib/runtime/log.h"
+#include "sw/device/lib/testing/rstmgr_testutils.h"
#include "sw/device/lib/testing/test_framework/check.h"
#include "sw/device/lib/testing/test_framework/ottf_main.h"
@@ -18,20 +19,20 @@
CHECK_DIF_OK(dif_rstmgr_init(
mmio_region_from_addr(TOP_EARLGREY_RSTMGR_AON_BASE_ADDR), &rstmgr));
- dif_rstmgr_reset_info_bitfield_t info;
- CHECK_DIF_OK(dif_rstmgr_reset_info_get(&rstmgr, &info));
+ dif_rstmgr_reset_info_bitfield_t reason;
+ rstmgr_testutils_reset_reason(&rstmgr, &reason);
// If POR, clear reason and request software reset
- if (info & kDifRstmgrResetInfoPor) {
+ if (reason & kDifRstmgrResetInfoPor) {
LOG_INFO("POR encountered!");
- CHECK_DIF_OK(dif_rstmgr_reset_info_clear(&rstmgr));
+ rstmgr_testutils_reset_reason_clear(&rstmgr);
CHECK_DIF_OK(dif_rstmgr_software_device_reset(&rstmgr));
// wait here until device reset
wait_for_interrupt();
- } else if (info == kDifRstmgrResetInfoSw) {
+ } else if (reason == kDifRstmgrResetInfoSw) {
LOG_INFO("Software reset encountered!");
- CHECK_DIF_OK(dif_rstmgr_reset_info_clear(&rstmgr));
+ rstmgr_testutils_reset_reason_clear(&rstmgr);
} else {
LOG_FATAL("Reset reason unexpected!");
test_status_set(kTestStatusFailed);