Skip to content

Commit 8b11bb3

Browse files
[rom_ctrl, test] rom_ctrl smoketest added
* new testcase implemented among top level sw tests * the new test reads the compile time initialized ROM values * if any comparision fails (expected values differs from read value) test is terminated with an error * sw test files reformated to compplie with clang format
1 parent 1e5f88c commit 8b11bb3

File tree

9 files changed

+148
-2
lines changed

9 files changed

+148
-2
lines changed

hw/top_chip/dv/top_chip_sim_cfg.hjson

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@
176176
sw_images: ["mailbox_smoketest_cheri_bare:5"]
177177
run_opts: ["+ChipMemSRAM_image_file={run_dir}/mailbox_smoketest_cheri_bare.vmem"]
178178
}
179+
{
180+
name: rom_ctrl_smoke
181+
uvm_test_seq: top_chip_dv_uart_base_vseq
182+
sw_images: ["rom_ctrl_smoketest_vanilla_bare:5"]
183+
run_opts: ["+ChipMemSRAM_image_file={run_dir}/rom_ctrl_smoketest_vanilla_bare.vmem"]
184+
}
179185
]
180186

181187
// List of regressions.
@@ -199,6 +205,7 @@
199205
"mailbox_smoke",
200206
//TODO currently broken.
201207
// "mailbox_smoke_cheri"
208+
"rom_ctrl_smoke"
202209
]
203210
}
204211
{
@@ -254,7 +261,8 @@
254261
{
255262
name: rom_ctrl
256263
tests: [
257-
"rom_ctrl_integrity_check"
264+
"rom_ctrl_integrity_check",
265+
"rom_ctrl_smoke"
258266
]
259267
}
260268
{

sw/device/lib/hal/CMakeLists.txt

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

5-
set(SRCS clkmgr.c gpio.c i2c.c mailbox.c mocha.c plic.c rstmgr.c spi_device.c timer.c uart.c)
5+
set(SRCS clkmgr.c gpio.c i2c.c mailbox.c mocha.c plic.c rstmgr.c spi_device.c timer.c uart.c rom_ctrl.c)
66

77
mocha_add_library(NAME hal LIBRARIES SOURCES ${SRCS})

sw/device/lib/hal/mocha.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include <cheriintrin.h>
1212
#endif /* defined(__riscv_zcherihybrid) */
1313

14+
static const uintptr_t rom_base = 0x80000ul;
1415
static const uintptr_t mailbox_base = 0x20010000ul;
1516
static const uintptr_t dv_test_status_base = 0x20020000ul;
1617
static const uintptr_t gpio_base = 0x40000000ul;
1718
static const uintptr_t clkmgr_base = 0x40020000ul;
1819
static const uintptr_t rstmgr_base = 0x40030000ul;
20+
static const uintptr_t rom_ctrl_base = 0x40050000ul;
1921
static const uintptr_t uart_base = 0x41000000ul;
2022
static const uintptr_t i2c_base = 0x42000000ul;
2123
static const uintptr_t spi_device_base = 0x43000000ul;
@@ -42,6 +44,15 @@ static void *create_mmio_capability(uintptr_t address, size_t length)
4244
}
4345
#endif /* defined(__riscv_zcherihybrid) */
4446

47+
rom_t mocha_system_rom(void)
48+
{
49+
#if defined(__riscv_zcherihybrid)
50+
return (rom_t)create_mmio_capability(rom_base, 0x8000u);
51+
#else /* !defined(__riscv_zcherihybrid) */
52+
return (rom_t)rom_base;
53+
#endif /* defined(__riscv_zcherihybrid) */
54+
}
55+
4556
mailbox_t mocha_system_mailbox(void)
4657
{
4758
#if defined(__riscv_zcherihybrid)
@@ -78,6 +89,15 @@ rstmgr_t mocha_system_rstmgr(void)
7889
#endif /* defined(__riscv_zcherihybrid) */
7990
}
8091

92+
rom_ctrl_t mocha_system_rom_ctrl(void)
93+
{
94+
#if defined(__riscv_zcherihybrid)
95+
return (rom_ctrl_t)create_mmio_capability(rom_ctrl_base, 0x48u);
96+
#else /* !defined(__riscv_zcherihybrid) */
97+
return (rom_ctrl_t)rom_ctrl_base;
98+
#endif /* defined(__riscv_zcherihybrid) */
99+
}
100+
81101
uart_t mocha_system_uart(void)
82102
{
83103
#if defined(__riscv_zcherihybrid)

sw/device/lib/hal/mocha.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "hal/i2c.h"
1212
#include "hal/mailbox.h"
1313
#include "hal/plic.h"
14+
#include "hal/rom_ctrl.h"
1415
#include "hal/rstmgr.h"
1516
#include "hal/spi_device.h"
1617
#include "hal/timer.h"
@@ -29,6 +30,8 @@ gpio_t mocha_system_gpio(void);
2930
clkmgr_t mocha_system_clkmgr(void);
3031
rstmgr_t mocha_system_rstmgr(void);
3132
uart_t mocha_system_uart(void);
33+
rom_t mocha_system_rom(void);
34+
rom_ctrl_t mocha_system_rom_ctrl(void);
3235
i2c_t mocha_system_i2c(void);
3336
spi_device_t mocha_system_spi_device(void);
3437
timer_t mocha_system_timer(void);

sw/device/lib/hal/rom_ctrl.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "hal/rom_ctrl.h"
6+
#include "hal/mmio.h"
7+
#include "hal/mocha.h"
8+
#include <stdint.h>
9+
10+
/* Read specific word_idx-th word from ROM memory */
11+
uint32_t read_rom(rom_t rom, uint32_t rel_addr)
12+
{
13+
return DEV_READ(rom + rel_addr);
14+
}

sw/device/lib/hal/rom_ctrl.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#pragma once
6+
7+
#include <stdbool.h>
8+
#include <stdint.h>
9+
10+
#define ROM_CTRL_REG (0x0)
11+
#define FATAL_ALERT_CAUSE (0x4)
12+
13+
typedef void *rom_ctrl_t;
14+
typedef void *rom_t;
15+
16+
#define ROM_CTRL_FROM_BASE_ADDR(addr) ((rom_ctrl_t)(addr))
17+
#define ROM_FROM_BASE_ADDR(addr) ((rom_t)(addr))
18+
19+
uint32_t read_rom(rom_t rom, uint32_t rel_addr);

sw/device/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ mocha_add_test(NAME tag_controller_tag_test SOURCES tag_controller/tag_test.c LI
1818
mocha_add_test(NAME timer_smoketest SOURCES timer/smoketest.c LIBRARIES ${LIBS} FPGA)
1919
mocha_add_test(NAME timer_interrupt_test SOURCES timer/interrupt.c LIBRARIES ${LIBS})
2020
mocha_add_test(NAME uart_smoketest SOURCES uart/smoketest.c LIBRARIES ${LIBS})
21+
mocha_add_test(NAME rom_ctrl_smoketest SOURCES rom_ctrl/smoketest.c LIBRARIES ${LIBS})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
@00000000
6+
DEADBEEF
7+
CAFEBABE
8+
00000001
9+
EEEEEEEE
10+
@00001000
11+
01234567
12+
10000001
13+
20000002
14+
30000003
15+
@00001FFC
16+
F000000F
17+
0EEEEEE0
18+
0FFFFFF0
19+
01010101
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright lowRISC contributors (COSMIC project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#include "hal/mmio.h"
6+
#include "hal/mocha.h"
7+
#include "hal/rom_ctrl.h"
8+
#include "hal/uart.h"
9+
#include "runtime/print.h"
10+
#include <stdbool.h>
11+
#include <stdint.h>
12+
13+
// Check ROM init values
14+
static bool rom_read_test(rom_t rom, uart_t console)
15+
{
16+
uint32_t data;
17+
uint32_t address;
18+
uint8_t address_length = 3;
19+
uint8_t data_length = 4;
20+
21+
// ROM Address values
22+
const uint32_t expected_addresses[3] = { 0x00000000, 0x00004000, 0x00007FF0 };
23+
24+
// ROM Init values
25+
const uint32_t expected_data[3][4] = { { 0xDEADBEEF, 0xCAFEBABE, 0x00000001, 0xEEEEEEEE },
26+
{ 0x01234567, 0x10000001, 0x20000002, 0x30000003 },
27+
{ 0xF000000F, 0x0EEEEEE0, 0x0FFFFFF0, 0x01010101 } };
28+
29+
uprintf(console, "\nRead ROM!\n");
30+
31+
// Reading and comparing
32+
for (uint8_t address_idx = 0; address_idx < address_length; address_idx++) {
33+
for (uint8_t word_idx = 0; word_idx < data_length; word_idx++) {
34+
address = 4 * word_idx + expected_addresses[address_idx];
35+
data = read_rom(rom, address);
36+
uprintf(console, "[%lx] | ", (unsigned long)(uintptr_t)(rom + address));
37+
uprintf(console, "0x%x \n", data);
38+
39+
if (expected_data[address_idx][word_idx] != data) {
40+
uprintf(console, "Expected: 0x%x\n", expected_data[address_idx][word_idx]);
41+
uprintf(console, "ROM Content mismatch Error. Terminating ROM CTRL read test\n");
42+
43+
return false;
44+
}
45+
}
46+
}
47+
48+
return true;
49+
}
50+
51+
bool test_main()
52+
{
53+
rom_t rom = mocha_system_rom();
54+
uart_t console = mocha_system_uart();
55+
bool read_test_res;
56+
57+
uart_init(console);
58+
59+
read_test_res = rom_read_test(rom, console);
60+
61+
return read_test_res;
62+
}

0 commit comments

Comments
 (0)