blob: c79d29b54839965615d1b28574a1e21571cb5fac [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Yann Gautier7e9d6cf2023-03-08 14:24:38 +01003# Copyright (c) 2019-2023 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
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +0000115 if [ "$run_config_candidates" ]; then
116 for config_fragment in $run_config_candidates; do
Fathi Boudra422bf772019-12-02 11:10:16 +0200117 (
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
Yann Gautier7e9d6cf2023-03-08 14:24:38 +0100166 if ! find "$from" \( -name "*.bin" -o -name '*.elf' -o -name '*.dtb' -o -name '*.axf' -o -name '*.stm32' \) -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
Anurag Koulbaedf932021-12-09 12:49:56 +0000182 */firmware-scp_ramfw/bin/*|*/firmware-scp_ramfw_fvp/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_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200186 cp $file $to/scp_rom.$ext
187 ;;
Anurag Koulbaedf932021-12-09 12:49:56 +0000188 */firmware-mcp_ramfw/bin/*|*/firmware-mcp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200189 cp $file $to/mcp_ram.$ext
190 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000191 */firmware-mcp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200192 cp $file $to/mcp_rom.$ext
193 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000194 */firmware-scp_romfw_bypass/bin/*)
Zelalem219df412020-05-17 19:21:20 -0500195 cp $file $to/scp_rom_bypass.$ext
196 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200197 *)
198 echo "Unknown SCP binary: $file" >&2
199 ;;
200 esac
201 done
202 ' bash '{}' +
203}
204
Manish Pandey1e7be852020-11-09 16:04:48 +0000205# Collect SPM/hafnium artefacts with "secure_" appended to the files
206# generated for SPM(secure hafnium).
207collect_spm_artefacts() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500208 if [ -d "${non_secure_from:?}" ]; then
209 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000210 fi
211
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500212 if [ -d "${secure_from:?}" ]; then
213 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
214 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000215}
216
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100217# Map the UART ID used for expect with the UART descriptor and port
218# used by the FPGA automation tools.
219map_uart() {
220 local port="${port:?}"
221 local descriptor="${descriptor:?}"
222 local baudrate="${baudrate:?}"
223 local run_root="${archive:?}/run"
224
225 local uart_dir="$run_root/uart${uart:?}"
226 mkdir -p "$uart_dir"
227
228 echo "$port" > "$uart_dir/port"
229 echo "$descriptor" > "$uart_dir/descriptor"
230 echo "$baudrate" > "$uart_dir/baudrate"
231
232 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
233}
234
Fathi Boudra422bf772019-12-02 11:10:16 +0200235# Arrange environment varibles to be set when expect scripts are launched
236set_expect_variable() {
237 local var="${1:?}"
238 local val="${2?}"
239
240 local run_root="${archive:?}/run"
241 local uart_dir="$run_root/uart${uart:?}"
242 mkdir -p "$uart_dir"
243
244 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
245 echo "UART$uart: env has $@"
246}
247
248# Place the binary package a pointer to expect script, and its parameters
249track_expect() {
250 local file="${file:?}"
251 local timeout="${timeout-600}"
252 local run_root="${archive:?}/run"
253
254 local uart_dir="$run_root/uart${uart:?}"
255 mkdir -p "$uart_dir"
256
257 echo "$file" > "$uart_dir/expect"
258 echo "$timeout" > "$uart_dir/timeout"
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700259 if [ -n "$lava_timeout" ]; then
260 set_run_env "lava_timeout" "$lava_timeout"
261 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200262
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700263 echo "UART$uart to be tracked with $file; timeout ${timeout}s; lava_timeout ${lava_timeout:-N/A}s"
Fathi Boudra422bf772019-12-02 11:10:16 +0200264
Chris Kayfab6edc2022-11-17 19:18:32 +0000265 if [ ! -z "${port}" ]; then
266 echo "${port}" > "$uart_dir/port"
267 fi
268
Fathi Boudra422bf772019-12-02 11:10:16 +0200269 # The run script assumes UART0 to be primary. If we're asked to set any
270 # other UART to be primary, set a run environment variable to signal
271 # that to the run script
272 if upon "$set_primary"; then
273 echo "Primary UART set to UART$uart."
274 set_run_env "primary_uart" "$uart"
275 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600276
277 # UART used by payload(such as tftf, Linux) may not be the same as the
278 # primary UART. Set a run environment variable to track the payload
279 # UART which is tracked to check if the test has finished sucessfully.
280 if upon "$set_payload_uart"; then
281 echo "Payload uses UART$uart."
282 set_run_env "payload_uart" "$uart"
283 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200284}
285
286# Extract a FIP in $1 using fiptool
287extract_fip() {
288 local fip="$1"
289
290 if is_url "$1"; then
291 url="$1" fetch_file
292 fip="$(basename "$1")"
293 fi
294
295 "$fiptool" unpack "$fip"
296 echo "Extracted FIP: $fip"
297}
298
299# Report build failure by printing a the tail end of build log. Archive the
300# build log for later inspection
301fail_build() {
302 local log_path
303
304 if upon "$jenkins_run"; then
305 log_path="$BUILD_URL/artifact/artefacts/build.log"
306 else
307 log_path="$build_log"
308 fi
309
310 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600311 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200312 echo "[...]"
313 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600314 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200315 echo
316 echo "See $log_path for full output"
317 echo
318 cp -t "$archive" "$build_log"
319 exit 1;
320}
321
322# Build a FIP with supplied arguments
323build_fip() {
324 (
325 echo "Building FIP with arguments: $@"
326 local tf_env="$workspace/tf.env"
327
328 if [ -f "$tf_env" ]; then
329 set -a
330 source "$tf_env"
331 set +a
332 fi
333
334 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
335 ${fip_targets:-fip} &>>"$build_log" || fail_build
336 )
337}
338
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200339# Build any extra rule from TF-A makefile with supplied arguments.
340#
341# This is useful in case you need to build something else than firmware binaries
342# or the FIP.
343build_tf_extra() {
344 (
345 tf_extra_rules=${tf_extra_rules:?}
346 echo "Building extra TF rule(s): $tf_extra_rules"
347 echo " Arguments: $@"
348
349 local tf_env="$workspace/tf.env"
350
351 if [ -f "$tf_env" ]; then
352 set -a
353 source "$tf_env"
354 set +a
355 fi
356
357 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
358 ${tf_extra_rules} &>>"$build_log" || fail_build
359 )
360}
361
Fathi Boudra422bf772019-12-02 11:10:16 +0200362fip_update() {
363 # Before the update process, check if the given image is supported by
364 # the fiptool. It's assumed that both fiptool and cert_create move in
365 # tandem, and therfore, if one has support, the other has it too.
366 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
367 return 1
368 fi
369
370 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
371 echo "Updating FIP image: $bin_name"
372 # Update HW config. Without TBBR, it's only a matter of using
373 # the update sub-command of fiptool
374 "$fiptool" update "--$bin_name" "${src:-}" \
375 "$archive/fip.bin"
376 else
377 echo "Updating FIP image (TBBR): $bin_name"
378 # With TBBR, we need to unpack, re-create certificates, and then
379 # recreate the FIP.
380 local fip_dir="$(mktempdir)"
381 local bin common_args stem
382 local rot_key="$(get_tf_opt ROT_KEY)"
383
384 rot_key="${rot_key:?}"
385 if ! is_abs "$rot_key"; then
386 rot_key="$tf_root/$rot_key"
387 fi
388
389 # Arguments only for cert_create
390 local cert_args="-n"
391 cert_args+=" --tfw-nvctr ${nvctr:-31}"
392 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
393 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
394 cert_args+=" --rot-key $rot_key"
395
396 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500397 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200398 "hw-config"
399 "tb-fw-config"
400 "nt-fw-config"
401 "soc-fw-config"
402 "tos-fw-config"
403 )
404
405 # Binaries without key certificates
406 declare -A has_no_key_cert
407 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
408 has_no_key_cert["$bin"]="1"
409 done
410
411 # Binaries without certificates
412 declare -A has_no_cert
413 for bin in "hw-config" "${dyn_config_opts[@]}"; do
414 has_no_cert["$bin"]="1"
415 done
416
417 pushd "$fip_dir"
418
419 # Unpack FIP
420 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
421
422 # Remove all existing certificates
423 rm -f *-cert.bin
424
425 # Copy the binary to be updated
426 cp -f "$src" "${bin_name}.bin"
427
428 # FIP unpack dumps binaries with the same name as the option
429 # used to pack it; likewise for certificates. Reverse-engineer
430 # the command line from the binary output.
431 common_args="--trusted-key-cert trusted_key.crt"
432 for bin in *.bin; do
433 stem="${bin%%.bin}"
434 common_args+=" --$stem $bin"
435 if not_upon "${has_no_cert[$stem]}"; then
436 common_args+=" --$stem-cert $stem.crt"
437 fi
438 if not_upon "${has_no_key_cert[$stem]}"; then
439 common_args+=" --$stem-key-cert $stem-key.crt"
440 fi
441 done
442
443 # Create certificates
444 "$cert_create" $cert_args $common_args &>>"$build_log"
445
446 # Recreate and archive FIP
447 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
448 archive_file "fip.bin"
449
450 popd
451 fi
452}
453
454# Update hw-config in FIP, and remove the original DTB afterwards.
455update_fip_hw_config() {
456 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600457 # in configs:
458 # 1. Where BL2 isn't present
459 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200460 case "1" in
461 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600462 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200463 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000464 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200465 return 0;;
466 esac
467
468 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
469 # Remove the DTB so that model won't load it
470 rm -f "$archive/dtb.bin"
471 fi
472}
473
474get_scp_opt() {
475 (
476 name="${1:?}"
477 if config_valid "$scp_config_file"; then
478 source "$scp_config_file"
479 echo "${!name}"
480 fi
481 )
482}
483
484get_tftf_opt() {
485 (
486 name="${1:?}"
487 if config_valid "$tftf_config_file"; then
488 source "$tftf_config_file"
489 echo "${!name}"
490 fi
491 )
492}
493
494get_tf_opt() {
495 (
496 name="${1:?}"
497 if config_valid "$tf_config_file"; then
498 source "$tf_config_file"
499 echo "${!name}"
500 fi
501 )
502}
503
504build_tf() {
505 (
506 env_file="$workspace/tf.env"
507 config_file="${tf_build_config:-$tf_config_file}"
508
509 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100510 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200511
512 source "$config_file"
513
514 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000515 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100516 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
517 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200518 mbedtls_dir="$workspace/mbedtls"
519 if [ ! -d "$mbedtls_dir" ]; then
520 mbedtls_ar="$workspace/mbedtls.tar.gz"
521
522 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
523 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500524 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200525 fi
526
527 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
528 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500529 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
530 not_upon "${TF_M_TESTS_PATH}"; then
531 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
532 fi
533 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
534 not_upon "${TF_M_EXTRAS_PATH}"; then
535 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
536 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200537 if [ -f "$env_file" ]; then
538 set -a
539 source "$env_file"
540 set +a
541 fi
542
Harrison Mutai013f6332022-02-16 16:06:33 +0000543 if is_arm_jenkins_env || upon "$local_ci"; then
544 path_list=(
545 "$llvm_dir/bin"
546 )
547 extend_path "PATH" "path_list"
548 fi
549
Fathi Boudra422bf772019-12-02 11:10:16 +0200550 cd "$tf_root"
551
552 # Always distclean when running on Jenkins. Skip distclean when running
553 # locally and explicitly requested.
554 if upon "$jenkins_run" || not_upon "$dont_clean"; then
555 make distclean &>>"$build_log" || fail_build
556 fi
557
558 # Log build command line. It is left unfolded on purpose to assist
559 # copying to clipboard.
560 cat <<EOF | log_separator >/dev/null
561
562Build command line:
563 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
564
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300565CC version:
566$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200567EOF
568
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000569 if not_upon "$local_ci"; then
570 connect_debugger=0
571 fi
572
Fathi Boudra422bf772019-12-02 11:10:16 +0200573 # Build TF. Since build output is being directed to the build log, have
574 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000575 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000576 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200577 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100578
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100579 if [ "$build_targets" != "doc" ]; then
580 poetry run memory -sr "$tf_build_path" 2>&1 | tee -a "$build_log"
581 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200582 )
583}
584
585build_tftf() {
586 (
587 config_file="${tftf_build_config:-$tftf_config_file}"
588
589 # Build tftf target by default
590 build_targets="${tftf_build_targets:-all}"
591
592 source "$config_file"
593
594 cd "$tftf_root"
595
596 # Always distclean when running on Jenkins. Skip distclean when running
597 # locally and explicitly requested.
598 if upon "$jenkins_run" || not_upon "$dont_clean"; then
599 make distclean &>>"$build_log" || fail_build
600 fi
601
602 # TFTF build system cannot reliably deal with -j option, so we avoid
603 # using that.
604
605 # Log build command line
606 cat <<EOF | log_separator >/dev/null
607
608Build command line:
609 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
610
611EOF
612
613 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
614 $build_targets &>>"$build_log" || fail_build
615 )
616}
617
618build_scp() {
619 (
620 config_file="${scp_build_config:-$scp_config_file}"
621
622 source "$config_file"
623
624 cd "$scp_root"
625
626 # Always distclean when running on Jenkins. Skip distclean when running
627 # locally and explicitly requested.
628 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000629 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200630 fi
631
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000632 python3 -m venv .venv
633 . .venv/bin/activate
634
635 # Install extra tools used by CMake build system
636 pip install -r requirements.txt --timeout 30 --retries 15
637
Fathi Boudra422bf772019-12-02 11:10:16 +0200638 # Log build command line. It is left unfolded on purpose to assist
639 # copying to clipboard.
640 cat <<EOF | log_separator >/dev/null
641
642SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000643 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
644 TOOLCHAIN=GNU \
645 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000646 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000647 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200648
649EOF
650
651 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000652 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
653 TOOLCHAIN=GNU \
654 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000655 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000656 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200657 || fail_build
658 )
659}
660
Zelalem219df412020-05-17 19:21:20 -0500661clone_scp_tools() {
662
663 if [ ! -d "$scp_tools_root" ]; then
664 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
665
666 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
667 where="$scp_tools_root" \
668 refspec="${scp_tools_commit}"
669 clone_repo &>>"$build_log"
670 else
671 echo "Already cloned SCP-tools ..." |& log_separator
672 fi
673
674 show_head "$scp_tools_root"
675
676 cd "$scp_tools_root"
677
678 echo "Updating submodules"
679
680 git submodule init
681
682 git submodule update
683
Nicola Mazzucato9b171422023-08-29 15:50:49 +0100684 lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'" | tr -d ",")
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000685
Zelalem219df412020-05-17 19:21:20 -0500686 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000687 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500688
689 git show --quiet --no-color | sed 's/^/ > /g'
690}
691
692clone_tf_for_scp_tools() {
693 scp_tools_arm_tf="$scp_tools_root/arm-tf"
694
695 if [ ! -d "$scp_tools_arm_tf" ]; then
696 echo "Cloning TF-4-SCP-tools ..." |& log_separator
697
698 clone_url="$tf_for_scp_tools_src_repo_url"
699 where="$scp_tools_arm_tf"
700
701 git clone "$clone_url" "$where"
702
703 cd "$scp_tools_arm_tf"
704
Joel Goddard3ad03062021-03-16 16:47:42 +0000705 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500706
707 git show --quiet --no-color | sed 's/^/ > /g'
708
709 else
710 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
711 fi
712}
713
714build_scmi_lib_scp_tools() {
715 (
716 cd "$scp_tools_root"
717
718 cd "scmi"
719
720 scp_tools_arm_tf="$scp_tools_root/arm-tf"
721
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600722 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500723
724 std_libs="-I$scp_tools_arm_tf/include/common"
725 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
726 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
727 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
728 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
729 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
730 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
731 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
732 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
733 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
734 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
735 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
736 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
737 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
738
739 cflags="-Og -g"
740 cflags="$cflags -mgeneral-regs-only"
741 cflags="$cflags -mstrict-align"
742 cflags="$cflags -nostdinc"
743 cflags="$cflags -fno-inline"
744 cflags="$cflags -ffreestanding"
745 cflags="$cflags -ffunction-sections"
746 cflags="$cflags -fdata-sections"
747 cflags="$cflags -DAARCH64"
748 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000749 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500750
751 cflags="$cflags $std_libs"
752
Joel Goddard3ad03062021-03-16 16:47:42 +0000753 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500754
755 echo "Building SCMI library (SCP-tools) ..."
756
757 make "CROSS_COMPILE=$cross_compile" \
758 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000759 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500760 "PROTOCOLS=$protocols" \
761 "clean" \
762 "all"
763 )
764}
765
766build_tf_for_scp_tools() {
767
768 cd "$scp_tools_root/arm-tf"
769
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600770 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500771
772 if [ "$1" = "release" ]; then
773 echo "Build TF-4-SCP-Tools rls..."
774 else
775 echo "Build TF-4-SCP-Tools dbg..."
776
777 make realclean
778
779 make "BM_TEST=scmi" \
780 "ARM_BOARD_OPTIMISE_MEM=1" \
781 "BM_CSS=juno" \
782 "CSS_USE_SCMI_SDS_DRIVER=1" \
783 "PLAT=juno" \
784 "DEBUG=1" \
785 "PLATFORM=juno" \
786 "CROSS_COMPILE=$cross_compile" \
787 "BM_WORKSPACE=$scp_tools_root/baremetal"
788
789 archive_file "build/juno/debug/bl1.bin"
790
791 archive_file "build/juno/debug/bl2.bin"
792
793 archive_file "build/juno/debug/bl31.bin"
794 fi
795}
796
797build_fip_for_scp_tools() {
798
799 cd "$scp_tools_root/arm-tf"
800
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600801 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500802
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000803 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500804 make fiptool
805 echo "Make FIP 4 SCP-Tools rls..."
806
807 else
808 make fiptool
809 echo "Make FIP 4 SCP-Tools dbg..."
810
811 make "PLAT=juno" \
812 "all" \
813 "fip" \
814 "DEBUG=1" \
815 "CROSS_COMPILE=$cross_compile" \
816 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
817 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000818 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500819
820 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
821 fi
822}
823
824build_cc() {
825# Building code coverage plugin
826 ARM_DIR=/arm
827 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
828 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
829 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
830 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
831 exit -1
832 fi # Error if arm warehouse not found
833 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
834
835 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
836}
837
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100838build_spm() {
839 (
840 env_file="$workspace/spm.env"
841 config_file="${spm_build_config:-$spm_config_file}"
842
843 source "$config_file"
844
845 if [ -f "$env_file" ]; then
846 set -a
847 source "$env_file"
848 set +a
849 fi
850
851 cd "$spm_root"
852
853 # Always clean when running on Jenkins. Skip clean when running
854 # locally and explicitly requested.
855 if upon "$jenkins_run" || not_upon "$dont_clean"; then
856 # make clean fails on a fresh repo where the project has not
857 # yet been built. Hence only clean if out/reference directory
858 # already exists.
859 if [ -d "out/reference" ]; then
860 make clean &>>"$build_log" || fail_build
861 fi
862 fi
863
864 # Log build command line. It is left unfolded on purpose to assist
865 # copying to clipboard.
866 cat <<EOF | log_separator >/dev/null
867
868Build command line:
869 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
870
871EOF
872
873 # Build SPM. Since build output is being directed to the build log, have
874 # descriptor 3 point to the current terminal for build wrappers to vent.
875 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
876 || fail_build
877 )
878}
Zelalem219df412020-05-17 19:21:20 -0500879
Fathi Boudra422bf772019-12-02 11:10:16 +0200880# Set metadata for the whole package so that it can be used by both Jenkins and
881# shell
882set_package_var() {
883 env_file="$artefacts/env" emit_env "$@"
884}
885
886set_tf_build_targets() {
887 echo "Set build target to '${targets:?}'"
888 set_hook_var "tf_build_targets" "$targets"
889}
890
891set_tftf_build_targets() {
892 echo "Set build target to '${targets:?}'"
893 set_hook_var "tftf_build_targets" "$targets"
894}
895
896set_scp_build_targets() {
897 echo "Set build target to '${targets:?}'"
898 set_hook_var "scp_build_targets" "$targets"
899}
900
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100901set_spm_build_targets() {
902 echo "Set build target to '${targets:?}'"
903 set_hook_var "spm_build_targets" "$targets"
904}
905
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000906set_spm_out_dir() {
907 echo "Set SPMC binary build to '${out_dir:?}'"
908 set_hook_var "spm_secure_out_dir" "$out_dir"
909}
Fathi Boudra422bf772019-12-02 11:10:16 +0200910# Look under $archive directory for known files such as blX images, kernel, DTB,
911# initrd etc. For each known file foo, if foo.bin exists, then set variable
912# foo_bin to the path of the file. Make the path relative to the workspace so as
913# to remove any @ characters, which Jenkins inserts for parallel runs. If the
914# file doesn't exist, unset its path.
915set_default_bin_paths() {
916 local image image_name image_path path
917 local archive="${archive:?}"
918 local set_vars
919 local var
920
921 pushd "$archive"
922
923 for file in *.bin; do
924 # Get a shell variable from the file's stem
925 var_name="${file%%.*}_bin"
926 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
927
928 # Skip setting the variable if it's already
929 if [ "${!var_name}" ]; then
930 echo "Note: not setting $var_name; already set to ${!var_name}"
931 continue
932 else
933 set_vars+="$var_name "
934 fi
935
936 eval "$var_name=$file"
937 done
938
939 echo "Binary paths set for: "
940 {
941 for var in $set_vars; do
942 echo -n "\$$var "
943 done
944 } | fmt -80 | sed 's/^/ /'
945 echo
946
947 popd
948}
949
950gen_model_params() {
951 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000952 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200953
954 set_default_bin_paths
955 echo "Generating model parameter for $model..."
956 source "$ci_root/model/${model:?}.sh"
957 archive_file "$model_param_file"
958}
959
960set_model_path() {
961 set_run_env "model_path" "${1:?}"
962}
963
Zelalem1af7a7b2020-08-04 17:34:32 -0500964set_model_env() {
965 local var="${1:?}"
966 local val="${2?}"
967 local run_root="${archive:?}/run"
968
969 mkdir -p "$run_root"
970 echo "export $var=$val" >> "$run_root/model_env"
971}
Fathi Boudra422bf772019-12-02 11:10:16 +0200972set_run_env() {
973 local var="${1:?}"
974 local val="${2?}"
975 local run_root="${archive:?}/run"
976
977 mkdir -p "$run_root"
978 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
979}
980
981show_head() {
982 # Display HEAD descripton
983 pushd "$1"
984 git show --quiet --no-color | sed 's/^/ > /g'
985 echo
986 popd
987}
988
989# Choose debug binaries to run; by default, release binaries are chosen to run
990use_debug_bins() {
991 local run_root="${archive:?}/run"
992
993 echo "Choosing debug binaries for execution"
994 set_package_var "BIN_MODE" "debug"
995}
996
997assert_can_git_clone() {
998 local name="${1:?}"
999 local dir="${!name}"
1000
1001 # If it doesn't exist, it can be cloned into
1002 if [ ! -e "$dir" ]; then
1003 return 0
1004 fi
1005
1006 # If it's a directory, it must be a Git clone already
1007 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
1008 # No need to clone again
1009 echo "Using existing git clone for $name: $dir"
1010 return 1
1011 fi
1012
1013 die "Path $dir exists but is not a git clone"
1014}
1015
1016clone_repo() {
1017 if ! is_url "${clone_url?}"; then
1018 # For --depth to take effect on local paths, it needs to use the
1019 # file:// scheme.
1020 clone_url="file://$clone_url"
1021 fi
1022
1023 git clone -q --depth 1 "$clone_url" "${where?}"
1024 if [ "$refspec" ]; then
1025 pushd "$where"
1026 git fetch -q --depth 1 origin "$refspec"
1027 git checkout -q FETCH_HEAD
1028 popd
1029 fi
1030}
1031
1032build_unstable() {
1033 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1034}
1035
1036undo_patch_record() {
1037 if [ ! -f "${patch_record:?}" ]; then
1038 return
1039 fi
1040
1041 # Undo patches in reverse
1042 echo
1043 for patch_name in $(tac "$patch_record"); do
1044 echo "Undoing $patch_name..."
1045 if ! git apply -R "$ci_root/patch/$patch_name"; then
1046 if upon "$local_ci"; then
1047 echo
1048 echo "Your local directory may have been dirtied."
1049 echo
1050 fi
1051 fail_build
1052 fi
1053 done
1054
1055 rm -f "$patch_record"
1056}
1057
1058undo_local_patches() {
1059 pushd "$tf_root"
1060 patch_record="$tf_patch_record" undo_patch_record
1061 popd
1062
1063 if [ -d "$tftf_root" ]; then
1064 pushd "$tftf_root"
1065 patch_record="$tftf_patch_record" undo_patch_record
1066 popd
1067 fi
1068}
1069
1070undo_tftf_patches() {
1071 pushd "$tftf_root"
1072 patch_record="$tftf_patch_record" undo_patch_record
1073 popd
1074}
1075
1076undo_tf_patches() {
1077 pushd "$tf_root"
1078 patch_record="$tf_patch_record" undo_patch_record
1079 popd
1080}
1081
1082apply_patch() {
1083 # If skip_patches is set, the developer has applied required patches
1084 # manually. They probably want to keep them applied for debugging
1085 # purposes too. This means we don't have to apply/revert them as part of
1086 # build process.
1087 if upon "$skip_patches"; then
1088 echo "Skipped applying ${1:?}..."
1089 return 0
1090 else
1091 echo "Applying ${1:?}..."
1092 fi
1093
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +02001094 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001095 echo "Skipping already applied ${1:?}"
1096 return 0
1097 fi
1098
Fathi Boudra422bf772019-12-02 11:10:16 +02001099 if git apply < "$ci_root/patch/$1"; then
1100 echo "$1" >> "${patch_record:?}"
1101 else
1102 if upon "$local_ci"; then
1103 undo_local_patches
1104 fi
1105 fail_build
1106 fi
1107}
1108
1109apply_tftf_patch() {
1110 pushd "$tftf_root"
1111 patch_record="$tftf_patch_record" apply_patch "$1"
1112 popd
1113}
1114
1115apply_tf_patch() {
1116 pushd "$tf_root"
1117 patch_record="$tf_patch_record" apply_patch "$1"
1118 popd
1119}
1120
1121# Clear workspace for a local run
1122if not_upon "$jenkins_run"; then
1123 rm -rf "$workspace"
1124
1125 # Clear residue from previous runs
1126 rm -rf "$archive"
1127fi
1128
1129mkdir -p "$workspace"
1130mkdir -p "$archive"
1131set_package_var "TEST_CONFIG" "$test_config"
1132
1133{
1134echo
1135echo "CONFIGURATION: $test_group/$test_config"
1136echo
1137} |& log_separator
1138
1139tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1140tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1141scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001142scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001143spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001144
1145test_config_file="$ci_root/group/$test_group/$test_config"
1146
1147tf_config_file="$ci_root/tf_config/$tf_config"
1148tftf_config_file="$ci_root/tftf_config/$tftf_config"
1149scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001150scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001151spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001152
1153# File that keeps track of applied patches
1154tf_patch_record="$workspace/tf_patches"
1155tftf_patch_record="$workspace/tftf_patches"
1156
1157pushd "$workspace"
1158
1159if ! config_valid "$tf_config"; then
1160 tf_config=
1161else
1162 echo "Trusted Firmware config:"
1163 echo
1164 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1165 echo
1166fi
1167
1168if ! config_valid "$tftf_config"; then
1169 tftf_config=
1170else
1171 echo "Trusted Firmware TF config:"
1172 echo
1173 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1174 echo
1175fi
1176
1177if ! config_valid "$scp_config"; then
1178 scp_config=
1179else
1180 echo "SCP firmware config:"
1181 echo
1182 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1183 echo
1184fi
1185
Zelalem219df412020-05-17 19:21:20 -05001186if ! config_valid "$scp_tools_config"; then
1187 scp_tools_config=
1188else
1189 echo "SCP Tools config:"
1190 echo
1191 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001192fi
1193
1194if ! config_valid "$spm_config"; then
1195 spm_config=
1196else
1197 echo "SPM config:"
1198 echo
1199 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001200 echo
1201fi
1202
Fathi Boudra422bf772019-12-02 11:10:16 +02001203if ! config_valid "$run_config"; then
1204 run_config=
1205fi
1206
1207if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1208 # If the Trusted Firmware repository has already been checked out, use
1209 # that location. Otherwise, clone one ourselves.
1210 echo "Cloning Trusted Firmware..."
1211 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1212 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1213 show_head "$tf_root"
1214fi
1215
1216if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1217 # If the Trusted Firmware TF repository has already been checked out,
1218 # use that location. Otherwise, clone one ourselves.
1219 echo "Cloning Trusted Firmware TF..."
1220 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1221 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1222 show_head "$tftf_root"
1223fi
1224
1225if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1226 # If the SCP firmware repository has already been checked out,
1227 # use that location. Otherwise, clone one ourselves.
1228 echo "Cloning SCP Firmware..."
1229 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1230 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1231
1232 pushd "$scp_root"
1233
1234 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001235 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001236 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1237 fi
1238
1239 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1240 # then to project filer if accessible.
1241 if [ -z "$cmsis_reference" ]; then
1242 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1243 if [ -d "$cmsis_ref_repo" ]; then
1244 cmsis_reference="--reference $cmsis_ref_repo"
1245 fi
1246 fi
1247
1248 git submodule -q update $cmsis_reference --init
1249
1250 popd
1251
1252 show_head "$scp_root"
1253fi
1254
Zelalem219df412020-05-17 19:21:20 -05001255if [ -n "$cc_config" ] ; then
1256 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1257 # Copy code coverage repository
1258 echo "Cloning Code Coverage..."
1259 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1260 show_head "$cc_root"
1261 fi
1262fi
1263
Daniel Boulby25385ab2023-12-14 14:36:25 +00001264if [ "$spm_config" ] ; then
1265 if assert_can_git_clone "spm_root"; then
1266 # If the SPM repository has already been checked out, use
1267 # that location. Otherwise, clone one ourselves.
1268 echo "Cloning SPM..."
1269 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1270 where="$spm_root" refspec="$SPM_REFSPEC" \
1271 clone_repo &>>"$build_log"
1272 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001273
1274 # Query git submodules
1275 pushd "$spm_root"
Daniel Boulby25385ab2023-12-14 14:36:25 +00001276 # Check if submodules need initialising
1277 if git submodule status | grep '^-'; then
1278 git submodule update --init
1279 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001280 popd
1281
1282 show_head "$spm_root"
1283fi
1284
Fathi Boudra422bf772019-12-02 11:10:16 +02001285if [ "$run_config" ]; then
1286 # Get candidates for run config
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001287 run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \
Fathi Boudra422bf772019-12-02 11:10:16 +02001288 "$run_config")"
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001289 if [ -z "$run_config_candidates" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001290 die "No run config candidates!"
1291 else
1292 echo
1293 echo "Chosen fragments:"
1294 echo
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001295 echo "$run_config_candidates" | sed 's/^\|\n/\t/g'
Fathi Boudra422bf772019-12-02 11:10:16 +02001296 echo
1297 fi
1298fi
1299
1300call_hook "test_setup"
1301echo
1302
1303if upon "$local_ci"; then
1304 # For local runs, since each config is tried in sequence, it's
1305 # advantageous to run jobs in parallel
1306 if [ "$make_j" ]; then
1307 make_j_opts="-j $make_j"
1308 else
1309 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1310 if [ "$n_cores" ]; then
1311 make_j_opts="-j $n_cores"
1312 fi
1313 fi
1314fi
1315
Harrison Mutai07043e92023-07-06 09:41:12 +01001316# Install python build dependencies
1317if is_arm_jenkins_env; then
1318 source "$ci_root/script/install_python_deps.sh"
1319fi
1320
Fathi Boudra422bf772019-12-02 11:10:16 +02001321modes="${bin_mode:-debug release}"
1322for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001323 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001324 # Build with a temporary archive
1325 build_archive="$archive/$mode"
1326 mkdir "$build_archive"
1327
1328 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001329 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001330 DEBUG=1
1331 else
Zelalem219df412020-05-17 19:21:20 -05001332 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001333 DEBUG=0
1334 fi
1335
1336 # Perform builds in a subshell so as not to pollute the current and
1337 # subsequent builds' environment
1338
Zelalem219df412020-05-17 19:21:20 -05001339 if config_valid "$cc_config"; then
1340 # Build code coverage plugin
1341 build_cc
1342 fi
1343
Fathi Boudra422bf772019-12-02 11:10:16 +02001344 # SCP build
1345 if config_valid "$scp_config"; then
1346 (
1347 echo "##########"
1348
1349 # Source platform-specific utilities
1350 plat="$(get_scp_opt PRODUCT)"
1351 plat_utils="$ci_root/${plat}_utils.sh"
1352 if [ -f "$plat_utils" ]; then
1353 source "$plat_utils"
1354 fi
1355
1356 archive="$build_archive"
1357 scp_build_root="$scp_root/build"
1358
1359 echo "Building SCP Firmware ($mode) ..." |& log_separator
1360
1361 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001362 to="$archive" collect_scp_artefacts
1363
1364 echo "##########"
1365 echo
1366 )
1367 fi
1368
Zelalem219df412020-05-17 19:21:20 -05001369 # SCP-tools build
1370 if config_valid "$scp_tools_config"; then
1371 (
1372 echo "##########"
1373
1374 archive="$build_archive"
1375 scp_tools_build_root="$scp_tools_root/build"
1376
1377 clone_scp_tools
1378
1379 echo "##########"
1380 echo
1381
1382 echo "##########"
1383 clone_tf_for_scp_tools
1384 echo "##########"
1385 echo
1386 )
1387 fi
1388
Fathi Boudra422bf772019-12-02 11:10:16 +02001389 # TFTF build
1390 if config_valid "$tftf_config"; then
1391 (
1392 echo "##########"
1393
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001394 plat_utils="$(get_tf_opt PLAT_UTILS)"
1395 if [ -z ${plat_utils} ]; then
1396 # Source platform-specific utilities.
1397 plat="$(get_tftf_opt PLAT)"
1398 plat_utils="$ci_root/${plat}_utils.sh"
1399 else
1400 # Source platform-specific utilities by
1401 # using plat_utils name.
1402 plat_utils="$ci_root/${plat_utils}.sh"
1403 fi
1404
Fathi Boudra422bf772019-12-02 11:10:16 +02001405 if [ -f "$plat_utils" ]; then
1406 source "$plat_utils"
1407 fi
1408
1409 archive="$build_archive"
1410 tftf_build_root="$tftf_root/build"
1411
1412 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1413
1414 # Call pre-build hook
1415 call_hook pre_tftf_build
1416
1417 build_tftf
1418
1419 from="$tftf_build_root" to="$archive" collect_build_artefacts
1420
1421 # Clear any local changes made by applied patches
1422 undo_tftf_patches
1423
1424 echo "##########"
1425 echo
1426 )
1427 fi
1428
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001429 # SPM build
1430 if config_valid "$spm_config"; then
1431 (
1432 echo "##########"
1433
1434 # Get platform name from spm_config file
1435 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1436 plat_utils="$ci_root/${plat}_utils.sh"
1437 if [ -f "$plat_utils" ]; then
1438 source "$plat_utils"
1439 fi
1440
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001441 # Call pre-build hook
1442 call_hook pre_spm_build
1443
Manish Pandey1e7be852020-11-09 16:04:48 +00001444 # SPM build generates two sets of binaries, one for normal and other
1445 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001446 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001447 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1448 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001449
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001450 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001451 echo "Building SPM ($mode) ..." |& log_separator
1452
1453 # NOTE: mode has no effect on SPM build (for now), hence debug
1454 # mode is built but subsequent build using release mode just
1455 # goes through with "nothing to do".
1456 build_spm
1457
1458 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001459 cksum $spm_build_root/hafnium.bin
1460
1461 # Some platforms only have secure configuration enabled. Hence,
1462 # non secure hanfnium binary might not be built.
1463 if [ -f $hafnium_build_root/hafnium.bin ]; then
1464 cksum $hafnium_build_root/hafnium.bin
1465 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001466
Manish Pandey1e7be852020-11-09 16:04:48 +00001467 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001468
1469 echo "##########"
1470 echo
1471 )
1472 fi
1473
Fathi Boudra422bf772019-12-02 11:10:16 +02001474 # TF build
1475 if config_valid "$tf_config"; then
1476 (
1477 echo "##########"
1478
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001479 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001480 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1481
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001482 if [ -z ${plat_utils} ]; then
1483 # Source platform-specific utilities.
1484 plat="$(get_tf_opt PLAT)"
1485 plat_utils="$ci_root/${plat}_utils.sh"
1486 else
1487 # Source platform-specific utilities by
1488 # using plat_utils name.
1489 plat_utils="$ci_root/${plat_utils}.sh"
1490 fi
1491
Fathi Boudra422bf772019-12-02 11:10:16 +02001492 if [ -f "$plat_utils" ]; then
1493 source "$plat_utils"
1494 fi
1495
Chris Kaye5a486b2023-08-04 11:50:31 +00001496 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1497 fvp_tsram_size="${fvp_tsram_size:-256}"
1498
Harrison Mutai6361dbe2023-02-16 14:12:40 +00001499 poetry -C "$tf_root" install --without doc
Chris Kayd0837902021-11-17 10:17:52 +00001500
Fathi Boudra422bf772019-12-02 11:10:16 +02001501 archive="$build_archive"
1502 tf_build_root="$tf_root/build"
1503
1504 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1505
1506 # Call pre-build hook
1507 call_hook pre_tf_build
1508
1509 build_tf
1510
1511 # Call post-build hook
1512 call_hook post_tf_build
1513
1514 # Pre-archive hook
1515 call_hook pre_tf_archive
1516
1517 from="$tf_build_root" to="$archive" collect_build_artefacts
1518
1519 # Post-archive hook
1520 call_hook post_tf_archive
1521
1522 call_hook fetch_tf_resource
1523 call_hook post_fetch_tf_resource
1524
Chris Kay4e8aaf12022-09-01 15:21:55 +01001525 # Generate LAVA job files if necessary
1526 call_hook generate_lava_job_template
1527 call_hook generate_lava_job
1528
Fathi Boudra422bf772019-12-02 11:10:16 +02001529 # Clear any local changes made by applied patches
1530 undo_tf_patches
1531
1532 echo "##########"
1533 )
1534 fi
1535
1536 echo
1537 echo
1538done
1539
1540call_hook pre_package
1541
1542call_hook post_package
1543
1544if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001545 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001546fi
1547
1548echo
1549echo "Done"