Skip to content

Commit 77e33b7

Browse files
committed
[tests] More tests
Signed-off-by: Robert Schilling <[email protected]>
1 parent 9c779e9 commit 77e33b7

File tree

7 files changed

+91
-74
lines changed

7 files changed

+91
-74
lines changed

sw/device/tests/BUILD

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6519,7 +6519,7 @@ test_suite(
65196519
test_harness = "//sw/host/tests/chip/rv_dm:access_after_hw_reset",
65206520
),
65216521
deps = [
6522-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
6522+
"//hw/top:dt",
65236523
"//sw/device/lib/dif:rstmgr",
65246524
"//sw/device/lib/runtime:hart",
65256525
"//sw/device/lib/runtime:log",
@@ -6989,9 +6989,10 @@ opentitan_test(
69896989
exec_env = dicts.add(
69906990
EARLGREY_TEST_ENVS,
69916991
EARLGREY_SILICON_OWNER_ROM_EXT_ENVS,
6992+
DARJEELING_TEST_ENVS,
69926993
),
69936994
deps = [
6994-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
6995+
"//hw/top:dt",
69956996
"//sw/device/lib/arch:device",
69966997
"//sw/device/lib/base:macros",
69976998
"//sw/device/lib/base:mmio",
@@ -7008,9 +7009,10 @@ opentitan_test(
70087009
exec_env = dicts.add(
70097010
EARLGREY_TEST_ENVS,
70107011
EARLGREY_SILICON_OWNER_ROM_EXT_ENVS,
7012+
DARJEELING_TEST_ENVS,
70117013
),
70127014
deps = [
7013-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
7015+
"//hw/top:dt",
70147016
"//sw/device/lib/arch:device",
70157017
"//sw/device/lib/base:macros",
70167018
"//sw/device/lib/base:mmio",
@@ -7158,14 +7160,17 @@ opentitan_binary(
71587160
"rv_core_ibex_epmp_test.S",
71597161
"rv_core_ibex_epmp_test.c",
71607162
],
7161-
exec_env = {
7162-
"//hw/top_earlgrey:fpga_cw310_rom_with_fake_keys": None,
7163-
"//hw/top_earlgrey:fpga_cw340_rom_with_fake_keys": None,
7164-
},
7163+
exec_env = dicts.add(
7164+
{
7165+
"//hw/top_earlgrey:fpga_cw310_rom_with_fake_keys": None,
7166+
"//hw/top_earlgrey:fpga_cw340_rom_with_fake_keys": None,
7167+
},
7168+
DARJEELING_TEST_ENVS,
7169+
),
71657170
kind = "ram",
71667171
linker_script = "//sw/device/silicon_creator/manuf/lib:sram_program_linker_script",
71677172
deps = [
7168-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
7173+
"//hw/top:dt",
71697174
"//sw/device/lib/arch:device",
71707175
"//sw/device/lib/base:macros",
71717176
"//sw/device/lib/runtime:log",
@@ -7291,12 +7296,14 @@ opentitan_binary(
72917296
kind = "ram",
72927297
linker_script = "//sw/device/silicon_creator/manuf/lib:sram_program_linker_script",
72937298
deps = [
7299+
"//hw/top:dt",
72947300
"//hw/top:pwm_c_regs",
72957301
"//hw/top:rv_timer_c_regs",
7296-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
72977302
"//sw/device/lib/arch:device",
72987303
"//sw/device/lib/base:macros",
72997304
"//sw/device/lib/dif:flash_ctrl",
7305+
"//sw/device/lib/dif:pwm",
7306+
"//sw/device/lib/dif:rv_timer",
73007307
"//sw/device/lib/runtime:log",
73017308
"//sw/device/lib/runtime:pmp",
73027309
"//sw/device/lib/testing:flash_ctrl_testutils",
@@ -7319,14 +7326,17 @@ opentitan_test(
73197326
["//hw/top_earlgrey:sim_verilator"],
73207327
),
73217328
EARLGREY_SILICON_OWNER_ROM_EXT_ENVS,
7329+
DARJEELING_TEST_ENVS,
73227330
),
73237331
deps = [
7332+
"//hw/top:dt",
73247333
"//hw/top:pwm_c_regs",
73257334
"//hw/top:rv_timer_c_regs",
7326-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
73277335
"//sw/device/lib/arch:device",
73287336
"//sw/device/lib/base:macros",
73297337
"//sw/device/lib/dif:flash_ctrl",
7338+
"//sw/device/lib/dif:pwm",
7339+
"//sw/device/lib/dif:rv_timer",
73307340
"//sw/device/lib/runtime:log",
73317341
"//sw/device/lib/runtime:pmp",
73327342
"//sw/device/lib/testing:flash_ctrl_testutils",
@@ -7601,7 +7611,7 @@ opentitan_test(
76017611
test_harness = "//sw/host/tests/chip/sram_ctrl:sram_ctrl_lc_escalation",
76027612
),
76037613
deps = [
7604-
"//hw/top_earlgrey/sw/autogen:top_earlgrey",
7614+
"//hw/top:dt",
76057615
"//sw/device/lib/arch:device",
76067616
"//sw/device/lib/base:macros",
76077617
"//sw/device/lib/base:mmio",

sw/device/tests/rv_core_ibex_epmp_test.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#include "hw/top/dt/dt_pinmux.h" // Generated
6+
#include "hw/top/dt/dt_sram_ctrl.h" // Generated
57
#include "sw/device/lib/arch/device.h"
68
#include "sw/device/lib/base/csr.h"
79
#include "sw/device/lib/dif/dif_uart.h"
@@ -16,8 +18,6 @@
1618
#include "sw/device/silicon_creator/lib/dbg_print.h"
1719
#include "sw/device/silicon_creator/lib/epmp_defs.h"
1820

19-
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
20-
2121
OTTF_DEFINE_TEST_CONFIG();
2222

2323
/**
@@ -196,8 +196,9 @@ static void pmp_setup_machine_area(void) {
196196
// but is in a lower PMP register so region 15's configuration
197197
// will be ignored in this area.
198198
const uint32_t kRodataEnd = (uint32_t)__rodata_end;
199-
const uint32_t kSramEnd = TOP_EARLGREY_SRAM_CTRL_MAIN_RAM_BASE_ADDR +
200-
TOP_EARLGREY_SRAM_CTRL_MAIN_RAM_SIZE_BYTES;
199+
const uint32_t kSramEnd =
200+
dt_sram_ctrl_memory_base(kDtSramCtrlMain, kDtSramCtrlMemoryRam) +
201+
dt_sram_ctrl_memory_size(kDtSramCtrlMain, kDtSramCtrlMemoryRam);
201202

202203
CSR_WRITE(CSR_REG_PMPADDR8, tor_address(kRodataEnd));
203204
CSR_WRITE(CSR_REG_PMPADDR9, tor_address(kSramEnd));
@@ -266,8 +267,7 @@ static void pmp_setup_test_locations(void) {
266267
*/
267268
static void setup_uart(void) {
268269
// Initialise DIF handles
269-
CHECK_DIF_OK(dif_pinmux_init(
270-
mmio_region_from_addr(TOP_EARLGREY_PINMUX_AON_BASE_ADDR), &pinmux));
270+
CHECK_DIF_OK(dif_pinmux_init_from_dt(kDtPinmuxAon, &pinmux));
271271

272272
// Initialise UART console.
273273
pinmux_testutils_init(&pinmux);

sw/device/tests/rv_core_ibex_mem_test.c

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,17 @@
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"
@@ -36,15 +43,14 @@
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

4147
OTTF_DEFINE_TEST_CONFIG();
4248

4349
enum {
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);
7368
const 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);
7769
const 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
*/
114105
static 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-
*/
173164
bool 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,

sw/device/tests/rv_dm_access_after_hw_reset.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
33
// SPDX-License-Identifier: Apache-2.0
44

5+
#include "hw/top/dt/dt_rstmgr.h" // Generated
56
#include "sw/device/lib/runtime/log.h"
67
#include "sw/device/lib/testing/rstmgr_testutils.h"
78
#include "sw/device/lib/testing/test_framework/check.h"
89
#include "sw/device/lib/testing/test_framework/ottf_main.h"
910
#include "sw/device/lib/testing/test_framework/ottf_utils.h"
1011

11-
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
12-
1312
/*
1413
- Wait for host to perform debugger tests
1514
- Once the host side confirms, do a SW reset of the chip
@@ -37,8 +36,7 @@ static void chip_sw_reset(void) {
3736
}
3837

3938
bool test_main(void) {
40-
CHECK_DIF_OK(dif_rstmgr_init(
41-
mmio_region_from_addr(TOP_EARLGREY_RSTMGR_AON_BASE_ADDR), &rstmgr));
39+
CHECK_DIF_OK(dif_rstmgr_init_from_dt(kDtRstmgrAon, &rstmgr));
4240

4341
// Check if there was a HW reset caused by the software.
4442
dif_rstmgr_reset_info_bitfield_t rst_info;

sw/device/tests/sram_ctrl_lc_escalation_test.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
* through the debug module.
1818
*/
1919

20+
#include "hw/top/dt/dt_alert_handler.h" // Generated
21+
#include "hw/top/dt/dt_lc_ctrl.h" // Generated
22+
#include "hw/top/dt/dt_sram_ctrl.h" // Generated
2023
#include "sw/device/lib/arch/device.h"
2124
#include "sw/device/lib/base/macros.h"
2225
#include "sw/device/lib/base/mmio.h"
@@ -30,7 +33,6 @@
3033
#include "sw/device/silicon_creator/lib/drivers/retention_sram.h"
3134

3235
#include "hw/top/sram_ctrl_regs.h" // Generated.
33-
#include "hw/top_earlgrey/sw/autogen/top_earlgrey.h"
3436

3537
static const uint32_t kStatusRegMask = kDifSramCtrlStatusBusIntegErr |
3638
kDifSramCtrlStatusInitErr |
@@ -69,11 +71,8 @@ static bool write_read_data(mmio_region_t sram_region, uint32_t data) {
6971
}
7072

7173
status_t configure_srams(void) {
72-
uint32_t base_addr;
73-
base_addr = TOP_EARLGREY_SRAM_CTRL_MAIN_REGS_BASE_ADDR;
74-
TRY(dif_sram_ctrl_init(mmio_region_from_addr(base_addr), &sram_ctrl_main));
75-
base_addr = TOP_EARLGREY_SRAM_CTRL_RET_AON_REGS_BASE_ADDR;
76-
TRY(dif_sram_ctrl_init(mmio_region_from_addr(base_addr), &sram_ctrl_ret));
74+
TRY(dif_sram_ctrl_init_from_dt(kDtSramCtrlMain, &sram_ctrl_main));
75+
TRY(dif_sram_ctrl_init_from_dt(kDtSramCtrlRetAon, &sram_ctrl_ret));
7776

7877
dif_sram_ctrl_status_bitfield_t status_main;
7978
dif_sram_ctrl_status_bitfield_t status_ret;
@@ -91,9 +90,7 @@ status_t configure_srams(void) {
9190
}
9291

9392
status_t configure_alert_handler(void) {
94-
TRY(dif_alert_handler_init(
95-
mmio_region_from_addr(TOP_EARLGREY_ALERT_HANDLER_BASE_ADDR),
96-
&alert_handler));
93+
TRY(dif_alert_handler_init_from_dt(kDtAlertHandler, &alert_handler));
9794

9895
dif_alert_handler_escalation_phase_t esc_phases[] = {{
9996
.phase = kDifAlertHandlerClassStatePhase0,
@@ -111,7 +108,9 @@ status_t configure_alert_handler(void) {
111108
};
112109

113110
TRY(dif_alert_handler_configure_alert(
114-
&alert_handler, kTopEarlgreyAlertIdLcCtrlFatalBusIntegError,
111+
&alert_handler,
112+
dt_lc_ctrl_alert_to_alert_id(kDtLcCtrlFirst,
113+
kDtLcCtrlAlertFatalBusIntegError),
115114
kDifAlertHandlerClassA, kDifToggleEnabled, kDifToggleEnabled));
116115
TRY(dif_alert_handler_configure_class(&alert_handler, kDifAlertHandlerClassA,
117116
class_config, kDifToggleEnabled,
@@ -123,17 +122,17 @@ status_t configure_alert_handler(void) {
123122
OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);
124123

125124
bool test_main(void) {
126-
CHECK_DIF_OK(dif_lc_ctrl_init(
127-
mmio_region_from_addr(TOP_EARLGREY_LC_CTRL_REGS_BASE_ADDR), &lc_ctrl));
125+
CHECK_DIF_OK(dif_lc_ctrl_init_from_dt(kDtLcCtrlFirst, &lc_ctrl));
128126

129127
CHECK_STATUS_OK(configure_alert_handler());
130128
CHECK_STATUS_OK(configure_srams());
131129

132130
// Read and Write to/from SRAMs. Main SRAM will use the address of the
133131
// buffer that has been allocated. Ret SRAM can start at the owner section.
134132
sram_buffer_addr_main = (uintptr_t)&sram_buffer_main;
135-
sram_buffer_addr_ret = TOP_EARLGREY_SRAM_CTRL_RET_AON_RAM_BASE_ADDR +
136-
offsetof(retention_sram_t, owner);
133+
sram_buffer_addr_ret =
134+
dt_sram_ctrl_memory_base(kDtSramCtrlRetAon, kDtSramCtrlMemoryRam) +
135+
offsetof(retention_sram_t, owner);
137136

138137
mmio_region_t sram_region_main = mmio_region_from_addr(sram_buffer_addr_main);
139138
mmio_region_t sram_region_ret = mmio_region_from_addr(sram_buffer_addr_ret);

0 commit comments

Comments
 (0)