forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: SoC: NSIM reorganization #7
Draft
kokas-a
wants to merge
1
commit into
agishev_foss_main
Choose a base branch
from
nsim_soc_reorg
base: agishev_foss_main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) 2024 Synopsys, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
if BOARD_NSIM_ARC_V_RMX500 | ||
|
||
config SYS_CLOCK_TICKS_PER_SEC | ||
default 1000 | ||
|
||
config SYS_CLOCK_HW_CYCLES_PER_SEC | ||
default 5000000 | ||
|
||
endif # BOARD_NSIM_ARC_V_RMX500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright (c) 2024 Synopsys, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
config BOARD_NSIM_ARC_V | ||
select SOC_RMX500 if BOARD_NSIM_ARC_V_RMX500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
set(SUPPORTED_EMU_PLATFORMS nsim) | ||
|
||
string(SUBSTRING "${BOARD_QUALIFIERS}" 1 -1 NSIM_BASE_FILENAME) | ||
string(REPLACE "/" "_" NSIM_BASE_FILENAME "${NSIM_BASE_FILENAME}") | ||
|
||
board_set_flasher_ifnset(arc-nsim) | ||
board_set_debugger_ifnset(arc-nsim) | ||
|
||
set(NSIM_PROPS "${NSIM_BASE_FILENAME}.props") | ||
board_runner_args(arc-nsim "--props=${NSIM_PROPS}") | ||
|
||
board_finalize_runner_args(arc-nsim) | ||
include(${ZEPHYR_BASE}/boards/common/mdb-nsim.board.cmake) | ||
include(${ZEPHYR_BASE}/boards/common/mdb-hw.board.cmake) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
board: | ||
name: nsim_arc_v | ||
vendor: snps | ||
socs: | ||
- name: rmx500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
.. _nsim_arc_v: | ||
|
||
DesignWare RISC-V nSIM and HAPS FPGA boards | ||
########################################### | ||
|
||
Overview | ||
******** | ||
|
||
This platform can be used to run Zephyr RTOS on the widest possible range of Synopsys RISC-V processors in | ||
simulation with `Designware ARC nSIM`_ or run same images on FPGA prototyping platform `HAPS`_. The | ||
platform includes the following features: | ||
|
||
* RISC-V processor core, which implements riscv32 ISA | ||
* Virtual serial console (a standard ``ns16550`` UART model) | ||
|
||
There are multiple supported board targets for that platform. Some but not all of currently | ||
available targets are listed below: | ||
|
||
* ``nsim_arc_v/rmx500`` - Synopsys RISC-V RMX500 core | ||
|
||
.. _board_nsim_arc_v_prop_files: | ||
|
||
It is recommended to look at precise description of a particular board target in ``.props`` | ||
files in :zephyr_file:`boards/snps/nsim_arc_v/support/` directory to understand | ||
which options are configured and so will be used on invocation of the simulator. | ||
|
||
.. warning:: | ||
All nSIM targets are used for demo and testing purposes. They are not meant to | ||
represent any real system and so might be renamed, removed or modified at any point. | ||
|
||
Programming and Debugging | ||
************************* | ||
|
||
Required Hardware and Software | ||
============================== | ||
|
||
To run single-core Zephyr RTOS applications in simulation on this board, | ||
either `DesignWare ARC nSIM`_ or `DesignWare ARC Free nSIM`_ is required. | ||
|
||
Building & Running Sample Applications | ||
====================================== | ||
|
||
Most board targets support building with both GNU and ARC MWDT toolchains, however | ||
there might be exceptions from that, especially for newly added targets. You can check supported | ||
toolchains for the board targets in the corresponding ``.yaml`` file. | ||
|
||
I.e. for the ``nsim_arc_v/rmx500`` board we can check :zephyr_file:`boards/snps/nsim_arc_v/nsim_arc_v_rmx500.yaml` | ||
|
||
The supported toolchains are listed in ``toolchain:`` array in ``.yaml`` file, where we can find: | ||
|
||
* **zephyr** - implies RISC-V GNU toolchain from Zephyr SDK. You can find more information about | ||
Zephyr SDK :ref:`here <toolchain_zephyr_sdk>`. | ||
* **cross-compile** - implies RISC-V GNU cross toolchain, which is not a part of Zephyr SDK. Note that | ||
some (especially new) board targets may declare ``cross-compile`` toolchain support without | ||
``zephyr`` toolchain support because corresponding target CPU support hasn't been added to Zephyr | ||
SDK yet. You can find more information about its usage here: :ref:`here <other_x_compilers>`. | ||
* **arcmwdt** - implies proprietary ARC MWDT toolchain. You can find more information about its | ||
usage here: :ref:`here <toolchain_designware_arc_mwdt>`. | ||
|
||
.. note:: | ||
Note that even if both GNU and MWDT toolchain support is declared for the target some tests or | ||
samples can be only built with either GNU or MWDT toolchain due to some features limited to a | ||
particular toolchain. | ||
|
||
Use this configuration to run basic Zephyr applications and kernel tests in | ||
nSIM, for example, with the :zephyr:code-sample:`synchronization` sample: | ||
|
||
.. zephyr-app-commands:: | ||
:zephyr-app: samples/synchronization | ||
:host-os: unix | ||
:board: nsim_arc_v/rmx500 | ||
:goals: flash | ||
|
||
This will build an image with the synchronization sample app, boot it using | ||
nSIM, and display the following console output: | ||
|
||
.. code-block:: console | ||
|
||
*** Booting Zephyr OS build zephyr-v3.2.0-3948-gd351a024dc87 *** | ||
thread_a: Hello World from cpu 0 on nsim_arc_v! | ||
thread_b: Hello World from cpu 0 on nsim_arc_v! | ||
thread_a: Hello World from cpu 0 on nsim_arc_v! | ||
thread_b: Hello World from cpu 0 on nsim_arc_v! | ||
thread_a: Hello World from cpu 0 on nsim_arc_v! | ||
|
||
|
||
.. note:: | ||
To exit the simulator, use :kbd:`Ctrl+]`, then :kbd:`Ctrl+c` | ||
|
||
.. _board_nsim_arc_v_verbose_build: | ||
|
||
.. tip:: | ||
You can get more details about the building process by running build in verbose mode. It can be | ||
done by passing ``-v`` flag to the west: ``west -v build -b nsim_hs samples/synchronization`` | ||
|
||
Debugging | ||
========= | ||
|
||
.. _board_nsim_arc_v_debugging_gdb: | ||
|
||
Debugging with GDB | ||
------------------ | ||
|
||
.. note:: | ||
Debugging on nSIM via GDB is only supported on single-core targets (which use standalone | ||
nSIM). | ||
|
||
.. note:: | ||
The normal ``west debug`` command won't work for debugging applications using nsim boards | ||
because both the nSIM simulator and the debugger use the same console for | ||
input / output. | ||
In case of GDB debugger it's possible to use a separate terminal windows for GDB and nSIM to | ||
avoid intermixing their output. | ||
|
||
After building your application, open two terminal windows. In terminal one, use nSIM to start a GDB | ||
server and wait for a remote connection with following command: | ||
|
||
.. code-block:: console | ||
|
||
west debugserver --runner arc-nsim | ||
|
||
In terminal two, connect to the GDB server using RISC-V GDB. You can find it in Zephyr SDK: | ||
|
||
* you should use :file:`riscv64-zephyr-elf-gdb` | ||
|
||
This command loads the symbol table from the elf binary file, for example the | ||
:file:`build/zephyr/zephyr.elf` file: | ||
|
||
.. code-block:: console | ||
|
||
riscv64-zephyr-elf-gdb -ex 'target remote localhost:3333' -ex load build/zephyr/zephyr.elf | ||
|
||
Now the debug environment has been set up, and it's possible to debug the application with gdb | ||
commands. | ||
|
||
Modifying the configuration | ||
*************************** | ||
|
||
If modification of existing nsim configuration is required or even there's a need in creation of a | ||
new one it's required to maintain alignment between | ||
|
||
* Zephyr OS configuration | ||
* nSIM & MDB configuration | ||
* GNU & MWDT toolchain compiler options | ||
|
||
.. note:: | ||
The ``.tcf`` configuration files are not supported by Zephyr directly. There are multiple | ||
reasons for that. ``.tcf`` perfectly suits building of bare-metal single-thread application - | ||
in that case all the compiler options from ``.tcf`` are passed to the compiler, so all the HW | ||
features are used by the application and optimal code is being generated. | ||
The situation is completely different when multi-thread feature-rich operation system is | ||
considered. Of course it is still possible to build all the code with all the | ||
options from ``.tcf`` - but that may be far from optimal solution. For example, such approach | ||
require so save & restore full register context for all tasks (and sometimes even for | ||
interrupts). And for DSP-enabled or for FPU-enabled systems that leads to dozens of extra | ||
registers save and restore even if the most of the user and kernel tasks don't actually use | ||
DSP or FPU. Instead we prefer to fine-tune the HW features usage which (with all its pros) | ||
require us to maintain them separately from ``.tcf`` configuration. | ||
|
||
|
||
Zephyr OS configuration | ||
======================= | ||
|
||
Zephyr OS configuration is defined via Kconfig and Device tree. These are non RISC-V-specific | ||
mechanisms which are described in :ref:`board porting guide <board_porting_guide>`. | ||
|
||
It is advised to look for ``<board_name>_defconfig``, ``<board_name>.dts`` and | ||
``<board_name>.yaml`` as an entry point for board target. | ||
|
||
nSIM configuration | ||
================== | ||
|
||
nSIM configuration is defined in :ref:`props and args files <board_nsim_arc_v_prop_files>`. | ||
Generally they are identical to the values from corresponding ``.tcf`` configuration with few | ||
exceptions: | ||
|
||
* The UART model is added | ||
* CLINT model is added | ||
|
||
GNU & MWDT toolchain compiler options | ||
===================================== | ||
|
||
The hardware-specific compiler options are set in corresponding SoC cmake file. For ``nsim_arc_v`` board | ||
it is :zephyr_file:`soc/snps/nsim_arc_v/CMakeLists.txt`. | ||
|
||
For the GNU toolchain the basic configuration is set via ``-mcpu`` which is defined in generic code | ||
and based on the selected CPU model via Kconfig. It still can be forcefully set to required value | ||
on SoC level. | ||
|
||
.. note:: | ||
The non hardware-specific compiler options like optimizations, library selections, C / C++ | ||
language options are still set in Zephyr generic code. It could be observed by | ||
:ref:`running build in verbose mode <board_nsim_arc_v_verbose_build>`. | ||
|
||
References | ||
********** | ||
|
||
.. _Designware ARC nSIM: https://www.synopsys.com/dw/ipdir.php?ds=sim_nsim | ||
.. _DesignWare ARC Free nSIM: https://www.synopsys.com/cgi-bin/dwarcnsim/req1.cgi | ||
.. _HAPS: https://www.synopsys.com/verification/prototyping/haps.html | ||
.. _ARC MWDT: https://www.synopsys.com/dw/ipdir.php?ds=sw_metaware |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/dts-v1/; | ||
|
||
#include "rmx500.dtsi" | ||
|
||
/ { | ||
model = "Synopsys Rmx500"; | ||
compatible = "snps,rmx500"; | ||
|
||
aliases { | ||
uart-0 = &uart0; | ||
}; | ||
|
||
chosen { | ||
zephyr,sram = &ddr0; | ||
zephyr,console = &uart0; | ||
zephyr,shell-uart = &uart0; | ||
}; | ||
|
||
}; | ||
|
||
&uart0 { | ||
status = "okay"; | ||
current-speed = <115200>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
identifier: nsim_arc_v/rmx500 | ||
name: Synopsys rmx500 | ||
simulation: nsim | ||
simulation_exec: nsimdrv | ||
type: sim | ||
arch: riscv | ||
toolchain: | ||
- zephyr | ||
- cross-compile | ||
testing: | ||
ignore_tags: | ||
- net | ||
- bluetooth | ||
vendor: snps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright (c) 2024 Synopsys, Inc. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
CONFIG_XIP=n | ||
CONFIG_CONSOLE=y | ||
CONFIG_SERIAL=y | ||
CONFIG_UART_CONSOLE=y | ||
CONFIG_BUILD_OUTPUT_HEX=y | ||
CONFIG_DEBUG_OPTIMIZATIONS=y | ||
CONFIG_INCLUDE_RESET_VECTOR=y | ||
CONFIG_LOG=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "rmx5xx.dtsi" | ||
|
||
/ { | ||
ddr0: memory@80000000 { | ||
device_type = "memory"; | ||
reg = <0x80000000 0x10000000>; /* 256 MB */ | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/ { | ||
#address-cells = <1>; | ||
#size-cells = <1>; | ||
|
||
cpus { | ||
timebase-frequency = <5000000>; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
|
||
cpu0: cpu@0 { | ||
compatible = "snps,av5rmx", "riscv"; | ||
device_type = "cpu"; | ||
reg = <0>; | ||
clock-frequency = <5000000>; | ||
riscv,isa = "rv32gc"; | ||
#cooling-cells = <2>; | ||
|
||
cpu0_intc: interrupt-controller { | ||
compatible = "riscv,cpu-intc"; | ||
interrupt-controller; | ||
#address-cells = <0>; | ||
#interrupt-cells = <1>; | ||
}; | ||
}; | ||
}; | ||
|
||
soc { | ||
compatible = "simple-bus"; | ||
ranges; | ||
interrupt-parent = <&clint>; | ||
#address-cells = <1>; | ||
#size-cells = <1>; | ||
|
||
clint: clint@2000000 { | ||
compatible = "sifive,clint0"; | ||
reg = <0x2000000 0x1000>; | ||
interrupts-extended = <&cpu0_intc 3 &cpu0_intc 7>; | ||
interrupt-names = "soft0", "timer0"; | ||
}; | ||
|
||
uart0: serial@10000000{ | ||
compatible = "ns16550", "snps,dw-apb-uart"; | ||
reg = <0x10000000 0x400>; | ||
reg-shift = <2>; | ||
clock-frequency = <50000000>; | ||
status = "disabled"; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
nsim_isa_family=rv32 | ||
nsim_isa_ext=+Zicsr.+Zifencei | ||
# nsim_isa_ext=-all.i.zicsr.zifencei.zihintpause.a.m.zba.zbb.zbs.zca.zcb.zcmp.zcmt.zicbom | ||
nsim_isa_big_endian=0 | ||
nsim_mem-dev=clint,base=0x2000000,size=4096 | ||
nsim_mem-dev=uart0,kind=16550,base=0x10000000,irq=24 | ||
nsim_mem-dev=plic,base=0xc000000,size=0x04000000,interrupts=128,priorities=16 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering what is this interrupt controller. I'd expect that CLINT should be the root interrupt controller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not pretty sure about this part. It looks like interface for CLINT. And CLINT has reference to cpu0_intc