Skip to content

Commit 0ce9904

Browse files
committed
boards: qemu: combine riscv boards
combine riscv boards and use the dt props to configure qemu with the right riscv isa and extensions Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
1 parent a37351d commit 0ce9904

22 files changed

+369
-0
lines changed

boards/qemu/riscv/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config BOARD_QEMU_RISCV
5+
select QEMU_TARGET
6+
select HAS_COVERAGE_SUPPORT
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if BOARD_QEMU_RISCV
5+
6+
# Use thread local storage by default so that this feature gets more CI coverage.
7+
configdefault THREAD_LOCAL_STORAGE
8+
default y
9+
10+
configdefault BUILD_OUTPUT_BIN
11+
default n
12+
13+
configdefault QEMU_ICOUNT_SHIFT
14+
default 6
15+
16+
endif # BOARD_QEMU_RISCV
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config BOARD_QEMU_RISCV
5+
select SOC_QEMU_VIRT_RISCV32 if BOARD_QEMU_RISCV_QEMU_VIRT_RISCV32 || BOARD_QEMU_RISCV_QEMU_VIRT_RISCV32_SMP
6+
select SOC_QEMU_VIRT_RISCV32E if BOARD_QEMU_RISCV_QEMU_VIRT_RISCV32E
7+
select SOC_QEMU_VIRT_RISCV64 if BOARD_QEMU_RISCV_QEMU_VIRT_RISCV64 || BOARD_QEMU_RISCV_QEMU_VIRT_RISCV64_SMP

boards/qemu/riscv/board.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
set(SUPPORTED_EMU_PLATFORMS qemu)
5+
6+
set(riscv_isa_extensions)
7+
set(riscv_isa_base)
8+
dt_prop(riscv_isa_extensions PATH "/cpus/cpu@0" PROPERTY "riscv,isa-extensions" REQUIRED)
9+
dt_prop(riscv_isa_base PATH "/cpus/cpu@0" PROPERTY "riscv,isa-base" REQUIRED)
10+
11+
set(qemu_riscv_cpu "${riscv_isa_base}")
12+
foreach(ext IN LISTS riscv_isa_extensions)
13+
if(ext)
14+
string(APPEND qemu_riscv_cpu ",${ext}=on")
15+
endif()
16+
endforeach()
17+
18+
if(CONFIG_RISCV_PMP)
19+
string(APPEND qemu_riscv_cpu ",pmp=on,u=on")
20+
endif()
21+
22+
if(CONFIG_64BIT)
23+
set(QEMU_binary_suffix riscv64)
24+
else()
25+
set(QEMU_binary_suffix riscv32)
26+
endif()
27+
28+
set(QEMU_CPU_TYPE_${ARCH} "${qemu_riscv_cpu}")
29+
30+
set(QEMU_FLAGS_${ARCH}
31+
-nographic
32+
-machine virt
33+
-bios none
34+
-m 256
35+
-cpu ${qemu_riscv_cpu}
36+
)
37+
board_set_debugger_ifnset(qemu)

boards/qemu/riscv/board.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
board:
2+
name: qemu_riscv
3+
full_name: QEMU Emulation for RISCV
4+
vendor: qemu
5+
socs:
6+
- name: qemu_virt_riscv32
7+
variants:
8+
- name: smp
9+
- name: qemu_virt_riscv32e
10+
- name: qemu_virt_riscv64
11+
variants:
12+
- name: smp

boards/qemu/riscv/doc/index.rst

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
.. zephyr:board:: qemu_riscv
2+
3+
Overview
4+
********
5+
6+
The RISCV QEMU board configuration is used to emulate the RISCV architecture.
7+
8+
Get the Toolchain and QEMU
9+
**************************
10+
11+
The minimum version of the `Zephyr SDK tools
12+
<https://github.com/zephyrproject-rtos/sdk-ng/releases>`_
13+
with toolchain and QEMU support for the RISCV64 architecture is v0.10.2.
14+
Please see the :ref:`installation instructions <install-required-tools>`
15+
for more details.
16+
17+
Programming and Debugging
18+
*************************
19+
20+
.. zephyr:board-supported-runners::
21+
22+
Applications for the ``qemu_riscv`` board configuration can be built and run in
23+
the usual way for emulated boards (see :ref:`build_an_application` and
24+
:ref:`application_run` for more details).
25+
26+
Flashing
27+
========
28+
29+
While this board is emulated and you can't "flash" it, you can use this
30+
configuration to run basic Zephyr applications and kernel tests in the QEMU
31+
emulated environment. For example, with the :zephyr:code-sample:`synchronization` sample:
32+
33+
.. zephyr-app-commands::
34+
:zephyr-app: samples/synchronization
35+
:host-os: unix
36+
:board: qemu_riscv/qemu_virt_riscv32
37+
:goals: run
38+
39+
40+
.. zephyr-app-commands::
41+
:zephyr-app: samples/synchronization
42+
:host-os: unix
43+
:board: qemu_riscv/qemu_virt_riscv32e
44+
:goals: run
45+
46+
47+
.. zephyr-app-commands::
48+
:zephyr-app: samples/synchronization
49+
:host-os: unix
50+
:board: qemu_riscv/qemu_virt_riscv64
51+
:goals: run
52+
53+
This will build an image with the synchronization sample app, boot it using
54+
QEMU, and display the following console output:
55+
56+
.. code-block:: console
57+
58+
***** BOOTING ZEPHYR OS v1.8.99 - BUILD: Jun 27 2017 13:09:26 *****
59+
threadA: Hello World from riscv64!
60+
threadB: Hello World from riscv64!
61+
threadA: Hello World from riscv64!
62+
threadB: Hello World from riscv64!
63+
threadA: Hello World from riscv64!
64+
threadB: Hello World from riscv64!
65+
threadA: Hello World from riscv64!
66+
threadB: Hello World from riscv64!
67+
threadA: Hello World from riscv64!
68+
threadB: Hello World from riscv64!
69+
70+
Exit QEMU by pressing :kbd:`CTRL+A` :kbd:`x`.
71+
72+
Debugging
73+
=========
74+
75+
Refer to the detailed overview about :ref:`application_debugging`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
/ {
9+
chosen {
10+
zephyr,console = &uart0;
11+
zephyr,shell-uart = &uart0;
12+
zephyr,sram = &ram0;
13+
};
14+
};
15+
16+
&uart0 {
17+
status = "okay";
18+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
*/
7+
8+
/dts-v1/;
9+
10+
#include <qemu/virt-riscv32.dtsi>
11+
#include "qemu_riscv_qemu_virt_riscv.dtsi"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
identifier: qemu_riscv/qemu_virt_riscv32
2+
name: QEMU Emulation for RISC-V 32-bit
3+
type: qemu
4+
simulation:
5+
- name: qemu
6+
arch: riscv
7+
toolchain:
8+
- zephyr
9+
supported:
10+
- netif
11+
ram: 262144
12+
flash: 32768
13+
testing:
14+
default: true
15+
ignore_tags:
16+
- net
17+
- bluetooth
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_CONSOLE=y
5+
CONFIG_SERIAL=y
6+
CONFIG_UART_CONSOLE=y
7+
CONFIG_STACK_SENTINEL=y
8+
CONFIG_XIP=n
9+
CONFIG_RISCV_PMP=y

0 commit comments

Comments
 (0)