blob: 8f3a61a86351a0f5d4aefa06896c210a6ac182e5 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05003# Copyright (c) 2019-2021 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# Builds a package with Trusted Firwmare and other payload binaries. The package
9# is meant to be executed by run_package.sh
10
11set -e
12
13ci_root="$(readlink -f "$(dirname "$0")/..")"
14source "$ci_root/utils.sh"
15
16if [ ! -d "$workspace" ]; then
17 die "Directory $workspace doesn't exist"
18fi
19
20# Directory to where the source code e.g. for Trusted Firmware is checked out.
Zelalem219df412020-05-17 19:21:20 -050021export tf_root="${tf_root:-$workspace/trusted_firmware}"
22export tftf_root="${tftf_root:-$workspace/trusted_firmware_tf}"
23export scp_root="${scp_root:-$workspace/scp}"
24scp_tools_root="${scp_tools_root:-$workspace/scp_tools}"
25cc_root="${cc_root:-$ccpathspec}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010026spm_root="${spm_root:-$workspace/spm}"
Zelalem219df412020-05-17 19:21:20 -050027
28scp_tf_tools_root="$scp_tools_root/scp_tf_tools"
Fathi Boudra422bf772019-12-02 11:10:16 +020029
30# Refspecs
31tf_refspec="$TF_REFSPEC"
32tftf_refspec="$TFTF_REFSPEC"
33scp_refspec="$SCP_REFSPEC"
Zelalem219df412020-05-17 19:21:20 -050034scp_tools_commit="${SCP_TOOLS_COMMIT:-master}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010035spm_refspec="$SPM_REFSPEC"
Fathi Boudra422bf772019-12-02 11:10:16 +020036
37test_config="${TEST_CONFIG:?}"
38test_group="${TEST_GROUP:?}"
39build_configs="${BUILD_CONFIG:?}"
40run_config="${RUN_CONFIG:?}"
Zelalem219df412020-05-17 19:21:20 -050041cc_config="${CC_ENABLE:-}"
Fathi Boudra422bf772019-12-02 11:10:16 +020042
43archive="$artefacts"
44build_log="$artefacts/build.log"
45fiptool="$tf_root/tools/fiptool/fiptool"
46cert_create="$tf_root/tools/cert_create/cert_create"
47
48# Validate $bin_mode
49case "$bin_mode" in
50 "" | debug | release)
51 ;;
52 *)
53 die "Invalid value for bin_mode: $bin_mode"
54 ;;
55esac
56
57# File to save any environem
58hook_env_file="$(mktempfile)"
59
60# Check if a config is valid
61config_valid() {
62 local config="${1?}"
63 if [ -z "$config" ] || [ "$(basename "$config")" = "nil" ]; then
64 return 1
65 fi
66
67 return 0
68}
69
70# Echo from a build wrapper. Print to descriptor 3 that's opened by the build
71# function.
72echo_w() {
73 echo $echo_flags "$@" >&3
74}
75
76# Print a separator to the log file. Intended to be used at the tail end of a pipe
77log_separator() {
78 {
79 echo
80 echo "----------"
81 } >> "$build_log"
82
83 tee -a "$build_log"
84
85 {
86 echo "----------"
87 echo
88 } >> "$build_log"
89}
90
91# Call function $1 if it's defined
92call_func() {
93 if type "${1:?}" &>/dev/null; then
94 echo
95 echo "> ${2:?}:$1()"
96 eval "$1"
97 echo "< $2:$1()"
98 fi
99}
100
101# Call hook $1 in all chosen fragments if it's defined. Hooks are invoked from
102# within a subshell, so any variables set within a hook are lost. Should a
103# variable needs to be set from within a hook, the function 'set_hook_var'
104# should be used
105call_hook() {
106 local func="$1"
107 local config_fragment
108
109 [ -z "$func" ] && return 0
110
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300111 echo "=== Calling hooks: $1 ==="
112
Fathi Boudra422bf772019-12-02 11:10:16 +0200113 : >"$hook_env_file"
114
115 if [ "$run_config_candiates" ]; then
116 for config_fragment in $run_config_candiates; do
117 (
118 source "$ci_root/run_config/$config_fragment"
119 call_func "$func" "$config_fragment"
120 )
121 done
122 fi
123
124 # Also source test config file
125 (
126 unset "$func"
127 source "$test_config_file"
128 call_func "$func" "$(basename $test_config_file)"
129 )
130
131 # Have any variables set take effect
132 source "$hook_env_file"
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300133
134 echo "=== End calling hooks: $1 ==="
Fathi Boudra422bf772019-12-02 11:10:16 +0200135}
136
137# Set a variable from within a hook
138set_hook_var() {
139 echo "export $1=\"${2?}\"" >> "$hook_env_file"
140}
141
142# Append to an array from within a hook
143append_hook_var() {
144 echo "export $1+=\"${2?}\"" >> "$hook_env_file"
145}
146
147# Have the main build script source a file
148source_later() {
149 echo "source ${1?}" >> "$hook_env_file"
150}
151
152# Setup TF build wrapper function by pointing to a script containing a function
153# that will be called with the TF build commands.
154setup_tf_build_wrapper() {
155 source_later "$ci_root/script/${wrapper?}_wrapper.sh"
156 set_hook_var "tf_build_wrapper" "${wrapper}_wrapper"
157 echo "Setup $wrapper build wrapper."
158}
159
160# Collect .bin files for archiving
161collect_build_artefacts() {
162 if [ ! -d "${from:?}" ]; then
163 return
164 fi
165
Javier Almansa Sobrinof98dbd82020-09-30 19:29:27 +0100166 if ! find "$from" \( -name "*.bin" -o -name '*.elf' -o -name '*.dtb' -o -name '*.axf' \) -exec cp -t "${to:?}" '{}' +; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200167 echo "You probably are running local CI on local repositories."
168 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
169 die
170 fi
171}
172
173# SCP and MCP binaries are named firmware.{bin,elf}, and are placed under
174# scp/mcp_ramfw and scp/mcp_romfw directories, so can't be collected by
175# collect_build_artefacts function.
176collect_scp_artefacts() {
177 to="${to:?}" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000178 find "$scp_root" \( \( -name "*.bin" -o -name '*.elf' \) -and ! -name 'CMake*' \) -exec bash -c '
Fathi Boudra422bf772019-12-02 11:10:16 +0200179 for file; do
180 ext="$(echo $file | awk -F. "{print \$NF}")"
181 case $file in
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000182 */firmware-scp_ramfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200183 cp $file $to/scp_ram.$ext
184 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000185 */firmware-scp_ramfw_fvp/bin/*)
Anurag Koulc7f61ce2021-02-24 19:11:06 +0000186 cp $file $to/scp_ramfw_fvp.$ext
187 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000188 */firmware-scp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200189 cp $file $to/scp_rom.$ext
190 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000191 */firmware-mcp_ramfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200192 cp $file $to/mcp_ram.$ext
193 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000194 */firmware-mcp_ramfw_fvp/bin/*)
Anurag Koulc7f61ce2021-02-24 19:11:06 +0000195 cp $file $to/mcp_ramfw_fvp.$ext
196 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000197 */firmware-mcp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200198 cp $file $to/mcp_rom.$ext
199 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000200 */firmware-scp_romfw_bypass/bin/*)
Zelalem219df412020-05-17 19:21:20 -0500201 cp $file $to/scp_rom_bypass.$ext
202 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200203 *)
204 echo "Unknown SCP binary: $file" >&2
205 ;;
206 esac
207 done
208 ' bash '{}' +
209}
210
Manish Pandey1e7be852020-11-09 16:04:48 +0000211# Collect SPM/hafnium artefacts with "secure_" appended to the files
212# generated for SPM(secure hafnium).
213collect_spm_artefacts() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500214 if [ -d "${non_secure_from:?}" ]; then
215 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000216 fi
217
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500218 if [ -d "${secure_from:?}" ]; then
219 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
220 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000221}
222
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100223# Map the UART ID used for expect with the UART descriptor and port
224# used by the FPGA automation tools.
225map_uart() {
226 local port="${port:?}"
227 local descriptor="${descriptor:?}"
228 local baudrate="${baudrate:?}"
229 local run_root="${archive:?}/run"
230
231 local uart_dir="$run_root/uart${uart:?}"
232 mkdir -p "$uart_dir"
233
234 echo "$port" > "$uart_dir/port"
235 echo "$descriptor" > "$uart_dir/descriptor"
236 echo "$baudrate" > "$uart_dir/baudrate"
237
238 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
239}
240
Fathi Boudra422bf772019-12-02 11:10:16 +0200241# Arrange environment varibles to be set when expect scripts are launched
242set_expect_variable() {
243 local var="${1:?}"
244 local val="${2?}"
245
246 local run_root="${archive:?}/run"
247 local uart_dir="$run_root/uart${uart:?}"
248 mkdir -p "$uart_dir"
249
250 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
251 echo "UART$uart: env has $@"
252}
253
254# Place the binary package a pointer to expect script, and its parameters
255track_expect() {
256 local file="${file:?}"
257 local timeout="${timeout-600}"
258 local run_root="${archive:?}/run"
259
260 local uart_dir="$run_root/uart${uart:?}"
261 mkdir -p "$uart_dir"
262
263 echo "$file" > "$uart_dir/expect"
264 echo "$timeout" > "$uart_dir/timeout"
265
266 echo "UART$uart to be tracked with $file; timeout ${timeout}s"
267
268 # The run script assumes UART0 to be primary. If we're asked to set any
269 # other UART to be primary, set a run environment variable to signal
270 # that to the run script
271 if upon "$set_primary"; then
272 echo "Primary UART set to UART$uart."
273 set_run_env "primary_uart" "$uart"
274 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600275
276 # UART used by payload(such as tftf, Linux) may not be the same as the
277 # primary UART. Set a run environment variable to track the payload
278 # UART which is tracked to check if the test has finished sucessfully.
279 if upon "$set_payload_uart"; then
280 echo "Payload uses UART$uart."
281 set_run_env "payload_uart" "$uart"
282 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200283}
284
285# Extract a FIP in $1 using fiptool
286extract_fip() {
287 local fip="$1"
288
289 if is_url "$1"; then
290 url="$1" fetch_file
291 fip="$(basename "$1")"
292 fi
293
294 "$fiptool" unpack "$fip"
295 echo "Extracted FIP: $fip"
296}
297
298# Report build failure by printing a the tail end of build log. Archive the
299# build log for later inspection
300fail_build() {
301 local log_path
302
303 if upon "$jenkins_run"; then
304 log_path="$BUILD_URL/artifact/artefacts/build.log"
305 else
306 log_path="$build_log"
307 fi
308
309 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600310 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200311 echo "[...]"
312 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600313 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200314 echo
315 echo "See $log_path for full output"
316 echo
317 cp -t "$archive" "$build_log"
318 exit 1;
319}
320
321# Build a FIP with supplied arguments
322build_fip() {
323 (
324 echo "Building FIP with arguments: $@"
325 local tf_env="$workspace/tf.env"
326
327 if [ -f "$tf_env" ]; then
328 set -a
329 source "$tf_env"
330 set +a
331 fi
332
333 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
334 ${fip_targets:-fip} &>>"$build_log" || fail_build
335 )
336}
337
338fip_update() {
339 # Before the update process, check if the given image is supported by
340 # the fiptool. It's assumed that both fiptool and cert_create move in
341 # tandem, and therfore, if one has support, the other has it too.
342 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
343 return 1
344 fi
345
346 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
347 echo "Updating FIP image: $bin_name"
348 # Update HW config. Without TBBR, it's only a matter of using
349 # the update sub-command of fiptool
350 "$fiptool" update "--$bin_name" "${src:-}" \
351 "$archive/fip.bin"
352 else
353 echo "Updating FIP image (TBBR): $bin_name"
354 # With TBBR, we need to unpack, re-create certificates, and then
355 # recreate the FIP.
356 local fip_dir="$(mktempdir)"
357 local bin common_args stem
358 local rot_key="$(get_tf_opt ROT_KEY)"
359
360 rot_key="${rot_key:?}"
361 if ! is_abs "$rot_key"; then
362 rot_key="$tf_root/$rot_key"
363 fi
364
365 # Arguments only for cert_create
366 local cert_args="-n"
367 cert_args+=" --tfw-nvctr ${nvctr:-31}"
368 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
369 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
370 cert_args+=" --rot-key $rot_key"
371
372 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500373 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200374 "hw-config"
375 "tb-fw-config"
376 "nt-fw-config"
377 "soc-fw-config"
378 "tos-fw-config"
379 )
380
381 # Binaries without key certificates
382 declare -A has_no_key_cert
383 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
384 has_no_key_cert["$bin"]="1"
385 done
386
387 # Binaries without certificates
388 declare -A has_no_cert
389 for bin in "hw-config" "${dyn_config_opts[@]}"; do
390 has_no_cert["$bin"]="1"
391 done
392
393 pushd "$fip_dir"
394
395 # Unpack FIP
396 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
397
398 # Remove all existing certificates
399 rm -f *-cert.bin
400
401 # Copy the binary to be updated
402 cp -f "$src" "${bin_name}.bin"
403
404 # FIP unpack dumps binaries with the same name as the option
405 # used to pack it; likewise for certificates. Reverse-engineer
406 # the command line from the binary output.
407 common_args="--trusted-key-cert trusted_key.crt"
408 for bin in *.bin; do
409 stem="${bin%%.bin}"
410 common_args+=" --$stem $bin"
411 if not_upon "${has_no_cert[$stem]}"; then
412 common_args+=" --$stem-cert $stem.crt"
413 fi
414 if not_upon "${has_no_key_cert[$stem]}"; then
415 common_args+=" --$stem-key-cert $stem-key.crt"
416 fi
417 done
418
419 # Create certificates
420 "$cert_create" $cert_args $common_args &>>"$build_log"
421
422 # Recreate and archive FIP
423 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
424 archive_file "fip.bin"
425
426 popd
427 fi
428}
429
430# Update hw-config in FIP, and remove the original DTB afterwards.
431update_fip_hw_config() {
432 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600433 # in configs:
434 # 1. Where BL2 isn't present
435 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200436 case "1" in
437 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600438 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200439 "$(get_tf_opt RESET_TO_SP_MIN)" | \
440 "$(get_tf_opt BL2_AT_EL3)")
441 return 0;;
442 esac
443
444 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
445 # Remove the DTB so that model won't load it
446 rm -f "$archive/dtb.bin"
447 fi
448}
449
450get_scp_opt() {
451 (
452 name="${1:?}"
453 if config_valid "$scp_config_file"; then
454 source "$scp_config_file"
455 echo "${!name}"
456 fi
457 )
458}
459
460get_tftf_opt() {
461 (
462 name="${1:?}"
463 if config_valid "$tftf_config_file"; then
464 source "$tftf_config_file"
465 echo "${!name}"
466 fi
467 )
468}
469
470get_tf_opt() {
471 (
472 name="${1:?}"
473 if config_valid "$tf_config_file"; then
474 source "$tf_config_file"
475 echo "${!name}"
476 fi
477 )
478}
479
480build_tf() {
481 (
482 env_file="$workspace/tf.env"
483 config_file="${tf_build_config:-$tf_config_file}"
484
485 # Build fiptool and all targets by default
486 build_targets="${tf_build_targets:-fiptool all}"
487
488 source "$config_file"
489
490 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000491 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
492 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200493 mbedtls_dir="$workspace/mbedtls"
494 if [ ! -d "$mbedtls_dir" ]; then
495 mbedtls_ar="$workspace/mbedtls.tar.gz"
496
497 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
498 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500499 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200500 fi
501
502 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
503 fi
504
505 if [ -f "$env_file" ]; then
506 set -a
507 source "$env_file"
508 set +a
509 fi
510
511 cd "$tf_root"
512
513 # Always distclean when running on Jenkins. Skip distclean when running
514 # locally and explicitly requested.
515 if upon "$jenkins_run" || not_upon "$dont_clean"; then
516 make distclean &>>"$build_log" || fail_build
517 fi
518
519 # Log build command line. It is left unfolded on purpose to assist
520 # copying to clipboard.
521 cat <<EOF | log_separator >/dev/null
522
523Build command line:
524 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
525
526EOF
527
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000528 if not_upon "$local_ci"; then
529 connect_debugger=0
530 fi
531
Fathi Boudra422bf772019-12-02 11:10:16 +0200532 # Build TF. Since build output is being directed to the build log, have
533 # descriptor 3 point to the current terminal for build wrappers to vent.
534 $tf_build_wrapper make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000535 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200536 $build_targets 3>&1 &>>"$build_log" || fail_build
537 )
538}
539
540build_tftf() {
541 (
542 config_file="${tftf_build_config:-$tftf_config_file}"
543
544 # Build tftf target by default
545 build_targets="${tftf_build_targets:-all}"
546
547 source "$config_file"
548
549 cd "$tftf_root"
550
551 # Always distclean when running on Jenkins. Skip distclean when running
552 # locally and explicitly requested.
553 if upon "$jenkins_run" || not_upon "$dont_clean"; then
554 make distclean &>>"$build_log" || fail_build
555 fi
556
557 # TFTF build system cannot reliably deal with -j option, so we avoid
558 # using that.
559
560 # Log build command line
561 cat <<EOF | log_separator >/dev/null
562
563Build command line:
564 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
565
566EOF
567
568 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
569 $build_targets &>>"$build_log" || fail_build
570 )
571}
572
573build_scp() {
574 (
575 config_file="${scp_build_config:-$scp_config_file}"
576
577 source "$config_file"
578
579 cd "$scp_root"
580
581 # Always distclean when running on Jenkins. Skip distclean when running
582 # locally and explicitly requested.
583 if upon "$jenkins_run" || not_upon "$dont_clean"; then
584 make clean &>>"$build_log" || fail_build
585 fi
586
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000587 python3 -m venv .venv
588 . .venv/bin/activate
589
590 # Install extra tools used by CMake build system
591 pip install -r requirements.txt --timeout 30 --retries 15
592
Fathi Boudra422bf772019-12-02 11:10:16 +0200593 # Log build command line. It is left unfolded on purpose to assist
594 # copying to clipboard.
595 cat <<EOF | log_separator >/dev/null
596
597SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000598 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
599 TOOLCHAIN=GNU \
600 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000601 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000602 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200603
604EOF
605
606 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000607 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
608 TOOLCHAIN=GNU \
609 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000610 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000611 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200612 || fail_build
613 )
614}
615
Zelalem219df412020-05-17 19:21:20 -0500616clone_scp_tools() {
617
618 if [ ! -d "$scp_tools_root" ]; then
619 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
620
621 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
622 where="$scp_tools_root" \
623 refspec="${scp_tools_commit}"
624 clone_repo &>>"$build_log"
625 else
626 echo "Already cloned SCP-tools ..." |& log_separator
627 fi
628
629 show_head "$scp_tools_root"
630
631 cd "$scp_tools_root"
632
633 echo "Updating submodules"
634
635 git submodule init
636
637 git submodule update
638
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000639 lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'")
640
Zelalem219df412020-05-17 19:21:20 -0500641 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000642 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500643
644 git show --quiet --no-color | sed 's/^/ > /g'
645}
646
647clone_tf_for_scp_tools() {
648 scp_tools_arm_tf="$scp_tools_root/arm-tf"
649
650 if [ ! -d "$scp_tools_arm_tf" ]; then
651 echo "Cloning TF-4-SCP-tools ..." |& log_separator
652
653 clone_url="$tf_for_scp_tools_src_repo_url"
654 where="$scp_tools_arm_tf"
655
656 git clone "$clone_url" "$where"
657
658 cd "$scp_tools_arm_tf"
659
Joel Goddard3ad03062021-03-16 16:47:42 +0000660 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500661
662 git show --quiet --no-color | sed 's/^/ > /g'
663
664 else
665 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
666 fi
667}
668
669build_scmi_lib_scp_tools() {
670 (
671 cd "$scp_tools_root"
672
673 cd "scmi"
674
675 scp_tools_arm_tf="$scp_tools_root/arm-tf"
676
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600677 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500678
679 std_libs="-I$scp_tools_arm_tf/include/common"
680 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
681 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
682 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
683 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
684 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
685 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
686 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
687 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
688 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
689 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
690 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
691 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
692 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
693
694 cflags="-Og -g"
695 cflags="$cflags -mgeneral-regs-only"
696 cflags="$cflags -mstrict-align"
697 cflags="$cflags -nostdinc"
698 cflags="$cflags -fno-inline"
699 cflags="$cflags -ffreestanding"
700 cflags="$cflags -ffunction-sections"
701 cflags="$cflags -fdata-sections"
702 cflags="$cflags -DAARCH64"
703 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000704 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500705
706 cflags="$cflags $std_libs"
707
Joel Goddard3ad03062021-03-16 16:47:42 +0000708 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500709
710 echo "Building SCMI library (SCP-tools) ..."
711
712 make "CROSS_COMPILE=$cross_compile" \
713 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000714 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500715 "PROTOCOLS=$protocols" \
716 "clean" \
717 "all"
718 )
719}
720
721build_tf_for_scp_tools() {
722
723 cd "$scp_tools_root/arm-tf"
724
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600725 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500726
727 if [ "$1" = "release" ]; then
728 echo "Build TF-4-SCP-Tools rls..."
729 else
730 echo "Build TF-4-SCP-Tools dbg..."
731
732 make realclean
733
734 make "BM_TEST=scmi" \
735 "ARM_BOARD_OPTIMISE_MEM=1" \
736 "BM_CSS=juno" \
737 "CSS_USE_SCMI_SDS_DRIVER=1" \
738 "PLAT=juno" \
739 "DEBUG=1" \
740 "PLATFORM=juno" \
741 "CROSS_COMPILE=$cross_compile" \
742 "BM_WORKSPACE=$scp_tools_root/baremetal"
743
744 archive_file "build/juno/debug/bl1.bin"
745
746 archive_file "build/juno/debug/bl2.bin"
747
748 archive_file "build/juno/debug/bl31.bin"
749 fi
750}
751
752build_fip_for_scp_tools() {
753
754 cd "$scp_tools_root/arm-tf"
755
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600756 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500757
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000758 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500759 make fiptool
760 echo "Make FIP 4 SCP-Tools rls..."
761
762 else
763 make fiptool
764 echo "Make FIP 4 SCP-Tools dbg..."
765
766 make "PLAT=juno" \
767 "all" \
768 "fip" \
769 "DEBUG=1" \
770 "CROSS_COMPILE=$cross_compile" \
771 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
772 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000773 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500774
775 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
776 fi
777}
778
779build_cc() {
780# Building code coverage plugin
781 ARM_DIR=/arm
782 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
783 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
784 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
785 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
786 exit -1
787 fi # Error if arm warehouse not found
788 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
789
790 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
791}
792
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100793build_spm() {
794 (
795 env_file="$workspace/spm.env"
796 config_file="${spm_build_config:-$spm_config_file}"
797
798 source "$config_file"
799
800 if [ -f "$env_file" ]; then
801 set -a
802 source "$env_file"
803 set +a
804 fi
805
806 cd "$spm_root"
807
808 # Always clean when running on Jenkins. Skip clean when running
809 # locally and explicitly requested.
810 if upon "$jenkins_run" || not_upon "$dont_clean"; then
811 # make clean fails on a fresh repo where the project has not
812 # yet been built. Hence only clean if out/reference directory
813 # already exists.
814 if [ -d "out/reference" ]; then
815 make clean &>>"$build_log" || fail_build
816 fi
817 fi
818
819 # Log build command line. It is left unfolded on purpose to assist
820 # copying to clipboard.
821 cat <<EOF | log_separator >/dev/null
822
823Build command line:
824 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
825
826EOF
827
828 # Build SPM. Since build output is being directed to the build log, have
829 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200830 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
831
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100832 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
833 || fail_build
834 )
835}
Zelalem219df412020-05-17 19:21:20 -0500836
Fathi Boudra422bf772019-12-02 11:10:16 +0200837# Set metadata for the whole package so that it can be used by both Jenkins and
838# shell
839set_package_var() {
840 env_file="$artefacts/env" emit_env "$@"
841}
842
843set_tf_build_targets() {
844 echo "Set build target to '${targets:?}'"
845 set_hook_var "tf_build_targets" "$targets"
846}
847
848set_tftf_build_targets() {
849 echo "Set build target to '${targets:?}'"
850 set_hook_var "tftf_build_targets" "$targets"
851}
852
853set_scp_build_targets() {
854 echo "Set build target to '${targets:?}'"
855 set_hook_var "scp_build_targets" "$targets"
856}
857
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100858set_spm_build_targets() {
859 echo "Set build target to '${targets:?}'"
860 set_hook_var "spm_build_targets" "$targets"
861}
862
Fathi Boudra422bf772019-12-02 11:10:16 +0200863# Look under $archive directory for known files such as blX images, kernel, DTB,
864# initrd etc. For each known file foo, if foo.bin exists, then set variable
865# foo_bin to the path of the file. Make the path relative to the workspace so as
866# to remove any @ characters, which Jenkins inserts for parallel runs. If the
867# file doesn't exist, unset its path.
868set_default_bin_paths() {
869 local image image_name image_path path
870 local archive="${archive:?}"
871 local set_vars
872 local var
873
874 pushd "$archive"
875
876 for file in *.bin; do
877 # Get a shell variable from the file's stem
878 var_name="${file%%.*}_bin"
879 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
880
881 # Skip setting the variable if it's already
882 if [ "${!var_name}" ]; then
883 echo "Note: not setting $var_name; already set to ${!var_name}"
884 continue
885 else
886 set_vars+="$var_name "
887 fi
888
889 eval "$var_name=$file"
890 done
891
892 echo "Binary paths set for: "
893 {
894 for var in $set_vars; do
895 echo -n "\$$var "
896 done
897 } | fmt -80 | sed 's/^/ /'
898 echo
899
900 popd
901}
902
903gen_model_params() {
904 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000905 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200906
907 set_default_bin_paths
908 echo "Generating model parameter for $model..."
909 source "$ci_root/model/${model:?}.sh"
910 archive_file "$model_param_file"
911}
912
913set_model_path() {
914 set_run_env "model_path" "${1:?}"
915}
916
Zelalem1af7a7b2020-08-04 17:34:32 -0500917set_model_env() {
918 local var="${1:?}"
919 local val="${2?}"
920 local run_root="${archive:?}/run"
921
922 mkdir -p "$run_root"
923 echo "export $var=$val" >> "$run_root/model_env"
924}
Fathi Boudra422bf772019-12-02 11:10:16 +0200925set_run_env() {
926 local var="${1:?}"
927 local val="${2?}"
928 local run_root="${archive:?}/run"
929
930 mkdir -p "$run_root"
931 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
932}
933
934show_head() {
935 # Display HEAD descripton
936 pushd "$1"
937 git show --quiet --no-color | sed 's/^/ > /g'
938 echo
939 popd
940}
941
942# Choose debug binaries to run; by default, release binaries are chosen to run
943use_debug_bins() {
944 local run_root="${archive:?}/run"
945
946 echo "Choosing debug binaries for execution"
947 set_package_var "BIN_MODE" "debug"
948}
949
950assert_can_git_clone() {
951 local name="${1:?}"
952 local dir="${!name}"
953
954 # If it doesn't exist, it can be cloned into
955 if [ ! -e "$dir" ]; then
956 return 0
957 fi
958
959 # If it's a directory, it must be a Git clone already
960 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
961 # No need to clone again
962 echo "Using existing git clone for $name: $dir"
963 return 1
964 fi
965
966 die "Path $dir exists but is not a git clone"
967}
968
969clone_repo() {
970 if ! is_url "${clone_url?}"; then
971 # For --depth to take effect on local paths, it needs to use the
972 # file:// scheme.
973 clone_url="file://$clone_url"
974 fi
975
976 git clone -q --depth 1 "$clone_url" "${where?}"
977 if [ "$refspec" ]; then
978 pushd "$where"
979 git fetch -q --depth 1 origin "$refspec"
980 git checkout -q FETCH_HEAD
981 popd
982 fi
983}
984
985build_unstable() {
986 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
987}
988
989undo_patch_record() {
990 if [ ! -f "${patch_record:?}" ]; then
991 return
992 fi
993
994 # Undo patches in reverse
995 echo
996 for patch_name in $(tac "$patch_record"); do
997 echo "Undoing $patch_name..."
998 if ! git apply -R "$ci_root/patch/$patch_name"; then
999 if upon "$local_ci"; then
1000 echo
1001 echo "Your local directory may have been dirtied."
1002 echo
1003 fi
1004 fail_build
1005 fi
1006 done
1007
1008 rm -f "$patch_record"
1009}
1010
1011undo_local_patches() {
1012 pushd "$tf_root"
1013 patch_record="$tf_patch_record" undo_patch_record
1014 popd
1015
1016 if [ -d "$tftf_root" ]; then
1017 pushd "$tftf_root"
1018 patch_record="$tftf_patch_record" undo_patch_record
1019 popd
1020 fi
1021}
1022
1023undo_tftf_patches() {
1024 pushd "$tftf_root"
1025 patch_record="$tftf_patch_record" undo_patch_record
1026 popd
1027}
1028
1029undo_tf_patches() {
1030 pushd "$tf_root"
1031 patch_record="$tf_patch_record" undo_patch_record
1032 popd
1033}
1034
1035apply_patch() {
1036 # If skip_patches is set, the developer has applied required patches
1037 # manually. They probably want to keep them applied for debugging
1038 # purposes too. This means we don't have to apply/revert them as part of
1039 # build process.
1040 if upon "$skip_patches"; then
1041 echo "Skipped applying ${1:?}..."
1042 return 0
1043 else
1044 echo "Applying ${1:?}..."
1045 fi
1046
1047 if git apply < "$ci_root/patch/$1"; then
1048 echo "$1" >> "${patch_record:?}"
1049 else
1050 if upon "$local_ci"; then
1051 undo_local_patches
1052 fi
1053 fail_build
1054 fi
1055}
1056
1057apply_tftf_patch() {
1058 pushd "$tftf_root"
1059 patch_record="$tftf_patch_record" apply_patch "$1"
1060 popd
1061}
1062
1063apply_tf_patch() {
1064 pushd "$tf_root"
1065 patch_record="$tf_patch_record" apply_patch "$1"
1066 popd
1067}
1068
1069# Clear workspace for a local run
1070if not_upon "$jenkins_run"; then
1071 rm -rf "$workspace"
1072
1073 # Clear residue from previous runs
1074 rm -rf "$archive"
1075fi
1076
1077mkdir -p "$workspace"
1078mkdir -p "$archive"
1079set_package_var "TEST_CONFIG" "$test_config"
1080
1081{
1082echo
1083echo "CONFIGURATION: $test_group/$test_config"
1084echo
1085} |& log_separator
1086
1087tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1088tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1089scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001090scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001091spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001092
1093test_config_file="$ci_root/group/$test_group/$test_config"
1094
1095tf_config_file="$ci_root/tf_config/$tf_config"
1096tftf_config_file="$ci_root/tftf_config/$tftf_config"
1097scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001098scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001099spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001100
1101# File that keeps track of applied patches
1102tf_patch_record="$workspace/tf_patches"
1103tftf_patch_record="$workspace/tftf_patches"
1104
1105pushd "$workspace"
1106
1107if ! config_valid "$tf_config"; then
1108 tf_config=
1109else
1110 echo "Trusted Firmware config:"
1111 echo
1112 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1113 echo
1114fi
1115
1116if ! config_valid "$tftf_config"; then
1117 tftf_config=
1118else
1119 echo "Trusted Firmware TF config:"
1120 echo
1121 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1122 echo
1123fi
1124
1125if ! config_valid "$scp_config"; then
1126 scp_config=
1127else
1128 echo "SCP firmware config:"
1129 echo
1130 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1131 echo
1132fi
1133
Zelalem219df412020-05-17 19:21:20 -05001134if ! config_valid "$scp_tools_config"; then
1135 scp_tools_config=
1136else
1137 echo "SCP Tools config:"
1138 echo
1139 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001140fi
1141
1142if ! config_valid "$spm_config"; then
1143 spm_config=
1144else
1145 echo "SPM config:"
1146 echo
1147 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001148 echo
1149fi
1150
Fathi Boudra422bf772019-12-02 11:10:16 +02001151if ! config_valid "$run_config"; then
1152 run_config=
1153fi
1154
1155if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1156 # If the Trusted Firmware repository has already been checked out, use
1157 # that location. Otherwise, clone one ourselves.
1158 echo "Cloning Trusted Firmware..."
1159 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1160 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1161 show_head "$tf_root"
1162fi
1163
1164if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1165 # If the Trusted Firmware TF repository has already been checked out,
1166 # use that location. Otherwise, clone one ourselves.
1167 echo "Cloning Trusted Firmware TF..."
1168 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1169 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1170 show_head "$tftf_root"
1171fi
1172
1173if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1174 # If the SCP firmware repository has already been checked out,
1175 # use that location. Otherwise, clone one ourselves.
1176 echo "Cloning SCP Firmware..."
1177 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1178 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1179
1180 pushd "$scp_root"
1181
1182 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001183 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001184 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1185 fi
1186
1187 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1188 # then to project filer if accessible.
1189 if [ -z "$cmsis_reference" ]; then
1190 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1191 if [ -d "$cmsis_ref_repo" ]; then
1192 cmsis_reference="--reference $cmsis_ref_repo"
1193 fi
1194 fi
1195
1196 git submodule -q update $cmsis_reference --init
1197
1198 popd
1199
1200 show_head "$scp_root"
1201fi
1202
Zelalem219df412020-05-17 19:21:20 -05001203if [ -n "$cc_config" ] ; then
1204 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1205 # Copy code coverage repository
1206 echo "Cloning Code Coverage..."
1207 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1208 show_head "$cc_root"
1209 fi
1210fi
1211
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001212if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1213 # If the SPM repository has already been checked out, use
1214 # that location. Otherwise, clone one ourselves.
1215 echo "Cloning SPM..."
1216 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1217 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1218
1219 # Query git submodules
1220 pushd "$spm_root"
1221 git submodule update --init
1222 popd
1223
1224 show_head "$spm_root"
1225fi
1226
Fathi Boudra422bf772019-12-02 11:10:16 +02001227if [ "$run_config" ]; then
1228 # Get candidates for run config
1229 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1230 "$run_config")"
1231 if [ -z "$run_config_candiates" ]; then
1232 die "No run config candidates!"
1233 else
1234 echo
1235 echo "Chosen fragments:"
1236 echo
1237 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1238 echo
1239 fi
1240fi
1241
1242call_hook "test_setup"
1243echo
1244
1245if upon "$local_ci"; then
1246 # For local runs, since each config is tried in sequence, it's
1247 # advantageous to run jobs in parallel
1248 if [ "$make_j" ]; then
1249 make_j_opts="-j $make_j"
1250 else
1251 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1252 if [ "$n_cores" ]; then
1253 make_j_opts="-j $n_cores"
1254 fi
1255 fi
1256fi
1257
1258modes="${bin_mode:-debug release}"
1259for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001260 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001261 # Build with a temporary archive
1262 build_archive="$archive/$mode"
1263 mkdir "$build_archive"
1264
1265 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001266 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001267 DEBUG=1
1268 else
Zelalem219df412020-05-17 19:21:20 -05001269 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001270 DEBUG=0
1271 fi
1272
1273 # Perform builds in a subshell so as not to pollute the current and
1274 # subsequent builds' environment
1275
Zelalem219df412020-05-17 19:21:20 -05001276 if config_valid "$cc_config"; then
1277 # Build code coverage plugin
1278 build_cc
1279 fi
1280
Fathi Boudra422bf772019-12-02 11:10:16 +02001281 # SCP build
1282 if config_valid "$scp_config"; then
1283 (
1284 echo "##########"
1285
1286 # Source platform-specific utilities
1287 plat="$(get_scp_opt PRODUCT)"
1288 plat_utils="$ci_root/${plat}_utils.sh"
1289 if [ -f "$plat_utils" ]; then
1290 source "$plat_utils"
1291 fi
1292
1293 archive="$build_archive"
1294 scp_build_root="$scp_root/build"
1295
1296 echo "Building SCP Firmware ($mode) ..." |& log_separator
1297
1298 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001299 to="$archive" collect_scp_artefacts
1300
1301 echo "##########"
1302 echo
1303 )
1304 fi
1305
Zelalem219df412020-05-17 19:21:20 -05001306 # SCP-tools build
1307 if config_valid "$scp_tools_config"; then
1308 (
1309 echo "##########"
1310
1311 archive="$build_archive"
1312 scp_tools_build_root="$scp_tools_root/build"
1313
1314 clone_scp_tools
1315
1316 echo "##########"
1317 echo
1318
1319 echo "##########"
1320 clone_tf_for_scp_tools
1321 echo "##########"
1322 echo
1323 )
1324 fi
1325
Fathi Boudra422bf772019-12-02 11:10:16 +02001326 # TFTF build
1327 if config_valid "$tftf_config"; then
1328 (
1329 echo "##########"
1330
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001331 plat_utils="$(get_tf_opt PLAT_UTILS)"
1332 if [ -z ${plat_utils} ]; then
1333 # Source platform-specific utilities.
1334 plat="$(get_tftf_opt PLAT)"
1335 plat_utils="$ci_root/${plat}_utils.sh"
1336 else
1337 # Source platform-specific utilities by
1338 # using plat_utils name.
1339 plat_utils="$ci_root/${plat_utils}.sh"
1340 fi
1341
Fathi Boudra422bf772019-12-02 11:10:16 +02001342 if [ -f "$plat_utils" ]; then
1343 source "$plat_utils"
1344 fi
1345
1346 archive="$build_archive"
1347 tftf_build_root="$tftf_root/build"
1348
1349 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1350
1351 # Call pre-build hook
1352 call_hook pre_tftf_build
1353
1354 build_tftf
1355
1356 from="$tftf_build_root" to="$archive" collect_build_artefacts
1357
1358 # Clear any local changes made by applied patches
1359 undo_tftf_patches
1360
1361 echo "##########"
1362 echo
1363 )
1364 fi
1365
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001366 # SPM build
1367 if config_valid "$spm_config"; then
1368 (
1369 echo "##########"
1370
1371 # Get platform name from spm_config file
1372 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1373 plat_utils="$ci_root/${plat}_utils.sh"
1374 if [ -f "$plat_utils" ]; then
1375 source "$plat_utils"
1376 fi
1377
Manish Pandey1e7be852020-11-09 16:04:48 +00001378 # SPM build generates two sets of binaries, one for normal and other
1379 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001380 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001381 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1382 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001383
1384 echo "Building SPM ($mode) ..." |& log_separator
1385
1386 # NOTE: mode has no effect on SPM build (for now), hence debug
1387 # mode is built but subsequent build using release mode just
1388 # goes through with "nothing to do".
1389 build_spm
1390
1391 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001392 cksum $spm_build_root/hafnium.bin
1393
1394 # Some platforms only have secure configuration enabled. Hence,
1395 # non secure hanfnium binary might not be built.
1396 if [ -f $hafnium_build_root/hafnium.bin ]; then
1397 cksum $hafnium_build_root/hafnium.bin
1398 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001399
Manish Pandey1e7be852020-11-09 16:04:48 +00001400 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001401
1402 echo "##########"
1403 echo
1404 )
1405 fi
1406
Fathi Boudra422bf772019-12-02 11:10:16 +02001407 # TF build
1408 if config_valid "$tf_config"; then
1409 (
1410 echo "##########"
1411
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001412 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001413 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1414
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001415 if [ -z ${plat_utils} ]; then
1416 # Source platform-specific utilities.
1417 plat="$(get_tf_opt PLAT)"
1418 plat_utils="$ci_root/${plat}_utils.sh"
1419 else
1420 # Source platform-specific utilities by
1421 # using plat_utils name.
1422 plat_utils="$ci_root/${plat_utils}.sh"
1423 fi
1424
Fathi Boudra422bf772019-12-02 11:10:16 +02001425 if [ -f "$plat_utils" ]; then
1426 source "$plat_utils"
1427 fi
1428
Chris Kayd0837902021-11-17 10:17:52 +00001429 source "$ci_root/script/install_python_deps_tf.sh"
1430
Fathi Boudra422bf772019-12-02 11:10:16 +02001431 archive="$build_archive"
1432 tf_build_root="$tf_root/build"
1433
1434 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1435
1436 # Call pre-build hook
1437 call_hook pre_tf_build
1438
1439 build_tf
1440
1441 # Call post-build hook
1442 call_hook post_tf_build
1443
1444 # Pre-archive hook
1445 call_hook pre_tf_archive
1446
1447 from="$tf_build_root" to="$archive" collect_build_artefacts
1448
1449 # Post-archive hook
1450 call_hook post_tf_archive
1451
1452 call_hook fetch_tf_resource
1453 call_hook post_fetch_tf_resource
1454
1455 # Clear any local changes made by applied patches
1456 undo_tf_patches
1457
1458 echo "##########"
1459 )
1460 fi
1461
1462 echo
1463 echo
1464done
1465
1466call_hook pre_package
1467
1468call_hook post_package
1469
1470if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001471 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001472fi
1473
1474echo
1475echo "Done"