blob: a3ba94aa4476af3830e25707fde8d1cdbd4622c6 [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}"
22export tftf_root="${tftf_root:-$workspace/trusted_firmware_tf}"
23export scp_root="${scp_root:-$workspace/scp}"
24scp_tools_root="${scp_tools_root:-$workspace/scp_tools}"
25cc_root="${cc_root:-$ccpathspec}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010026spm_root="${spm_root:-$workspace/spm}"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +000027rmm_root="${rmm_root:-$workspace/tf-rmm}"
Zelalem219df412020-05-17 19:21:20 -050028
29scp_tf_tools_root="$scp_tools_root/scp_tf_tools"
Fathi Boudra422bf772019-12-02 11:10:16 +020030
31# Refspecs
32tf_refspec="$TF_REFSPEC"
33tftf_refspec="$TFTF_REFSPEC"
34scp_refspec="$SCP_REFSPEC"
Zelalem219df412020-05-17 19:21:20 -050035scp_tools_commit="${SCP_TOOLS_COMMIT:-master}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010036spm_refspec="$SPM_REFSPEC"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +000037rmm_refspec="$RMM_REFSPEC"
Fathi Boudra422bf772019-12-02 11:10:16 +020038
39test_config="${TEST_CONFIG:?}"
40test_group="${TEST_GROUP:?}"
41build_configs="${BUILD_CONFIG:?}"
42run_config="${RUN_CONFIG:?}"
Zelalem219df412020-05-17 19:21:20 -050043cc_config="${CC_ENABLE:-}"
Fathi Boudra422bf772019-12-02 11:10:16 +020044
45archive="$artefacts"
46build_log="$artefacts/build.log"
47fiptool="$tf_root/tools/fiptool/fiptool"
48cert_create="$tf_root/tools/cert_create/cert_create"
49
50# Validate $bin_mode
51case "$bin_mode" in
52 "" | debug | release)
53 ;;
54 *)
55 die "Invalid value for bin_mode: $bin_mode"
56 ;;
57esac
58
59# File to save any environem
60hook_env_file="$(mktempfile)"
61
62# Check if a config is valid
63config_valid() {
64 local config="${1?}"
65 if [ -z "$config" ] || [ "$(basename "$config")" = "nil" ]; then
66 return 1
67 fi
68
69 return 0
70}
71
72# Echo from a build wrapper. Print to descriptor 3 that's opened by the build
73# function.
74echo_w() {
75 echo $echo_flags "$@" >&3
76}
77
78# Print a separator to the log file. Intended to be used at the tail end of a pipe
79log_separator() {
80 {
81 echo
82 echo "----------"
83 } >> "$build_log"
84
85 tee -a "$build_log"
86
87 {
88 echo "----------"
89 echo
90 } >> "$build_log"
91}
92
93# Call function $1 if it's defined
94call_func() {
95 if type "${1:?}" &>/dev/null; then
96 echo
97 echo "> ${2:?}:$1()"
98 eval "$1"
99 echo "< $2:$1()"
100 fi
101}
102
Paul Sokolovskybe6510c2024-08-15 21:54:00 +0300103# Retry a command a number of times if it fails. Intended for I/O commands
104# in a CI environment which may be flaky.
105function retry() {
106 for i in $(seq 1 3); do
107 if "$@"; then
108 return 0
109 fi
110 sleep $(( i * 5 ))
111 done
112 return 1
113}
114
Fathi Boudra422bf772019-12-02 11:10:16 +0200115# Call hook $1 in all chosen fragments if it's defined. Hooks are invoked from
116# within a subshell, so any variables set within a hook are lost. Should a
117# variable needs to be set from within a hook, the function 'set_hook_var'
118# should be used
119call_hook() {
120 local func="$1"
121 local config_fragment
122
123 [ -z "$func" ] && return 0
124
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300125 echo "=== Calling hooks: $1 ==="
126
Fathi Boudra422bf772019-12-02 11:10:16 +0200127 : >"$hook_env_file"
128
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +0000129 if [ "$run_config_candidates" ]; then
130 for config_fragment in $run_config_candidates; do
Fathi Boudra422bf772019-12-02 11:10:16 +0200131 (
132 source "$ci_root/run_config/$config_fragment"
133 call_func "$func" "$config_fragment"
134 )
135 done
136 fi
137
138 # Also source test config file
139 (
140 unset "$func"
141 source "$test_config_file"
142 call_func "$func" "$(basename $test_config_file)"
143 )
144
145 # Have any variables set take effect
146 source "$hook_env_file"
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300147
148 echo "=== End calling hooks: $1 ==="
Fathi Boudra422bf772019-12-02 11:10:16 +0200149}
150
151# Set a variable from within a hook
152set_hook_var() {
153 echo "export $1=\"${2?}\"" >> "$hook_env_file"
154}
155
156# Append to an array from within a hook
157append_hook_var() {
158 echo "export $1+=\"${2?}\"" >> "$hook_env_file"
159}
160
161# Have the main build script source a file
162source_later() {
163 echo "source ${1?}" >> "$hook_env_file"
164}
165
166# Setup TF build wrapper function by pointing to a script containing a function
167# that will be called with the TF build commands.
168setup_tf_build_wrapper() {
169 source_later "$ci_root/script/${wrapper?}_wrapper.sh"
170 set_hook_var "tf_build_wrapper" "${wrapper}_wrapper"
171 echo "Setup $wrapper build wrapper."
172}
173
174# Collect .bin files for archiving
175collect_build_artefacts() {
176 if [ ! -d "${from:?}" ]; then
177 return
178 fi
179
Yann Gautier7e9d6cf2023-03-08 14:24:38 +0100180 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 +0200181 echo "You probably are running local CI on local repositories."
182 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
183 die
184 fi
185}
186
187# SCP and MCP binaries are named firmware.{bin,elf}, and are placed under
188# scp/mcp_ramfw and scp/mcp_romfw directories, so can't be collected by
189# collect_build_artefacts function.
190collect_scp_artefacts() {
191 to="${to:?}" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000192 find "$scp_root" \( \( -name "*.bin" -o -name '*.elf' \) -and ! -name 'CMake*' \) -exec bash -c '
Fathi Boudra422bf772019-12-02 11:10:16 +0200193 for file; do
194 ext="$(echo $file | awk -F. "{print \$NF}")"
195 case $file in
Anurag Koulbaedf932021-12-09 12:49:56 +0000196 */firmware-scp_ramfw/bin/*|*/firmware-scp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200197 cp $file $to/scp_ram.$ext
198 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000199 */firmware-scp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200200 cp $file $to/scp_rom.$ext
201 ;;
Anurag Koulbaedf932021-12-09 12:49:56 +0000202 */firmware-mcp_ramfw/bin/*|*/firmware-mcp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200203 cp $file $to/mcp_ram.$ext
204 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000205 */firmware-mcp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200206 cp $file $to/mcp_rom.$ext
207 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000208 */firmware-scp_romfw_bypass/bin/*)
Zelalem219df412020-05-17 19:21:20 -0500209 cp $file $to/scp_rom_bypass.$ext
210 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200211 *)
212 echo "Unknown SCP binary: $file" >&2
213 ;;
214 esac
215 done
216 ' bash '{}' +
217}
218
Manish Pandey1e7be852020-11-09 16:04:48 +0000219# Collect SPM/hafnium artefacts with "secure_" appended to the files
220# generated for SPM(secure hafnium).
221collect_spm_artefacts() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500222 if [ -d "${non_secure_from:?}" ]; then
223 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000224 fi
225
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500226 if [ -d "${secure_from:?}" ]; then
227 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
228 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000229}
230
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200231collect_rfa_artefacts() {
232 if [ ! -d "${from:?}" ]; then
233 return
234 fi
235
236 if ! find "$from" -maxdepth 1 \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +; then
237 echo "You probably are running local CI on local repositories."
238 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
239 die
240 fi
241}
242
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100243# Map the UART ID used for expect with the UART descriptor and port
244# used by the FPGA automation tools.
245map_uart() {
246 local port="${port:?}"
247 local descriptor="${descriptor:?}"
248 local baudrate="${baudrate:?}"
249 local run_root="${archive:?}/run"
250
251 local uart_dir="$run_root/uart${uart:?}"
252 mkdir -p "$uart_dir"
253
254 echo "$port" > "$uart_dir/port"
255 echo "$descriptor" > "$uart_dir/descriptor"
256 echo "$baudrate" > "$uart_dir/baudrate"
257
258 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
259}
260
Fathi Boudra422bf772019-12-02 11:10:16 +0200261# Arrange environment varibles to be set when expect scripts are launched
262set_expect_variable() {
263 local var="${1:?}"
264 local val="${2?}"
265
266 local run_root="${archive:?}/run"
267 local uart_dir="$run_root/uart${uart:?}"
268 mkdir -p "$uart_dir"
269
270 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
271 echo "UART$uart: env has $@"
272}
273
274# Place the binary package a pointer to expect script, and its parameters
275track_expect() {
276 local file="${file:?}"
277 local timeout="${timeout-600}"
278 local run_root="${archive:?}/run"
279
280 local uart_dir="$run_root/uart${uart:?}"
281 mkdir -p "$uart_dir"
282
283 echo "$file" > "$uart_dir/expect"
284 echo "$timeout" > "$uart_dir/timeout"
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700285 if [ -n "$lava_timeout" ]; then
286 set_run_env "lava_timeout" "$lava_timeout"
287 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200288
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700289 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 +0200290
Chris Kayfab6edc2022-11-17 19:18:32 +0000291 if [ ! -z "${port}" ]; then
292 echo "${port}" > "$uart_dir/port"
293 fi
294
Fathi Boudra422bf772019-12-02 11:10:16 +0200295 # The run script assumes UART0 to be primary. If we're asked to set any
296 # other UART to be primary, set a run environment variable to signal
297 # that to the run script
298 if upon "$set_primary"; then
299 echo "Primary UART set to UART$uart."
300 set_run_env "primary_uart" "$uart"
301 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600302
303 # UART used by payload(such as tftf, Linux) may not be the same as the
304 # primary UART. Set a run environment variable to track the payload
305 # UART which is tracked to check if the test has finished sucessfully.
306 if upon "$set_payload_uart"; then
307 echo "Payload uses UART$uart."
308 set_run_env "payload_uart" "$uart"
309 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200310}
311
312# Extract a FIP in $1 using fiptool
313extract_fip() {
314 local fip="$1"
315
316 if is_url "$1"; then
317 url="$1" fetch_file
318 fip="$(basename "$1")"
319 fi
320
321 "$fiptool" unpack "$fip"
322 echo "Extracted FIP: $fip"
323}
324
325# Report build failure by printing a the tail end of build log. Archive the
326# build log for later inspection
327fail_build() {
328 local log_path
329
330 if upon "$jenkins_run"; then
331 log_path="$BUILD_URL/artifact/artefacts/build.log"
332 else
333 log_path="$build_log"
334 fi
335
336 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600337 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200338 echo "[...]"
339 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600340 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200341 echo
342 echo "See $log_path for full output"
343 echo
344 cp -t "$archive" "$build_log"
345 exit 1;
346}
347
348# Build a FIP with supplied arguments
349build_fip() {
350 (
351 echo "Building FIP with arguments: $@"
352 local tf_env="$workspace/tf.env"
353
354 if [ -f "$tf_env" ]; then
355 set -a
356 source "$tf_env"
357 set +a
358 fi
359
360 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
361 ${fip_targets:-fip} &>>"$build_log" || fail_build
362 )
363}
364
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200365# Build any extra rule from TF-A makefile with supplied arguments.
366#
367# This is useful in case you need to build something else than firmware binaries
368# or the FIP.
369build_tf_extra() {
370 (
371 tf_extra_rules=${tf_extra_rules:?}
372 echo "Building extra TF rule(s): $tf_extra_rules"
373 echo " Arguments: $@"
374
375 local tf_env="$workspace/tf.env"
376
377 if [ -f "$tf_env" ]; then
378 set -a
379 source "$tf_env"
380 set +a
381 fi
382
383 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
384 ${tf_extra_rules} &>>"$build_log" || fail_build
385 )
386}
387
Fathi Boudra422bf772019-12-02 11:10:16 +0200388fip_update() {
389 # Before the update process, check if the given image is supported by
390 # the fiptool. It's assumed that both fiptool and cert_create move in
Chris Kay197b1022023-08-16 21:31:41 +0100391 # tandem, and therefore, if one has support, the other has it too.
392 if ! ("$fiptool" update 2>&1 || true) | grep -qe "\s\+--${bin_name:?}"; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200393 return 1
394 fi
395
396 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
397 echo "Updating FIP image: $bin_name"
398 # Update HW config. Without TBBR, it's only a matter of using
399 # the update sub-command of fiptool
400 "$fiptool" update "--$bin_name" "${src:-}" \
401 "$archive/fip.bin"
402 else
403 echo "Updating FIP image (TBBR): $bin_name"
404 # With TBBR, we need to unpack, re-create certificates, and then
405 # recreate the FIP.
406 local fip_dir="$(mktempdir)"
407 local bin common_args stem
408 local rot_key="$(get_tf_opt ROT_KEY)"
409
410 rot_key="${rot_key:?}"
411 if ! is_abs "$rot_key"; then
412 rot_key="$tf_root/$rot_key"
413 fi
414
415 # Arguments only for cert_create
416 local cert_args="-n"
417 cert_args+=" --tfw-nvctr ${nvctr:-31}"
418 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
419 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
420 cert_args+=" --rot-key $rot_key"
421
422 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500423 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200424 "hw-config"
425 "tb-fw-config"
426 "nt-fw-config"
427 "soc-fw-config"
428 "tos-fw-config"
429 )
430
431 # Binaries without key certificates
432 declare -A has_no_key_cert
433 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
434 has_no_key_cert["$bin"]="1"
435 done
436
437 # Binaries without certificates
438 declare -A has_no_cert
439 for bin in "hw-config" "${dyn_config_opts[@]}"; do
440 has_no_cert["$bin"]="1"
441 done
442
443 pushd "$fip_dir"
444
445 # Unpack FIP
446 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
447
448 # Remove all existing certificates
449 rm -f *-cert.bin
450
451 # Copy the binary to be updated
452 cp -f "$src" "${bin_name}.bin"
453
454 # FIP unpack dumps binaries with the same name as the option
455 # used to pack it; likewise for certificates. Reverse-engineer
456 # the command line from the binary output.
457 common_args="--trusted-key-cert trusted_key.crt"
458 for bin in *.bin; do
459 stem="${bin%%.bin}"
460 common_args+=" --$stem $bin"
461 if not_upon "${has_no_cert[$stem]}"; then
462 common_args+=" --$stem-cert $stem.crt"
463 fi
464 if not_upon "${has_no_key_cert[$stem]}"; then
465 common_args+=" --$stem-key-cert $stem-key.crt"
466 fi
467 done
468
469 # Create certificates
470 "$cert_create" $cert_args $common_args &>>"$build_log"
471
472 # Recreate and archive FIP
473 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
474 archive_file "fip.bin"
475
476 popd
477 fi
478}
479
480# Update hw-config in FIP, and remove the original DTB afterwards.
481update_fip_hw_config() {
482 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600483 # in configs:
484 # 1. Where BL2 isn't present
485 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200486 case "1" in
487 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600488 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200489 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000490 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200491 return 0;;
492 esac
493
494 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
495 # Remove the DTB so that model won't load it
496 rm -f "$archive/dtb.bin"
497 fi
498}
499
500get_scp_opt() {
501 (
502 name="${1:?}"
503 if config_valid "$scp_config_file"; then
504 source "$scp_config_file"
505 echo "${!name}"
506 fi
507 )
508}
509
510get_tftf_opt() {
511 (
512 name="${1:?}"
513 if config_valid "$tftf_config_file"; then
514 source "$tftf_config_file"
515 echo "${!name}"
516 fi
517 )
518}
519
520get_tf_opt() {
521 (
522 name="${1:?}"
523 if config_valid "$tf_config_file"; then
524 source "$tf_config_file"
525 echo "${!name}"
526 fi
527 )
528}
529
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000530get_rmm_opt() {
531 (
532 name="${1:?}"
533 if config_valid "$rmm_config_file"; then
534 source "$rmm_config_file"
535 echo "${!name}"
536 fi
537 )
538}
539
Fathi Boudra422bf772019-12-02 11:10:16 +0200540build_tf() {
541 (
542 env_file="$workspace/tf.env"
543 config_file="${tf_build_config:-$tf_config_file}"
544
545 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100546 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200547
548 source "$config_file"
549
550 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000551 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100552 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
553 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200554 mbedtls_dir="$workspace/mbedtls"
555 if [ ! -d "$mbedtls_dir" ]; then
556 mbedtls_ar="$workspace/mbedtls.tar.gz"
557
558 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
559 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500560 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200561 fi
562
563 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
564 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500565 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
566 not_upon "${TF_M_TESTS_PATH}"; then
567 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
568 fi
569 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
570 not_upon "${TF_M_EXTRAS_PATH}"; then
571 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
572 fi
David Vincze82db6932024-02-21 12:05:50 +0100573 if [ "$(get_tf_opt DICE_PROTECTION_ENVIRONMENT)" = 1 ] &&
574 not_upon "${QCBOR_DIR}"; then
575 emit_env "QCBOR_DIR" "$WORKSPACE/qcbor"
576 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200577 if [ -f "$env_file" ]; then
578 set -a
579 source "$env_file"
580 set +a
581 fi
582
Harrison Mutai013f6332022-02-16 16:06:33 +0000583 if is_arm_jenkins_env || upon "$local_ci"; then
584 path_list=(
585 "$llvm_dir/bin"
586 )
587 extend_path "PATH" "path_list"
588 fi
589
Fathi Boudra422bf772019-12-02 11:10:16 +0200590 cd "$tf_root"
591
592 # Always distclean when running on Jenkins. Skip distclean when running
593 # locally and explicitly requested.
594 if upon "$jenkins_run" || not_upon "$dont_clean"; then
595 make distclean &>>"$build_log" || fail_build
596 fi
597
598 # Log build command line. It is left unfolded on purpose to assist
599 # copying to clipboard.
600 cat <<EOF | log_separator >/dev/null
601
602Build command line:
603 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
604
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300605CC version:
606$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200607EOF
608
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000609 if not_upon "$local_ci"; then
610 connect_debugger=0
611 fi
612
Fathi Boudra422bf772019-12-02 11:10:16 +0200613 # Build TF. Since build output is being directed to the build log, have
614 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000615 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000616 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200617 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100618
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100619 if [ "$build_targets" != "doc" ]; then
Harrison Mutai2c2c9172024-04-12 11:24:27 +0000620 (poetry run memory -sr "$tf_build_root" 2>&1 || true) | tee -a "$build_log"
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100621 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200622 )
623}
624
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200625build_rfa() {
626 (
627 config_file="${tf_build_config:-$tf_config_file}"
628
629 # Build the 'all' target by default.
630 build_targets="${tf_build_targets:-all}"
631
632 source "$config_file"
633
Sandrine Afsa21d4a542025-06-24 10:27:15 +0200634 cd "$tf_root"
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200635
636 # Always distclean when running on Jenkins. Skip distclean when running
637 # locally and explicitly requested.
638 if upon "$jenkins_run" || not_upon "$dont_clean"; then
639 echo "Cleaning TF-A..."
640 make -C "$TFA" distclean &>>"$build_log" || fail_build
641
642 echo 'Cleaning RF-A...'
643 cargo clean &>>"$build_log" || fail_build
644 fi
645
646 # Log build command line. It is left unfolded on purpose to assist
647 # copying to clipboard.
648 cat <<EOF | log_separator >/dev/null
649
650Build command line:
651 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG $build_targets
652
653cargo version:
654$(cargo --version 2>&1)
655EOF
656
657 # Build RF-A and TF-A. Since build output is being directed to the build
658 # log, have descriptor 3 point to the current terminal for build
659 # wrappers to vent.
Tomás González72aca672025-06-11 11:26:00 +0100660 eval make $make_j_opts $(cat "$config_file") \
661 DEBUG="$DEBUG" \
Sandrine Afsa07d2bd72025-04-16 17:03:12 +0200662 $build_targets 3>&1 &>>"$build_log" || fail_build
663 )
664}
665
Fathi Boudra422bf772019-12-02 11:10:16 +0200666build_tftf() {
667 (
668 config_file="${tftf_build_config:-$tftf_config_file}"
669
670 # Build tftf target by default
671 build_targets="${tftf_build_targets:-all}"
672
673 source "$config_file"
674
675 cd "$tftf_root"
676
677 # Always distclean when running on Jenkins. Skip distclean when running
678 # locally and explicitly requested.
679 if upon "$jenkins_run" || not_upon "$dont_clean"; then
680 make distclean &>>"$build_log" || fail_build
681 fi
682
683 # TFTF build system cannot reliably deal with -j option, so we avoid
684 # using that.
685
686 # Log build command line
687 cat <<EOF | log_separator >/dev/null
688
689Build command line:
Boyan Karatotev51060ba2024-10-29 16:55:10 +0000690 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
Fathi Boudra422bf772019-12-02 11:10:16 +0200691
692EOF
693
Boyan Karatotev51060ba2024-10-29 16:55:10 +0000694 make $make_j_opts $(cat "$config_file") DEBUG="$DEBUG" V=1 \
Fathi Boudra422bf772019-12-02 11:10:16 +0200695 $build_targets &>>"$build_log" || fail_build
696 )
697}
698
699build_scp() {
700 (
701 config_file="${scp_build_config:-$scp_config_file}"
702
703 source "$config_file"
704
705 cd "$scp_root"
706
707 # Always distclean when running on Jenkins. Skip distclean when running
708 # locally and explicitly requested.
709 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000710 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200711 fi
712
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000713 python3 -m venv .venv
714 . .venv/bin/activate
715
716 # Install extra tools used by CMake build system
717 pip install -r requirements.txt --timeout 30 --retries 15
718
Fathi Boudra422bf772019-12-02 11:10:16 +0200719 # Log build command line. It is left unfolded on purpose to assist
720 # copying to clipboard.
721 cat <<EOF | log_separator >/dev/null
722
723SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000724 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
725 TOOLCHAIN=GNU \
726 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000727 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000728 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200729
730EOF
731
732 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000733 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
734 TOOLCHAIN=GNU \
735 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000736 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000737 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200738 || fail_build
739 )
740}
741
Zelalem219df412020-05-17 19:21:20 -0500742clone_scp_tools() {
743
744 if [ ! -d "$scp_tools_root" ]; then
745 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
746
747 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
748 where="$scp_tools_root" \
749 refspec="${scp_tools_commit}"
750 clone_repo &>>"$build_log"
751 else
752 echo "Already cloned SCP-tools ..." |& log_separator
753 fi
754
755 show_head "$scp_tools_root"
756
757 cd "$scp_tools_root"
758
759 echo "Updating submodules"
760
761 git submodule init
762
763 git submodule update
764
Nicola Mazzucato9b171422023-08-29 15:50:49 +0100765 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 +0000766
Zelalem219df412020-05-17 19:21:20 -0500767 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000768 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500769
770 git show --quiet --no-color | sed 's/^/ > /g'
771}
772
773clone_tf_for_scp_tools() {
774 scp_tools_arm_tf="$scp_tools_root/arm-tf"
775
776 if [ ! -d "$scp_tools_arm_tf" ]; then
777 echo "Cloning TF-4-SCP-tools ..." |& log_separator
778
779 clone_url="$tf_for_scp_tools_src_repo_url"
780 where="$scp_tools_arm_tf"
781
782 git clone "$clone_url" "$where"
783
784 cd "$scp_tools_arm_tf"
785
Joel Goddard3ad03062021-03-16 16:47:42 +0000786 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500787
788 git show --quiet --no-color | sed 's/^/ > /g'
789
790 else
791 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
792 fi
793}
794
795build_scmi_lib_scp_tools() {
796 (
797 cd "$scp_tools_root"
798
799 cd "scmi"
800
801 scp_tools_arm_tf="$scp_tools_root/arm-tf"
802
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600803 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500804
805 std_libs="-I$scp_tools_arm_tf/include/common"
806 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
807 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
808 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
809 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
810 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
811 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
812 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
813 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
814 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
815 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
816 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
817 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
818 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
819
820 cflags="-Og -g"
821 cflags="$cflags -mgeneral-regs-only"
822 cflags="$cflags -mstrict-align"
823 cflags="$cflags -nostdinc"
824 cflags="$cflags -fno-inline"
825 cflags="$cflags -ffreestanding"
826 cflags="$cflags -ffunction-sections"
827 cflags="$cflags -fdata-sections"
828 cflags="$cflags -DAARCH64"
829 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000830 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500831
832 cflags="$cflags $std_libs"
833
Joel Goddard3ad03062021-03-16 16:47:42 +0000834 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500835
836 echo "Building SCMI library (SCP-tools) ..."
837
838 make "CROSS_COMPILE=$cross_compile" \
839 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000840 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500841 "PROTOCOLS=$protocols" \
842 "clean" \
843 "all"
844 )
845}
846
847build_tf_for_scp_tools() {
848
849 cd "$scp_tools_root/arm-tf"
850
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600851 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500852
853 if [ "$1" = "release" ]; then
854 echo "Build TF-4-SCP-Tools rls..."
855 else
856 echo "Build TF-4-SCP-Tools dbg..."
857
858 make realclean
859
860 make "BM_TEST=scmi" \
861 "ARM_BOARD_OPTIMISE_MEM=1" \
862 "BM_CSS=juno" \
863 "CSS_USE_SCMI_SDS_DRIVER=1" \
864 "PLAT=juno" \
865 "DEBUG=1" \
866 "PLATFORM=juno" \
867 "CROSS_COMPILE=$cross_compile" \
868 "BM_WORKSPACE=$scp_tools_root/baremetal"
869
870 archive_file "build/juno/debug/bl1.bin"
871
872 archive_file "build/juno/debug/bl2.bin"
873
874 archive_file "build/juno/debug/bl31.bin"
875 fi
876}
877
878build_fip_for_scp_tools() {
879
880 cd "$scp_tools_root/arm-tf"
881
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600882 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500883
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000884 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500885 make fiptool
886 echo "Make FIP 4 SCP-Tools rls..."
887
888 else
889 make fiptool
890 echo "Make FIP 4 SCP-Tools dbg..."
891
892 make "PLAT=juno" \
893 "all" \
894 "fip" \
895 "DEBUG=1" \
896 "CROSS_COMPILE=$cross_compile" \
897 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
898 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000899 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500900
901 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
902 fi
903}
904
905build_cc() {
906# Building code coverage plugin
907 ARM_DIR=/arm
908 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
909 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
910 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
911 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
912 exit -1
913 fi # Error if arm warehouse not found
914 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
915
916 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
917}
918
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100919build_spm() {
920 (
921 env_file="$workspace/spm.env"
922 config_file="${spm_build_config:-$spm_config_file}"
923
924 source "$config_file"
925
926 if [ -f "$env_file" ]; then
927 set -a
928 source "$env_file"
929 set +a
930 fi
931
932 cd "$spm_root"
933
934 # Always clean when running on Jenkins. Skip clean when running
935 # locally and explicitly requested.
936 if upon "$jenkins_run" || not_upon "$dont_clean"; then
937 # make clean fails on a fresh repo where the project has not
938 # yet been built. Hence only clean if out/reference directory
939 # already exists.
940 if [ -d "out/reference" ]; then
941 make clean &>>"$build_log" || fail_build
942 fi
943 fi
944
945 # Log build command line. It is left unfolded on purpose to assist
946 # copying to clipboard.
947 cat <<EOF | log_separator >/dev/null
948
949Build command line:
950 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
951
952EOF
953
954 # Build SPM. Since build output is being directed to the build log, have
955 # descriptor 3 point to the current terminal for build wrappers to vent.
956 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
957 || fail_build
958 )
959}
Zelalem219df412020-05-17 19:21:20 -0500960
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000961build_rmm() {
962 (
963 env_file="$workspace/rmm.env"
964 config_file="${rmm_build_config:-$rmm_config_file}"
965
966 # Build fiptool and all targets by default
967 build_targets="${rmm_build_targets}"
968 export CROSS_COMPILE="${aarch64_none_elf_prefix}"
969
970 source "$config_file"
971
972 if [ -f "$env_file" ]; then
973 set -a
974 source "$env_file"
975 set +a
976 fi
977
978 cd "$rmm_root"
979
980 if [ -f "$rmm_root/requirements.txt" ]; then
981 export PATH="$HOME/.local/bin:$PATH"
982 python3 -m pip install --upgrade pip
983 python3 -m pip install -r "$rmm_root/requirements.txt"
984 fi
985
986 # Always distclean when running on Jenkins. Skip distclean when running
987 # locally and explicitly requested.
988 if upon "$jenkins_run" || not_upon "$dont_clean"; then
989 # Remove 'rmm\build' folder
990 echo "Removing $rmm_build_root..."
991 rm -rf $rmm_build_root
992 fi
993
994 # Log build command line. It is left unfolded on purpose to assist
995 # copying to clipboard.
996 cat <<EOF | log_separator >/dev/null
997
998Build command line:
999 cmake -DRMM_CONFIG=${plat}_defcfg $cmake_gen -S $rmm_root -B $rmm_build_root -DCMAKE_BUILD_TYPE=$cmake_build_type
1000 cmake --build $rmm_build_root $make_j_opts -v
1001EOF
1002 if not_upon "$local_ci"; then
1003 connect_debugger=0
1004 fi
1005
1006 cmake -DRMM_CONFIG=${plat}_defcfg $cmake_gen -S $rmm_root -B $rmm_build_root -DCMAKE_BUILD_TYPE=$cmake_build_type
1007 cmake --build $rmm_build_root $make_j_opts -v 3>&1 &>>"$build_log" || fail_build
1008 )
1009}
1010
Fathi Boudra422bf772019-12-02 11:10:16 +02001011# Set metadata for the whole package so that it can be used by both Jenkins and
1012# shell
1013set_package_var() {
1014 env_file="$artefacts/env" emit_env "$@"
1015}
1016
1017set_tf_build_targets() {
1018 echo "Set build target to '${targets:?}'"
1019 set_hook_var "tf_build_targets" "$targets"
1020}
1021
1022set_tftf_build_targets() {
1023 echo "Set build target to '${targets:?}'"
1024 set_hook_var "tftf_build_targets" "$targets"
1025}
1026
1027set_scp_build_targets() {
1028 echo "Set build target to '${targets:?}'"
1029 set_hook_var "scp_build_targets" "$targets"
1030}
1031
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001032set_spm_build_targets() {
1033 echo "Set build target to '${targets:?}'"
1034 set_hook_var "spm_build_targets" "$targets"
1035}
1036
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001037set_spm_out_dir() {
1038 echo "Set SPMC binary build to '${out_dir:?}'"
1039 set_hook_var "spm_secure_out_dir" "$out_dir"
1040}
Fathi Boudra422bf772019-12-02 11:10:16 +02001041# Look under $archive directory for known files such as blX images, kernel, DTB,
1042# initrd etc. For each known file foo, if foo.bin exists, then set variable
1043# foo_bin to the path of the file. Make the path relative to the workspace so as
1044# to remove any @ characters, which Jenkins inserts for parallel runs. If the
1045# file doesn't exist, unset its path.
1046set_default_bin_paths() {
1047 local image image_name image_path path
1048 local archive="${archive:?}"
1049 local set_vars
1050 local var
1051
1052 pushd "$archive"
1053
1054 for file in *.bin; do
1055 # Get a shell variable from the file's stem
1056 var_name="${file%%.*}_bin"
1057 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
1058
1059 # Skip setting the variable if it's already
1060 if [ "${!var_name}" ]; then
1061 echo "Note: not setting $var_name; already set to ${!var_name}"
1062 continue
1063 else
1064 set_vars+="$var_name "
1065 fi
1066
1067 eval "$var_name=$file"
1068 done
1069
1070 echo "Binary paths set for: "
1071 {
1072 for var in $set_vars; do
1073 echo -n "\$$var "
1074 done
1075 } | fmt -80 | sed 's/^/ /'
1076 echo
1077
1078 popd
1079}
1080
1081gen_model_params() {
1082 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +00001083 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +02001084
1085 set_default_bin_paths
1086 echo "Generating model parameter for $model..."
1087 source "$ci_root/model/${model:?}.sh"
1088 archive_file "$model_param_file"
1089}
1090
1091set_model_path() {
1092 set_run_env "model_path" "${1:?}"
1093}
1094
Zelalem1af7a7b2020-08-04 17:34:32 -05001095set_model_env() {
1096 local var="${1:?}"
1097 local val="${2?}"
1098 local run_root="${archive:?}/run"
1099
1100 mkdir -p "$run_root"
1101 echo "export $var=$val" >> "$run_root/model_env"
1102}
Fathi Boudra422bf772019-12-02 11:10:16 +02001103set_run_env() {
1104 local var="${1:?}"
1105 local val="${2?}"
1106 local run_root="${archive:?}/run"
1107
1108 mkdir -p "$run_root"
1109 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
1110}
1111
1112show_head() {
1113 # Display HEAD descripton
1114 pushd "$1"
1115 git show --quiet --no-color | sed 's/^/ > /g'
1116 echo
1117 popd
1118}
1119
1120# Choose debug binaries to run; by default, release binaries are chosen to run
1121use_debug_bins() {
1122 local run_root="${archive:?}/run"
1123
1124 echo "Choosing debug binaries for execution"
1125 set_package_var "BIN_MODE" "debug"
1126}
1127
1128assert_can_git_clone() {
1129 local name="${1:?}"
1130 local dir="${!name}"
1131
1132 # If it doesn't exist, it can be cloned into
1133 if [ ! -e "$dir" ]; then
1134 return 0
1135 fi
1136
1137 # If it's a directory, it must be a Git clone already
1138 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
1139 # No need to clone again
1140 echo "Using existing git clone for $name: $dir"
1141 return 1
1142 fi
1143
1144 die "Path $dir exists but is not a git clone"
1145}
1146
1147clone_repo() {
1148 if ! is_url "${clone_url?}"; then
1149 # For --depth to take effect on local paths, it needs to use the
1150 # file:// scheme.
1151 clone_url="file://$clone_url"
1152 fi
1153
1154 git clone -q --depth 1 "$clone_url" "${where?}"
1155 if [ "$refspec" ]; then
1156 pushd "$where"
1157 git fetch -q --depth 1 origin "$refspec"
1158 git checkout -q FETCH_HEAD
1159 popd
1160 fi
1161}
1162
1163build_unstable() {
1164 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1165}
1166
1167undo_patch_record() {
1168 if [ ! -f "${patch_record:?}" ]; then
1169 return
1170 fi
1171
1172 # Undo patches in reverse
1173 echo
1174 for patch_name in $(tac "$patch_record"); do
1175 echo "Undoing $patch_name..."
1176 if ! git apply -R "$ci_root/patch/$patch_name"; then
1177 if upon "$local_ci"; then
1178 echo
1179 echo "Your local directory may have been dirtied."
1180 echo
1181 fi
1182 fail_build
1183 fi
1184 done
1185
1186 rm -f "$patch_record"
1187}
1188
1189undo_local_patches() {
1190 pushd "$tf_root"
1191 patch_record="$tf_patch_record" undo_patch_record
1192 popd
1193
1194 if [ -d "$tftf_root" ]; then
1195 pushd "$tftf_root"
1196 patch_record="$tftf_patch_record" undo_patch_record
1197 popd
1198 fi
1199}
1200
1201undo_tftf_patches() {
1202 pushd "$tftf_root"
1203 patch_record="$tftf_patch_record" undo_patch_record
1204 popd
1205}
1206
1207undo_tf_patches() {
1208 pushd "$tf_root"
1209 patch_record="$tf_patch_record" undo_patch_record
1210 popd
1211}
1212
1213apply_patch() {
1214 # If skip_patches is set, the developer has applied required patches
1215 # manually. They probably want to keep them applied for debugging
1216 # purposes too. This means we don't have to apply/revert them as part of
1217 # build process.
1218 if upon "$skip_patches"; then
1219 echo "Skipped applying ${1:?}..."
1220 return 0
1221 else
1222 echo "Applying ${1:?}..."
1223 fi
1224
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +02001225 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001226 echo "Skipping already applied ${1:?}"
1227 return 0
1228 fi
1229
Fathi Boudra422bf772019-12-02 11:10:16 +02001230 if git apply < "$ci_root/patch/$1"; then
1231 echo "$1" >> "${patch_record:?}"
1232 else
1233 if upon "$local_ci"; then
1234 undo_local_patches
1235 fi
1236 fail_build
1237 fi
1238}
1239
1240apply_tftf_patch() {
1241 pushd "$tftf_root"
1242 patch_record="$tftf_patch_record" apply_patch "$1"
1243 popd
1244}
1245
1246apply_tf_patch() {
1247 pushd "$tf_root"
1248 patch_record="$tf_patch_record" apply_patch "$1"
1249 popd
1250}
1251
1252# Clear workspace for a local run
Leandro Bellibe7b8fa2024-07-18 10:14:22 +01001253if not_upon "$jenkins_run" && not_upon "$dont_clean"; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001254 rm -rf "$workspace"
1255
1256 # Clear residue from previous runs
1257 rm -rf "$archive"
1258fi
1259
1260mkdir -p "$workspace"
1261mkdir -p "$archive"
1262set_package_var "TEST_CONFIG" "$test_config"
1263
1264{
1265echo
1266echo "CONFIGURATION: $test_group/$test_config"
1267echo
1268} |& log_separator
1269
1270tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1271tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1272scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001273scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001274spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001275rmm_config="$(echo "$build_configs" | awk -F, '{print $6}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001276
1277test_config_file="$ci_root/group/$test_group/$test_config"
1278
1279tf_config_file="$ci_root/tf_config/$tf_config"
1280tftf_config_file="$ci_root/tftf_config/$tftf_config"
1281scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001282scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001283spm_config_file="$ci_root/spm_config/$spm_config"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001284rmm_config_file="$ci_root/rmm_config/$rmm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001285
1286# File that keeps track of applied patches
1287tf_patch_record="$workspace/tf_patches"
1288tftf_patch_record="$workspace/tftf_patches"
1289
1290pushd "$workspace"
1291
1292if ! config_valid "$tf_config"; then
1293 tf_config=
1294else
1295 echo "Trusted Firmware config:"
1296 echo
1297 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1298 echo
1299fi
1300
1301if ! config_valid "$tftf_config"; then
1302 tftf_config=
1303else
1304 echo "Trusted Firmware TF config:"
1305 echo
1306 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1307 echo
1308fi
1309
1310if ! config_valid "$scp_config"; then
1311 scp_config=
1312else
1313 echo "SCP firmware config:"
1314 echo
1315 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1316 echo
1317fi
1318
Zelalem219df412020-05-17 19:21:20 -05001319if ! config_valid "$scp_tools_config"; then
1320 scp_tools_config=
1321else
1322 echo "SCP Tools config:"
1323 echo
1324 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001325fi
1326
1327if ! config_valid "$spm_config"; then
1328 spm_config=
1329else
1330 echo "SPM config:"
1331 echo
1332 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001333 echo
1334fi
1335
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001336# File that keeps track of applied patches
1337rmm_patch_record="$workspace/rmm_patches"
1338
1339if ! config_valid "$rmm_config"; then
1340 rmm_config=
1341else
1342 echo "Trusted Firmware RMM config:"
1343 echo
1344 sort "$rmm_config_file" | sed '/^\s*$/d;s/^/\t/'
1345 echo
1346fi
1347
Fathi Boudra422bf772019-12-02 11:10:16 +02001348if ! config_valid "$run_config"; then
1349 run_config=
1350fi
1351
1352if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1353 # If the Trusted Firmware repository has already been checked out, use
1354 # that location. Otherwise, clone one ourselves.
1355 echo "Cloning Trusted Firmware..."
1356 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1357 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1358 show_head "$tf_root"
1359fi
1360
1361if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1362 # If the Trusted Firmware TF repository has already been checked out,
1363 # use that location. Otherwise, clone one ourselves.
1364 echo "Cloning Trusted Firmware TF..."
1365 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1366 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1367 show_head "$tftf_root"
1368fi
1369
1370if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1371 # If the SCP firmware repository has already been checked out,
1372 # use that location. Otherwise, clone one ourselves.
1373 echo "Cloning SCP Firmware..."
1374 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1375 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1376
1377 pushd "$scp_root"
1378
1379 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001380 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001381 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1382 fi
1383
1384 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1385 # then to project filer if accessible.
1386 if [ -z "$cmsis_reference" ]; then
1387 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1388 if [ -d "$cmsis_ref_repo" ]; then
1389 cmsis_reference="--reference $cmsis_ref_repo"
1390 fi
1391 fi
1392
1393 git submodule -q update $cmsis_reference --init
1394
1395 popd
1396
1397 show_head "$scp_root"
1398fi
1399
Zelalem219df412020-05-17 19:21:20 -05001400if [ -n "$cc_config" ] ; then
1401 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1402 # Copy code coverage repository
1403 echo "Cloning Code Coverage..."
1404 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1405 show_head "$cc_root"
1406 fi
1407fi
1408
Daniel Boulby25385ab2023-12-14 14:36:25 +00001409if [ "$spm_config" ] ; then
1410 if assert_can_git_clone "spm_root"; then
1411 # If the SPM repository has already been checked out, use
1412 # that location. Otherwise, clone one ourselves.
1413 echo "Cloning SPM..."
1414 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1415 where="$spm_root" refspec="$SPM_REFSPEC" \
1416 clone_repo &>>"$build_log"
1417 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001418
1419 # Query git submodules
1420 pushd "$spm_root"
Daniel Boulby25385ab2023-12-14 14:36:25 +00001421 # Check if submodules need initialising
Paul Sokolovskyad274422024-09-01 10:27:56 +03001422
1423 # This handling is needed to reliably fetch submodules
1424 # in CI environment.
1425 for subm in $(git submodule status | awk '/^-/ {print $2}'); do
1426 for i in $(seq 1 7); do
1427 git submodule init $subm
1428 if git submodule update $subm; then
1429 break
1430 fi
1431 git submodule deinit --force $subm
1432 echo "Retrying $subm"
1433 sleep $((RANDOM % 10 + 5))
1434 done
1435 done
1436
1437 git submodule status
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001438 popd
1439
1440 show_head "$spm_root"
1441fi
1442
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001443if [ "$rmm_config" ] && assert_can_git_clone "rmm_root"; then
Manish V Badarkhe41909452025-04-11 12:06:45 +01001444 # If the RMM repository has already been checked out,
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001445 # use that location. Otherwise, clone one ourselves.
1446 echo "Cloning TF-RMM..."
1447 clone_url="${RMM_CHECKOUT_LOC:-$rmm_src_repo_url}" where="$rmm_root" \
1448 refspec="$RMM_REFSPEC" clone_repo &>>"$build_log"
1449 show_head "$rmm_root"
1450fi
1451
Fathi Boudra422bf772019-12-02 11:10:16 +02001452if [ "$run_config" ]; then
1453 # Get candidates for run config
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001454 run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \
Fathi Boudra422bf772019-12-02 11:10:16 +02001455 "$run_config")"
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001456 if [ -z "$run_config_candidates" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001457 die "No run config candidates!"
1458 else
1459 echo
1460 echo "Chosen fragments:"
1461 echo
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001462 echo "$run_config_candidates" | sed 's/^\|\n/\t/g'
Fathi Boudra422bf772019-12-02 11:10:16 +02001463 echo
Harrison Mutai4dfe1192024-07-03 12:35:38 +00001464
1465 if [ ! -n "$bin_mode" ]; then
1466 if echo $run_config_candidates | grep -wq "debug"; then
1467 bin_mode="debug"
1468 else
1469 bin_mode="release"
1470 fi
1471 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001472 fi
1473fi
1474
1475call_hook "test_setup"
1476echo
1477
1478if upon "$local_ci"; then
1479 # For local runs, since each config is tried in sequence, it's
1480 # advantageous to run jobs in parallel
1481 if [ "$make_j" ]; then
1482 make_j_opts="-j $make_j"
1483 else
1484 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1485 if [ "$n_cores" ]; then
1486 make_j_opts="-j $n_cores"
1487 fi
1488 fi
1489fi
1490
Harrison Mutai07043e92023-07-06 09:41:12 +01001491# Install python build dependencies
1492if is_arm_jenkins_env; then
1493 source "$ci_root/script/install_python_deps.sh"
1494fi
1495
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001496# Print CMake version
1497cmake_ver=$(echo `cmake --version | sed -n '1p'`)
1498echo "Using $cmake_ver"
1499
1500# Check for Ninja
1501if [ -x "$(command -v ninja)" ]; then
1502 # Print Ninja version
1503 ninja_ver=$(echo `ninja --version | sed -n '1p'`)
1504 echo "Using ninja $ninja_ver"
1505 export cmake_gen="-G Ninja"
1506else
1507 echo 'Ninja is not installed'
1508 export cmake_gen=""
1509fi
1510
1511undo_rmm_patches() {
1512 pushd "$rmm_root"
1513 patch_record="$rmm_patch_record" undo_patch_record
1514 popd
1515}
1516
Fathi Boudra422bf772019-12-02 11:10:16 +02001517modes="${bin_mode:-debug release}"
1518for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001519 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001520 # Build with a temporary archive
1521 build_archive="$archive/$mode"
1522 mkdir "$build_archive"
1523
1524 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001525 export bin_mode="debug"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001526 cmake_build_type="Debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001527 DEBUG=1
1528 else
Zelalem219df412020-05-17 19:21:20 -05001529 export bin_mode="release"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001530 cmake_build_type="Release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001531 DEBUG=0
1532 fi
1533
1534 # Perform builds in a subshell so as not to pollute the current and
1535 # subsequent builds' environment
1536
Zelalem219df412020-05-17 19:21:20 -05001537 if config_valid "$cc_config"; then
1538 # Build code coverage plugin
1539 build_cc
1540 fi
1541
Fathi Boudra422bf772019-12-02 11:10:16 +02001542 # SCP build
1543 if config_valid "$scp_config"; then
1544 (
1545 echo "##########"
1546
1547 # Source platform-specific utilities
1548 plat="$(get_scp_opt PRODUCT)"
1549 plat_utils="$ci_root/${plat}_utils.sh"
1550 if [ -f "$plat_utils" ]; then
1551 source "$plat_utils"
1552 fi
1553
1554 archive="$build_archive"
1555 scp_build_root="$scp_root/build"
1556
1557 echo "Building SCP Firmware ($mode) ..." |& log_separator
1558
1559 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001560 to="$archive" collect_scp_artefacts
1561
1562 echo "##########"
1563 echo
1564 )
1565 fi
1566
Zelalem219df412020-05-17 19:21:20 -05001567 # SCP-tools build
1568 if config_valid "$scp_tools_config"; then
1569 (
1570 echo "##########"
1571
1572 archive="$build_archive"
1573 scp_tools_build_root="$scp_tools_root/build"
1574
1575 clone_scp_tools
1576
1577 echo "##########"
1578 echo
1579
1580 echo "##########"
1581 clone_tf_for_scp_tools
1582 echo "##########"
1583 echo
1584 )
1585 fi
1586
Fathi Boudra422bf772019-12-02 11:10:16 +02001587 # TFTF build
1588 if config_valid "$tftf_config"; then
1589 (
1590 echo "##########"
1591
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001592 plat_utils="$(get_tf_opt PLAT_UTILS)"
1593 if [ -z ${plat_utils} ]; then
1594 # Source platform-specific utilities.
1595 plat="$(get_tftf_opt PLAT)"
1596 plat_utils="$ci_root/${plat}_utils.sh"
1597 else
1598 # Source platform-specific utilities by
1599 # using plat_utils name.
1600 plat_utils="$ci_root/${plat_utils}.sh"
1601 fi
1602
Fathi Boudra422bf772019-12-02 11:10:16 +02001603 if [ -f "$plat_utils" ]; then
1604 source "$plat_utils"
1605 fi
1606
1607 archive="$build_archive"
1608 tftf_build_root="$tftf_root/build"
1609
1610 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1611
1612 # Call pre-build hook
1613 call_hook pre_tftf_build
1614
1615 build_tftf
1616
1617 from="$tftf_build_root" to="$archive" collect_build_artefacts
1618
1619 # Clear any local changes made by applied patches
1620 undo_tftf_patches
1621
1622 echo "##########"
1623 echo
1624 )
1625 fi
1626
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001627 # SPM build
1628 if config_valid "$spm_config"; then
1629 (
1630 echo "##########"
1631
1632 # Get platform name from spm_config file
1633 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1634 plat_utils="$ci_root/${plat}_utils.sh"
1635 if [ -f "$plat_utils" ]; then
1636 source "$plat_utils"
1637 fi
1638
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001639 # Call pre-build hook
1640 call_hook pre_spm_build
1641
Manish Pandey1e7be852020-11-09 16:04:48 +00001642 # SPM build generates two sets of binaries, one for normal and other
1643 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001644 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001645 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1646 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001647
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001648 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001649 echo "Building SPM ($mode) ..." |& log_separator
1650
1651 # NOTE: mode has no effect on SPM build (for now), hence debug
1652 # mode is built but subsequent build using release mode just
1653 # goes through with "nothing to do".
1654 build_spm
1655
1656 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001657 cksum $spm_build_root/hafnium.bin
1658
1659 # Some platforms only have secure configuration enabled. Hence,
1660 # non secure hanfnium binary might not be built.
1661 if [ -f $hafnium_build_root/hafnium.bin ]; then
1662 cksum $hafnium_build_root/hafnium.bin
1663 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001664
Manish Pandey1e7be852020-11-09 16:04:48 +00001665 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001666
1667 echo "##########"
1668 echo
1669 )
1670 fi
1671
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001672 # TF RMM build
1673 if config_valid "$rmm_config"; then
1674 (
1675 echo "##########"
1676
1677 plat_utils="$(get_rmm_opt PLAT_UTILS)"
1678 if [ -z ${plat_utils} ]; then
1679 # Source platform-specific utilities.
1680 plat="$(get_rmm_opt PLAT)"
1681 plat_utils="$ci_root/${plat}_utils.sh"
1682 else
1683 # Source platform-specific utilities by
1684 # using plat_utils name.
1685 plat_utils="$ci_root/${plat_utils}.sh"
1686 fi
1687
1688 if [ -f "$plat_utils" ]; then
1689 source "$plat_utils"
1690 fi
1691
1692 archive="$build_archive"
1693 rmm_build_root="$rmm_root/build"
1694
1695 echo "Building Trusted Firmware RMM ($mode) ..." |& log_separator
1696
1697 #call_hook pre_rmm_build
1698 build_rmm
1699
1700 # Collect all rmm.* files: rmm.img, rmm.elf, rmm.dump, rmm.map
1701 from="$rmm_build_root" to="$archive" collect_build_artefacts
1702
1703 # Clear any local changes made by applied patches
1704 undo_rmm_patches
1705
1706 echo "##########"
1707 )
1708 fi
1709
Fathi Boudra422bf772019-12-02 11:10:16 +02001710 # TF build
1711 if config_valid "$tf_config"; then
1712 (
1713 echo "##########"
1714
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001715 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001716 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1717
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001718 if [ -z ${plat_utils} ]; then
1719 # Source platform-specific utilities.
1720 plat="$(get_tf_opt PLAT)"
1721 plat_utils="$ci_root/${plat}_utils.sh"
1722 else
1723 # Source platform-specific utilities by
1724 # using plat_utils name.
1725 plat_utils="$ci_root/${plat_utils}.sh"
1726 fi
1727
Fathi Boudra422bf772019-12-02 11:10:16 +02001728 if [ -f "$plat_utils" ]; then
1729 source "$plat_utils"
1730 fi
1731
Chris Kaye5a486b2023-08-04 11:50:31 +00001732 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1733 fvp_tsram_size="${fvp_tsram_size:-256}"
1734
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001735 if not_upon "$(get_tf_opt RUST)"; then
1736 poetry -C "$tf_root" install --without docs
1737 fi
Chris Kayd0837902021-11-17 10:17:52 +00001738
Fathi Boudra422bf772019-12-02 11:10:16 +02001739 archive="$build_archive"
Fathi Boudra422bf772019-12-02 11:10:16 +02001740
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001741 if not_upon "$(get_tf_opt RUST)"; then
1742 tf_build_root="$tf_root/build"
1743 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1744 else
1745 # Clone TF-A repo if required. Save its path into the
1746 # special variable "TFA", which is used by RF-A build
1747 # system.
1748 export TFA="${TFA-$workspace/tfa}"
1749 if assert_can_git_clone "TFA"; then
1750 echo "Cloning TF-A..."
1751 clone_url="$tf_src_repo_url" where="$TFA" clone_repo
1752 fi
1753 show_head "$TFA"
1754 poetry -C "$TFA" install --without docs
Fathi Boudra422bf772019-12-02 11:10:16 +02001755
Sandrine Afsa21d4a542025-06-24 10:27:15 +02001756 rfa_build_root="$tf_root/target"
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001757 echo "Building Rusted Firmware ($mode) ..." |& log_separator
1758
1759 if not_upon "$local_ci"; then
1760 # In the CI Dockerfile, rustup is installed by the root user in the
1761 # non-default location /usr/local/rustup, so $RUSTUP_HOME is required to
1762 # access rust config e.g. default toolchains and run cargo
1763 #
1764 # Leave $CARGO_HOME blank so when this script is run in CI by the buildslave
1765 # user, it uses the default /home/buildslave/.cargo directory which it has
1766 # write permissions for - that allows it to download new crates during
1767 # compilation
1768 #
1769 # The buildslave user does not have write permissions to the default
1770 # $CARGO_HOME=/usr/local/cargo dir and so will error when trying to download
1771 # new crates otherwise
1772 #
1773 # note: $PATH still contains /usr/local/cargo/bin at this point so cargo is
1774 # still run via the root installation
1775 #
1776 # see https://github.com/rust-lang/rustup/issues/1085
1777 set_hook_var "RUSTUP_HOME" "/usr/local/rustup"
1778 fi
Tomás Gonzáleze72d5382024-11-13 14:08:25 +00001779 fi
1780
Fathi Boudra422bf772019-12-02 11:10:16 +02001781 # Call pre-build hook
1782 call_hook pre_tf_build
1783
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001784 if upon "$(get_tf_opt RUST)"; then
1785 build_rfa
1786 else
1787 build_tf
1788 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001789
1790 # Call post-build hook
1791 call_hook post_tf_build
1792
1793 # Pre-archive hook
1794 call_hook pre_tf_archive
1795
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001796 if not_upon "$(get_tf_opt RUST)"; then
1797 from="$tf_build_root" to="$archive" collect_build_artefacts
1798 else
1799 from="$rfa_build_root" to="$archive" collect_rfa_artefacts
Zachary Leaf5494d732024-10-22 10:49:36 +01001800 fi
1801
Fathi Boudra422bf772019-12-02 11:10:16 +02001802 # Post-archive hook
1803 call_hook post_tf_archive
1804
1805 call_hook fetch_tf_resource
1806 call_hook post_fetch_tf_resource
1807
Chris Kay4e8aaf12022-09-01 15:21:55 +01001808 # Generate LAVA job files if necessary
1809 call_hook generate_lava_job_template
1810 call_hook generate_lava_job
1811
Fathi Boudra422bf772019-12-02 11:10:16 +02001812 # Clear any local changes made by applied patches
1813 undo_tf_patches
1814
1815 echo "##########"
1816 )
1817 fi
1818
1819 echo
1820 echo
1821done
1822
1823call_hook pre_package
1824
1825call_hook post_package
1826
1827if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001828 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001829fi
1830
1831echo
1832echo "Done"