blob: bb0167806bdc390de501c03e43dbb5292c4e111b [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}')"
Tomás Gonzálezfa3e24b2025-07-22 10:59:06 +01001276rfa_config="$(echo "$build_configs" | awk -F, '{print $7}')"
1277
Fathi Boudra422bf772019-12-02 11:10:16 +02001278
1279test_config_file="$ci_root/group/$test_group/$test_config"
1280
1281tf_config_file="$ci_root/tf_config/$tf_config"
1282tftf_config_file="$ci_root/tftf_config/$tftf_config"
1283scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001284scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001285spm_config_file="$ci_root/spm_config/$spm_config"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001286rmm_config_file="$ci_root/rmm_config/$rmm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001287
1288# File that keeps track of applied patches
1289tf_patch_record="$workspace/tf_patches"
1290tftf_patch_record="$workspace/tftf_patches"
1291
1292pushd "$workspace"
1293
1294if ! config_valid "$tf_config"; then
1295 tf_config=
1296else
1297 echo "Trusted Firmware config:"
1298 echo
1299 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1300 echo
1301fi
1302
1303if ! config_valid "$tftf_config"; then
1304 tftf_config=
1305else
1306 echo "Trusted Firmware TF config:"
1307 echo
1308 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1309 echo
1310fi
1311
1312if ! config_valid "$scp_config"; then
1313 scp_config=
1314else
1315 echo "SCP firmware config:"
1316 echo
1317 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1318 echo
1319fi
1320
Zelalem219df412020-05-17 19:21:20 -05001321if ! config_valid "$scp_tools_config"; then
1322 scp_tools_config=
1323else
1324 echo "SCP Tools config:"
1325 echo
1326 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001327fi
1328
1329if ! config_valid "$spm_config"; then
1330 spm_config=
1331else
1332 echo "SPM config:"
1333 echo
1334 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001335 echo
1336fi
1337
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001338# File that keeps track of applied patches
1339rmm_patch_record="$workspace/rmm_patches"
1340
1341if ! config_valid "$rmm_config"; then
1342 rmm_config=
1343else
1344 echo "Trusted Firmware RMM config:"
1345 echo
1346 sort "$rmm_config_file" | sed '/^\s*$/d;s/^/\t/'
1347 echo
1348fi
1349
Fathi Boudra422bf772019-12-02 11:10:16 +02001350if ! config_valid "$run_config"; then
1351 run_config=
1352fi
1353
1354if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1355 # If the Trusted Firmware repository has already been checked out, use
1356 # that location. Otherwise, clone one ourselves.
1357 echo "Cloning Trusted Firmware..."
1358 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1359 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1360 show_head "$tf_root"
1361fi
1362
1363if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1364 # If the Trusted Firmware TF repository has already been checked out,
1365 # use that location. Otherwise, clone one ourselves.
1366 echo "Cloning Trusted Firmware TF..."
1367 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1368 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1369 show_head "$tftf_root"
1370fi
1371
1372if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1373 # If the SCP firmware repository has already been checked out,
1374 # use that location. Otherwise, clone one ourselves.
1375 echo "Cloning SCP Firmware..."
1376 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1377 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1378
1379 pushd "$scp_root"
1380
1381 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001382 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001383 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1384 fi
1385
1386 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1387 # then to project filer if accessible.
1388 if [ -z "$cmsis_reference" ]; then
1389 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1390 if [ -d "$cmsis_ref_repo" ]; then
1391 cmsis_reference="--reference $cmsis_ref_repo"
1392 fi
1393 fi
1394
1395 git submodule -q update $cmsis_reference --init
1396
1397 popd
1398
1399 show_head "$scp_root"
1400fi
1401
Zelalem219df412020-05-17 19:21:20 -05001402if [ -n "$cc_config" ] ; then
1403 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1404 # Copy code coverage repository
1405 echo "Cloning Code Coverage..."
1406 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1407 show_head "$cc_root"
1408 fi
1409fi
1410
Daniel Boulby25385ab2023-12-14 14:36:25 +00001411if [ "$spm_config" ] ; then
1412 if assert_can_git_clone "spm_root"; then
1413 # If the SPM repository has already been checked out, use
1414 # that location. Otherwise, clone one ourselves.
1415 echo "Cloning SPM..."
1416 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1417 where="$spm_root" refspec="$SPM_REFSPEC" \
1418 clone_repo &>>"$build_log"
1419 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001420
1421 # Query git submodules
1422 pushd "$spm_root"
Daniel Boulby25385ab2023-12-14 14:36:25 +00001423 # Check if submodules need initialising
Paul Sokolovskyad274422024-09-01 10:27:56 +03001424
1425 # This handling is needed to reliably fetch submodules
1426 # in CI environment.
1427 for subm in $(git submodule status | awk '/^-/ {print $2}'); do
1428 for i in $(seq 1 7); do
1429 git submodule init $subm
1430 if git submodule update $subm; then
1431 break
1432 fi
1433 git submodule deinit --force $subm
1434 echo "Retrying $subm"
1435 sleep $((RANDOM % 10 + 5))
1436 done
1437 done
1438
1439 git submodule status
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001440 popd
1441
1442 show_head "$spm_root"
1443fi
1444
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001445if [ "$rmm_config" ] && assert_can_git_clone "rmm_root"; then
Manish V Badarkhe41909452025-04-11 12:06:45 +01001446 # If the RMM repository has already been checked out,
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001447 # use that location. Otherwise, clone one ourselves.
1448 echo "Cloning TF-RMM..."
1449 clone_url="${RMM_CHECKOUT_LOC:-$rmm_src_repo_url}" where="$rmm_root" \
1450 refspec="$RMM_REFSPEC" clone_repo &>>"$build_log"
1451 show_head "$rmm_root"
1452fi
1453
Fathi Boudra422bf772019-12-02 11:10:16 +02001454if [ "$run_config" ]; then
1455 # Get candidates for run config
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001456 run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \
Fathi Boudra422bf772019-12-02 11:10:16 +02001457 "$run_config")"
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001458 if [ -z "$run_config_candidates" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001459 die "No run config candidates!"
1460 else
1461 echo
1462 echo "Chosen fragments:"
1463 echo
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001464 echo "$run_config_candidates" | sed 's/^\|\n/\t/g'
Fathi Boudra422bf772019-12-02 11:10:16 +02001465 echo
Harrison Mutai4dfe1192024-07-03 12:35:38 +00001466
1467 if [ ! -n "$bin_mode" ]; then
1468 if echo $run_config_candidates | grep -wq "debug"; then
1469 bin_mode="debug"
1470 else
1471 bin_mode="release"
1472 fi
1473 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001474 fi
1475fi
1476
1477call_hook "test_setup"
1478echo
1479
1480if upon "$local_ci"; then
1481 # For local runs, since each config is tried in sequence, it's
1482 # advantageous to run jobs in parallel
1483 if [ "$make_j" ]; then
1484 make_j_opts="-j $make_j"
1485 else
1486 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1487 if [ "$n_cores" ]; then
1488 make_j_opts="-j $n_cores"
1489 fi
1490 fi
1491fi
1492
Harrison Mutai07043e92023-07-06 09:41:12 +01001493# Install python build dependencies
1494if is_arm_jenkins_env; then
1495 source "$ci_root/script/install_python_deps.sh"
1496fi
1497
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001498# Print CMake version
1499cmake_ver=$(echo `cmake --version | sed -n '1p'`)
1500echo "Using $cmake_ver"
1501
1502# Check for Ninja
1503if [ -x "$(command -v ninja)" ]; then
1504 # Print Ninja version
1505 ninja_ver=$(echo `ninja --version | sed -n '1p'`)
1506 echo "Using ninja $ninja_ver"
1507 export cmake_gen="-G Ninja"
1508else
1509 echo 'Ninja is not installed'
1510 export cmake_gen=""
1511fi
1512
1513undo_rmm_patches() {
1514 pushd "$rmm_root"
1515 patch_record="$rmm_patch_record" undo_patch_record
1516 popd
1517}
1518
Fathi Boudra422bf772019-12-02 11:10:16 +02001519modes="${bin_mode:-debug release}"
1520for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001521 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001522 # Build with a temporary archive
1523 build_archive="$archive/$mode"
1524 mkdir "$build_archive"
1525
1526 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001527 export bin_mode="debug"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001528 cmake_build_type="Debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001529 DEBUG=1
1530 else
Zelalem219df412020-05-17 19:21:20 -05001531 export bin_mode="release"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001532 cmake_build_type="Release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001533 DEBUG=0
1534 fi
1535
1536 # Perform builds in a subshell so as not to pollute the current and
1537 # subsequent builds' environment
1538
Zelalem219df412020-05-17 19:21:20 -05001539 if config_valid "$cc_config"; then
1540 # Build code coverage plugin
1541 build_cc
1542 fi
1543
Fathi Boudra422bf772019-12-02 11:10:16 +02001544 # SCP build
1545 if config_valid "$scp_config"; then
1546 (
1547 echo "##########"
1548
1549 # Source platform-specific utilities
1550 plat="$(get_scp_opt PRODUCT)"
1551 plat_utils="$ci_root/${plat}_utils.sh"
1552 if [ -f "$plat_utils" ]; then
1553 source "$plat_utils"
1554 fi
1555
1556 archive="$build_archive"
1557 scp_build_root="$scp_root/build"
1558
1559 echo "Building SCP Firmware ($mode) ..." |& log_separator
1560
1561 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001562 to="$archive" collect_scp_artefacts
1563
1564 echo "##########"
1565 echo
1566 )
1567 fi
1568
Zelalem219df412020-05-17 19:21:20 -05001569 # SCP-tools build
1570 if config_valid "$scp_tools_config"; then
1571 (
1572 echo "##########"
1573
1574 archive="$build_archive"
1575 scp_tools_build_root="$scp_tools_root/build"
1576
1577 clone_scp_tools
1578
1579 echo "##########"
1580 echo
1581
1582 echo "##########"
1583 clone_tf_for_scp_tools
1584 echo "##########"
1585 echo
1586 )
1587 fi
1588
Fathi Boudra422bf772019-12-02 11:10:16 +02001589 # TFTF build
1590 if config_valid "$tftf_config"; then
1591 (
1592 echo "##########"
1593
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001594 plat_utils="$(get_tf_opt PLAT_UTILS)"
1595 if [ -z ${plat_utils} ]; then
1596 # Source platform-specific utilities.
1597 plat="$(get_tftf_opt PLAT)"
1598 plat_utils="$ci_root/${plat}_utils.sh"
1599 else
1600 # Source platform-specific utilities by
1601 # using plat_utils name.
1602 plat_utils="$ci_root/${plat_utils}.sh"
1603 fi
1604
Fathi Boudra422bf772019-12-02 11:10:16 +02001605 if [ -f "$plat_utils" ]; then
1606 source "$plat_utils"
1607 fi
1608
1609 archive="$build_archive"
1610 tftf_build_root="$tftf_root/build"
1611
1612 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1613
1614 # Call pre-build hook
1615 call_hook pre_tftf_build
1616
1617 build_tftf
1618
1619 from="$tftf_build_root" to="$archive" collect_build_artefacts
1620
1621 # Clear any local changes made by applied patches
1622 undo_tftf_patches
1623
1624 echo "##########"
1625 echo
1626 )
1627 fi
1628
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001629 # SPM build
1630 if config_valid "$spm_config"; then
1631 (
1632 echo "##########"
1633
1634 # Get platform name from spm_config file
1635 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1636 plat_utils="$ci_root/${plat}_utils.sh"
1637 if [ -f "$plat_utils" ]; then
1638 source "$plat_utils"
1639 fi
1640
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001641 # Call pre-build hook
1642 call_hook pre_spm_build
1643
Manish Pandey1e7be852020-11-09 16:04:48 +00001644 # SPM build generates two sets of binaries, one for normal and other
1645 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001646 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001647 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1648 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001649
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001650 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001651 echo "Building SPM ($mode) ..." |& log_separator
1652
1653 # NOTE: mode has no effect on SPM build (for now), hence debug
1654 # mode is built but subsequent build using release mode just
1655 # goes through with "nothing to do".
1656 build_spm
1657
1658 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001659 cksum $spm_build_root/hafnium.bin
1660
1661 # Some platforms only have secure configuration enabled. Hence,
1662 # non secure hanfnium binary might not be built.
1663 if [ -f $hafnium_build_root/hafnium.bin ]; then
1664 cksum $hafnium_build_root/hafnium.bin
1665 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001666
Manish Pandey1e7be852020-11-09 16:04:48 +00001667 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001668
1669 echo "##########"
1670 echo
1671 )
1672 fi
1673
Tomás González0393e802025-07-22 11:06:41 +01001674 # TF RMM build
1675 if config_valid "$rmm_config"; then
1676 (
1677 echo "##########"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001678
Tomás González0393e802025-07-22 11:06:41 +01001679 plat_utils="$(get_rmm_opt PLAT_UTILS)"
1680 if [ -z ${plat_utils} ]; then
1681 # Source platform-specific utilities.
1682 plat="$(get_rmm_opt PLAT)"
1683 plat_utils="$ci_root/${plat}_utils.sh"
1684 else
1685 # Source platform-specific utilities by
1686 # using plat_utils name.
1687 plat_utils="$ci_root/${plat_utils}.sh"
1688 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001689
Tomás González0393e802025-07-22 11:06:41 +01001690 if [ -f "$plat_utils" ]; then
1691 source "$plat_utils"
1692 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001693
Tomás González0393e802025-07-22 11:06:41 +01001694 archive="$build_archive"
1695 rmm_build_root="$rmm_root/build"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001696
Tomás González0393e802025-07-22 11:06:41 +01001697 echo "Building Trusted Firmware RMM ($mode) ..." |& log_separator
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001698
Tomás González0393e802025-07-22 11:06:41 +01001699 #call_hook pre_rmm_build
1700 build_rmm
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001701
Tomás González0393e802025-07-22 11:06:41 +01001702 # Collect all rmm.* files: rmm.img, rmm.elf, rmm.dump, rmm.map
1703 from="$rmm_build_root" to="$archive" collect_build_artefacts
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001704
Tomás González0393e802025-07-22 11:06:41 +01001705 # Clear any local changes made by applied patches
1706 undo_rmm_patches
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001707
Tomás González0393e802025-07-22 11:06:41 +01001708 echo "##########"
1709 )
1710 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001711
Fathi Boudra422bf772019-12-02 11:10:16 +02001712 # TF build
1713 if config_valid "$tf_config"; then
1714 (
1715 echo "##########"
1716
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001717 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001718 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1719
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001720 if [ -z ${plat_utils} ]; then
1721 # Source platform-specific utilities.
1722 plat="$(get_tf_opt PLAT)"
1723 plat_utils="$ci_root/${plat}_utils.sh"
1724 else
1725 # Source platform-specific utilities by
1726 # using plat_utils name.
1727 plat_utils="$ci_root/${plat_utils}.sh"
1728 fi
1729
Fathi Boudra422bf772019-12-02 11:10:16 +02001730 if [ -f "$plat_utils" ]; then
1731 source "$plat_utils"
1732 fi
1733
Chris Kaye5a486b2023-08-04 11:50:31 +00001734 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1735 fvp_tsram_size="${fvp_tsram_size:-256}"
1736
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001737 if not_upon "$(get_tf_opt RUST)"; then
1738 poetry -C "$tf_root" install --without docs
1739 fi
Chris Kayd0837902021-11-17 10:17:52 +00001740
Fathi Boudra422bf772019-12-02 11:10:16 +02001741 archive="$build_archive"
Fathi Boudra422bf772019-12-02 11:10:16 +02001742
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001743 if not_upon "$(get_tf_opt RUST)"; then
1744 tf_build_root="$tf_root/build"
1745 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1746 else
1747 # Clone TF-A repo if required. Save its path into the
1748 # special variable "TFA", which is used by RF-A build
1749 # system.
1750 export TFA="${TFA-$workspace/tfa}"
1751 if assert_can_git_clone "TFA"; then
1752 echo "Cloning TF-A..."
1753 clone_url="$tf_src_repo_url" where="$TFA" clone_repo
1754 fi
1755 show_head "$TFA"
1756 poetry -C "$TFA" install --without docs
Fathi Boudra422bf772019-12-02 11:10:16 +02001757
Sandrine Afsa21d4a542025-06-24 10:27:15 +02001758 rfa_build_root="$tf_root/target"
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001759 echo "Building Rusted Firmware ($mode) ..." |& log_separator
1760
1761 if not_upon "$local_ci"; then
1762 # In the CI Dockerfile, rustup is installed by the root user in the
1763 # non-default location /usr/local/rustup, so $RUSTUP_HOME is required to
1764 # access rust config e.g. default toolchains and run cargo
1765 #
1766 # Leave $CARGO_HOME blank so when this script is run in CI by the buildslave
1767 # user, it uses the default /home/buildslave/.cargo directory which it has
1768 # write permissions for - that allows it to download new crates during
1769 # compilation
1770 #
1771 # The buildslave user does not have write permissions to the default
1772 # $CARGO_HOME=/usr/local/cargo dir and so will error when trying to download
1773 # new crates otherwise
1774 #
1775 # note: $PATH still contains /usr/local/cargo/bin at this point so cargo is
1776 # still run via the root installation
1777 #
1778 # see https://github.com/rust-lang/rustup/issues/1085
1779 set_hook_var "RUSTUP_HOME" "/usr/local/rustup"
1780 fi
Tomás Gonzáleze72d5382024-11-13 14:08:25 +00001781 fi
1782
Fathi Boudra422bf772019-12-02 11:10:16 +02001783 # Call pre-build hook
1784 call_hook pre_tf_build
1785
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001786 if upon "$(get_tf_opt RUST)"; then
1787 build_rfa
1788 else
1789 build_tf
1790 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001791
1792 # Call post-build hook
1793 call_hook post_tf_build
1794
1795 # Pre-archive hook
1796 call_hook pre_tf_archive
1797
Sandrine Afsa07d2bd72025-04-16 17:03:12 +02001798 if not_upon "$(get_tf_opt RUST)"; then
1799 from="$tf_build_root" to="$archive" collect_build_artefacts
1800 else
1801 from="$rfa_build_root" to="$archive" collect_rfa_artefacts
Zachary Leaf5494d732024-10-22 10:49:36 +01001802 fi
1803
Fathi Boudra422bf772019-12-02 11:10:16 +02001804 # Post-archive hook
1805 call_hook post_tf_archive
1806
1807 call_hook fetch_tf_resource
1808 call_hook post_fetch_tf_resource
1809
Chris Kay4e8aaf12022-09-01 15:21:55 +01001810 # Generate LAVA job files if necessary
1811 call_hook generate_lava_job_template
1812 call_hook generate_lava_job
1813
Fathi Boudra422bf772019-12-02 11:10:16 +02001814 # Clear any local changes made by applied patches
1815 undo_tf_patches
1816
1817 echo "##########"
1818 )
1819 fi
1820
1821 echo
1822 echo
1823done
1824
1825call_hook pre_package
1826
1827call_hook post_package
1828
1829if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001830 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001831fi
1832
1833echo
1834echo "Done"