Skip to content

Apache NuttX RTOS for Sophgo SG2000 RISC-V SoC (Milk-V Duo S SBC)

Compare
Choose a tag to compare
@lupyuen lupyuen released this 17 Jun 03:31
· 1 commit to sg2000c since this release

See apache#12510

Build Script:

#!/usr/bin/env bash
#  Build NuttX for SG2000

## TODO: Set PATH
export PATH="$HOME/xpack-riscv-none-elf-gcc-13.2.0-2/bin:$PATH"

rm init.S
rm initrd
rm -r boards/risc-v/sg2000/duos/src/etctmp

set -e  #  Exit when any command fails
set -x  #  Echo commands

## Build NuttX
function build_nuttx {

  ## Go to NuttX Folder
  pushd ../nuttx

  ## Build NuttX
  make -j 8

  ## Return to previous folder
  popd
}

## Build Apps Filesystem
function build_apps {

  ## Go to NuttX Folder
  pushd ../nuttx

  ## Build Apps Filesystem
  make -j 8 export
  pushd ../apps
  ./tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz
  make -j 8 import
  popd

  ## Return to previous folder
  popd
}

## Pull updates
git pull && git status && hash1=`git rev-parse HEAD`
pushd ../apps
git pull && git status && hash2=`git rev-parse HEAD`
popd
echo NuttX Source: https://github.com/apache/nuttx/tree/$hash1 >nuttx.hash
echo NuttX Apps: https://github.com/apache/nuttx-apps/tree/$hash2 >>nuttx.hash

## Show the versions of GCC and Zig
riscv-none-elf-gcc -v

## Configure build
tools/configure.sh duos:nsh || true

## Build NuttX
build_nuttx

## Build Apps Filesystem
build_apps

## Add a.out to Apps Filesystem for TCC
rm -f /tmp/pattern.txt
start=$((0x22056900))
set +x  #  Don't echo commands
for i in {0..1023}
do
  printf 0x%x\\n $(($start + $i)) >> /tmp/pattern.txt
done
set -x  #  Echo commands
cat /tmp/pattern.txt \
  | xxd -revert -plain \
  >../apps/bin/a.out

## Generate Initial RAM Disk
genromfs -f initrd -d ../apps/bin -V "NuttXBootVol"

## Show the size
riscv-none-elf-size nuttx

## Export the Binary Image to `nuttx.bin`
riscv-none-elf-objcopy \
  -O binary \
  nuttx \
  nuttx.bin

## Prepare a Padding with 64 KB of zeroes
head -c 65536 /dev/zero >/tmp/nuttx.pad

## Append Padding and Initial RAM Disk to NuttX Kernel
cat nuttx.bin /tmp/nuttx.pad initrd \
  >Image

## Copy the config
cp .config nuttx.config

## Dump the disassembly to nuttx.S
riscv-none-elf-objdump \
  --syms --source --reloc --demangle --line-numbers --wide \
  --debugging \
  nuttx \
  >nuttx.S \
  2>&1

## Dump the init disassembly to init.S
riscv-none-elf-objdump \
  --syms --source --reloc --demangle --line-numbers --wide \
  --debugging \
  ../apps/bin/init \
  >init.S \
  2>&1

## Dump the hello disassembly to hello.S
riscv-none-elf-objdump \
  --syms --source --reloc --demangle --line-numbers --wide \
  --debugging \
  ../apps/bin/hello \
  >hello.S \
  2>&1

## Copy NuttX Image to TFTP Server
scp Image tftpserver:/tftpboot/Image-sg2000
ssh tftpserver ls -l /tftpboot/Image-sg2000

## Check Coding Style
../nxstyle .gitignore
../nxstyle arch/risc-v/Kconfig
../nxstyle arch/risc-v/include/sg2000/chip.h
../nxstyle arch/risc-v/include/sg2000/irq.h
../nxstyle arch/risc-v/src/sg2000/Kconfig
../nxstyle arch/risc-v/src/sg2000/Make.defs
../nxstyle arch/risc-v/src/sg2000/chip.h
../nxstyle arch/risc-v/src/sg2000/hardware/sg2000_memorymap.h
../nxstyle arch/risc-v/src/sg2000/hardware/sg2000_plic.h
../nxstyle arch/risc-v/src/sg2000/sg2000_allocateheap.c
../nxstyle arch/risc-v/src/sg2000/sg2000_head.S
../nxstyle arch/risc-v/src/sg2000/sg2000_irq.c
../nxstyle arch/risc-v/src/sg2000/sg2000_irq_dispatch.c
../nxstyle arch/risc-v/src/sg2000/sg2000_memorymap.h
../nxstyle arch/risc-v/src/sg2000/sg2000_mm_init.c
../nxstyle arch/risc-v/src/sg2000/sg2000_mm_init.h
../nxstyle arch/risc-v/src/sg2000/sg2000_pgalloc.c
../nxstyle arch/risc-v/src/sg2000/sg2000_start.c
../nxstyle arch/risc-v/src/sg2000/sg2000_timerisr.c
../nxstyle boards/Kconfig
../nxstyle boards/risc-v/sg2000/duos/Kconfig
../nxstyle boards/risc-v/sg2000/duos/configs/nsh/defconfig
../nxstyle boards/risc-v/sg2000/duos/include/board.h
../nxstyle boards/risc-v/sg2000/duos/include/board_memorymap.h
../nxstyle boards/risc-v/sg2000/duos/scripts/Make.defs
../nxstyle boards/risc-v/sg2000/duos/scripts/ld.script
../nxstyle boards/risc-v/sg2000/duos/src/.gitignore
../nxstyle boards/risc-v/sg2000/duos/src/Makefile
../nxstyle boards/risc-v/sg2000/duos/src/etc/init.d/rc.sysinit
../nxstyle boards/risc-v/sg2000/duos/src/etc/init.d/rcS
../nxstyle boards/risc-v/sg2000/duos/src/sg2000_appinit.c
../nxstyle drivers/serial/uart_16550.c

## Run the firmware
script /tmp/nuttx-sg2000.log screen /dev/tty.usbserial-0001 115200