Skip to content

Commit 4d945a7

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

File tree

7 files changed

+96
-71
lines changed

7 files changed

+96
-71
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: 48 additions & 26 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,19 @@
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

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+
4354
enum {
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.
6775
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);
7376
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);
7777
const 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
*/
114113
static 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-
*/
173172
bool 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,

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;

0 commit comments

Comments
 (0)