-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
build
executable file
·227 lines (200 loc) · 6.99 KB
/
build
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!/bin/bash
################################################################
# CanAirIO Deploy Util
# ====================
#
# (C) @hpsaturn 2022
#
# Original tool for deploy flavors of CanAirIO firmware.
#
# REVISIONS
# +++++++++
# 20220713 General changes for try to hava a better generic tool
################################################################
SRC_REV=`cat platformio.ini | grep 'revision =' | awk '{print $3}'`
SRC_VER=`cat platformio.ini | grep 'version =' | awk '{print $3}'`
TARGET=`cat platformio.ini | grep 'target =' | awk '{print $3}'`
DATE=`date +%Y%m%d`
OUTDIR=".pio/build"
RELDIR="releases"
BINDIR="binaries"
MANIFEST="manifest"
NAME="canairio"
DEFAULT="TTGO_T7"
OWNER="kike-canaries"
REPO="canairio_firmware"
INSDIR=$RELDIR/installer/${NAME}_installer
flavors="TTGO_T7 WEMOSOLED HELTEC TTGO_TQ ESP32DEVKIT TTGO_TDISPLAY ESP32PICOD4 M5STICKCPLUS M5ATOM M5PICOD4 ESP32C3 ESP32C3OIPLUS ESP32C3LOLIN ESP32C3SEEDX ESP32S3 TTGO_T7S3 LORADEVKIT"
#flavors="TTGO_T7 WEMOSOLED ESP32DEVKIT TTGO_TDISPLAY M5STICKCPLUS M5ATOM ESP32C3 ESP32C3OIPLUS ESP32C3LOLIN ESP32C3SEEDX"
#flavors="TTGO_T7 ESP32C3 ESP32C3OIPLUS ESP32C3LOLIN ESP32C3SEEDX"
showHelp () {
echo ""
echo "************************************************"
echo "** Build release flavor or installer package **"
echo "************************************************"
echo ""
echo "Usage: ./build [flavor|list|all|installer|github|ota|webi|help|print|list|clean]"
echo ""
echo "example: ./build clean"
echo "example: ./build all"
echo -n "example: ./build "; echo ${flavors} | awk '{print $1}'
echo "example: ./build installer"
echo ""
echo "Supported boards: "
echo "./build list"
echo ""
echo "Build installer option will build a installer package for Linux"
echo "with OTA support and USB support"
echo ""
}
clean () {
echo "Clean installer directory.."
rm -rf $RELDIR/$BINDIR
rm -rf $RELDIR/$MANIFEST
rm -f $INSDIR/*.bin
rm -f $INSDIR/*.py
for flavor in $flavors; do
echo "Clean flavor $flavor.."
pio run -s -e $flavor -t clean
done
}
build () {
echo ""
echo "***********************************************"
echo "** Building $1"
echo "***********************************************"
echo ""
pio run -s -e $1
echo ""
echo "***********************************************"
echo "** Firmware $1 output:"
echo -n "** MD5:"
FIRMDIR=$RELDIR/$BINDIR/$1
mkdir -p $FIRMDIR
cp $OUTDIR/$1/firmware.bin $FIRMDIR/${NAME}_${1}_rev${SRC_REV}.bin
if [ $1 == ESP32C3 ] || [ $1 == ESP32C3LOLIN ] || [ $1 == ESP32C3SEEDX ] || [ $1 == ESP32C3OIPLUS ]; then
/usr/bin/python3 ${PIO_HOME}/packages/tool-esptoolpy/esptool.py --chip esp32c3 merge_bin -o $FIRMDIR/${NAME}_${1}_rev${SRC_REV}_merged.bin --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0000 $OUTDIR/$1/bootloader.bin 0x8000 $OUTDIR/$1/partitions.bin 0xe000 ${PIO_HOME}/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 $OUTDIR/$1/firmware.bin
elif [ $1 == ESP32S3 ] || [ $1 == TTGO_T7S3 ]; then
/usr/bin/python3 ${PIO_HOME}/packages/tool-esptoolpy/esptool.py --chip esp32s3 merge_bin -o $FIRMDIR/${NAME}_${1}_rev${SRC_REV}_merged.bin --flash_mode dio --flash_freq 80m --flash_size 8MB 0x0000 $OUTDIR/$1/bootloader.bin 0x8000 $OUTDIR/$1/partitions.bin 0xe000 ${PIO_HOME}/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin 0x10000 $OUTDIR/$1/firmware.bin
else
esptool --chip esp32 merge_bin -o $FIRMDIR/${NAME}_${1}_rev${SRC_REV}_merged.bin --flash_mode dio --flash_freq 40m --flash_size 4MB 0x1000 ${PIO_HOME}/packages/[email protected]/tools/sdk/esp32/bin/bootloader_dio_40m.bin 0x8000 $OUTDIR/$1/partitions.bin 0xe000 ${PIO_HOME}/packages/[email protected]/tools/partitions/boot_app0.bin 0x10000 $OUTDIR/$1/firmware.bin
fi
md5sum $FIRMDIR/${NAME}_${1}_rev${SRC_REV}.bin
md5sum $FIRMDIR/${NAME}_${1}_rev${SRC_REV}_merged.bin
echo "***********************************************"
echo ""
}
buildInstaller () {
echo "***********************************************"
echo "** Building installer with target: $TARGET"
echo "***********************************************"
echo ""
echo "Update installer tool.."
cp $PIO_HOME/packages/[email protected]/esptool.py $INSDIR/
echo "Update installer flavors.."
rm -f $INSDIR/*.bin
cp $RELDIR/$BINDIR/*/*${SRC_REV}_merged.bin $INSDIR/
cp ${PIO_HOME}/packages/tool-esptoolpy/esptool.py $INSDIR/
printOutput
cd $INSDIR/..
rm -f ${NAME}_${TARGET}_rev${SRC_REV}_${DATE}.zip
zip -r ${NAME}_${TARGET}_rev${SRC_REV}_${DATE}.zip ${NAME}_installer
echo ""
du -hs ${NAME}_${TARGET}_rev${SRC_REV}_${DATE}.zip
echo ""
}
publish_release () {
cd $INSDIR/..
# github-release upload --owner ${OWNER} --repo ${REPO} --tag "rev${SRC_REV}" --release-name "rev${SRC_REV} v${SRC_VER}" --body "${COMMIT_LOG}" ${NAME}_${TARGET}_rev${SRC_REV}_${DATE}.zip
echo "Publishing release: v${SRC_VER} rev${SRC_REV}"
echo "uploading: ${NAME}_${TARGET}_rev${SRC_REV}_${DATE}.zip"
git tag -a "v${SRC_VER}" -m "release v${SRC_VER} rev${SRC_REV}"
git push origin "v${SRC_VER}"
git log -n 10 --pretty=format:"%h %s" | gh release create "v${SRC_VER}" -F - -t "v${SRC_VER} rev${SRC_REV}" -p ${NAME}_${TARGET}_rev${SRC_REV}_${DATE}.zip
}
publish_release_ota () {
scp $RELDIR/$BINDIR/*/*${SRC_REV}.bin canairio:$canairio_target/$TARGET
scp $RELDIR/$MANIFEST/$TARGET/*.json canairio:$canairio_target/$TARGET
}
publish_release_webtools () {
scp $INSDIR/*.bin canairio:$canairio_target/webi/$TARGET
scp $INSDIR/*.txt canairio:$canairio_target/webi/$TARGET
scp $INSDIR/*.md canairio:$canairio_target/webi/$TARGET
scp $RELDIR/$MANIFEST/webi/$TARGET/*.json canairio:$canairio_target/webi/$TARGET
}
printOutput () {
echo ""
FIRMDIR=$RELDIR/$BINDIR
if [ ! -d "$FIRMDIR" ]; then
echo "Please first build any flavor!"
echo ""
exit 1
fi
mkdir -p $INSDIR
rm -f $INSDIR/md5output.txt
touch $INSDIR/md5output.txt
cd $FIRMDIR
for flavor in *; do
MD5FLAVOR=`md5sum $flavor/${NAME}_${flavor}_rev${SRC_REV}_merged.bin`
echo $MD5FLAVOR >> ../../$INSDIR/md5output.txt
done
cat ../../$INSDIR/md5output.txt
cd ../..
echo ""
}
if [ "$1" = "" ]; then
showHelp
else
case "$1" in
clean)
clean
;;
installer)
buildInstaller
;;
help)
showHelp
;;
--help)
showHelp
;;
-help)
showHelp
;;
print)
printOutput
;;
all)
for flavor in $flavors; do
build $flavor
done
printOutput
;;
github)
publish_release
;;
ota)
publish_release_ota
;;
webi)
publish_release_webtools
;;
list)
for flavor in $flavors; do
echo $flavor
done
;;
*)
if [[ $flavors == *"$1"* ]]; then
build $1
else
echo ""
echo "ERROR: Flavor not found!"
echo ""
echo "Please check flavor parameter with 'list' command"
echo ""
fi
;;
esac
fi
exit 0