Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active August 10, 2024 09:23
Show Gist options
  • Save lupyuen/e0aaed0310a7b84f5ad7896e6827a968 to your computer and use it in GitHub Desktop.
Save lupyuen/e0aaed0310a7b84f5ad7896e6827a968 to your computer and use it in GitHub Desktop.
Apache NuttX RTOS: Build Rust App for QEMU RISC-V 64-bit. See https://lupyuen.github.io/articles/rust5
#!/usr/bin/env bash
# Build NuttX for QEMU RISC-V 64-bit with Rust App
## TODO: Set PATH
export PATH="$HOME/xpack-riscv-none-elf-gcc-13.2.0-2/bin:$PATH"
set -e # Exit when any command fails
set -x # Echo commands
## 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 the NuttX Build
make distclean
tools/configure.sh rv-virt:nsh64 || true
## Enable Hello Rust App
kconfig-tweak --enable CONFIG_EXAMPLES_HELLO_RUST
## Update the Kconfig Dependencies
make olddefconfig
## Build NuttX
make
## 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
## Dump the Rust App Disassembly to hello_rust_1.S
riscv-none-elf-objdump \
--syms --source --reloc --demangle --line-numbers --wide \
--debugging \
../apps/examples/hello_rust/*1.o \
>hello_rust_1.S \
2>&1
## Start the emulator
qemu-system-riscv64 \
-semihosting \
-M virt,aclint=on \
-cpu rv64 \
-kernel nuttx \
-nographic \
-bios none \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment