blob: f98daf1241fa9d9cebffe6d38ca06c738233c24b [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
Manish V Badarkhe84c3a482025-04-16 08:15:38 +0100180 if ! find "$from" \( -name "*.bin" -o -name '*.elf' -o -name '*.dtb' -o -name '*.axf' -o -name '*.stm32' -o -name '*.img' \) -exec cp -t "${to:?}" '{}' +; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200181 echo "You probably are running local CI on local repositories."
182 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
183 die
184 fi
185}
186
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
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100231# Map the UART ID used for expect with the UART descriptor and port
232# used by the FPGA automation tools.
233map_uart() {
234 local port="${port:?}"
235 local descriptor="${descriptor:?}"
236 local baudrate="${baudrate:?}"
237 local run_root="${archive:?}/run"
238
239 local uart_dir="$run_root/uart${uart:?}"
240 mkdir -p "$uart_dir"
241
242 echo "$port" > "$uart_dir/port"
243 echo "$descriptor" > "$uart_dir/descriptor"
244 echo "$baudrate" > "$uart_dir/baudrate"
245
246 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
247}
248
Fathi Boudra422bf772019-12-02 11:10:16 +0200249# Arrange environment varibles to be set when expect scripts are launched
250set_expect_variable() {
251 local var="${1:?}"
252 local val="${2?}"
253
254 local run_root="${archive:?}/run"
255 local uart_dir="$run_root/uart${uart:?}"
256 mkdir -p "$uart_dir"
257
258 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
259 echo "UART$uart: env has $@"
260}
261
262# Place the binary package a pointer to expect script, and its parameters
263track_expect() {
264 local file="${file:?}"
265 local timeout="${timeout-600}"
266 local run_root="${archive:?}/run"
267
268 local uart_dir="$run_root/uart${uart:?}"
269 mkdir -p "$uart_dir"
270
271 echo "$file" > "$uart_dir/expect"
272 echo "$timeout" > "$uart_dir/timeout"
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700273 if [ -n "$lava_timeout" ]; then
274 set_run_env "lava_timeout" "$lava_timeout"
275 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200276
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700277 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 +0200278
Chris Kayfab6edc2022-11-17 19:18:32 +0000279 if [ ! -z "${port}" ]; then
280 echo "${port}" > "$uart_dir/port"
281 fi
282
Fathi Boudra422bf772019-12-02 11:10:16 +0200283 # The run script assumes UART0 to be primary. If we're asked to set any
284 # other UART to be primary, set a run environment variable to signal
285 # that to the run script
286 if upon "$set_primary"; then
287 echo "Primary UART set to UART$uart."
288 set_run_env "primary_uart" "$uart"
289 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600290
291 # UART used by payload(such as tftf, Linux) may not be the same as the
292 # primary UART. Set a run environment variable to track the payload
293 # UART which is tracked to check if the test has finished sucessfully.
294 if upon "$set_payload_uart"; then
295 echo "Payload uses UART$uart."
296 set_run_env "payload_uart" "$uart"
297 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200298}
299
300# Extract a FIP in $1 using fiptool
301extract_fip() {
302 local fip="$1"
303
304 if is_url "$1"; then
305 url="$1" fetch_file
306 fip="$(basename "$1")"
307 fi
308
309 "$fiptool" unpack "$fip"
310 echo "Extracted FIP: $fip"
311}
312
313# Report build failure by printing a the tail end of build log. Archive the
314# build log for later inspection
315fail_build() {
316 local log_path
317
318 if upon "$jenkins_run"; then
319 log_path="$BUILD_URL/artifact/artefacts/build.log"
320 else
321 log_path="$build_log"
322 fi
323
324 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600325 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200326 echo "[...]"
327 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600328 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200329 echo
330 echo "See $log_path for full output"
331 echo
332 cp -t "$archive" "$build_log"
333 exit 1;
334}
335
336# Build a FIP with supplied arguments
337build_fip() {
338 (
339 echo "Building FIP with arguments: $@"
340 local tf_env="$workspace/tf.env"
341
342 if [ -f "$tf_env" ]; then
343 set -a
344 source "$tf_env"
345 set +a
346 fi
347
348 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
349 ${fip_targets:-fip} &>>"$build_log" || fail_build
350 )
351}
352
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200353# Build any extra rule from TF-A makefile with supplied arguments.
354#
355# This is useful in case you need to build something else than firmware binaries
356# or the FIP.
357build_tf_extra() {
358 (
359 tf_extra_rules=${tf_extra_rules:?}
360 echo "Building extra TF rule(s): $tf_extra_rules"
361 echo " Arguments: $@"
362
363 local tf_env="$workspace/tf.env"
364
365 if [ -f "$tf_env" ]; then
366 set -a
367 source "$tf_env"
368 set +a
369 fi
370
371 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
372 ${tf_extra_rules} &>>"$build_log" || fail_build
373 )
374}
375
Fathi Boudra422bf772019-12-02 11:10:16 +0200376fip_update() {
377 # Before the update process, check if the given image is supported by
378 # the fiptool. It's assumed that both fiptool and cert_create move in
Chris Kay197b1022023-08-16 21:31:41 +0100379 # tandem, and therefore, if one has support, the other has it too.
380 if ! ("$fiptool" update 2>&1 || true) | grep -qe "\s\+--${bin_name:?}"; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200381 return 1
382 fi
383
384 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
385 echo "Updating FIP image: $bin_name"
386 # Update HW config. Without TBBR, it's only a matter of using
387 # the update sub-command of fiptool
388 "$fiptool" update "--$bin_name" "${src:-}" \
389 "$archive/fip.bin"
390 else
391 echo "Updating FIP image (TBBR): $bin_name"
392 # With TBBR, we need to unpack, re-create certificates, and then
393 # recreate the FIP.
394 local fip_dir="$(mktempdir)"
395 local bin common_args stem
396 local rot_key="$(get_tf_opt ROT_KEY)"
397
398 rot_key="${rot_key:?}"
399 if ! is_abs "$rot_key"; then
400 rot_key="$tf_root/$rot_key"
401 fi
402
403 # Arguments only for cert_create
404 local cert_args="-n"
405 cert_args+=" --tfw-nvctr ${nvctr:-31}"
406 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
407 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
408 cert_args+=" --rot-key $rot_key"
409
410 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500411 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200412 "hw-config"
413 "tb-fw-config"
414 "nt-fw-config"
415 "soc-fw-config"
416 "tos-fw-config"
417 )
418
419 # Binaries without key certificates
420 declare -A has_no_key_cert
421 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
422 has_no_key_cert["$bin"]="1"
423 done
424
425 # Binaries without certificates
426 declare -A has_no_cert
427 for bin in "hw-config" "${dyn_config_opts[@]}"; do
428 has_no_cert["$bin"]="1"
429 done
430
431 pushd "$fip_dir"
432
433 # Unpack FIP
434 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
435
436 # Remove all existing certificates
437 rm -f *-cert.bin
438
439 # Copy the binary to be updated
440 cp -f "$src" "${bin_name}.bin"
441
442 # FIP unpack dumps binaries with the same name as the option
443 # used to pack it; likewise for certificates. Reverse-engineer
444 # the command line from the binary output.
445 common_args="--trusted-key-cert trusted_key.crt"
446 for bin in *.bin; do
447 stem="${bin%%.bin}"
448 common_args+=" --$stem $bin"
449 if not_upon "${has_no_cert[$stem]}"; then
450 common_args+=" --$stem-cert $stem.crt"
451 fi
452 if not_upon "${has_no_key_cert[$stem]}"; then
453 common_args+=" --$stem-key-cert $stem-key.crt"
454 fi
455 done
456
457 # Create certificates
458 "$cert_create" $cert_args $common_args &>>"$build_log"
459
460 # Recreate and archive FIP
461 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
462 archive_file "fip.bin"
463
464 popd
465 fi
466}
467
468# Update hw-config in FIP, and remove the original DTB afterwards.
469update_fip_hw_config() {
470 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600471 # in configs:
472 # 1. Where BL2 isn't present
473 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200474 case "1" in
475 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600476 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200477 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000478 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200479 return 0;;
480 esac
481
482 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
483 # Remove the DTB so that model won't load it
484 rm -f "$archive/dtb.bin"
485 fi
486}
487
488get_scp_opt() {
489 (
490 name="${1:?}"
491 if config_valid "$scp_config_file"; then
492 source "$scp_config_file"
493 echo "${!name}"
494 fi
495 )
496}
497
498get_tftf_opt() {
499 (
500 name="${1:?}"
501 if config_valid "$tftf_config_file"; then
502 source "$tftf_config_file"
503 echo "${!name}"
504 fi
505 )
506}
507
508get_tf_opt() {
509 (
510 name="${1:?}"
511 if config_valid "$tf_config_file"; then
512 source "$tf_config_file"
513 echo "${!name}"
514 fi
515 )
516}
517
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000518get_rmm_opt() {
519 (
520 name="${1:?}"
Manish V Badarkhea3505272025-04-17 14:20:42 +0100521 default="$2"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000522 if config_valid "$rmm_config_file"; then
523 source "$rmm_config_file"
Manish V Badarkhea3505272025-04-17 14:20:42 +0100524 # If !name is not defined, go with the default
525 # value (if defined)
526 if [ -z "${!name}" ]; then
527 echo "$default"
528 else
529 echo "${!name}"
530 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000531 fi
532 )
533}
534
Fathi Boudra422bf772019-12-02 11:10:16 +0200535build_tf() {
536 (
537 env_file="$workspace/tf.env"
538 config_file="${tf_build_config:-$tf_config_file}"
539
540 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100541 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200542
543 source "$config_file"
544
545 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000546 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100547 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
548 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200549 mbedtls_dir="$workspace/mbedtls"
550 if [ ! -d "$mbedtls_dir" ]; then
551 mbedtls_ar="$workspace/mbedtls.tar.gz"
552
553 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
554 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500555 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200556 fi
557
558 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
559 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500560 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
561 not_upon "${TF_M_TESTS_PATH}"; then
562 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
563 fi
564 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
565 not_upon "${TF_M_EXTRAS_PATH}"; then
566 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
567 fi
David Vincze82db6932024-02-21 12:05:50 +0100568 if [ "$(get_tf_opt DICE_PROTECTION_ENVIRONMENT)" = 1 ] &&
569 not_upon "${QCBOR_DIR}"; then
570 emit_env "QCBOR_DIR" "$WORKSPACE/qcbor"
571 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200572 if [ -f "$env_file" ]; then
573 set -a
574 source "$env_file"
575 set +a
576 fi
577
Harrison Mutai013f6332022-02-16 16:06:33 +0000578 if is_arm_jenkins_env || upon "$local_ci"; then
579 path_list=(
580 "$llvm_dir/bin"
581 )
582 extend_path "PATH" "path_list"
583 fi
584
Fathi Boudra422bf772019-12-02 11:10:16 +0200585 cd "$tf_root"
586
587 # Always distclean when running on Jenkins. Skip distclean when running
588 # locally and explicitly requested.
589 if upon "$jenkins_run" || not_upon "$dont_clean"; then
590 make distclean &>>"$build_log" || fail_build
591 fi
592
593 # Log build command line. It is left unfolded on purpose to assist
594 # copying to clipboard.
595 cat <<EOF | log_separator >/dev/null
596
597Build command line:
598 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
599
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300600CC version:
601$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200602EOF
603
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000604 if not_upon "$local_ci"; then
605 connect_debugger=0
606 fi
607
Fathi Boudra422bf772019-12-02 11:10:16 +0200608 # Build TF. Since build output is being directed to the build log, have
609 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000610 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000611 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200612 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100613
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100614 if [ "$build_targets" != "doc" ]; then
Chris Kay9ab2d952025-05-29 13:46:24 +0100615 (poetry run memory --root "$tf_build_root" symbols 2>&1 || true) | tee -a "${build_log}"
616
617 for map in $(find "${tf_build_root}" -name '*.map'); do
618 (poetry run memory --root "${tf_build_root}" summary "${map}" 2>&1 || true) | tee -a "${build_log}"
619 done
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100620 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200621 )
622}
623
624build_tftf() {
625 (
626 config_file="${tftf_build_config:-$tftf_config_file}"
627
628 # Build tftf target by default
629 build_targets="${tftf_build_targets:-all}"
630
631 source "$config_file"
632
633 cd "$tftf_root"
634
635 # Always distclean when running on Jenkins. Skip distclean when running
636 # locally and explicitly requested.
637 if upon "$jenkins_run" || not_upon "$dont_clean"; then
638 make distclean &>>"$build_log" || fail_build
639 fi
640
641 # TFTF build system cannot reliably deal with -j option, so we avoid
642 # using that.
643
644 # Log build command line
645 cat <<EOF | log_separator >/dev/null
646
647Build command line:
Boyan Karatotev51060ba2024-10-29 16:55:10 +0000648 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
Fathi Boudra422bf772019-12-02 11:10:16 +0200649
650EOF
651
Boyan Karatotev51060ba2024-10-29 16:55:10 +0000652 make $make_j_opts $(cat "$config_file") DEBUG="$DEBUG" V=1 \
Fathi Boudra422bf772019-12-02 11:10:16 +0200653 $build_targets &>>"$build_log" || fail_build
654 )
655}
656
657build_scp() {
658 (
659 config_file="${scp_build_config:-$scp_config_file}"
660
661 source "$config_file"
662
663 cd "$scp_root"
664
665 # Always distclean when running on Jenkins. Skip distclean when running
666 # locally and explicitly requested.
667 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000668 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200669 fi
670
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000671 python3 -m venv .venv
672 . .venv/bin/activate
673
674 # Install extra tools used by CMake build system
675 pip install -r requirements.txt --timeout 30 --retries 15
676
Fathi Boudra422bf772019-12-02 11:10:16 +0200677 # Log build command line. It is left unfolded on purpose to assist
678 # copying to clipboard.
679 cat <<EOF | log_separator >/dev/null
680
681SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000682 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
683 TOOLCHAIN=GNU \
684 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000685 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000686 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200687
688EOF
689
690 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000691 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
692 TOOLCHAIN=GNU \
693 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000694 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000695 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200696 || fail_build
697 )
698}
699
Zelalem219df412020-05-17 19:21:20 -0500700clone_scp_tools() {
701
702 if [ ! -d "$scp_tools_root" ]; then
703 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
704
705 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
706 where="$scp_tools_root" \
707 refspec="${scp_tools_commit}"
708 clone_repo &>>"$build_log"
709 else
710 echo "Already cloned SCP-tools ..." |& log_separator
711 fi
712
713 show_head "$scp_tools_root"
714
715 cd "$scp_tools_root"
716
717 echo "Updating submodules"
718
719 git submodule init
720
721 git submodule update
722
Nicola Mazzucato9b171422023-08-29 15:50:49 +0100723 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 +0000724
Zelalem219df412020-05-17 19:21:20 -0500725 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000726 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500727
728 git show --quiet --no-color | sed 's/^/ > /g'
729}
730
731clone_tf_for_scp_tools() {
732 scp_tools_arm_tf="$scp_tools_root/arm-tf"
733
734 if [ ! -d "$scp_tools_arm_tf" ]; then
735 echo "Cloning TF-4-SCP-tools ..." |& log_separator
736
737 clone_url="$tf_for_scp_tools_src_repo_url"
738 where="$scp_tools_arm_tf"
739
740 git clone "$clone_url" "$where"
741
742 cd "$scp_tools_arm_tf"
743
Joel Goddard3ad03062021-03-16 16:47:42 +0000744 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500745
746 git show --quiet --no-color | sed 's/^/ > /g'
747
748 else
749 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
750 fi
751}
752
753build_scmi_lib_scp_tools() {
754 (
755 cd "$scp_tools_root"
756
757 cd "scmi"
758
759 scp_tools_arm_tf="$scp_tools_root/arm-tf"
760
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600761 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500762
763 std_libs="-I$scp_tools_arm_tf/include/common"
764 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
765 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
766 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
767 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
768 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
769 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
770 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
771 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
772 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
773 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
774 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
775 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
776 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
777
778 cflags="-Og -g"
779 cflags="$cflags -mgeneral-regs-only"
780 cflags="$cflags -mstrict-align"
781 cflags="$cflags -nostdinc"
782 cflags="$cflags -fno-inline"
783 cflags="$cflags -ffreestanding"
784 cflags="$cflags -ffunction-sections"
785 cflags="$cflags -fdata-sections"
786 cflags="$cflags -DAARCH64"
787 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000788 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500789
790 cflags="$cflags $std_libs"
791
Joel Goddard3ad03062021-03-16 16:47:42 +0000792 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500793
794 echo "Building SCMI library (SCP-tools) ..."
795
796 make "CROSS_COMPILE=$cross_compile" \
797 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000798 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500799 "PROTOCOLS=$protocols" \
800 "clean" \
801 "all"
802 )
803}
804
805build_tf_for_scp_tools() {
806
807 cd "$scp_tools_root/arm-tf"
808
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600809 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500810
811 if [ "$1" = "release" ]; then
812 echo "Build TF-4-SCP-Tools rls..."
813 else
814 echo "Build TF-4-SCP-Tools dbg..."
815
816 make realclean
817
818 make "BM_TEST=scmi" \
819 "ARM_BOARD_OPTIMISE_MEM=1" \
820 "BM_CSS=juno" \
821 "CSS_USE_SCMI_SDS_DRIVER=1" \
822 "PLAT=juno" \
823 "DEBUG=1" \
824 "PLATFORM=juno" \
825 "CROSS_COMPILE=$cross_compile" \
826 "BM_WORKSPACE=$scp_tools_root/baremetal"
827
828 archive_file "build/juno/debug/bl1.bin"
829
830 archive_file "build/juno/debug/bl2.bin"
831
832 archive_file "build/juno/debug/bl31.bin"
833 fi
834}
835
836build_fip_for_scp_tools() {
837
838 cd "$scp_tools_root/arm-tf"
839
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600840 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500841
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000842 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500843 make fiptool
844 echo "Make FIP 4 SCP-Tools rls..."
845
846 else
847 make fiptool
848 echo "Make FIP 4 SCP-Tools dbg..."
849
850 make "PLAT=juno" \
851 "all" \
852 "fip" \
853 "DEBUG=1" \
854 "CROSS_COMPILE=$cross_compile" \
855 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
856 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000857 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500858
859 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
860 fi
861}
862
863build_cc() {
864# Building code coverage plugin
865 ARM_DIR=/arm
866 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
867 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
868 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
869 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
870 exit -1
871 fi # Error if arm warehouse not found
872 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
873
874 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
875}
876
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100877build_spm() {
878 (
879 env_file="$workspace/spm.env"
880 config_file="${spm_build_config:-$spm_config_file}"
881
882 source "$config_file"
883
884 if [ -f "$env_file" ]; then
885 set -a
886 source "$env_file"
887 set +a
888 fi
889
890 cd "$spm_root"
891
892 # Always clean when running on Jenkins. Skip clean when running
893 # locally and explicitly requested.
894 if upon "$jenkins_run" || not_upon "$dont_clean"; then
895 # make clean fails on a fresh repo where the project has not
896 # yet been built. Hence only clean if out/reference directory
897 # already exists.
898 if [ -d "out/reference" ]; then
899 make clean &>>"$build_log" || fail_build
900 fi
901 fi
902
903 # Log build command line. It is left unfolded on purpose to assist
904 # copying to clipboard.
905 cat <<EOF | log_separator >/dev/null
906
907Build command line:
908 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
909
910EOF
911
912 # Build SPM. Since build output is being directed to the build log, have
913 # descriptor 3 point to the current terminal for build wrappers to vent.
914 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
915 || fail_build
916 )
917}
Zelalem219df412020-05-17 19:21:20 -0500918
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000919build_rmm() {
920 (
921 env_file="$workspace/rmm.env"
922 config_file="${rmm_build_config:-$rmm_config_file}"
923
924 # Build fiptool and all targets by default
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000925 export CROSS_COMPILE="${aarch64_none_elf_prefix}"
926
927 source "$config_file"
928
929 if [ -f "$env_file" ]; then
930 set -a
931 source "$env_file"
932 set +a
933 fi
934
935 cd "$rmm_root"
936
937 if [ -f "$rmm_root/requirements.txt" ]; then
938 export PATH="$HOME/.local/bin:$PATH"
939 python3 -m pip install --upgrade pip
940 python3 -m pip install -r "$rmm_root/requirements.txt"
941 fi
942
943 # Always distclean when running on Jenkins. Skip distclean when running
944 # locally and explicitly requested.
945 if upon "$jenkins_run" || not_upon "$dont_clean"; then
946 # Remove 'rmm\build' folder
947 echo "Removing $rmm_build_root..."
948 rm -rf $rmm_build_root
949 fi
950
Manish V Badarkhea3505272025-04-17 14:20:42 +0100951 if not_upon "$local_ci"; then
952 connect_debugger=0
953 fi
954
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000955 # Log build command line. It is left unfolded on purpose to assist
956 # copying to clipboard.
957 cat <<EOF | log_separator >/dev/null
958
959Build command line:
Manish V Badarkhea3505272025-04-17 14:20:42 +0100960 cmake -DRMM_CONFIG=${plat}_defcfg "$cmake_gen" -S $rmm_root -B $rmm_build_root -DRMM_TOOLCHAIN=$rmm_toolchain -DRMM_FPU_USE_AT_REL2=$rmm_fpu_use_at_rel2 -DATTEST_EL3_TOKEN_SIGN=$rmm_attest_el3_token_sign -DRMM_V1_1=$rmm_v1_1 ${extra_options}
961 cmake --build $rmm_build_root --config $cmake_build_type $make_j_opts -v ${extra_targets+-- $extra_targets}
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000962
Manish V Badarkhea3505272025-04-17 14:20:42 +0100963EOF
964 cmake \
965 -DRMM_CONFIG=${plat}_defcfg $cmake_gen \
966 -S $rmm_root -B $rmm_build_root \
967 -DRMM_TOOLCHAIN=$rmm_toolchain \
968 -DRMM_FPU_USE_AT_REL2=$rmm_fpu_use_at_rel2 \
969 -DATTEST_EL3_TOKEN_SIGN=$rmm_attest_el3_token_sign \
970 -DRMM_V1_1=$rmm_v1_1 \
971 ${extra_options}
972 cmake --build $rmm_build_root --config $cmake_build_type $make_j_opts -v ${extra_targets+-- $extra_targets} 3>&1 &>>"$build_log" || fail_build
973 )
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000974}
975
Fathi Boudra422bf772019-12-02 11:10:16 +0200976# Set metadata for the whole package so that it can be used by both Jenkins and
977# shell
978set_package_var() {
979 env_file="$artefacts/env" emit_env "$@"
980}
981
982set_tf_build_targets() {
983 echo "Set build target to '${targets:?}'"
984 set_hook_var "tf_build_targets" "$targets"
985}
986
987set_tftf_build_targets() {
988 echo "Set build target to '${targets:?}'"
989 set_hook_var "tftf_build_targets" "$targets"
990}
991
992set_scp_build_targets() {
993 echo "Set build target to '${targets:?}'"
994 set_hook_var "scp_build_targets" "$targets"
995}
996
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100997set_spm_build_targets() {
998 echo "Set build target to '${targets:?}'"
999 set_hook_var "spm_build_targets" "$targets"
1000}
1001
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001002set_spm_out_dir() {
1003 echo "Set SPMC binary build to '${out_dir:?}'"
1004 set_hook_var "spm_secure_out_dir" "$out_dir"
1005}
Fathi Boudra422bf772019-12-02 11:10:16 +02001006# Look under $archive directory for known files such as blX images, kernel, DTB,
1007# initrd etc. For each known file foo, if foo.bin exists, then set variable
1008# foo_bin to the path of the file. Make the path relative to the workspace so as
1009# to remove any @ characters, which Jenkins inserts for parallel runs. If the
1010# file doesn't exist, unset its path.
1011set_default_bin_paths() {
1012 local image image_name image_path path
1013 local archive="${archive:?}"
1014 local set_vars
1015 local var
1016
1017 pushd "$archive"
1018
1019 for file in *.bin; do
1020 # Get a shell variable from the file's stem
1021 var_name="${file%%.*}_bin"
1022 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
1023
1024 # Skip setting the variable if it's already
1025 if [ "${!var_name}" ]; then
1026 echo "Note: not setting $var_name; already set to ${!var_name}"
1027 continue
1028 else
1029 set_vars+="$var_name "
1030 fi
1031
1032 eval "$var_name=$file"
1033 done
1034
1035 echo "Binary paths set for: "
1036 {
1037 for var in $set_vars; do
1038 echo -n "\$$var "
1039 done
1040 } | fmt -80 | sed 's/^/ /'
1041 echo
1042
1043 popd
1044}
1045
1046gen_model_params() {
1047 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +00001048 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +02001049
1050 set_default_bin_paths
1051 echo "Generating model parameter for $model..."
1052 source "$ci_root/model/${model:?}.sh"
1053 archive_file "$model_param_file"
1054}
1055
1056set_model_path() {
1057 set_run_env "model_path" "${1:?}"
1058}
1059
Zelalem1af7a7b2020-08-04 17:34:32 -05001060set_model_env() {
1061 local var="${1:?}"
1062 local val="${2?}"
1063 local run_root="${archive:?}/run"
1064
1065 mkdir -p "$run_root"
1066 echo "export $var=$val" >> "$run_root/model_env"
1067}
Fathi Boudra422bf772019-12-02 11:10:16 +02001068set_run_env() {
1069 local var="${1:?}"
1070 local val="${2?}"
1071 local run_root="${archive:?}/run"
1072
1073 mkdir -p "$run_root"
1074 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
1075}
1076
1077show_head() {
1078 # Display HEAD descripton
1079 pushd "$1"
1080 git show --quiet --no-color | sed 's/^/ > /g'
1081 echo
1082 popd
1083}
1084
1085# Choose debug binaries to run; by default, release binaries are chosen to run
1086use_debug_bins() {
1087 local run_root="${archive:?}/run"
1088
1089 echo "Choosing debug binaries for execution"
1090 set_package_var "BIN_MODE" "debug"
1091}
1092
1093assert_can_git_clone() {
1094 local name="${1:?}"
1095 local dir="${!name}"
1096
1097 # If it doesn't exist, it can be cloned into
1098 if [ ! -e "$dir" ]; then
1099 return 0
1100 fi
1101
1102 # If it's a directory, it must be a Git clone already
1103 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
1104 # No need to clone again
1105 echo "Using existing git clone for $name: $dir"
1106 return 1
1107 fi
1108
1109 die "Path $dir exists but is not a git clone"
1110}
1111
1112clone_repo() {
1113 if ! is_url "${clone_url?}"; then
1114 # For --depth to take effect on local paths, it needs to use the
1115 # file:// scheme.
1116 clone_url="file://$clone_url"
1117 fi
1118
1119 git clone -q --depth 1 "$clone_url" "${where?}"
1120 if [ "$refspec" ]; then
1121 pushd "$where"
1122 git fetch -q --depth 1 origin "$refspec"
1123 git checkout -q FETCH_HEAD
1124 popd
1125 fi
1126}
1127
1128build_unstable() {
1129 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1130}
1131
1132undo_patch_record() {
1133 if [ ! -f "${patch_record:?}" ]; then
1134 return
1135 fi
1136
1137 # Undo patches in reverse
1138 echo
1139 for patch_name in $(tac "$patch_record"); do
1140 echo "Undoing $patch_name..."
1141 if ! git apply -R "$ci_root/patch/$patch_name"; then
1142 if upon "$local_ci"; then
1143 echo
1144 echo "Your local directory may have been dirtied."
1145 echo
1146 fi
1147 fail_build
1148 fi
1149 done
1150
1151 rm -f "$patch_record"
1152}
1153
1154undo_local_patches() {
1155 pushd "$tf_root"
1156 patch_record="$tf_patch_record" undo_patch_record
1157 popd
1158
1159 if [ -d "$tftf_root" ]; then
1160 pushd "$tftf_root"
1161 patch_record="$tftf_patch_record" undo_patch_record
1162 popd
1163 fi
1164}
1165
1166undo_tftf_patches() {
1167 pushd "$tftf_root"
1168 patch_record="$tftf_patch_record" undo_patch_record
1169 popd
1170}
1171
1172undo_tf_patches() {
1173 pushd "$tf_root"
1174 patch_record="$tf_patch_record" undo_patch_record
1175 popd
1176}
1177
1178apply_patch() {
1179 # If skip_patches is set, the developer has applied required patches
1180 # manually. They probably want to keep them applied for debugging
1181 # purposes too. This means we don't have to apply/revert them as part of
1182 # build process.
1183 if upon "$skip_patches"; then
1184 echo "Skipped applying ${1:?}..."
1185 return 0
1186 else
1187 echo "Applying ${1:?}..."
1188 fi
1189
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +02001190 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001191 echo "Skipping already applied ${1:?}"
1192 return 0
1193 fi
1194
Fathi Boudra422bf772019-12-02 11:10:16 +02001195 if git apply < "$ci_root/patch/$1"; then
1196 echo "$1" >> "${patch_record:?}"
1197 else
1198 if upon "$local_ci"; then
1199 undo_local_patches
1200 fi
1201 fail_build
1202 fi
1203}
1204
1205apply_tftf_patch() {
1206 pushd "$tftf_root"
1207 patch_record="$tftf_patch_record" apply_patch "$1"
1208 popd
1209}
1210
1211apply_tf_patch() {
1212 pushd "$tf_root"
1213 patch_record="$tf_patch_record" apply_patch "$1"
1214 popd
1215}
1216
1217# Clear workspace for a local run
Leandro Bellibe7b8fa2024-07-18 10:14:22 +01001218if not_upon "$jenkins_run" && not_upon "$dont_clean"; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001219 rm -rf "$workspace"
1220
1221 # Clear residue from previous runs
1222 rm -rf "$archive"
1223fi
1224
1225mkdir -p "$workspace"
1226mkdir -p "$archive"
1227set_package_var "TEST_CONFIG" "$test_config"
1228
1229{
1230echo
1231echo "CONFIGURATION: $test_group/$test_config"
1232echo
1233} |& log_separator
1234
1235tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1236tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1237scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001238scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001239spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001240rmm_config="$(echo "$build_configs" | awk -F, '{print $6}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001241
1242test_config_file="$ci_root/group/$test_group/$test_config"
1243
1244tf_config_file="$ci_root/tf_config/$tf_config"
1245tftf_config_file="$ci_root/tftf_config/$tftf_config"
1246scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001247scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001248spm_config_file="$ci_root/spm_config/$spm_config"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001249rmm_config_file="$ci_root/rmm_config/$rmm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001250
1251# File that keeps track of applied patches
1252tf_patch_record="$workspace/tf_patches"
1253tftf_patch_record="$workspace/tftf_patches"
1254
1255pushd "$workspace"
1256
1257if ! config_valid "$tf_config"; then
1258 tf_config=
1259else
1260 echo "Trusted Firmware config:"
1261 echo
1262 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1263 echo
1264fi
1265
1266if ! config_valid "$tftf_config"; then
1267 tftf_config=
1268else
1269 echo "Trusted Firmware TF config:"
1270 echo
1271 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1272 echo
1273fi
1274
1275if ! config_valid "$scp_config"; then
1276 scp_config=
1277else
1278 echo "SCP firmware config:"
1279 echo
1280 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1281 echo
1282fi
1283
Zelalem219df412020-05-17 19:21:20 -05001284if ! config_valid "$scp_tools_config"; then
1285 scp_tools_config=
1286else
1287 echo "SCP Tools config:"
1288 echo
1289 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001290fi
1291
1292if ! config_valid "$spm_config"; then
1293 spm_config=
1294else
1295 echo "SPM config:"
1296 echo
1297 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001298 echo
1299fi
1300
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001301# File that keeps track of applied patches
1302rmm_patch_record="$workspace/rmm_patches"
1303
1304if ! config_valid "$rmm_config"; then
1305 rmm_config=
1306else
1307 echo "Trusted Firmware RMM config:"
1308 echo
1309 sort "$rmm_config_file" | sed '/^\s*$/d;s/^/\t/'
1310 echo
1311fi
1312
Fathi Boudra422bf772019-12-02 11:10:16 +02001313if ! config_valid "$run_config"; then
1314 run_config=
1315fi
1316
1317if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1318 # If the Trusted Firmware repository has already been checked out, use
1319 # that location. Otherwise, clone one ourselves.
1320 echo "Cloning Trusted Firmware..."
1321 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1322 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1323 show_head "$tf_root"
1324fi
1325
1326if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1327 # If the Trusted Firmware TF repository has already been checked out,
1328 # use that location. Otherwise, clone one ourselves.
1329 echo "Cloning Trusted Firmware TF..."
1330 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1331 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1332 show_head "$tftf_root"
1333fi
1334
1335if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1336 # If the SCP firmware repository has already been checked out,
1337 # use that location. Otherwise, clone one ourselves.
1338 echo "Cloning SCP Firmware..."
1339 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1340 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1341
1342 pushd "$scp_root"
1343
1344 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001345 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001346 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1347 fi
1348
1349 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1350 # then to project filer if accessible.
1351 if [ -z "$cmsis_reference" ]; then
1352 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1353 if [ -d "$cmsis_ref_repo" ]; then
1354 cmsis_reference="--reference $cmsis_ref_repo"
1355 fi
1356 fi
1357
1358 git submodule -q update $cmsis_reference --init
1359
1360 popd
1361
1362 show_head "$scp_root"
1363fi
1364
Zelalem219df412020-05-17 19:21:20 -05001365if [ -n "$cc_config" ] ; then
1366 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1367 # Copy code coverage repository
1368 echo "Cloning Code Coverage..."
1369 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1370 show_head "$cc_root"
1371 fi
1372fi
1373
Daniel Boulby25385ab2023-12-14 14:36:25 +00001374if [ "$spm_config" ] ; then
1375 if assert_can_git_clone "spm_root"; then
1376 # If the SPM repository has already been checked out, use
1377 # that location. Otherwise, clone one ourselves.
1378 echo "Cloning SPM..."
1379 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1380 where="$spm_root" refspec="$SPM_REFSPEC" \
1381 clone_repo &>>"$build_log"
1382 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001383
1384 # Query git submodules
1385 pushd "$spm_root"
Daniel Boulby25385ab2023-12-14 14:36:25 +00001386 # Check if submodules need initialising
Paul Sokolovskyad274422024-09-01 10:27:56 +03001387
1388 # This handling is needed to reliably fetch submodules
1389 # in CI environment.
1390 for subm in $(git submodule status | awk '/^-/ {print $2}'); do
1391 for i in $(seq 1 7); do
1392 git submodule init $subm
1393 if git submodule update $subm; then
1394 break
1395 fi
1396 git submodule deinit --force $subm
1397 echo "Retrying $subm"
1398 sleep $((RANDOM % 10 + 5))
1399 done
1400 done
1401
1402 git submodule status
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001403 popd
1404
1405 show_head "$spm_root"
1406fi
1407
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001408if [ "$rmm_config" ] && assert_can_git_clone "rmm_root"; then
Manish V Badarkhe41909452025-04-11 12:06:45 +01001409 # If the RMM repository has already been checked out,
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001410 # use that location. Otherwise, clone one ourselves.
1411 echo "Cloning TF-RMM..."
1412 clone_url="${RMM_CHECKOUT_LOC:-$rmm_src_repo_url}" where="$rmm_root" \
1413 refspec="$RMM_REFSPEC" clone_repo &>>"$build_log"
1414 show_head "$rmm_root"
1415fi
1416
Fathi Boudra422bf772019-12-02 11:10:16 +02001417if [ "$run_config" ]; then
1418 # Get candidates for run config
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001419 run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \
Fathi Boudra422bf772019-12-02 11:10:16 +02001420 "$run_config")"
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001421 if [ -z "$run_config_candidates" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001422 die "No run config candidates!"
1423 else
1424 echo
1425 echo "Chosen fragments:"
1426 echo
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001427 echo "$run_config_candidates" | sed 's/^\|\n/\t/g'
Fathi Boudra422bf772019-12-02 11:10:16 +02001428 echo
Harrison Mutai4dfe1192024-07-03 12:35:38 +00001429
1430 if [ ! -n "$bin_mode" ]; then
1431 if echo $run_config_candidates | grep -wq "debug"; then
1432 bin_mode="debug"
1433 else
1434 bin_mode="release"
1435 fi
1436 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001437 fi
1438fi
1439
1440call_hook "test_setup"
1441echo
1442
1443if upon "$local_ci"; then
1444 # For local runs, since each config is tried in sequence, it's
1445 # advantageous to run jobs in parallel
1446 if [ "$make_j" ]; then
1447 make_j_opts="-j $make_j"
1448 else
1449 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1450 if [ "$n_cores" ]; then
1451 make_j_opts="-j $n_cores"
1452 fi
1453 fi
1454fi
1455
Harrison Mutai07043e92023-07-06 09:41:12 +01001456# Install python build dependencies
1457if is_arm_jenkins_env; then
1458 source "$ci_root/script/install_python_deps.sh"
1459fi
1460
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001461# Print CMake version
1462cmake_ver=$(echo `cmake --version | sed -n '1p'`)
1463echo "Using $cmake_ver"
1464
1465# Check for Ninja
1466if [ -x "$(command -v ninja)" ]; then
1467 # Print Ninja version
1468 ninja_ver=$(echo `ninja --version | sed -n '1p'`)
1469 echo "Using ninja $ninja_ver"
1470 export cmake_gen="-G Ninja"
1471else
1472 echo 'Ninja is not installed'
1473 export cmake_gen=""
1474fi
1475
1476undo_rmm_patches() {
1477 pushd "$rmm_root"
1478 patch_record="$rmm_patch_record" undo_patch_record
1479 popd
1480}
1481
Fathi Boudra422bf772019-12-02 11:10:16 +02001482modes="${bin_mode:-debug release}"
1483for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001484 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001485 # Build with a temporary archive
1486 build_archive="$archive/$mode"
1487 mkdir "$build_archive"
1488
1489 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001490 export bin_mode="debug"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001491 cmake_build_type="Debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001492 DEBUG=1
1493 else
Zelalem219df412020-05-17 19:21:20 -05001494 export bin_mode="release"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001495 cmake_build_type="Release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001496 DEBUG=0
1497 fi
1498
1499 # Perform builds in a subshell so as not to pollute the current and
1500 # subsequent builds' environment
1501
Zelalem219df412020-05-17 19:21:20 -05001502 if config_valid "$cc_config"; then
1503 # Build code coverage plugin
1504 build_cc
1505 fi
1506
Fathi Boudra422bf772019-12-02 11:10:16 +02001507 # SCP build
1508 if config_valid "$scp_config"; then
1509 (
1510 echo "##########"
1511
1512 # Source platform-specific utilities
1513 plat="$(get_scp_opt PRODUCT)"
1514 plat_utils="$ci_root/${plat}_utils.sh"
1515 if [ -f "$plat_utils" ]; then
1516 source "$plat_utils"
1517 fi
1518
1519 archive="$build_archive"
1520 scp_build_root="$scp_root/build"
1521
1522 echo "Building SCP Firmware ($mode) ..." |& log_separator
1523
1524 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001525 to="$archive" collect_scp_artefacts
1526
1527 echo "##########"
1528 echo
1529 )
1530 fi
1531
Zelalem219df412020-05-17 19:21:20 -05001532 # SCP-tools build
1533 if config_valid "$scp_tools_config"; then
1534 (
1535 echo "##########"
1536
1537 archive="$build_archive"
1538 scp_tools_build_root="$scp_tools_root/build"
1539
1540 clone_scp_tools
1541
1542 echo "##########"
1543 echo
1544
1545 echo "##########"
1546 clone_tf_for_scp_tools
1547 echo "##########"
1548 echo
1549 )
1550 fi
1551
Fathi Boudra422bf772019-12-02 11:10:16 +02001552 # TFTF build
1553 if config_valid "$tftf_config"; then
1554 (
1555 echo "##########"
1556
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001557 plat_utils="$(get_tf_opt PLAT_UTILS)"
1558 if [ -z ${plat_utils} ]; then
1559 # Source platform-specific utilities.
1560 plat="$(get_tftf_opt PLAT)"
1561 plat_utils="$ci_root/${plat}_utils.sh"
1562 else
1563 # Source platform-specific utilities by
1564 # using plat_utils name.
1565 plat_utils="$ci_root/${plat_utils}.sh"
1566 fi
1567
Fathi Boudra422bf772019-12-02 11:10:16 +02001568 if [ -f "$plat_utils" ]; then
1569 source "$plat_utils"
1570 fi
1571
1572 archive="$build_archive"
1573 tftf_build_root="$tftf_root/build"
1574
1575 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1576
1577 # Call pre-build hook
1578 call_hook pre_tftf_build
1579
1580 build_tftf
1581
1582 from="$tftf_build_root" to="$archive" collect_build_artefacts
1583
1584 # Clear any local changes made by applied patches
1585 undo_tftf_patches
1586
1587 echo "##########"
1588 echo
1589 )
1590 fi
1591
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001592 # SPM build
1593 if config_valid "$spm_config"; then
1594 (
1595 echo "##########"
1596
1597 # Get platform name from spm_config file
1598 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1599 plat_utils="$ci_root/${plat}_utils.sh"
1600 if [ -f "$plat_utils" ]; then
1601 source "$plat_utils"
1602 fi
1603
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001604 # Call pre-build hook
1605 call_hook pre_spm_build
1606
Manish Pandey1e7be852020-11-09 16:04:48 +00001607 # SPM build generates two sets of binaries, one for normal and other
1608 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001609 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001610 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1611 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001612
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001613 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001614 echo "Building SPM ($mode) ..." |& log_separator
1615
1616 # NOTE: mode has no effect on SPM build (for now), hence debug
1617 # mode is built but subsequent build using release mode just
1618 # goes through with "nothing to do".
1619 build_spm
1620
1621 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001622 cksum $spm_build_root/hafnium.bin
1623
1624 # Some platforms only have secure configuration enabled. Hence,
1625 # non secure hanfnium binary might not be built.
1626 if [ -f $hafnium_build_root/hafnium.bin ]; then
1627 cksum $hafnium_build_root/hafnium.bin
1628 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001629
Manish Pandey1e7be852020-11-09 16:04:48 +00001630 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001631
1632 echo "##########"
1633 echo
1634 )
1635 fi
1636
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001637 # TF RMM build
1638 if config_valid "$rmm_config"; then
1639 (
1640 echo "##########"
1641
1642 plat_utils="$(get_rmm_opt PLAT_UTILS)"
1643 if [ -z ${plat_utils} ]; then
1644 # Source platform-specific utilities.
1645 plat="$(get_rmm_opt PLAT)"
Manish V Badarkhea3505272025-04-17 14:20:42 +01001646 extra_options="$(get_rmm_opt EXTRA_OPTIONS)"
1647 extra_targets="$(get_rmm_opt EXTRA_TARGETS "")"
1648 rmm_toolchain="$(get_rmm_opt TOOLCHAIN gnu)"
1649 rmm_fpu_use_at_rel2="$(get_rmm_opt RMM_FPU_USE_AT_REL2 OFF)"
1650 rmm_attest_el3_token_sign="$(get_rmm_opt ATTEST_EL3_TOKEN_SIGN OFF)"
1651 rmm_v1_1="$(get_rmm_opt RMM_V1_1 ON)"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001652 plat_utils="$ci_root/${plat}_utils.sh"
1653 else
1654 # Source platform-specific utilities by
1655 # using plat_utils name.
1656 plat_utils="$ci_root/${plat_utils}.sh"
1657 fi
1658
1659 if [ -f "$plat_utils" ]; then
1660 source "$plat_utils"
1661 fi
1662
1663 archive="$build_archive"
1664 rmm_build_root="$rmm_root/build"
1665
1666 echo "Building Trusted Firmware RMM ($mode) ..." |& log_separator
1667
1668 #call_hook pre_rmm_build
1669 build_rmm
1670
1671 # Collect all rmm.* files: rmm.img, rmm.elf, rmm.dump, rmm.map
1672 from="$rmm_build_root" to="$archive" collect_build_artefacts
1673
1674 # Clear any local changes made by applied patches
1675 undo_rmm_patches
1676
1677 echo "##########"
1678 )
1679 fi
1680
Fathi Boudra422bf772019-12-02 11:10:16 +02001681 # TF build
1682 if config_valid "$tf_config"; then
1683 (
1684 echo "##########"
1685
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001686 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001687 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1688
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001689 if [ -z ${plat_utils} ]; then
1690 # Source platform-specific utilities.
1691 plat="$(get_tf_opt PLAT)"
1692 plat_utils="$ci_root/${plat}_utils.sh"
1693 else
1694 # Source platform-specific utilities by
1695 # using plat_utils name.
1696 plat_utils="$ci_root/${plat_utils}.sh"
1697 fi
1698
Fathi Boudra422bf772019-12-02 11:10:16 +02001699 if [ -f "$plat_utils" ]; then
1700 source "$plat_utils"
1701 fi
1702
Chris Kaye5a486b2023-08-04 11:50:31 +00001703 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1704 fvp_tsram_size="${fvp_tsram_size:-256}"
1705
Harrison Mutaidc703402024-08-02 14:40:16 +00001706 poetry -C "$tf_root" install --without docs
Chris Kayd0837902021-11-17 10:17:52 +00001707
Fathi Boudra422bf772019-12-02 11:10:16 +02001708 archive="$build_archive"
1709 tf_build_root="$tf_root/build"
1710
1711 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1712
1713 # Call pre-build hook
1714 call_hook pre_tf_build
1715
1716 build_tf
1717
1718 # Call post-build hook
1719 call_hook post_tf_build
1720
1721 # Pre-archive hook
1722 call_hook pre_tf_archive
1723
1724 from="$tf_build_root" to="$archive" collect_build_artefacts
1725
1726 # Post-archive hook
1727 call_hook post_tf_archive
1728
1729 call_hook fetch_tf_resource
1730 call_hook post_fetch_tf_resource
1731
Chris Kay4e8aaf12022-09-01 15:21:55 +01001732 # Generate LAVA job files if necessary
1733 call_hook generate_lava_job_template
1734 call_hook generate_lava_job
1735
Fathi Boudra422bf772019-12-02 11:10:16 +02001736 # Clear any local changes made by applied patches
1737 undo_tf_patches
1738
1739 echo "##########"
1740 )
1741 fi
1742
1743 echo
1744 echo
1745done
1746
1747call_hook pre_package
1748
1749call_hook post_package
1750
1751if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001752 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001753fi
1754
1755echo
1756echo "Done"