Skip to content

Nim on NuttX for QEMU RISC-V (64-bit)

Latest
Compare
Choose a tag to compare
@lupyuen lupyuen released this 29 Dec 05:35
· 5 commits to main since this release
68ee019

NuttX Source: https://github.com/apache/nuttx/tree/a69aadf6adac60011ac83b347fcdde300f8ca96c

NuttX Apps: https://github.com/apache/nuttx-apps/tree/1c8af3517d6b7ce7dcf71c562cc3e5d7b634b54a

Build Log: https://gist.github.com/lupyuen/09e653cbd227b9cdff7cf3cb0a5e1ffa

Build Script:

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

## TODO: Set PATH
export PATH=/home/vscode/.nimble/bin:$PATH
export PATH=/workspaces/bookworm/xpack-riscv-none-elf-gcc-13.2.0-2/bin:$PATH

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
}

## Download the WIP NuttX Source Code
git clone \
  --branch nim \
  https://github.com/lupyuen2/wip-pinephone-nuttx \
  nuttx
git clone \
  --branch nim \
  https://github.com/lupyuen2/wip-pinephone-nuttx-apps \
  apps
cd nuttx

## 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 Nim
riscv-none-elf-gcc -v
nim -v

## Configure build
make distclean || true
tools/configure.sh rv-virt:nsh64

## Build NuttX
build_nuttx

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

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

## 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

## Start the emulator
  qemu-system-riscv64 \
    -semihosting \
    -M virt,aclint=on \
    -cpu rv64 \
    -smp 8 \
    -bios none \
    -kernel nuttx \
    -nographic

## Copy Build Output
rm /tmp/bookworm.tar
tar cvf /tmp/bookworm.tar \
  hello_nim.S \
  hello.S \
  init.S \
  nuttx.S \
  nuttx.config \
  Image \
  nuttx.bin \
  initrd \
  nuttx.hex \
  nuttx.manifest \
  System.map \
  nuttx \
  nuttx.map \
  nuttx.hash
scp /tmp/bookworm.tar tftpserver:.
echo 'scp tftpserver:bookworm.tar /tmp/bookworm.tar && open -a Finder /tmp'