Skip to content

Instantly share code, notes, and snippets.

@lupyuen
Last active May 23, 2023 02:54
Show Gist options
  • Save lupyuen/aa1f5c0c45e6029b10e5e2f955d8386c to your computer and use it in GitHub Desktop.
Save lupyuen/aa1f5c0c45e6029b10e5e2f955d8386c to your computer and use it in GitHub Desktop.
Apache NuttX RTOS for PinePhone: Build Script for macOS
#!/usr/bin/env bash
# Build NuttX for PinePhone
# TODO: Update PATH
export PATH="$PATH:/Applications/ArmGNUToolchain/11.3.rel1/aarch64-none-elf/bin"
export PATH="$PATH:$HOME/zig-macos-x86_64-0.10.0-dev.2351+b64a1d5ab"
rm Image.gz
set -e # Exit when any command fails
set -x # Echo commands
## Test locally
function test_local {
pushd ../pinephone-nuttx/test
./run.sh
popd
}
## Build the LVGL Zig App
function build_zig {
## Go to LVGL Zig Folder
pushd ../pinephone-lvgl-zig
git pull
## Check that NuttX Build has completed and `lv_demo_widgets.*.o` exists
if [ ! -f ../apps/graphics/lvgl/lvgl/demos/widgets/lv_demo_widgets.*.o ]
then
echo "*** Error: Build NuttX first before building Zig app"
build_nuttx
build_zig
fi
## Compile the Zig App for PinePhone
## (armv8-a with cortex-a53)
## TODO: Change ".." to your NuttX Project Directory
zig build-obj \
--verbose-cimport \
-target aarch64-freestanding-none \
-mcpu cortex_a53 \
-isystem "../nuttx/include" \
-I "../apps/include" \
-I "../apps/graphics/lvgl" \
-I "../apps/graphics/lvgl/lvgl/src/core" \
-I "../apps/graphics/lvgl/lvgl/src/draw" \
-I "../apps/graphics/lvgl/lvgl/src/draw/arm2d" \
-I "../apps/graphics/lvgl/lvgl/src/draw/nxp" \
-I "../apps/graphics/lvgl/lvgl/src/draw/nxp/pxp" \
-I "../apps/graphics/lvgl/lvgl/src/draw/nxp/vglite" \
-I "../apps/graphics/lvgl/lvgl/src/draw/sdl" \
-I "../apps/graphics/lvgl/lvgl/src/draw/stm32_dma2d" \
-I "../apps/graphics/lvgl/lvgl/src/draw/sw" \
-I "../apps/graphics/lvgl/lvgl/src/draw/swm341_dma2d" \
-I "../apps/graphics/lvgl/lvgl/src/font" \
-I "../apps/graphics/lvgl/lvgl/src/hal" \
-I "../apps/graphics/lvgl/lvgl/src/misc" \
-I "../apps/graphics/lvgl/lvgl/src/widgets" \
lvgltest.zig
## Copy the compiled app to NuttX and overwrite `lv_demo_widgets.*.o`
## TODO: Change ".." to your NuttX Project Directory
cp lvgltest.o \
../apps/graphics/lvgl/lvgl/demos/widgets/lv_demo_widgets.*.o
## Return to NuttX Folder
popd
}
function build_zig_render {
pushd ../pinephone-nuttx
git pull
# Compile the Zig App for PinePhone
# (armv8-a with cortex-a53)
# TODO: Change ".." to your NuttX Project Directory
zig build-obj \
--verbose-cimport \
-target aarch64-freestanding-none \
-mcpu cortex_a53 \
-isystem "../nuttx/include" \
-I "../apps/include" \
render.zig
# Copy the compiled app to NuttX and overwrite `hello.o`
# TODO: Change ".." to your NuttX Project Directory
cp render.o \
../apps/examples/hello/*hello.o
popd
}
## Build NuttX
function build_nuttx {
## Go to NuttX Folder
pushd ../nuttx
## Build NuttX
make -j
## Return to previous folder
popd
}
## Test locally
####test_local && sleep 2
## Show the versions of GCC and Zig
aarch64-none-elf-gcc -v
zig version
## TODO: Configure build for PinePhone LVGL
## tools/configure.sh pinephone:lvgl
## Build the Zig App
####
build_zig
## Build NuttX
build_nuttx
## Show the size
aarch64-none-elf-size nuttx
## Dump the disassembly to nuttx.S
aarch64-none-elf-objdump \
-t -S --demangle --line-numbers --wide \
nuttx \
>nuttx.S \
2>&1 \
&
## Check coding style
set +e # Ignore errors
../nxstyle boards/arm64/a64/pinephone/src/pinephone_bringup.c
../nxstyle boards/arm64/a64/pinephone/src/pinephone_modem.c
../nxstyle boards/arm64/a64/pinephone/src/pinephone_modem.h
../nxstyle arch/arm64/src/a64/a64_serial.c
../nxstyle arch/arm64/src/a64/a64_serial.h
../nxstyle arch/arm64/src/a64/hardware/a64_memorymap.h
../nxstyle arch/arm64/src/a64/Kconfig
##../nxstyle boards/arm64/a64/pinephone/src/pinephone_pmic.c
##../nxstyle arch/arm64/src/a64/a64_pio.c
../nxstyle ../apps/examples/lvglterm/lvglterm.c
../nxstyle ../apps/examples/lvgldemo/lvgldemo.c
../nxstyle boards/arm64/a64/pinephone/src/pinephone_touch.c
../nxstyle boards/arm64/a64/pinephone/src/pinephone_touch.h
../nxstyle arch/arm64/src/a64/a64_pio.h
../nxstyle arch/arm64/src/a64/hardware/a64_pio.h
../nxstyle arch/arm64/include/a64/irq.h
../nxstyle boards/arm64/a64/pinephone/src/pinephone_pmic.h
../nxstyle boards/arm64/a64/pinephone/src/pinephone_display.c
../nxstyle boards/arm64/a64/pinephone/src/pinephone_display.h
../nxstyle boards/arm64/a64/pinephone/src/pinephone_lcd.c
../nxstyle boards/arm64/a64/pinephone/src/pinephone_lcd.h
../nxstyle boards/arm64/a64/pinephone/Kconfig
../nxstyle boards/arm64/a64/pinephone/configs/lcd/defconfig
../nxstyle boards/arm64/a64/pinephone/src/Makefile
../nxstyle Documentation/platforms/arm/a64/boards/pinephone/index.rst
../nxstyle arch/arm64/src/a64/Make.defs
../nxstyle boards/arm64/a64/pinephone/configs/nsh/defconfig
# ../nxstyle include/nuttx/input/gt9xx.h
# ../nxstyle drivers/input/gt9xx.c
# ../nxstyle drivers/input/Make.defs
# ../nxstyle drivers/input/Kconfig
# ../nxstyle arch/arm64/src/a64/a64_rsb.c
# ../nxstyle arch/arm64/src/a64/a64_rsb.h
# ../nxstyle arch/arm64/src/a64/a64_de.c
# ../nxstyle arch/arm64/src/a64/a64_de.h
# ../nxstyle arch/arm64/src/a64/a64_tcon0.c
# ../nxstyle arch/arm64/src/a64/a64_tcon0.h
# ../nxstyle arch/arm64/src/a64/mipi_dsi.c
# ../nxstyle arch/arm64/src/a64/mipi_dsi.h
# ../nxstyle arch/arm64/src/a64/a64_mipi_dsi.c
# ../nxstyle arch/arm64/src/a64/a64_mipi_dsi.h
# ../nxstyle arch/arm64/src/a64/a64_mipi_dphy.c
# ../nxstyle arch/arm64/src/a64/a64_mipi_dphy.h
# ../nxstyle include/nuttx/crc16.h
# ../nxstyle libs/libc/misc/Make.defs
# ../nxstyle libs/libc/misc/lib_crc16ccitt.c
set -e # Exit when any command fails
## Boot NuttX on QEMU (Single Core) with GIC v3
# qemu-system-aarch64 \
# -cpu cortex-a53 \
# -nographic \
# -machine virt,virtualization=on,gic-version=3 \
# -net none \
# -chardev stdio,id=con,mux=on \
# -serial chardev:con \
# -mon chardev=con,mode=readline \
# -kernel ./nuttx \
## Boot NuttX on QEMU (Quad Core) with GIC v3
# qemu-system-aarch64 \
# -smp 4 \
# -cpu cortex-a53 \
# -nographic \
# -machine virt,virtualization=on,gic-version=3 \
# -net none \
# -chardev stdio,id=con,mux=on \
# -serial chardev:con \
# -mon chardev=con,mode=readline \
# -kernel ./nuttx \
## Boot NuttX on QEMU (Single Core) with GIC v2
# qemu-system-aarch64 \
# -cpu cortex-a53 \
# -nographic \
# -machine virt,virtualization=on,gic-version=2 \
# -net none \
# -chardev stdio,id=con,mux=on \
# -serial chardev:con \
# -mon chardev=con,mode=readline \
# -kernel ./nuttx \
# &
# sleep 2
# kill %1
if [ ! -d "/Volumes/NO NAME" ]
then
exit
fi
## Copy the config
cp .config nuttx.config
## Compress the NuttX Image
cp nuttx.bin Image
rm -f Image.gz
gzip Image
## Copy to microSD
cp Image.gz "/Volumes/NO NAME"
ls -l "/Volumes/NO NAME/Image.gz"
## TODO: Archive the NuttX Image
rm Image.gz
## Unmount microSD
## TODO: Verify that /dev/disk2 is microSD
diskutil unmountDisk /dev/disk2
## Wait for USB Serial to be connected
set +x # Don't echo commands
echo "***** Connect PinePhone to USB Serial"
while : ; do
[[ -c "/dev/tty.usbserial-1410" ]] && break
sleep 1
done
set -x # Echo commands
## Run the firmware
script /tmp/run.log screen /dev/tty.usbserial-1410 115200
## Filter the Run Log for Phone Number
../filter-log.sh
## Unused
exit
open -a "Disk Utility"
open -a CoolTerm
make clean && make distclean && ./tools/configure.sh -l pinephone:nsh
make clean && make distclean && ./tools/configure.sh -l qemu-armv8a:nsh
make clean && make distclean && ./tools/configure.sh -l qemu-armv8a:nsh_smp
make clean && make distclean && ./tools/configure.sh -l qemu-armv8a:nsh_gicv2
## Build Documentation
cd nuttx
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
## Copy files
cp arch/arm64/src/a64/a64_serial.c /tmp
cp arch/arm64/src/a64/a64_serial.h /tmp
cp arch/arm64/src/a64/hardware/a64_memorymap.h /tmp
cp Documentation/platforms/arm/a64/boards/pinephone/index.rst /tmp
cp arch/arm64/src/a64/Kconfig /tmp
cp boards/arm64/a64/pinephone/configs/lcd/defconfig /tmp/lcd-defconfig
cp boards/arm64/a64/pinephone/configs/lvgl/defconfig /tmp/lvgl-defconfig
cp boards/arm64/a64/pinephone/configs/nsh/defconfig /tmp/nsh-defconfig
cp boards/arm64/a64/pinephone/configs/sensor/defconfig /tmp/sensor-defconfig
cp /tmp/a64_serial.c arch/arm64/src/a64/
cp /tmp/a64_serial.h arch/arm64/src/a64/
cp /tmp/a64_memorymap.h arch/arm64/src/a64/hardware/
cp /tmp/index.rst Documentation/platforms/arm/a64/boards/pinephone/
cp /tmp/Kconfig arch/arm64/src/a64/
cp /tmp/lcd-defconfig boards/arm64/a64/pinephone/configs/lcd/defconfig
cp /tmp/lvgl-defconfig boards/arm64/a64/pinephone/configs/lvgl/defconfig
cp /tmp/nsh-defconfig boards/arm64/a64/pinephone/configs/nsh/defconfig
cp /tmp/sensor-defconfig boards/arm64/a64/pinephone/configs/sensor/defconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment