1717 * Two MMIO registers from two different devices are written to and read from.
1818 */
1919
20+ #include "hw/top/dt/dt_flash_ctrl.h" // Generated
21+ #include "hw/top/dt/dt_pinmux.h" // Generated
22+ #include "hw/top/dt/dt_pwm.h" // Generated
23+ #include "hw/top/dt/dt_rom_ctrl.h" // Generated
24+ #include "hw/top/dt/dt_rv_timer.h" // Generated
2025#include "sw/device/lib/arch/boot_stage.h"
2126#include "sw/device/lib/arch/device.h"
2227#include "sw/device/lib/base/csr.h"
2328#include "sw/device/lib/dif/dif_flash_ctrl.h"
29+ #include "sw/device/lib/dif/dif_pwm.h"
30+ #include "sw/device/lib/dif/dif_rv_timer.h"
2431#include "sw/device/lib/dif/dif_uart.h"
2532#include "sw/device/lib/runtime/ibex.h"
2633#include "sw/device/lib/runtime/log.h"
3643#include "hw/top/flash_ctrl_regs.h"
3744#include "hw/top/pwm_regs.h"
3845#include "hw/top/rv_timer_regs.h"
39- #include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
4046
4147OTTF_DEFINE_TEST_CONFIG ();
4248
4349enum {
4450 // Search within this ROM region to find `c.jr x1`, so execution can be
45- // tested.
46- kRomTestLocStart = TOP_EARLGREY_ROM_CTRL_ROM_BASE_ADDR + 0x400 ,
47- kRomTestLocEnd = TOP_EARLGREY_ROM_CTRL_ROM_BASE_ADDR + 0x500 ,
51+ // tested. ROM base address will be computed at runtime.
52+ kRomTestLocOffset = 0x400 ,
53+ kRomTestLocSize = 0x100 ,
4854 kRomTestLocContent = 0x8082 ,
4955
5056 // Number of bytes per page.
@@ -57,23 +63,9 @@ enum {
5763 // The start page used by this test. Points to the start of the owner
5864 // partition in bank 1, otherwise known as owner partition B.
5965 kBank1StartPageNum = 256 + kRomExtPageCount ,
60-
61- kFlashTestLoc = TOP_EARLGREY_FLASH_CTRL_MEM_BASE_ADDR +
62- kBank1StartPageNum * kFlashBytesPerPage ,
6366};
6467
65- // The flash test location is set to the encoding of `jalr x0, 0(x1)`
66- // so execution can be tested.
67- const uint32_t kFlashTestLocContent = 0x00008067 ;
68- void (* flash_test_gadget )(void ) = (void (* )(void ))kFlashTestLoc ;
69-
70- volatile uint32_t * kMMIOTestLoc1 =
71- (uint32_t * )(TOP_EARLGREY_RV_TIMER_BASE_ADDR +
72- RV_TIMER_COMPARE_LOWER0_0_REG_OFFSET );
7368const uint32_t kMMIOTestLoc1Content = 0x126d8c15 ; // a random value
74-
75- volatile uint32_t * kMMIOTestLoc2 =
76- (uint32_t * )(TOP_EARLGREY_PWM_AON_BASE_ADDR + PWM_DUTY_CYCLE_0_REG_OFFSET );
7769const uint32_t kMMIOTestLoc2Content = 0xe4210e64 ; // a random value
7870
7971/**
@@ -84,8 +76,7 @@ static void setup_uart(void) {
8476 static dif_pinmux_t pinmux ;
8577
8678 // Initialise DIF handles
87- CHECK_DIF_OK (dif_pinmux_init (
88- mmio_region_from_addr (TOP_EARLGREY_PINMUX_AON_BASE_ADDR ), & pinmux ));
79+ CHECK_DIF_OK (dif_pinmux_init_from_dt (kDtPinmuxAon , & pinmux ));
8980
9081 // Initialise UART console.
9182 pinmux_testutils_init (& pinmux );
@@ -113,13 +104,16 @@ static void use_icache(bool enable) {
113104 */
114105static void setup_flash (void ) {
115106 // Create a PMP region for the flash
107+ uintptr_t flash_mem_base =
108+ dt_flash_ctrl_memory_base (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
109+ size_t flash_mem_size =
110+ dt_flash_ctrl_memory_size (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
116111 pmp_region_config_t config = {
117112 .lock = kPmpRegionLockLocked ,
118113 .permissions = kPmpRegionPermissionsReadWriteExecute ,
119114 };
120- pmp_region_configure_napot_result_t result = pmp_region_configure_napot (
121- 8 , config , TOP_EARLGREY_FLASH_CTRL_MEM_BASE_ADDR ,
122- TOP_EARLGREY_FLASH_CTRL_MEM_SIZE_BYTES );
115+ pmp_region_configure_napot_result_t result =
116+ pmp_region_configure_napot (8 , config , flash_mem_base , flash_mem_size );
123117 CHECK (result == kPmpRegionConfigureNapotOk ,
124118 "Load configuration failed, error code = %d" , result );
125119 // When running as ROM_EXT, ROM configures the flash memory to be readonly.
@@ -132,9 +126,7 @@ static void setup_flash(void) {
132126
133127 // Initialise the flash controller.
134128 dif_flash_ctrl_state_t flash_ctrl ;
135- CHECK_DIF_OK (dif_flash_ctrl_init_state (
136- & flash_ctrl ,
137- mmio_region_from_addr (TOP_EARLGREY_FLASH_CTRL_CORE_BASE_ADDR )));
129+ CHECK_DIF_OK (dif_flash_ctrl_init_state_from_dt (& flash_ctrl , kDtFlashCtrl ));
138130
139131 CHECK_STATUS_OK (flash_ctrl_testutils_wait_for_init (& flash_ctrl ));
140132
@@ -158,6 +150,8 @@ static void setup_flash(void) {
158150 dif_flash_ctrl_set_exec_enablement (& flash_ctrl , kDifToggleEnabled ));
159151
160152 // Write the wanted value to flash
153+ uintptr_t kFlashTestLoc =
154+ flash_mem_base + kBank1StartPageNum * kFlashBytesPerPage ;
161155 CHECK_STATUS_OK (flash_ctrl_testutils_erase_and_write_page (
162156 /*flash_state=*/ & flash_ctrl ,
163157 /*byte_address=*/ kFlashTestLoc ,
@@ -167,16 +161,31 @@ static void setup_flash(void) {
167161 /*word_count=*/ 1 ));
168162}
169163
170- /**
171- * The entry point of the SRAM test.
172- */
173164bool test_main (void ) {
174165 setup_uart ();
175166
167+ // Initialize MMIO peripherals to get their base addresses
168+ dif_rv_timer_t rv_timer ;
169+ CHECK_DIF_OK (dif_rv_timer_init_from_dt (kDtRvTimer , & rv_timer ));
170+ volatile uint32_t * kMMIOTestLoc1 =
171+ (uint32_t * )((uintptr_t )rv_timer .base_addr +
172+ RV_TIMER_COMPARE_LOWER0_0_REG_OFFSET );
173+
174+ dif_pwm_t pwm ;
175+ CHECK_DIF_OK (dif_pwm_init_from_dt (kDtPwmAon , & pwm ));
176+ volatile uint32_t * kMMIOTestLoc2 =
177+ (uint32_t * )((uintptr_t )pwm .base_addr + PWM_DUTY_CYCLE_0_REG_OFFSET );
178+
176179 // ROM access is blocked in the silicon owner stage.
177180 if (kBootStage != kBootStageOwner ) {
178181 LOG_INFO ("Testing Load from ROM Location." );
179182
183+ // Get ROM base address
184+ uintptr_t rom_base =
185+ dt_rom_ctrl_memory_base (kDtRomCtrl , kDtRomCtrlMemoryRom );
186+ uintptr_t kRomTestLocStart = rom_base + kRomTestLocOffset ;
187+ uintptr_t kRomTestLocEnd = kRomTestLocStart + kRomTestLocSize ;
188+
180189 // For the execution test we a specific `c.jr x1` (i.e. function return)
181190 // instruction. Since the address can vary between ROM builds, we scan a
182191 // small region to find it.
@@ -221,6 +230,11 @@ bool test_main(void) {
221230 setup_flash ();
222231
223232 LOG_INFO ("Check flash load" );
233+ uintptr_t flash_mem_base =
234+ dt_flash_ctrl_memory_base (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
235+ uintptr_t kFlashTestLoc =
236+ flash_mem_base + kBank1StartPageNum * kFlashBytesPerPage ;
237+ void (* flash_test_gadget )(void ) = (void (* )(void ))kFlashTestLoc ;
224238 load = * (volatile const uint32_t * )kFlashTestLoc ;
225239 CHECK (
226240 load == kFlashTestLocContent ,
0 commit comments