blob: 162503637685974523ac3b9b126546f60df2a34f [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
Paul Sokolovsky0027af42024-08-15 21:54:00 +0300101# Retry a command a number of times if it fails. Intended for I/O commands
102# in a CI environment which may be flaky.
103function retry() {
104 for i in $(seq 1 3); do
105 if "$@"; then
106 return 0
107 fi
108 sleep $(( i * 5 ))
109 done
110 return 1
111}
112
Fathi Boudra422bf772019-12-02 11:10:16 +0200113# Call hook $1 in all chosen fragments if it's defined. Hooks are invoked from
114# within a subshell, so any variables set within a hook are lost. Should a
115# variable needs to be set from within a hook, the function 'set_hook_var'
116# should be used
117call_hook() {
118 local func="$1"
119 local config_fragment
120
121 [ -z "$func" ] && return 0
122
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300123 echo "=== Calling hooks: $1 ==="
124
Fathi Boudra422bf772019-12-02 11:10:16 +0200125 : >"$hook_env_file"
126
127 if [ "$run_config_candiates" ]; then
128 for config_fragment in $run_config_candiates; do
129 (
130 source "$ci_root/run_config/$config_fragment"
131 call_func "$func" "$config_fragment"
132 )
133 done
134 fi
135
136 # Also source test config file
137 (
138 unset "$func"
139 source "$test_config_file"
140 call_func "$func" "$(basename $test_config_file)"
141 )
142
143 # Have any variables set take effect
144 source "$hook_env_file"
Paul Sokolovskye9962cd2021-12-17 18:39:40 +0300145
146 echo "=== End calling hooks: $1 ==="
Fathi Boudra422bf772019-12-02 11:10:16 +0200147}
148
149# Set a variable from within a hook
150set_hook_var() {
151 echo "export $1=\"${2?}\"" >> "$hook_env_file"
152}
153
154# Append to an array from within a hook
155append_hook_var() {
156 echo "export $1+=\"${2?}\"" >> "$hook_env_file"
157}
158
159# Have the main build script source a file
160source_later() {
161 echo "source ${1?}" >> "$hook_env_file"
162}
163
164# Setup TF build wrapper function by pointing to a script containing a function
165# that will be called with the TF build commands.
166setup_tf_build_wrapper() {
167 source_later "$ci_root/script/${wrapper?}_wrapper.sh"
168 set_hook_var "tf_build_wrapper" "${wrapper}_wrapper"
169 echo "Setup $wrapper build wrapper."
170}
171
172# Collect .bin files for archiving
173collect_build_artefacts() {
174 if [ ! -d "${from:?}" ]; then
175 return
176 fi
177
Yann Gautier7e9d6cf2023-03-08 14:24:38 +0100178 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 +0200179 echo "You probably are running local CI on local repositories."
180 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
181 die
182 fi
183}
184
185# SCP and MCP binaries are named firmware.{bin,elf}, and are placed under
186# scp/mcp_ramfw and scp/mcp_romfw directories, so can't be collected by
187# collect_build_artefacts function.
188collect_scp_artefacts() {
189 to="${to:?}" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000190 find "$scp_root" \( \( -name "*.bin" -o -name '*.elf' \) -and ! -name 'CMake*' \) -exec bash -c '
Fathi Boudra422bf772019-12-02 11:10:16 +0200191 for file; do
192 ext="$(echo $file | awk -F. "{print \$NF}")"
193 case $file in
Anurag Koulbaedf932021-12-09 12:49:56 +0000194 */firmware-scp_ramfw/bin/*|*/firmware-scp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200195 cp $file $to/scp_ram.$ext
196 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000197 */firmware-scp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200198 cp $file $to/scp_rom.$ext
199 ;;
Anurag Koulbaedf932021-12-09 12:49:56 +0000200 */firmware-mcp_ramfw/bin/*|*/firmware-mcp_ramfw_fvp/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200201 cp $file $to/mcp_ram.$ext
202 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000203 */firmware-mcp_romfw/bin/*)
Fathi Boudra422bf772019-12-02 11:10:16 +0200204 cp $file $to/mcp_rom.$ext
205 ;;
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000206 */firmware-scp_romfw_bypass/bin/*)
Zelalem219df412020-05-17 19:21:20 -0500207 cp $file $to/scp_rom_bypass.$ext
208 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200209 *)
210 echo "Unknown SCP binary: $file" >&2
211 ;;
212 esac
213 done
214 ' bash '{}' +
215}
216
Manish Pandey1e7be852020-11-09 16:04:48 +0000217# Collect SPM/hafnium artefacts with "secure_" appended to the files
218# generated for SPM(secure hafnium).
219collect_spm_artefacts() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500220 if [ -d "${non_secure_from:?}" ]; then
221 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000222 fi
223
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500224 if [ -d "${secure_from:?}" ]; then
225 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
226 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000227}
228
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100229# Map the UART ID used for expect with the UART descriptor and port
230# used by the FPGA automation tools.
231map_uart() {
232 local port="${port:?}"
233 local descriptor="${descriptor:?}"
234 local baudrate="${baudrate:?}"
235 local run_root="${archive:?}/run"
236
237 local uart_dir="$run_root/uart${uart:?}"
238 mkdir -p "$uart_dir"
239
240 echo "$port" > "$uart_dir/port"
241 echo "$descriptor" > "$uart_dir/descriptor"
242 echo "$baudrate" > "$uart_dir/baudrate"
243
244 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
245}
246
Fathi Boudra422bf772019-12-02 11:10:16 +0200247# Arrange environment varibles to be set when expect scripts are launched
248set_expect_variable() {
249 local var="${1:?}"
250 local val="${2?}"
251
252 local run_root="${archive:?}/run"
253 local uart_dir="$run_root/uart${uart:?}"
254 mkdir -p "$uart_dir"
255
256 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
257 echo "UART$uart: env has $@"
258}
259
260# Place the binary package a pointer to expect script, and its parameters
261track_expect() {
262 local file="${file:?}"
263 local timeout="${timeout-600}"
264 local run_root="${archive:?}/run"
265
266 local uart_dir="$run_root/uart${uart:?}"
267 mkdir -p "$uart_dir"
268
269 echo "$file" > "$uart_dir/expect"
270 echo "$timeout" > "$uart_dir/timeout"
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700271 if [ -n "$lava_timeout" ]; then
272 set_run_env "lava_timeout" "$lava_timeout"
273 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200274
Paul Sokolovskybfa8bab2023-01-25 19:34:51 +0700275 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 +0200276
Chris Kayfab6edc2022-11-17 19:18:32 +0000277 if [ ! -z "${port}" ]; then
278 echo "${port}" > "$uart_dir/port"
279 fi
280
Fathi Boudra422bf772019-12-02 11:10:16 +0200281 # The run script assumes UART0 to be primary. If we're asked to set any
282 # other UART to be primary, set a run environment variable to signal
283 # that to the run script
284 if upon "$set_primary"; then
285 echo "Primary UART set to UART$uart."
286 set_run_env "primary_uart" "$uart"
287 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600288
289 # UART used by payload(such as tftf, Linux) may not be the same as the
290 # primary UART. Set a run environment variable to track the payload
291 # UART which is tracked to check if the test has finished sucessfully.
292 if upon "$set_payload_uart"; then
293 echo "Payload uses UART$uart."
294 set_run_env "payload_uart" "$uart"
295 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200296}
297
298# Extract a FIP in $1 using fiptool
299extract_fip() {
300 local fip="$1"
301
302 if is_url "$1"; then
303 url="$1" fetch_file
304 fip="$(basename "$1")"
305 fi
306
307 "$fiptool" unpack "$fip"
308 echo "Extracted FIP: $fip"
309}
310
311# Report build failure by printing a the tail end of build log. Archive the
312# build log for later inspection
313fail_build() {
314 local log_path
315
316 if upon "$jenkins_run"; then
317 log_path="$BUILD_URL/artifact/artefacts/build.log"
318 else
319 log_path="$build_log"
320 fi
321
322 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600323 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200324 echo "[...]"
325 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600326 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200327 echo
328 echo "See $log_path for full output"
329 echo
330 cp -t "$archive" "$build_log"
331 exit 1;
332}
333
334# Build a FIP with supplied arguments
335build_fip() {
336 (
337 echo "Building FIP with arguments: $@"
338 local tf_env="$workspace/tf.env"
339
340 if [ -f "$tf_env" ]; then
341 set -a
342 source "$tf_env"
343 set +a
344 fi
345
346 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
347 ${fip_targets:-fip} &>>"$build_log" || fail_build
348 )
349}
350
Sandrine Bailleux189fdb32023-10-20 13:41:22 +0200351# Build any extra rule from TF-A makefile with supplied arguments.
352#
353# This is useful in case you need to build something else than firmware binaries
354# or the FIP.
355build_tf_extra() {
356 (
357 tf_extra_rules=${tf_extra_rules:?}
358 echo "Building extra TF rule(s): $tf_extra_rules"
359 echo " Arguments: $@"
360
361 local tf_env="$workspace/tf.env"
362
363 if [ -f "$tf_env" ]; then
364 set -a
365 source "$tf_env"
366 set +a
367 fi
368
369 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
370 ${tf_extra_rules} &>>"$build_log" || fail_build
371 )
372}
373
Fathi Boudra422bf772019-12-02 11:10:16 +0200374fip_update() {
375 # Before the update process, check if the given image is supported by
376 # the fiptool. It's assumed that both fiptool and cert_create move in
377 # tandem, and therfore, if one has support, the other has it too.
378 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
379 return 1
380 fi
381
382 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
383 echo "Updating FIP image: $bin_name"
384 # Update HW config. Without TBBR, it's only a matter of using
385 # the update sub-command of fiptool
386 "$fiptool" update "--$bin_name" "${src:-}" \
387 "$archive/fip.bin"
388 else
389 echo "Updating FIP image (TBBR): $bin_name"
390 # With TBBR, we need to unpack, re-create certificates, and then
391 # recreate the FIP.
392 local fip_dir="$(mktempdir)"
393 local bin common_args stem
394 local rot_key="$(get_tf_opt ROT_KEY)"
395
396 rot_key="${rot_key:?}"
397 if ! is_abs "$rot_key"; then
398 rot_key="$tf_root/$rot_key"
399 fi
400
401 # Arguments only for cert_create
402 local cert_args="-n"
403 cert_args+=" --tfw-nvctr ${nvctr:-31}"
404 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
405 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
406 cert_args+=" --rot-key $rot_key"
407
408 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500409 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200410 "hw-config"
411 "tb-fw-config"
412 "nt-fw-config"
413 "soc-fw-config"
414 "tos-fw-config"
415 )
416
417 # Binaries without key certificates
418 declare -A has_no_key_cert
419 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
420 has_no_key_cert["$bin"]="1"
421 done
422
423 # Binaries without certificates
424 declare -A has_no_cert
425 for bin in "hw-config" "${dyn_config_opts[@]}"; do
426 has_no_cert["$bin"]="1"
427 done
428
429 pushd "$fip_dir"
430
431 # Unpack FIP
432 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
433
434 # Remove all existing certificates
435 rm -f *-cert.bin
436
437 # Copy the binary to be updated
438 cp -f "$src" "${bin_name}.bin"
439
440 # FIP unpack dumps binaries with the same name as the option
441 # used to pack it; likewise for certificates. Reverse-engineer
442 # the command line from the binary output.
443 common_args="--trusted-key-cert trusted_key.crt"
444 for bin in *.bin; do
445 stem="${bin%%.bin}"
446 common_args+=" --$stem $bin"
447 if not_upon "${has_no_cert[$stem]}"; then
448 common_args+=" --$stem-cert $stem.crt"
449 fi
450 if not_upon "${has_no_key_cert[$stem]}"; then
451 common_args+=" --$stem-key-cert $stem-key.crt"
452 fi
453 done
454
455 # Create certificates
456 "$cert_create" $cert_args $common_args &>>"$build_log"
457
458 # Recreate and archive FIP
459 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
460 archive_file "fip.bin"
461
462 popd
463 fi
464}
465
466# Update hw-config in FIP, and remove the original DTB afterwards.
467update_fip_hw_config() {
468 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600469 # in configs:
470 # 1. Where BL2 isn't present
471 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200472 case "1" in
473 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600474 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200475 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000476 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200477 return 0;;
478 esac
479
480 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
481 # Remove the DTB so that model won't load it
482 rm -f "$archive/dtb.bin"
483 fi
484}
485
486get_scp_opt() {
487 (
488 name="${1:?}"
489 if config_valid "$scp_config_file"; then
490 source "$scp_config_file"
491 echo "${!name}"
492 fi
493 )
494}
495
496get_tftf_opt() {
497 (
498 name="${1:?}"
499 if config_valid "$tftf_config_file"; then
500 source "$tftf_config_file"
501 echo "${!name}"
502 fi
503 )
504}
505
506get_tf_opt() {
507 (
508 name="${1:?}"
509 if config_valid "$tf_config_file"; then
510 source "$tf_config_file"
511 echo "${!name}"
512 fi
513 )
514}
515
516build_tf() {
517 (
518 env_file="$workspace/tf.env"
519 config_file="${tf_build_config:-$tf_config_file}"
520
521 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100522 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200523
524 source "$config_file"
525
526 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000527 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100528 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
529 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200530 mbedtls_dir="$workspace/mbedtls"
531 if [ ! -d "$mbedtls_dir" ]; then
532 mbedtls_ar="$workspace/mbedtls.tar.gz"
533
534 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
535 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500536 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200537 fi
538
539 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
540 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500541 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
542 not_upon "${TF_M_TESTS_PATH}"; then
543 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
544 fi
545 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
546 not_upon "${TF_M_EXTRAS_PATH}"; then
547 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
548 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200549 if [ -f "$env_file" ]; then
550 set -a
551 source "$env_file"
552 set +a
553 fi
554
Harrison Mutai013f6332022-02-16 16:06:33 +0000555 if is_arm_jenkins_env || upon "$local_ci"; then
556 path_list=(
557 "$llvm_dir/bin"
558 )
559 extend_path "PATH" "path_list"
560 fi
561
Fathi Boudra422bf772019-12-02 11:10:16 +0200562 cd "$tf_root"
563
564 # Always distclean when running on Jenkins. Skip distclean when running
565 # locally and explicitly requested.
566 if upon "$jenkins_run" || not_upon "$dont_clean"; then
567 make distclean &>>"$build_log" || fail_build
568 fi
569
570 # Log build command line. It is left unfolded on purpose to assist
571 # copying to clipboard.
572 cat <<EOF | log_separator >/dev/null
573
574Build command line:
575 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
576
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300577CC version:
578$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200579EOF
580
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000581 if not_upon "$local_ci"; then
582 connect_debugger=0
583 fi
584
Fathi Boudra422bf772019-12-02 11:10:16 +0200585 # Build TF. Since build output is being directed to the build log, have
586 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000587 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000588 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200589 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100590
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100591 if [ "$build_targets" != "doc" ]; then
592 poetry run memory -sr "$tf_build_path" 2>&1 | tee -a "$build_log"
593 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200594 )
595}
596
597build_tftf() {
598 (
599 config_file="${tftf_build_config:-$tftf_config_file}"
600
601 # Build tftf target by default
602 build_targets="${tftf_build_targets:-all}"
603
604 source "$config_file"
605
606 cd "$tftf_root"
607
608 # Always distclean when running on Jenkins. Skip distclean when running
609 # locally and explicitly requested.
610 if upon "$jenkins_run" || not_upon "$dont_clean"; then
611 make distclean &>>"$build_log" || fail_build
612 fi
613
614 # TFTF build system cannot reliably deal with -j option, so we avoid
615 # using that.
616
617 # Log build command line
618 cat <<EOF | log_separator >/dev/null
619
620Build command line:
621 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
622
623EOF
624
625 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
626 $build_targets &>>"$build_log" || fail_build
627 )
628}
629
630build_scp() {
631 (
632 config_file="${scp_build_config:-$scp_config_file}"
633
634 source "$config_file"
635
636 cd "$scp_root"
637
638 # Always distclean when running on Jenkins. Skip distclean when running
639 # locally and explicitly requested.
640 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000641 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200642 fi
643
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000644 python3 -m venv .venv
645 . .venv/bin/activate
646
647 # Install extra tools used by CMake build system
648 pip install -r requirements.txt --timeout 30 --retries 15
649
Fathi Boudra422bf772019-12-02 11:10:16 +0200650 # Log build command line. It is left unfolded on purpose to assist
651 # copying to clipboard.
652 cat <<EOF | log_separator >/dev/null
653
654SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000655 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
656 TOOLCHAIN=GNU \
657 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000658 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000659 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200660
661EOF
662
663 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000664 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
665 TOOLCHAIN=GNU \
666 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000667 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000668 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200669 || fail_build
670 )
671}
672
Zelalem219df412020-05-17 19:21:20 -0500673clone_scp_tools() {
674
675 if [ ! -d "$scp_tools_root" ]; then
676 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
677
678 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
679 where="$scp_tools_root" \
680 refspec="${scp_tools_commit}"
681 clone_repo &>>"$build_log"
682 else
683 echo "Already cloned SCP-tools ..." |& log_separator
684 fi
685
686 show_head "$scp_tools_root"
687
688 cd "$scp_tools_root"
689
690 echo "Updating submodules"
691
692 git submodule init
693
694 git submodule update
695
Nicola Mazzucato9b171422023-08-29 15:50:49 +0100696 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 +0000697
Zelalem219df412020-05-17 19:21:20 -0500698 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000699 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500700
701 git show --quiet --no-color | sed 's/^/ > /g'
702}
703
704clone_tf_for_scp_tools() {
705 scp_tools_arm_tf="$scp_tools_root/arm-tf"
706
707 if [ ! -d "$scp_tools_arm_tf" ]; then
708 echo "Cloning TF-4-SCP-tools ..." |& log_separator
709
710 clone_url="$tf_for_scp_tools_src_repo_url"
711 where="$scp_tools_arm_tf"
712
713 git clone "$clone_url" "$where"
714
715 cd "$scp_tools_arm_tf"
716
Joel Goddard3ad03062021-03-16 16:47:42 +0000717 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500718
719 git show --quiet --no-color | sed 's/^/ > /g'
720
721 else
722 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
723 fi
724}
725
726build_scmi_lib_scp_tools() {
727 (
728 cd "$scp_tools_root"
729
730 cd "scmi"
731
732 scp_tools_arm_tf="$scp_tools_root/arm-tf"
733
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600734 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500735
736 std_libs="-I$scp_tools_arm_tf/include/common"
737 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
738 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
739 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
740 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
741 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
742 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
743 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
744 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
745 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
746 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
747 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
748 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
749 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
750
751 cflags="-Og -g"
752 cflags="$cflags -mgeneral-regs-only"
753 cflags="$cflags -mstrict-align"
754 cflags="$cflags -nostdinc"
755 cflags="$cflags -fno-inline"
756 cflags="$cflags -ffreestanding"
757 cflags="$cflags -ffunction-sections"
758 cflags="$cflags -fdata-sections"
759 cflags="$cflags -DAARCH64"
760 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000761 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500762
763 cflags="$cflags $std_libs"
764
Joel Goddard3ad03062021-03-16 16:47:42 +0000765 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500766
767 echo "Building SCMI library (SCP-tools) ..."
768
769 make "CROSS_COMPILE=$cross_compile" \
770 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000771 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500772 "PROTOCOLS=$protocols" \
773 "clean" \
774 "all"
775 )
776}
777
778build_tf_for_scp_tools() {
779
780 cd "$scp_tools_root/arm-tf"
781
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600782 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500783
784 if [ "$1" = "release" ]; then
785 echo "Build TF-4-SCP-Tools rls..."
786 else
787 echo "Build TF-4-SCP-Tools dbg..."
788
789 make realclean
790
791 make "BM_TEST=scmi" \
792 "ARM_BOARD_OPTIMISE_MEM=1" \
793 "BM_CSS=juno" \
794 "CSS_USE_SCMI_SDS_DRIVER=1" \
795 "PLAT=juno" \
796 "DEBUG=1" \
797 "PLATFORM=juno" \
798 "CROSS_COMPILE=$cross_compile" \
799 "BM_WORKSPACE=$scp_tools_root/baremetal"
800
801 archive_file "build/juno/debug/bl1.bin"
802
803 archive_file "build/juno/debug/bl2.bin"
804
805 archive_file "build/juno/debug/bl31.bin"
806 fi
807}
808
809build_fip_for_scp_tools() {
810
811 cd "$scp_tools_root/arm-tf"
812
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600813 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500814
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000815 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500816 make fiptool
817 echo "Make FIP 4 SCP-Tools rls..."
818
819 else
820 make fiptool
821 echo "Make FIP 4 SCP-Tools dbg..."
822
823 make "PLAT=juno" \
824 "all" \
825 "fip" \
826 "DEBUG=1" \
827 "CROSS_COMPILE=$cross_compile" \
828 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
829 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000830 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500831
832 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
833 fi
834}
835
836build_cc() {
837# Building code coverage plugin
838 ARM_DIR=/arm
839 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
840 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
841 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
842 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
843 exit -1
844 fi # Error if arm warehouse not found
845 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
846
847 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
848}
849
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100850build_spm() {
851 (
852 env_file="$workspace/spm.env"
853 config_file="${spm_build_config:-$spm_config_file}"
854
855 source "$config_file"
856
857 if [ -f "$env_file" ]; then
858 set -a
859 source "$env_file"
860 set +a
861 fi
862
863 cd "$spm_root"
864
865 # Always clean when running on Jenkins. Skip clean when running
866 # locally and explicitly requested.
867 if upon "$jenkins_run" || not_upon "$dont_clean"; then
868 # make clean fails on a fresh repo where the project has not
869 # yet been built. Hence only clean if out/reference directory
870 # already exists.
871 if [ -d "out/reference" ]; then
872 make clean &>>"$build_log" || fail_build
873 fi
874 fi
875
876 # Log build command line. It is left unfolded on purpose to assist
877 # copying to clipboard.
878 cat <<EOF | log_separator >/dev/null
879
880Build command line:
881 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
882
883EOF
884
885 # Build SPM. Since build output is being directed to the build log, have
886 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200887 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
888
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100889 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
890 || fail_build
891 )
892}
Zelalem219df412020-05-17 19:21:20 -0500893
Fathi Boudra422bf772019-12-02 11:10:16 +0200894# Set metadata for the whole package so that it can be used by both Jenkins and
895# shell
896set_package_var() {
897 env_file="$artefacts/env" emit_env "$@"
898}
899
900set_tf_build_targets() {
901 echo "Set build target to '${targets:?}'"
902 set_hook_var "tf_build_targets" "$targets"
903}
904
905set_tftf_build_targets() {
906 echo "Set build target to '${targets:?}'"
907 set_hook_var "tftf_build_targets" "$targets"
908}
909
910set_scp_build_targets() {
911 echo "Set build target to '${targets:?}'"
912 set_hook_var "scp_build_targets" "$targets"
913}
914
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100915set_spm_build_targets() {
916 echo "Set build target to '${targets:?}'"
917 set_hook_var "spm_build_targets" "$targets"
918}
919
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000920set_spm_out_dir() {
921 echo "Set SPMC binary build to '${out_dir:?}'"
922 set_hook_var "spm_secure_out_dir" "$out_dir"
923}
Fathi Boudra422bf772019-12-02 11:10:16 +0200924# Look under $archive directory for known files such as blX images, kernel, DTB,
925# initrd etc. For each known file foo, if foo.bin exists, then set variable
926# foo_bin to the path of the file. Make the path relative to the workspace so as
927# to remove any @ characters, which Jenkins inserts for parallel runs. If the
928# file doesn't exist, unset its path.
929set_default_bin_paths() {
930 local image image_name image_path path
931 local archive="${archive:?}"
932 local set_vars
933 local var
934
935 pushd "$archive"
936
937 for file in *.bin; do
938 # Get a shell variable from the file's stem
939 var_name="${file%%.*}_bin"
940 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
941
942 # Skip setting the variable if it's already
943 if [ "${!var_name}" ]; then
944 echo "Note: not setting $var_name; already set to ${!var_name}"
945 continue
946 else
947 set_vars+="$var_name "
948 fi
949
950 eval "$var_name=$file"
951 done
952
953 echo "Binary paths set for: "
954 {
955 for var in $set_vars; do
956 echo -n "\$$var "
957 done
958 } | fmt -80 | sed 's/^/ /'
959 echo
960
961 popd
962}
963
964gen_model_params() {
965 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000966 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200967
968 set_default_bin_paths
969 echo "Generating model parameter for $model..."
970 source "$ci_root/model/${model:?}.sh"
971 archive_file "$model_param_file"
972}
973
974set_model_path() {
975 set_run_env "model_path" "${1:?}"
976}
977
Zelalem1af7a7b2020-08-04 17:34:32 -0500978set_model_env() {
979 local var="${1:?}"
980 local val="${2?}"
981 local run_root="${archive:?}/run"
982
983 mkdir -p "$run_root"
984 echo "export $var=$val" >> "$run_root/model_env"
985}
Fathi Boudra422bf772019-12-02 11:10:16 +0200986set_run_env() {
987 local var="${1:?}"
988 local val="${2?}"
989 local run_root="${archive:?}/run"
990
991 mkdir -p "$run_root"
992 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
993}
994
995show_head() {
996 # Display HEAD descripton
997 pushd "$1"
998 git show --quiet --no-color | sed 's/^/ > /g'
999 echo
1000 popd
1001}
1002
1003# Choose debug binaries to run; by default, release binaries are chosen to run
1004use_debug_bins() {
1005 local run_root="${archive:?}/run"
1006
1007 echo "Choosing debug binaries for execution"
1008 set_package_var "BIN_MODE" "debug"
1009}
1010
1011assert_can_git_clone() {
1012 local name="${1:?}"
1013 local dir="${!name}"
1014
1015 # If it doesn't exist, it can be cloned into
1016 if [ ! -e "$dir" ]; then
1017 return 0
1018 fi
1019
1020 # If it's a directory, it must be a Git clone already
1021 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
1022 # No need to clone again
1023 echo "Using existing git clone for $name: $dir"
1024 return 1
1025 fi
1026
1027 die "Path $dir exists but is not a git clone"
1028}
1029
1030clone_repo() {
1031 if ! is_url "${clone_url?}"; then
1032 # For --depth to take effect on local paths, it needs to use the
1033 # file:// scheme.
1034 clone_url="file://$clone_url"
1035 fi
1036
1037 git clone -q --depth 1 "$clone_url" "${where?}"
1038 if [ "$refspec" ]; then
1039 pushd "$where"
1040 git fetch -q --depth 1 origin "$refspec"
1041 git checkout -q FETCH_HEAD
1042 popd
1043 fi
1044}
1045
1046build_unstable() {
1047 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1048}
1049
1050undo_patch_record() {
1051 if [ ! -f "${patch_record:?}" ]; then
1052 return
1053 fi
1054
1055 # Undo patches in reverse
1056 echo
1057 for patch_name in $(tac "$patch_record"); do
1058 echo "Undoing $patch_name..."
1059 if ! git apply -R "$ci_root/patch/$patch_name"; then
1060 if upon "$local_ci"; then
1061 echo
1062 echo "Your local directory may have been dirtied."
1063 echo
1064 fi
1065 fail_build
1066 fi
1067 done
1068
1069 rm -f "$patch_record"
1070}
1071
1072undo_local_patches() {
1073 pushd "$tf_root"
1074 patch_record="$tf_patch_record" undo_patch_record
1075 popd
1076
1077 if [ -d "$tftf_root" ]; then
1078 pushd "$tftf_root"
1079 patch_record="$tftf_patch_record" undo_patch_record
1080 popd
1081 fi
1082}
1083
1084undo_tftf_patches() {
1085 pushd "$tftf_root"
1086 patch_record="$tftf_patch_record" undo_patch_record
1087 popd
1088}
1089
1090undo_tf_patches() {
1091 pushd "$tf_root"
1092 patch_record="$tf_patch_record" undo_patch_record
1093 popd
1094}
1095
1096apply_patch() {
1097 # If skip_patches is set, the developer has applied required patches
1098 # manually. They probably want to keep them applied for debugging
1099 # purposes too. This means we don't have to apply/revert them as part of
1100 # build process.
1101 if upon "$skip_patches"; then
1102 echo "Skipped applying ${1:?}..."
1103 return 0
1104 else
1105 echo "Applying ${1:?}..."
1106 fi
1107
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +02001108 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001109 echo "Skipping already applied ${1:?}"
1110 return 0
1111 fi
1112
Fathi Boudra422bf772019-12-02 11:10:16 +02001113 if git apply < "$ci_root/patch/$1"; then
1114 echo "$1" >> "${patch_record:?}"
1115 else
1116 if upon "$local_ci"; then
1117 undo_local_patches
1118 fi
1119 fail_build
1120 fi
1121}
1122
1123apply_tftf_patch() {
1124 pushd "$tftf_root"
1125 patch_record="$tftf_patch_record" apply_patch "$1"
1126 popd
1127}
1128
1129apply_tf_patch() {
1130 pushd "$tf_root"
1131 patch_record="$tf_patch_record" apply_patch "$1"
1132 popd
1133}
1134
1135# Clear workspace for a local run
1136if not_upon "$jenkins_run"; then
1137 rm -rf "$workspace"
1138
1139 # Clear residue from previous runs
1140 rm -rf "$archive"
1141fi
1142
1143mkdir -p "$workspace"
1144mkdir -p "$archive"
1145set_package_var "TEST_CONFIG" "$test_config"
1146
1147{
1148echo
1149echo "CONFIGURATION: $test_group/$test_config"
1150echo
1151} |& log_separator
1152
1153tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1154tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1155scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001156scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001157spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001158
1159test_config_file="$ci_root/group/$test_group/$test_config"
1160
1161tf_config_file="$ci_root/tf_config/$tf_config"
1162tftf_config_file="$ci_root/tftf_config/$tftf_config"
1163scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001164scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001165spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001166
1167# File that keeps track of applied patches
1168tf_patch_record="$workspace/tf_patches"
1169tftf_patch_record="$workspace/tftf_patches"
1170
1171pushd "$workspace"
1172
1173if ! config_valid "$tf_config"; then
1174 tf_config=
1175else
1176 echo "Trusted Firmware config:"
1177 echo
1178 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1179 echo
1180fi
1181
1182if ! config_valid "$tftf_config"; then
1183 tftf_config=
1184else
1185 echo "Trusted Firmware TF config:"
1186 echo
1187 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1188 echo
1189fi
1190
1191if ! config_valid "$scp_config"; then
1192 scp_config=
1193else
1194 echo "SCP firmware config:"
1195 echo
1196 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1197 echo
1198fi
1199
Zelalem219df412020-05-17 19:21:20 -05001200if ! config_valid "$scp_tools_config"; then
1201 scp_tools_config=
1202else
1203 echo "SCP Tools config:"
1204 echo
1205 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001206fi
1207
1208if ! config_valid "$spm_config"; then
1209 spm_config=
1210else
1211 echo "SPM config:"
1212 echo
1213 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001214 echo
1215fi
1216
Fathi Boudra422bf772019-12-02 11:10:16 +02001217if ! config_valid "$run_config"; then
1218 run_config=
1219fi
1220
1221if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1222 # If the Trusted Firmware repository has already been checked out, use
1223 # that location. Otherwise, clone one ourselves.
1224 echo "Cloning Trusted Firmware..."
1225 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1226 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1227 show_head "$tf_root"
1228fi
1229
1230if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1231 # If the Trusted Firmware TF repository has already been checked out,
1232 # use that location. Otherwise, clone one ourselves.
1233 echo "Cloning Trusted Firmware TF..."
1234 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1235 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1236 show_head "$tftf_root"
1237fi
1238
1239if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1240 # If the SCP firmware repository has already been checked out,
1241 # use that location. Otherwise, clone one ourselves.
1242 echo "Cloning SCP Firmware..."
1243 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1244 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1245
1246 pushd "$scp_root"
1247
1248 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001249 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001250 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1251 fi
1252
1253 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1254 # then to project filer if accessible.
1255 if [ -z "$cmsis_reference" ]; then
1256 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1257 if [ -d "$cmsis_ref_repo" ]; then
1258 cmsis_reference="--reference $cmsis_ref_repo"
1259 fi
1260 fi
1261
1262 git submodule -q update $cmsis_reference --init
1263
1264 popd
1265
1266 show_head "$scp_root"
1267fi
1268
Zelalem219df412020-05-17 19:21:20 -05001269if [ -n "$cc_config" ] ; then
1270 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1271 # Copy code coverage repository
1272 echo "Cloning Code Coverage..."
1273 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1274 show_head "$cc_root"
1275 fi
1276fi
1277
Daniel Boulby052f1bb2023-12-14 14:36:25 +00001278if [ "$spm_config" ] ; then
1279 if assert_can_git_clone "spm_root"; then
1280 # If the SPM repository has already been checked out, use
1281 # that location. Otherwise, clone one ourselves.
1282 echo "Cloning SPM..."
1283 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1284 where="$spm_root" refspec="$SPM_REFSPEC" \
1285 clone_repo &>>"$build_log"
1286 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001287
1288 # Query git submodules
1289 pushd "$spm_root"
Daniel Boulby052f1bb2023-12-14 14:36:25 +00001290 # Check if submodules need initialising
1291 if git submodule status | grep '^-'; then
Paul Sokolovskyb6046cf2024-09-01 00:47:51 +03001292 git submodule init
1293 retry git submodule update
Daniel Boulby052f1bb2023-12-14 14:36:25 +00001294 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001295 popd
1296
1297 show_head "$spm_root"
1298fi
1299
Fathi Boudra422bf772019-12-02 11:10:16 +02001300if [ "$run_config" ]; then
1301 # Get candidates for run config
1302 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1303 "$run_config")"
1304 if [ -z "$run_config_candiates" ]; then
1305 die "No run config candidates!"
1306 else
1307 echo
1308 echo "Chosen fragments:"
1309 echo
1310 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1311 echo
1312 fi
1313fi
1314
1315call_hook "test_setup"
1316echo
1317
1318if upon "$local_ci"; then
1319 # For local runs, since each config is tried in sequence, it's
1320 # advantageous to run jobs in parallel
1321 if [ "$make_j" ]; then
1322 make_j_opts="-j $make_j"
1323 else
1324 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1325 if [ "$n_cores" ]; then
1326 make_j_opts="-j $n_cores"
1327 fi
1328 fi
1329fi
1330
Harrison Mutai07043e92023-07-06 09:41:12 +01001331# Install python build dependencies
1332if is_arm_jenkins_env; then
1333 source "$ci_root/script/install_python_deps.sh"
1334fi
1335
Fathi Boudra422bf772019-12-02 11:10:16 +02001336modes="${bin_mode:-debug release}"
1337for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001338 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001339 # Build with a temporary archive
1340 build_archive="$archive/$mode"
1341 mkdir "$build_archive"
1342
1343 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001344 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001345 DEBUG=1
1346 else
Zelalem219df412020-05-17 19:21:20 -05001347 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001348 DEBUG=0
1349 fi
1350
1351 # Perform builds in a subshell so as not to pollute the current and
1352 # subsequent builds' environment
1353
Zelalem219df412020-05-17 19:21:20 -05001354 if config_valid "$cc_config"; then
1355 # Build code coverage plugin
1356 build_cc
1357 fi
1358
Fathi Boudra422bf772019-12-02 11:10:16 +02001359 # SCP build
1360 if config_valid "$scp_config"; then
1361 (
1362 echo "##########"
1363
1364 # Source platform-specific utilities
1365 plat="$(get_scp_opt PRODUCT)"
1366 plat_utils="$ci_root/${plat}_utils.sh"
1367 if [ -f "$plat_utils" ]; then
1368 source "$plat_utils"
1369 fi
1370
1371 archive="$build_archive"
1372 scp_build_root="$scp_root/build"
1373
1374 echo "Building SCP Firmware ($mode) ..." |& log_separator
1375
1376 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001377 to="$archive" collect_scp_artefacts
1378
1379 echo "##########"
1380 echo
1381 )
1382 fi
1383
Zelalem219df412020-05-17 19:21:20 -05001384 # SCP-tools build
1385 if config_valid "$scp_tools_config"; then
1386 (
1387 echo "##########"
1388
1389 archive="$build_archive"
1390 scp_tools_build_root="$scp_tools_root/build"
1391
1392 clone_scp_tools
1393
1394 echo "##########"
1395 echo
1396
1397 echo "##########"
1398 clone_tf_for_scp_tools
1399 echo "##########"
1400 echo
1401 )
1402 fi
1403
Fathi Boudra422bf772019-12-02 11:10:16 +02001404 # TFTF build
1405 if config_valid "$tftf_config"; then
1406 (
1407 echo "##########"
1408
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001409 plat_utils="$(get_tf_opt PLAT_UTILS)"
1410 if [ -z ${plat_utils} ]; then
1411 # Source platform-specific utilities.
1412 plat="$(get_tftf_opt PLAT)"
1413 plat_utils="$ci_root/${plat}_utils.sh"
1414 else
1415 # Source platform-specific utilities by
1416 # using plat_utils name.
1417 plat_utils="$ci_root/${plat_utils}.sh"
1418 fi
1419
Fathi Boudra422bf772019-12-02 11:10:16 +02001420 if [ -f "$plat_utils" ]; then
1421 source "$plat_utils"
1422 fi
1423
1424 archive="$build_archive"
1425 tftf_build_root="$tftf_root/build"
1426
1427 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1428
1429 # Call pre-build hook
1430 call_hook pre_tftf_build
1431
1432 build_tftf
1433
1434 from="$tftf_build_root" to="$archive" collect_build_artefacts
1435
1436 # Clear any local changes made by applied patches
1437 undo_tftf_patches
1438
1439 echo "##########"
1440 echo
1441 )
1442 fi
1443
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001444 # SPM build
1445 if config_valid "$spm_config"; then
1446 (
1447 echo "##########"
1448
1449 # Get platform name from spm_config file
1450 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1451 plat_utils="$ci_root/${plat}_utils.sh"
1452 if [ -f "$plat_utils" ]; then
1453 source "$plat_utils"
1454 fi
1455
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001456 # Call pre-build hook
1457 call_hook pre_spm_build
1458
Manish Pandey1e7be852020-11-09 16:04:48 +00001459 # SPM build generates two sets of binaries, one for normal and other
1460 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001461 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001462 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1463 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001464
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001465 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001466 echo "Building SPM ($mode) ..." |& log_separator
1467
1468 # NOTE: mode has no effect on SPM build (for now), hence debug
1469 # mode is built but subsequent build using release mode just
1470 # goes through with "nothing to do".
1471 build_spm
1472
1473 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001474 cksum $spm_build_root/hafnium.bin
1475
1476 # Some platforms only have secure configuration enabled. Hence,
1477 # non secure hanfnium binary might not be built.
1478 if [ -f $hafnium_build_root/hafnium.bin ]; then
1479 cksum $hafnium_build_root/hafnium.bin
1480 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001481
Manish Pandey1e7be852020-11-09 16:04:48 +00001482 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001483
1484 echo "##########"
1485 echo
1486 )
1487 fi
1488
Fathi Boudra422bf772019-12-02 11:10:16 +02001489 # TF build
1490 if config_valid "$tf_config"; then
1491 (
1492 echo "##########"
1493
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001494 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001495 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1496
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001497 if [ -z ${plat_utils} ]; then
1498 # Source platform-specific utilities.
1499 plat="$(get_tf_opt PLAT)"
1500 plat_utils="$ci_root/${plat}_utils.sh"
1501 else
1502 # Source platform-specific utilities by
1503 # using plat_utils name.
1504 plat_utils="$ci_root/${plat_utils}.sh"
1505 fi
1506
Fathi Boudra422bf772019-12-02 11:10:16 +02001507 if [ -f "$plat_utils" ]; then
1508 source "$plat_utils"
1509 fi
1510
Chris Kaye5a486b2023-08-04 11:50:31 +00001511 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1512 fvp_tsram_size="${fvp_tsram_size:-256}"
1513
Harrison Mutai6361dbe2023-02-16 14:12:40 +00001514 poetry -C "$tf_root" install --without doc
Chris Kayd0837902021-11-17 10:17:52 +00001515
Fathi Boudra422bf772019-12-02 11:10:16 +02001516 archive="$build_archive"
1517 tf_build_root="$tf_root/build"
1518
1519 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1520
1521 # Call pre-build hook
1522 call_hook pre_tf_build
1523
1524 build_tf
1525
1526 # Call post-build hook
1527 call_hook post_tf_build
1528
1529 # Pre-archive hook
1530 call_hook pre_tf_archive
1531
1532 from="$tf_build_root" to="$archive" collect_build_artefacts
1533
1534 # Post-archive hook
1535 call_hook post_tf_archive
1536
1537 call_hook fetch_tf_resource
1538 call_hook post_fetch_tf_resource
1539
Chris Kay4e8aaf12022-09-01 15:21:55 +01001540 # Generate LAVA job files if necessary
1541 call_hook generate_lava_job_template
1542 call_hook generate_lava_job
1543
Fathi Boudra422bf772019-12-02 11:10:16 +02001544 # Clear any local changes made by applied patches
1545 undo_tf_patches
1546
1547 echo "##########"
1548 )
1549 fi
1550
1551 echo
1552 echo
1553done
1554
1555call_hook pre_package
1556
1557call_hook post_package
1558
1559if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001560 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001561fi
1562
1563echo
1564echo "Done"