risc-v: Initial support for CanMV-k230 board and K230 chip

The code is mainly derived from the NuttX qemu-rv/rv-virt codebase.

Major changes:

- boards/Kconfig:       add new BOARD_K230_CANMV
- arch/risc-v/Kconfig:  add new CHIP_K230 chip and ARCH_RV_MMIO_BITS
- arch/risc-v/src/common/riscv_mtimer.c: use ARCH_RV_MMIO_BITS to
                        select MMIO access width

New additions:

- arch/risc-v/include/k230/: k230 SoC definitions
- arch/risc-v/src/k230/:     k230 SoC sources
- boards/risc-v/k230/canmv230/:  CanMV-K230 board sources and configs
- Documentation/platforms/risc-v/k230/: simple doc

Note that only FLAT build works for canmv230 now.

This PR has changes in RiscV common layer thus may affect other RiscV ports
It changes the mtime/mtimecmp access control from using config ARCH_RV64 to
newly intorduced config ARCH_RV_MMIO_BITS.

Original design uses ARCH_RV64 to select 64bit MMIO in riscv_mtimer.c, this
can't cope with the situation with K230 --- it has ARCH_RV64 but only can do
32bit MMIO. So a new ARCH_RV_MMIO_BITS config has been introduced. Its value
depicts the MMIO width in bits. The MMIO_BITS defaults to 32/64 for RV32/
RV64 respectively. This allows the macro to replace current use of ARCH_RV64
in riscv_mtimer.c.

The new MMIO_BITS config is a derived one, and for RiscV chips with
equal CPU and MMIO widths there is no need to explicitly set it as the
default rule will do that. Only chips with different CPU and MMIO widths
need set it in Kconfig.

So by design this change should be safe but RiscV ports should be checked.

"ostest" verification has been done for:

- canmv230/nsh
- rv-vivt/nsh
- rv-virt/nsh64

configuration generation and manual check of derived RV_MMIO_BITS has been
done for:

- star64/nsh
- arty_a7/nsh
- bl602evb/nsh

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This commit is contained in:
Yanfeng Liu
2023-12-13 10:59:21 +08:00
committed by Xiang Xiao
parent 751bc1528a
commit 75d0c2946d
35 changed files with 2606 additions and 2 deletions
@@ -0,0 +1,63 @@
=============
CanMV K230
=============
The `Kendryte K230 <https://www.canaan.io/product/k230>`_ SoC contains two indepedent T-Head C908 based RV64GC CPU cores. The CPU1 even has RVV1.0 vector extension and operates at higher speed. The SoC contains accelerators for depth image processing, audio processing and neural network inferencing etc.
The `CanMV K230 <https://developer.canaan-creative.com/k230/dev/zh/CanMV_K230_%E6%95%99%E7%A8%8B.html>`_ is a raspberry-pi sized single board computer with 512MB DRAM and a microSD card slot for booting. It comes with serial console, Ethernet, HDMI and USB/OTG ports. Unfortuunately it doesn't support JTAG alike debugging interfaces.
The `K230 SDK <https://github.com/kendryte/k230_sdk>`_ contains source code, libraries and user guides for booting up an AMP enviroment with Linux on CPU0 and RT-Thread on CPU1.
K230 boots from CPU0 and loads U-Boot into DRAM first, then U-Boot kicks off OpenSBI wrapped Linux/RTT OS images on respective CPU cores accordingly.
The K230 U-Boot operates in machine mode, thus provides an ideal environment for NuttX. allowing one to run flat or kernel builds in theory.
Preparations
============
Please follow the K230 SDK to prepare a booting SD card for the board, or use prebuilt boot image from `here <https://kendryte-download.canaan-creative.com/developer/k230/k230_canmv_sdcard_v1.2_nncase_v2.5.1.img.gz>`_.
Make sure that before trying NuttX:
- The board can boot default SDK image normally.
- U-Boot console can be accessed from host(e.g. `minicom -D /dev/ttyACM0`).
- U-Boot has access to a TFTP service is available.
- You can drop files to the TFTP service folder.
Note for below NuttX tests, the SD image is only used to enter U-Boot console.
RISC-V Toolchain
================
Before building NuttX for Star64, download the **RISC-V Toolchain riscv64-unknown-elf** from `XPack <https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack>`_ or use "gcc-riscv64-unknown-elf" on Ubuntu.
Building
========
To build NuttX for CanMV, :doc:`install the prerequisites </quickstart/install>` and :doc:`clone the git repositories </quickstart/install>` for ``nuttx`` and ``apps``.
Configure the NuttX project and build the project:
.. code:: console
$ cd nuttx
$ tools/configure.sh canmv230:nsh
$ make -j4
There should have `nuttx.bin` generated.
Booting
=======
Copy the `nuttx.bin` to the TFTP service folder and work with the U-Boot console:
.. code:: console
k230# usb start
k230# ping $serverip
k230# tftp 8000000 nuttx.bin
k230# boot_barememtal 0 8000000 $filesize
Then the `nsh> `console should appear, type `help` to see available commands.
@@ -0,0 +1,12 @@
=============
Kendryte K230
=============
Supported Boards
================
.. toctree::
:glob:
:maxdepth: 1
boards/*/*