Correct flash_ctrl_data_erase_verify parameter.

Need the base address of the flash memory, not the controller registers.
Requires plumbing through the bootstrap api's.

Bug: 362960646

Bypass-Presubmit-Reason: passes on manual retry

Change-Id: I8ee4cd7c8d1d13b30a8210a09b722bcb1652db21
diff --git a/sw/device/lib/testing/test_rom/test_rom.c b/sw/device/lib/testing/test_rom/test_rom.c
index 1149a56..4dc5360 100644
--- a/sw/device/lib/testing/test_rom/test_rom.c
+++ b/sw/device/lib/testing/test_rom/test_rom.c
@@ -200,8 +200,10 @@
     LOG_INFO("Boot strap requested");
 
     const uintptr_t flash_ctrl_addr = TOP_EARLGREY_FLASH_CTRL_CORE_BASE_ADDR;
+    const uintptr_t flash_mem_addr = TOP_EARLGREY_FLASH_CTRL_MEM_BASE_ADDR;
     const uintptr_t spi_device_addr = TOP_EARLGREY_SPI_DEVICE_BASE_ADDR;
-    rom_error_t bootstrap_err = bootstrap(flash_ctrl_addr, spi_device_addr, otp_addr, gpio_addr);
+    rom_error_t bootstrap_err = bootstrap(flash_ctrl_addr, flash_mem_addr,
+                                          spi_device_addr, otp_addr, gpio_addr);
     if (bootstrap_err != kErrorOk) {
       LOG_ERROR("Bootstrap failed with status code: %08x",
                 (uint32_t)bootstrap_err);
diff --git a/sw/device/silicon_creator/lib/drivers/mock_flash_ctrl.cc b/sw/device/silicon_creator/lib/drivers/mock_flash_ctrl.cc
index 6af61ff..1b101ec 100644
--- a/sw/device/silicon_creator/lib/drivers/mock_flash_ctrl.cc
+++ b/sw/device/silicon_creator/lib/drivers/mock_flash_ctrl.cc
@@ -44,7 +44,7 @@
   return MockFlashCtrl::Instance().DataErase(addr, erase_type);
 }
 
-rom_error_t flash_ctrl_data_erase_verify(uintptr_t base_addr, uint32_t addr,
+rom_error_t flash_ctrl_data_erase_verify(uintptr_t mem_base_addr, uint32_t addr,
                                          flash_ctrl_erase_type_t erase_type) {
   return MockFlashCtrl::Instance().DataEraseVerify(addr, erase_type);
 }
diff --git a/sw/device/silicon_creator/rom/bootstrap.c b/sw/device/silicon_creator/rom/bootstrap.c
index 4f4ec7c..aa56f96 100644
--- a/sw/device/silicon_creator/rom/bootstrap.c
+++ b/sw/device/silicon_creator/rom/bootstrap.c
@@ -260,11 +260,13 @@
  * @param state Bootstrap state.
  * @return Result of the operation.
  */
-static rom_error_t bootstrap_handle_erase_verify(uintptr_t flash_ctrl_addr, uintptr_t spi_device_addr, bootstrap_state_t *state) {
+static rom_error_t bootstrap_handle_erase_verify(uintptr_t flash_mem_addr,
+                                                 uintptr_t spi_device_addr,
+                                                 bootstrap_state_t *state) {
   HARDENED_CHECK_EQ(*state, kBootstrapStateEraseVerify);
 
-  rom_error_t err_0 = flash_ctrl_data_erase_verify(flash_ctrl_addr, 0, kFlashCtrlEraseTypeBank);
-  rom_error_t err_1 = flash_ctrl_data_erase_verify(flash_ctrl_addr,
+  rom_error_t err_0 = flash_ctrl_data_erase_verify(flash_mem_addr, 0, kFlashCtrlEraseTypeBank);
+  rom_error_t err_1 = flash_ctrl_data_erase_verify(flash_mem_addr,
       FLASH_CTRL_PARAM_BYTES_PER_BANK, kFlashCtrlEraseTypeBank);
   HARDENED_RETURN_IF_ERROR(err_0);
   HARDENED_RETURN_IF_ERROR(err_1);
@@ -356,6 +358,7 @@
 
 // NB: assumes flash_ctrl_init is already called
 rom_error_t bootstrap(uintptr_t flash_ctrl_addr,
+                      uintptr_t flash_mem_addr,
                       uintptr_t spi_device_addr,
                       uintptr_t otp_addr,
                       uintptr_t gpio_addr) {
@@ -378,7 +381,7 @@
         break;
       case kBootstrapStateEraseVerify:
         HARDENED_CHECK_EQ(state, kBootstrapStateEraseVerify);
-        error = bootstrap_handle_erase_verify(flash_ctrl_addr, spi_device_addr, &state);
+        error = bootstrap_handle_erase_verify(flash_mem_addr, spi_device_addr, &state);
         break;
       case kBootstrapStateProgram:
         HARDENED_CHECK_EQ(state, kBootstrapStateProgram);
diff --git a/sw/device/silicon_creator/rom/bootstrap.h b/sw/device/silicon_creator/rom/bootstrap.h
index ee9f8cb..f44cf4f 100644
--- a/sw/device/silicon_creator/rom/bootstrap.h
+++ b/sw/device/silicon_creator/rom/bootstrap.h
@@ -38,12 +38,15 @@
  * This function only returns on error since a successful bootstrap ends with a
  * chip reset.
  *
+ * @param flash_ctrl_addr The base address of the flash controller registers.
+ * @param flash_mem_addr The base address of the flash memory.
+ * @param spi_device_addr The base address of the SPI device registers.
  * @param otp_addr The base address of the OTP memory.
  * @param gpio_addr The base address of the GPIO registers.
- * @param spi_device_addr The base address of the SPI device registers.
  * @return Result of the operation.
  */
 rom_error_t bootstrap(uintptr_t flash_ctrl_addr,
+                      uintptr_t flash_mem_addr,
                       uintptr_t spi_device_addr,
                       uintptr_t otp_addr,
                       uintptr_t gpio_addr);
diff --git a/sw/device/silicon_creator/rom/bootstrap_unittest.cc b/sw/device/silicon_creator/rom/bootstrap_unittest.cc
index 3c00a62..1d014ca 100644
--- a/sw/device/silicon_creator/rom/bootstrap_unittest.cc
+++ b/sw/device/silicon_creator/rom/bootstrap_unittest.cc
@@ -33,6 +33,7 @@
     kBaseSpiDevice = TOP_EARLGREY_SPI_DEVICE_BASE_ADDR,
     kBaseGpio = TOP_EARLGREY_GPIO_BASE_ADDR,
     kBaseFlashCtrl = TOP_EARLGREY_FLASH_CTRL_CORE_BASE_ADDR,
+    kBaseFlashMem = TOP_EARLGREY_FLASH_CTRL_MEM_BASE_ADDR,
 };
 
 using ::testing::_;
@@ -158,6 +159,7 @@
   }
 
   const uintptr_t flash_ctrl_addr_ = kBaseFlashCtrl;
+  const uintptr_t flash_mem_addr_ = kBaseFlashMem;
   const uintptr_t spi_device_addr_ = kBaseSpiDevice;
   const uintptr_t gpio_addr_ = kBaseGpio;
   const uintptr_t otp_addr_ = kBaseOtp;
@@ -254,7 +256,7 @@
   EXPECT_CALL(spi_device_, CmdGet(NotNull()))
       .WillOnce(Return(kErrorSpiDevicePayloadOverflow));
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorSpiDevicePayloadOverflow);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorSpiDevicePayloadOverflow);
 }
 
 TEST_F(BootstrapTest, PayloadOverflowProgram) {
@@ -271,7 +273,7 @@
   EXPECT_CALL(spi_device_, CmdGet(NotNull()))
       .WillOnce(Return(kErrorSpiDevicePayloadOverflow));
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorSpiDevicePayloadOverflow);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorSpiDevicePayloadOverflow);
 }
 
 TEST_F(BootstrapTest, BootstrapSimple) {
@@ -302,7 +304,7 @@
   ExpectSpiCmd(ResetCmd());
   EXPECT_CALL(rstmgr_, Reset());
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, BootstrapOddPayload) {
@@ -336,7 +338,7 @@
   ExpectSpiCmd(ResetCmd());
   EXPECT_CALL(rstmgr_, Reset());
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, BootstrapMisalignedAddrLongPayload) {
@@ -370,7 +372,7 @@
   ExpectSpiCmd(ResetCmd());
   EXPECT_CALL(rstmgr_, Reset());
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, BootstrapMisalignedAddrShortPayload) {
@@ -401,7 +403,7 @@
   ExpectSpiCmd(ResetCmd());
   EXPECT_CALL(rstmgr_, Reset());
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, BootstrapStartWithSectorErase) {
@@ -434,7 +436,7 @@
   ExpectSpiCmd(ResetCmd());
   EXPECT_CALL(rstmgr_, Reset());
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, BootstrapProgramWithErase) {
@@ -478,7 +480,7 @@
   ExpectSpiCmd(ResetCmd());
   EXPECT_CALL(rstmgr_, Reset());
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, MisalignedEraseAddress) {
@@ -510,7 +512,7 @@
   ExpectSpiCmd(ResetCmd());
   EXPECT_CALL(rstmgr_, Reset());
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, IgnoredCommands) {
@@ -539,7 +541,7 @@
   ExpectSpiCmd(ResetCmd());
   EXPECT_CALL(rstmgr_, Reset());
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, EraseBank0Error) {
@@ -549,7 +551,7 @@
   ExpectSpiFlashStatusGet(true);
   ExpectFlashCtrlChipErase(kErrorUnknown, kErrorOk);
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, EraseBank1Error) {
@@ -559,7 +561,7 @@
   ExpectSpiFlashStatusGet(true);
   ExpectFlashCtrlChipErase(kErrorOk, kErrorUnknown);
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, EraseVerifyBank0Error) {
@@ -572,7 +574,7 @@
   // Verify
   ExpectFlashCtrlEraseVerify(kErrorUnknown, kErrorOk);
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, EraseVerifyBank1Error) {
@@ -585,7 +587,7 @@
   // Verify
   ExpectFlashCtrlEraseVerify(kErrorOk, kErrorUnknown);
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, DataWriteError) {
@@ -613,7 +615,7 @@
       .WillOnce(Return(kErrorUnknown));
   ExpectFlashCtrlAllDisable();
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, DataWriteErrorMisalignedAddr) {
@@ -639,7 +641,7 @@
       .WillOnce(Return(kErrorUnknown));
   ExpectFlashCtrlAllDisable();
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorUnknown);
 }
 
 TEST_F(BootstrapTest, BadProgramAddress) {
@@ -657,7 +659,7 @@
   ExpectSpiCmd(page_program_cmd);
   ExpectSpiFlashStatusGet(true);
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorBootstrapProgramAddress);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorBootstrapProgramAddress);
 }
 
 TEST_F(BootstrapTest, BadEraseAddress) {
@@ -675,13 +677,13 @@
                               FLASH_CTRL_PARAM_REG_NUM_BANKS));
   ExpectSpiFlashStatusGet(true);
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorBootstrapEraseAddress);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorBootstrapEraseAddress);
 }
 
 TEST_F(BootstrapTest, NotRequested) {
   ExpectBootstrapRequestCheck(false);
 
-  EXPECT_EQ(bootstrap(flash_ctrl_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorBootstrapNotRequested);
+  EXPECT_EQ(bootstrap(flash_ctrl_addr_, flash_mem_addr_, spi_device_addr_, otp_addr_, gpio_addr_), kErrorBootstrapNotRequested);
 }
 
 }  // namespace