blob: 59f757dfdf381b8255a8cec8ebd7979eada456e6 [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}"
Zelalem219df412020-05-17 19:21:20 -050023cc_root="${cc_root:-$ccpathspec}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010024spm_root="${spm_root:-$workspace/spm}"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +000025rmm_root="${rmm_root:-$workspace/tf-rmm}"
Zelalem219df412020-05-17 19:21:20 -050026
Fathi Boudra422bf772019-12-02 11:10:16 +020027# Refspecs
28tf_refspec="$TF_REFSPEC"
29tftf_refspec="$TFTF_REFSPEC"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010030spm_refspec="$SPM_REFSPEC"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +000031rmm_refspec="$RMM_REFSPEC"
Fathi Boudra422bf772019-12-02 11:10:16 +020032
33test_config="${TEST_CONFIG:?}"
34test_group="${TEST_GROUP:?}"
35build_configs="${BUILD_CONFIG:?}"
36run_config="${RUN_CONFIG:?}"
Zelalem219df412020-05-17 19:21:20 -050037cc_config="${CC_ENABLE:-}"
Fathi Boudra422bf772019-12-02 11:10:16 +020038
Boyan Karatotev97de8d82025-03-06 15:22:21 +000039export archive="$artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +020040build_log="$artefacts/build.log"
Boyan Karatotevde2cd442025-07-28 09:50:29 +010041
42fiptool_path() {
43 echo $tf_build_root/$(get_tf_opt PLAT)/${bin_mode}/tools/fiptool/fiptool
44}
45
46cert_create_path() {
47 echo $tf_build_root/$(get_tf_opt PLAT)/${bin_mode}/tools/cert_create/cert_create
48}
Fathi Boudra422bf772019-12-02 11:10:16 +020049
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
Manish Pandey1e7be852020-11-09 16:04:48 +0000187# Collect SPM/hafnium artefacts with "secure_" appended to the files
188# generated for SPM(secure hafnium).
189collect_spm_artefacts() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500190 if [ -d "${non_secure_from:?}" ]; then
191 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000192 fi
193
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500194 if [ -d "${secure_from:?}" ]; then
195 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
196 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000197}
198
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100199# Map the UART ID used for expect with the UART descriptor and port
200# used by the FPGA automation tools.
201map_uart() {
202 local port="${port:?}"
203 local descriptor="${descriptor:?}"
204 local baudrate="${baudrate:?}"
205 local run_root="${archive:?}/run"
206
207 local uart_dir="$run_root/uart${uart:?}"
208 mkdir -p "$uart_dir"
209
210 echo "$port" > "$uart_dir/port"
211 echo "$descriptor" > "$uart_dir/descriptor"
212 echo "$baudrate" > "$uart_dir/baudrate"
213
214 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
215}
216
Fathi Boudra422bf772019-12-02 11:10:16 +0200217# Arrange environment varibles to be set when expect scripts are launched
218set_expect_variable() {
219 local var="${1:?}"
220 local val="${2?}"
221
222 local run_root="${archive:?}/run"
223 local uart_dir="$run_root/uart${uart:?}"
224 mkdir -p "$uart_dir"
225
226 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
227 echo "UART$uart: env has $@"
228}
229
230# Place the binary package a pointer to expect script, and its parameters
231track_expect() {
232 local file="${file:?}"
233 local timeout="${timeout-600}"
234 local run_root="${archive:?}/run"
235
236 local uart_dir="$run_root/uart${uart:?}"
237 mkdir -p "$uart_dir"
238
239 echo "$file" > "$uart_dir/expect"
240 echo "$timeout" > "$uart_dir/timeout"
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700241 if [ -n "$lava_timeout" ]; then
242 set_run_env "lava_timeout" "$lava_timeout"
243 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200244
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700245 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 +0200246
Chris Kayfab6edc2022-11-17 19:18:32 +0000247 if [ ! -z "${port}" ]; then
248 echo "${port}" > "$uart_dir/port"
249 fi
250
Fathi Boudra422bf772019-12-02 11:10:16 +0200251 # The run script assumes UART0 to be primary. If we're asked to set any
252 # other UART to be primary, set a run environment variable to signal
253 # that to the run script
254 if upon "$set_primary"; then
255 echo "Primary UART set to UART$uart."
256 set_run_env "primary_uart" "$uart"
257 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600258
259 # UART used by payload(such as tftf, Linux) may not be the same as the
260 # primary UART. Set a run environment variable to track the payload
261 # UART which is tracked to check if the test has finished sucessfully.
262 if upon "$set_payload_uart"; then
263 echo "Payload uses UART$uart."
264 set_run_env "payload_uart" "$uart"
265 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200266}
267
268# Extract a FIP in $1 using fiptool
269extract_fip() {
270 local fip="$1"
271
272 if is_url "$1"; then
273 url="$1" fetch_file
274 fip="$(basename "$1")"
275 fi
276
Boyan Karatotevde2cd442025-07-28 09:50:29 +0100277 fiptool=$(fiptool_path)
Fathi Boudra422bf772019-12-02 11:10:16 +0200278 "$fiptool" unpack "$fip"
279 echo "Extracted FIP: $fip"
280}
281
282# Report build failure by printing a the tail end of build log. Archive the
283# build log for later inspection
284fail_build() {
285 local log_path
286
287 if upon "$jenkins_run"; then
288 log_path="$BUILD_URL/artifact/artefacts/build.log"
289 else
290 log_path="$build_log"
291 fi
292
293 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600294 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200295 echo "[...]"
296 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600297 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200298 echo
299 echo "See $log_path for full output"
300 echo
301 cp -t "$archive" "$build_log"
302 exit 1;
303}
304
305# Build a FIP with supplied arguments
306build_fip() {
307 (
308 echo "Building FIP with arguments: $@"
309 local tf_env="$workspace/tf.env"
310
311 if [ -f "$tf_env" ]; then
312 set -a
313 source "$tf_env"
314 set +a
315 fi
316
Boyan Karatotev99e12312025-05-02 15:00:24 +0100317 make -C "$tf_root" $make_j_opts $(cat "$tf_config_file") DEBUG="$DEBUG" BUILD_BASE=$tf_build_root V=1 "$@" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200318 ${fip_targets:-fip} &>>"$build_log" || fail_build
319 )
320}
321
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200322# Build any extra rule from TF-A makefile with supplied arguments.
323#
324# This is useful in case you need to build something else than firmware binaries
325# or the FIP.
326build_tf_extra() {
327 (
328 tf_extra_rules=${tf_extra_rules:?}
329 echo "Building extra TF rule(s): $tf_extra_rules"
330 echo " Arguments: $@"
331
332 local tf_env="$workspace/tf.env"
333
334 if [ -f "$tf_env" ]; then
335 set -a
336 source "$tf_env"
337 set +a
338 fi
339
Boyan Karatotev99e12312025-05-02 15:00:24 +0100340 make -C "$tf_root" $make_j_opts $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 BUILD_BASE=$tf_build_root "$@" \
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200341 ${tf_extra_rules} &>>"$build_log" || fail_build
342 )
343}
344
Fathi Boudra422bf772019-12-02 11:10:16 +0200345fip_update() {
Boyan Karatotevde2cd442025-07-28 09:50:29 +0100346 fiptool=$(fiptool_path)
Fathi Boudra422bf772019-12-02 11:10:16 +0200347 # Before the update process, check if the given image is supported by
348 # the fiptool. It's assumed that both fiptool and cert_create move in
Chris Kay197b1022023-08-16 21:31:41 +0100349 # tandem, and therefore, if one has support, the other has it too.
350 if ! ("$fiptool" update 2>&1 || true) | grep -qe "\s\+--${bin_name:?}"; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200351 return 1
352 fi
353
354 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
355 echo "Updating FIP image: $bin_name"
356 # Update HW config. Without TBBR, it's only a matter of using
357 # the update sub-command of fiptool
358 "$fiptool" update "--$bin_name" "${src:-}" \
359 "$archive/fip.bin"
360 else
361 echo "Updating FIP image (TBBR): $bin_name"
362 # With TBBR, we need to unpack, re-create certificates, and then
363 # recreate the FIP.
364 local fip_dir="$(mktempdir)"
365 local bin common_args stem
366 local rot_key="$(get_tf_opt ROT_KEY)"
367
368 rot_key="${rot_key:?}"
369 if ! is_abs "$rot_key"; then
370 rot_key="$tf_root/$rot_key"
371 fi
372
373 # Arguments only for cert_create
374 local cert_args="-n"
375 cert_args+=" --tfw-nvctr ${nvctr:-31}"
376 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
377 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
378 cert_args+=" --rot-key $rot_key"
379
380 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500381 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200382 "hw-config"
383 "tb-fw-config"
384 "nt-fw-config"
385 "soc-fw-config"
386 "tos-fw-config"
387 )
388
389 # Binaries without key certificates
390 declare -A has_no_key_cert
391 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
392 has_no_key_cert["$bin"]="1"
393 done
394
395 # Binaries without certificates
396 declare -A has_no_cert
397 for bin in "hw-config" "${dyn_config_opts[@]}"; do
398 has_no_cert["$bin"]="1"
399 done
400
401 pushd "$fip_dir"
402
403 # Unpack FIP
404 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
405
406 # Remove all existing certificates
407 rm -f *-cert.bin
408
409 # Copy the binary to be updated
410 cp -f "$src" "${bin_name}.bin"
411
412 # FIP unpack dumps binaries with the same name as the option
413 # used to pack it; likewise for certificates. Reverse-engineer
414 # the command line from the binary output.
415 common_args="--trusted-key-cert trusted_key.crt"
416 for bin in *.bin; do
417 stem="${bin%%.bin}"
418 common_args+=" --$stem $bin"
419 if not_upon "${has_no_cert[$stem]}"; then
420 common_args+=" --$stem-cert $stem.crt"
421 fi
422 if not_upon "${has_no_key_cert[$stem]}"; then
423 common_args+=" --$stem-key-cert $stem-key.crt"
424 fi
425 done
426
427 # Create certificates
Boyan Karatotevde2cd442025-07-28 09:50:29 +0100428 cert_create=$(cert_create_path)
Fathi Boudra422bf772019-12-02 11:10:16 +0200429 "$cert_create" $cert_args $common_args &>>"$build_log"
430
431 # Recreate and archive FIP
432 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
433 archive_file "fip.bin"
434
435 popd
436 fi
437}
438
439# Update hw-config in FIP, and remove the original DTB afterwards.
440update_fip_hw_config() {
441 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600442 # in configs:
443 # 1. Where BL2 isn't present
444 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200445 case "1" in
446 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600447 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200448 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000449 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200450 return 0;;
451 esac
452
453 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
454 # Remove the DTB so that model won't load it
455 rm -f "$archive/dtb.bin"
456 fi
457}
458
Fathi Boudra422bf772019-12-02 11:10:16 +0200459get_tftf_opt() {
460 (
461 name="${1:?}"
462 if config_valid "$tftf_config_file"; then
463 source "$tftf_config_file"
464 echo "${!name}"
465 fi
466 )
467}
468
469get_tf_opt() {
470 (
471 name="${1:?}"
472 if config_valid "$tf_config_file"; then
473 source "$tf_config_file"
474 echo "${!name}"
475 fi
476 )
477}
478
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000479get_rmm_opt() {
480 (
481 name="${1:?}"
Manish V Badarkhea3505272025-04-17 14:20:42 +0100482 default="$2"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000483 if config_valid "$rmm_config_file"; then
484 source "$rmm_config_file"
Manish V Badarkhea3505272025-04-17 14:20:42 +0100485 # If !name is not defined, go with the default
486 # value (if defined)
487 if [ -z "${!name}" ]; then
488 echo "$default"
489 else
490 echo "${!name}"
491 fi
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000492 fi
493 )
494}
495
Fathi Boudra422bf772019-12-02 11:10:16 +0200496build_tf() {
497 (
498 env_file="$workspace/tf.env"
499 config_file="${tf_build_config:-$tf_config_file}"
500
501 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100502 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200503
504 source "$config_file"
505
506 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000507 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100508 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
509 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200510 mbedtls_dir="$workspace/mbedtls"
511 if [ ! -d "$mbedtls_dir" ]; then
512 mbedtls_ar="$workspace/mbedtls.tar.gz"
513
514 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
515 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500516 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200517 fi
518
519 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
520 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500521 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
522 not_upon "${TF_M_TESTS_PATH}"; then
523 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
524 fi
525 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
526 not_upon "${TF_M_EXTRAS_PATH}"; then
527 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
528 fi
David Vincze82db6932024-02-21 12:05:50 +0100529 if [ "$(get_tf_opt DICE_PROTECTION_ENVIRONMENT)" = 1 ] &&
530 not_upon "${QCBOR_DIR}"; then
531 emit_env "QCBOR_DIR" "$WORKSPACE/qcbor"
532 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200533 if [ -f "$env_file" ]; then
534 set -a
535 source "$env_file"
536 set +a
537 fi
538
Harrison Mutai013f6332022-02-16 16:06:33 +0000539 if is_arm_jenkins_env || upon "$local_ci"; then
540 path_list=(
541 "$llvm_dir/bin"
542 )
543 extend_path "PATH" "path_list"
544 fi
545
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000546 pushd "$tf_root"
Fathi Boudra422bf772019-12-02 11:10:16 +0200547
548 # Always distclean when running on Jenkins. Skip distclean when running
549 # locally and explicitly requested.
550 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000551 make distclean BUILD_BASE=$tf_build_root &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200552 fi
553
554 # Log build command line. It is left unfolded on purpose to assist
555 # copying to clipboard.
556 cat <<EOF | log_separator >/dev/null
557
558Build command line:
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000559 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 BUILD_BASE=$tf_build_root $build_targets
Fathi Boudra422bf772019-12-02 11:10:16 +0200560
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300561CC version:
562$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200563EOF
564
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000565 if not_upon "$local_ci"; then
566 connect_debugger=0
567 fi
568
Fathi Boudra422bf772019-12-02 11:10:16 +0200569 # Build TF. Since build output is being directed to the build log, have
570 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000571 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000572 DEBUG="$DEBUG" V=1 BUILD_BASE="$tf_build_root" SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200573 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100574
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100575 if [ "$build_targets" != "doc" ]; then
Chris Kay9ab2d952025-05-29 13:46:24 +0100576 (poetry run memory --root "$tf_build_root" symbols 2>&1 || true) | tee -a "${build_log}"
577
578 for map in $(find "${tf_build_root}" -name '*.map'); do
579 (poetry run memory --root "${tf_build_root}" summary "${map}" 2>&1 || true) | tee -a "${build_log}"
580 done
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100581 fi
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000582 popd
Fathi Boudra422bf772019-12-02 11:10:16 +0200583 )
584}
585
586build_tftf() {
587 (
588 config_file="${tftf_build_config:-$tftf_config_file}"
589
590 # Build tftf target by default
591 build_targets="${tftf_build_targets:-all}"
592
593 source "$config_file"
594
595 cd "$tftf_root"
596
597 # Always distclean when running on Jenkins. Skip distclean when running
598 # locally and explicitly requested.
599 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000600 make distclean BUILD_BASE="$tftf_build_root" &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200601 fi
602
603 # TFTF build system cannot reliably deal with -j option, so we avoid
604 # using that.
605
606 # Log build command line
607 cat <<EOF | log_separator >/dev/null
608
609Build command line:
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000610 make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 BUILD_BASE="$tftf_build_root" $build_targets
Fathi Boudra422bf772019-12-02 11:10:16 +0200611
612EOF
613
Boyan Karatotev97de8d82025-03-06 15:22:21 +0000614 make $make_j_opts $(cat "$config_file") DEBUG="$DEBUG" V=1 BUILD_BASE="$tftf_build_root" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200615 $build_targets &>>"$build_log" || fail_build
616 )
617}
618
Zelalem219df412020-05-17 19:21:20 -0500619build_cc() {
620# Building code coverage plugin
621 ARM_DIR=/arm
622 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
623 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
624 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
625 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
626 exit -1
627 fi # Error if arm warehouse not found
628 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
629
630 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
631}
632
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100633build_spm() {
634 (
635 env_file="$workspace/spm.env"
636 config_file="${spm_build_config:-$spm_config_file}"
637
638 source "$config_file"
639
640 if [ -f "$env_file" ]; then
641 set -a
642 source "$env_file"
643 set +a
644 fi
645
646 cd "$spm_root"
647
648 # Always clean when running on Jenkins. Skip clean when running
649 # locally and explicitly requested.
650 if upon "$jenkins_run" || not_upon "$dont_clean"; then
651 # make clean fails on a fresh repo where the project has not
652 # yet been built. Hence only clean if out/reference directory
653 # already exists.
654 if [ -d "out/reference" ]; then
655 make clean &>>"$build_log" || fail_build
656 fi
657 fi
658
659 # Log build command line. It is left unfolded on purpose to assist
660 # copying to clipboard.
661 cat <<EOF | log_separator >/dev/null
662
663Build command line:
664 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
665
666EOF
667
668 # Build SPM. Since build output is being directed to the build log, have
669 # descriptor 3 point to the current terminal for build wrappers to vent.
670 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
671 || fail_build
672 )
673}
Zelalem219df412020-05-17 19:21:20 -0500674
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000675build_rmm() {
676 (
677 env_file="$workspace/rmm.env"
678 config_file="${rmm_build_config:-$rmm_config_file}"
679
680 # Build fiptool and all targets by default
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000681 export CROSS_COMPILE="${aarch64_none_elf_prefix}"
682
683 source "$config_file"
684
685 if [ -f "$env_file" ]; then
686 set -a
687 source "$env_file"
688 set +a
689 fi
690
691 cd "$rmm_root"
692
693 if [ -f "$rmm_root/requirements.txt" ]; then
694 export PATH="$HOME/.local/bin:$PATH"
695 python3 -m pip install --upgrade pip
696 python3 -m pip install -r "$rmm_root/requirements.txt"
697 fi
698
699 # Always distclean when running on Jenkins. Skip distclean when running
700 # locally and explicitly requested.
701 if upon "$jenkins_run" || not_upon "$dont_clean"; then
702 # Remove 'rmm\build' folder
703 echo "Removing $rmm_build_root..."
704 rm -rf $rmm_build_root
705 fi
706
Manish V Badarkhea3505272025-04-17 14:20:42 +0100707 if not_upon "$local_ci"; then
708 connect_debugger=0
709 fi
710
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000711 # Log build command line. It is left unfolded on purpose to assist
712 # copying to clipboard.
713 cat <<EOF | log_separator >/dev/null
714
715Build command line:
Manish V Badarkhea3505272025-04-17 14:20:42 +0100716 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}
717 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 +0000718
Manish V Badarkhea3505272025-04-17 14:20:42 +0100719EOF
720 cmake \
721 -DRMM_CONFIG=${plat}_defcfg $cmake_gen \
722 -S $rmm_root -B $rmm_build_root \
723 -DRMM_TOOLCHAIN=$rmm_toolchain \
724 -DRMM_FPU_USE_AT_REL2=$rmm_fpu_use_at_rel2 \
725 -DATTEST_EL3_TOKEN_SIGN=$rmm_attest_el3_token_sign \
726 -DRMM_V1_1=$rmm_v1_1 \
727 ${extra_options}
728 cmake --build $rmm_build_root --config $cmake_build_type $make_j_opts -v ${extra_targets+-- $extra_targets} 3>&1 &>>"$build_log" || fail_build
729 )
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000730}
731
Fathi Boudra422bf772019-12-02 11:10:16 +0200732# Set metadata for the whole package so that it can be used by both Jenkins and
733# shell
734set_package_var() {
735 env_file="$artefacts/env" emit_env "$@"
736}
737
738set_tf_build_targets() {
739 echo "Set build target to '${targets:?}'"
740 set_hook_var "tf_build_targets" "$targets"
741}
742
743set_tftf_build_targets() {
744 echo "Set build target to '${targets:?}'"
745 set_hook_var "tftf_build_targets" "$targets"
746}
747
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100748set_spm_build_targets() {
749 echo "Set build target to '${targets:?}'"
750 set_hook_var "spm_build_targets" "$targets"
751}
752
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000753set_spm_out_dir() {
754 echo "Set SPMC binary build to '${out_dir:?}'"
755 set_hook_var "spm_secure_out_dir" "$out_dir"
756}
Fathi Boudra422bf772019-12-02 11:10:16 +0200757# Look under $archive directory for known files such as blX images, kernel, DTB,
758# initrd etc. For each known file foo, if foo.bin exists, then set variable
759# foo_bin to the path of the file. Make the path relative to the workspace so as
760# to remove any @ characters, which Jenkins inserts for parallel runs. If the
761# file doesn't exist, unset its path.
762set_default_bin_paths() {
763 local image image_name image_path path
764 local archive="${archive:?}"
765 local set_vars
766 local var
767
768 pushd "$archive"
769
770 for file in *.bin; do
771 # Get a shell variable from the file's stem
772 var_name="${file%%.*}_bin"
773 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
774
775 # Skip setting the variable if it's already
776 if [ "${!var_name}" ]; then
777 echo "Note: not setting $var_name; already set to ${!var_name}"
778 continue
779 else
780 set_vars+="$var_name "
781 fi
782
783 eval "$var_name=$file"
784 done
785
786 echo "Binary paths set for: "
787 {
788 for var in $set_vars; do
789 echo -n "\$$var "
790 done
791 } | fmt -80 | sed 's/^/ /'
792 echo
793
794 popd
795}
796
797gen_model_params() {
798 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000799 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200800
801 set_default_bin_paths
802 echo "Generating model parameter for $model..."
803 source "$ci_root/model/${model:?}.sh"
804 archive_file "$model_param_file"
805}
806
807set_model_path() {
808 set_run_env "model_path" "${1:?}"
809}
810
Zelalem1af7a7b2020-08-04 17:34:32 -0500811set_model_env() {
812 local var="${1:?}"
813 local val="${2?}"
814 local run_root="${archive:?}/run"
815
816 mkdir -p "$run_root"
817 echo "export $var=$val" >> "$run_root/model_env"
818}
Fathi Boudra422bf772019-12-02 11:10:16 +0200819set_run_env() {
820 local var="${1:?}"
821 local val="${2?}"
822 local run_root="${archive:?}/run"
823
824 mkdir -p "$run_root"
825 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
826}
827
828show_head() {
829 # Display HEAD descripton
830 pushd "$1"
831 git show --quiet --no-color | sed 's/^/ > /g'
832 echo
833 popd
834}
835
836# Choose debug binaries to run; by default, release binaries are chosen to run
837use_debug_bins() {
838 local run_root="${archive:?}/run"
839
840 echo "Choosing debug binaries for execution"
841 set_package_var "BIN_MODE" "debug"
842}
843
844assert_can_git_clone() {
845 local name="${1:?}"
846 local dir="${!name}"
847
848 # If it doesn't exist, it can be cloned into
849 if [ ! -e "$dir" ]; then
850 return 0
851 fi
852
853 # If it's a directory, it must be a Git clone already
854 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
855 # No need to clone again
856 echo "Using existing git clone for $name: $dir"
857 return 1
858 fi
859
860 die "Path $dir exists but is not a git clone"
861}
862
863clone_repo() {
864 if ! is_url "${clone_url?}"; then
865 # For --depth to take effect on local paths, it needs to use the
866 # file:// scheme.
867 clone_url="file://$clone_url"
868 fi
869
870 git clone -q --depth 1 "$clone_url" "${where?}"
871 if [ "$refspec" ]; then
872 pushd "$where"
873 git fetch -q --depth 1 origin "$refspec"
874 git checkout -q FETCH_HEAD
875 popd
876 fi
877}
878
879build_unstable() {
880 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
881}
882
883undo_patch_record() {
884 if [ ! -f "${patch_record:?}" ]; then
885 return
886 fi
887
888 # Undo patches in reverse
889 echo
890 for patch_name in $(tac "$patch_record"); do
891 echo "Undoing $patch_name..."
892 if ! git apply -R "$ci_root/patch/$patch_name"; then
893 if upon "$local_ci"; then
894 echo
895 echo "Your local directory may have been dirtied."
896 echo
897 fi
898 fail_build
899 fi
900 done
901
902 rm -f "$patch_record"
903}
904
905undo_local_patches() {
906 pushd "$tf_root"
907 patch_record="$tf_patch_record" undo_patch_record
908 popd
909
910 if [ -d "$tftf_root" ]; then
911 pushd "$tftf_root"
912 patch_record="$tftf_patch_record" undo_patch_record
913 popd
914 fi
915}
916
917undo_tftf_patches() {
918 pushd "$tftf_root"
919 patch_record="$tftf_patch_record" undo_patch_record
920 popd
921}
922
923undo_tf_patches() {
924 pushd "$tf_root"
925 patch_record="$tf_patch_record" undo_patch_record
926 popd
927}
928
929apply_patch() {
930 # If skip_patches is set, the developer has applied required patches
931 # manually. They probably want to keep them applied for debugging
932 # purposes too. This means we don't have to apply/revert them as part of
933 # build process.
934 if upon "$skip_patches"; then
935 echo "Skipped applying ${1:?}..."
936 return 0
937 else
938 echo "Applying ${1:?}..."
939 fi
940
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +0200941 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -0500942 echo "Skipping already applied ${1:?}"
943 return 0
944 fi
945
Fathi Boudra422bf772019-12-02 11:10:16 +0200946 if git apply < "$ci_root/patch/$1"; then
947 echo "$1" >> "${patch_record:?}"
948 else
949 if upon "$local_ci"; then
950 undo_local_patches
951 fi
952 fail_build
953 fi
954}
955
Fathi Boudra422bf772019-12-02 11:10:16 +0200956apply_tf_patch() {
957 pushd "$tf_root"
958 patch_record="$tf_patch_record" apply_patch "$1"
959 popd
960}
961
Fathi Boudra422bf772019-12-02 11:10:16 +0200962mkdir -p "$workspace"
963mkdir -p "$archive"
964set_package_var "TEST_CONFIG" "$test_config"
965
966{
967echo
968echo "CONFIGURATION: $test_group/$test_config"
969echo
970} |& log_separator
971
972tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
973tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
Chris Kay4f7846a2025-08-04 19:56:35 +0100974spm_config="$(echo "$build_configs" | awk -F, '{print $3}')"
975rmm_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Fathi Boudra422bf772019-12-02 11:10:16 +0200976
977test_config_file="$ci_root/group/$test_group/$test_config"
978
979tf_config_file="$ci_root/tf_config/$tf_config"
980tftf_config_file="$ci_root/tftf_config/$tftf_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100981spm_config_file="$ci_root/spm_config/$spm_config"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +0000982rmm_config_file="$ci_root/rmm_config/$rmm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200983
984# File that keeps track of applied patches
985tf_patch_record="$workspace/tf_patches"
986tftf_patch_record="$workspace/tftf_patches"
987
988pushd "$workspace"
989
990if ! config_valid "$tf_config"; then
991 tf_config=
992else
993 echo "Trusted Firmware config:"
994 echo
995 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
996 echo
997fi
998
999if ! config_valid "$tftf_config"; then
1000 tftf_config=
1001else
1002 echo "Trusted Firmware TF config:"
1003 echo
1004 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1005 echo
1006fi
1007
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001008if ! config_valid "$spm_config"; then
1009 spm_config=
1010else
1011 echo "SPM config:"
1012 echo
1013 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001014 echo
1015fi
1016
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001017# File that keeps track of applied patches
1018rmm_patch_record="$workspace/rmm_patches"
1019
1020if ! config_valid "$rmm_config"; then
1021 rmm_config=
1022else
1023 echo "Trusted Firmware RMM config:"
1024 echo
1025 sort "$rmm_config_file" | sed '/^\s*$/d;s/^/\t/'
1026 echo
1027fi
1028
Fathi Boudra422bf772019-12-02 11:10:16 +02001029if ! config_valid "$run_config"; then
1030 run_config=
1031fi
1032
1033if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1034 # If the Trusted Firmware repository has already been checked out, use
1035 # that location. Otherwise, clone one ourselves.
1036 echo "Cloning Trusted Firmware..."
1037 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1038 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1039 show_head "$tf_root"
1040fi
1041
1042if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1043 # If the Trusted Firmware TF repository has already been checked out,
1044 # use that location. Otherwise, clone one ourselves.
1045 echo "Cloning Trusted Firmware TF..."
1046 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1047 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1048 show_head "$tftf_root"
1049fi
1050
Zelalem219df412020-05-17 19:21:20 -05001051if [ -n "$cc_config" ] ; then
1052 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1053 # Copy code coverage repository
1054 echo "Cloning Code Coverage..."
1055 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1056 show_head "$cc_root"
1057 fi
1058fi
1059
Daniel Boulby25385ab2023-12-14 14:36:25 +00001060if [ "$spm_config" ] ; then
1061 if assert_can_git_clone "spm_root"; then
1062 # If the SPM repository has already been checked out, use
1063 # that location. Otherwise, clone one ourselves.
1064 echo "Cloning SPM..."
1065 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1066 where="$spm_root" refspec="$SPM_REFSPEC" \
1067 clone_repo &>>"$build_log"
1068 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001069
1070 # Query git submodules
1071 pushd "$spm_root"
Daniel Boulby25385ab2023-12-14 14:36:25 +00001072 # Check if submodules need initialising
Paul Sokolovskyad274422024-09-01 10:27:56 +03001073
1074 # This handling is needed to reliably fetch submodules
1075 # in CI environment.
1076 for subm in $(git submodule status | awk '/^-/ {print $2}'); do
1077 for i in $(seq 1 7); do
1078 git submodule init $subm
1079 if git submodule update $subm; then
1080 break
1081 fi
1082 git submodule deinit --force $subm
1083 echo "Retrying $subm"
1084 sleep $((RANDOM % 10 + 5))
1085 done
1086 done
1087
1088 git submodule status
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001089 popd
1090
1091 show_head "$spm_root"
1092fi
1093
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001094if [ "$rmm_config" ] && assert_can_git_clone "rmm_root"; then
Manish V Badarkhe41909452025-04-11 12:06:45 +01001095 # If the RMM repository has already been checked out,
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001096 # use that location. Otherwise, clone one ourselves.
1097 echo "Cloning TF-RMM..."
1098 clone_url="${RMM_CHECKOUT_LOC:-$rmm_src_repo_url}" where="$rmm_root" \
1099 refspec="$RMM_REFSPEC" clone_repo &>>"$build_log"
1100 show_head "$rmm_root"
1101fi
1102
Fathi Boudra422bf772019-12-02 11:10:16 +02001103if [ "$run_config" ]; then
1104 # Get candidates for run config
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001105 run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \
Fathi Boudra422bf772019-12-02 11:10:16 +02001106 "$run_config")"
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001107 if [ -z "$run_config_candidates" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001108 die "No run config candidates!"
1109 else
1110 echo
1111 echo "Chosen fragments:"
1112 echo
Nicola Mazzucato7fc5abd2024-02-23 21:32:48 +00001113 echo "$run_config_candidates" | sed 's/^\|\n/\t/g'
Fathi Boudra422bf772019-12-02 11:10:16 +02001114 echo
Harrison Mutai4dfe1192024-07-03 12:35:38 +00001115
1116 if [ ! -n "$bin_mode" ]; then
1117 if echo $run_config_candidates | grep -wq "debug"; then
1118 bin_mode="debug"
1119 else
1120 bin_mode="release"
1121 fi
1122 fi
Fathi Boudra422bf772019-12-02 11:10:16 +02001123 fi
1124fi
1125
1126call_hook "test_setup"
1127echo
1128
1129if upon "$local_ci"; then
1130 # For local runs, since each config is tried in sequence, it's
1131 # advantageous to run jobs in parallel
1132 if [ "$make_j" ]; then
1133 make_j_opts="-j $make_j"
1134 else
1135 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1136 if [ "$n_cores" ]; then
1137 make_j_opts="-j $n_cores"
1138 fi
1139 fi
1140fi
1141
Harrison Mutai07043e92023-07-06 09:41:12 +01001142# Install python build dependencies
1143if is_arm_jenkins_env; then
1144 source "$ci_root/script/install_python_deps.sh"
1145fi
1146
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001147# Print CMake version
1148cmake_ver=$(echo `cmake --version | sed -n '1p'`)
1149echo "Using $cmake_ver"
1150
1151# Check for Ninja
1152if [ -x "$(command -v ninja)" ]; then
1153 # Print Ninja version
1154 ninja_ver=$(echo `ninja --version | sed -n '1p'`)
1155 echo "Using ninja $ninja_ver"
1156 export cmake_gen="-G Ninja"
1157else
1158 echo 'Ninja is not installed'
1159 export cmake_gen=""
1160fi
1161
1162undo_rmm_patches() {
1163 pushd "$rmm_root"
1164 patch_record="$rmm_patch_record" undo_patch_record
1165 popd
1166}
1167
Fathi Boudra422bf772019-12-02 11:10:16 +02001168modes="${bin_mode:-debug release}"
1169for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001170 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001171 # Build with a temporary archive
1172 build_archive="$archive/$mode"
1173 mkdir "$build_archive"
1174
1175 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001176 export bin_mode="debug"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001177 cmake_build_type="Debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001178 DEBUG=1
1179 else
Zelalem219df412020-05-17 19:21:20 -05001180 export bin_mode="release"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001181 cmake_build_type="Release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001182 DEBUG=0
1183 fi
1184
1185 # Perform builds in a subshell so as not to pollute the current and
1186 # subsequent builds' environment
1187
Zelalem219df412020-05-17 19:21:20 -05001188 if config_valid "$cc_config"; then
1189 # Build code coverage plugin
1190 build_cc
1191 fi
1192
Fathi Boudra422bf772019-12-02 11:10:16 +02001193 # TFTF build
1194 if config_valid "$tftf_config"; then
1195 (
1196 echo "##########"
1197
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001198 plat_utils="$(get_tf_opt PLAT_UTILS)"
1199 if [ -z ${plat_utils} ]; then
1200 # Source platform-specific utilities.
1201 plat="$(get_tftf_opt PLAT)"
1202 plat_utils="$ci_root/${plat}_utils.sh"
1203 else
1204 # Source platform-specific utilities by
1205 # using plat_utils name.
1206 plat_utils="$ci_root/${plat_utils}.sh"
1207 fi
1208
Fathi Boudra422bf772019-12-02 11:10:16 +02001209 if [ -f "$plat_utils" ]; then
1210 source "$plat_utils"
1211 fi
1212
1213 archive="$build_archive"
Boyan Karatotev97de8d82025-03-06 15:22:21 +00001214 tftf_build_root="$archive/build/tftf"
1215 mkdir -p ${tftf_build_root}
Fathi Boudra422bf772019-12-02 11:10:16 +02001216
1217 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1218
1219 # Call pre-build hook
1220 call_hook pre_tftf_build
1221
1222 build_tftf
1223
1224 from="$tftf_build_root" to="$archive" collect_build_artefacts
1225
1226 # Clear any local changes made by applied patches
1227 undo_tftf_patches
1228
1229 echo "##########"
1230 echo
1231 )
1232 fi
1233
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001234 # SPM build
1235 if config_valid "$spm_config"; then
1236 (
1237 echo "##########"
1238
1239 # Get platform name from spm_config file
1240 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1241 plat_utils="$ci_root/${plat}_utils.sh"
1242 if [ -f "$plat_utils" ]; then
1243 source "$plat_utils"
1244 fi
1245
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001246 # Call pre-build hook
1247 call_hook pre_spm_build
1248
Manish Pandey1e7be852020-11-09 16:04:48 +00001249 # SPM build generates two sets of binaries, one for normal and other
1250 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001251 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001252 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1253 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001254
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001255 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001256 echo "Building SPM ($mode) ..." |& log_separator
1257
1258 # NOTE: mode has no effect on SPM build (for now), hence debug
1259 # mode is built but subsequent build using release mode just
1260 # goes through with "nothing to do".
1261 build_spm
1262
1263 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001264 cksum $spm_build_root/hafnium.bin
1265
1266 # Some platforms only have secure configuration enabled. Hence,
1267 # non secure hanfnium binary might not be built.
1268 if [ -f $hafnium_build_root/hafnium.bin ]; then
1269 cksum $hafnium_build_root/hafnium.bin
1270 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001271
Manish Pandey1e7be852020-11-09 16:04:48 +00001272 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001273
1274 echo "##########"
1275 echo
1276 )
1277 fi
1278
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001279 # TF RMM build
1280 if config_valid "$rmm_config"; then
1281 (
1282 echo "##########"
1283
1284 plat_utils="$(get_rmm_opt PLAT_UTILS)"
1285 if [ -z ${plat_utils} ]; then
1286 # Source platform-specific utilities.
1287 plat="$(get_rmm_opt PLAT)"
Manish V Badarkhea3505272025-04-17 14:20:42 +01001288 extra_options="$(get_rmm_opt EXTRA_OPTIONS)"
1289 extra_targets="$(get_rmm_opt EXTRA_TARGETS "")"
1290 rmm_toolchain="$(get_rmm_opt TOOLCHAIN gnu)"
1291 rmm_fpu_use_at_rel2="$(get_rmm_opt RMM_FPU_USE_AT_REL2 OFF)"
1292 rmm_attest_el3_token_sign="$(get_rmm_opt ATTEST_EL3_TOKEN_SIGN OFF)"
1293 rmm_v1_1="$(get_rmm_opt RMM_V1_1 ON)"
Manish V Badarkhed62aa5f2025-03-18 21:18:14 +00001294 plat_utils="$ci_root/${plat}_utils.sh"
1295 else
1296 # Source platform-specific utilities by
1297 # using plat_utils name.
1298 plat_utils="$ci_root/${plat_utils}.sh"
1299 fi
1300
1301 if [ -f "$plat_utils" ]; then
1302 source "$plat_utils"
1303 fi
1304
1305 archive="$build_archive"
1306 rmm_build_root="$rmm_root/build"
1307
1308 echo "Building Trusted Firmware RMM ($mode) ..." |& log_separator
1309
1310 #call_hook pre_rmm_build
1311 build_rmm
1312
1313 # Collect all rmm.* files: rmm.img, rmm.elf, rmm.dump, rmm.map
1314 from="$rmm_build_root" to="$archive" collect_build_artefacts
1315
1316 # Clear any local changes made by applied patches
1317 undo_rmm_patches
1318
1319 echo "##########"
1320 )
1321 fi
1322
Fathi Boudra422bf772019-12-02 11:10:16 +02001323 # TF build
1324 if config_valid "$tf_config"; then
1325 (
1326 echo "##########"
1327
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001328 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001329 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1330
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001331 if [ -z ${plat_utils} ]; then
1332 # Source platform-specific utilities.
1333 plat="$(get_tf_opt PLAT)"
1334 plat_utils="$ci_root/${plat}_utils.sh"
1335 else
1336 # Source platform-specific utilities by
1337 # using plat_utils name.
1338 plat_utils="$ci_root/${plat_utils}.sh"
1339 fi
1340
Fathi Boudra422bf772019-12-02 11:10:16 +02001341 if [ -f "$plat_utils" ]; then
1342 source "$plat_utils"
1343 fi
1344
Chris Kaye5a486b2023-08-04 11:50:31 +00001345 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1346 fvp_tsram_size="${fvp_tsram_size:-256}"
1347
Harrison Mutaidc703402024-08-02 14:40:16 +00001348 poetry -C "$tf_root" install --without docs
Chris Kayd0837902021-11-17 10:17:52 +00001349
Fathi Boudra422bf772019-12-02 11:10:16 +02001350 archive="$build_archive"
Boyan Karatotev97de8d82025-03-06 15:22:21 +00001351 tf_build_root="$archive/build/tfa"
1352 mkdir -p ${tf_build_root}
Fathi Boudra422bf772019-12-02 11:10:16 +02001353
1354 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1355
1356 # Call pre-build hook
1357 call_hook pre_tf_build
1358
1359 build_tf
1360
1361 # Call post-build hook
1362 call_hook post_tf_build
1363
1364 # Pre-archive hook
1365 call_hook pre_tf_archive
1366
1367 from="$tf_build_root" to="$archive" collect_build_artefacts
1368
1369 # Post-archive hook
1370 call_hook post_tf_archive
1371
1372 call_hook fetch_tf_resource
1373 call_hook post_fetch_tf_resource
1374
Chris Kay4e8aaf12022-09-01 15:21:55 +01001375 # Generate LAVA job files if necessary
1376 call_hook generate_lava_job_template
1377 call_hook generate_lava_job
1378
Fathi Boudra422bf772019-12-02 11:10:16 +02001379 # Clear any local changes made by applied patches
1380 undo_tf_patches
1381
1382 echo "##########"
1383 )
1384 fi
1385
1386 echo
1387 echo
1388done
1389
1390call_hook pre_package
1391
1392call_hook post_package
1393
1394if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001395 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001396fi
1397
1398echo
1399echo "Done"