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"
2430#include "sw/device/lib/dif/dif_uart.h"
2531#include "sw/device/lib/runtime/ibex.h"
2632#include "sw/device/lib/runtime/log.h"
3642#include "hw/top/flash_ctrl_regs.h"
3743#include "hw/top/pwm_regs.h"
3844#include "hw/top/rv_timer_regs.h"
39- #include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
4045
4146OTTF_DEFINE_TEST_CONFIG ();
4247
48+ static_assert (kDtFlashCtrlCount == 1 , "this test expects a flash_ctrl" );
49+ static_assert (kDtPwmCount == 1 , "this test expects a pwm" );
50+ static_assert (kDtRvTimerCount == 1 , "this test expects a rv_timer" );
51+ static_assert (kDtRomCtrlCount == 1 , "this test expects a rom_ctrl" );
52+
4353enum {
4454 // 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 ,
55+ // tested. ROM base address will be computed at runtime.
56+ kRomTestLocOffset = 0x400 ,
57+ kRomTestLocSize = 0x100 ,
4858 kRomTestLocContent = 0x8082 ,
4959
5060 // Number of bytes per page.
@@ -57,23 +67,12 @@ enum {
5767 // The start page used by this test. Points to the start of the owner
5868 // partition in bank 1, otherwise known as owner partition B.
5969 kBank1StartPageNum = 256 + kRomExtPageCount ,
60-
61- kFlashTestLoc = TOP_EARLGREY_FLASH_CTRL_MEM_BASE_ADDR +
62- kBank1StartPageNum * kFlashBytesPerPage ,
6370};
6471
6572// The flash test location is set to the encoding of `jalr x0, 0(x1)`
6673// so execution can be tested.
6774const 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 );
7375const 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 );
7776const uint32_t kMMIOTestLoc2Content = 0xe4210e64 ; // a random value
7877
7978/**
@@ -84,8 +83,7 @@ static void setup_uart(void) {
8483 static dif_pinmux_t pinmux ;
8584
8685 // Initialise DIF handles
87- CHECK_DIF_OK (dif_pinmux_init (
88- mmio_region_from_addr (TOP_EARLGREY_PINMUX_AON_BASE_ADDR ), & pinmux ));
86+ CHECK_DIF_OK (dif_pinmux_init_from_dt (kDtPinmuxAon , & pinmux ));
8987
9088 // Initialise UART console.
9189 pinmux_testutils_init (& pinmux );
@@ -113,13 +111,16 @@ static void use_icache(bool enable) {
113111 */
114112static void setup_flash (void ) {
115113 // Create a PMP region for the flash
114+ uintptr_t flash_mem_base =
115+ dt_flash_ctrl_memory_base (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
116+ size_t flash_mem_size =
117+ dt_flash_ctrl_memory_size (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
116118 pmp_region_config_t config = {
117119 .lock = kPmpRegionLockLocked ,
118120 .permissions = kPmpRegionPermissionsReadWriteExecute ,
119121 };
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 );
122+ pmp_region_configure_napot_result_t result =
123+ pmp_region_configure_napot (8 , config , flash_mem_base , flash_mem_size );
123124 CHECK (result == kPmpRegionConfigureNapotOk ,
124125 "Load configuration failed, error code = %d" , result );
125126 // When running as ROM_EXT, ROM configures the flash memory to be readonly.
@@ -132,9 +133,7 @@ static void setup_flash(void) {
132133
133134 // Initialise the flash controller.
134135 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 )));
136+ CHECK_DIF_OK (dif_flash_ctrl_init_state_from_dt (& flash_ctrl , kDtFlashCtrl ));
138137
139138 CHECK_STATUS_OK (flash_ctrl_testutils_wait_for_init (& flash_ctrl ));
140139
@@ -158,6 +157,8 @@ static void setup_flash(void) {
158157 dif_flash_ctrl_set_exec_enablement (& flash_ctrl , kDifToggleEnabled ));
159158
160159 // Write the wanted value to flash
160+ uintptr_t kFlashTestLoc =
161+ flash_mem_base + kBank1StartPageNum * kFlashBytesPerPage ;
161162 CHECK_STATUS_OK (flash_ctrl_testutils_erase_and_write_page (
162163 /*flash_state=*/ & flash_ctrl ,
163164 /*byte_address=*/ kFlashTestLoc ,
@@ -167,16 +168,26 @@ static void setup_flash(void) {
167168 /*word_count=*/ 1 ));
168169}
169170
170- /**
171- * The entry point of the SRAM test.
172- */
173171bool test_main (void ) {
174172 setup_uart ();
175173
174+ volatile uint32_t * kMMIOTestLoc1 =
175+ dt_rv_timer_reg_block (kDtRvTimer , kDtRvTimerRegBlockCore ) +
176+ RV_TIMER_COMPARE_LOWER0_0_REG_OFFSET ;
177+ volatile uint32_t * kMMIOTestLoc2 =
178+ dt_pwm_reg_block (kDtPwmAon , kDtPwmRegBlockCore ) +
179+ PWM_DUTY_CYCLE_0_REG_OFFSET ;
180+
176181 // ROM access is blocked in the silicon owner stage.
177182 if (kBootStage != kBootStageOwner ) {
178183 LOG_INFO ("Testing Load from ROM Location." );
179184
185+ // Get ROM base address
186+ uintptr_t rom_base =
187+ dt_rom_ctrl_memory_base (kDtRomCtrl , kDtRomCtrlMemoryRom );
188+ uintptr_t kRomTestLocStart = rom_base + kRomTestLocOffset ;
189+ uintptr_t kRomTestLocEnd = kRomTestLocStart + kRomTestLocSize ;
190+
180191 // For the execution test we a specific `c.jr x1` (i.e. function return)
181192 // instruction. Since the address can vary between ROM builds, we scan a
182193 // small region to find it.
@@ -221,6 +232,11 @@ bool test_main(void) {
221232 setup_flash ();
222233
223234 LOG_INFO ("Check flash load" );
235+ uintptr_t flash_mem_base =
236+ dt_flash_ctrl_memory_base (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
237+ uintptr_t kFlashTestLoc =
238+ flash_mem_base + kBank1StartPageNum * kFlashBytesPerPage ;
239+ void (* flash_test_gadget )(void ) = (void (* )(void ))kFlashTestLoc ;
224240 load = * (volatile const uint32_t * )kFlashTestLoc ;
225241 CHECK (
226242 load == kFlashTestLocContent ,
0 commit comments