blob: c63db612c53cc8bbc440ed75a5fa1336a5364bfd [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Yann Gautier7e9d6cf2023-03-08 14:24:38 +01003# Copyright (c) 2019-2023 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}"
Zelalem219df412020-05-17 19:21:20 -050027
28scp_tf_tools_root="$scp_tools_root/scp_tf_tools"
Fathi Boudra422bf772019-12-02 11:10:16 +020029
30# Refspecs
31tf_refspec="$TF_REFSPEC"
32tftf_refspec="$TFTF_REFSPEC"
33scp_refspec="$SCP_REFSPEC"
Zelalem219df412020-05-17 19:21:20 -050034scp_tools_commit="${SCP_TOOLS_COMMIT:-master}"
Olivier Deprez0a9a3482019-12-16 14:10:31 +010035spm_refspec="$SPM_REFSPEC"
Fathi Boudra422bf772019-12-02 11:10:16 +020036
37test_config="${TEST_CONFIG:?}"
38test_group="${TEST_GROUP:?}"
39build_configs="${BUILD_CONFIG:?}"
40run_config="${RUN_CONFIG:?}"
Zelalem219df412020-05-17 19:21:20 -050041cc_config="${CC_ENABLE:-}"
Fathi Boudra422bf772019-12-02 11:10:16 +020042
43archive="$artefacts"
44build_log="$artefacts/build.log"
45fiptool="$tf_root/tools/fiptool/fiptool"
46cert_create="$tf_root/tools/cert_create/cert_create"
47
48# Validate $bin_mode
49case "$bin_mode" in
50 "" | debug | release)
51 ;;
52 *)
53 die "Invalid value for bin_mode: $bin_mode"
54 ;;
55esac
56
57# File to save any environem
58hook_env_file="$(mktempfile)"
59
60# Check if a config is valid
61config_valid() {
62 local config="${1?}"
63 if [ -z "$config" ] || [ "$(basename "$config")" = "nil" ]; then
64 return 1
65 fi
66
67 return 0
68}
69
70# Echo from a build wrapper. Print to descriptor 3 that's opened by the build
71# function.
72echo_w() {
73 echo $echo_flags "$@" >&3
74}
75
76# Print a separator to the log file. Intended to be used at the tail end of a pipe
77log_separator() {
78 {
79 echo
80 echo "----------"
81 } >> "$build_log"
82
83 tee -a "$build_log"
84
85 {
86 echo "----------"
87 echo
88 } >> "$build_log"
89}
90
91# Call function $1 if it's defined
92call_func() {
93 if type "${1:?}" &>/dev/null; then
94 echo
95 echo "> ${2:?}:$1()"
96 eval "$1"
97 echo "< $2:$1()"
98 fi
99}
100
101# Call hook $1 in all chosen fragments if it's defined. Hooks are invoked from
102# within a subshell, so any variables set within a hook are lost. Should a
103# variable needs to be set from within a hook, the function 'set_hook_var'
104# should be used
105call_hook() {
106 local func="$1"
107 local config_fragment
108
109 [ -z "$func" ] && return 0
110
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300111 echo "=== Calling hooks: $1 ==="
112
Fathi Boudra422bf772019-12-02 11:10:16 +0200113 : >"$hook_env_file"
114
115 if [ "$run_config_candiates" ]; then
116 for config_fragment in $run_config_candiates; do
117 (
118 source "$ci_root/run_config/$config_fragment"
119 call_func "$func" "$config_fragment"
120 )
121 done
122 fi
123
124 # Also source test config file
125 (
126 unset "$func"
127 source "$test_config_file"
128 call_func "$func" "$(basename $test_config_file)"
129 )
130
131 # Have any variables set take effect
132 source "$hook_env_file"
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300133
134 echo "=== End calling hooks: $1 ==="
Fathi Boudra422bf772019-12-02 11:10:16 +0200135}
136
137# Set a variable from within a hook
138set_hook_var() {
139 echo "export $1=\"${2?}\"" >> "$hook_env_file"
140}
141
142# Append to an array from within a hook
143append_hook_var() {
144 echo "export $1+=\"${2?}\"" >> "$hook_env_file"
145}
146
147# Have the main build script source a file
148source_later() {
149 echo "source ${1?}" >> "$hook_env_file"
150}
151
152# Setup TF build wrapper function by pointing to a script containing a function
153# that will be called with the TF build commands.
154setup_tf_build_wrapper() {
155 source_later "$ci_root/script/${wrapper?}_wrapper.sh"
156 set_hook_var "tf_build_wrapper" "${wrapper}_wrapper"
157 echo "Setup $wrapper build wrapper."
158}
159
160# Collect .bin files for archiving
161collect_build_artefacts() {
162 if [ ! -d "${from:?}" ]; then
163 return
164 fi
165
Yann Gautier7e9d6cf2023-03-08 14:24:38 +0100166 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 +0200167 echo "You probably are running local CI on local repositories."
168 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
169 die
170 fi
171}
172
173# SCP and MCP binaries are named firmware.{bin,elf}, and are placed under
174# scp/mcp_ramfw and scp/mcp_romfw directories, so can't be collected by
175# collect_build_artefacts function.
176collect_scp_artefacts() {
177 to="${to:?}" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000178 find "$scp_root" \( \( -name "*.bin" -o -name '*.elf' \) -and ! -name 'CMake*' \) -exec bash -c '
Fathi Boudra422bf772019-12-02 11:10:16 +0200179 for file; do
180 ext="$(echo $file | awk -F. "{print \$NF}")"
181 case $file in
Anurag Koulbaedf932021-12-09 12:49:56 +0000182 */firmware-scp_ramfw/bin/*|*/firmware-scp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200183 cp $file $to/scp_ram.$ext
184 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000185 */firmware-scp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200186 cp $file $to/scp_rom.$ext
187 ;;
Anurag Koulbaedf932021-12-09 12:49:56 +0000188 */firmware-mcp_ramfw/bin/*|*/firmware-mcp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200189 cp $file $to/mcp_ram.$ext
190 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000191 */firmware-mcp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200192 cp $file $to/mcp_rom.$ext
193 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000194 */firmware-scp_romfw_bypass/bin/*)
Zelalem219df412020-05-17 19:21:20 -0500195 cp $file $to/scp_rom_bypass.$ext
196 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200197 *)
198 echo "Unknown SCP binary: $file" >&2
199 ;;
200 esac
201 done
202 ' bash '{}' +
203}
204
Manish Pandey1e7be852020-11-09 16:04:48 +0000205# Collect SPM/hafnium artefacts with "secure_" appended to the files
206# generated for SPM(secure hafnium).
207collect_spm_artefacts() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500208 if [ -d "${non_secure_from:?}" ]; then
209 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000210 fi
211
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500212 if [ -d "${secure_from:?}" ]; then
213 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
214 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000215}
216
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100217# Map the UART ID used for expect with the UART descriptor and port
218# used by the FPGA automation tools.
219map_uart() {
220 local port="${port:?}"
221 local descriptor="${descriptor:?}"
222 local baudrate="${baudrate:?}"
223 local run_root="${archive:?}/run"
224
225 local uart_dir="$run_root/uart${uart:?}"
226 mkdir -p "$uart_dir"
227
228 echo "$port" > "$uart_dir/port"
229 echo "$descriptor" > "$uart_dir/descriptor"
230 echo "$baudrate" > "$uart_dir/baudrate"
231
232 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
233}
234
Fathi Boudra422bf772019-12-02 11:10:16 +0200235# Arrange environment varibles to be set when expect scripts are launched
236set_expect_variable() {
237 local var="${1:?}"
238 local val="${2?}"
239
240 local run_root="${archive:?}/run"
241 local uart_dir="$run_root/uart${uart:?}"
242 mkdir -p "$uart_dir"
243
244 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
245 echo "UART$uart: env has $@"
246}
247
248# Place the binary package a pointer to expect script, and its parameters
249track_expect() {
250 local file="${file:?}"
251 local timeout="${timeout-600}"
252 local run_root="${archive:?}/run"
253
254 local uart_dir="$run_root/uart${uart:?}"
255 mkdir -p "$uart_dir"
256
257 echo "$file" > "$uart_dir/expect"
258 echo "$timeout" > "$uart_dir/timeout"
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700259 if [ -n "$lava_timeout" ]; then
260 set_run_env "lava_timeout" "$lava_timeout"
261 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200262
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700263 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 +0200264
Chris Kayfab6edc2022-11-17 19:18:32 +0000265 if [ ! -z "${port}" ]; then
266 echo "${port}" > "$uart_dir/port"
267 fi
268
Fathi Boudra422bf772019-12-02 11:10:16 +0200269 # The run script assumes UART0 to be primary. If we're asked to set any
270 # other UART to be primary, set a run environment variable to signal
271 # that to the run script
272 if upon "$set_primary"; then
273 echo "Primary UART set to UART$uart."
274 set_run_env "primary_uart" "$uart"
275 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600276
277 # UART used by payload(such as tftf, Linux) may not be the same as the
278 # primary UART. Set a run environment variable to track the payload
279 # UART which is tracked to check if the test has finished sucessfully.
280 if upon "$set_payload_uart"; then
281 echo "Payload uses UART$uart."
282 set_run_env "payload_uart" "$uart"
283 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200284}
285
286# Extract a FIP in $1 using fiptool
287extract_fip() {
288 local fip="$1"
289
290 if is_url "$1"; then
291 url="$1" fetch_file
292 fip="$(basename "$1")"
293 fi
294
295 "$fiptool" unpack "$fip"
296 echo "Extracted FIP: $fip"
297}
298
299# Report build failure by printing a the tail end of build log. Archive the
300# build log for later inspection
301fail_build() {
302 local log_path
303
304 if upon "$jenkins_run"; then
305 log_path="$BUILD_URL/artifact/artefacts/build.log"
306 else
307 log_path="$build_log"
308 fi
309
310 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600311 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200312 echo "[...]"
313 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600314 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200315 echo
316 echo "See $log_path for full output"
317 echo
318 cp -t "$archive" "$build_log"
319 exit 1;
320}
321
322# Build a FIP with supplied arguments
323build_fip() {
324 (
325 echo "Building FIP with arguments: $@"
326 local tf_env="$workspace/tf.env"
327
328 if [ -f "$tf_env" ]; then
329 set -a
330 source "$tf_env"
331 set +a
332 fi
333
334 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
335 ${fip_targets:-fip} &>>"$build_log" || fail_build
336 )
337}
338
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200339# Build any extra rule from TF-A makefile with supplied arguments.
340#
341# This is useful in case you need to build something else than firmware binaries
342# or the FIP.
343build_tf_extra() {
344 (
345 tf_extra_rules=${tf_extra_rules:?}
346 echo "Building extra TF rule(s): $tf_extra_rules"
347 echo " Arguments: $@"
348
349 local tf_env="$workspace/tf.env"
350
351 if [ -f "$tf_env" ]; then
352 set -a
353 source "$tf_env"
354 set +a
355 fi
356
357 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
358 ${tf_extra_rules} &>>"$build_log" || fail_build
359 )
360}
361
Fathi Boudra422bf772019-12-02 11:10:16 +0200362fip_update() {
363 # Before the update process, check if the given image is supported by
364 # the fiptool. It's assumed that both fiptool and cert_create move in
365 # tandem, and therfore, if one has support, the other has it too.
366 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
367 return 1
368 fi
369
370 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
371 echo "Updating FIP image: $bin_name"
372 # Update HW config. Without TBBR, it's only a matter of using
373 # the update sub-command of fiptool
374 "$fiptool" update "--$bin_name" "${src:-}" \
375 "$archive/fip.bin"
376 else
377 echo "Updating FIP image (TBBR): $bin_name"
378 # With TBBR, we need to unpack, re-create certificates, and then
379 # recreate the FIP.
380 local fip_dir="$(mktempdir)"
381 local bin common_args stem
382 local rot_key="$(get_tf_opt ROT_KEY)"
383
384 rot_key="${rot_key:?}"
385 if ! is_abs "$rot_key"; then
386 rot_key="$tf_root/$rot_key"
387 fi
388
389 # Arguments only for cert_create
390 local cert_args="-n"
391 cert_args+=" --tfw-nvctr ${nvctr:-31}"
392 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
393 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
394 cert_args+=" --rot-key $rot_key"
395
396 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500397 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200398 "hw-config"
399 "tb-fw-config"
400 "nt-fw-config"
401 "soc-fw-config"
402 "tos-fw-config"
403 )
404
405 # Binaries without key certificates
406 declare -A has_no_key_cert
407 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
408 has_no_key_cert["$bin"]="1"
409 done
410
411 # Binaries without certificates
412 declare -A has_no_cert
413 for bin in "hw-config" "${dyn_config_opts[@]}"; do
414 has_no_cert["$bin"]="1"
415 done
416
417 pushd "$fip_dir"
418
419 # Unpack FIP
420 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
421
422 # Remove all existing certificates
423 rm -f *-cert.bin
424
425 # Copy the binary to be updated
426 cp -f "$src" "${bin_name}.bin"
427
428 # FIP unpack dumps binaries with the same name as the option
429 # used to pack it; likewise for certificates. Reverse-engineer
430 # the command line from the binary output.
431 common_args="--trusted-key-cert trusted_key.crt"
432 for bin in *.bin; do
433 stem="${bin%%.bin}"
434 common_args+=" --$stem $bin"
435 if not_upon "${has_no_cert[$stem]}"; then
436 common_args+=" --$stem-cert $stem.crt"
437 fi
438 if not_upon "${has_no_key_cert[$stem]}"; then
439 common_args+=" --$stem-key-cert $stem-key.crt"
440 fi
441 done
442
443 # Create certificates
444 "$cert_create" $cert_args $common_args &>>"$build_log"
445
446 # Recreate and archive FIP
447 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
448 archive_file "fip.bin"
449
450 popd
451 fi
452}
453
454# Update hw-config in FIP, and remove the original DTB afterwards.
455update_fip_hw_config() {
456 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600457 # in configs:
458 # 1. Where BL2 isn't present
459 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200460 case "1" in
461 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600462 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200463 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000464 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200465 return 0;;
466 esac
467
468 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
469 # Remove the DTB so that model won't load it
470 rm -f "$archive/dtb.bin"
471 fi
472}
473
474get_scp_opt() {
475 (
476 name="${1:?}"
477 if config_valid "$scp_config_file"; then
478 source "$scp_config_file"
479 echo "${!name}"
480 fi
481 )
482}
483
484get_tftf_opt() {
485 (
486 name="${1:?}"
487 if config_valid "$tftf_config_file"; then
488 source "$tftf_config_file"
489 echo "${!name}"
490 fi
491 )
492}
493
494get_tf_opt() {
495 (
496 name="${1:?}"
497 if config_valid "$tf_config_file"; then
498 source "$tf_config_file"
499 echo "${!name}"
500 fi
501 )
502}
503
504build_tf() {
505 (
506 env_file="$workspace/tf.env"
507 config_file="${tf_build_config:-$tf_config_file}"
508
509 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100510 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200511
512 source "$config_file"
513
514 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000515 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100516 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
517 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200518 mbedtls_dir="$workspace/mbedtls"
519 if [ ! -d "$mbedtls_dir" ]; then
520 mbedtls_ar="$workspace/mbedtls.tar.gz"
521
522 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
523 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500524 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200525 fi
526
527 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
528 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500529 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
530 not_upon "${TF_M_TESTS_PATH}"; then
531 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
532 fi
533 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
534 not_upon "${TF_M_EXTRAS_PATH}"; then
535 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
536 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200537 if [ -f "$env_file" ]; then
538 set -a
539 source "$env_file"
540 set +a
541 fi
542
Harrison Mutai013f6332022-02-16 16:06:33 +0000543 if is_arm_jenkins_env || upon "$local_ci"; then
544 path_list=(
545 "$llvm_dir/bin"
546 )
547 extend_path "PATH" "path_list"
548 fi
549
Fathi Boudra422bf772019-12-02 11:10:16 +0200550 cd "$tf_root"
551
552 # Always distclean when running on Jenkins. Skip distclean when running
553 # locally and explicitly requested.
554 if upon "$jenkins_run" || not_upon "$dont_clean"; then
555 make distclean &>>"$build_log" || fail_build
556 fi
557
558 # Log build command line. It is left unfolded on purpose to assist
559 # copying to clipboard.
560 cat <<EOF | log_separator >/dev/null
561
562Build command line:
563 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
564
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300565CC version:
566$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200567EOF
568
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000569 if not_upon "$local_ci"; then
570 connect_debugger=0
571 fi
572
Fathi Boudra422bf772019-12-02 11:10:16 +0200573 # Build TF. Since build output is being directed to the build log, have
574 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000575 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000576 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200577 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100578
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100579 if [ "$build_targets" != "doc" ]; then
580 poetry run memory -sr "$tf_build_path" 2>&1 | tee -a "$build_log"
581 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200582 )
583}
584
585build_tftf() {
586 (
587 config_file="${tftf_build_config:-$tftf_config_file}"
588
589 # Build tftf target by default
590 build_targets="${tftf_build_targets:-all}"
591
592 source "$config_file"
593
594 cd "$tftf_root"
595
596 # Always distclean when running on Jenkins. Skip distclean when running
597 # locally and explicitly requested.
598 if upon "$jenkins_run" || not_upon "$dont_clean"; then
599 make distclean &>>"$build_log" || fail_build
600 fi
601
602 # TFTF build system cannot reliably deal with -j option, so we avoid
603 # using that.
604
605 # Log build command line
606 cat <<EOF | log_separator >/dev/null
607
608Build command line:
609 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
610
611EOF
612
613 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
614 $build_targets &>>"$build_log" || fail_build
615 )
616}
617
618build_scp() {
619 (
620 config_file="${scp_build_config:-$scp_config_file}"
621
622 source "$config_file"
623
624 cd "$scp_root"
625
626 # Always distclean when running on Jenkins. Skip distclean when running
627 # locally and explicitly requested.
628 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000629 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200630 fi
631
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000632 python3 -m venv .venv
633 . .venv/bin/activate
634
635 # Install extra tools used by CMake build system
636 pip install -r requirements.txt --timeout 30 --retries 15
637
Fathi Boudra422bf772019-12-02 11:10:16 +0200638 # Log build command line. It is left unfolded on purpose to assist
639 # copying to clipboard.
640 cat <<EOF | log_separator >/dev/null
641
642SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000643 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
644 TOOLCHAIN=GNU \
645 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000646 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000647 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200648
649EOF
650
651 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000652 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
653 TOOLCHAIN=GNU \
654 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000655 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000656 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200657 || fail_build
658 )
659}
660
Zelalem219df412020-05-17 19:21:20 -0500661clone_scp_tools() {
662
663 if [ ! -d "$scp_tools_root" ]; then
664 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
665
666 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
667 where="$scp_tools_root" \
668 refspec="${scp_tools_commit}"
669 clone_repo &>>"$build_log"
670 else
671 echo "Already cloned SCP-tools ..." |& log_separator
672 fi
673
674 show_head "$scp_tools_root"
675
676 cd "$scp_tools_root"
677
678 echo "Updating submodules"
679
680 git submodule init
681
682 git submodule update
683
Nicola Mazzucato9b171422023-08-29 15:50:49 +0100684 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 +0000685
Zelalem219df412020-05-17 19:21:20 -0500686 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000687 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500688
689 git show --quiet --no-color | sed 's/^/ > /g'
690}
691
692clone_tf_for_scp_tools() {
693 scp_tools_arm_tf="$scp_tools_root/arm-tf"
694
695 if [ ! -d "$scp_tools_arm_tf" ]; then
696 echo "Cloning TF-4-SCP-tools ..." |& log_separator
697
698 clone_url="$tf_for_scp_tools_src_repo_url"
699 where="$scp_tools_arm_tf"
700
701 git clone "$clone_url" "$where"
702
703 cd "$scp_tools_arm_tf"
704
Joel Goddard3ad03062021-03-16 16:47:42 +0000705 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500706
707 git show --quiet --no-color | sed 's/^/ > /g'
708
709 else
710 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
711 fi
712}
713
714build_scmi_lib_scp_tools() {
715 (
716 cd "$scp_tools_root"
717
718 cd "scmi"
719
720 scp_tools_arm_tf="$scp_tools_root/arm-tf"
721
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600722 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500723
724 std_libs="-I$scp_tools_arm_tf/include/common"
725 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
726 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
727 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
728 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
729 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
730 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
731 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
732 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
733 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
734 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
735 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
736 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
737 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
738
739 cflags="-Og -g"
740 cflags="$cflags -mgeneral-regs-only"
741 cflags="$cflags -mstrict-align"
742 cflags="$cflags -nostdinc"
743 cflags="$cflags -fno-inline"
744 cflags="$cflags -ffreestanding"
745 cflags="$cflags -ffunction-sections"
746 cflags="$cflags -fdata-sections"
747 cflags="$cflags -DAARCH64"
748 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000749 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500750
751 cflags="$cflags $std_libs"
752
Joel Goddard3ad03062021-03-16 16:47:42 +0000753 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500754
755 echo "Building SCMI library (SCP-tools) ..."
756
757 make "CROSS_COMPILE=$cross_compile" \
758 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000759 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500760 "PROTOCOLS=$protocols" \
761 "clean" \
762 "all"
763 )
764}
765
766build_tf_for_scp_tools() {
767
768 cd "$scp_tools_root/arm-tf"
769
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600770 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500771
772 if [ "$1" = "release" ]; then
773 echo "Build TF-4-SCP-Tools rls..."
774 else
775 echo "Build TF-4-SCP-Tools dbg..."
776
777 make realclean
778
779 make "BM_TEST=scmi" \
780 "ARM_BOARD_OPTIMISE_MEM=1" \
781 "BM_CSS=juno" \
782 "CSS_USE_SCMI_SDS_DRIVER=1" \
783 "PLAT=juno" \
784 "DEBUG=1" \
785 "PLATFORM=juno" \
786 "CROSS_COMPILE=$cross_compile" \
787 "BM_WORKSPACE=$scp_tools_root/baremetal"
788
789 archive_file "build/juno/debug/bl1.bin"
790
791 archive_file "build/juno/debug/bl2.bin"
792
793 archive_file "build/juno/debug/bl31.bin"
794 fi
795}
796
797build_fip_for_scp_tools() {
798
799 cd "$scp_tools_root/arm-tf"
800
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600801 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500802
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000803 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500804 make fiptool
805 echo "Make FIP 4 SCP-Tools rls..."
806
807 else
808 make fiptool
809 echo "Make FIP 4 SCP-Tools dbg..."
810
811 make "PLAT=juno" \
812 "all" \
813 "fip" \
814 "DEBUG=1" \
815 "CROSS_COMPILE=$cross_compile" \
816 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
817 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000818 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500819
820 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
821 fi
822}
823
824build_cc() {
825# Building code coverage plugin
826 ARM_DIR=/arm
827 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
828 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
829 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
830 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
831 exit -1
832 fi # Error if arm warehouse not found
833 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
834
835 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
836}
837
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100838build_spm() {
839 (
840 env_file="$workspace/spm.env"
841 config_file="${spm_build_config:-$spm_config_file}"
842
843 source "$config_file"
844
845 if [ -f "$env_file" ]; then
846 set -a
847 source "$env_file"
848 set +a
849 fi
850
851 cd "$spm_root"
852
853 # Always clean when running on Jenkins. Skip clean when running
854 # locally and explicitly requested.
855 if upon "$jenkins_run" || not_upon "$dont_clean"; then
856 # make clean fails on a fresh repo where the project has not
857 # yet been built. Hence only clean if out/reference directory
858 # already exists.
859 if [ -d "out/reference" ]; then
860 make clean &>>"$build_log" || fail_build
861 fi
862 fi
863
864 # Log build command line. It is left unfolded on purpose to assist
865 # copying to clipboard.
866 cat <<EOF | log_separator >/dev/null
867
868Build command line:
869 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
870
871EOF
872
873 # Build SPM. Since build output is being directed to the build log, have
874 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200875 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
876
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100877 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
878 || fail_build
879 )
880}
Zelalem219df412020-05-17 19:21:20 -0500881
Fathi Boudra422bf772019-12-02 11:10:16 +0200882# Set metadata for the whole package so that it can be used by both Jenkins and
883# shell
884set_package_var() {
885 env_file="$artefacts/env" emit_env "$@"
886}
887
888set_tf_build_targets() {
889 echo "Set build target to '${targets:?}'"
890 set_hook_var "tf_build_targets" "$targets"
891}
892
893set_tftf_build_targets() {
894 echo "Set build target to '${targets:?}'"
895 set_hook_var "tftf_build_targets" "$targets"
896}
897
898set_scp_build_targets() {
899 echo "Set build target to '${targets:?}'"
900 set_hook_var "scp_build_targets" "$targets"
901}
902
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100903set_spm_build_targets() {
904 echo "Set build target to '${targets:?}'"
905 set_hook_var "spm_build_targets" "$targets"
906}
907
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000908set_spm_out_dir() {
909 echo "Set SPMC binary build to '${out_dir:?}'"
910 set_hook_var "spm_secure_out_dir" "$out_dir"
911}
Fathi Boudra422bf772019-12-02 11:10:16 +0200912# Look under $archive directory for known files such as blX images, kernel, DTB,
913# initrd etc. For each known file foo, if foo.bin exists, then set variable
914# foo_bin to the path of the file. Make the path relative to the workspace so as
915# to remove any @ characters, which Jenkins inserts for parallel runs. If the
916# file doesn't exist, unset its path.
917set_default_bin_paths() {
918 local image image_name image_path path
919 local archive="${archive:?}"
920 local set_vars
921 local var
922
923 pushd "$archive"
924
925 for file in *.bin; do
926 # Get a shell variable from the file's stem
927 var_name="${file%%.*}_bin"
928 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
929
930 # Skip setting the variable if it's already
931 if [ "${!var_name}" ]; then
932 echo "Note: not setting $var_name; already set to ${!var_name}"
933 continue
934 else
935 set_vars+="$var_name "
936 fi
937
938 eval "$var_name=$file"
939 done
940
941 echo "Binary paths set for: "
942 {
943 for var in $set_vars; do
944 echo -n "\$$var "
945 done
946 } | fmt -80 | sed 's/^/ /'
947 echo
948
949 popd
950}
951
952gen_model_params() {
953 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000954 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200955
956 set_default_bin_paths
957 echo "Generating model parameter for $model..."
958 source "$ci_root/model/${model:?}.sh"
959 archive_file "$model_param_file"
960}
961
962set_model_path() {
963 set_run_env "model_path" "${1:?}"
964}
965
Zelalem1af7a7b2020-08-04 17:34:32 -0500966set_model_env() {
967 local var="${1:?}"
968 local val="${2?}"
969 local run_root="${archive:?}/run"
970
971 mkdir -p "$run_root"
972 echo "export $var=$val" >> "$run_root/model_env"
973}
Fathi Boudra422bf772019-12-02 11:10:16 +0200974set_run_env() {
975 local var="${1:?}"
976 local val="${2?}"
977 local run_root="${archive:?}/run"
978
979 mkdir -p "$run_root"
980 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
981}
982
983show_head() {
984 # Display HEAD descripton
985 pushd "$1"
986 git show --quiet --no-color | sed 's/^/ > /g'
987 echo
988 popd
989}
990
991# Choose debug binaries to run; by default, release binaries are chosen to run
992use_debug_bins() {
993 local run_root="${archive:?}/run"
994
995 echo "Choosing debug binaries for execution"
996 set_package_var "BIN_MODE" "debug"
997}
998
999assert_can_git_clone() {
1000 local name="${1:?}"
1001 local dir="${!name}"
1002
1003 # If it doesn't exist, it can be cloned into
1004 if [ ! -e "$dir" ]; then
1005 return 0
1006 fi
1007
1008 # If it's a directory, it must be a Git clone already
1009 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
1010 # No need to clone again
1011 echo "Using existing git clone for $name: $dir"
1012 return 1
1013 fi
1014
1015 die "Path $dir exists but is not a git clone"
1016}
1017
1018clone_repo() {
1019 if ! is_url "${clone_url?}"; then
1020 # For --depth to take effect on local paths, it needs to use the
1021 # file:// scheme.
1022 clone_url="file://$clone_url"
1023 fi
1024
1025 git clone -q --depth 1 "$clone_url" "${where?}"
1026 if [ "$refspec" ]; then
1027 pushd "$where"
1028 git fetch -q --depth 1 origin "$refspec"
1029 git checkout -q FETCH_HEAD
1030 popd
1031 fi
1032}
1033
1034build_unstable() {
1035 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1036}
1037
1038undo_patch_record() {
1039 if [ ! -f "${patch_record:?}" ]; then
1040 return
1041 fi
1042
1043 # Undo patches in reverse
1044 echo
1045 for patch_name in $(tac "$patch_record"); do
1046 echo "Undoing $patch_name..."
1047 if ! git apply -R "$ci_root/patch/$patch_name"; then
1048 if upon "$local_ci"; then
1049 echo
1050 echo "Your local directory may have been dirtied."
1051 echo
1052 fi
1053 fail_build
1054 fi
1055 done
1056
1057 rm -f "$patch_record"
1058}
1059
1060undo_local_patches() {
1061 pushd "$tf_root"
1062 patch_record="$tf_patch_record" undo_patch_record
1063 popd
1064
1065 if [ -d "$tftf_root" ]; then
1066 pushd "$tftf_root"
1067 patch_record="$tftf_patch_record" undo_patch_record
1068 popd
1069 fi
1070}
1071
1072undo_tftf_patches() {
1073 pushd "$tftf_root"
1074 patch_record="$tftf_patch_record" undo_patch_record
1075 popd
1076}
1077
1078undo_tf_patches() {
1079 pushd "$tf_root"
1080 patch_record="$tf_patch_record" undo_patch_record
1081 popd
1082}
1083
1084apply_patch() {
1085 # If skip_patches is set, the developer has applied required patches
1086 # manually. They probably want to keep them applied for debugging
1087 # purposes too. This means we don't have to apply/revert them as part of
1088 # build process.
1089 if upon "$skip_patches"; then
1090 echo "Skipped applying ${1:?}..."
1091 return 0
1092 else
1093 echo "Applying ${1:?}..."
1094 fi
1095
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +02001096 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001097 echo "Skipping already applied ${1:?}"
1098 return 0
1099 fi
1100
Fathi Boudra422bf772019-12-02 11:10:16 +02001101 if git apply < "$ci_root/patch/$1"; then
1102 echo "$1" >> "${patch_record:?}"
1103 else
1104 if upon "$local_ci"; then
1105 undo_local_patches
1106 fi
1107 fail_build
1108 fi
1109}
1110
1111apply_tftf_patch() {
1112 pushd "$tftf_root"
1113 patch_record="$tftf_patch_record" apply_patch "$1"
1114 popd
1115}
1116
1117apply_tf_patch() {
1118 pushd "$tf_root"
1119 patch_record="$tf_patch_record" apply_patch "$1"
1120 popd
1121}
1122
1123# Clear workspace for a local run
1124if not_upon "$jenkins_run"; then
1125 rm -rf "$workspace"
1126
1127 # Clear residue from previous runs
1128 rm -rf "$archive"
1129fi
1130
1131mkdir -p "$workspace"
1132mkdir -p "$archive"
1133set_package_var "TEST_CONFIG" "$test_config"
1134
1135{
1136echo
1137echo "CONFIGURATION: $test_group/$test_config"
1138echo
1139} |& log_separator
1140
1141tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1142tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1143scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001144scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001145spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001146
1147test_config_file="$ci_root/group/$test_group/$test_config"
1148
1149tf_config_file="$ci_root/tf_config/$tf_config"
1150tftf_config_file="$ci_root/tftf_config/$tftf_config"
1151scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001152scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001153spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001154
1155# File that keeps track of applied patches
1156tf_patch_record="$workspace/tf_patches"
1157tftf_patch_record="$workspace/tftf_patches"
1158
1159pushd "$workspace"
1160
1161if ! config_valid "$tf_config"; then
1162 tf_config=
1163else
1164 echo "Trusted Firmware config:"
1165 echo
1166 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1167 echo
1168fi
1169
1170if ! config_valid "$tftf_config"; then
1171 tftf_config=
1172else
1173 echo "Trusted Firmware TF config:"
1174 echo
1175 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1176 echo
1177fi
1178
1179if ! config_valid "$scp_config"; then
1180 scp_config=
1181else
1182 echo "SCP firmware config:"
1183 echo
1184 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1185 echo
1186fi
1187
Zelalem219df412020-05-17 19:21:20 -05001188if ! config_valid "$scp_tools_config"; then
1189 scp_tools_config=
1190else
1191 echo "SCP Tools config:"
1192 echo
1193 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001194fi
1195
1196if ! config_valid "$spm_config"; then
1197 spm_config=
1198else
1199 echo "SPM config:"
1200 echo
1201 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001202 echo
1203fi
1204
Fathi Boudra422bf772019-12-02 11:10:16 +02001205if ! config_valid "$run_config"; then
1206 run_config=
1207fi
1208
1209if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1210 # If the Trusted Firmware repository has already been checked out, use
1211 # that location. Otherwise, clone one ourselves.
1212 echo "Cloning Trusted Firmware..."
1213 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1214 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1215 show_head "$tf_root"
1216fi
1217
1218if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1219 # If the Trusted Firmware TF repository has already been checked out,
1220 # use that location. Otherwise, clone one ourselves.
1221 echo "Cloning Trusted Firmware TF..."
1222 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1223 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1224 show_head "$tftf_root"
1225fi
1226
1227if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1228 # If the SCP firmware repository has already been checked out,
1229 # use that location. Otherwise, clone one ourselves.
1230 echo "Cloning SCP Firmware..."
1231 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1232 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1233
1234 pushd "$scp_root"
1235
1236 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001237 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001238 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1239 fi
1240
1241 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1242 # then to project filer if accessible.
1243 if [ -z "$cmsis_reference" ]; then
1244 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1245 if [ -d "$cmsis_ref_repo" ]; then
1246 cmsis_reference="--reference $cmsis_ref_repo"
1247 fi
1248 fi
1249
1250 git submodule -q update $cmsis_reference --init
1251
1252 popd
1253
1254 show_head "$scp_root"
1255fi
1256
Zelalem219df412020-05-17 19:21:20 -05001257if [ -n "$cc_config" ] ; then
1258 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1259 # Copy code coverage repository
1260 echo "Cloning Code Coverage..."
1261 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1262 show_head "$cc_root"
1263 fi
1264fi
1265
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001266if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1267 # If the SPM repository has already been checked out, use
1268 # that location. Otherwise, clone one ourselves.
1269 echo "Cloning SPM..."
1270 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1271 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1272
1273 # Query git submodules
1274 pushd "$spm_root"
1275 git submodule update --init
1276 popd
1277
1278 show_head "$spm_root"
1279fi
1280
Fathi Boudra422bf772019-12-02 11:10:16 +02001281if [ "$run_config" ]; then
1282 # Get candidates for run config
1283 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1284 "$run_config")"
1285 if [ -z "$run_config_candiates" ]; then
1286 die "No run config candidates!"
1287 else
1288 echo
1289 echo "Chosen fragments:"
1290 echo
1291 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1292 echo
1293 fi
1294fi
1295
1296call_hook "test_setup"
1297echo
1298
1299if upon "$local_ci"; then
1300 # For local runs, since each config is tried in sequence, it's
1301 # advantageous to run jobs in parallel
1302 if [ "$make_j" ]; then
1303 make_j_opts="-j $make_j"
1304 else
1305 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1306 if [ "$n_cores" ]; then
1307 make_j_opts="-j $n_cores"
1308 fi
1309 fi
1310fi
1311
Harrison Mutai07043e92023-07-06 09:41:12 +01001312# Install python build dependencies
1313if is_arm_jenkins_env; then
1314 source "$ci_root/script/install_python_deps.sh"
1315fi
1316
Fathi Boudra422bf772019-12-02 11:10:16 +02001317modes="${bin_mode:-debug release}"
1318for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001319 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001320 # Build with a temporary archive
1321 build_archive="$archive/$mode"
1322 mkdir "$build_archive"
1323
1324 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001325 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001326 DEBUG=1
1327 else
Zelalem219df412020-05-17 19:21:20 -05001328 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001329 DEBUG=0
1330 fi
1331
1332 # Perform builds in a subshell so as not to pollute the current and
1333 # subsequent builds' environment
1334
Zelalem219df412020-05-17 19:21:20 -05001335 if config_valid "$cc_config"; then
1336 # Build code coverage plugin
1337 build_cc
1338 fi
1339
Fathi Boudra422bf772019-12-02 11:10:16 +02001340 # SCP build
1341 if config_valid "$scp_config"; then
1342 (
1343 echo "##########"
1344
1345 # Source platform-specific utilities
1346 plat="$(get_scp_opt PRODUCT)"
1347 plat_utils="$ci_root/${plat}_utils.sh"
1348 if [ -f "$plat_utils" ]; then
1349 source "$plat_utils"
1350 fi
1351
1352 archive="$build_archive"
1353 scp_build_root="$scp_root/build"
1354
1355 echo "Building SCP Firmware ($mode) ..." |& log_separator
1356
1357 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001358 to="$archive" collect_scp_artefacts
1359
1360 echo "##########"
1361 echo
1362 )
1363 fi
1364
Zelalem219df412020-05-17 19:21:20 -05001365 # SCP-tools build
1366 if config_valid "$scp_tools_config"; then
1367 (
1368 echo "##########"
1369
1370 archive="$build_archive"
1371 scp_tools_build_root="$scp_tools_root/build"
1372
1373 clone_scp_tools
1374
1375 echo "##########"
1376 echo
1377
1378 echo "##########"
1379 clone_tf_for_scp_tools
1380 echo "##########"
1381 echo
1382 )
1383 fi
1384
Fathi Boudra422bf772019-12-02 11:10:16 +02001385 # TFTF build
1386 if config_valid "$tftf_config"; then
1387 (
1388 echo "##########"
1389
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001390 plat_utils="$(get_tf_opt PLAT_UTILS)"
1391 if [ -z ${plat_utils} ]; then
1392 # Source platform-specific utilities.
1393 plat="$(get_tftf_opt PLAT)"
1394 plat_utils="$ci_root/${plat}_utils.sh"
1395 else
1396 # Source platform-specific utilities by
1397 # using plat_utils name.
1398 plat_utils="$ci_root/${plat_utils}.sh"
1399 fi
1400
Fathi Boudra422bf772019-12-02 11:10:16 +02001401 if [ -f "$plat_utils" ]; then
1402 source "$plat_utils"
1403 fi
1404
1405 archive="$build_archive"
1406 tftf_build_root="$tftf_root/build"
1407
1408 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1409
1410 # Call pre-build hook
1411 call_hook pre_tftf_build
1412
1413 build_tftf
1414
1415 from="$tftf_build_root" to="$archive" collect_build_artefacts
1416
1417 # Clear any local changes made by applied patches
1418 undo_tftf_patches
1419
1420 echo "##########"
1421 echo
1422 )
1423 fi
1424
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001425 # SPM build
1426 if config_valid "$spm_config"; then
1427 (
1428 echo "##########"
1429
1430 # Get platform name from spm_config file
1431 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1432 plat_utils="$ci_root/${plat}_utils.sh"
1433 if [ -f "$plat_utils" ]; then
1434 source "$plat_utils"
1435 fi
1436
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001437 # Call pre-build hook
1438 call_hook pre_spm_build
1439
Manish Pandey1e7be852020-11-09 16:04:48 +00001440 # SPM build generates two sets of binaries, one for normal and other
1441 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001442 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001443 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1444 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001445
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001446 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001447 echo "Building SPM ($mode) ..." |& log_separator
1448
1449 # NOTE: mode has no effect on SPM build (for now), hence debug
1450 # mode is built but subsequent build using release mode just
1451 # goes through with "nothing to do".
1452 build_spm
1453
1454 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001455 cksum $spm_build_root/hafnium.bin
1456
1457 # Some platforms only have secure configuration enabled. Hence,
1458 # non secure hanfnium binary might not be built.
1459 if [ -f $hafnium_build_root/hafnium.bin ]; then
1460 cksum $hafnium_build_root/hafnium.bin
1461 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001462
Manish Pandey1e7be852020-11-09 16:04:48 +00001463 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001464
1465 echo "##########"
1466 echo
1467 )
1468 fi
1469
Fathi Boudra422bf772019-12-02 11:10:16 +02001470 # TF build
1471 if config_valid "$tf_config"; then
1472 (
1473 echo "##########"
1474
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001475 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001476 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1477
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001478 if [ -z ${plat_utils} ]; then
1479 # Source platform-specific utilities.
1480 plat="$(get_tf_opt PLAT)"
1481 plat_utils="$ci_root/${plat}_utils.sh"
1482 else
1483 # Source platform-specific utilities by
1484 # using plat_utils name.
1485 plat_utils="$ci_root/${plat_utils}.sh"
1486 fi
1487
Fathi Boudra422bf772019-12-02 11:10:16 +02001488 if [ -f "$plat_utils" ]; then
1489 source "$plat_utils"
1490 fi
1491
Chris Kaye5a486b2023-08-04 11:50:31 +00001492 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1493 fvp_tsram_size="${fvp_tsram_size:-256}"
1494
Harrison Mutai6361dbe2023-02-16 14:12:40 +00001495 poetry -C "$tf_root" install --without doc
Chris Kayd0837902021-11-17 10:17:52 +00001496
Fathi Boudra422bf772019-12-02 11:10:16 +02001497 archive="$build_archive"
1498 tf_build_root="$tf_root/build"
1499
1500 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1501
1502 # Call pre-build hook
1503 call_hook pre_tf_build
1504
1505 build_tf
1506
1507 # Call post-build hook
1508 call_hook post_tf_build
1509
1510 # Pre-archive hook
1511 call_hook pre_tf_archive
1512
1513 from="$tf_build_root" to="$archive" collect_build_artefacts
1514
1515 # Post-archive hook
1516 call_hook post_tf_archive
1517
1518 call_hook fetch_tf_resource
1519 call_hook post_fetch_tf_resource
1520
Chris Kay4e8aaf12022-09-01 15:21:55 +01001521 # Generate LAVA job files if necessary
1522 call_hook generate_lava_job_template
1523 call_hook generate_lava_job
1524
Fathi Boudra422bf772019-12-02 11:10:16 +02001525 # Clear any local changes made by applied patches
1526 undo_tf_patches
1527
1528 echo "##########"
1529 )
1530 fi
1531
1532 echo
1533 echo
1534done
1535
1536call_hook pre_package
1537
1538call_hook post_package
1539
1540if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001541 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001542fi
1543
1544echo
1545echo "Done"