blob: 535b7e3d7ffc861f7bb7dd6303b12a76659e5006 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Boyan Karatotev27057342025-07-28 09:56:23 +01003# Copyright (c) 2019-2025 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}"
Zelalem219df412020-05-17 19:21:20 -050023cc_root="${cc_root:-$ccpathspec}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010024spm_root="${spm_root:-$workspace/spm}"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +000025rmm_root="${rmm_root:-$workspace/tf-rmm}"
Zelalem219df412020-05-17 19:21:20 -050026
Fathi Boudra422bf772019-12-02 11:10:16 +020027# Refspecs
28tf_refspec="$TF_REFSPEC"
29tftf_refspec="$TFTF_REFSPEC"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010030spm_refspec="$SPM_REFSPEC"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +000031rmm_refspec="$RMM_REFSPEC"
Fathi Boudra422bf772019-12-02 11:10:16 +020032
33test_config="${TEST_CONFIG:?}"
34test_group="${TEST_GROUP:?}"
35build_configs="${BUILD_CONFIG:?}"
36run_config="${RUN_CONFIG:?}"
Zelalem219df412020-05-17 19:21:20 -050037cc_config="${CC_ENABLE:-}"
Fathi Boudra422bf772019-12-02 11:10:16 +020038
Boyan Karatotev97de8d82025-03-06 15:22:21 +000039export archive="$artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +020040build_log="$artefacts/build.log"
Boyan Karatotevde2cd442025-07-28 09:50:29 +010041
42fiptool_path() {
43 echo $tf_build_root/$(get_tf_opt PLAT)/${bin_mode}/tools/fiptool/fiptool
44}
45
46cert_create_path() {
47 echo $tf_build_root/$(get_tf_opt PLAT)/${bin_mode}/tools/cert_create/cert_create
48}
Fathi Boudra422bf772019-12-02 11:10:16 +020049
50# Validate $bin_mode
51case "$bin_mode" in
52 "" | debug | release)
53 ;;
54 *)
55 die "Invalid value for bin_mode: $bin_mode"
56 ;;
57esac
58
59# File to save any environem
60hook_env_file="$(mktempfile)"
61
62# Check if a config is valid
63config_valid() {
64 local config="${1?}"
65 if [ -z "$config" ] || [ "$(basename "$config")" = "nil" ]; then
66 return 1
67 fi
68
69 return 0
70}
71
72# Echo from a build wrapper. Print to descriptor 3 that's opened by the build
73# function.
74echo_w() {
75 echo $echo_flags "$@" >&3
76}
77
78# Print a separator to the log file. Intended to be used at the tail end of a pipe
79log_separator() {
80 {
81 echo
82 echo "----------"
83 } >> "$build_log"
84
85 tee -a "$build_log"
86
87 {
88 echo "----------"
89 echo
90 } >> "$build_log"
91}
92
93# Call function $1 if it's defined
94call_func() {
95 if type "${1:?}" &>/dev/null; then
96 echo
97 echo "> ${2:?}:$1()"
98 eval "$1"
99 echo "< $2:$1()"
100 fi
101}
102
Paul Sokolovskybe6510c2024-08-15 21:54:00 +0300103# Retry a command a number of times if it fails. Intended for I/O commands
104# in a CI environment which may be flaky.
105function retry() {
106 for i in $(seq 1 3); do
107 if "$@"; then
108 return 0
109 fi
110 sleep $(( i * 5 ))
111 done
112 return 1
113}
114
Fathi Boudra422bf772019-12-02 11:10:16 +0200115# Call hook $1 in all chosen fragments if it's defined. Hooks are invoked from
116# within a subshell, so any variables set within a hook are lost. Should a
117# variable needs to be set from within a hook, the function 'set_hook_var'
118# should be used
119call_hook() {
120 local func="$1"
121 local config_fragment
122
123 [ -z "$func" ] && return 0
124
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300125 echo "=== Calling hooks: $1 ==="
126
Fathi Boudra422bf772019-12-02 11:10:16 +0200127 : >"$hook_env_file"
128
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +0000129 if [ "$run_config_candidates" ]; then
130 for config_fragment in $run_config_candidates; do
Fathi Boudra422bf772019-12-02 11:10:16 +0200131 (
132 source "$ci_root/run_config/$config_fragment"
133 call_func "$func" "$config_fragment"
134 )
135 done
136 fi
137
138 # Also source test config file
139 (
140 unset "$func"
141 source "$test_config_file"
142 call_func "$func" "$(basename $test_config_file)"
143 )
144
145 # Have any variables set take effect
146 source "$hook_env_file"
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300147
148 echo "=== End calling hooks: $1 ==="
Fathi Boudra422bf772019-12-02 11:10:16 +0200149}
150
151# Set a variable from within a hook
152set_hook_var() {
153 echo "export $1=\"${2?}\"" >> "$hook_env_file"
154}
155
156# Append to an array from within a hook
157append_hook_var() {
158 echo "export $1+=\"${2?}\"" >> "$hook_env_file"
159}
160
161# Have the main build script source a file
162source_later() {
163 echo "source ${1?}" >> "$hook_env_file"
164}
165
166# Setup TF build wrapper function by pointing to a script containing a function
167# that will be called with the TF build commands.
168setup_tf_build_wrapper() {
169 source_later "$ci_root/script/${wrapper?}_wrapper.sh"
170 set_hook_var "tf_build_wrapper" "${wrapper}_wrapper"
171 echo "Setup $wrapper build wrapper."
172}
173
174# Collect .bin files for archiving
175collect_build_artefacts() {
176 if [ ! -d "${from:?}" ]; then
177 return
178 fi
179
Manish V Badarkhe84c3a482025-04-16 08:15:38 +0100180 if ! find "$from" \( -name "*.bin" -o -name '*.elf' -o -name '*.dtb' -o -name '*.axf' -o -name '*.stm32' -o -name '*.img' \) -exec cp -t "${to:?}" '{}' +; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200181 echo "You probably are running local CI on local repositories."
182 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
183 die
184 fi
185}
186
Manish Pandey1e7be852020-11-09 16:04:48 +0000187# Collect SPM/hafnium artefacts with "secure_" appended to the files
188# generated for SPM(secure hafnium).
189collect_spm_artefacts() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500190 if [ -d "${non_secure_from:?}" ]; then
191 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000192 fi
193
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500194 if [ -d "${secure_from:?}" ]; then
195 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
196 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000197}
198
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100199# Map the UART ID used for expect with the UART descriptor and port
200# used by the FPGA automation tools.
201map_uart() {
202 local port="${port:?}"
203 local descriptor="${descriptor:?}"
204 local baudrate="${baudrate:?}"
205 local run_root="${archive:?}/run"
206
207 local uart_dir="$run_root/uart${uart:?}"
208 mkdir -p "$uart_dir"
209
210 echo "$port" > "$uart_dir/port"
211 echo "$descriptor" > "$uart_dir/descriptor"
212 echo "$baudrate" > "$uart_dir/baudrate"
213
214 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
215}
216
Fathi Boudra422bf772019-12-02 11:10:16 +0200217# Arrange environment varibles to be set when expect scripts are launched
218set_expect_variable() {
219 local var="${1:?}"
220 local val="${2?}"
221
222 local run_root="${archive:?}/run"
223 local uart_dir="$run_root/uart${uart:?}"
224 mkdir -p "$uart_dir"
225
226 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
227 echo "UART$uart: env has $@"
228}
229
230# Place the binary package a pointer to expect script, and its parameters
231track_expect() {
232 local file="${file:?}"
233 local timeout="${timeout-600}"
234 local run_root="${archive:?}/run"
235
236 local uart_dir="$run_root/uart${uart:?}"
237 mkdir -p "$uart_dir"
238
239 echo "$file" > "$uart_dir/expect"
240 echo "$timeout" > "$uart_dir/timeout"
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700241 if [ -n "$lava_timeout" ]; then
242 set_run_env "lava_timeout" "$lava_timeout"
243 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200244
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700245 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 +0200246
Chris Kayfab6edc2022-11-17 19:18:32 +0000247 if [ ! -z "${port}" ]; then
248 echo "${port}" > "$uart_dir/port"
249 fi
250
Fathi Boudra422bf772019-12-02 11:10:16 +0200251 # The run script assumes UART0 to be primary. If we're asked to set any
252 # other UART to be primary, set a run environment variable to signal
253 # that to the run script
254 if upon "$set_primary"; then
255 echo "Primary UART set to UART$uart."
256 set_run_env "primary_uart" "$uart"
257 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600258
259 # UART used by payload(such as tftf, Linux) may not be the same as the
260 # primary UART. Set a run environment variable to track the payload
261 # UART which is tracked to check if the test has finished sucessfully.
262 if upon "$set_payload_uart"; then
263 echo "Payload uses UART$uart."
264 set_run_env "payload_uart" "$uart"
265 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200266}
267
268# Extract a FIP in $1 using fiptool
269extract_fip() {
270 local fip="$1"
271
272 if is_url "$1"; then
273 url="$1" fetch_file
274 fip="$(basename "$1")"
275 fi
276
Boyan Karatotevde2cd442025-07-28 09:50:29 +0100277 fiptool=$(fiptool_path)
Fathi Boudra422bf772019-12-02 11:10:16 +0200278 "$fiptool" unpack "$fip"
279 echo "Extracted FIP: $fip"
280}
281
282# Report build failure by printing a the tail end of build log. Archive the
283# build log for later inspection
284fail_build() {
285 local log_path
286
287 if upon "$jenkins_run"; then
288 log_path="$BUILD_URL/artifact/artefacts/build.log"
289 else
290 log_path="$build_log"
291 fi
292
293 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600294 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200295 echo "[...]"
296 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600297 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200298 echo
299 echo "See $log_path for full output"
300 echo
301 cp -t "$archive" "$build_log"
302 exit 1;
303}
304
305# Build a FIP with supplied arguments
306build_fip() {
307 (
308 echo "Building FIP with arguments: $@"
309 local tf_env="$workspace/tf.env"
310
311 if [ -f "$tf_env" ]; then
312 set -a
313 source "$tf_env"
314 set +a
315 fi
316
Boyan Karatotev99e12312025-05-02 15:00:24 +0100317 make -C "$tf_root" $make_j_opts $(cat "$tf_config_file") DEBUG="$DEBUG" BUILD_BASE=$tf_build_root V=1 "$@" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200318 ${fip_targets:-fip} &>>"$build_log" || fail_build
319 )
320}
321
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200322# Build any extra rule from TF-A makefile with supplied arguments.
323#
324# This is useful in case you need to build something else than firmware binaries
325# or the FIP.
326build_tf_extra() {
327 (
328 tf_extra_rules=${tf_extra_rules:?}
329 echo "Building extra TF rule(s): $tf_extra_rules"
330 echo " Arguments: $@"
331
332 local tf_env="$workspace/tf.env"
333
334 if [ -f "$tf_env" ]; then
335 set -a
336 source "$tf_env"
337 set +a
338 fi
339
Boyan Karatotev99e12312025-05-02 15:00:24 +0100340 make -C "$tf_root" $make_j_opts $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 BUILD_BASE=$tf_build_root "$@" \
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200341 ${tf_extra_rules} &>>"$build_log" || fail_build
342 )
343}
344
Fathi Boudra422bf772019-12-02 11:10:16 +0200345fip_update() {
Boyan Karatotevde2cd442025-07-28 09:50:29 +0100346 fiptool=$(fiptool_path)
Fathi Boudra422bf772019-12-02 11:10:16 +0200347 # Before the update process, check if the given image is supported by
348 # the fiptool. It's assumed that both fiptool and cert_create move in
Chris Kay197b1022023-08-16 21:31:41 +0100349 # tandem, and therefore, if one has support, the other has it too.
350 if ! ("$fiptool" update 2>&1 || true) | grep -qe "\s\+--${bin_name:?}"; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200351 return 1
352 fi
353
354 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
355 echo "Updating FIP image: $bin_name"
356 # Update HW config. Without TBBR, it's only a matter of using
357 # the update sub-command of fiptool
358 "$fiptool" update "--$bin_name" "${src:-}" \
359 "$archive/fip.bin"
360 else
361 echo "Updating FIP image (TBBR): $bin_name"
362 # With TBBR, we need to unpack, re-create certificates, and then
363 # recreate the FIP.
364 local fip_dir="$(mktempdir)"
365 local bin common_args stem
366 local rot_key="$(get_tf_opt ROT_KEY)"
367
368 rot_key="${rot_key:?}"
369 if ! is_abs "$rot_key"; then
370 rot_key="$tf_root/$rot_key"
371 fi
372
373 # Arguments only for cert_create
374 local cert_args="-n"
375 cert_args+=" --tfw-nvctr ${nvctr:-31}"
376 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
377 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
378 cert_args+=" --rot-key $rot_key"
379
380 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500381 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200382 "hw-config"
383 "tb-fw-config"
384 "nt-fw-config"
385 "soc-fw-config"
386 "tos-fw-config"
387 )
388
389 # Binaries without key certificates
390 declare -A has_no_key_cert
391 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
392 has_no_key_cert["$bin"]="1"
393 done
394
395 # Binaries without certificates
396 declare -A has_no_cert
397 for bin in "hw-config" "${dyn_config_opts[@]}"; do
398 has_no_cert["$bin"]="1"
399 done
400
401 pushd "$fip_dir"
402
403 # Unpack FIP
404 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
405
406 # Remove all existing certificates
407 rm -f *-cert.bin
408
409 # Copy the binary to be updated
410 cp -f "$src" "${bin_name}.bin"
411
412 # FIP unpack dumps binaries with the same name as the option
413 # used to pack it; likewise for certificates. Reverse-engineer
414 # the command line from the binary output.
415 common_args="--trusted-key-cert trusted_key.crt"
416 for bin in *.bin; do
417 stem="${bin%%.bin}"
418 common_args+=" --$stem $bin"
419 if not_upon "${has_no_cert[$stem]}"; then
420 common_args+=" --$stem-cert $stem.crt"
421 fi
422 if not_upon "${has_no_key_cert[$stem]}"; then
423 common_args+=" --$stem-key-cert $stem-key.crt"
424 fi
425 done
426
427 # Create certificates
Boyan Karatotevde2cd442025-07-28 09:50:29 +0100428 cert_create=$(cert_create_path)
Fathi Boudra422bf772019-12-02 11:10:16 +0200429 "$cert_create" $cert_args $common_args &>>"$build_log"
430
431 # Recreate and archive FIP
432 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
433 archive_file "fip.bin"
434
435 popd
436 fi
437}
438
439# Update hw-config in FIP, and remove the original DTB afterwards.
440update_fip_hw_config() {
441 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600442 # in configs:
443 # 1. Where BL2 isn't present
444 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200445 case "1" in
446 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600447 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200448 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000449 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200450 return 0;;
451 esac
452
453 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
454 # Remove the DTB so that model won't load it
455 rm -f "$archive/dtb.bin"
456 fi
457}
458
Fathi Boudra422bf772019-12-02 11:10:16 +0200459get_tftf_opt() {
460 (
461 name="${1:?}"
462 if config_valid "$tftf_config_file"; then
463 source "$tftf_config_file"
464 echo "${!name}"
465 fi
466 )
467}
468
469get_tf_opt() {
470 (
471 name="${1:?}"
472 if config_valid "$tf_config_file"; then
473 source "$tf_config_file"
474 echo "${!name}"
475 fi
476 )
477}
478
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000479get_rmm_opt() {
480 (
481 name="${1:?}"
Manish V Badarkhea3505272025-04-17 14:20:42 +0100482 default="$2"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000483 if config_valid "$rmm_config_file"; then
484 source "$rmm_config_file"
Manish V Badarkhea3505272025-04-17 14:20:42 +0100485 # If !name is not defined, go with the default
486 # value (if defined)
487 if [ -z "${!name}" ]; then
488 echo "$default"
489 else
490 echo "${!name}"
491 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000492 fi
493 )
494}
495
Fathi Boudra422bf772019-12-02 11:10:16 +0200496build_tf() {
497 (
498 env_file="$workspace/tf.env"
499 config_file="${tf_build_config:-$tf_config_file}"
500
501 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100502 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200503
504 source "$config_file"
505
506 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000507 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100508 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
509 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200510 mbedtls_dir="$workspace/mbedtls"
511 if [ ! -d "$mbedtls_dir" ]; then
512 mbedtls_ar="$workspace/mbedtls.tar.gz"
513
514 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
515 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500516 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200517 fi
518
519 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
520 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500521 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
522 not_upon "${TF_M_TESTS_PATH}"; then
523 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
524 fi
525 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
526 not_upon "${TF_M_EXTRAS_PATH}"; then
527 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
528 fi
David Vincze82db6932024-02-21 12:05:50 +0100529 if [ "$(get_tf_opt DICE_PROTECTION_ENVIRONMENT)" = 1 ] &&
530 not_upon "${QCBOR_DIR}"; then
531 emit_env "QCBOR_DIR" "$WORKSPACE/qcbor"
532 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200533 if [ -f "$env_file" ]; then
534 set -a
535 source "$env_file"
536 set +a
537 fi
538
Harrison Mutai013f6332022-02-16 16:06:33 +0000539 if is_arm_jenkins_env || upon "$local_ci"; then
540 path_list=(
541 "$llvm_dir/bin"
542 )
543 extend_path "PATH" "path_list"
544 fi
545
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000546 pushd "$tf_root"
Fathi Boudra422bf772019-12-02 11:10:16 +0200547
548 # Always distclean when running on Jenkins. Skip distclean when running
549 # locally and explicitly requested.
550 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000551 make distclean BUILD_BASE=$tf_build_root &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200552 fi
553
554 # Log build command line. It is left unfolded on purpose to assist
555 # copying to clipboard.
556 cat <<EOF | log_separator >/dev/null
557
558Build command line:
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000559 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 BUILD_BASE=$tf_build_root $build_targets
Fathi Boudra422bf772019-12-02 11:10:16 +0200560
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300561CC version:
562$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200563EOF
564
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000565 if not_upon "$local_ci"; then
566 connect_debugger=0
567 fi
568
Fathi Boudra422bf772019-12-02 11:10:16 +0200569 # Build TF. Since build output is being directed to the build log, have
570 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000571 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000572 DEBUG="$DEBUG" V=1 BUILD_BASE="$tf_build_root" SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200573 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100574
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100575 if [ "$build_targets" != "doc" ]; then
Chris Kay9ab2d952025-05-29 13:46:24 +0100576 (poetry run memory --root "$tf_build_root" symbols 2>&1 || true) | tee -a "${build_log}"
577
578 for map in $(find "${tf_build_root}" -name '*.map'); do
579 (poetry run memory --root "${tf_build_root}" summary "${map}" 2>&1 || true) | tee -a "${build_log}"
580 done
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100581 fi
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000582 popd
Fathi Boudra422bf772019-12-02 11:10:16 +0200583 )
584}
585
586build_tftf() {
587 (
588 config_file="${tftf_build_config:-$tftf_config_file}"
589
590 # Build tftf target by default
591 build_targets="${tftf_build_targets:-all}"
592
593 source "$config_file"
594
595 cd "$tftf_root"
596
597 # Always distclean when running on Jenkins. Skip distclean when running
598 # locally and explicitly requested.
599 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000600 make distclean BUILD_BASE="$tftf_build_root" &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200601 fi
602
603 # TFTF build system cannot reliably deal with -j option, so we avoid
604 # using that.
605
606 # Log build command line
607 cat <<EOF | log_separator >/dev/null
608
609Build command line:
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000610 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 BUILD_BASE="$tftf_build_root" $build_targets
Fathi Boudra422bf772019-12-02 11:10:16 +0200611
612EOF
613
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000614 make $make_j_opts $(cat "$config_file") DEBUG="$DEBUG" V=1 BUILD_BASE="$tftf_build_root" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200615 $build_targets &>>"$build_log" || fail_build
616 )
617}
618
Zelalem219df412020-05-17 19:21:20 -0500619build_cc() {
620# Building code coverage plugin
621 ARM_DIR=/arm
622 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
623 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
624 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
625 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
626 exit -1
627 fi # Error if arm warehouse not found
628 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
629
630 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
631}
632
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100633build_spm() {
634 (
635 env_file="$workspace/spm.env"
636 config_file="${spm_build_config:-$spm_config_file}"
637
638 source "$config_file"
639
640 if [ -f "$env_file" ]; then
641 set -a
642 source "$env_file"
643 set +a
644 fi
645
646 cd "$spm_root"
647
648 # Always clean when running on Jenkins. Skip clean when running
649 # locally and explicitly requested.
650 if upon "$jenkins_run" || not_upon "$dont_clean"; then
651 # make clean fails on a fresh repo where the project has not
652 # yet been built. Hence only clean if out/reference directory
653 # already exists.
654 if [ -d "out/reference" ]; then
655 make clean &>>"$build_log" || fail_build
656 fi
657 fi
658
659 # Log build command line. It is left unfolded on purpose to assist
660 # copying to clipboard.
661 cat <<EOF | log_separator >/dev/null
662
663Build command line:
Boyan Karatotev27057342025-07-28 09:56:23 +0100664 make $make_j_opts OUT=$spm_build_root $(cat "$config_file" | tr '\n' ' ')
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100665
666EOF
667
668 # Build SPM. Since build output is being directed to the build log, have
669 # descriptor 3 point to the current terminal for build wrappers to vent.
Boyan Karatotev27057342025-07-28 09:56:23 +0100670 make $make_j_opts OUT=$spm_build_root $(cat "$config_file") 3>&1 &>>"$build_log" \
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100671 || fail_build
672 )
673}
Zelalem219df412020-05-17 19:21:20 -0500674
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000675build_rmm() {
676 (
677 env_file="$workspace/rmm.env"
678 config_file="${rmm_build_config:-$rmm_config_file}"
679
680 # Build fiptool and all targets by default
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000681 export CROSS_COMPILE="${aarch64_none_elf_prefix}"
682
683 source "$config_file"
684
685 if [ -f "$env_file" ]; then
686 set -a
687 source "$env_file"
688 set +a
689 fi
690
691 cd "$rmm_root"
692
693 if [ -f "$rmm_root/requirements.txt" ]; then
694 export PATH="$HOME/.local/bin:$PATH"
695 python3 -m pip install --upgrade pip
696 python3 -m pip install -r "$rmm_root/requirements.txt"
697 fi
698
699 # Always distclean when running on Jenkins. Skip distclean when running
700 # locally and explicitly requested.
701 if upon "$jenkins_run" || not_upon "$dont_clean"; then
702 # Remove 'rmm\build' folder
703 echo "Removing $rmm_build_root..."
704 rm -rf $rmm_build_root
705 fi
706
Manish V Badarkhea3505272025-04-17 14:20:42 +0100707 if not_upon "$local_ci"; then
708 connect_debugger=0
709 fi
710
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000711 # Log build command line. It is left unfolded on purpose to assist
712 # copying to clipboard.
713 cat <<EOF | log_separator >/dev/null
714
715Build command line:
Manish V Badarkhea3505272025-04-17 14:20:42 +0100716 cmake -DRMM_CONFIG=${plat}_defcfg "$cmake_gen" -S $rmm_root -B $rmm_build_root -DRMM_TOOLCHAIN=$rmm_toolchain -DRMM_FPU_USE_AT_REL2=$rmm_fpu_use_at_rel2 -DATTEST_EL3_TOKEN_SIGN=$rmm_attest_el3_token_sign -DRMM_V1_1=$rmm_v1_1 ${extra_options}
717 cmake --build $rmm_build_root --config $cmake_build_type $make_j_opts -v ${extra_targets+-- $extra_targets}
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000718
Manish V Badarkhea3505272025-04-17 14:20:42 +0100719EOF
720 cmake \
721 -DRMM_CONFIG=${plat}_defcfg $cmake_gen \
722 -S $rmm_root -B $rmm_build_root \
723 -DRMM_TOOLCHAIN=$rmm_toolchain \
724 -DRMM_FPU_USE_AT_REL2=$rmm_fpu_use_at_rel2 \
725 -DATTEST_EL3_TOKEN_SIGN=$rmm_attest_el3_token_sign \
726 -DRMM_V1_1=$rmm_v1_1 \
727 ${extra_options}
728 cmake --build $rmm_build_root --config $cmake_build_type $make_j_opts -v ${extra_targets+-- $extra_targets} 3>&1 &>>"$build_log" || fail_build
729 )
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000730}
731
Fathi Boudra422bf772019-12-02 11:10:16 +0200732# Set metadata for the whole package so that it can be used by both Jenkins and
733# shell
734set_package_var() {
735 env_file="$artefacts/env" emit_env "$@"
736}
737
738set_tf_build_targets() {
739 echo "Set build target to '${targets:?}'"
740 set_hook_var "tf_build_targets" "$targets"
741}
742
743set_tftf_build_targets() {
744 echo "Set build target to '${targets:?}'"
745 set_hook_var "tftf_build_targets" "$targets"
746}
747
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100748set_spm_build_targets() {
749 echo "Set build target to '${targets:?}'"
750 set_hook_var "spm_build_targets" "$targets"
751}
752
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000753set_spm_out_dir() {
754 echo "Set SPMC binary build to '${out_dir:?}'"
755 set_hook_var "spm_secure_out_dir" "$out_dir"
756}
Fathi Boudra422bf772019-12-02 11:10:16 +0200757# Look under $archive directory for known files such as blX images, kernel, DTB,
758# initrd etc. For each known file foo, if foo.bin exists, then set variable
759# foo_bin to the path of the file. Make the path relative to the workspace so as
760# to remove any @ characters, which Jenkins inserts for parallel runs. If the
761# file doesn't exist, unset its path.
762set_default_bin_paths() {
763 local image image_name image_path path
764 local archive="${archive:?}"
765 local set_vars
766 local var
767
768 pushd "$archive"
769
770 for file in *.bin; do
771 # Get a shell variable from the file's stem
772 var_name="${file%%.*}_bin"
773 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
774
775 # Skip setting the variable if it's already
776 if [ "${!var_name}" ]; then
777 echo "Note: not setting $var_name; already set to ${!var_name}"
778 continue
779 else
780 set_vars+="$var_name "
781 fi
782
783 eval "$var_name=$file"
784 done
785
786 echo "Binary paths set for: "
787 {
788 for var in $set_vars; do
789 echo -n "\$$var "
790 done
791 } | fmt -80 | sed 's/^/ /'
792 echo
793
794 popd
795}
796
797gen_model_params() {
798 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000799 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200800
801 set_default_bin_paths
802 echo "Generating model parameter for $model..."
803 source "$ci_root/model/${model:?}.sh"
804 archive_file "$model_param_file"
805}
806
807set_model_path() {
808 set_run_env "model_path" "${1:?}"
809}
810
Zelalem1af7a7b2020-08-04 17:34:32 -0500811set_model_env() {
812 local var="${1:?}"
813 local val="${2?}"
814 local run_root="${archive:?}/run"
815
816 mkdir -p "$run_root"
817 echo "export $var=$val" >> "$run_root/model_env"
818}
Fathi Boudra422bf772019-12-02 11:10:16 +0200819set_run_env() {
820 local var="${1:?}"
821 local val="${2?}"
822 local run_root="${archive:?}/run"
823
824 mkdir -p "$run_root"
825 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
826}
827
828show_head() {
829 # Display HEAD descripton
830 pushd "$1"
831 git show --quiet --no-color | sed 's/^/ > /g'
832 echo
833 popd
834}
835
836# Choose debug binaries to run; by default, release binaries are chosen to run
837use_debug_bins() {
838 local run_root="${archive:?}/run"
839
840 echo "Choosing debug binaries for execution"
841 set_package_var "BIN_MODE" "debug"
842}
843
844assert_can_git_clone() {
845 local name="${1:?}"
846 local dir="${!name}"
847
848 # If it doesn't exist, it can be cloned into
849 if [ ! -e "$dir" ]; then
850 return 0
851 fi
852
853 # If it's a directory, it must be a Git clone already
854 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
855 # No need to clone again
856 echo "Using existing git clone for $name: $dir"
857 return 1
858 fi
859
860 die "Path $dir exists but is not a git clone"
861}
862
863clone_repo() {
864 if ! is_url "${clone_url?}"; then
865 # For --depth to take effect on local paths, it needs to use the
866 # file:// scheme.
867 clone_url="file://$clone_url"
868 fi
869
870 git clone -q --depth 1 "$clone_url" "${where?}"
871 if [ "$refspec" ]; then
872 pushd "$where"
873 git fetch -q --depth 1 origin "$refspec"
874 git checkout -q FETCH_HEAD
875 popd
876 fi
877}
878
879build_unstable() {
880 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
881}
882
883undo_patch_record() {
884 if [ ! -f "${patch_record:?}" ]; then
885 return
886 fi
887
888 # Undo patches in reverse
889 echo
890 for patch_name in $(tac "$patch_record"); do
891 echo "Undoing $patch_name..."
892 if ! git apply -R "$ci_root/patch/$patch_name"; then
893 if upon "$local_ci"; then
894 echo
895 echo "Your local directory may have been dirtied."
896 echo
897 fi
898 fail_build
899 fi
900 done
901
902 rm -f "$patch_record"
903}
904
905undo_local_patches() {
906 pushd "$tf_root"
907 patch_record="$tf_patch_record" undo_patch_record
908 popd
909
910 if [ -d "$tftf_root" ]; then
911 pushd "$tftf_root"
912 patch_record="$tftf_patch_record" undo_patch_record
913 popd
914 fi
915}
916
917undo_tftf_patches() {
918 pushd "$tftf_root"
919 patch_record="$tftf_patch_record" undo_patch_record
920 popd
921}
922
923undo_tf_patches() {
924 pushd "$tf_root"
925 patch_record="$tf_patch_record" undo_patch_record
926 popd
927}
928
929apply_patch() {
930 # If skip_patches is set, the developer has applied required patches
931 # manually. They probably want to keep them applied for debugging
932 # purposes too. This means we don't have to apply/revert them as part of
933 # build process.
934 if upon "$skip_patches"; then
935 echo "Skipped applying ${1:?}..."
936 return 0
937 else
938 echo "Applying ${1:?}..."
939 fi
940
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +0200941 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -0500942 echo "Skipping already applied ${1:?}"
943 return 0
944 fi
945
Fathi Boudra422bf772019-12-02 11:10:16 +0200946 if git apply < "$ci_root/patch/$1"; then
947 echo "$1" >> "${patch_record:?}"
948 else
949 if upon "$local_ci"; then
950 undo_local_patches
951 fi
952 fail_build
953 fi
954}
955
Fathi Boudra422bf772019-12-02 11:10:16 +0200956apply_tf_patch() {
Boyan Karatotevfaf9a9d2025-07-28 09:52:05 +0100957 root="$tf_root"
958 new_root="$archive/tfa_mirror"
959
960 # paralell builds are only used locally. Don't do for CI since this will
961 # have a speed penalty. Also skip if this was already done as a single
962 # job may apply many patches.
963 if upon "$local_ci" && [[ ! -d $new_root ]]; then
964 root=$new_root
965 diff=$(mktempfile)
966
967 # get anything still uncommitted
968 pushd $tf_root
969 git diff HEAD > $diff
970 popd
971
972 # git will hard link when cloning locally, no need for --depth=1
973 git clone "$tf_root" $root --shallow-submodules
974
975 tf_root=$root # next apply_tf_patch will run in the same hook
976 set_hook_var "tf_root" "$root" # for anyone outside the hook
977
978 # apply uncommited changes so they are picked up in the build
979 pushd $tf_root
980 git apply $diff &> /dev/null || true
981 popd
982
983 fi
984
985 pushd "$root"
Fathi Boudra422bf772019-12-02 11:10:16 +0200986 patch_record="$tf_patch_record" apply_patch "$1"
987 popd
988}
989
Fathi Boudra422bf772019-12-02 11:10:16 +0200990mkdir -p "$workspace"
991mkdir -p "$archive"
992set_package_var "TEST_CONFIG" "$test_config"
993
994{
995echo
996echo "CONFIGURATION: $test_group/$test_config"
997echo
998} |& log_separator
999
1000tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1001tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
Chris Kay4f7846a2025-08-04 19:56:35 +01001002spm_config="$(echo "$build_configs" | awk -F, '{print $3}')"
1003rmm_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001004
1005test_config_file="$ci_root/group/$test_group/$test_config"
1006
1007tf_config_file="$ci_root/tf_config/$tf_config"
1008tftf_config_file="$ci_root/tftf_config/$tftf_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001009spm_config_file="$ci_root/spm_config/$spm_config"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001010rmm_config_file="$ci_root/rmm_config/$rmm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001011
1012# File that keeps track of applied patches
1013tf_patch_record="$workspace/tf_patches"
1014tftf_patch_record="$workspace/tftf_patches"
1015
1016pushd "$workspace"
1017
1018if ! config_valid "$tf_config"; then
1019 tf_config=
1020else
1021 echo "Trusted Firmware config:"
1022 echo
1023 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1024 echo
1025fi
1026
1027if ! config_valid "$tftf_config"; then
1028 tftf_config=
1029else
1030 echo "Trusted Firmware TF config:"
1031 echo
1032 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1033 echo
1034fi
1035
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001036if ! config_valid "$spm_config"; then
1037 spm_config=
1038else
1039 echo "SPM config:"
1040 echo
1041 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001042 echo
1043fi
1044
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001045# File that keeps track of applied patches
1046rmm_patch_record="$workspace/rmm_patches"
1047
1048if ! config_valid "$rmm_config"; then
1049 rmm_config=
1050else
1051 echo "Trusted Firmware RMM config:"
1052 echo
1053 sort "$rmm_config_file" | sed '/^\s*$/d;s/^/\t/'
1054 echo
1055fi
1056
Fathi Boudra422bf772019-12-02 11:10:16 +02001057if ! config_valid "$run_config"; then
1058 run_config=
1059fi
1060
1061if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1062 # If the Trusted Firmware repository has already been checked out, use
1063 # that location. Otherwise, clone one ourselves.
1064 echo "Cloning Trusted Firmware..."
1065 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1066 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1067 show_head "$tf_root"
1068fi
1069
1070if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1071 # If the Trusted Firmware TF repository has already been checked out,
1072 # use that location. Otherwise, clone one ourselves.
1073 echo "Cloning Trusted Firmware TF..."
1074 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1075 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1076 show_head "$tftf_root"
1077fi
1078
Zelalem219df412020-05-17 19:21:20 -05001079if [ -n "$cc_config" ] ; then
1080 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1081 # Copy code coverage repository
1082 echo "Cloning Code Coverage..."
1083 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1084 show_head "$cc_root"
1085 fi
1086fi
1087
Daniel Boulby25385ab2023-12-14 14:36:25 +00001088if [ "$spm_config" ] ; then
1089 if assert_can_git_clone "spm_root"; then
1090 # If the SPM repository has already been checked out, use
1091 # that location. Otherwise, clone one ourselves.
1092 echo "Cloning SPM..."
1093 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1094 where="$spm_root" refspec="$SPM_REFSPEC" \
1095 clone_repo &>>"$build_log"
1096 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001097
1098 # Query git submodules
1099 pushd "$spm_root"
Daniel Boulby25385ab2023-12-14 14:36:25 +00001100 # Check if submodules need initialising
Paul Sokolovskyad274422024-09-01 10:27:56 +03001101
1102 # This handling is needed to reliably fetch submodules
1103 # in CI environment.
1104 for subm in $(git submodule status | awk '/^-/ {print $2}'); do
1105 for i in $(seq 1 7); do
1106 git submodule init $subm
1107 if git submodule update $subm; then
1108 break
1109 fi
1110 git submodule deinit --force $subm
1111 echo "Retrying $subm"
1112 sleep $((RANDOM % 10 + 5))
1113 done
1114 done
1115
1116 git submodule status
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001117 popd
1118
1119 show_head "$spm_root"
1120fi
1121
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001122if [ "$rmm_config" ] && assert_can_git_clone "rmm_root"; then
Manish V Badarkhe41909452025-04-11 12:06:45 +01001123 # If the RMM repository has already been checked out,
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001124 # use that location. Otherwise, clone one ourselves.
1125 echo "Cloning TF-RMM..."
1126 clone_url="${RMM_CHECKOUT_LOC:-$rmm_src_repo_url}" where="$rmm_root" \
1127 refspec="$RMM_REFSPEC" clone_repo &>>"$build_log"
1128 show_head "$rmm_root"
1129fi
1130
Fathi Boudra422bf772019-12-02 11:10:16 +02001131if [ "$run_config" ]; then
1132 # Get candidates for run config
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001133 run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \
Fathi Boudra422bf772019-12-02 11:10:16 +02001134 "$run_config")"
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001135 if [ -z "$run_config_candidates" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001136 die "No run config candidates!"
1137 else
1138 echo
1139 echo "Chosen fragments:"
1140 echo
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001141 echo "$run_config_candidates" | sed 's/^\|\n/\t/g'
Fathi Boudra422bf772019-12-02 11:10:16 +02001142 echo
Harrison Mutai4dfe1192024-07-03 12:35:38 +00001143
1144 if [ ! -n "$bin_mode" ]; then
1145 if echo $run_config_candidates | grep -wq "debug"; then
1146 bin_mode="debug"
1147 else
1148 bin_mode="release"
1149 fi
1150 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001151 fi
1152fi
1153
1154call_hook "test_setup"
1155echo
1156
1157if upon "$local_ci"; then
1158 # For local runs, since each config is tried in sequence, it's
1159 # advantageous to run jobs in parallel
1160 if [ "$make_j" ]; then
1161 make_j_opts="-j $make_j"
1162 else
1163 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1164 if [ "$n_cores" ]; then
1165 make_j_opts="-j $n_cores"
1166 fi
1167 fi
1168fi
1169
Harrison Mutai07043e92023-07-06 09:41:12 +01001170# Install python build dependencies
1171if is_arm_jenkins_env; then
1172 source "$ci_root/script/install_python_deps.sh"
1173fi
1174
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001175# Print CMake version
1176cmake_ver=$(echo `cmake --version | sed -n '1p'`)
1177echo "Using $cmake_ver"
1178
1179# Check for Ninja
1180if [ -x "$(command -v ninja)" ]; then
1181 # Print Ninja version
1182 ninja_ver=$(echo `ninja --version | sed -n '1p'`)
1183 echo "Using ninja $ninja_ver"
1184 export cmake_gen="-G Ninja"
1185else
1186 echo 'Ninja is not installed'
1187 export cmake_gen=""
1188fi
1189
1190undo_rmm_patches() {
1191 pushd "$rmm_root"
1192 patch_record="$rmm_patch_record" undo_patch_record
1193 popd
1194}
1195
Fathi Boudra422bf772019-12-02 11:10:16 +02001196modes="${bin_mode:-debug release}"
1197for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001198 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001199 # Build with a temporary archive
1200 build_archive="$archive/$mode"
1201 mkdir "$build_archive"
1202
1203 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001204 export bin_mode="debug"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001205 cmake_build_type="Debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001206 DEBUG=1
1207 else
Zelalem219df412020-05-17 19:21:20 -05001208 export bin_mode="release"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001209 cmake_build_type="Release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001210 DEBUG=0
1211 fi
1212
1213 # Perform builds in a subshell so as not to pollute the current and
1214 # subsequent builds' environment
1215
Zelalem219df412020-05-17 19:21:20 -05001216 if config_valid "$cc_config"; then
1217 # Build code coverage plugin
1218 build_cc
1219 fi
1220
Fathi Boudra422bf772019-12-02 11:10:16 +02001221 # TFTF build
1222 if config_valid "$tftf_config"; then
1223 (
1224 echo "##########"
1225
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001226 plat_utils="$(get_tf_opt PLAT_UTILS)"
1227 if [ -z ${plat_utils} ]; then
1228 # Source platform-specific utilities.
1229 plat="$(get_tftf_opt PLAT)"
1230 plat_utils="$ci_root/${plat}_utils.sh"
1231 else
1232 # Source platform-specific utilities by
1233 # using plat_utils name.
1234 plat_utils="$ci_root/${plat_utils}.sh"
1235 fi
1236
Fathi Boudra422bf772019-12-02 11:10:16 +02001237 if [ -f "$plat_utils" ]; then
1238 source "$plat_utils"
1239 fi
1240
1241 archive="$build_archive"
Boyan Karatotev97de8d82025-03-06 15:22:21 +00001242 tftf_build_root="$archive/build/tftf"
1243 mkdir -p ${tftf_build_root}
Fathi Boudra422bf772019-12-02 11:10:16 +02001244
1245 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1246
1247 # Call pre-build hook
1248 call_hook pre_tftf_build
1249
1250 build_tftf
1251
1252 from="$tftf_build_root" to="$archive" collect_build_artefacts
1253
1254 # Clear any local changes made by applied patches
1255 undo_tftf_patches
1256
1257 echo "##########"
1258 echo
1259 )
1260 fi
1261
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001262 # SPM build
1263 if config_valid "$spm_config"; then
1264 (
1265 echo "##########"
1266
1267 # Get platform name from spm_config file
1268 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1269 plat_utils="$ci_root/${plat}_utils.sh"
1270 if [ -f "$plat_utils" ]; then
1271 source "$plat_utils"
1272 fi
1273
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001274 # Call pre-build hook
1275 call_hook pre_spm_build
1276
Manish Pandey1e7be852020-11-09 16:04:48 +00001277 # SPM build generates two sets of binaries, one for normal and other
1278 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001279 archive="$build_archive"
Boyan Karatotev27057342025-07-28 09:56:23 +01001280 spm_build_root="$archive/build/spm"
1281
1282 spm_secure_build_root="$spm_build_root/$spm_secure_out_dir"
1283 spm_ns_build_root="$spm_build_root/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001284
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001285 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001286 echo "Building SPM ($mode) ..." |& log_separator
1287
1288 # NOTE: mode has no effect on SPM build (for now), hence debug
1289 # mode is built but subsequent build using release mode just
1290 # goes through with "nothing to do".
1291 build_spm
1292
1293 # Show SPM/Hafnium binary details
Boyan Karatotev27057342025-07-28 09:56:23 +01001294 cksum $spm_secure_build_root/hafnium.bin
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001295
1296 # Some platforms only have secure configuration enabled. Hence,
1297 # non secure hanfnium binary might not be built.
Boyan Karatotev27057342025-07-28 09:56:23 +01001298 if [ -f $spm_ns_build_root/hafnium.bin ]; then
1299 cksum $spm_ns_build_root/hafnium.bin
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001300 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001301
Boyan Karatotev27057342025-07-28 09:56:23 +01001302 secure_from="$spm_secure_build_root" non_secure_from="$spm_ns_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001303
1304 echo "##########"
1305 echo
1306 )
1307 fi
1308
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001309 # TF RMM build
1310 if config_valid "$rmm_config"; then
1311 (
1312 echo "##########"
1313
1314 plat_utils="$(get_rmm_opt PLAT_UTILS)"
1315 if [ -z ${plat_utils} ]; then
1316 # Source platform-specific utilities.
1317 plat="$(get_rmm_opt PLAT)"
Manish V Badarkhea3505272025-04-17 14:20:42 +01001318 extra_options="$(get_rmm_opt EXTRA_OPTIONS)"
1319 extra_targets="$(get_rmm_opt EXTRA_TARGETS "")"
1320 rmm_toolchain="$(get_rmm_opt TOOLCHAIN gnu)"
1321 rmm_fpu_use_at_rel2="$(get_rmm_opt RMM_FPU_USE_AT_REL2 OFF)"
1322 rmm_attest_el3_token_sign="$(get_rmm_opt ATTEST_EL3_TOKEN_SIGN OFF)"
1323 rmm_v1_1="$(get_rmm_opt RMM_V1_1 ON)"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001324 plat_utils="$ci_root/${plat}_utils.sh"
1325 else
1326 # Source platform-specific utilities by
1327 # using plat_utils name.
1328 plat_utils="$ci_root/${plat_utils}.sh"
1329 fi
1330
1331 if [ -f "$plat_utils" ]; then
1332 source "$plat_utils"
1333 fi
1334
1335 archive="$build_archive"
1336 rmm_build_root="$rmm_root/build"
1337
1338 echo "Building Trusted Firmware RMM ($mode) ..." |& log_separator
1339
1340 #call_hook pre_rmm_build
1341 build_rmm
1342
1343 # Collect all rmm.* files: rmm.img, rmm.elf, rmm.dump, rmm.map
1344 from="$rmm_build_root" to="$archive" collect_build_artefacts
1345
1346 # Clear any local changes made by applied patches
1347 undo_rmm_patches
1348
1349 echo "##########"
1350 )
1351 fi
1352
Fathi Boudra422bf772019-12-02 11:10:16 +02001353 # TF build
1354 if config_valid "$tf_config"; then
1355 (
1356 echo "##########"
1357
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001358 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001359 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1360
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001361 if [ -z ${plat_utils} ]; then
1362 # Source platform-specific utilities.
1363 plat="$(get_tf_opt PLAT)"
1364 plat_utils="$ci_root/${plat}_utils.sh"
1365 else
1366 # Source platform-specific utilities by
1367 # using plat_utils name.
1368 plat_utils="$ci_root/${plat_utils}.sh"
1369 fi
1370
Fathi Boudra422bf772019-12-02 11:10:16 +02001371 if [ -f "$plat_utils" ]; then
1372 source "$plat_utils"
1373 fi
1374
Chris Kaye5a486b2023-08-04 11:50:31 +00001375 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1376 fvp_tsram_size="${fvp_tsram_size:-256}"
1377
Harrison Mutaidc703402024-08-02 14:40:16 +00001378 poetry -C "$tf_root" install --without docs
Chris Kayd0837902021-11-17 10:17:52 +00001379
Fathi Boudra422bf772019-12-02 11:10:16 +02001380 archive="$build_archive"
Boyan Karatotev97de8d82025-03-06 15:22:21 +00001381 tf_build_root="$archive/build/tfa"
1382 mkdir -p ${tf_build_root}
Fathi Boudra422bf772019-12-02 11:10:16 +02001383
1384 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1385
1386 # Call pre-build hook
1387 call_hook pre_tf_build
1388
1389 build_tf
1390
1391 # Call post-build hook
1392 call_hook post_tf_build
1393
1394 # Pre-archive hook
1395 call_hook pre_tf_archive
1396
1397 from="$tf_build_root" to="$archive" collect_build_artefacts
1398
1399 # Post-archive hook
1400 call_hook post_tf_archive
1401
1402 call_hook fetch_tf_resource
1403 call_hook post_fetch_tf_resource
1404
Chris Kay4e8aaf12022-09-01 15:21:55 +01001405 # Generate LAVA job files if necessary
1406 call_hook generate_lava_job_template
1407 call_hook generate_lava_job
1408
Fathi Boudra422bf772019-12-02 11:10:16 +02001409 # Clear any local changes made by applied patches
1410 undo_tf_patches
1411
1412 echo "##########"
1413 )
1414 fi
1415
1416 echo
1417 echo
1418done
1419
1420call_hook pre_package
1421
1422call_hook post_package
1423
1424if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001425 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001426fi
1427
1428echo
1429echo "Done"