Skip to content

Commit c2c578f

Browse files
committed
[sival/flash_ctrl] Modify flash_ctrl test scripts for checking read/write
This commit updates the flash_ctrl test files for read/write access before flash operations. Signed-off-by: Ramesh Prakash <[email protected]>
1 parent edb11ee commit c2c578f

File tree

4 files changed

+103
-10
lines changed

4 files changed

+103
-10
lines changed

sw/device/tests/flash_ctrl_idle_low_power_test.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "sw/device/lib/testing/autogen/isr_testutils.h"
2323

2424
OTTF_DEFINE_TEST_CONFIG();
25-
25+
static uint32_t flash_region_index;
2626
static dif_rv_plic_t plic;
2727
static dif_aon_timer_t aon;
2828
static dif_rv_core_ibex_t rv_core_ibex;
@@ -43,7 +43,8 @@ static top_earlgrey_plic_peripheral_t peripheral_serviced;
4343
static dif_aon_timer_irq_t irq_serviced;
4444

4545
enum {
46-
kFlashDataRegion = 2, // The ROM_EXT protects itself using regions 0-1.
46+
// kFlashDataRegion = 7, // The ROM_EXT protects itself using regions 0-1.
47+
kFlashCtrlParamNumRegions = 7,
4748
kRegionBasePageIndex =
4849
256 + 32, // First non-ROM_EXT page in bank 1 (avoids program code.)
4950
kPartitionId = 0,
@@ -126,8 +127,24 @@ bool test_main(void) {
126127
rstmgr_reset_info = rstmgr_testutils_reason_get();
127128

128129
uint32_t address = 0;
130+
131+
for (uint32_t region = 0; region < kFlashCtrlParamNumRegions + 1; region++) {
132+
bool locked;
133+
LOG_INFO("Testing REGION 0x%x", region);
134+
CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash, region, &locked));
135+
if (!locked) {
136+
// We can use this region
137+
flash_region_index = region;
138+
LOG_INFO("This region is unlocked REGION 0x%x", region);
139+
break;
140+
}
141+
}
142+
143+
// CHECK_STATUS_OK(flash_ctrl_testutils_data_region_setup(
144+
// &flash, kRegionBasePageIndex, kFlashDataRegion, kRegionSize, &address));
145+
129146
CHECK_STATUS_OK(flash_ctrl_testutils_data_region_setup(
130-
&flash, kRegionBasePageIndex, kFlashDataRegion, kRegionSize, &address));
147+
&flash, kRegionBasePageIndex, flash_region_index, kRegionSize, &address));
131148

132149
if (rstmgr_reset_info == kDifRstmgrResetInfoPor) {
133150
// Create data. Random data will be different than

sw/device/tests/flash_ctrl_ops_test.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ enum {
7070
kPageSize = 2048,
7171
};
7272

73+
const uint32_t FLASH_CTRL_PARAM_NUM_REGIONS = 7;
7374
const uint32_t kRandomData1[kInfoSize] = {
7475
0xb295d21b, 0xecdfbdcd, 0x67e7ab2d, 0x6f660b08, 0x273bf65c, 0xe80f1695,
7576
0x586b80db, 0xc3dba27e, 0xdc124c5d, 0xb01ccd52, 0x815713e1, 0x31a141b2,
@@ -310,6 +311,18 @@ static void do_bank1_data_partition_test(void) {
310311
(i == 0) ? flash_bank_1_page_index : flash_bank_1_page_index_scr;
311312
const uint32_t *test_data = (i == 0) ? kRandomData4 : kRandomData5;
312313

314+
for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) {
315+
bool locked;
316+
// CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash_state,
317+
// flash_bank_1_data_region, &locked));
318+
CHECK_DIF_OK(
319+
dif_flash_ctrl_data_region_is_locked(&flash_state, region, &locked));
320+
if (!locked) {
321+
flash_bank_1_data_region = region;
322+
LOG_INFO("This region is unlocked REGION 0x%x", region);
323+
break;
324+
}
325+
}
313326
if (i == 0) {
314327
// Set region1 for non-scrambled ecc enabled.
315328
CHECK_STATUS_OK(flash_ctrl_testutils_data_region_setup(
@@ -423,16 +436,29 @@ static void do_bank1_data_partition_test(void) {
423436
bool test_main(void) {
424437
flash_info = dif_flash_ctrl_get_device_info();
425438

439+
// for(uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS+1; region++)
440+
// {
441+
// bool locked;
442+
// LOG_INFO("Testing REGION 0x%x" ,region);
443+
// CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash, region,
444+
// &locked)); if(!locked) { We can use this region
445+
// flash_region_index = region;
446+
// LOG_INFO("This region is unlocked REGION 0x%x" ,region);
447+
// }
448+
// break;
449+
// }
450+
426451
// Determine the region index and page index to use for tests.
427452
// Test data page used for flash bank 1 should be the lowest and highest
428453
// usable page.
429454
if (kBootStage != kBootStageOwner) {
430455
flash_bank_0_data_region = 0;
431456
flash_bank_1_page_index = flash_info.data_pages;
457+
LOG_INFO("Running as owner");
432458
} else {
433459
// If we boot up in owner stage, the first 2 regions will be used by
434460
// ROM_EXT.
435-
flash_bank_0_data_region = 2;
461+
flash_bank_0_data_region = 3;
436462
// First 0x20 pages are configured by ROM_EXT. To avoid conflicts, skip over
437463
// these pages.
438464
flash_bank_1_page_index = flash_info.data_pages + 0x20;
@@ -460,7 +486,9 @@ bool test_main(void) {
460486
do_info_partition_test(kFlashInfoPageIdOwnerSecret, kRandomData2);
461487
do_info_partition_test(kFlashInfoPageIdIsoPart, kRandomData3);
462488
do_bank0_data_partition_test();
489+
LOG_INFO("Running as not owner");
463490
}
491+
LOG_INFO(" Non -owner");
464492
do_bank1_data_partition_test();
465493

466494
return true;

sw/device/tests/flash_ctrl_write_clear_test.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
OTTF_DEFINE_TEST_CONFIG();
2424

25+
static uint32_t flash_region_index;
26+
static uint32_t flash_page_to_test;
27+
2528
enum {
2629
// Some dif_flash_ctrl functions don't require the partition parameter when
2730
// interacting with data partitions. This constant is added to improve
@@ -40,7 +43,7 @@ enum {
4043
kBank1StartPageNum = 256 + kRomExtPageCount,
4144

4245
// The ROM_EXT protects itself using regions 0-1.
43-
kFlashRegionNum = 2,
46+
kFlashRegionNum = 3,
4447

4548
};
4649

@@ -105,6 +108,29 @@ bool test_main(void) {
105108
CHECK_DIF_OK(dif_flash_ctrl_init_state(
106109
&flash, mmio_region_from_addr(TOP_EARLGREY_FLASH_CTRL_CORE_BASE_ADDR)));
107110

111+
flash_region_index = 0;
112+
flash_page_to_test = 0;
113+
for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) {
114+
bool locked;
115+
LOG_INFO("Testing REGION 0x%x", region);
116+
CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash, region, &locked));
117+
if (!locked) {
118+
// We can use this region
119+
flash_region_index = region;
120+
LOG_INFO("This region is unlocked REGION 0x%x", region);
121+
break;
122+
}
123+
dif_flash_ctrl_data_region_properties_t cfg;
124+
CHECK_DIF_OK(
125+
dif_flash_ctrl_get_data_region_properties(&flash, region, &cfg));
126+
// Avoid this region
127+
if (cfg.size > 0) {
128+
flash_page_to_test = MAX(flash_page_to_test, cfg.base + cfg.size);
129+
}
130+
}
131+
132+
// kFlashRegionNum = flash_region_index;
133+
108134
// The ROM_EXT configures the default region access. We can't modify the
109135
// values after configured.
110136
if (kBootStage != kBootStageOwner) {
@@ -114,7 +140,7 @@ bool test_main(void) {
114140
}
115141

116142
LOG_INFO("ECC enabled with high endurance disabled.");
117-
flash_ctrl_write_clear_test(/*mp_region_index=*/kFlashRegionNum,
143+
flash_ctrl_write_clear_test(/*mp_region_index=*/flash_region_index,
118144
(dif_flash_ctrl_data_region_properties_t){
119145
.base = kBank1StartPageNum,
120146
.size = 1,

sw/device/tests/rv_core_ibex_mem_test.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ enum {
6161
kFlashTestLoc = TOP_EARLGREY_FLASH_CTRL_MEM_BASE_ADDR +
6262
kBank1StartPageNum * kFlashBytesPerPage,
6363
// The ROM_EXT protects itself using regions 0-1.
64-
kFlashRegionNum = 2,
64+
kFlashRegionNum = 5,
6565
};
66+
static uint32_t flash_region_index;
6667

6768
// The flash test location is set to the encoding of `jalr x0, 0(x1)`
6869
// so execution can be tested.
@@ -162,12 +163,33 @@ static void setup_flash(void) {
162163
.ecc_en = kMultiBitBool4False,
163164
.high_endurance_en = kMultiBitBool4False};
164165
dif_flash_ctrl_data_region_properties_t data_region = {
165-
.base = kBank1StartPageNum, .size = 0x1, .properties = region_properties};
166+
.base = kBank1StartPageNum, .size = 0x2, .properties = region_properties};
167+
168+
// Added RP - Check for unlocked region
169+
for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) {
170+
bool locked;
171+
LOG_INFO("Testing REGION 0x%x", region);
172+
CHECK_DIF_OK(
173+
dif_flash_ctrl_data_region_is_locked(&flash_ctrl, region, &locked));
174+
if (!locked) {
175+
// We can use this region
176+
flash_region_index = region;
177+
LOG_INFO("This region is unlocked REGION 0x%x", region);
178+
break;
179+
}
180+
// dif_flash_ctrl_data_region_properties_t cfg;
181+
// CHECK_DIF_OK(dif_flash_ctrl_get_data_region_properties(&flash, region,
182+
// &cfg));
183+
// Avoid this region
184+
// if(cfg.size > 0) {
185+
// flash_page_to_test = MAX(flash_page_to_test, cfg.base + cfg.size);
186+
}
187+
// Check for unlocked region ends
166188

167189
CHECK_DIF_OK(dif_flash_ctrl_set_data_region_properties(
168-
&flash_ctrl, kFlashRegionNum, data_region));
190+
&flash_ctrl, flash_region_index, data_region));
169191
CHECK_DIF_OK(dif_flash_ctrl_set_data_region_enablement(
170-
&flash_ctrl, kFlashRegionNum, kDifToggleEnabled));
192+
&flash_ctrl, flash_region_index, kDifToggleEnabled));
171193

172194
// Make flash executable
173195
CHECK_DIF_OK(

0 commit comments

Comments
 (0)