diff --git a/sw/device/tests/flash_ctrl_idle_low_power_test.c b/sw/device/tests/flash_ctrl_idle_low_power_test.c index 0b74469bd9a77..c3ba21d06bc6d 100644 --- a/sw/device/tests/flash_ctrl_idle_low_power_test.c +++ b/sw/device/tests/flash_ctrl_idle_low_power_test.c @@ -22,7 +22,7 @@ #include "sw/device/lib/testing/autogen/isr_testutils.h" OTTF_DEFINE_TEST_CONFIG(); - +static uint32_t flash_region_index; static dif_rv_plic_t plic; static dif_aon_timer_t aon; static dif_rv_core_ibex_t rv_core_ibex; @@ -43,7 +43,8 @@ static top_earlgrey_plic_peripheral_t peripheral_serviced; static dif_aon_timer_irq_t irq_serviced; enum { - kFlashDataRegion = 2, // The ROM_EXT protects itself using regions 0-1. + // kFlashDataRegion = 7, // The ROM_EXT protects itself using regions 0-1. + kFlashCtrlParamNumRegions = 7, kRegionBasePageIndex = 256 + 32, // First non-ROM_EXT page in bank 1 (avoids program code.) kPartitionId = 0, @@ -126,8 +127,24 @@ bool test_main(void) { rstmgr_reset_info = rstmgr_testutils_reason_get(); uint32_t address = 0; + + for (uint32_t region = 0; region < kFlashCtrlParamNumRegions + 1; region++) { + bool locked; + LOG_INFO("Testing REGION 0x%x", region); + CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash, region, &locked)); + if (!locked) { + // We can use this region + flash_region_index = region; + LOG_INFO("This region is unlocked REGION 0x%x", region); + break; + } + } + + // CHECK_STATUS_OK(flash_ctrl_testutils_data_region_setup( + // &flash, kRegionBasePageIndex, kFlashDataRegion, kRegionSize, &address)); + CHECK_STATUS_OK(flash_ctrl_testutils_data_region_setup( - &flash, kRegionBasePageIndex, kFlashDataRegion, kRegionSize, &address)); + &flash, kRegionBasePageIndex, flash_region_index, kRegionSize, &address)); if (rstmgr_reset_info == kDifRstmgrResetInfoPor) { // Create data. Random data will be different than diff --git a/sw/device/tests/flash_ctrl_ops_test.c b/sw/device/tests/flash_ctrl_ops_test.c index d421aa0ccc1aa..9e2511a90f414 100644 --- a/sw/device/tests/flash_ctrl_ops_test.c +++ b/sw/device/tests/flash_ctrl_ops_test.c @@ -70,6 +70,7 @@ enum { kPageSize = 2048, }; +const uint32_t FLASH_CTRL_PARAM_NUM_REGIONS = 7; const uint32_t kRandomData1[kInfoSize] = { 0xb295d21b, 0xecdfbdcd, 0x67e7ab2d, 0x6f660b08, 0x273bf65c, 0xe80f1695, 0x586b80db, 0xc3dba27e, 0xdc124c5d, 0xb01ccd52, 0x815713e1, 0x31a141b2, @@ -310,6 +311,18 @@ static void do_bank1_data_partition_test(void) { (i == 0) ? flash_bank_1_page_index : flash_bank_1_page_index_scr; const uint32_t *test_data = (i == 0) ? kRandomData4 : kRandomData5; + for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) { + bool locked; + // CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash_state, + // flash_bank_1_data_region, &locked)); + CHECK_DIF_OK( + dif_flash_ctrl_data_region_is_locked(&flash_state, region, &locked)); + if (!locked) { + flash_bank_1_data_region = region; + LOG_INFO("This region is unlocked REGION 0x%x", region); + break; + } + } if (i == 0) { // Set region1 for non-scrambled ecc enabled. CHECK_STATUS_OK(flash_ctrl_testutils_data_region_setup( @@ -423,16 +436,29 @@ static void do_bank1_data_partition_test(void) { bool test_main(void) { flash_info = dif_flash_ctrl_get_device_info(); + // for(uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS+1; region++) + // { + // bool locked; + // LOG_INFO("Testing REGION 0x%x" ,region); + // CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash, region, + // &locked)); if(!locked) { We can use this region + // flash_region_index = region; + // LOG_INFO("This region is unlocked REGION 0x%x" ,region); + // } + // break; + // } + // Determine the region index and page index to use for tests. // Test data page used for flash bank 1 should be the lowest and highest // usable page. if (kBootStage != kBootStageOwner) { flash_bank_0_data_region = 0; flash_bank_1_page_index = flash_info.data_pages; + LOG_INFO("Running as owner"); } else { // If we boot up in owner stage, the first 2 regions will be used by // ROM_EXT. - flash_bank_0_data_region = 2; + flash_bank_0_data_region = 3; // First 0x20 pages are configured by ROM_EXT. To avoid conflicts, skip over // these pages. flash_bank_1_page_index = flash_info.data_pages + 0x20; @@ -460,7 +486,9 @@ bool test_main(void) { do_info_partition_test(kFlashInfoPageIdOwnerSecret, kRandomData2); do_info_partition_test(kFlashInfoPageIdIsoPart, kRandomData3); do_bank0_data_partition_test(); + LOG_INFO("Running as not owner"); } + LOG_INFO(" Non -owner"); do_bank1_data_partition_test(); return true; diff --git a/sw/device/tests/flash_ctrl_write_clear_test.c b/sw/device/tests/flash_ctrl_write_clear_test.c index 558b0e2edeae6..c2e934888caad 100644 --- a/sw/device/tests/flash_ctrl_write_clear_test.c +++ b/sw/device/tests/flash_ctrl_write_clear_test.c @@ -22,6 +22,9 @@ OTTF_DEFINE_TEST_CONFIG(); +static uint32_t flash_region_index; +static uint32_t flash_page_to_test; + enum { // Some dif_flash_ctrl functions don't require the partition parameter when // interacting with data partitions. This constant is added to improve @@ -40,7 +43,7 @@ enum { kBank1StartPageNum = 256 + kRomExtPageCount, // The ROM_EXT protects itself using regions 0-1. - kFlashRegionNum = 2, + kFlashRegionNum = 3, }; @@ -105,6 +108,29 @@ bool test_main(void) { CHECK_DIF_OK(dif_flash_ctrl_init_state( &flash, mmio_region_from_addr(TOP_EARLGREY_FLASH_CTRL_CORE_BASE_ADDR))); + flash_region_index = 0; + flash_page_to_test = 0; + for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) { + bool locked; + LOG_INFO("Testing REGION 0x%x", region); + CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash, region, &locked)); + if (!locked) { + // We can use this region + flash_region_index = region; + LOG_INFO("This region is unlocked REGION 0x%x", region); + break; + } + dif_flash_ctrl_data_region_properties_t cfg; + CHECK_DIF_OK( + dif_flash_ctrl_get_data_region_properties(&flash, region, &cfg)); + // Avoid this region + if (cfg.size > 0) { + flash_page_to_test = MAX(flash_page_to_test, cfg.base + cfg.size); + } + } + + // kFlashRegionNum = flash_region_index; + // The ROM_EXT configures the default region access. We can't modify the // values after configured. if (kBootStage != kBootStageOwner) { @@ -114,7 +140,7 @@ bool test_main(void) { } LOG_INFO("ECC enabled with high endurance disabled."); - flash_ctrl_write_clear_test(/*mp_region_index=*/kFlashRegionNum, + flash_ctrl_write_clear_test(/*mp_region_index=*/flash_region_index, (dif_flash_ctrl_data_region_properties_t){ .base = kBank1StartPageNum, .size = 1, diff --git a/sw/device/tests/rv_core_ibex_mem_test.c b/sw/device/tests/rv_core_ibex_mem_test.c index c1e322ba13708..16ab31ff188cc 100644 --- a/sw/device/tests/rv_core_ibex_mem_test.c +++ b/sw/device/tests/rv_core_ibex_mem_test.c @@ -61,8 +61,9 @@ enum { kFlashTestLoc = TOP_EARLGREY_FLASH_CTRL_MEM_BASE_ADDR + kBank1StartPageNum * kFlashBytesPerPage, // The ROM_EXT protects itself using regions 0-1. - kFlashRegionNum = 2, + kFlashRegionNum = 5, }; +static uint32_t flash_region_index; // The flash test location is set to the encoding of `jalr x0, 0(x1)` // so execution can be tested. @@ -162,12 +163,33 @@ static void setup_flash(void) { .ecc_en = kMultiBitBool4False, .high_endurance_en = kMultiBitBool4False}; dif_flash_ctrl_data_region_properties_t data_region = { - .base = kBank1StartPageNum, .size = 0x1, .properties = region_properties}; + .base = kBank1StartPageNum, .size = 0x2, .properties = region_properties}; + + // Added RP - Check for unlocked region + for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) { + bool locked; + LOG_INFO("Testing REGION 0x%x", region); + CHECK_DIF_OK( + dif_flash_ctrl_data_region_is_locked(&flash_ctrl, region, &locked)); + if (!locked) { + // We can use this region + flash_region_index = region; + LOG_INFO("This region is unlocked REGION 0x%x", region); + break; + } + // dif_flash_ctrl_data_region_properties_t cfg; + // CHECK_DIF_OK(dif_flash_ctrl_get_data_region_properties(&flash, region, + // &cfg)); + // Avoid this region + // if(cfg.size > 0) { + // flash_page_to_test = MAX(flash_page_to_test, cfg.base + cfg.size); + } + // Check for unlocked region ends CHECK_DIF_OK(dif_flash_ctrl_set_data_region_properties( - &flash_ctrl, kFlashRegionNum, data_region)); + &flash_ctrl, flash_region_index, data_region)); CHECK_DIF_OK(dif_flash_ctrl_set_data_region_enablement( - &flash_ctrl, kFlashRegionNum, kDifToggleEnabled)); + &flash_ctrl, flash_region_index, kDifToggleEnabled)); // Make flash executable CHECK_DIF_OK(