blob: 8d3723ed784314c532dab85841f53c43c459b762 [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
651 echo "Cleaning TF-A..."
Tomás González866b23a2025-07-22 11:05:57 +0100652 make -C "$tf_root" distclean &>>"$build_log" || fail_build
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200653
654 echo 'Cleaning RF-A...'
655 cargo clean &>>"$build_log" || fail_build
656 fi
657
658 # Log build command line. It is left unfolded on purpose to assist
659 # copying to clipboard.
660 cat <<EOF | log_separator >/dev/null
661
662Build command line:
663 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG $build_targets
664
665cargo version:
666$(cargo --version 2>&1)
667EOF
668
669 # Build RF-A and TF-A. Since build output is being directed to the build
670 # log, have descriptor 3 point to the current terminal for build
671 # wrappers to vent.
Tomás González72aca672025-06-11 11:26:00 +0100672 eval make $make_j_opts $(cat "$config_file") \
673 DEBUG="$DEBUG" \
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200674 $build_targets 3>&1 &>>"$build_log" || fail_build
675 )
676}
677
Fathi Boudra422bf772019-12-02 11:10:16 +0200678build_tftf() {
679 (
680 config_file="${tftf_build_config:-$tftf_config_file}"
681
682 # Build tftf target by default
683 build_targets="${tftf_build_targets:-all}"
684
685 source "$config_file"
686
687 cd "$tftf_root"
688
689 # Always distclean when running on Jenkins. Skip distclean when running
690 # locally and explicitly requested.
691 if upon "$jenkins_run" || not_upon "$dont_clean"; then
692 make distclean &>>"$build_log" || fail_build
693 fi
694
695 # TFTF build system cannot reliably deal with -j option, so we avoid
696 # using that.
697
698 # Log build command line
699 cat <<EOF | log_separator >/dev/null
700
701Build command line:
Boyan Karatotev51060ba2024-10-29 16:55:10 +0000702 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
Fathi Boudra422bf772019-12-02 11:10:16 +0200703
704EOF
705
Boyan Karatotev51060ba2024-10-29 16:55:10 +0000706 make $make_j_opts $(cat "$config_file") DEBUG="$DEBUG" V=1 \
Fathi Boudra422bf772019-12-02 11:10:16 +0200707 $build_targets &>>"$build_log" || fail_build
708 )
709}
710
711build_scp() {
712 (
713 config_file="${scp_build_config:-$scp_config_file}"
714
715 source "$config_file"
716
717 cd "$scp_root"
718
719 # Always distclean when running on Jenkins. Skip distclean when running
720 # locally and explicitly requested.
721 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000722 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200723 fi
724
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000725 python3 -m venv .venv
726 . .venv/bin/activate
727
728 # Install extra tools used by CMake build system
729 pip install -r requirements.txt --timeout 30 --retries 15
730
Fathi Boudra422bf772019-12-02 11:10:16 +0200731 # Log build command line. It is left unfolded on purpose to assist
732 # copying to clipboard.
733 cat <<EOF | log_separator >/dev/null
734
735SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000736 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
737 TOOLCHAIN=GNU \
738 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000739 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000740 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200741
742EOF
743
744 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000745 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
746 TOOLCHAIN=GNU \
747 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000748 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000749 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200750 || fail_build
751 )
752}
753
Zelalem219df412020-05-17 19:21:20 -0500754clone_scp_tools() {
755
756 if [ ! -d "$scp_tools_root" ]; then
757 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
758
759 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
760 where="$scp_tools_root" \
761 refspec="${scp_tools_commit}"
762 clone_repo &>>"$build_log"
763 else
764 echo "Already cloned SCP-tools ..." |& log_separator
765 fi
766
767 show_head "$scp_tools_root"
768
769 cd "$scp_tools_root"
770
771 echo "Updating submodules"
772
773 git submodule init
774
775 git submodule update
776
Nicola Mazzucato9b171422023-08-29 15:50:49 +0100777 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 +0000778
Zelalem219df412020-05-17 19:21:20 -0500779 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000780 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500781
782 git show --quiet --no-color | sed 's/^/ > /g'
783}
784
785clone_tf_for_scp_tools() {
786 scp_tools_arm_tf="$scp_tools_root/arm-tf"
787
788 if [ ! -d "$scp_tools_arm_tf" ]; then
789 echo "Cloning TF-4-SCP-tools ..." |& log_separator
790
791 clone_url="$tf_for_scp_tools_src_repo_url"
792 where="$scp_tools_arm_tf"
793
794 git clone "$clone_url" "$where"
795
796 cd "$scp_tools_arm_tf"
797
Joel Goddard3ad03062021-03-16 16:47:42 +0000798 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500799
800 git show --quiet --no-color | sed 's/^/ > /g'
801
802 else
803 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
804 fi
805}
806
807build_scmi_lib_scp_tools() {
808 (
809 cd "$scp_tools_root"
810
811 cd "scmi"
812
813 scp_tools_arm_tf="$scp_tools_root/arm-tf"
814
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600815 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500816
817 std_libs="-I$scp_tools_arm_tf/include/common"
818 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
819 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
820 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
821 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
822 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
823 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
824 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
825 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
826 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
827 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
828 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
829 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
830 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
831
832 cflags="-Og -g"
833 cflags="$cflags -mgeneral-regs-only"
834 cflags="$cflags -mstrict-align"
835 cflags="$cflags -nostdinc"
836 cflags="$cflags -fno-inline"
837 cflags="$cflags -ffreestanding"
838 cflags="$cflags -ffunction-sections"
839 cflags="$cflags -fdata-sections"
840 cflags="$cflags -DAARCH64"
841 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000842 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500843
844 cflags="$cflags $std_libs"
845
Joel Goddard3ad03062021-03-16 16:47:42 +0000846 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500847
848 echo "Building SCMI library (SCP-tools) ..."
849
850 make "CROSS_COMPILE=$cross_compile" \
851 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000852 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500853 "PROTOCOLS=$protocols" \
854 "clean" \
855 "all"
856 )
857}
858
859build_tf_for_scp_tools() {
860
861 cd "$scp_tools_root/arm-tf"
862
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600863 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500864
865 if [ "$1" = "release" ]; then
866 echo "Build TF-4-SCP-Tools rls..."
867 else
868 echo "Build TF-4-SCP-Tools dbg..."
869
870 make realclean
871
872 make "BM_TEST=scmi" \
873 "ARM_BOARD_OPTIMISE_MEM=1" \
874 "BM_CSS=juno" \
875 "CSS_USE_SCMI_SDS_DRIVER=1" \
876 "PLAT=juno" \
877 "DEBUG=1" \
878 "PLATFORM=juno" \
879 "CROSS_COMPILE=$cross_compile" \
880 "BM_WORKSPACE=$scp_tools_root/baremetal"
881
882 archive_file "build/juno/debug/bl1.bin"
883
884 archive_file "build/juno/debug/bl2.bin"
885
886 archive_file "build/juno/debug/bl31.bin"
887 fi
888}
889
890build_fip_for_scp_tools() {
891
892 cd "$scp_tools_root/arm-tf"
893
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600894 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500895
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000896 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500897 make fiptool
898 echo "Make FIP 4 SCP-Tools rls..."
899
900 else
901 make fiptool
902 echo "Make FIP 4 SCP-Tools dbg..."
903
904 make "PLAT=juno" \
905 "all" \
906 "fip" \
907 "DEBUG=1" \
908 "CROSS_COMPILE=$cross_compile" \
909 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
910 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000911 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500912
913 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
914 fi
915}
916
917build_cc() {
918# Building code coverage plugin
919 ARM_DIR=/arm
920 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
921 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
922 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
923 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
924 exit -1
925 fi # Error if arm warehouse not found
926 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
927
928 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
929}
930
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100931build_spm() {
932 (
933 env_file="$workspace/spm.env"
934 config_file="${spm_build_config:-$spm_config_file}"
935
936 source "$config_file"
937
938 if [ -f "$env_file" ]; then
939 set -a
940 source "$env_file"
941 set +a
942 fi
943
944 cd "$spm_root"
945
946 # Always clean when running on Jenkins. Skip clean when running
947 # locally and explicitly requested.
948 if upon "$jenkins_run" || not_upon "$dont_clean"; then
949 # make clean fails on a fresh repo where the project has not
950 # yet been built. Hence only clean if out/reference directory
951 # already exists.
952 if [ -d "out/reference" ]; then
953 make clean &>>"$build_log" || fail_build
954 fi
955 fi
956
957 # Log build command line. It is left unfolded on purpose to assist
958 # copying to clipboard.
959 cat <<EOF | log_separator >/dev/null
960
961Build command line:
962 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
963
964EOF
965
966 # Build SPM. Since build output is being directed to the build log, have
967 # descriptor 3 point to the current terminal for build wrappers to vent.
968 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
969 || fail_build
970 )
971}
Zelalem219df412020-05-17 19:21:20 -0500972
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000973build_rmm() {
974 (
975 env_file="$workspace/rmm.env"
976 config_file="${rmm_build_config:-$rmm_config_file}"
977
978 # Build fiptool and all targets by default
979 build_targets="${rmm_build_targets}"
980 export CROSS_COMPILE="${aarch64_none_elf_prefix}"
981
982 source "$config_file"
983
984 if [ -f "$env_file" ]; then
985 set -a
986 source "$env_file"
987 set +a
988 fi
989
990 cd "$rmm_root"
991
992 if [ -f "$rmm_root/requirements.txt" ]; then
993 export PATH="$HOME/.local/bin:$PATH"
994 python3 -m pip install --upgrade pip
995 python3 -m pip install -r "$rmm_root/requirements.txt"
996 fi
997
998 # Always distclean when running on Jenkins. Skip distclean when running
999 # locally and explicitly requested.
1000 if upon "$jenkins_run" || not_upon "$dont_clean"; then
1001 # Remove 'rmm\build' folder
1002 echo "Removing $rmm_build_root..."
1003 rm -rf $rmm_build_root
1004 fi
1005
1006 # Log build command line. It is left unfolded on purpose to assist
1007 # copying to clipboard.
1008 cat <<EOF | log_separator >/dev/null
1009
1010Build command line:
1011 cmake -DRMM_CONFIG=${plat}_defcfg $cmake_gen -S $rmm_root -B $rmm_build_root -DCMAKE_BUILD_TYPE=$cmake_build_type
1012 cmake --build $rmm_build_root $make_j_opts -v
1013EOF
1014 if not_upon "$local_ci"; then
1015 connect_debugger=0
1016 fi
1017
1018 cmake -DRMM_CONFIG=${plat}_defcfg $cmake_gen -S $rmm_root -B $rmm_build_root -DCMAKE_BUILD_TYPE=$cmake_build_type
1019 cmake --build $rmm_build_root $make_j_opts -v 3>&1 &>>"$build_log" || fail_build
1020 )
1021}
1022
Fathi Boudra422bf772019-12-02 11:10:16 +02001023# Set metadata for the whole package so that it can be used by both Jenkins and
1024# shell
1025set_package_var() {
1026 env_file="$artefacts/env" emit_env "$@"
1027}
1028
1029set_tf_build_targets() {
1030 echo "Set build target to '${targets:?}'"
1031 set_hook_var "tf_build_targets" "$targets"
1032}
1033
Tomás González866b23a2025-07-22 11:05:57 +01001034set_rfa_build_targets() {
1035 echo "Set build target to '${targets:?}'"
1036 set_hook_var "rfa_build_targets" "$targets"
1037}
1038
Fathi Boudra422bf772019-12-02 11:10:16 +02001039set_tftf_build_targets() {
1040 echo "Set build target to '${targets:?}'"
1041 set_hook_var "tftf_build_targets" "$targets"
1042}
1043
1044set_scp_build_targets() {
1045 echo "Set build target to '${targets:?}'"
1046 set_hook_var "scp_build_targets" "$targets"
1047}
1048
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001049set_spm_build_targets() {
1050 echo "Set build target to '${targets:?}'"
1051 set_hook_var "spm_build_targets" "$targets"
1052}
1053
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001054set_spm_out_dir() {
1055 echo "Set SPMC binary build to '${out_dir:?}'"
1056 set_hook_var "spm_secure_out_dir" "$out_dir"
1057}
Fathi Boudra422bf772019-12-02 11:10:16 +02001058# Look under $archive directory for known files such as blX images, kernel, DTB,
1059# initrd etc. For each known file foo, if foo.bin exists, then set variable
1060# foo_bin to the path of the file. Make the path relative to the workspace so as
1061# to remove any @ characters, which Jenkins inserts for parallel runs. If the
1062# file doesn't exist, unset its path.
1063set_default_bin_paths() {
1064 local image image_name image_path path
1065 local archive="${archive:?}"
1066 local set_vars
1067 local var
1068
1069 pushd "$archive"
1070
1071 for file in *.bin; do
1072 # Get a shell variable from the file's stem
1073 var_name="${file%%.*}_bin"
1074 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
1075
1076 # Skip setting the variable if it's already
1077 if [ "${!var_name}" ]; then
1078 echo "Note: not setting $var_name; already set to ${!var_name}"
1079 continue
1080 else
1081 set_vars+="$var_name "
1082 fi
1083
1084 eval "$var_name=$file"
1085 done
1086
1087 echo "Binary paths set for: "
1088 {
1089 for var in $set_vars; do
1090 echo -n "\$$var "
1091 done
1092 } | fmt -80 | sed 's/^/ /'
1093 echo
1094
1095 popd
1096}
1097
1098gen_model_params() {
1099 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +00001100 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +02001101
1102 set_default_bin_paths
1103 echo "Generating model parameter for $model..."
1104 source "$ci_root/model/${model:?}.sh"
1105 archive_file "$model_param_file"
1106}
1107
1108set_model_path() {
1109 set_run_env "model_path" "${1:?}"
1110}
1111
Zelalem1af7a7b2020-08-04 17:34:32 -05001112set_model_env() {
1113 local var="${1:?}"
1114 local val="${2?}"
1115 local run_root="${archive:?}/run"
1116
1117 mkdir -p "$run_root"
1118 echo "export $var=$val" >> "$run_root/model_env"
1119}
Fathi Boudra422bf772019-12-02 11:10:16 +02001120set_run_env() {
1121 local var="${1:?}"
1122 local val="${2?}"
1123 local run_root="${archive:?}/run"
1124
1125 mkdir -p "$run_root"
1126 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
1127}
1128
1129show_head() {
1130 # Display HEAD descripton
1131 pushd "$1"
1132 git show --quiet --no-color | sed 's/^/ > /g'
1133 echo
1134 popd
1135}
1136
1137# Choose debug binaries to run; by default, release binaries are chosen to run
1138use_debug_bins() {
1139 local run_root="${archive:?}/run"
1140
1141 echo "Choosing debug binaries for execution"
1142 set_package_var "BIN_MODE" "debug"
1143}
1144
1145assert_can_git_clone() {
1146 local name="${1:?}"
1147 local dir="${!name}"
1148
1149 # If it doesn't exist, it can be cloned into
1150 if [ ! -e "$dir" ]; then
1151 return 0
1152 fi
1153
1154 # If it's a directory, it must be a Git clone already
1155 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
1156 # No need to clone again
1157 echo "Using existing git clone for $name: $dir"
1158 return 1
1159 fi
1160
1161 die "Path $dir exists but is not a git clone"
1162}
1163
1164clone_repo() {
1165 if ! is_url "${clone_url?}"; then
1166 # For --depth to take effect on local paths, it needs to use the
1167 # file:// scheme.
1168 clone_url="file://$clone_url"
1169 fi
1170
1171 git clone -q --depth 1 "$clone_url" "${where?}"
1172 if [ "$refspec" ]; then
1173 pushd "$where"
1174 git fetch -q --depth 1 origin "$refspec"
1175 git checkout -q FETCH_HEAD
1176 popd
1177 fi
1178}
1179
1180build_unstable() {
1181 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1182}
1183
1184undo_patch_record() {
1185 if [ ! -f "${patch_record:?}" ]; then
1186 return
1187 fi
1188
1189 # Undo patches in reverse
1190 echo
1191 for patch_name in $(tac "$patch_record"); do
1192 echo "Undoing $patch_name..."
1193 if ! git apply -R "$ci_root/patch/$patch_name"; then
1194 if upon "$local_ci"; then
1195 echo
1196 echo "Your local directory may have been dirtied."
1197 echo
1198 fi
1199 fail_build
1200 fi
1201 done
1202
1203 rm -f "$patch_record"
1204}
1205
1206undo_local_patches() {
1207 pushd "$tf_root"
1208 patch_record="$tf_patch_record" undo_patch_record
1209 popd
1210
1211 if [ -d "$tftf_root" ]; then
1212 pushd "$tftf_root"
1213 patch_record="$tftf_patch_record" undo_patch_record
1214 popd
1215 fi
1216}
1217
1218undo_tftf_patches() {
1219 pushd "$tftf_root"
1220 patch_record="$tftf_patch_record" undo_patch_record
1221 popd
1222}
1223
1224undo_tf_patches() {
1225 pushd "$tf_root"
1226 patch_record="$tf_patch_record" undo_patch_record
1227 popd
1228}
1229
1230apply_patch() {
1231 # If skip_patches is set, the developer has applied required patches
1232 # manually. They probably want to keep them applied for debugging
1233 # purposes too. This means we don't have to apply/revert them as part of
1234 # build process.
1235 if upon "$skip_patches"; then
1236 echo "Skipped applying ${1:?}..."
1237 return 0
1238 else
1239 echo "Applying ${1:?}..."
1240 fi
1241
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +02001242 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001243 echo "Skipping already applied ${1:?}"
1244 return 0
1245 fi
1246
Fathi Boudra422bf772019-12-02 11:10:16 +02001247 if git apply < "$ci_root/patch/$1"; then
1248 echo "$1" >> "${patch_record:?}"
1249 else
1250 if upon "$local_ci"; then
1251 undo_local_patches
1252 fi
1253 fail_build
1254 fi
1255}
1256
1257apply_tftf_patch() {
1258 pushd "$tftf_root"
1259 patch_record="$tftf_patch_record" apply_patch "$1"
1260 popd
1261}
1262
1263apply_tf_patch() {
1264 pushd "$tf_root"
1265 patch_record="$tf_patch_record" apply_patch "$1"
1266 popd
1267}
1268
1269# Clear workspace for a local run
Leandro Bellibe7b8fa2024-07-18 10:14:22 +01001270if not_upon "$jenkins_run" && not_upon "$dont_clean"; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001271 rm -rf "$workspace"
1272
1273 # Clear residue from previous runs
1274 rm -rf "$archive"
1275fi
1276
1277mkdir -p "$workspace"
1278mkdir -p "$archive"
1279set_package_var "TEST_CONFIG" "$test_config"
1280
1281{
1282echo
1283echo "CONFIGURATION: $test_group/$test_config"
1284echo
1285} |& log_separator
1286
1287tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1288tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1289scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001290scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001291spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001292rmm_config="$(echo "$build_configs" | awk -F, '{print $6}')"
Tomás Gonzálezfa3e24b2025-07-22 10:59:06 +01001293rfa_config="$(echo "$build_configs" | awk -F, '{print $7}')"
1294
Fathi Boudra422bf772019-12-02 11:10:16 +02001295
1296test_config_file="$ci_root/group/$test_group/$test_config"
1297
1298tf_config_file="$ci_root/tf_config/$tf_config"
1299tftf_config_file="$ci_root/tftf_config/$tftf_config"
1300scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001301scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001302spm_config_file="$ci_root/spm_config/$spm_config"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001303rmm_config_file="$ci_root/rmm_config/$rmm_config"
Tomás González866b23a2025-07-22 11:05:57 +01001304rfa_config_file="$ci_root/rfa_config/$rfa_config"
1305
Fathi Boudra422bf772019-12-02 11:10:16 +02001306
1307# File that keeps track of applied patches
1308tf_patch_record="$workspace/tf_patches"
1309tftf_patch_record="$workspace/tftf_patches"
Tomás González866b23a2025-07-22 11:05:57 +01001310rfa_patch_record="$workspace/rfa_patches"
Fathi Boudra422bf772019-12-02 11:10:16 +02001311
1312pushd "$workspace"
1313
1314if ! config_valid "$tf_config"; then
1315 tf_config=
1316else
1317 echo "Trusted Firmware config:"
1318 echo
1319 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1320 echo
1321fi
1322
Tomás González866b23a2025-07-22 11:05:57 +01001323if ! config_valid "$rfa_config"; then
1324 rfa_config=
1325else
1326 echo "RF-A config:"
1327 echo
1328 sort "$rfa_config_file" | sed '/^\s*$/d;s/^/\t/'
1329 echo
1330fi
1331
Fathi Boudra422bf772019-12-02 11:10:16 +02001332if ! config_valid "$tftf_config"; then
1333 tftf_config=
1334else
1335 echo "Trusted Firmware TF config:"
1336 echo
1337 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1338 echo
1339fi
1340
1341if ! config_valid "$scp_config"; then
1342 scp_config=
1343else
1344 echo "SCP firmware config:"
1345 echo
1346 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1347 echo
1348fi
1349
Zelalem219df412020-05-17 19:21:20 -05001350if ! config_valid "$scp_tools_config"; then
1351 scp_tools_config=
1352else
1353 echo "SCP Tools config:"
1354 echo
1355 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001356fi
1357
1358if ! config_valid "$spm_config"; then
1359 spm_config=
1360else
1361 echo "SPM config:"
1362 echo
1363 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001364 echo
1365fi
1366
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001367# File that keeps track of applied patches
1368rmm_patch_record="$workspace/rmm_patches"
1369
1370if ! config_valid "$rmm_config"; then
1371 rmm_config=
1372else
1373 echo "Trusted Firmware RMM config:"
1374 echo
1375 sort "$rmm_config_file" | sed '/^\s*$/d;s/^/\t/'
1376 echo
1377fi
1378
Fathi Boudra422bf772019-12-02 11:10:16 +02001379if ! config_valid "$run_config"; then
1380 run_config=
1381fi
1382
1383if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1384 # If the Trusted Firmware repository has already been checked out, use
1385 # that location. Otherwise, clone one ourselves.
1386 echo "Cloning Trusted Firmware..."
1387 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1388 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1389 show_head "$tf_root"
1390fi
1391
Tomás González866b23a2025-07-22 11:05:57 +01001392if [ "$rfa_config" ] && assert_can_git_clone "rfa_root"; then
1393 # If the Rusted Firmware repository has already been checked out, use
1394 # that location. Otherwise, clone one ourselves.
1395 echo "Cloning Rusted Firmware..."
1396
1397 clone_url="${RFA_CHECKOUT_LOC:-$rfa_src_repo_url}" where="$rfa_root" \
1398 refspec="$RFA_REFSPEC" clone_repo &>>"$build_log"
1399 show_head "$rfa_root"
1400fi
1401
Fathi Boudra422bf772019-12-02 11:10:16 +02001402if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1403 # If the Trusted Firmware TF repository has already been checked out,
1404 # use that location. Otherwise, clone one ourselves.
1405 echo "Cloning Trusted Firmware TF..."
1406 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1407 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1408 show_head "$tftf_root"
1409fi
1410
1411if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1412 # If the SCP firmware repository has already been checked out,
1413 # use that location. Otherwise, clone one ourselves.
1414 echo "Cloning SCP Firmware..."
1415 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1416 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1417
1418 pushd "$scp_root"
1419
1420 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001421 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001422 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1423 fi
1424
1425 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1426 # then to project filer if accessible.
1427 if [ -z "$cmsis_reference" ]; then
1428 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1429 if [ -d "$cmsis_ref_repo" ]; then
1430 cmsis_reference="--reference $cmsis_ref_repo"
1431 fi
1432 fi
1433
1434 git submodule -q update $cmsis_reference --init
1435
1436 popd
1437
1438 show_head "$scp_root"
1439fi
1440
Zelalem219df412020-05-17 19:21:20 -05001441if [ -n "$cc_config" ] ; then
1442 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1443 # Copy code coverage repository
1444 echo "Cloning Code Coverage..."
1445 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1446 show_head "$cc_root"
1447 fi
1448fi
1449
Daniel Boulby25385ab2023-12-14 14:36:25 +00001450if [ "$spm_config" ] ; then
1451 if assert_can_git_clone "spm_root"; then
1452 # If the SPM repository has already been checked out, use
1453 # that location. Otherwise, clone one ourselves.
1454 echo "Cloning SPM..."
1455 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1456 where="$spm_root" refspec="$SPM_REFSPEC" \
1457 clone_repo &>>"$build_log"
1458 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001459
1460 # Query git submodules
1461 pushd "$spm_root"
Daniel Boulby25385ab2023-12-14 14:36:25 +00001462 # Check if submodules need initialising
Paul Sokolovskyad274422024-09-01 10:27:56 +03001463
1464 # This handling is needed to reliably fetch submodules
1465 # in CI environment.
1466 for subm in $(git submodule status | awk '/^-/ {print $2}'); do
1467 for i in $(seq 1 7); do
1468 git submodule init $subm
1469 if git submodule update $subm; then
1470 break
1471 fi
1472 git submodule deinit --force $subm
1473 echo "Retrying $subm"
1474 sleep $((RANDOM % 10 + 5))
1475 done
1476 done
1477
1478 git submodule status
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001479 popd
1480
1481 show_head "$spm_root"
1482fi
1483
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001484if [ "$rmm_config" ] && assert_can_git_clone "rmm_root"; then
Manish V Badarkhe41909452025-04-11 12:06:45 +01001485 # If the RMM repository has already been checked out,
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001486 # use that location. Otherwise, clone one ourselves.
1487 echo "Cloning TF-RMM..."
1488 clone_url="${RMM_CHECKOUT_LOC:-$rmm_src_repo_url}" where="$rmm_root" \
1489 refspec="$RMM_REFSPEC" clone_repo &>>"$build_log"
1490 show_head "$rmm_root"
1491fi
1492
Fathi Boudra422bf772019-12-02 11:10:16 +02001493if [ "$run_config" ]; then
1494 # Get candidates for run config
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001495 run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \
Fathi Boudra422bf772019-12-02 11:10:16 +02001496 "$run_config")"
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001497 if [ -z "$run_config_candidates" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001498 die "No run config candidates!"
1499 else
1500 echo
1501 echo "Chosen fragments:"
1502 echo
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001503 echo "$run_config_candidates" | sed 's/^\|\n/\t/g'
Fathi Boudra422bf772019-12-02 11:10:16 +02001504 echo
Harrison Mutai4dfe1192024-07-03 12:35:38 +00001505
1506 if [ ! -n "$bin_mode" ]; then
1507 if echo $run_config_candidates | grep -wq "debug"; then
1508 bin_mode="debug"
1509 else
1510 bin_mode="release"
1511 fi
1512 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001513 fi
1514fi
1515
1516call_hook "test_setup"
1517echo
1518
1519if upon "$local_ci"; then
1520 # For local runs, since each config is tried in sequence, it's
1521 # advantageous to run jobs in parallel
1522 if [ "$make_j" ]; then
1523 make_j_opts="-j $make_j"
1524 else
1525 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1526 if [ "$n_cores" ]; then
1527 make_j_opts="-j $n_cores"
1528 fi
1529 fi
1530fi
1531
Harrison Mutai07043e92023-07-06 09:41:12 +01001532# Install python build dependencies
1533if is_arm_jenkins_env; then
1534 source "$ci_root/script/install_python_deps.sh"
1535fi
1536
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001537# Print CMake version
1538cmake_ver=$(echo `cmake --version | sed -n '1p'`)
1539echo "Using $cmake_ver"
1540
1541# Check for Ninja
1542if [ -x "$(command -v ninja)" ]; then
1543 # Print Ninja version
1544 ninja_ver=$(echo `ninja --version | sed -n '1p'`)
1545 echo "Using ninja $ninja_ver"
1546 export cmake_gen="-G Ninja"
1547else
1548 echo 'Ninja is not installed'
1549 export cmake_gen=""
1550fi
1551
1552undo_rmm_patches() {
1553 pushd "$rmm_root"
1554 patch_record="$rmm_patch_record" undo_patch_record
1555 popd
1556}
1557
Fathi Boudra422bf772019-12-02 11:10:16 +02001558modes="${bin_mode:-debug release}"
1559for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001560 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001561 # Build with a temporary archive
1562 build_archive="$archive/$mode"
1563 mkdir "$build_archive"
1564
1565 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001566 export bin_mode="debug"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001567 cmake_build_type="Debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001568 DEBUG=1
1569 else
Zelalem219df412020-05-17 19:21:20 -05001570 export bin_mode="release"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001571 cmake_build_type="Release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001572 DEBUG=0
1573 fi
1574
1575 # Perform builds in a subshell so as not to pollute the current and
1576 # subsequent builds' environment
1577
Zelalem219df412020-05-17 19:21:20 -05001578 if config_valid "$cc_config"; then
1579 # Build code coverage plugin
1580 build_cc
1581 fi
1582
Fathi Boudra422bf772019-12-02 11:10:16 +02001583 # SCP build
1584 if config_valid "$scp_config"; then
1585 (
1586 echo "##########"
1587
1588 # Source platform-specific utilities
1589 plat="$(get_scp_opt PRODUCT)"
1590 plat_utils="$ci_root/${plat}_utils.sh"
1591 if [ -f "$plat_utils" ]; then
1592 source "$plat_utils"
1593 fi
1594
1595 archive="$build_archive"
1596 scp_build_root="$scp_root/build"
1597
1598 echo "Building SCP Firmware ($mode) ..." |& log_separator
1599
1600 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001601 to="$archive" collect_scp_artefacts
1602
1603 echo "##########"
1604 echo
1605 )
1606 fi
1607
Zelalem219df412020-05-17 19:21:20 -05001608 # SCP-tools build
1609 if config_valid "$scp_tools_config"; then
1610 (
1611 echo "##########"
1612
1613 archive="$build_archive"
1614 scp_tools_build_root="$scp_tools_root/build"
1615
1616 clone_scp_tools
1617
1618 echo "##########"
1619 echo
1620
1621 echo "##########"
1622 clone_tf_for_scp_tools
1623 echo "##########"
1624 echo
1625 )
1626 fi
1627
Fathi Boudra422bf772019-12-02 11:10:16 +02001628 # TFTF build
1629 if config_valid "$tftf_config"; then
1630 (
1631 echo "##########"
1632
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001633 plat_utils="$(get_tf_opt PLAT_UTILS)"
1634 if [ -z ${plat_utils} ]; then
1635 # Source platform-specific utilities.
1636 plat="$(get_tftf_opt PLAT)"
1637 plat_utils="$ci_root/${plat}_utils.sh"
1638 else
1639 # Source platform-specific utilities by
1640 # using plat_utils name.
1641 plat_utils="$ci_root/${plat_utils}.sh"
1642 fi
1643
Fathi Boudra422bf772019-12-02 11:10:16 +02001644 if [ -f "$plat_utils" ]; then
1645 source "$plat_utils"
1646 fi
1647
1648 archive="$build_archive"
1649 tftf_build_root="$tftf_root/build"
1650
1651 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1652
1653 # Call pre-build hook
1654 call_hook pre_tftf_build
1655
1656 build_tftf
1657
1658 from="$tftf_build_root" to="$archive" collect_build_artefacts
1659
1660 # Clear any local changes made by applied patches
1661 undo_tftf_patches
1662
1663 echo "##########"
1664 echo
1665 )
1666 fi
1667
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001668 # SPM build
1669 if config_valid "$spm_config"; then
1670 (
1671 echo "##########"
1672
1673 # Get platform name from spm_config file
1674 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1675 plat_utils="$ci_root/${plat}_utils.sh"
1676 if [ -f "$plat_utils" ]; then
1677 source "$plat_utils"
1678 fi
1679
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001680 # Call pre-build hook
1681 call_hook pre_spm_build
1682
Manish Pandey1e7be852020-11-09 16:04:48 +00001683 # SPM build generates two sets of binaries, one for normal and other
1684 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001685 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001686 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1687 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001688
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001689 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001690 echo "Building SPM ($mode) ..." |& log_separator
1691
1692 # NOTE: mode has no effect on SPM build (for now), hence debug
1693 # mode is built but subsequent build using release mode just
1694 # goes through with "nothing to do".
1695 build_spm
1696
1697 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001698 cksum $spm_build_root/hafnium.bin
1699
1700 # Some platforms only have secure configuration enabled. Hence,
1701 # non secure hanfnium binary might not be built.
1702 if [ -f $hafnium_build_root/hafnium.bin ]; then
1703 cksum $hafnium_build_root/hafnium.bin
1704 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001705
Manish Pandey1e7be852020-11-09 16:04:48 +00001706 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001707
1708 echo "##########"
1709 echo
1710 )
1711 fi
1712
Tomás González0393e802025-07-22 11:06:41 +01001713 # TF RMM build
1714 if config_valid "$rmm_config"; then
1715 (
1716 echo "##########"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001717
Tomás González0393e802025-07-22 11:06:41 +01001718 plat_utils="$(get_rmm_opt PLAT_UTILS)"
1719 if [ -z ${plat_utils} ]; then
1720 # Source platform-specific utilities.
1721 plat="$(get_rmm_opt PLAT)"
1722 plat_utils="$ci_root/${plat}_utils.sh"
1723 else
1724 # Source platform-specific utilities by
1725 # using plat_utils name.
1726 plat_utils="$ci_root/${plat_utils}.sh"
1727 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001728
Tomás González0393e802025-07-22 11:06:41 +01001729 if [ -f "$plat_utils" ]; then
1730 source "$plat_utils"
1731 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001732
Tomás González0393e802025-07-22 11:06:41 +01001733 archive="$build_archive"
1734 rmm_build_root="$rmm_root/build"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001735
Tomás González0393e802025-07-22 11:06:41 +01001736 echo "Building Trusted Firmware RMM ($mode) ..." |& log_separator
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001737
Tomás González0393e802025-07-22 11:06:41 +01001738 #call_hook pre_rmm_build
1739 build_rmm
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001740
Tomás González0393e802025-07-22 11:06:41 +01001741 # Collect all rmm.* files: rmm.img, rmm.elf, rmm.dump, rmm.map
1742 from="$rmm_build_root" to="$archive" collect_build_artefacts
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001743
Tomás González0393e802025-07-22 11:06:41 +01001744 # Clear any local changes made by applied patches
1745 undo_rmm_patches
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001746
Tomás González0393e802025-07-22 11:06:41 +01001747 echo "##########"
1748 )
1749 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001750
Tomás González866b23a2025-07-22 11:05:57 +01001751 # RF-A build
1752 if config_valid "$rfa_config"; then
1753 (
1754 echo "##########"
1755
1756 plat="$(get_rfa_opt PLAT)"
1757 plat_utils="$ci_root/${plat}_utils.sh"
1758 if [ -f "$plat_utils" ]; then
1759 source "$plat_utils"
1760 fi
1761
1762 fvp_tsram_size="$(get_rfa_opt FVP_TRUSTED_SRAM_SIZE)"
1763 fvp_tsram_size="${fvp_tsram_size:-256}"
1764
1765 archive="$build_archive"
1766
1767 # Clone TF-A repo if required. Save its path into the
1768 # special variable "TFA", which is used by RF-A build
1769 # system.
1770 export TFA="${TFA:-$tf_root}"
1771 if assert_can_git_clone "TFA"; then
1772 echo "Cloning TF-A..."
1773 clone_url="$tf_src_repo_url" where="$TFA" clone_repo
1774 fi
1775 show_head "$TFA"
1776 poetry -C "$TFA" install --without docs
1777
1778 rfa_build_root="$rfa_root/target"
1779 echo "Building Rusted Firmware ($mode) ..." |& log_separator
1780
1781 if not_upon "$local_ci"; then
1782 # In the CI Dockerfile, rustup is installed by the root user in the
1783 # non-default location /usr/local/rustup, so $RUSTUP_HOME is required to
1784 # access rust config e.g. default toolchains and run cargo
1785 #
1786 # Leave $CARGO_HOME blank so when this script is run in CI by the buildslave
1787 # user, it uses the default /home/buildslave/.cargo directory which it has
1788 # write permissions for - that allows it to download new crates during
1789 # compilation
1790 #
1791 # The buildslave user does not have write permissions to the default
1792 # $CARGO_HOME=/usr/local/cargo dir and so will error when trying to download
1793 # new crates otherwise
1794 #
1795 # note: $PATH still contains /usr/local/cargo/bin at this point so cargo is
1796 # still run via the root installation
1797 #
1798 # see https://github.com/rust-lang/rustup/issues/1085
1799 set_hook_var "RUSTUP_HOME" "/usr/local/rustup"
1800 fi
1801
1802 # Call pre-build hook
1803 call_hook pre_rfa_build
1804
1805 build_rfa
1806
1807 # Call post-build hook
1808 call_hook post_rfa_build
1809
1810 # Pre-archive hook
1811 call_hook pre_rfa_archive
1812
1813 from="$rfa_build_root" to="$archive" collect_rfa_artefacts
1814
1815 # Post-archive hook
1816 call_hook post_rfa_archive
1817
1818 call_hook fetch_rfa_resource
1819 call_hook post_fetch_rfa_resource
1820
1821 # Generate LAVA job files if necessary
1822 call_hook generate_lava_job_template
1823 call_hook generate_lava_job
1824
1825 echo "##########"
1826 )
1827 fi
1828
Fathi Boudra422bf772019-12-02 11:10:16 +02001829 # TF build
1830 if config_valid "$tf_config"; then
1831 (
1832 echo "##########"
1833
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001834 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001835 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1836
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001837 if [ -z ${plat_utils} ]; then
1838 # Source platform-specific utilities.
1839 plat="$(get_tf_opt PLAT)"
1840 plat_utils="$ci_root/${plat}_utils.sh"
1841 else
1842 # Source platform-specific utilities by
1843 # using plat_utils name.
1844 plat_utils="$ci_root/${plat_utils}.sh"
1845 fi
1846
Fathi Boudra422bf772019-12-02 11:10:16 +02001847 if [ -f "$plat_utils" ]; then
1848 source "$plat_utils"
1849 fi
1850
Chris Kaye5a486b2023-08-04 11:50:31 +00001851 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1852 fvp_tsram_size="${fvp_tsram_size:-256}"
1853
Tomás González866b23a2025-07-22 11:05:57 +01001854 poetry -C "$tf_root" install --without docs
Chris Kayd0837902021-11-17 10:17:52 +00001855
Fathi Boudra422bf772019-12-02 11:10:16 +02001856 archive="$build_archive"
Fathi Boudra422bf772019-12-02 11:10:16 +02001857
Tomás González866b23a2025-07-22 11:05:57 +01001858 tf_build_root="$tf_root/build"
1859 echo "Building Trusted Firmware ($mode) ..." |& log_separator
Tomás Gonzáleze72d5382024-11-13 14:08:25 +00001860
Fathi Boudra422bf772019-12-02 11:10:16 +02001861 # Call pre-build hook
1862 call_hook pre_tf_build
1863
Tomás González866b23a2025-07-22 11:05:57 +01001864 build_tf
Fathi Boudra422bf772019-12-02 11:10:16 +02001865
1866 # Call post-build hook
1867 call_hook post_tf_build
1868
1869 # Pre-archive hook
1870 call_hook pre_tf_archive
1871
Tomás González866b23a2025-07-22 11:05:57 +01001872 from="$tf_build_root" to="$archive" collect_build_artefacts
Zachary Leaf5494d732024-10-22 10:49:36 +01001873
Fathi Boudra422bf772019-12-02 11:10:16 +02001874 # Post-archive hook
1875 call_hook post_tf_archive
1876
1877 call_hook fetch_tf_resource
1878 call_hook post_fetch_tf_resource
1879
Chris Kay4e8aaf12022-09-01 15:21:55 +01001880 # Generate LAVA job files if necessary
1881 call_hook generate_lava_job_template
1882 call_hook generate_lava_job
1883
Fathi Boudra422bf772019-12-02 11:10:16 +02001884 # Clear any local changes made by applied patches
1885 undo_tf_patches
1886
1887 echo "##########"
1888 )
1889 fi
1890
1891 echo
1892 echo
1893done
1894
1895call_hook pre_package
1896
1897call_hook post_package
1898
1899if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001900 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001901fi
1902
1903echo
1904echo "Done"