Skip to content

Commit

Permalink
SoC: NSIM reorganization
Browse files Browse the repository at this point in the history
NSIM reorganization

Signed-off-by: Nikolay Agishev <[email protected]>
  • Loading branch information
Nikolay Agishev committed May 13, 2024
1 parent b1de9a6 commit 78b5f1c
Show file tree
Hide file tree
Showing 162 changed files with 821 additions and 264 deletions.
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.
12 changes: 12 additions & 0 deletions boards/snps/nsim/arc_v/Kconfig.defconfig
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
5 changes: 5 additions & 0 deletions boards/snps/nsim/arc_v/Kconfig.nsim_arc_v
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
16 changes: 16 additions & 0 deletions boards/snps/nsim/arc_v/board.cmake
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)
5 changes: 5 additions & 0 deletions boards/snps/nsim/arc_v/board.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
board:
name: nsim_arc_v
vendor: snps
socs:
- name: rmx500
201 changes: 201 additions & 0 deletions boards/snps/nsim/arc_v/doc/index.rst
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
24 changes: 24 additions & 0 deletions boards/snps/nsim/arc_v/nsim_arc_v_rmx500.dts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/dts-v1/;

#include "rmx500.dtsi"

/ {
model = "Synpsys 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>;
};
14 changes: 14 additions & 0 deletions boards/snps/nsim/arc_v/nsim_arc_v_rmx500.yaml
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
11 changes: 11 additions & 0 deletions boards/snps/nsim/arc_v/nsim_arc_v_rmx500_defconfig
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
8 changes: 8 additions & 0 deletions boards/snps/nsim/arc_v/rmx500.dtsi
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 */
};
};
50 changes: 50 additions & 0 deletions boards/snps/nsim/arc_v/rmx5xx.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/ {
#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 = "rv64imafdc";
#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>;
dma-noncoherent;
#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";
};
};
};
9 changes: 9 additions & 0 deletions boards/snps/nsim/arc_v/support/rmx500.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
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_isa_host_timer=0
# nsim_isa_host_timer_mhz=50
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CONFIG_SOC_NSIM=y
CONFIG_SOC_FAMILY_NSIM_ARC_CLASSIC=y
CONFIG_SOC_NSIM_SEM=y
CONFIG_BOARD_NSIM=y
CONFIG_SYS_CLOCK_TICKS_PER_SEC=100
Expand Down
Loading

0 comments on commit 78b5f1c

Please sign in to comment.