Created
February 24, 2025 00:43
-
-
Save lupyuen/16cd1ba3a56de1928cb956503ebdb9ac to your computer and use it in GitHub Desktop.
Apache NuttX RTOS on StarPro64: Build Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Build NuttX for StarPro64 | |
set -e # Exit when any command fails | |
set -x # Echo commands | |
## TODO: Set PATH | |
export PATH="$HOME/xpack-riscv-none-elf-gcc-13.2.0-2/bin:$PATH" | |
rm -rf \ | |
hello.S \ | |
Image \ | |
init.S \ | |
initrd \ | |
boards/risc-v/sg2000/milkv_duos/src/etctmp | |
## Build NuttX | |
function build_nuttx { | |
## Go to NuttX Folder | |
pushd ../nuttx | |
## Build NuttX | |
make -j | |
## Return to previous folder | |
popd | |
} | |
## Build Apps Filesystem | |
function build_apps { | |
## Go to NuttX Folder | |
pushd ../nuttx | |
## Build Apps Filesystem | |
make -j export | |
pushd ../apps | |
./tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz | |
make -j import | |
popd | |
## Return to previous folder | |
popd | |
} | |
## Pull updates | |
git status && hash1=`git rev-parse HEAD` | |
pushd ../apps | |
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 | |
make -j distclean || true | |
tools/configure.sh milkv_duos:nsh || true | |
## 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 | |
## 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 | |
## Check the Coding Style | |
../nxstyle arch/risc-v/src/common/riscv_addrenv.c | |
## Copy NuttX Image to TFTP Server | |
scp Image tftpserver:/tftpboot/Image-starpro64 | |
ssh tftpserver ls -l /tftpboot/Image-starpro64 | |
## Boot NuttX over TFTP | |
echo "\n\n" 'setenv tftp_server 192.168.31.10 ; dhcp ${kernel_addr_r} ${tftp_server}:Image-starpro64 ; tftpboot ${fdt_addr_r} ${tftp_server}:jh7110-star64-pine64.dtb ; fdt addr ${fdt_addr_r} ; booti ${kernel_addr_r} - ${fdt_addr_r}\n\n' | |
# exit | |
## Get the Home Assistant Token, copied from http://localhost:8123/profile/security | |
## token=xxxx | |
set +x ## Disable echo | |
. $HOME/home-assistant-token.sh | |
set -x ## Enable echo | |
set +x ## Disable echo | |
echo "----- Power Off the SBC" | |
curl \ | |
-X POST \ | |
-H "Authorization: Bearer $token" \ | |
-H "Content-Type: application/json" \ | |
-d '{"entity_id": "automation.starpro64_power_off"}' \ | |
http://localhost:8123/api/services/automation/trigger | |
set -x ## Enable echo | |
set +x ## Disable echo | |
echo "----- Power On the SBC" | |
curl \ | |
-X POST \ | |
-H "Authorization: Bearer $token" \ | |
-H "Content-Type: application/json" \ | |
-d '{"entity_id": "automation.starpro64_power_on"}' \ | |
http://localhost:8123/api/services/automation/trigger | |
set -x ## Enable echo | |
echo Press Enter to Power Off | |
read | |
rm -rf \ | |
hello.S \ | |
Image \ | |
init.S \ | |
initrd \ | |
boards/risc-v/sg2000/milkv_duos/src/etctmp | |
set +x ## Disable echo | |
echo "----- Power Off the SBC" | |
curl \ | |
-X POST \ | |
-H "Authorization: Bearer $token" \ | |
-H "Content-Type: application/json" \ | |
-d '{"entity_id": "automation.starpro64_power_off"}' \ | |
http://localhost:8123/api/services/automation/trigger | |
set -x ## Enable echo | |
exit #### | |
## Update NuttX Config | |
make menuconfig \ | |
&& make savedefconfig \ | |
&& grep -v CONFIG_HOST defconfig \ | |
>boards/risc-v/sg2000/milkv_duos/configs/nsh/defconfig | |
## Build Documentation | |
cd nuttx | |
cd Documentation | |
### Previously: pip3 install pipenv | |
brew install pipenv | |
pipenv install | |
pipenv shell | |
clear ; rm -r _build ; make html | |
clear ; rm -r _build ; make html 2>&1 | grep rst | |
## For macOS: | |
pip install setuptools |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment