forked from openthread/ot-reference-release
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-firmware.bash
More file actions
executable file
·447 lines (385 loc) · 13.1 KB
/
Copy pathmake-firmware.bash
File metadata and controls
executable file
·447 lines (385 loc) · 13.1 KB
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
#!/bin/bash
#
# Copyright (c) 2021, The OpenThread Authors.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of the copyright holder nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
set -euxo pipefail
if [[ -n ${BASH_SOURCE[0]} ]]; then
script_path="${BASH_SOURCE[0]}"
else
script_path="$0"
fi
script_dir="$(dirname "$(realpath "$script_path")")"
repo_dir="$(dirname "$script_dir")"
# Global Vars
platform=""
build_dir=""
build_script_flags=()
NRFUTIL=""
readonly build_1_4_options_common=(
"-DOT_THREAD_VERSION=1.4"
"-DOT_SRP_SERVER=ON"
"-DOT_ECDSA=ON"
"-DOT_SERVICE=ON"
"-DOT_DNSSD_SERVER=ON"
"-DOT_SRP_CLIENT=ON"
)
readonly build_1_4_options_nrf=(
""
)
readonly build_1_3_options_common=(
"-DOT_THREAD_VERSION=1.3"
"-DOT_SRP_SERVER=ON"
"-DOT_ECDSA=ON"
"-DOT_SERVICE=ON"
"-DOT_DNSSD_SERVER=ON"
"-DOT_SRP_CLIENT=ON"
)
readonly build_1_3_options_nrf=(
""
)
readonly build_1_2_options_common=(
'-DOT_THREAD_VERSION=1.2'
'-DOT_REFERENCE_DEVICE=ON'
'-DOT_BORDER_ROUTER=ON'
'-DOT_SERVICE=ON'
'-DOT_COMMISSIONER=ON'
'-DOT_JOINER=ON'
'-DOT_MAC_FILTER=ON'
'-DOT_DHCP6_SERVER=ON'
'-DOT_DHCP6_CLIENT=ON'
'-DOT_DUA=ON'
'-DOT_MLR=ON'
'-DOT_LINK_METRICS_INITIATOR=ON'
'-DOT_LINK_METRICS_SUBJECT=ON'
'-DOT_CSL_RECEIVER=ON'
'-DOT_BORDER_AGENT=OFF'
'-DOT_COAP=OFF'
'-DOT_COAPS=OFF'
'-DOT_ECDSA=OFF'
'-DOT_FULL_LOGS=OFF'
'-DOT_IP6_FRAGM=OFF'
'-DOT_LINK_RAW=OFF'
'-DOT_NETDIAG_CLIENT=OFF'
'-DOT_SNTP_CLIENT=OFF'
'-DOT_UDP_FORWARD=OFF'
)
readonly build_1_2_options_nrf=(
'-DOT_BOOTLOADER=USB'
'-DOT_CSL_RECEIVER=ON'
)
readonly build_1_1_env_common=(
'BORDER_ROUTER=1'
'REFERENCE_DEVICE=1'
'COMMISSIONER=1'
'DHCP6_CLIENT=1'
'DHCP6_SERVER=1'
'JOINER=1'
'MAC_FILTER=1'
'BOOTLOADER=USB'
)
readonly build_1_1_env_nrf=(
'USB=1'
)
# Args
# - $1: The name of the hex file to zip
# - $2: The basename of the file
# - $3: Thread version number, e.g. 1.2
# - $4: Timestamp
# - $5: Commit ID
distribute()
{
local hex_file=$1
local zip_file="$2-$3-$4-$5.zip"
case "${platform}" in
nrf* | ncs*)
${NRFUTIL} pkg generate --debug-mode --hw-version 52 --sd-req 0 --application "${hex_file}" --key-file /tmp/private.pem "${zip_file}"
;;
*)
zip "${zip_file}" "${hex_file}"
;;
esac
mv "${zip_file}" "$OUTPUT_ROOT"
}
# Environment Vars
# - $thread_version: Thread version number, e.g. 1.2
# Args
# - $1: The basename of the file to zip, e.g. ot-cli-ftd
# - $2: The binary path (optional)
package_ot()
{
# Parse Args
local basename=${1?Please specify app basename}
local binary_path=${2:-"${build_dir}/bin/${basename}"}
thread_version=${thread_version?}
# Get build info
local commit_id
local timestamp
commit_id=$(cd "${repo_dir}"/openthread && git rev-parse --short HEAD)
timestamp=$(date +%Y%m%d)
# Generate .hex file
local hex_file="${basename}"-"${thread_version}".hex
if [ ! -f "$binary_path" ]; then
echo "WARN: $binary_path does not exist. Skipping packaging"
return
fi
arm-none-eabi-objcopy -O ihex "$binary_path" "${hex_file}"
# Distribute
distribute "${hex_file}" "${basename}" "${thread_version}" "${timestamp}" "${commit_id}"
}
# Envionment variables:
# - build_type: Type of build (optional)
# - build_script_flags: Any flags specific to the platform repo's build script (optional)
# Args:
# - $1 - thread_version: Thread version number, e.g. 1.2
# - $2 - platform_repo: Path to platform's repo, e.g. ot-efr32, ot-nrf528xx
build_ot()
{
thread_version=${thread_version?}
platform_repo=${platform_repo?}
mkdir -p "$OUTPUT_ROOT"
case "${thread_version}" in
"1.2"|"1.3"|"1.4")
# Build OpenThread 1.2 or 1.3 or 1.4
cd "${platform_repo}"
git clean -xfd
# Use OpenThread from top-level of repo
rm -rf openthread
# git_archive_all doesn't accept symbolic link, so make a copy of openthread and make
# it not a submodule
cp -rp ../openthread .
rm openthread/.git
# Build
build_dir=${OT_CMAKE_BUILD_DIR:-"${repo_dir}"/build-"${thread_version}"/"${platform}"}
if [ -z "${build_script_flags[@]}" ]; then
OT_CMAKE_BUILD_DIR="${build_dir}" ./script/build "${platform}" "${build_type:-}" "$@"
else
OT_CMAKE_BUILD_DIR="${build_dir}" ./script/build "${build_script_flags[@]}" "${platform}" "${build_type:-}" "$@"
fi
# Package and distribute
local dist_apps=(
ot-cli-ftd
ot-rcp
)
for app in "${dist_apps[@]}"; do
package_ot "${app}"
done
# Clean up
git clean -xfd
;;
"1.1")
# Build OpenThread 1.1
cd openthread-1.1
# Prep
git clean -xfd
./bootstrap
# Build
make -f examples/Makefile-"${platform}" "${options[@]}"
# Package and distribute
local dist_apps=(
ot-cli-ftd
ot-rcp
)
for app in "${dist_apps[@]}"; do
package_ot "${app}" "${thread_version}" output/"${platform}"/bin/"${app}"
done
# Clean up
git clean -xfd
;;
esac
cd "${repo_dir}"
}
die()
{
echo "$*" 1>&2
exit 1
}
nrfutil_setup()
{
# Setup nrfutil
if [[ $OSTYPE == "linux"* ]]; then
ostype=unknown-linux-gnu
arch=x86_64
elif [[ $OSTYPE == "darwin"* ]]; then
ostype=apple-darwin
arch=$(uname -m)
fi
NRFUTIL=/tmp/nrfutil-${ostype}-${arch}
if [ ! -f $NRFUTIL ]; then
wget -O $NRFUTIL https://files.nordicsemi.com/ui/api/v1/download?repoKey=swtools\&path=external/nrfutil/executables/${arch}-${ostype}/nrfutil
chmod +x $NRFUTIL
fi
$NRFUTIL install nrf5sdk-tools
$NRFUTIL install sdk-manager
$NRFUTIL install toolchain-manager
$NRFUTIL toolchain-manager install --ncs-version $(<"${script_dir}"'/../config/ncs/toolchain-version')
# Generate private key
if [ ! -f /tmp/private.pem ]; then
$NRFUTIL keys generate /tmp/private.pem
fi
}
deploy_ncs()
{
local commit_hash
commit_hash=$(<"${script_dir}"'/../config/ncs/sdk-nrf-commit')
pip3 install --user west
mkdir -p "${script_dir}"/../ncs
cd "${script_dir}"/../ncs
unset ZEPHYR_BASE
west init -m https://github.com/nrfconnect/sdk-nrf --mr main || true
cd nrf
git fetch origin
git reset --hard "$commit_hash" || die "ERROR: unable to checkout the specified sdk-nrf commit."
west update -n -o=--depth=1
cd ..
if [[ -n ${OPENTHREAD_COMMIT_HASH:=} ]]; then
echo "Using custom OT SHA: ${OPENTHREAD_COMMIT_HASH?}"
cd modules/lib/openthread
# remove remote if exists to make clean repository
if git remote | grep -q openthread; then
git remote remove openthread
fi
git remote add openthread https://github.com/openthread/openthread.git
git fetch openthread "$OPENTHREAD_COMMIT_HASH"
git checkout FETCH_HEAD || die "ERROR: unable to checkout the specified openthread commit."
cd ../../../
fi
}
build_ncs()
{
mkdir -p "$OUTPUT_ROOT"
deploy_ncs
cd nrf
thread_version=${thread_version?}
local timestamp=$(date +%Y%m%d)
local commit_id=$(git rev-parse --short HEAD)
# variant is a list of entries: "app:sample_name"
local variants
case "${thread_version}" in
1.1)
variants=("ot-cli-ftd:cli")
;;
*)
variants=("ot-cli-ftd:cli" "ot-rcp:coprocessor")
;;
esac
for variant in "${variants[@]}"; do
local app=$(echo $variant | cut -d':' -f1)
local sample_name=$(echo $variant | cut -d':' -f2)
local sample_path="samples/openthread/${sample_name}"
local sample_config_path="${script_dir}/../config/ncs/overlay"
local sample_config="${sample_config_path}-common.conf;${sample_config_path}-${app}-common.conf;${sample_config_path}-${app}-${thread_version}.conf"
local build_path="/tmp/ncs_${app}_${thread_version}"
local hex_path="${build_path}/${sample_name}/zephyr/zephyr.hex"
$NRFUTIL sdk-manager toolchain launch --ncs-version $(<"${script_dir}"'/../config/ncs/toolchain-version') -- \
west build -d "${build_path}" -b nrf52840dongle/nrf52840 -p always "${sample_path}" --sysbuild -- -DOVERLAY_CONFIG="${sample_config}"
distribute "${hex_path}" "${app}" "${thread_version}" "${timestamp}" "${commit_id}"
done
}
build()
{
if [ "${REFERENCE_RELEASE_TYPE?}" = "1.2" ]; then
build_1_2_options=("${build_1_2_options_common[@]}")
build_1_1_env=("${build_1_1_env_common[@]}")
case "${platform}" in
nrf*)
build_1_2_options+=("${build_1_2_options_nrf[@]}")
build_1_1_env+=("${build_1_1_env_nrf[@]}")
platform_repo=ot-nrf528xx
thread_version=1.2 build_type="USB_trans" build_ot "${build_1_2_options[@]}" "$@"
thread_version=1.1 build_type="USB_trans" build_ot "${build_1_1_env[@]}" "$@"
;;
ncs)
thread_version=1.2 build_ncs
thread_version=1.1 build_ncs
;;
esac
elif [ "${REFERENCE_RELEASE_TYPE}" = "1.3" ]; then
options=("${build_1_3_options_common[@]}")
case "${platform}" in
nrf*)
options+=("${build_1_3_options_nrf[@]}")
platform_repo=ot-nrf528xx
thread_version=1.3 build_type="USB_trans" build_ot "${options[@]}" "$@"
;;
efr32mg12)
platform_repo=ot-efr32
build_script_flags=("--skip-silabs-apps")
thread_version=1.3 build_ot "-DBOARD=brd4166a" "${options[@]}" "$@"
;;
ncs)
thread_version=1.3 build_ncs
;;
esac
elif [ "${REFERENCE_RELEASE_TYPE}" = "1.4" ]; then
options=("${build_1_4_options_common[@]}")
case "${platform}" in
nrf*)
options+=("${build_1_4_options_nrf[@]}")
platform_repo=ot-nrf528xx
thread_version=1.4 build_type="USB_trans" build_ot "${options[@]}" "$@"
;;
efr32mg12)
platform_repo=ot-efr32
build_script_flags=("--skip-silabs-apps")
thread_version=1.4 build_ot "-DBOARD=brd4166a" "${options[@]}" "$@"
;;
ncs)
thread_version=1.4 build_ncs
;;
esac
else
die "Error: REFERENCE_RELEASE_TYPE = ${REFERENCE_RELEASE_TYPE} is unsupported"
fi
}
main()
{
readonly OT_PLATFORMS=(nrf52840 efr32mg12 ncs)
local platforms=()
if [[ $# == 0 ]]; then
platforms=("${OT_PLATFORMS[@]}")
else
platforms=("$1")
shift
fi
# Print OUTPUT_ROOT. Error if OUTPUT_ROOT is not defined
OUTPUT_ROOT=$(realpath "${OUTPUT_ROOT?}")
echo "OUTPUT_ROOT=${OUTPUT_ROOT}"
mkdir -p "${OUTPUT_ROOT}"
for p in "${platforms[@]}"; do
# Check if the platform is supported.
echo "${OT_PLATFORMS[@]}" | grep -wq "${p}" || die "ERROR: Unsupported platform: ${p}"
printf "\n\n======================================\nBuilding firmware for %s\n======================================\n\n" "${p}"
platform=${p}
case "${platform}" in
nrf* | ncs*)
nrfutil_setup
;;
esac
build "$@"
done
}
main "$@"