-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·147 lines (120 loc) · 4.3 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env bash
## macOS and WSL script to build, flash and run Rust Firmware for NuttX on BL602.
## We use a custom Rust target `riscv32imacf-unknown-none-elf` that sets `llvm-abiname` to `ilp32f` for Single-Precision Hardware Floating-Point.
## (Because NuttX BL602 was compiled with "gcc -march=rv32imafc -mabi=ilp32f")
## TODO: BL602 is actually RV32-ACFIMX
set -e ## Exit when any command fails
set -x ## Echo commands
## Name of app
export APP_NAME=nuttx
## Path to NuttX
export NUTTX_PATH=$PWD/../../../nuttx
## Where blflash is located
## For macOS: export BLFLASH_PATH=$PWD/../../../../blflash
## For WSL:
export BLFLASH_PATH=/mnt/c/pinecone/blflash
## Where GCC is located
export GCC_PATH=$PWD/../../../xpack-riscv-none-embed-gcc
## Rust build profile: debug or release
rust_build_profile=debug
## rust_build_profile=release
## Rust target: Custom target for llvm-abiname=ilp32f
## https://docs.rust-embedded.org/embedonomicon/compiler-support.html#built-in-target
## https://docs.rust-embedded.org/embedonomicon/custom-target.html
rust_build_target=$PWD/riscv32imacf-unknown-none-elf.json
rust_build_target_folder=riscv32imacf-unknown-none-elf
set +x ## Disable echo
echo ; echo "----- Building Rust app and NuttX firmware for $rust_build_target_folder / $APP_NAME..."
## Rust target: Standard target
## rust_build_target=riscv32imac-unknown-none-elf
## rust_build_target_folder=riscv32imac-unknown-none-elf
## Rust build options: Build the Rust Core Library for our custom target
rust_build_options="--target $rust_build_target -Z build-std=core"
if [ "$rust_build_profile" == 'release' ]; then
# Build for release
rust_build_options="--release $rust_build_options"
## else
# Build for debug: No change in options
fi
## Location of the Stub Library. We will replace this stub by the Rust Library
## rust_app_dest will be set to ../../../nuttx/staging/librust.a
rust_app_dir=$NUTTX_PATH/staging
rust_app_dest=$rust_app_dir/librust.a
## Location of the compiled Rust Library
## rust_app_build will be set to rust/target/riscv32imacf-unknown-none-elf/debug/libapp.a
rust_build_dir=$PWD/rust/target/$rust_build_target_folder/$rust_build_profile
rust_app_build=$rust_build_dir/libapp.a
## Remove the Stub Library if it exists:
## ../../../nuttx/staging/librust.a
if [ -e $rust_app_dest ]; then
rm $rust_app_dest
fi
## Remove the Rust Library if it exists:
## rust/target/riscv32imacf-unknown-none-elf/debug/libapp.a
if [ -e $rust_app_build ]; then
rm $rust_app_build
fi
set +x ## Disable echo
echo ; echo "----- Build NuttX Firmware"
set -x ## Enable echo
## Build the firmware with the Stub Library, ignoring references to the Rust Library
if [ "$SKIP_FIRST_BUILD" == '1' ]; then
echo "Skipping first build"
else
pushd $NUTTX_PATH
make || echo "----- Ignore undefined references to Rust Library"
popd
fi
set +x ## Disable echo
echo ; echo "----- Build Rust Library"
set -x ## Enable echo
## Build the Rust Library
pushd rust
rustup default nightly
cargo clippy $rust_build_options
cargo build $rust_build_options
popd
## Replace the Stub Library by the compiled Rust Library
## Stub Library: ../../../nuttx/staging/librust.a
## Rust Library: rust/target/riscv32imacf-unknown-none-elf/debug/libapp.a
cp $rust_app_build $rust_app_dest
set +x ## Disable echo
echo ; echo "----- Link NuttX Firmware with Rust Library"
set -x ## Enable echo
## Link the Rust Library to the firmware
pushd $NUTTX_PATH
make
popd
## Generate the disassembly
## $GCC_PATH/bin/riscv-none-embed-objdump \
## -t -S --demangle --line-numbers --wide \
## build_out/$APP_NAME.elf \
## >build_out/$APP_NAME.S \
## 2>&1
## Copy firmware to blflash
cp $NUTTX_PATH/$APP_NAME.* $BLFLASH_PATH
ls -l $BLFLASH_PATH/$APP_NAME.bin
set +x ## Disable echo
echo ; echo "----- Flash NuttX Firmware"
set -x ## Enable echo
## Flash the firmware
if [ "$SKIP_FLASH" == '1' ]; then
echo "Skipping flash"
else
pushd $BLFLASH_PATH
blflash flash $APP_NAME.bin \
--port /dev/tty.usbserial-14* \
--initial-baud-rate 230400 \
--baud-rate 230400
sleep 5
popd
fi
set +x ## Disable echo
echo ; echo "----- Run NuttX Firmware"
set -x ## Enable echo
## Run the firmware
if [ "$SKIP_FLASH" == '1' ]; then
echo "Skipping run"
else
open -a CoolTerm
fi