blob: 3c6e0eef9350825396c46591d9ddf37e66ae4f8b [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
David Vincze82db6932024-02-21 12:05:50 +01003# Copyright (c) 2019-2024 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}"
Tomás González866b23a2025-07-22 11:05:57 +010022export rfa_root="${rfa_root:-$workspace/rusted-firmware-a}"
Zelalem219df412020-05-17 19:21:20 -050023export tftf_root="${tftf_root:-$workspace/trusted_firmware_tf}"
24export scp_root="${scp_root:-$workspace/scp}"
25scp_tools_root="${scp_tools_root:-$workspace/scp_tools}"
26cc_root="${cc_root:-$ccpathspec}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010027spm_root="${spm_root:-$workspace/spm}"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +000028rmm_root="${rmm_root:-$workspace/tf-rmm}"
Zelalem219df412020-05-17 19:21:20 -050029
30scp_tf_tools_root="$scp_tools_root/scp_tf_tools"
Fathi Boudra422bf772019-12-02 11:10:16 +020031
32# Refspecs
33tf_refspec="$TF_REFSPEC"
34tftf_refspec="$TFTF_REFSPEC"
35scp_refspec="$SCP_REFSPEC"
Zelalem219df412020-05-17 19:21:20 -050036scp_tools_commit="${SCP_TOOLS_COMMIT:-master}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010037spm_refspec="$SPM_REFSPEC"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +000038rmm_refspec="$RMM_REFSPEC"
Tomás González866b23a2025-07-22 11:05:57 +010039rfa_refspec="$RFA_REFSPEC"
Fathi Boudra422bf772019-12-02 11:10:16 +020040
41test_config="${TEST_CONFIG:?}"
42test_group="${TEST_GROUP:?}"
43build_configs="${BUILD_CONFIG:?}"
44run_config="${RUN_CONFIG:?}"
Zelalem219df412020-05-17 19:21:20 -050045cc_config="${CC_ENABLE:-}"
Fathi Boudra422bf772019-12-02 11:10:16 +020046
47archive="$artefacts"
48build_log="$artefacts/build.log"
49fiptool="$tf_root/tools/fiptool/fiptool"
50cert_create="$tf_root/tools/cert_create/cert_create"
51
52# Validate $bin_mode
53case "$bin_mode" in
54 "" | debug | release)
55 ;;
56 *)
57 die "Invalid value for bin_mode: $bin_mode"
58 ;;
59esac
60
61# File to save any environem
62hook_env_file="$(mktempfile)"
63
64# Check if a config is valid
65config_valid() {
66 local config="${1?}"
67 if [ -z "$config" ] || [ "$(basename "$config")" = "nil" ]; then
68 return 1
69 fi
70
71 return 0
72}
73
74# Echo from a build wrapper. Print to descriptor 3 that's opened by the build
75# function.
76echo_w() {
77 echo $echo_flags "$@" >&3
78}
79
80# Print a separator to the log file. Intended to be used at the tail end of a pipe
81log_separator() {
82 {
83 echo
84 echo "----------"
85 } >> "$build_log"
86
87 tee -a "$build_log"
88
89 {
90 echo "----------"
91 echo
92 } >> "$build_log"
93}
94
95# Call function $1 if it's defined
96call_func() {
97 if type "${1:?}" &>/dev/null; then
98 echo
99 echo "> ${2:?}:$1()"
100 eval "$1"
101 echo "< $2:$1()"
102 fi
103}
104
Paul Sokolovskybe6510c2024-08-15 21:54:00 +0300105# Retry a command a number of times if it fails. Intended for I/O commands
106# in a CI environment which may be flaky.
107function retry() {
108 for i in $(seq 1 3); do
109 if "$@"; then
110 return 0
111 fi
112 sleep $(( i * 5 ))
113 done
114 return 1
115}
116
Fathi Boudra422bf772019-12-02 11:10:16 +0200117# Call hook $1 in all chosen fragments if it's defined. Hooks are invoked from
118# within a subshell, so any variables set within a hook are lost. Should a
119# variable needs to be set from within a hook, the function 'set_hook_var'
120# should be used
121call_hook() {
122 local func="$1"
123 local config_fragment
124
125 [ -z "$func" ] && return 0
126
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300127 echo "=== Calling hooks: $1 ==="
128
Fathi Boudra422bf772019-12-02 11:10:16 +0200129 : >"$hook_env_file"
130
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +0000131 if [ "$run_config_candidates" ]; then
132 for config_fragment in $run_config_candidates; do
Fathi Boudra422bf772019-12-02 11:10:16 +0200133 (
134 source "$ci_root/run_config/$config_fragment"
135 call_func "$func" "$config_fragment"
136 )
137 done
138 fi
139
140 # Also source test config file
141 (
142 unset "$func"
143 source "$test_config_file"
144 call_func "$func" "$(basename $test_config_file)"
145 )
146
147 # Have any variables set take effect
148 source "$hook_env_file"
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300149
150 echo "=== End calling hooks: $1 ==="
Fathi Boudra422bf772019-12-02 11:10:16 +0200151}
152
153# Set a variable from within a hook
154set_hook_var() {
155 echo "export $1=\"${2?}\"" >> "$hook_env_file"
156}
157
158# Append to an array from within a hook
159append_hook_var() {
160 echo "export $1+=\"${2?}\"" >> "$hook_env_file"
161}
162
163# Have the main build script source a file
164source_later() {
165 echo "source ${1?}" >> "$hook_env_file"
166}
167
168# Setup TF build wrapper function by pointing to a script containing a function
169# that will be called with the TF build commands.
170setup_tf_build_wrapper() {
171 source_later "$ci_root/script/${wrapper?}_wrapper.sh"
172 set_hook_var "tf_build_wrapper" "${wrapper}_wrapper"
173 echo "Setup $wrapper build wrapper."
174}
175
176# Collect .bin files for archiving
177collect_build_artefacts() {
178 if [ ! -d "${from:?}" ]; then
179 return
180 fi
181
Yann Gautier7e9d6cf2023-03-08 14:24:38 +0100182 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 +0200183 echo "You probably are running local CI on local repositories."
184 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
185 die
186 fi
187}
188
189# SCP and MCP binaries are named firmware.{bin,elf}, and are placed under
190# scp/mcp_ramfw and scp/mcp_romfw directories, so can't be collected by
191# collect_build_artefacts function.
192collect_scp_artefacts() {
193 to="${to:?}" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000194 find "$scp_root" \( \( -name "*.bin" -o -name '*.elf' \) -and ! -name 'CMake*' \) -exec bash -c '
Fathi Boudra422bf772019-12-02 11:10:16 +0200195 for file; do
196 ext="$(echo $file | awk -F. "{print \$NF}")"
197 case $file in
Anurag Koulbaedf932021-12-09 12:49:56 +0000198 */firmware-scp_ramfw/bin/*|*/firmware-scp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200199 cp $file $to/scp_ram.$ext
200 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000201 */firmware-scp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200202 cp $file $to/scp_rom.$ext
203 ;;
Anurag Koulbaedf932021-12-09 12:49:56 +0000204 */firmware-mcp_ramfw/bin/*|*/firmware-mcp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200205 cp $file $to/mcp_ram.$ext
206 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000207 */firmware-mcp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200208 cp $file $to/mcp_rom.$ext
209 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000210 */firmware-scp_romfw_bypass/bin/*)
Zelalem219df412020-05-17 19:21:20 -0500211 cp $file $to/scp_rom_bypass.$ext
212 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200213 *)
214 echo "Unknown SCP binary: $file" >&2
215 ;;
216 esac
217 done
218 ' bash '{}' +
219}
220
Manish Pandey1e7be852020-11-09 16:04:48 +0000221# Collect SPM/hafnium artefacts with "secure_" appended to the files
222# generated for SPM(secure hafnium).
223collect_spm_artefacts() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500224 if [ -d "${non_secure_from:?}" ]; then
225 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000226 fi
227
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500228 if [ -d "${secure_from:?}" ]; then
229 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
230 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000231}
232
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200233collect_rfa_artefacts() {
234 if [ ! -d "${from:?}" ]; then
235 return
236 fi
237
238 if ! find "$from" -maxdepth 1 \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +; then
239 echo "You probably are running local CI on local repositories."
240 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
241 die
242 fi
243}
244
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100245# Map the UART ID used for expect with the UART descriptor and port
246# used by the FPGA automation tools.
247map_uart() {
248 local port="${port:?}"
249 local descriptor="${descriptor:?}"
250 local baudrate="${baudrate:?}"
251 local run_root="${archive:?}/run"
252
253 local uart_dir="$run_root/uart${uart:?}"
254 mkdir -p "$uart_dir"
255
256 echo "$port" > "$uart_dir/port"
257 echo "$descriptor" > "$uart_dir/descriptor"
258 echo "$baudrate" > "$uart_dir/baudrate"
259
260 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
261}
262
Fathi Boudra422bf772019-12-02 11:10:16 +0200263# Arrange environment varibles to be set when expect scripts are launched
264set_expect_variable() {
265 local var="${1:?}"
266 local val="${2?}"
267
268 local run_root="${archive:?}/run"
269 local uart_dir="$run_root/uart${uart:?}"
270 mkdir -p "$uart_dir"
271
272 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
273 echo "UART$uart: env has $@"
274}
275
276# Place the binary package a pointer to expect script, and its parameters
277track_expect() {
278 local file="${file:?}"
279 local timeout="${timeout-600}"
280 local run_root="${archive:?}/run"
281
282 local uart_dir="$run_root/uart${uart:?}"
283 mkdir -p "$uart_dir"
284
285 echo "$file" > "$uart_dir/expect"
286 echo "$timeout" > "$uart_dir/timeout"
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700287 if [ -n "$lava_timeout" ]; then
288 set_run_env "lava_timeout" "$lava_timeout"
289 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200290
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700291 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 +0200292
Chris Kayfab6edc2022-11-17 19:18:32 +0000293 if [ ! -z "${port}" ]; then
294 echo "${port}" > "$uart_dir/port"
295 fi
296
Fathi Boudra422bf772019-12-02 11:10:16 +0200297 # The run script assumes UART0 to be primary. If we're asked to set any
298 # other UART to be primary, set a run environment variable to signal
299 # that to the run script
300 if upon "$set_primary"; then
301 echo "Primary UART set to UART$uart."
302 set_run_env "primary_uart" "$uart"
303 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600304
305 # UART used by payload(such as tftf, Linux) may not be the same as the
306 # primary UART. Set a run environment variable to track the payload
307 # UART which is tracked to check if the test has finished sucessfully.
308 if upon "$set_payload_uart"; then
309 echo "Payload uses UART$uart."
310 set_run_env "payload_uart" "$uart"
311 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200312}
313
314# Extract a FIP in $1 using fiptool
315extract_fip() {
316 local fip="$1"
317
318 if is_url "$1"; then
319 url="$1" fetch_file
320 fip="$(basename "$1")"
321 fi
322
323 "$fiptool" unpack "$fip"
324 echo "Extracted FIP: $fip"
325}
326
327# Report build failure by printing a the tail end of build log. Archive the
328# build log for later inspection
329fail_build() {
330 local log_path
331
332 if upon "$jenkins_run"; then
333 log_path="$BUILD_URL/artifact/artefacts/build.log"
334 else
335 log_path="$build_log"
336 fi
337
338 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600339 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200340 echo "[...]"
341 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600342 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200343 echo
344 echo "See $log_path for full output"
345 echo
346 cp -t "$archive" "$build_log"
347 exit 1;
348}
349
350# Build a FIP with supplied arguments
351build_fip() {
352 (
353 echo "Building FIP with arguments: $@"
354 local tf_env="$workspace/tf.env"
355
356 if [ -f "$tf_env" ]; then
357 set -a
358 source "$tf_env"
359 set +a
360 fi
361
362 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
363 ${fip_targets:-fip} &>>"$build_log" || fail_build
364 )
365}
366
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200367# Build any extra rule from TF-A makefile with supplied arguments.
368#
369# This is useful in case you need to build something else than firmware binaries
370# or the FIP.
371build_tf_extra() {
372 (
373 tf_extra_rules=${tf_extra_rules:?}
374 echo "Building extra TF rule(s): $tf_extra_rules"
375 echo " Arguments: $@"
376
377 local tf_env="$workspace/tf.env"
378
379 if [ -f "$tf_env" ]; then
380 set -a
381 source "$tf_env"
382 set +a
383 fi
384
385 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
386 ${tf_extra_rules} &>>"$build_log" || fail_build
387 )
388}
389
Fathi Boudra422bf772019-12-02 11:10:16 +0200390fip_update() {
391 # Before the update process, check if the given image is supported by
392 # the fiptool. It's assumed that both fiptool and cert_create move in
Chris Kay197b1022023-08-16 21:31:41 +0100393 # tandem, and therefore, if one has support, the other has it too.
394 if ! ("$fiptool" update 2>&1 || true) | grep -qe "\s\+--${bin_name:?}"; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200395 return 1
396 fi
397
398 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
399 echo "Updating FIP image: $bin_name"
400 # Update HW config. Without TBBR, it's only a matter of using
401 # the update sub-command of fiptool
402 "$fiptool" update "--$bin_name" "${src:-}" \
403 "$archive/fip.bin"
404 else
405 echo "Updating FIP image (TBBR): $bin_name"
406 # With TBBR, we need to unpack, re-create certificates, and then
407 # recreate the FIP.
408 local fip_dir="$(mktempdir)"
409 local bin common_args stem
410 local rot_key="$(get_tf_opt ROT_KEY)"
411
412 rot_key="${rot_key:?}"
413 if ! is_abs "$rot_key"; then
414 rot_key="$tf_root/$rot_key"
415 fi
416
417 # Arguments only for cert_create
418 local cert_args="-n"
419 cert_args+=" --tfw-nvctr ${nvctr:-31}"
420 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
421 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
422 cert_args+=" --rot-key $rot_key"
423
424 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500425 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200426 "hw-config"
427 "tb-fw-config"
428 "nt-fw-config"
429 "soc-fw-config"
430 "tos-fw-config"
431 )
432
433 # Binaries without key certificates
434 declare -A has_no_key_cert
435 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
436 has_no_key_cert["$bin"]="1"
437 done
438
439 # Binaries without certificates
440 declare -A has_no_cert
441 for bin in "hw-config" "${dyn_config_opts[@]}"; do
442 has_no_cert["$bin"]="1"
443 done
444
445 pushd "$fip_dir"
446
447 # Unpack FIP
448 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
449
450 # Remove all existing certificates
451 rm -f *-cert.bin
452
453 # Copy the binary to be updated
454 cp -f "$src" "${bin_name}.bin"
455
456 # FIP unpack dumps binaries with the same name as the option
457 # used to pack it; likewise for certificates. Reverse-engineer
458 # the command line from the binary output.
459 common_args="--trusted-key-cert trusted_key.crt"
460 for bin in *.bin; do
461 stem="${bin%%.bin}"
462 common_args+=" --$stem $bin"
463 if not_upon "${has_no_cert[$stem]}"; then
464 common_args+=" --$stem-cert $stem.crt"
465 fi
466 if not_upon "${has_no_key_cert[$stem]}"; then
467 common_args+=" --$stem-key-cert $stem-key.crt"
468 fi
469 done
470
471 # Create certificates
472 "$cert_create" $cert_args $common_args &>>"$build_log"
473
474 # Recreate and archive FIP
475 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
476 archive_file "fip.bin"
477
478 popd
479 fi
480}
481
482# Update hw-config in FIP, and remove the original DTB afterwards.
483update_fip_hw_config() {
484 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600485 # in configs:
486 # 1. Where BL2 isn't present
487 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200488 case "1" in
489 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600490 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200491 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000492 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200493 return 0;;
494 esac
495
496 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
497 # Remove the DTB so that model won't load it
498 rm -f "$archive/dtb.bin"
499 fi
500}
501
502get_scp_opt() {
503 (
504 name="${1:?}"
505 if config_valid "$scp_config_file"; then
506 source "$scp_config_file"
507 echo "${!name}"
508 fi
509 )
510}
511
512get_tftf_opt() {
513 (
514 name="${1:?}"
515 if config_valid "$tftf_config_file"; then
516 source "$tftf_config_file"
517 echo "${!name}"
518 fi
519 )
520}
521
522get_tf_opt() {
523 (
524 name="${1:?}"
525 if config_valid "$tf_config_file"; then
526 source "$tf_config_file"
527 echo "${!name}"
528 fi
529 )
530}
531
Tomás González866b23a2025-07-22 11:05:57 +0100532get_rfa_opt() {
533 (
534 name="${1:?}"
535 if config_valid "$rfa_config_file"; then
536 source "$rfa_config_file"
537 echo "${!name}"
538 fi
539 )
540}
541
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000542get_rmm_opt() {
543 (
544 name="${1:?}"
545 if config_valid "$rmm_config_file"; then
546 source "$rmm_config_file"
547 echo "${!name}"
548 fi
549 )
550}
551
Fathi Boudra422bf772019-12-02 11:10:16 +0200552build_tf() {
553 (
554 env_file="$workspace/tf.env"
555 config_file="${tf_build_config:-$tf_config_file}"
556
557 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100558 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200559
560 source "$config_file"
561
562 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000563 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100564 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
565 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200566 mbedtls_dir="$workspace/mbedtls"
567 if [ ! -d "$mbedtls_dir" ]; then
568 mbedtls_ar="$workspace/mbedtls.tar.gz"
569
570 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
571 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500572 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200573 fi
574
575 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
576 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500577 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
578 not_upon "${TF_M_TESTS_PATH}"; then
579 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
580 fi
581 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
582 not_upon "${TF_M_EXTRAS_PATH}"; then
583 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
584 fi
David Vincze82db6932024-02-21 12:05:50 +0100585 if [ "$(get_tf_opt DICE_PROTECTION_ENVIRONMENT)" = 1 ] &&
586 not_upon "${QCBOR_DIR}"; then
587 emit_env "QCBOR_DIR" "$WORKSPACE/qcbor"
588 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200589 if [ -f "$env_file" ]; then
590 set -a
591 source "$env_file"
592 set +a
593 fi
594
Harrison Mutai013f6332022-02-16 16:06:33 +0000595 if is_arm_jenkins_env || upon "$local_ci"; then
596 path_list=(
597 "$llvm_dir/bin"
598 )
599 extend_path "PATH" "path_list"
600 fi
601
Fathi Boudra422bf772019-12-02 11:10:16 +0200602 cd "$tf_root"
603
604 # Always distclean when running on Jenkins. Skip distclean when running
605 # locally and explicitly requested.
606 if upon "$jenkins_run" || not_upon "$dont_clean"; then
607 make distclean &>>"$build_log" || fail_build
608 fi
609
610 # Log build command line. It is left unfolded on purpose to assist
611 # copying to clipboard.
612 cat <<EOF | log_separator >/dev/null
613
614Build command line:
615 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
616
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300617CC version:
618$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200619EOF
620
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000621 if not_upon "$local_ci"; then
622 connect_debugger=0
623 fi
624
Fathi Boudra422bf772019-12-02 11:10:16 +0200625 # Build TF. Since build output is being directed to the build log, have
626 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000627 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000628 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200629 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100630
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100631 if [ "$build_targets" != "doc" ]; then
Harrison Mutai2c2c9172024-04-12 11:24:27 +0000632 (poetry run memory -sr "$tf_build_root" 2>&1 || true) | tee -a "$build_log"
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100633 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200634 )
635}
636
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200637build_rfa() {
638 (
Tomás González866b23a2025-07-22 11:05:57 +0100639 config_file="${rfa_build_config:-$rfa_config_file}"
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200640
641 # Build the 'all' target by default.
Tomás González866b23a2025-07-22 11:05:57 +0100642 build_targets="${rfa_build_targets:-all}"
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200643
644 source "$config_file"
645
Tomás González866b23a2025-07-22 11:05:57 +0100646 cd "$rfa_root"
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200647
648 # Always distclean when running on Jenkins. Skip distclean when running
649 # locally and explicitly requested.
650 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200651 echo 'Cleaning RF-A...'
652 cargo clean &>>"$build_log" || fail_build
653 fi
654
655 # Log build command line. It is left unfolded on purpose to assist
656 # copying to clipboard.
657 cat <<EOF | log_separator >/dev/null
658
659Build command line:
660 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG $build_targets
661
662cargo version:
663$(cargo --version 2>&1)
664EOF
665
Tomás Gonzálezb304e212025-07-28 13:39:30 +0100666 # Build RF-A. Since build output is being directed to the build log, have
667 # descriptor 3 point to the current terminal for build wrappers to vent.
Tomás González72aca672025-06-11 11:26:00 +0100668 eval make $make_j_opts $(cat "$config_file") \
669 DEBUG="$DEBUG" \
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200670 $build_targets 3>&1 &>>"$build_log" || fail_build
671 )
672}
673
Fathi Boudra422bf772019-12-02 11:10:16 +0200674build_tftf() {
675 (
676 config_file="${tftf_build_config:-$tftf_config_file}"
677
678 # Build tftf target by default
679 build_targets="${tftf_build_targets:-all}"
680
681 source "$config_file"
682
683 cd "$tftf_root"
684
685 # Always distclean when running on Jenkins. Skip distclean when running
686 # locally and explicitly requested.
687 if upon "$jenkins_run" || not_upon "$dont_clean"; then
688 make distclean &>>"$build_log" || fail_build
689 fi
690
691 # TFTF build system cannot reliably deal with -j option, so we avoid
692 # using that.
693
694 # Log build command line
695 cat <<EOF | log_separator >/dev/null
696
697Build command line:
Boyan Karatotev51060ba2024-10-29 16:55:10 +0000698 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
Fathi Boudra422bf772019-12-02 11:10:16 +0200699
700EOF
701
Boyan Karatotev51060ba2024-10-29 16:55:10 +0000702 make $make_j_opts $(cat "$config_file") DEBUG="$DEBUG" V=1 \
Fathi Boudra422bf772019-12-02 11:10:16 +0200703 $build_targets &>>"$build_log" || fail_build
704 )
705}
706
707build_scp() {
708 (
709 config_file="${scp_build_config:-$scp_config_file}"
710
711 source "$config_file"
712
713 cd "$scp_root"
714
715 # Always distclean when running on Jenkins. Skip distclean when running
716 # locally and explicitly requested.
717 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000718 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200719 fi
720
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000721 python3 -m venv .venv
722 . .venv/bin/activate
723
724 # Install extra tools used by CMake build system
725 pip install -r requirements.txt --timeout 30 --retries 15
726
Fathi Boudra422bf772019-12-02 11:10:16 +0200727 # Log build command line. It is left unfolded on purpose to assist
728 # copying to clipboard.
729 cat <<EOF | log_separator >/dev/null
730
731SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000732 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
733 TOOLCHAIN=GNU \
734 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000735 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000736 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200737
738EOF
739
740 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000741 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
742 TOOLCHAIN=GNU \
743 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000744 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000745 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200746 || fail_build
747 )
748}
749
Zelalem219df412020-05-17 19:21:20 -0500750clone_scp_tools() {
751
752 if [ ! -d "$scp_tools_root" ]; then
753 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
754
755 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
756 where="$scp_tools_root" \
757 refspec="${scp_tools_commit}"
758 clone_repo &>>"$build_log"
759 else
760 echo "Already cloned SCP-tools ..." |& log_separator
761 fi
762
763 show_head "$scp_tools_root"
764
765 cd "$scp_tools_root"
766
767 echo "Updating submodules"
768
769 git submodule init
770
771 git submodule update
772
Nicola Mazzucato9b171422023-08-29 15:50:49 +0100773 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 +0000774
Zelalem219df412020-05-17 19:21:20 -0500775 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000776 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500777
778 git show --quiet --no-color | sed 's/^/ > /g'
779}
780
781clone_tf_for_scp_tools() {
782 scp_tools_arm_tf="$scp_tools_root/arm-tf"
783
784 if [ ! -d "$scp_tools_arm_tf" ]; then
785 echo "Cloning TF-4-SCP-tools ..." |& log_separator
786
787 clone_url="$tf_for_scp_tools_src_repo_url"
788 where="$scp_tools_arm_tf"
789
790 git clone "$clone_url" "$where"
791
792 cd "$scp_tools_arm_tf"
793
Joel Goddard3ad03062021-03-16 16:47:42 +0000794 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500795
796 git show --quiet --no-color | sed 's/^/ > /g'
797
798 else
799 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
800 fi
801}
802
803build_scmi_lib_scp_tools() {
804 (
805 cd "$scp_tools_root"
806
807 cd "scmi"
808
809 scp_tools_arm_tf="$scp_tools_root/arm-tf"
810
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600811 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500812
813 std_libs="-I$scp_tools_arm_tf/include/common"
814 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
815 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
816 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
817 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
818 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
819 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
820 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
821 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
822 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
823 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
824 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
825 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
826 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
827
828 cflags="-Og -g"
829 cflags="$cflags -mgeneral-regs-only"
830 cflags="$cflags -mstrict-align"
831 cflags="$cflags -nostdinc"
832 cflags="$cflags -fno-inline"
833 cflags="$cflags -ffreestanding"
834 cflags="$cflags -ffunction-sections"
835 cflags="$cflags -fdata-sections"
836 cflags="$cflags -DAARCH64"
837 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000838 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500839
840 cflags="$cflags $std_libs"
841
Joel Goddard3ad03062021-03-16 16:47:42 +0000842 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500843
844 echo "Building SCMI library (SCP-tools) ..."
845
846 make "CROSS_COMPILE=$cross_compile" \
847 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000848 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500849 "PROTOCOLS=$protocols" \
850 "clean" \
851 "all"
852 )
853}
854
855build_tf_for_scp_tools() {
856
857 cd "$scp_tools_root/arm-tf"
858
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600859 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500860
861 if [ "$1" = "release" ]; then
862 echo "Build TF-4-SCP-Tools rls..."
863 else
864 echo "Build TF-4-SCP-Tools dbg..."
865
866 make realclean
867
868 make "BM_TEST=scmi" \
869 "ARM_BOARD_OPTIMISE_MEM=1" \
870 "BM_CSS=juno" \
871 "CSS_USE_SCMI_SDS_DRIVER=1" \
872 "PLAT=juno" \
873 "DEBUG=1" \
874 "PLATFORM=juno" \
875 "CROSS_COMPILE=$cross_compile" \
876 "BM_WORKSPACE=$scp_tools_root/baremetal"
877
878 archive_file "build/juno/debug/bl1.bin"
879
880 archive_file "build/juno/debug/bl2.bin"
881
882 archive_file "build/juno/debug/bl31.bin"
883 fi
884}
885
886build_fip_for_scp_tools() {
887
888 cd "$scp_tools_root/arm-tf"
889
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600890 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500891
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000892 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500893 make fiptool
894 echo "Make FIP 4 SCP-Tools rls..."
895
896 else
897 make fiptool
898 echo "Make FIP 4 SCP-Tools dbg..."
899
900 make "PLAT=juno" \
901 "all" \
902 "fip" \
903 "DEBUG=1" \
904 "CROSS_COMPILE=$cross_compile" \
905 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
906 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000907 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500908
909 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
910 fi
911}
912
913build_cc() {
914# Building code coverage plugin
915 ARM_DIR=/arm
916 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
917 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
918 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
919 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
920 exit -1
921 fi # Error if arm warehouse not found
922 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
923
924 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
925}
926
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100927build_spm() {
928 (
929 env_file="$workspace/spm.env"
930 config_file="${spm_build_config:-$spm_config_file}"
931
932 source "$config_file"
933
934 if [ -f "$env_file" ]; then
935 set -a
936 source "$env_file"
937 set +a
938 fi
939
940 cd "$spm_root"
941
942 # Always clean when running on Jenkins. Skip clean when running
943 # locally and explicitly requested.
944 if upon "$jenkins_run" || not_upon "$dont_clean"; then
945 # make clean fails on a fresh repo where the project has not
946 # yet been built. Hence only clean if out/reference directory
947 # already exists.
948 if [ -d "out/reference" ]; then
949 make clean &>>"$build_log" || fail_build
950 fi
951 fi
952
953 # Log build command line. It is left unfolded on purpose to assist
954 # copying to clipboard.
955 cat <<EOF | log_separator >/dev/null
956
957Build command line:
958 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
959
960EOF
961
962 # Build SPM. Since build output is being directed to the build log, have
963 # descriptor 3 point to the current terminal for build wrappers to vent.
964 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
965 || fail_build
966 )
967}
Zelalem219df412020-05-17 19:21:20 -0500968
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000969build_rmm() {
970 (
971 env_file="$workspace/rmm.env"
972 config_file="${rmm_build_config:-$rmm_config_file}"
973
974 # Build fiptool and all targets by default
975 build_targets="${rmm_build_targets}"
976 export CROSS_COMPILE="${aarch64_none_elf_prefix}"
977
978 source "$config_file"
979
980 if [ -f "$env_file" ]; then
981 set -a
982 source "$env_file"
983 set +a
984 fi
985
986 cd "$rmm_root"
987
988 if [ -f "$rmm_root/requirements.txt" ]; then
989 export PATH="$HOME/.local/bin:$PATH"
990 python3 -m pip install --upgrade pip
991 python3 -m pip install -r "$rmm_root/requirements.txt"
992 fi
993
994 # Always distclean when running on Jenkins. Skip distclean when running
995 # locally and explicitly requested.
996 if upon "$jenkins_run" || not_upon "$dont_clean"; then
997 # Remove 'rmm\build' folder
998 echo "Removing $rmm_build_root..."
999 rm -rf $rmm_build_root
1000 fi
1001
1002 # Log build command line. It is left unfolded on purpose to assist
1003 # copying to clipboard.
1004 cat <<EOF | log_separator >/dev/null
1005
1006Build command line:
1007 cmake -DRMM_CONFIG=${plat}_defcfg $cmake_gen -S $rmm_root -B $rmm_build_root -DCMAKE_BUILD_TYPE=$cmake_build_type
1008 cmake --build $rmm_build_root $make_j_opts -v
1009EOF
1010 if not_upon "$local_ci"; then
1011 connect_debugger=0
1012 fi
1013
1014 cmake -DRMM_CONFIG=${plat}_defcfg $cmake_gen -S $rmm_root -B $rmm_build_root -DCMAKE_BUILD_TYPE=$cmake_build_type
1015 cmake --build $rmm_build_root $make_j_opts -v 3>&1 &>>"$build_log" || fail_build
1016 )
1017}
1018
Fathi Boudra422bf772019-12-02 11:10:16 +02001019# Set metadata for the whole package so that it can be used by both Jenkins and
1020# shell
1021set_package_var() {
1022 env_file="$artefacts/env" emit_env "$@"
1023}
1024
1025set_tf_build_targets() {
1026 echo "Set build target to '${targets:?}'"
1027 set_hook_var "tf_build_targets" "$targets"
1028}
1029
Tomás González866b23a2025-07-22 11:05:57 +01001030set_rfa_build_targets() {
1031 echo "Set build target to '${targets:?}'"
1032 set_hook_var "rfa_build_targets" "$targets"
1033}
1034
Fathi Boudra422bf772019-12-02 11:10:16 +02001035set_tftf_build_targets() {
1036 echo "Set build target to '${targets:?}'"
1037 set_hook_var "tftf_build_targets" "$targets"
1038}
1039
1040set_scp_build_targets() {
1041 echo "Set build target to '${targets:?}'"
1042 set_hook_var "scp_build_targets" "$targets"
1043}
1044
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001045set_spm_build_targets() {
1046 echo "Set build target to '${targets:?}'"
1047 set_hook_var "spm_build_targets" "$targets"
1048}
1049
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001050set_spm_out_dir() {
1051 echo "Set SPMC binary build to '${out_dir:?}'"
1052 set_hook_var "spm_secure_out_dir" "$out_dir"
1053}
Fathi Boudra422bf772019-12-02 11:10:16 +02001054# Look under $archive directory for known files such as blX images, kernel, DTB,
1055# initrd etc. For each known file foo, if foo.bin exists, then set variable
1056# foo_bin to the path of the file. Make the path relative to the workspace so as
1057# to remove any @ characters, which Jenkins inserts for parallel runs. If the
1058# file doesn't exist, unset its path.
1059set_default_bin_paths() {
1060 local image image_name image_path path
1061 local archive="${archive:?}"
1062 local set_vars
1063 local var
1064
1065 pushd "$archive"
1066
1067 for file in *.bin; do
1068 # Get a shell variable from the file's stem
1069 var_name="${file%%.*}_bin"
1070 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
1071
1072 # Skip setting the variable if it's already
1073 if [ "${!var_name}" ]; then
1074 echo "Note: not setting $var_name; already set to ${!var_name}"
1075 continue
1076 else
1077 set_vars+="$var_name "
1078 fi
1079
1080 eval "$var_name=$file"
1081 done
1082
1083 echo "Binary paths set for: "
1084 {
1085 for var in $set_vars; do
1086 echo -n "\$$var "
1087 done
1088 } | fmt -80 | sed 's/^/ /'
1089 echo
1090
1091 popd
1092}
1093
1094gen_model_params() {
1095 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +00001096 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +02001097
1098 set_default_bin_paths
1099 echo "Generating model parameter for $model..."
1100 source "$ci_root/model/${model:?}.sh"
1101 archive_file "$model_param_file"
1102}
1103
1104set_model_path() {
1105 set_run_env "model_path" "${1:?}"
1106}
1107
Zelalem1af7a7b2020-08-04 17:34:32 -05001108set_model_env() {
1109 local var="${1:?}"
1110 local val="${2?}"
1111 local run_root="${archive:?}/run"
1112
1113 mkdir -p "$run_root"
1114 echo "export $var=$val" >> "$run_root/model_env"
1115}
Fathi Boudra422bf772019-12-02 11:10:16 +02001116set_run_env() {
1117 local var="${1:?}"
1118 local val="${2?}"
1119 local run_root="${archive:?}/run"
1120
1121 mkdir -p "$run_root"
1122 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
1123}
1124
1125show_head() {
1126 # Display HEAD descripton
1127 pushd "$1"
1128 git show --quiet --no-color | sed 's/^/ > /g'
1129 echo
1130 popd
1131}
1132
1133# Choose debug binaries to run; by default, release binaries are chosen to run
1134use_debug_bins() {
1135 local run_root="${archive:?}/run"
1136
1137 echo "Choosing debug binaries for execution"
1138 set_package_var "BIN_MODE" "debug"
1139}
1140
1141assert_can_git_clone() {
1142 local name="${1:?}"
1143 local dir="${!name}"
1144
1145 # If it doesn't exist, it can be cloned into
1146 if [ ! -e "$dir" ]; then
1147 return 0
1148 fi
1149
1150 # If it's a directory, it must be a Git clone already
1151 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
1152 # No need to clone again
1153 echo "Using existing git clone for $name: $dir"
1154 return 1
1155 fi
1156
1157 die "Path $dir exists but is not a git clone"
1158}
1159
1160clone_repo() {
1161 if ! is_url "${clone_url?}"; then
1162 # For --depth to take effect on local paths, it needs to use the
1163 # file:// scheme.
1164 clone_url="file://$clone_url"
1165 fi
1166
1167 git clone -q --depth 1 "$clone_url" "${where?}"
1168 if [ "$refspec" ]; then
1169 pushd "$where"
1170 git fetch -q --depth 1 origin "$refspec"
1171 git checkout -q FETCH_HEAD
1172 popd
1173 fi
1174}
1175
1176build_unstable() {
1177 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1178}
1179
1180undo_patch_record() {
1181 if [ ! -f "${patch_record:?}" ]; then
1182 return
1183 fi
1184
1185 # Undo patches in reverse
1186 echo
1187 for patch_name in $(tac "$patch_record"); do
1188 echo "Undoing $patch_name..."
1189 if ! git apply -R "$ci_root/patch/$patch_name"; then
1190 if upon "$local_ci"; then
1191 echo
1192 echo "Your local directory may have been dirtied."
1193 echo
1194 fi
1195 fail_build
1196 fi
1197 done
1198
1199 rm -f "$patch_record"
1200}
1201
1202undo_local_patches() {
1203 pushd "$tf_root"
1204 patch_record="$tf_patch_record" undo_patch_record
1205 popd
1206
1207 if [ -d "$tftf_root" ]; then
1208 pushd "$tftf_root"
1209 patch_record="$tftf_patch_record" undo_patch_record
1210 popd
1211 fi
1212}
1213
1214undo_tftf_patches() {
1215 pushd "$tftf_root"
1216 patch_record="$tftf_patch_record" undo_patch_record
1217 popd
1218}
1219
1220undo_tf_patches() {
1221 pushd "$tf_root"
1222 patch_record="$tf_patch_record" undo_patch_record
1223 popd
1224}
1225
1226apply_patch() {
1227 # If skip_patches is set, the developer has applied required patches
1228 # manually. They probably want to keep them applied for debugging
1229 # purposes too. This means we don't have to apply/revert them as part of
1230 # build process.
1231 if upon "$skip_patches"; then
1232 echo "Skipped applying ${1:?}..."
1233 return 0
1234 else
1235 echo "Applying ${1:?}..."
1236 fi
1237
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +02001238 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001239 echo "Skipping already applied ${1:?}"
1240 return 0
1241 fi
1242
Fathi Boudra422bf772019-12-02 11:10:16 +02001243 if git apply < "$ci_root/patch/$1"; then
1244 echo "$1" >> "${patch_record:?}"
1245 else
1246 if upon "$local_ci"; then
1247 undo_local_patches
1248 fi
1249 fail_build
1250 fi
1251}
1252
1253apply_tftf_patch() {
1254 pushd "$tftf_root"
1255 patch_record="$tftf_patch_record" apply_patch "$1"
1256 popd
1257}
1258
1259apply_tf_patch() {
1260 pushd "$tf_root"
1261 patch_record="$tf_patch_record" apply_patch "$1"
1262 popd
1263}
1264
1265# Clear workspace for a local run
Leandro Bellibe7b8fa2024-07-18 10:14:22 +01001266if not_upon "$jenkins_run" && not_upon "$dont_clean"; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001267 rm -rf "$workspace"
1268
1269 # Clear residue from previous runs
1270 rm -rf "$archive"
1271fi
1272
1273mkdir -p "$workspace"
1274mkdir -p "$archive"
1275set_package_var "TEST_CONFIG" "$test_config"
1276
1277{
1278echo
1279echo "CONFIGURATION: $test_group/$test_config"
1280echo
1281} |& log_separator
1282
1283tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1284tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1285scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001286scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001287spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001288rmm_config="$(echo "$build_configs" | awk -F, '{print $6}')"
Tomás Gonzálezfa3e24b2025-07-22 10:59:06 +01001289rfa_config="$(echo "$build_configs" | awk -F, '{print $7}')"
1290
Fathi Boudra422bf772019-12-02 11:10:16 +02001291
1292test_config_file="$ci_root/group/$test_group/$test_config"
1293
1294tf_config_file="$ci_root/tf_config/$tf_config"
1295tftf_config_file="$ci_root/tftf_config/$tftf_config"
1296scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001297scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001298spm_config_file="$ci_root/spm_config/$spm_config"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001299rmm_config_file="$ci_root/rmm_config/$rmm_config"
Tomás González866b23a2025-07-22 11:05:57 +01001300rfa_config_file="$ci_root/rfa_config/$rfa_config"
1301
Fathi Boudra422bf772019-12-02 11:10:16 +02001302
1303# File that keeps track of applied patches
1304tf_patch_record="$workspace/tf_patches"
1305tftf_patch_record="$workspace/tftf_patches"
Tomás González866b23a2025-07-22 11:05:57 +01001306rfa_patch_record="$workspace/rfa_patches"
Fathi Boudra422bf772019-12-02 11:10:16 +02001307
1308pushd "$workspace"
1309
1310if ! config_valid "$tf_config"; then
1311 tf_config=
1312else
1313 echo "Trusted Firmware config:"
1314 echo
1315 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1316 echo
1317fi
1318
Tomás González866b23a2025-07-22 11:05:57 +01001319if ! config_valid "$rfa_config"; then
1320 rfa_config=
1321else
1322 echo "RF-A config:"
1323 echo
1324 sort "$rfa_config_file" | sed '/^\s*$/d;s/^/\t/'
1325 echo
1326fi
1327
Fathi Boudra422bf772019-12-02 11:10:16 +02001328if ! config_valid "$tftf_config"; then
1329 tftf_config=
1330else
1331 echo "Trusted Firmware TF config:"
1332 echo
1333 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1334 echo
1335fi
1336
1337if ! config_valid "$scp_config"; then
1338 scp_config=
1339else
1340 echo "SCP firmware config:"
1341 echo
1342 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1343 echo
1344fi
1345
Zelalem219df412020-05-17 19:21:20 -05001346if ! config_valid "$scp_tools_config"; then
1347 scp_tools_config=
1348else
1349 echo "SCP Tools config:"
1350 echo
1351 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001352fi
1353
1354if ! config_valid "$spm_config"; then
1355 spm_config=
1356else
1357 echo "SPM config:"
1358 echo
1359 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001360 echo
1361fi
1362
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001363# File that keeps track of applied patches
1364rmm_patch_record="$workspace/rmm_patches"
1365
1366if ! config_valid "$rmm_config"; then
1367 rmm_config=
1368else
1369 echo "Trusted Firmware RMM config:"
1370 echo
1371 sort "$rmm_config_file" | sed '/^\s*$/d;s/^/\t/'
1372 echo
1373fi
1374
Fathi Boudra422bf772019-12-02 11:10:16 +02001375if ! config_valid "$run_config"; then
1376 run_config=
1377fi
1378
1379if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1380 # If the Trusted Firmware repository has already been checked out, use
1381 # that location. Otherwise, clone one ourselves.
1382 echo "Cloning Trusted Firmware..."
1383 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1384 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1385 show_head "$tf_root"
1386fi
1387
Tomás González866b23a2025-07-22 11:05:57 +01001388if [ "$rfa_config" ] && assert_can_git_clone "rfa_root"; then
1389 # If the Rusted Firmware repository has already been checked out, use
1390 # that location. Otherwise, clone one ourselves.
1391 echo "Cloning Rusted Firmware..."
1392
1393 clone_url="${RFA_CHECKOUT_LOC:-$rfa_src_repo_url}" where="$rfa_root" \
1394 refspec="$RFA_REFSPEC" clone_repo &>>"$build_log"
1395 show_head "$rfa_root"
1396fi
1397
Fathi Boudra422bf772019-12-02 11:10:16 +02001398if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1399 # If the Trusted Firmware TF repository has already been checked out,
1400 # use that location. Otherwise, clone one ourselves.
1401 echo "Cloning Trusted Firmware TF..."
1402 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1403 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1404 show_head "$tftf_root"
1405fi
1406
1407if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1408 # If the SCP firmware repository has already been checked out,
1409 # use that location. Otherwise, clone one ourselves.
1410 echo "Cloning SCP Firmware..."
1411 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1412 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1413
1414 pushd "$scp_root"
1415
1416 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001417 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001418 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1419 fi
1420
1421 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1422 # then to project filer if accessible.
1423 if [ -z "$cmsis_reference" ]; then
1424 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1425 if [ -d "$cmsis_ref_repo" ]; then
1426 cmsis_reference="--reference $cmsis_ref_repo"
1427 fi
1428 fi
1429
1430 git submodule -q update $cmsis_reference --init
1431
1432 popd
1433
1434 show_head "$scp_root"
1435fi
1436
Zelalem219df412020-05-17 19:21:20 -05001437if [ -n "$cc_config" ] ; then
1438 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1439 # Copy code coverage repository
1440 echo "Cloning Code Coverage..."
1441 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1442 show_head "$cc_root"
1443 fi
1444fi
1445
Daniel Boulby25385ab2023-12-14 14:36:25 +00001446if [ "$spm_config" ] ; then
1447 if assert_can_git_clone "spm_root"; then
1448 # If the SPM repository has already been checked out, use
1449 # that location. Otherwise, clone one ourselves.
1450 echo "Cloning SPM..."
1451 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1452 where="$spm_root" refspec="$SPM_REFSPEC" \
1453 clone_repo &>>"$build_log"
1454 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001455
1456 # Query git submodules
1457 pushd "$spm_root"
Daniel Boulby25385ab2023-12-14 14:36:25 +00001458 # Check if submodules need initialising
Paul Sokolovskyad274422024-09-01 10:27:56 +03001459
1460 # This handling is needed to reliably fetch submodules
1461 # in CI environment.
1462 for subm in $(git submodule status | awk '/^-/ {print $2}'); do
1463 for i in $(seq 1 7); do
1464 git submodule init $subm
1465 if git submodule update $subm; then
1466 break
1467 fi
1468 git submodule deinit --force $subm
1469 echo "Retrying $subm"
1470 sleep $((RANDOM % 10 + 5))
1471 done
1472 done
1473
1474 git submodule status
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001475 popd
1476
1477 show_head "$spm_root"
1478fi
1479
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001480if [ "$rmm_config" ] && assert_can_git_clone "rmm_root"; then
Manish V Badarkhe41909452025-04-11 12:06:45 +01001481 # If the RMM repository has already been checked out,
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001482 # use that location. Otherwise, clone one ourselves.
1483 echo "Cloning TF-RMM..."
1484 clone_url="${RMM_CHECKOUT_LOC:-$rmm_src_repo_url}" where="$rmm_root" \
1485 refspec="$RMM_REFSPEC" clone_repo &>>"$build_log"
1486 show_head "$rmm_root"
1487fi
1488
Fathi Boudra422bf772019-12-02 11:10:16 +02001489if [ "$run_config" ]; then
1490 # Get candidates for run config
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001491 run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \
Fathi Boudra422bf772019-12-02 11:10:16 +02001492 "$run_config")"
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001493 if [ -z "$run_config_candidates" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001494 die "No run config candidates!"
1495 else
1496 echo
1497 echo "Chosen fragments:"
1498 echo
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001499 echo "$run_config_candidates" | sed 's/^\|\n/\t/g'
Fathi Boudra422bf772019-12-02 11:10:16 +02001500 echo
Harrison Mutai4dfe1192024-07-03 12:35:38 +00001501
1502 if [ ! -n "$bin_mode" ]; then
1503 if echo $run_config_candidates | grep -wq "debug"; then
1504 bin_mode="debug"
1505 else
1506 bin_mode="release"
1507 fi
1508 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001509 fi
1510fi
1511
1512call_hook "test_setup"
1513echo
1514
1515if upon "$local_ci"; then
1516 # For local runs, since each config is tried in sequence, it's
1517 # advantageous to run jobs in parallel
1518 if [ "$make_j" ]; then
1519 make_j_opts="-j $make_j"
1520 else
1521 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1522 if [ "$n_cores" ]; then
1523 make_j_opts="-j $n_cores"
1524 fi
1525 fi
1526fi
1527
Harrison Mutai07043e92023-07-06 09:41:12 +01001528# Install python build dependencies
1529if is_arm_jenkins_env; then
1530 source "$ci_root/script/install_python_deps.sh"
1531fi
1532
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001533# Print CMake version
1534cmake_ver=$(echo `cmake --version | sed -n '1p'`)
1535echo "Using $cmake_ver"
1536
1537# Check for Ninja
1538if [ -x "$(command -v ninja)" ]; then
1539 # Print Ninja version
1540 ninja_ver=$(echo `ninja --version | sed -n '1p'`)
1541 echo "Using ninja $ninja_ver"
1542 export cmake_gen="-G Ninja"
1543else
1544 echo 'Ninja is not installed'
1545 export cmake_gen=""
1546fi
1547
1548undo_rmm_patches() {
1549 pushd "$rmm_root"
1550 patch_record="$rmm_patch_record" undo_patch_record
1551 popd
1552}
1553
Fathi Boudra422bf772019-12-02 11:10:16 +02001554modes="${bin_mode:-debug release}"
1555for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001556 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001557 # Build with a temporary archive
1558 build_archive="$archive/$mode"
1559 mkdir "$build_archive"
1560
1561 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001562 export bin_mode="debug"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001563 cmake_build_type="Debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001564 DEBUG=1
1565 else
Zelalem219df412020-05-17 19:21:20 -05001566 export bin_mode="release"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001567 cmake_build_type="Release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001568 DEBUG=0
1569 fi
1570
1571 # Perform builds in a subshell so as not to pollute the current and
1572 # subsequent builds' environment
1573
Zelalem219df412020-05-17 19:21:20 -05001574 if config_valid "$cc_config"; then
1575 # Build code coverage plugin
1576 build_cc
1577 fi
1578
Fathi Boudra422bf772019-12-02 11:10:16 +02001579 # SCP build
1580 if config_valid "$scp_config"; then
1581 (
1582 echo "##########"
1583
1584 # Source platform-specific utilities
1585 plat="$(get_scp_opt PRODUCT)"
1586 plat_utils="$ci_root/${plat}_utils.sh"
1587 if [ -f "$plat_utils" ]; then
1588 source "$plat_utils"
1589 fi
1590
1591 archive="$build_archive"
1592 scp_build_root="$scp_root/build"
1593
1594 echo "Building SCP Firmware ($mode) ..." |& log_separator
1595
1596 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001597 to="$archive" collect_scp_artefacts
1598
1599 echo "##########"
1600 echo
1601 )
1602 fi
1603
Zelalem219df412020-05-17 19:21:20 -05001604 # SCP-tools build
1605 if config_valid "$scp_tools_config"; then
1606 (
1607 echo "##########"
1608
1609 archive="$build_archive"
1610 scp_tools_build_root="$scp_tools_root/build"
1611
1612 clone_scp_tools
1613
1614 echo "##########"
1615 echo
1616
1617 echo "##########"
1618 clone_tf_for_scp_tools
1619 echo "##########"
1620 echo
1621 )
1622 fi
1623
Fathi Boudra422bf772019-12-02 11:10:16 +02001624 # TFTF build
1625 if config_valid "$tftf_config"; then
1626 (
1627 echo "##########"
1628
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001629 plat_utils="$(get_tf_opt PLAT_UTILS)"
1630 if [ -z ${plat_utils} ]; then
1631 # Source platform-specific utilities.
1632 plat="$(get_tftf_opt PLAT)"
1633 plat_utils="$ci_root/${plat}_utils.sh"
1634 else
1635 # Source platform-specific utilities by
1636 # using plat_utils name.
1637 plat_utils="$ci_root/${plat_utils}.sh"
1638 fi
1639
Fathi Boudra422bf772019-12-02 11:10:16 +02001640 if [ -f "$plat_utils" ]; then
1641 source "$plat_utils"
1642 fi
1643
1644 archive="$build_archive"
1645 tftf_build_root="$tftf_root/build"
1646
1647 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1648
1649 # Call pre-build hook
1650 call_hook pre_tftf_build
1651
1652 build_tftf
1653
1654 from="$tftf_build_root" to="$archive" collect_build_artefacts
1655
1656 # Clear any local changes made by applied patches
1657 undo_tftf_patches
1658
1659 echo "##########"
1660 echo
1661 )
1662 fi
1663
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001664 # SPM build
1665 if config_valid "$spm_config"; then
1666 (
1667 echo "##########"
1668
1669 # Get platform name from spm_config file
1670 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1671 plat_utils="$ci_root/${plat}_utils.sh"
1672 if [ -f "$plat_utils" ]; then
1673 source "$plat_utils"
1674 fi
1675
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001676 # Call pre-build hook
1677 call_hook pre_spm_build
1678
Manish Pandey1e7be852020-11-09 16:04:48 +00001679 # SPM build generates two sets of binaries, one for normal and other
1680 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001681 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001682 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1683 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001684
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001685 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001686 echo "Building SPM ($mode) ..." |& log_separator
1687
1688 # NOTE: mode has no effect on SPM build (for now), hence debug
1689 # mode is built but subsequent build using release mode just
1690 # goes through with "nothing to do".
1691 build_spm
1692
1693 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001694 cksum $spm_build_root/hafnium.bin
1695
1696 # Some platforms only have secure configuration enabled. Hence,
1697 # non secure hanfnium binary might not be built.
1698 if [ -f $hafnium_build_root/hafnium.bin ]; then
1699 cksum $hafnium_build_root/hafnium.bin
1700 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001701
Manish Pandey1e7be852020-11-09 16:04:48 +00001702 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001703
1704 echo "##########"
1705 echo
1706 )
1707 fi
1708
Tomás González0393e802025-07-22 11:06:41 +01001709 # TF RMM build
1710 if config_valid "$rmm_config"; then
1711 (
1712 echo "##########"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001713
Tomás González0393e802025-07-22 11:06:41 +01001714 plat_utils="$(get_rmm_opt PLAT_UTILS)"
1715 if [ -z ${plat_utils} ]; then
1716 # Source platform-specific utilities.
1717 plat="$(get_rmm_opt PLAT)"
1718 plat_utils="$ci_root/${plat}_utils.sh"
1719 else
1720 # Source platform-specific utilities by
1721 # using plat_utils name.
1722 plat_utils="$ci_root/${plat_utils}.sh"
1723 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001724
Tomás González0393e802025-07-22 11:06:41 +01001725 if [ -f "$plat_utils" ]; then
1726 source "$plat_utils"
1727 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001728
Tomás González0393e802025-07-22 11:06:41 +01001729 archive="$build_archive"
1730 rmm_build_root="$rmm_root/build"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001731
Tomás González0393e802025-07-22 11:06:41 +01001732 echo "Building Trusted Firmware RMM ($mode) ..." |& log_separator
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001733
Tomás González0393e802025-07-22 11:06:41 +01001734 #call_hook pre_rmm_build
1735 build_rmm
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001736
Tomás González0393e802025-07-22 11:06:41 +01001737 # Collect all rmm.* files: rmm.img, rmm.elf, rmm.dump, rmm.map
1738 from="$rmm_build_root" to="$archive" collect_build_artefacts
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001739
Tomás González0393e802025-07-22 11:06:41 +01001740 # Clear any local changes made by applied patches
1741 undo_rmm_patches
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001742
Tomás González0393e802025-07-22 11:06:41 +01001743 echo "##########"
1744 )
1745 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001746
Fathi Boudra422bf772019-12-02 11:10:16 +02001747 # TF build
1748 if config_valid "$tf_config"; then
1749 (
1750 echo "##########"
1751
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001752 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001753 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1754
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001755 if [ -z ${plat_utils} ]; then
1756 # Source platform-specific utilities.
1757 plat="$(get_tf_opt PLAT)"
1758 plat_utils="$ci_root/${plat}_utils.sh"
1759 else
1760 # Source platform-specific utilities by
1761 # using plat_utils name.
1762 plat_utils="$ci_root/${plat_utils}.sh"
1763 fi
1764
Fathi Boudra422bf772019-12-02 11:10:16 +02001765 if [ -f "$plat_utils" ]; then
1766 source "$plat_utils"
1767 fi
1768
Chris Kaye5a486b2023-08-04 11:50:31 +00001769 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1770 fvp_tsram_size="${fvp_tsram_size:-256}"
1771
Tomás González866b23a2025-07-22 11:05:57 +01001772 poetry -C "$tf_root" install --without docs
Chris Kayd0837902021-11-17 10:17:52 +00001773
Fathi Boudra422bf772019-12-02 11:10:16 +02001774 archive="$build_archive"
Fathi Boudra422bf772019-12-02 11:10:16 +02001775
Tomás González866b23a2025-07-22 11:05:57 +01001776 tf_build_root="$tf_root/build"
1777 echo "Building Trusted Firmware ($mode) ..." |& log_separator
Tomás Gonzáleze72d5382024-11-13 14:08:25 +00001778
Fathi Boudra422bf772019-12-02 11:10:16 +02001779 # Call pre-build hook
1780 call_hook pre_tf_build
1781
Tomás González866b23a2025-07-22 11:05:57 +01001782 build_tf
Fathi Boudra422bf772019-12-02 11:10:16 +02001783
1784 # Call post-build hook
1785 call_hook post_tf_build
1786
1787 # Pre-archive hook
1788 call_hook pre_tf_archive
1789
Tomás González866b23a2025-07-22 11:05:57 +01001790 from="$tf_build_root" to="$archive" collect_build_artefacts
Zachary Leaf5494d732024-10-22 10:49:36 +01001791
Fathi Boudra422bf772019-12-02 11:10:16 +02001792 # Post-archive hook
1793 call_hook post_tf_archive
1794
1795 call_hook fetch_tf_resource
1796 call_hook post_fetch_tf_resource
1797
Chris Kay4e8aaf12022-09-01 15:21:55 +01001798 # Generate LAVA job files if necessary
1799 call_hook generate_lava_job_template
1800 call_hook generate_lava_job
1801
Fathi Boudra422bf772019-12-02 11:10:16 +02001802 # Clear any local changes made by applied patches
1803 undo_tf_patches
1804
1805 echo "##########"
1806 )
1807 fi
1808
Tomás Gonzálezb304e212025-07-28 13:39:30 +01001809 # RF-A build
1810 if config_valid "$rfa_config"; then
1811 (
1812 echo "##########"
1813
1814 plat="$(get_rfa_opt PLAT)"
1815 plat_utils="$ci_root/${plat}_utils.sh"
1816 if [ -f "$plat_utils" ]; then
1817 source "$plat_utils"
1818 fi
1819
1820 archive="$build_archive"
1821
1822 tf_build_root="$tf_root/build"
1823 rfa_build_root="$rfa_root/target"
1824
1825 echo "Building Rusted Firmware ($mode) ..." |& log_separator
1826
1827 if not_upon "$local_ci"; then
1828 # In the CI Dockerfile, rustup is installed by the root user in the
1829 # non-default location /usr/local/rustup, so $RUSTUP_HOME is required to
1830 # access rust config e.g. default toolchains and run cargo
1831 #
1832 # Leave $CARGO_HOME blank so when this script is run in CI by the buildslave
1833 # user, it uses the default /home/buildslave/.cargo directory which it has
1834 # write permissions for - that allows it to download new crates during
1835 # compilation
1836 #
1837 # The buildslave user does not have write permissions to the default
1838 # $CARGO_HOME=/usr/local/cargo dir and so will error when trying to download
1839 # new crates otherwise
1840 #
1841 # note: $PATH still contains /usr/local/cargo/bin at this point so cargo is
1842 # still run via the root installation
1843 #
1844 # see https://github.com/rust-lang/rustup/issues/1085
1845 set_hook_var "RUSTUP_HOME" "/usr/local/rustup"
1846 fi
1847
1848 # Call pre-build hook
1849 call_hook pre_rfa_build
1850
1851 build_rfa
1852
1853 # Call post-build hook
1854 call_hook post_rfa_build
1855
1856 # Pre-archive hook
1857 call_hook pre_rfa_archive
1858
1859 from="$rfa_build_root" to="$archive" collect_rfa_artefacts
1860
1861 # Post-archive hook
1862 call_hook post_rfa_archive
1863
1864 call_hook fetch_rfa_resource
1865 call_hook post_fetch_rfa_resource
1866
1867 # Generate LAVA job files if necessary
1868 call_hook generate_lava_job_template
1869 call_hook generate_lava_job
1870
1871 echo "##########"
1872 )
1873 fi
1874
Fathi Boudra422bf772019-12-02 11:10:16 +02001875 echo
1876 echo
1877done
1878
1879call_hook pre_package
1880
1881call_hook post_package
1882
1883if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001884 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001885fi
1886
1887echo
1888echo "Done"