Last active
September 18, 2023 08:58
-
-
Save lupyuen/8ba3de9ebba0881678b6ecab977443f5 to your computer and use it in GitHub Desktop.
Build Apache NuttX RTOS on Raspberry Pi OS (64-bit)
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
## SiFive RISC-V Toolchain doesn't support Raspberry Pi OS and other Arm64 Linux Distros. | |
## This is how we build NuttX with another RISC-V Toolchain: xPack GNU RISC-V Embedded GCC | |
## Based on https://xpack.github.io/dev-tools/riscv-none-elf-gcc/install/ | |
~ $ neofetch | |
_,met$$$$$gg. pi@pi64 | |
,g$$$$$$$$$$$$$$$P. ------- | |
,g$$P" """Y$$.". OS: Debian GNU/Linux 11 (bullseye) aarch64 | |
,$$P' `$$$. Host: Raspberry Pi 4 Model B Rev 1.1 | |
',$$P ,ggs. `$$b: Kernel: 6.1.21-v8+ | |
`d$$' ,$P"' . $$$ Uptime: 25 mins | |
$$P d$' , $$P Packages: 1425 (dpkg) | |
$$: $$. - ,d$$' Shell: bash 5.1.4 | |
$$; Y$b._ _,d$P' Terminal: /dev/pts/0 | |
Y$$. `.`"Y$$$$P"' CPU: BCM2835 (4) @ 1.500GHz | |
`$$b "-.__ Memory: 306MiB / 3794MiB | |
`Y$$ | |
`Y$$. | |
`$$b. | |
`Y$$b. | |
`"Y$b._ | |
`""" | |
## Install Build Prequisites, based on... | |
## https://lupyuen.github.io/articles/nuttx#install-prerequisites | |
## https://github.com/lupyuen/nuttx-star64/blob/main/.github/workflows/star64.yml | |
~ $ sudo apt update | |
~ $ sudo apt -y install \ | |
bison flex gettext texinfo libncurses5-dev libncursesw5-dev \ | |
gperf automake libtool pkg-config build-essential gperf genromfs \ | |
libgmp-dev libmpc-dev libmpfr-dev libisl-dev binutils-dev libelf-dev \ | |
libexpat-dev u-boot-tools util-linux \ | |
kconfig-frontends \ | |
wget u-boot-tools | |
## Install Toolchain for RISC-V Target: xPack GNU RISC-V Embedded GCC (for Arm64 Linux) | |
## Based on https://xpack.github.io/dev-tools/riscv-none-elf-gcc/install/ | |
## For Arm64 Target (PinePhone): https://xpack.github.io/dev-tools/aarch64-none-elf-gcc/ | |
~ $ sudo apt -y remove \ | |
gcc-riscv64-unknown-elf \ | |
binutils-riscv64-unknown-elf \ | |
picolibc-riscv64-unknown-elf | |
~ $ ls /usr/bin/riscv* | |
ls: cannot access '/usr/bin/riscv*': No such file or directory | |
~ $ wget https://github.com/xpack-dev-tools/riscv-none-elf-gcc-xpack/releases/download/v12.3.0-1/xpack-riscv-none-elf-gcc-12.3.0-1-linux-arm64.tar.gz | |
~ $ tar xf xpack-riscv-none-elf-gcc-12.3.0-1-linux-arm64.tar.gz | |
~ $ export PATH=$PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin:$PATH | |
## xPack Toolchain names the binaries as "riscv" instead of "riscv64". | |
## So we symlink the Toolchain Binaries from "riscv" to "riscv64". | |
## TODO: Symlink the rest of the Toolchain Binaries | |
~ $ ln -s $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv-none-elf-ar $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv64-unknown-elf-ar | |
~ $ ln -s $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv-none-elf-gcc $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv64-unknown-elf-gcc | |
~ $ ln -s $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv-none-elf-ld $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv64-unknown-elf-ld | |
~ $ ln -s $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv-none-elf-nm $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv64-unknown-elf-nm | |
~ $ ln -s $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv-none-elf-objcopy $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv64-unknown-elf-objcopy | |
~ $ ln -s $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv-none-elf-objdump $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv64-unknown-elf-objdump | |
~ $ ln -s $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv-none-elf-size $PWD/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv64-unknown-elf-size | |
~ $ which riscv64-unknown-elf-gcc | |
/home/pi/xpack-riscv-none-elf-gcc-12.3.0-1/bin/riscv64-unknown-elf-gcc | |
~ $ riscv64-unknown-elf-gcc -v | |
Using built-in specs. | |
COLLECT_GCC=riscv64-unknown-elf-gcc | |
COLLECT_LTO_WRAPPER=/home/pi/xpack-riscv-none-elf-gcc-12.3.0-1/bin/../libexec/gcc/riscv-none-elf/12.3.0/lto-wrapper | |
Target: riscv-none-elf | |
Configured with: /__w/riscv-none-elf-gcc-xpack/riscv-none-elf-gcc-xpack/build/linux-arm64/sources/gcc-12.3.0/configure --prefix=/__w/riscv-none-elf-gcc-xpack/riscv-none-elf-gcc-xpack/build/linux-arm64/application --with-sysroot=/__w/riscv-none-elf-gcc-xpack/riscv-none-elf-gcc-xpack/build/linux-arm64/application/riscv-none-elf --with-native-system-header-dir=/include --infodir=/__w/riscv-none-elf-gcc-xpack/riscv-none-elf-gcc-xpack/build/linux-arm64/aarch64-unknown-linux-gnu/install/share/info --mandir=/__w/riscv-none-elf-gcc-xpack/riscv-none-elf-gcc-xpack/build/linux-arm64/aarch64-unknown-linux-gnu/install/share/man --htmldir=/__w/riscv-none-elf-gcc-xpack/riscv-none-elf-gcc-xpack/build/linux-arm64/aarch64-unknown-linux-gnu/install/share/html --pdfdir=/__w/riscv-none-elf-gcc-xpack/riscv-none-elf-gcc-xpack/build/linux-arm64/aarch64-unknown-linux-gnu/install/share/pdf --build=aarch64-unknown-linux-gnu --host=aarch64-unknown-linux-gnu --target=riscv-none-elf --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libsanitizer --disable-libssp --disable-nls --disable-shared --disable-threads --disable-tls --enable-checking=release --enable-languages=c,c++,fortran --with-gmp=/__w/riscv-none-elf-gcc-xpack/riscv-none-elf-gcc-xpack/build/linux-arm64/aarch64-unknown-linux-gnu/install --with-newlib --with-pkgversion='xPack GNU RISC-V Embedded GCC aarch64' --with-gnu-as --with-gnu-ld --with-system-zlib --with-abi=ilp32 --with-arch=rv32imac --enable-multilib | |
Thread model: single | |
Supported LTO compression algorithms: zlib zstd | |
gcc version 12.3.0 (xPack GNU RISC-V Embedded GCC aarch64) | |
## Build NuttX, based on... | |
## https://lupyuen.github.io/articles/release#build-nuttx-for-star64 | |
## https://github.com/lupyuen/nuttx-star64/blob/main/.github/workflows/star64.yml | |
~ $ mkdir nuttx | |
~ $ cd nuttx | |
~/nuttx $ git clone https://github.com/apache/nuttx.git nuttx | |
~/nuttx $ git clone https://github.com/apache/nuttx-apps apps | |
~/nuttx $ cd nuttx | |
~/nuttx/nuttx $ hash1=`git rev-parse HEAD` | |
~/nuttx/nuttx $ pushd ../apps | |
~/nuttx/apps $ hash2=`git rev-parse HEAD` | |
~/nuttx/apps $ popd | |
~/nuttx/nuttx $ echo NuttX Source: https://github.com/apache/nuttx/tree/$hash1 >nuttx.hash | |
~/nuttx/nuttx $ echo NuttX Apps: https://github.com/apache/nuttx-apps/tree/$hash2 >>nuttx.hash | |
~/nuttx/nuttx $ cat nuttx.hash | |
NuttX Source: https://github.com/apache/nuttx/tree/ac62a08ac9d933556f1905a535d6bddff593eacd | |
NuttX Apps: https://github.com/apache/nuttx-apps/tree/9f2f86441d20cc04e6a0d7b95130d7d13f360f14 | |
## Build NuttX for Star64 JH7110 SBC (or VisionFive2 SBC) | |
## To build NuttX for QEMU: Change "star64:nsh" to "rv-virt:nsh64" | |
~/nuttx/nuttx $ make distclean | |
~/nuttx/nuttx $ tools/configure.sh star64:nsh | |
~/nuttx/nuttx $ make | |
LD: nuttx | |
CP: nuttx.hex | |
~/nuttx/nuttx $ riscv64-unknown-elf-objcopy \ | |
-O binary \ | |
nuttx \ | |
nuttx.bin | |
~/nuttx/nuttx $ cp nuttx.bin Image | |
~/nuttx/nuttx $ make export | |
~/nuttx/nuttx $ pushd ../apps | |
~/nuttx/apps $ tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz | |
~/nuttx/apps $ make import | |
~/nuttx/apps $ popd | |
~/nuttx/nuttx $ genromfs -f initrd -d ../apps/bin -V "NuttXBootVol" | |
~/nuttx/nuttx $ ls -l | |
total 20200 | |
drwxr-xr-x 20 pi pi 4096 Sep 16 17:27 arch | |
drwxr-xr-x 2 pi pi 4096 Sep 16 17:27 audio | |
-rw-r--r-- 1 pi pi 2230 Sep 16 17:27 AUTHORS | |
drwxr-xr-x 4 pi pi 4096 Sep 16 19:47 binfmt | |
drwxr-xr-x 19 pi pi 4096 Sep 16 19:44 boards | |
-rwxr-xr-x 1 pi pi 4193 Sep 16 17:27 build-globals.sh | |
drwxr-xr-x 2 pi pi 4096 Sep 16 17:27 cmake | |
-rw-r--r-- 1 pi pi 24736 Sep 16 17:27 CMakeLists.txt | |
-rw-r--r-- 1 pi pi 1692 Sep 16 17:27 CONTRIBUTING.md | |
drwxr-xr-x 2 pi pi 4096 Sep 16 17:27 crypto | |
-rw-r--r-- 1 pi pi 2494 Sep 16 19:38 defconfig | |
drwxr-xr-x 13 pi pi 4096 Sep 16 17:27 Documentation | |
drwxr-xr-x 51 pi pi 4096 Sep 16 19:44 drivers | |
drwxr-xr-x 2 pi pi 4096 Sep 16 17:27 dummy | |
drwxr-xr-x 28 pi pi 4096 Sep 16 19:47 fs | |
drwxr-xr-x 6 pi pi 4096 Sep 16 17:27 graphics | |
-rwxr-xr-x 1 pi pi 2097800 Sep 17 10:23 Image | |
drwxr-xr-x 12 pi pi 4096 Sep 16 19:38 include | |
-rw-r--r-- 1 pi pi 8990720 Sep 16 19:51 initrd | |
-rw-r--r-- 1 pi pi 4051 Sep 16 17:27 INVIOLABLES.md | |
-rw-r--r-- 1 pi pi 56986 Sep 16 17:27 Kconfig | |
drwxr-xr-x 7 pi pi 4096 Sep 16 17:27 libs | |
-rw-r--r-- 1 pi pi 407210 Sep 16 17:27 LICENSE | |
lrwxrwxrwx 1 pi pi 75 Sep 16 19:38 Make.defs -> /home/pi/nuttx/nuttx/tools/../boards/risc-v/jh7110/star64/scripts/Make.defs | |
-rw-r--r-- 1 pi pi 1415 Sep 16 17:27 Makefile | |
drwxr-xr-x 17 pi pi 4096 Sep 16 19:46 mm | |
drwxr-xr-x 30 pi pi 4096 Sep 16 17:27 net | |
-rw-r--r-- 1 pi pi 3107 Sep 16 17:27 NOTICE | |
-rwxr-xr-x 1 pi pi 2822448 Sep 16 19:49 nuttx | |
-rwxr-xr-x 1 pi pi 2097800 Sep 17 10:19 nuttx.bin | |
-rw-r--r-- 1 pi pi 3784640 Sep 16 19:49 nuttx-export-12.2.1.tar.gz | |
-rw-r--r-- 1 pi pi 476984 Sep 16 19:49 nuttx.hex | |
-rw-r--r-- 1 pi pi 37 Sep 16 19:49 nuttx.manifest | |
-rw-r--r-- 1 pi pi 1659049 Sep 16 19:49 nuttx.map | |
drwxr-xr-x 2 pi pi 4096 Sep 16 17:27 openamp | |
drwxr-xr-x 2 pi pi 4096 Sep 16 17:27 pass1 | |
-rw-r--r-- 1 pi pi 96771 Sep 16 17:27 README.md | |
-rw-r--r-- 1 pi pi 1792738 Sep 16 17:27 ReleaseNotes | |
drwxr-xr-x 21 pi pi 12288 Sep 16 19:44 sched | |
drwxr-xr-x 2 pi pi 4096 Sep 16 19:47 staging | |
drwxr-xr-x 5 pi pi 20480 Sep 16 19:44 syscall | |
-rw-r--r-- 1 pi pi 40462 Sep 16 19:49 System.map | |
drwxr-xr-x 18 pi pi 4096 Sep 16 19:38 tools | |
drwxr-xr-x 3 pi pi 4096 Sep 16 17:27 video | |
drwxr-xr-x 5 pi pi 4096 Sep 16 17:27 wireless | |
## Boot the `Image` and `initrd` on Star64 JH7110 SBC: | |
## https://lupyuen.github.io/articles/tftp | |
## NuttX boots OK on Star64 JH7110 SBC: | |
## Starting kernel ... | |
## clk u5_dw_i2c_clk_core already disabled | |
## clk u5_dw_i2c_clk_apb already disabled | |
## BC | |
## NuttShell (NSH) NuttX-12.2.1 | |
## nsh> uname -a | |
## NuttX 12.2.1 ac62a08ac9 Sep 16 2023 19:41:49 risc-v star64 | |
## nsh> free | |
## total used free largest nused nfree | |
## Kmem: 2065400 14600 2050800 2049216 50 2 | |
## Page: 20971520 643072 20328448 20328448 | |
## nsh> ls /dev | |
## /dev: | |
## console | |
## null | |
## ram0 | |
## ttyS0 | |
## zero | |
## nsh> hello | |
## Hello, World!! | |
## Also works with Math Functions: | |
## Source Code: https://gist.github.com/lupyuen/63bd510d7e45ceebe7443c78ed31c6c8 | |
## Output Log: https://gist.github.com/lupyuen/9bdb1f5478318631d0480f03f6041d83 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment