Skip to content

Commit 36236e9

Browse files
committed
[sw] Add HW_ID platform check
Update the test framework smoketest to read the HW_ID register, validate it against known values, and fail on an unrecognised ID. Signed-off-by: martin-velay <mvelay@lowrisc.org>
1 parent 214ab93 commit 36236e9

4 files changed

Lines changed: 34 additions & 12 deletions

File tree

sw/device/lib/hal/mocha.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
static const uintptr_t rom_base = 0x80000ul;
1515
static const uintptr_t mailbox_base = 0x20010000ul;
16-
static const uintptr_t dv_test_status_base = 0x20020000ul;
16+
static const uintptr_t dv_window_base = 0x20020000ul;
1717
static const uintptr_t ethernet_base = 0x30000000ul;
1818
static const uintptr_t gpio_base = 0x40000000ul;
1919
static const uintptr_t clkmgr_base = 0x40020000ul;
@@ -193,11 +193,11 @@ void *mocha_system_dram(void)
193193
#endif /* defined(__riscv_zcherihybrid) */
194194
}
195195

196-
void *mocha_system_dv_test_status(void)
196+
dv_window_t mocha_system_dv_window(void)
197197
{
198198
#if defined(__riscv_zcherihybrid)
199-
return create_mmio_capability(dv_test_status_base, 0x100u);
199+
return (dv_window_t)create_mmio_capability(dv_window_base, sizeof(struct dv_window_memory_layout));
200200
#else /* !defined(__riscv_zcherihybrid) */
201-
return (void *)dv_test_status_base;
201+
return (dv_window_t)dv_window_base;
202202
#endif /* defined(__riscv_zcherihybrid) */
203203
}

sw/device/lib/hal/mocha.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#pragma once
88

99
#include "hal/clkmgr.h"
10+
#include "hal/dv.h"
1011
#include "hal/entropy_src.h"
1112
#include "hal/ethernet.h"
1213
#include "hal/gpio.h"
@@ -51,4 +52,10 @@ spi_host_t mocha_system_spi_host(void);
5152
plic_t mocha_system_plic(void);
5253
void *mocha_system_dram(void);
5354

54-
void *mocha_system_dv_test_status(void);
55+
dv_window_t mocha_system_dv_window(void);
56+
57+
enum : uint32_t {
58+
hwid_fpga_genesys2 = 0xau,
59+
hwid_sim_verilator = 0x1au,
60+
hwid_sim_uvm = 0x2au,
61+
};

sw/device/lib/test_framework/main.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include "boot/trap.h"
66
#include "hal/hart.h"
7-
#include "hal/mmio.h"
87
#include "hal/mocha.h"
98
#include "hal/uart.h"
109
#include "runtime/print.h"
@@ -53,11 +52,11 @@ test_exception_handler(struct trap_registers *registers, struct trap_context *co
5352
[[noreturn]] void test_exit(bool success)
5453
{
5554
uart_t console = mocha_system_uart();
56-
void *dv_test_status = mocha_system_dv_test_status();
55+
dv_window_t dv_window = mocha_system_dv_window();
5756

5857
uart_puts(console, "TEST RESULT: ");
5958
uart_puts(console, success ? "PASSED" : "FAILED");
60-
DEV_WRITE(dv_test_status, success ? TEST_STATUS_PASSED : TEST_STATUS_FAILED);
59+
dv_window->test_status = success ? TEST_STATUS_PASSED : TEST_STATUS_FAILED;
6160

6261
uart_putchar(console, '\n');
6362
uart_puts(console, "Safe to exit simulator.");
@@ -75,12 +74,12 @@ test_exception_handler(struct trap_registers *registers, struct trap_context *co
7574
[[noreturn]] void main(void)
7675
{
7776
uart_t console = mocha_system_uart();
78-
void *dv_test_status = mocha_system_dv_test_status();
77+
dv_window_t dv_window = mocha_system_dv_window();
7978

8079
uart_init(console);
8180
// Flush the uart
8281
uart_wait_for(console, uart_status_txidle);
83-
DEV_WRITE(dv_test_status, TEST_STATUS_IN_TEST);
82+
dv_window->test_status = TEST_STATUS_IN_TEST;
8483

8584
bool result = test_main(console);
8685
// Flush the uart

sw/device/tests/test_framework/smoketest.c

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

5-
#include "hal/uart.h"
5+
#include "hal/mocha.h"
66
#include <stdbool.h>
77

88
bool test_main(uart_t console)
99
{
10+
uint32_t hw_id = mocha_system_dv_window()->hw_id;
11+
1012
uart_puts(console, "Test framework smoketest\n");
11-
return true;
13+
14+
switch (hw_id) {
15+
case hwid_fpga_genesys2:
16+
uart_puts(console, "Platform: Genesys2 FPGA\n");
17+
return true;
18+
case hwid_sim_verilator:
19+
uart_puts(console, "Platform: Verilator Simulation\n");
20+
return true;
21+
case hwid_sim_uvm:
22+
uart_puts(console, "Platform: UVM Simulation\n");
23+
return true;
24+
default:
25+
uart_puts(console, "Unknown Hardware ID\n");
26+
return false;
27+
}
1228
}

0 commit comments

Comments
 (0)