Skip to content

Commit 85880e7

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 85880e7

File tree

4 files changed

+83
-29
lines changed

4 files changed

+83
-29
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,6 @@
2222
#include "sw/device/lib/testing/autogen/isr_testutils.h"
2323

2424
OTTF_DEFINE_TEST_CONFIG();
25-
2625
static dif_rv_plic_t plic;
2726
static dif_aon_timer_t aon;
2827
static dif_rv_core_ibex_t rv_core_ibex;
@@ -43,7 +42,7 @@ static top_earlgrey_plic_peripheral_t peripheral_serviced;
4342
static dif_aon_timer_irq_t irq_serviced;
4443

4544
enum {
46-
kFlashDataRegion = 2, // The ROM_EXT protects itself using regions 0-1.
45+
kFlashCtrlParamNumRegions = 8,
4746
kRegionBasePageIndex =
4847
256 + 32, // First non-ROM_EXT page in bank 1 (avoids program code.)
4948
kPartitionId = 0,
@@ -102,6 +101,8 @@ bool test_main(void) {
102101
dif_pwrmgr_t pwrmgr;
103102
dif_rstmgr_t rstmgr;
104103

104+
uint32_t flash_region_index = 0;
105+
105106
CHECK_DIF_OK(dif_rv_plic_init(
106107
mmio_region_from_addr(TOP_EARLGREY_RV_PLIC_BASE_ADDR), &plic));
107108
CHECK_DIF_OK(dif_flash_ctrl_init_state(
@@ -126,8 +127,24 @@ bool test_main(void) {
126127
rstmgr_reset_info = rstmgr_testutils_reason_get();
127128

128129
uint32_t address = 0;
130+
// Find the first unlocked flash region and use that for testing
131+
for (uint32_t region = 0; region < kFlashCtrlParamNumRegions; 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("Region %u is unlocked");
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 & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ enum {
6868
kInfoSize = 16,
6969
kDataSize = 32,
7070
kPageSize = 2048,
71+
FLASH_CTRL_PARAM_NUM_REGIONS = 8,
7172
};
7273

7374
const uint32_t kRandomData1[kInfoSize] = {
@@ -309,13 +310,35 @@ static void do_bank1_data_partition_test(void) {
309310
uint32_t page_index =
310311
(i == 0) ? flash_bank_1_page_index : flash_bank_1_page_index_scr;
311312
const uint32_t *test_data = (i == 0) ? kRandomData4 : kRandomData5;
312-
313+
// Find the first unlocked flash region and use that for testing
314+
for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) {
315+
bool locked;
316+
CHECK_DIF_OK(
317+
dif_flash_ctrl_data_region_is_locked(&flash_state, region, &locked));
318+
if (!locked) {
319+
flash_bank_1_data_region = region;
320+
LOG_INFO("Region %u is unlocked");
321+
break;
322+
}
323+
}
313324
if (i == 0) {
314325
// Set region1 for non-scrambled ecc enabled.
315326
CHECK_STATUS_OK(flash_ctrl_testutils_data_region_setup(
316327
&flash_state, page_index, flash_bank_1_data_region, kRegionSize,
317328
&address));
318329
} else {
330+
for (uint32_t region = flash_bank_1_data_region + 1;
331+
region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) {
332+
bool locked;
333+
CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash_state, region,
334+
&locked));
335+
if (!locked) {
336+
flash_bank_1_data_region_scr = region;
337+
LOG_INFO("Region %u is unlocked");
338+
break;
339+
}
340+
}
341+
319342
// Set region2 for scrambled ecc enabled.
320343
CHECK_STATUS_OK(flash_ctrl_testutils_data_region_scrambled_setup(
321344
&flash_state, page_index, flash_bank_1_data_region_scr, kRegionSize,
@@ -423,22 +446,12 @@ static void do_bank1_data_partition_test(void) {
423446
bool test_main(void) {
424447
flash_info = dif_flash_ctrl_get_device_info();
425448

426-
// Determine the region index and page index to use for tests.
427-
// Test data page used for flash bank 1 should be the lowest and highest
428-
// usable page.
429-
if (kBootStage != kBootStageOwner) {
430-
flash_bank_0_data_region = 0;
431-
flash_bank_1_page_index = flash_info.data_pages;
432-
} else {
433-
// If we boot up in owner stage, the first 2 regions will be used by
434-
// ROM_EXT.
435-
flash_bank_0_data_region = 2;
436-
// First 0x20 pages are configured by ROM_EXT. To avoid conflicts, skip over
437-
// these pages.
438-
flash_bank_1_page_index = flash_info.data_pages + 0x20;
439-
}
449+
flash_bank_0_data_region = 3;
450+
// First 0x20 pages are configured by ROM_EXT. To avoid conflicts, skip over
451+
// these pages.
452+
flash_bank_1_page_index = flash_info.data_pages + 0x20;
440453
flash_bank_1_data_region = flash_bank_0_data_region + 1;
441-
flash_bank_1_data_region_scr = flash_bank_0_data_region + 2;
454+
// flash_bank_1_data_region_scr is defined later
442455
flash_bank_1_page_index_scr = flash_info.data_pages * 2 - 1;
443456

444457
CHECK_DIF_OK(dif_rv_plic_init(

sw/device/tests/flash_ctrl_write_clear_test.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
OTTF_DEFINE_TEST_CONFIG();
2424

25+
static uint32_t flash_region_index;
26+
2527
enum {
2628
// Some dif_flash_ctrl functions don't require the partition parameter when
2729
// interacting with data partitions. This constant is added to improve
@@ -39,9 +41,6 @@ enum {
3941
// partition in bank 1, otherwise known as owner partition B.
4042
kBank1StartPageNum = 256 + kRomExtPageCount,
4143

42-
// The ROM_EXT protects itself using regions 0-1.
43-
kFlashRegionNum = 2,
44-
4544
};
4645

4746
// The `flash_word_verify()` function will need to be updated if this assertion
@@ -93,7 +92,6 @@ static void flash_ctrl_write_clear_test(
9392
const uint64_t kExpectedValues[] = {
9493
UINT64_MAX, UINT64_MAX - 1, 0, 0xa5a5a5a594949494, 0xaaaaaaaaaaaaaaaa,
9594
};
96-
9795
for (size_t i = 0; i < ARRAYSIZE(kExpectedValues); ++i) {
9896
flash_word_write_verify(start_addr + sizeof(uint64_t) * i,
9997
kExpectedValues[i]);
@@ -105,6 +103,19 @@ bool test_main(void) {
105103
CHECK_DIF_OK(dif_flash_ctrl_init_state(
106104
&flash, mmio_region_from_addr(TOP_EARLGREY_FLASH_CTRL_CORE_BASE_ADDR)));
107105

106+
flash_region_index = 0;
107+
// Find the first unlocked flash region and use that for testing
108+
for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) {
109+
bool locked;
110+
LOG_INFO("Testing REGION 0x%x", region);
111+
CHECK_DIF_OK(dif_flash_ctrl_data_region_is_locked(&flash, region, &locked));
112+
if (!locked) {
113+
flash_region_index = region;
114+
LOG_INFO("Region %u is unlocked");
115+
break;
116+
}
117+
}
118+
108119
// The ROM_EXT configures the default region access. We can't modify the
109120
// values after configured.
110121
if (kBootStage != kBootStageOwner) {
@@ -114,7 +125,7 @@ bool test_main(void) {
114125
}
115126

116127
LOG_INFO("ECC enabled with high endurance disabled.");
117-
flash_ctrl_write_clear_test(/*mp_region_index=*/kFlashRegionNum,
128+
flash_ctrl_write_clear_test(/*mp_region_index=*/flash_region_index,
118129
(dif_flash_ctrl_data_region_properties_t){
119130
.base = kBank1StartPageNum,
120131
.size = 1,
@@ -128,7 +139,7 @@ bool test_main(void) {
128139
}});
129140

130141
LOG_INFO("ECC enabled with high endurance enabled.");
131-
flash_ctrl_write_clear_test(/*mp_region_index=*/kFlashRegionNum,
142+
flash_ctrl_write_clear_test(/*mp_region_index=*/flash_region_index,
132143
(dif_flash_ctrl_data_region_properties_t){
133144
.base = kBank1StartPageNum + 1,
134145
.size = 1,

sw/device/tests/rv_core_ibex_mem_test.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ 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,
6564
};
65+
static uint32_t flash_region_index;
6666

6767
// The flash test location is set to the encoding of `jalr x0, 0(x1)`
6868
// so execution can be tested.
@@ -162,12 +162,25 @@ static void setup_flash(void) {
162162
.ecc_en = kMultiBitBool4False,
163163
.high_endurance_en = kMultiBitBool4False};
164164
dif_flash_ctrl_data_region_properties_t data_region = {
165-
.base = kBank1StartPageNum, .size = 0x1, .properties = region_properties};
165+
.base = kBank1StartPageNum, .size = 0x2, .properties = region_properties};
166+
167+
// Find the first unlocked flash region and use that for testing
168+
for (uint32_t region = 0; region < FLASH_CTRL_PARAM_NUM_REGIONS; region++) {
169+
bool locked;
170+
LOG_INFO("Testing REGION 0x%x", region);
171+
CHECK_DIF_OK(
172+
dif_flash_ctrl_data_region_is_locked(&flash_ctrl, region, &locked));
173+
if (!locked) {
174+
flash_region_index = region;
175+
LOG_INFO("Region %u is unlocked");
176+
break;
177+
}
178+
}
166179

167180
CHECK_DIF_OK(dif_flash_ctrl_set_data_region_properties(
168-
&flash_ctrl, kFlashRegionNum, data_region));
181+
&flash_ctrl, flash_region_index, data_region));
169182
CHECK_DIF_OK(dif_flash_ctrl_set_data_region_enablement(
170-
&flash_ctrl, kFlashRegionNum, kDifToggleEnabled));
183+
&flash_ctrl, flash_region_index, kDifToggleEnabled));
171184

172185
// Make flash executable
173186
CHECK_DIF_OK(

0 commit comments

Comments
 (0)