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
49+ static_assert (kDtFlashCtrlCount == 1 , "this test expects a flash_ctrl" );
50+ static_assert (kDtPwmCount == 1 , "this test expects a pwm" );
51+ static_assert (kDtRvTimerCount == 1 , "this test expects a rv_timer" );
52+ static_assert (kDtRomCtrlCount == 1 , "this test expects a rom_ctrl" );
53+
4354enum {
4455 // 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 ,
56+ // tested. ROM base address will be computed at runtime.
57+ kRomTestLocOffset = 0x400 ,
58+ kRomTestLocSize = 0x100 ,
4859 kRomTestLocContent = 0x8082 ,
4960
5061 // Number of bytes per page.
@@ -57,23 +68,12 @@ enum {
5768 // The start page used by this test. Points to the start of the owner
5869 // partition in bank 1, otherwise known as owner partition B.
5970 kBank1StartPageNum = 256 + kRomExtPageCount ,
60-
61- kFlashTestLoc = TOP_EARLGREY_FLASH_CTRL_MEM_BASE_ADDR +
62- kBank1StartPageNum * kFlashBytesPerPage ,
6371};
6472
6573// The flash test location is set to the encoding of `jalr x0, 0(x1)`
6674// so execution can be tested.
6775const 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 );
7376const 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 );
7777const uint32_t kMMIOTestLoc2Content = 0xe4210e64 ; // a random value
7878
7979/**
@@ -84,8 +84,7 @@ static void setup_uart(void) {
8484 static dif_pinmux_t pinmux ;
8585
8686 // Initialise DIF handles
87- CHECK_DIF_OK (dif_pinmux_init (
88- mmio_region_from_addr (TOP_EARLGREY_PINMUX_AON_BASE_ADDR ), & pinmux ));
87+ CHECK_DIF_OK (dif_pinmux_init_from_dt (kDtPinmuxAon , & pinmux ));
8988
9089 // Initialise UART console.
9190 pinmux_testutils_init (& pinmux );
@@ -113,13 +112,16 @@ static void use_icache(bool enable) {
113112 */
114113static void setup_flash (void ) {
115114 // Create a PMP region for the flash
115+ uintptr_t flash_mem_base =
116+ dt_flash_ctrl_memory_base (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
117+ size_t flash_mem_size =
118+ dt_flash_ctrl_memory_size (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
116119 pmp_region_config_t config = {
117120 .lock = kPmpRegionLockLocked ,
118121 .permissions = kPmpRegionPermissionsReadWriteExecute ,
119122 };
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 );
123+ pmp_region_configure_napot_result_t result =
124+ pmp_region_configure_napot (8 , config , flash_mem_base , flash_mem_size );
123125 CHECK (result == kPmpRegionConfigureNapotOk ,
124126 "Load configuration failed, error code = %d" , result );
125127 // When running as ROM_EXT, ROM configures the flash memory to be readonly.
@@ -132,9 +134,7 @@ static void setup_flash(void) {
132134
133135 // Initialise the flash controller.
134136 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 )));
137+ CHECK_DIF_OK (dif_flash_ctrl_init_state_from_dt (& flash_ctrl , kDtFlashCtrl ));
138138
139139 CHECK_STATUS_OK (flash_ctrl_testutils_wait_for_init (& flash_ctrl ));
140140
@@ -158,6 +158,8 @@ static void setup_flash(void) {
158158 dif_flash_ctrl_set_exec_enablement (& flash_ctrl , kDifToggleEnabled ));
159159
160160 // Write the wanted value to flash
161+ uintptr_t kFlashTestLoc =
162+ flash_mem_base + kBank1StartPageNum * kFlashBytesPerPage ;
161163 CHECK_STATUS_OK (flash_ctrl_testutils_erase_and_write_page (
162164 /*flash_state=*/ & flash_ctrl ,
163165 /*byte_address=*/ kFlashTestLoc ,
@@ -167,16 +169,31 @@ static void setup_flash(void) {
167169 /*word_count=*/ 1 ));
168170}
169171
170- /**
171- * The entry point of the SRAM test.
172- */
173172bool test_main (void ) {
174173 setup_uart ();
175174
175+ // Initialize MMIO peripherals to get their base addresses
176+ dif_rv_timer_t rv_timer ;
177+ CHECK_DIF_OK (dif_rv_timer_init_from_dt (kDtRvTimer , & rv_timer ));
178+ volatile uint32_t * kMMIOTestLoc1 =
179+ (uint32_t * )((uintptr_t )rv_timer .base_addr +
180+ RV_TIMER_COMPARE_LOWER0_0_REG_OFFSET );
181+
182+ dif_pwm_t pwm ;
183+ CHECK_DIF_OK (dif_pwm_init_from_dt (kDtPwmAon , & pwm ));
184+ volatile uint32_t * kMMIOTestLoc2 =
185+ (uint32_t * )((uintptr_t )pwm .base_addr + PWM_DUTY_CYCLE_0_REG_OFFSET );
186+
176187 // ROM access is blocked in the silicon owner stage.
177188 if (kBootStage != kBootStageOwner ) {
178189 LOG_INFO ("Testing Load from ROM Location." );
179190
191+ // Get ROM base address
192+ uintptr_t rom_base =
193+ dt_rom_ctrl_memory_base (kDtRomCtrl , kDtRomCtrlMemoryRom );
194+ uintptr_t kRomTestLocStart = rom_base + kRomTestLocOffset ;
195+ uintptr_t kRomTestLocEnd = kRomTestLocStart + kRomTestLocSize ;
196+
180197 // For the execution test we a specific `c.jr x1` (i.e. function return)
181198 // instruction. Since the address can vary between ROM builds, we scan a
182199 // small region to find it.
@@ -221,6 +238,11 @@ bool test_main(void) {
221238 setup_flash ();
222239
223240 LOG_INFO ("Check flash load" );
241+ uintptr_t flash_mem_base =
242+ dt_flash_ctrl_memory_base (kDtFlashCtrl , kDtFlashCtrlMemoryMem );
243+ uintptr_t kFlashTestLoc =
244+ flash_mem_base + kBank1StartPageNum * kFlashBytesPerPage ;
245+ void (* flash_test_gadget )(void ) = (void (* )(void ))kFlashTestLoc ;
224246 load = * (volatile const uint32_t * )kFlashTestLoc ;
225247 CHECK (
226248 load == kFlashTestLocContent ,
0 commit comments