[sw] update software for init polling
Signed-off-by: Timothy Chen <timothytim@google.com>
diff --git a/sw/device/boot_rom/boot_rom.c b/sw/device/boot_rom/boot_rom.c
index 3e3aef5..c4f4eea 100644
--- a/sw/device/boot_rom/boot_rom.c
+++ b/sw/device/boot_rom/boot_rom.c
@@ -8,6 +8,7 @@
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_gpio.h"
#include "sw/device/lib/dif/dif_uart.h"
+#include "sw/device/lib/flash_ctrl.h"
#include "sw/device/lib/pinmux.h"
#include "sw/device/lib/runtime/hart.h"
#include "sw/device/lib/runtime/log.h"
@@ -32,6 +33,9 @@
void _boot_start(void) {
test_status_set(kTestStatusInBootRom);
pinmux_init();
+ flash_init();
+ while (flash_get_init_status())
+ ;
CHECK(
dif_uart_init(
diff --git a/sw/device/lib/flash_ctrl.c b/sw/device/lib/flash_ctrl.c
index 7b34865..8c4c075 100644
--- a/sw/device/lib/flash_ctrl.c
+++ b/sw/device/lib/flash_ctrl.c
@@ -3,6 +3,8 @@
// SPDX-License-Identifier: Apache-2.0
#include "sw/device/lib/flash_ctrl.h"
+#include "sw/device/lib/base/mmio.h"
+
#include "flash_ctrl_regs.h" // Generated.
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
@@ -245,3 +247,14 @@
uint32_t flash_read_scratch_reg(void) {
return REG32(FLASH_CTRL0_BASE_ADDR + FLASH_CTRL_SCRATCH_REG_OFFSET);
}
+
+bool flash_get_init_status(void) {
+ mmio_region_t flash_base = mmio_region_from_addr(FLASH_CTRL0_BASE_ADDR);
+ return mmio_region_get_bit32(flash_base, FLASH_CTRL_STATUS_REG_OFFSET,
+ FLASH_CTRL_STATUS_INIT_WIP_BIT);
+}
+
+void flash_init(void) {
+ mmio_region_t flash_base = mmio_region_from_addr(FLASH_CTRL0_BASE_ADDR);
+ mmio_region_write32(flash_base, FLASH_CTRL_INIT_REG_OFFSET, 1);
+}
diff --git a/sw/device/lib/flash_ctrl.h b/sw/device/lib/flash_ctrl.h
index 33e3a95..93aa2a3 100644
--- a/sw/device/lib/flash_ctrl.h
+++ b/sw/device/lib/flash_ctrl.h
@@ -136,4 +136,10 @@
/** Read scratch register */
uint32_t flash_read_scratch_reg(void);
+/** Initialize flash controller */
+void flash_init(void);
+
+/** Get flash initialization status */
+bool flash_get_init_status(void);
+
#endif // OPENTITAN_SW_DEVICE_LIB_FLASH_CTRL_H_