boards/risc-v: Add support for Milk-V Duo S SBC (SOPHGO SG2000 SoC)

This PR adds support for Milk-V Duo S 64-bit RISC-V SBC, based on SOPHGO SG2000 SoC (T-Head C906 Core). Most of the code is derived from NuttX for Ox64 BL808. The source files are explained in the articles here: https://github.com/lupyuen/nuttx-sg2000

Modified Files:

`boards/Kconfig`: Added Milk-V Duo S board

`arch/risc-v/src/sg2000/sg2000_timerisr.c`: Fixed MTIMER_FREQ for sleep() to work correctly

New Files in boards/risc-v/sg2000/milkv_duos:

`src/sg2000_appinit.c`: Startup Code

`include/board.h`: Milk-V Duo S Definitions

`include/board_memorymap.h`: Memory Map

`src/etc/init.d/rc.sysinit`, `rcS`: Startup Script

`src/.gitignore`: Ignore the tmp filesystem

`scripts/ld.script`: Linker Script

`scripts/Make.defs`: Milk-V Duo S Makefile

`src/Makefile`: Milk-V Duo S Makefile

`Kconfig`: Milk-V Duo S Config

`configs/nsh/defconfig`: Build Config for `milkv_duos:nsh`

Updated Documentation:

`platforms/risc-v/sg2000/index.rst`: New page for SOPHGO SG2000 SoC

`platforms/risc-v/sg2000/boards/milkv_duos/index.rst`: Building and booting NuttX for Milk-V Duo S
This commit is contained in:
Lup Yuen Lee 2024-06-17 10:06:17 +08:00 committed by Xiang Xiao
parent 02cce1ec71
commit 008803865f
15 changed files with 918 additions and 1 deletions

View file

@ -0,0 +1,183 @@
============
Milk-V Duo S
============
`Milk-V Duo S <https://milkv.io/duo-s>`_ is a RISC-V Single-Board Computer
based on the SOPHGO SG2000 RISC-V SoC with T-Head C906 64-bit Main Processor,
512 MB of SIP DRAM memory and 100 Mbps Ethernet.
Features
========
- **System on Chip:** SOPHGO SG2000
- **CPU:**
- 64-bit T-Head C906 1.0 GHz (Main Processor)
- 64-bit T-Head C906 700 MHz (Co-Processor)
- 64-bit Arm Cortex-A53 1.0 GHz (Alternate Main Processor)
- **MCU:** 8051 with 6 KB SRAM
- **Memory:** SIP DRAM 512 MB
- **TPU:** 0.5 TOPS INT8
- **Storage:** 1 x microSD Connector, 1 x eMMC Pad
- **USB:** 1 x Type-C for Power and Data or 1 x USB 2.0 A Port Host
- **MIPI CSI:** 1 x 16P FPC Connector (MIPI CSI 2-Lane), 1 x 15P FPC Connector (MIPI CSI 2-Lane)
- **Sensor Support:** 5M @ 30 FPS
- **MIPI DSI:** Via GPIO Header (MIPI DSI 4-Lane)
- **Ethernet:** 100 Mbps Ethernet Port (RJ45)
- **Wireless:** Optional Wi-Fi 6 / Bluetooth 5
- **Audio:** Via GPIO Pin
- **GPIO:** Up to 39 x GPIO Pin (via 2 x 26-Pin GPIO Header)
- **Others:** 1 x Boot Switch, 1 x Recovery Key, 1 x Reset Key
Serial Console
==============
A **USB Serial Adapter** is required to run NuttX on Milk-V Duo S,
**CP2102** is recommended. CH340 might not work correctly with Duo S.
Connect the USB Serial Adapter to Duo S Serial Console at:
========== ================
USB Serial Milk-V Duo S Pin
========== ================
GND Pin 6 (GND)
RX Pin 8 (XGPIOA 16 / UART0 TX)
TX Pin 10 (XGPIOA 17 / UART0 RX)
========== ================
On the USB Serial Adapter, set the **Voltage Level** to 3V3.
Connect Duo S to our computer with the USB Serial Adapter.
On our computer, start a Serial Terminal and connect to the USB Serial Port
at **115.2 kbps**:
.. code:: console
$ screen /dev/ttyUSB0 115200
NuttX will appear in the Serial Console when it boots on Duo S.
RISC-V Toolchain
================
Before building NuttX for Milk-V Duo S, download the toolchain for
`xPack GNU RISC-V Embedded GCC (riscv-none-elf) <https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases>`_.
Add the downloaded toolchain ``xpack-riscv-none-elf-gcc-.../bin``
to the ``PATH`` Environment Variable.
Check the RISC-V Toolchain:
.. code:: console
$ riscv-none-elf-gcc -v
Building
========
To build NuttX for Milk-V Duo S, :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 milkv_duos:nsh
$ make
This produces the NuttX Kernel ``nuttx.bin``. Next, build the NuttX Apps Filesystem:
.. code:: console
$ make export
$ pushd ../apps
$ tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz
$ make import
$ popd
$ genromfs -f initrd -d ../apps/bin -V "NuttXBootVol"
This generates the Initial RAM Disk ``initrd``.
Package the NuttX Kernel and Initial RAM Disk into a NuttX Image:
.. code:: console
$ head -c 65536 /dev/zero >/tmp/nuttx.pad
$ cat nuttx.bin /tmp/nuttx.pad initrd >Image-sg2000
The NuttX Image ``Image-sg2000`` will be copied to the TFTP Server in the next step.
Booting
=======
NuttX requires a microSD Card with U-Boot Bootloader. Prepare a
`Linux microSD Card <https://lupyuen.github.io/articles/sg2000#download-the-linux-microsd>`_
for Duo S.
To boot NuttX on Milk-V Duo S, flip the `Main Processor Switch <https://lupyuen.github.io/articles/sg2000#boot-without-microsd>`_
to **RV** (RISC-V).
On our computer, `install the TFTP Server <https://lupyuen.github.io/articles/sg2000#boot-nuttx-over-tftp>`_.
Copy the file ``Image-sg2000`` from the previous section to the TFTP Server,
together with the Device Tree:
.. code:: console
$ wget https://github.com/lupyuen2/wip-nuttx/releases/download/sg2000-1/cv181x_milkv_duos_sd.dtb
$ scp Image-sg2000 \
tftpserver:/tftpfolder/Image-sg2000
$ scp cv181x_milkv_duos_sd.dtb \
tftpserver:/tftpfolder/cv181x_milkv_duos_sd.dtb
Check that Duo S is connected to our computer via a USB Serial Adapter at 115.2 kbps:
.. code:: console
$ screen /dev/ttyUSB0 115200
Insert the microSD Card into Duo S, connect the Ethernet Port and power up via the USB-C Port.
When Duo S boots, press Enter to see the U-Boot Prompt.
Run these commands to `boot NuttX over TFTP <https://lupyuen.github.io/articles/sg2000#boot-nuttx-over-tftp>`_:
.. code:: console
# Change to your TFTP Server
$ setenv tftp_server 192.168.x.x
$ saveenv
$ dhcp ${kernel_addr_r} ${tftp_server}:Image-sg2000
$ tftpboot ${fdt_addr_r} ${tftp_server}:cv181x_milkv_duos_sd.dtb
$ fdt addr ${fdt_addr_r}
$ booti ${kernel_addr_r} - ${fdt_addr_r}
Or configure U-Boot to `boot NuttX automatically <https://lupyuen.github.io/articles/sg2000#boot-nuttx-over-tftp>`_.
NuttX boots on Duo S and NuttShell (nsh) appears in the Serial Console.
To see the available commands in NuttShell:
.. code:: console
$ help
Configurations
==============
nsh
---
Basic configuration that runs NuttShell (nsh).
This configuration is focused on low level, command-line driver testing.
Built-in applications are supported, but none are enabled.
Serial Console is enabled on UART0 at 115.2 kbps.
Peripheral Support
==================
NuttX for Milk-V Duo S supports these peripherals:
======================== ======= =====
Peripheral Support NOTES
======================== ======= =====
UART Yes
======================== ======= =====

View file

@ -0,0 +1,36 @@
=============
SOPHGO SG2000
=============
`SOPHGO SG2000 <https://milkv.io/chips/sg2000>`_ is a 64-bit RISC-V SoC with 2 RISC-V Cores and 1 Arm Core:
- **Main Processor:** T-Head C906 1.0 GHz 64-bit RISC-V Core
- 32 KB I-Cache, 64KB D-Cache
- Integrated Vector and Floating-Point Operation Unit (FPU)
- **Co-Processor:** T-Head C906 700 MHz 64-bit RISC-V Core
- Integrated Floating-Point Unit (FPU)
- **Alternate Main Processor:** Cortex-A53 1.0 GHz 64-bit Arm Core
- 32 KB I-Cache, 32 KB D-Cache
- 128 KB L2 Cache
- Support Neon and Floating-Point Operation Unit (FPU)
- **MCU:** 8051 with 6 KB SRAM
- **TPU:** 0.5 TOPS INT8
- **Memory:** SIP DRAM 512 MB
- **Video Module:** ISP 5M @ 30 FPS, 2L MIPI DSI 5M @ 30 FPS, 4L or 2L+2L MIPI CSI 5M @ 30 FPS, H.265 / H.264 Decoding and Encoding 5M @ 30 FPS
- **Audio Module:** 16-bit Audio Codec, 2 x I2S / PCM, 1 x DMIC
- **Storage:** SPI-NOR, SPI-NAND, eMMC 5.0, 2 x SDIO 3.0
- **Network:** 10M / 100M MAC PHY
- **Security Module:** Crypto, Secure Boot, TRNG, Efuse
- **Peripherals:** 1 x USB 2.0 DRD, 5 x UART, 4 x SPI, 16 x PWM, 1 x IR, 6 x I2C, 6 x ADC, GPIOs
Supported Boards
================
.. toctree::
:glob:
:maxdepth: 1
boards/*/*

View file

@ -38,7 +38,7 @@
* Pre-processor Definitions
****************************************************************************/
#define MTIMER_FREQ 1000000
#define MTIMER_FREQ 25000000ul
/****************************************************************************
* Public Functions

View file

@ -2007,6 +2007,13 @@ config ARCH_BOARD_BL808_OX64
This options selects support for NuttX on PINE64 Ox64 based
on Bouffalo Lab BL808 SoC.
config ARCH_BOARD_SG2000_MILKV_DUOS
bool "Milk-V Duo S"
depends on ARCH_CHIP_SG2000
---help---
This options selects support for NuttX on Milk-V Duo S based
on SOPHGO SG2000 SoC.
config ARCH_BOARD_S32K118EVB
bool "NXP S32K118EVB"
depends on ARCH_CHIP_S32K118
@ -3368,6 +3375,7 @@ config ARCH_BOARD
default "star64" if ARCH_BOARD_JH7110_STAR64
default "canmv230" if ARCH_BOARD_K230_CANMV
default "ox64" if ARCH_BOARD_BL808_OX64
default "milkv_duos" if ARCH_BOARD_SG2000_MILKV_DUOS
default "sabre-6quad" if ARCH_BOARD_SABRE_6QUAD
default "tc397" if ARCH_BOARD_TC397
default "qemu-armv7a" if ARCH_BOARD_QEMU_ARMV7A
@ -4302,6 +4310,9 @@ endif
if ARCH_BOARD_BL808_OX64
source "boards/risc-v/bl808/ox64/Kconfig"
endif
if ARCH_BOARD_SG2000_MILKV_DUOS
source "boards/risc-v/sg2000/milkv_duos/Kconfig"
endif
if ARCH_BOARD_ESP32C3_DEVKIT
source "boards/risc-v/esp32c3-legacy/esp32c3-devkit/Kconfig"
endif

View file

View file

@ -0,0 +1,93 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_DISABLE_OS_API is not set
# CONFIG_NSH_DISABLE_LOSMART is not set
CONFIG_16550_ADDRWIDTH=0
CONFIG_16550_REGINCR=4
CONFIG_16550_UART0=y
CONFIG_16550_UART0_BASE=0x04140000
CONFIG_16550_UART0_CLOCK=24883200
CONFIG_16550_UART0_IRQ=69
CONFIG_16550_UART0_SERIAL_CONSOLE=y
CONFIG_16550_UART=y
CONFIG_16550_WAIT_LCR=y
CONFIG_ARCH="risc-v"
CONFIG_ARCH_ADDRENV=y
CONFIG_ARCH_BOARD="milkv_duos"
CONFIG_ARCH_BOARD_SG2000_MILKV_DUOS=y
CONFIG_ARCH_CHIP="sg2000"
CONFIG_ARCH_CHIP_SG2000=y
CONFIG_ARCH_DATA_NPAGES=128
CONFIG_ARCH_DATA_VBASE=0xC0100000
CONFIG_ARCH_HEAP_NPAGES=128
CONFIG_ARCH_HEAP_VBASE=0xC0200000
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_KERNEL_STACKSIZE=3072
CONFIG_ARCH_PGPOOL_MAPPING=y
CONFIG_ARCH_PGPOOL_PBASE=0x80600000
CONFIG_ARCH_PGPOOL_SIZE=4194304
CONFIG_ARCH_PGPOOL_VBASE=0x80600000
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_TEXT_NPAGES=128
CONFIG_ARCH_TEXT_VBASE=0xC0000000
CONFIG_ARCH_USE_MMU=y
CONFIG_ARCH_USE_MPU=y
CONFIG_ARCH_USE_S_MODE=y
CONFIG_BOARDCTL_ROMDISK=y
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=1120
CONFIG_BUILD_KERNEL=y
CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_ASSERTIONS_EXPRESSION=y
CONFIG_DEBUG_FEATURES=y
CONFIG_DEBUG_FULLOPT=y
CONFIG_DEBUG_SYMBOLS=y
CONFIG_DEV_ZERO=y
CONFIG_ELF=y
CONFIG_EXAMPLES_HELLO=m
CONFIG_FS_PROCFS=y
CONFIG_FS_ROMFS=y
CONFIG_IDLETHREAD_STACKSIZE=3072
CONFIG_INIT_FILEPATH="/system/bin/init"
CONFIG_INIT_MOUNT=y
CONFIG_INIT_MOUNT_FLAGS=0x1
CONFIG_INIT_MOUNT_TARGET="/system/bin"
CONFIG_INIT_STACKSIZE=3072
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_ENVPATH=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_MEMSET_64BIT=y
CONFIG_MEMSET_OPTSPEED=y
CONFIG_MM_PGALLOC=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_FILE_APPS=y
CONFIG_NSH_READLINE=y
CONFIG_PATH_INITIAL="/system/bin"
CONFIG_RAM_SIZE=1048576
CONFIG_RAM_START=0x80200000
CONFIG_RAW_BINARY=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HAVE_PARENT=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_SERIAL_UART_ARCH_MMIO=y
CONFIG_STACK_COLORATION=y
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2021
CONFIG_SYMTAB_ORDEREDBYNAME=y
CONFIG_SYSTEM_NSH=y
CONFIG_SYSTEM_NSH_PROGNAME="init"
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_USEC_PER_TICK=1000

View file

@ -0,0 +1,78 @@
/****************************************************************************
* boards/risc-v/sg2000/milkv_duos/include/board.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_RISCV_SG2000_MILKV_DUOS_INCLUDE_BOARD_H
#define __BOARDS_RISCV_SG2000_MILKV_DUOS_INCLUDE_BOARD_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define LED_STARTED 0 /* N/A */
#define LED_HEAPALLOCATE 1 /* N/A */
#define LED_IRQSENABLED 2 /* N/A */
#define LED_STACKCREATED 3 /* N/A */
#define LED_INIRQ 4 /* N/A */
#define LED_SIGNAL 5 /* N/A */
#define LED_ASSERTION 6 /* N/A */
#define LED_PANIC 7 /* N/A */
#define LED_CPU 8 /* LED */
/****************************************************************************
* Public Types
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: sg2000_boardinitialize
****************************************************************************/
void sg2000_boardinitialize(void);
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_SG2000_MILKV_DUOS_INCLUDE_BOARD_H */

View file

@ -0,0 +1,88 @@
/****************************************************************************
* boards/risc-v/sg2000/milkv_duos/include/board_memorymap.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __BOARDS_RISCV_SG2000_MILKV_DUOS_INCLUDE_BOARD_MEMORYMAP_H
#define __BOARDS_RISCV_SG2000_MILKV_DUOS_INCLUDE_BOARD_MEMORYMAP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* DDR start address */
#define SG2000_DDR_BASE (0x50200000)
#define SG2000_DDR_SIZE (0x03e00000)
/* Kernel code memory (RX) */
#define KFLASH_START (uintptr_t)__kflash_start
#define KFLASH_SIZE (uintptr_t)__kflash_size
#define KSRAM_START (uintptr_t)__ksram_start
#define KSRAM_SIZE (uintptr_t)__ksram_size
#define KSRAM_END (uintptr_t)__ksram_end
/* Kernel RAM (RW) */
#define PGPOOL_START (uintptr_t)__pgheap_start
#define PGPOOL_SIZE (uintptr_t)__pgheap_size
/* Page pool (RWX) */
#define PGPOOL_START (uintptr_t)__pgheap_start
#define PGPOOL_SIZE (uintptr_t)__pgheap_size
#define PGPOOL_END (PGPOOL_START + PGPOOL_SIZE)
/* Ramdisk (RW) */
#define RAMDISK_START (uintptr_t)__ramdisk_start
#define RAMDISK_SIZE (uintptr_t)__ramdisk_size
/****************************************************************************
* Public Data
****************************************************************************/
/* Kernel code memory (RX) */
extern uint8_t __kflash_start[];
extern uint8_t __kflash_size[];
/* Kernel RAM (RW) */
extern uint8_t __ksram_start[];
extern uint8_t __ksram_size[];
extern uint8_t __ksram_end[];
/* Page pool (RWX) */
extern uint8_t __pgheap_start[];
extern uint8_t __pgheap_size[];
/* Ramdisk (RW) */
extern uint8_t __ramdisk_start[];
extern uint8_t __ramdisk_size[];
#endif /* __BOARDS_RISCV_SG2000_MILKV_DUOS_INCLUDE_BOARD_MEMORYMAP_H */

View file

@ -0,0 +1,43 @@
############################################################################
# boards/risc-v/sg2000/milkv_duos/scripts/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/.config
include $(TOPDIR)/tools/Config.mk
include $(TOPDIR)/arch/risc-v/src/common/Toolchain.defs
LDSCRIPT = ld.script
ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)$(LDSCRIPT)
ARCHPICFLAGS = -fpic -msingle-pic-base
CFLAGS := $(ARCHCFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CPICFLAGS = $(ARCHPICFLAGS) $(CFLAGS)
CXXFLAGS := $(ARCHCXXFLAGS) $(ARCHOPTIMIZATION) $(ARCHCPUFLAGS) $(ARCHXXINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS) -pipe
CXXPICFLAGS = $(ARCHPICFLAGS) $(CXXFLAGS)
CPPFLAGS := $(ARCHINCLUDES) $(ARCHDEFINES) $(EXTRAFLAGS)
AFLAGS += $(CFLAGS) -D__ASSEMBLY__
# ELF module definitions
CELFFLAGS = $(CFLAGS)
CXXELFFLAGS = $(CXXFLAGS)
LDELFFLAGS = --oformat elf64-littleriscv
LDELFFLAGS += -r -e main
LDELFFLAGS += -T $(call CONVERT_PATH,$(TOPDIR)/binfmt/libelf/gnu-elf.ld)

View file

@ -0,0 +1,151 @@
/****************************************************************************
* boards/risc-v/sg2000/milkv_duos/scripts/ld.script
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
MEMORY
{
kflash (rx) : ORIGIN = 0x80200000, LENGTH = 2048K /* w/ cache */
ksram (rwx) : ORIGIN = 0x80400000, LENGTH = 2048K /* w/ cache */
pgram (rwx) : ORIGIN = 0x80600000, LENGTH = 4096K /* w/ cache */
ramdisk (rwx) : ORIGIN = 0x80A00000, LENGTH = 16M /* w/ cache */
}
OUTPUT_ARCH("riscv")
/* Provide the kernel boundaries */
__kflash_start = ORIGIN(kflash);
__kflash_size = LENGTH(kflash);
__ksram_start = ORIGIN(ksram);
__ksram_size = LENGTH(ksram);
__ksram_end = ORIGIN(ksram) + LENGTH(ksram);
/* Page heap */
__pgheap_start = ORIGIN(pgram);
__pgheap_size = LENGTH(pgram) + LENGTH(ramdisk);
/* Application ramdisk */
__ramdisk_start = ORIGIN(ramdisk);
__ramdisk_size = LENGTH(ramdisk);
__ramdisk_end = ORIGIN(ramdisk) + LENGTH(ramdisk);
SECTIONS
{
. = 0x80200000;
.text :
{
_stext = . ;
*(.text)
*(.text.*)
*(.gnu.warning)
*(.stub)
*(.glue_7)
*(.glue_7t)
*(.jcr)
/* C++ support: The .init and .fini sections contain specific logic
* to manage static constructors and destructors.
*/
*(.gnu.linkonce.t.*)
*(.init) /* Old ABI */
*(.fini) /* Old ABI */
_etext = . ;
}
.rodata :
{
_srodata = . ;
*(.rodata)
*(.rodata1)
*(.rodata.*)
*(.gnu.linkonce.r*)
_erodata = . ;
}
.tdata : {
_stdata = ABSOLUTE(.);
*(.tdata .tdata.* .gnu.linkonce.td.*);
_etdata = ABSOLUTE(.);
}
.tbss : {
_stbss = ABSOLUTE(.);
*(.tbss .tbss.* .gnu.linkonce.tb.* .tcommon);
_etbss = ABSOLUTE(.);
}
_eronly = ABSOLUTE(.);
.data :
{
_sdata = . ;
*(.data)
*(.data1)
*(.data.*)
*(.gnu.linkonce.d*)
. = ALIGN(4);
_edata = . ;
}
.bss :
{
_sbss = . ;
*(.bss)
*(.bss.*)
*(.sbss)
*(.sbss.*)
*(.gnu.linkonce.b*)
*(COMMON)
. = ALIGN(32);
_ebss = . ;
} > ksram
/* Page tables here, align to 4K boundary */
.pgtables (NOLOAD) : ALIGN(0x1000) {
*(.pgtables)
. = ALIGN(4);
} > ksram
/* Stack top */
.stack_top : {
. = ALIGN(32);
_ebss = ABSOLUTE(.);
} > ksram
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}

View file

@ -0,0 +1,2 @@
etctmp
etctmp.c

View file

@ -0,0 +1,27 @@
############################################################################
# boards/risc-v/sg2000/milkv_duos/src/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
RCSRCS = etc/init.d/rc.sysinit etc/init.d/rcS
CSRCS = sg2000_appinit.c
include $(TOPDIR)/boards/Board.mk

View file

@ -0,0 +1,19 @@
/****************************************************************************
* boards/risc-v/sg2000/milkv_duos/src/etc/init.d/rc.sysinit
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

View file

@ -0,0 +1,19 @@
/****************************************************************************
* boards/risc-v/sg2000/milkv_duos/src/etc/init.d/rcS
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

View file

@ -0,0 +1,167 @@
/****************************************************************************
* boards/risc-v/sg2000/milkv_duos/src/sg2000_appinit.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <stdio.h>
#include <syslog.h>
#include <errno.h>
#include <nuttx/board.h>
#include <nuttx/drivers/ramdisk.h>
#include <sys/mount.h>
#include <sys/boardctl.h>
#include <arch/board/board_memorymap.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Ramdisk Definition */
#define SECTORSIZE 512
#define NSECTORS(b) (((b) + SECTORSIZE - 1) / SECTORSIZE)
#define RAMDISK_DEVICE_MINOR 0
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: mount_ramdisk
*
* Description:
* Mount a ramdisk defined in the ld.script to /dev/ramX. The ramdisk is
* intended to contain a romfs with applications which can be spawned at
* runtime.
*
* Returned Value:
* OK is returned on success.
* -ERRORNO is returned on failure.
*
****************************************************************************/
static int mount_ramdisk(void)
{
int ret;
struct boardioc_romdisk_s desc;
desc.minor = RAMDISK_DEVICE_MINOR;
desc.nsectors = NSECTORS((ssize_t)__ramdisk_size);
desc.sectsize = SECTORSIZE;
desc.image = __ramdisk_start;
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
if (ret < 0)
{
syslog(LOG_ERR, "Ramdisk register failed: %s\n", strerror(errno));
syslog(LOG_ERR, "Ramdisk mountpoint /dev/ram%d\n",
RAMDISK_DEVICE_MINOR);
syslog(LOG_ERR, "Ramdisk length %lu, origin %lx\n",
(ssize_t)__ramdisk_size, (uintptr_t)__ramdisk_start);
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: board_app_initialize
*
* Description:
* Perform architecture specific initialization
*
* Input Parameters:
* arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initialization logic and the
* matching application logic. The value could be such things as a
* mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH,
* or whatever you would like to do with it. Every implementation
* should accept zero/NULL as a default configuration.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* any failure to indicate the nature of the failure.
*
****************************************************************************/
int board_app_initialize(uintptr_t arg)
{
#ifdef CONFIG_BOARD_LATE_INITIALIZE
/* Board initialization already performed by board_late_initialize() */
return OK;
#else
/* Perform board-specific initialization */
#ifdef CONFIG_NSH_ARCHINIT
mount(NULL, "/proc", "procfs", 0, NULL);
#endif
return OK;
#endif
}
/****************************************************************************
* Name: board_late_initialize
*
* Description:
* If CONFIG_BOARD_LATE_INITIALIZE is selected, then an additional
* initialization call will be performed in the boot-up sequence to a
* function called board_late_initialize(). board_late_initialize() will
* be called after up_initialize() and board_early_initialize() and just
* before the initial application is started. This additional
* initialization phase may be used, for example, to initialize board-
* specific device drivers for which board_early_initialize() is not
* suitable.
*
* Waiting for events, use of I2C, SPI, etc are permissible in the context
* of board_late_initialize(). That is because board_late_initialize()
* will run on a temporary, internal kernel thread.
*
****************************************************************************/
void board_late_initialize(void)
{
/* Mount the RAM Disk */
mount_ramdisk();
/* Perform board-specific initialization */
#ifdef CONFIG_NSH_ARCHINIT
mount(NULL, "/proc", "procfs", 0, NULL);
#endif
}