Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Created August 26, 2023 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lupyuen/62392f5644f903232f5fcde2d5b9a03d to your computer and use it in GitHub Desktop.
Save lupyuen/62392f5644f903232f5fcde2d5b9a03d to your computer and use it in GitHub Desktop.
Shell Script to build and run NuttX for Star64
#!/usr/bin/env bash
## Build and run NuttX for Star64
## TODO: Set PATH
export PATH="$HOME/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-apple-darwin/bin:$PATH"
rm init.S
rm initrd
rm -r boards/risc-v/jh7110/star64/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 export
pushd ../apps
./tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz
make import
popd
## Return to previous folder
popd
}
## Generate FIT Image
function build_fit {
## Generate FIT Image from `nuttx.bin`, `initrd` and `jh7110-visionfive-v2.dtb`.
## `nuttx.its` must be in the same directory as the NuttX binaries!
cp ../nuttx-star64/nuttx.its .
cp ../jh7110-visionfive-v2.dtb .
mkimage \
-f nuttx.its \
-A riscv \
-O linux \
-T flat_dt \
starfiveu.fit
## Copy to microSD
cp starfiveu.fit "/Volumes/NO NAME"
ls -l "/Volumes/NO NAME/starfiveu.fit"
## Unmount microSD
## TODO: Verify that /dev/disk2 is microSD
diskutil unmountDisk /dev/disk2
}
## 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
riscv64-unknown-elf-gcc -v
## TODO: Configure build
## tools/configure.sh star64: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
riscv64-unknown-elf-size nuttx
## Export the Binary Image to nuttx.bin
riscv64-unknown-elf-objcopy \
-O binary \
nuttx \
nuttx.bin
## Copy the config
cp .config nuttx.config
## Copy NuttX Binary Image, Device Tree and Initial RAM Disk to TFTP Folder
cp nuttx.bin $HOME/tftproot/Image
cp ../jh7110-star64-pine64.dtb $HOME/tftproot
cp initrd $HOME/tftproot
ls -l $HOME/tftproot/Image
## Copy NuttX Binary Image, Device Tree and Initial RAM Disk to TFTP Server
scp nuttx.bin tftpserver:/tftpboot/Image
scp ../jh7110-star64-pine64.dtb tftpserver:/tftpboot
scp initrd tftpserver:/tftpboot
ssh tftpserver ls -l /tftpboot/Image
## Dump the disassembly to nuttx.S
riscv64-unknown-elf-objdump \
-t -S --demangle --line-numbers --wide \
nuttx \
>nuttx.S \
2>&1
## Dump the init disassembly to init.S
riscv64-unknown-elf-objdump \
-t -S --demangle --line-numbers --wide \
../apps/bin/init \
>init.S \
2>&1
## TODO: Check coding style
## ../nxstyle arch/risc-v/src/jh7110/jh7110_start.c
## Wait for USB Serial to be connected
set +x # Don't echo commands
echo "***** Connect Star64 to USB Serial"
while : ; do
[[ -c "/dev/tty.usbserial-1420" ]] && break
sleep 1
done
set -x # Echo commands
## Run NuttX over USB Serial
script /tmp/run.log screen /dev/tty.usbserial-1420 115200
## TODO: Build Documentation
## cd Documentation
## pip3 install pipenv
## pipenv install
## pipenv shell
## clear ; rm -r _build ; make html
## clear ; rm -r _build ; make html 2>&1 | grep rst
## TODO: Get PR Diff
## pr=https://github.com/lupyuen2/wip-pinephone-nuttx/pull/40
## curl -L $pr.diff \
## | grep "diff --git" \
## | sort \
## | cut -d" " -f3 \
## | cut -c3-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment