Skip to content

Releases: lupyuen/nuttx-nim

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

29 Dec 05:35
68ee019
Compare
Choose a tag to compare

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'

Nim on NuttX for Ox64

27 Dec 23:43
68ee019
Compare
Choose a tag to compare

NuttX Source: https://github.com/apache/nuttx/tree/7b6952588d6e9ad41fab27b8ffd6e3eb18b8c0eb

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

Build Log: https://gist.github.com/lupyuen/578a7eb2d4d827aa252fff37c172dd18

Build Script:

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

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

rm init.S
rm initrd
rm -r boards/risc-v/bl808/ox64/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
}

## 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 ox64:nsh

## Build NuttX
build_nuttx

## Build Apps Filesystem
build_apps

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

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

scp Image tftpserver:.
ssh tftpserver ls -l Image
echo 'scp tftpserver:Image /tmp/Image && cp /tmp/Image "/Volumes/NO NAME/" && ls -l "/Volumes/NO NAME/Image" && diskutil unmountDisk /dev/disk2 && open -a CoolTerm'

tar cvf /tmp/nimcache.tar /workspaces/bookworm/apps/.nimcache
scp /tmp/nimcache.tar tftpserver:.

exit ####

echo ----- Wait for microSD
set +x  #  Don't echo commands
echo "***** Insert microSD into computer"
while : ; do
  if [ -d "/Volumes/NO NAME" ]
  then
    break
  fi
  sleep 1
done
sleep 1
set -x  #  Echo commands

echo ----- Copy to microSD
cp Image "/Volumes/NO NAME/"
ls -l "/Volumes/NO NAME/Image"

## TODO: Verify that /dev/disk2 is microSD
echo ----- Unmount microSD
diskutil unmountDisk /dev/disk2

## Run the firmware
open -a CoolTerm