blob: 741c797b8fa7b76ee3e19471545aeeb878081085 [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
339fip_update() {
340 # Before the update process, check if the given image is supported by
341 # the fiptool. It's assumed that both fiptool and cert_create move in
342 # tandem, and therfore, if one has support, the other has it too.
343 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
344 return 1
345 fi
346
347 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
348 echo "Updating FIP image: $bin_name"
349 # Update HW config. Without TBBR, it's only a matter of using
350 # the update sub-command of fiptool
351 "$fiptool" update "--$bin_name" "${src:-}" \
352 "$archive/fip.bin"
353 else
354 echo "Updating FIP image (TBBR): $bin_name"
355 # With TBBR, we need to unpack, re-create certificates, and then
356 # recreate the FIP.
357 local fip_dir="$(mktempdir)"
358 local bin common_args stem
359 local rot_key="$(get_tf_opt ROT_KEY)"
360
361 rot_key="${rot_key:?}"
362 if ! is_abs "$rot_key"; then
363 rot_key="$tf_root/$rot_key"
364 fi
365
366 # Arguments only for cert_create
367 local cert_args="-n"
368 cert_args+=" --tfw-nvctr ${nvctr:-31}"
369 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
370 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
371 cert_args+=" --rot-key $rot_key"
372
373 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500374 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200375 "hw-config"
376 "tb-fw-config"
377 "nt-fw-config"
378 "soc-fw-config"
379 "tos-fw-config"
380 )
381
382 # Binaries without key certificates
383 declare -A has_no_key_cert
384 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
385 has_no_key_cert["$bin"]="1"
386 done
387
388 # Binaries without certificates
389 declare -A has_no_cert
390 for bin in "hw-config" "${dyn_config_opts[@]}"; do
391 has_no_cert["$bin"]="1"
392 done
393
394 pushd "$fip_dir"
395
396 # Unpack FIP
397 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
398
399 # Remove all existing certificates
400 rm -f *-cert.bin
401
402 # Copy the binary to be updated
403 cp -f "$src" "${bin_name}.bin"
404
405 # FIP unpack dumps binaries with the same name as the option
406 # used to pack it; likewise for certificates. Reverse-engineer
407 # the command line from the binary output.
408 common_args="--trusted-key-cert trusted_key.crt"
409 for bin in *.bin; do
410 stem="${bin%%.bin}"
411 common_args+=" --$stem $bin"
412 if not_upon "${has_no_cert[$stem]}"; then
413 common_args+=" --$stem-cert $stem.crt"
414 fi
415 if not_upon "${has_no_key_cert[$stem]}"; then
416 common_args+=" --$stem-key-cert $stem-key.crt"
417 fi
418 done
419
420 # Create certificates
421 "$cert_create" $cert_args $common_args &>>"$build_log"
422
423 # Recreate and archive FIP
424 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
425 archive_file "fip.bin"
426
427 popd
428 fi
429}
430
431# Update hw-config in FIP, and remove the original DTB afterwards.
432update_fip_hw_config() {
433 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600434 # in configs:
435 # 1. Where BL2 isn't present
436 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200437 case "1" in
438 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600439 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200440 "$(get_tf_opt RESET_TO_SP_MIN)" | \
Maksims Svecovs7a0da522023-03-06 16:28:27 +0000441 "$(get_tf_opt RESET_TO_BL2)")
Fathi Boudra422bf772019-12-02 11:10:16 +0200442 return 0;;
443 esac
444
445 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
446 # Remove the DTB so that model won't load it
447 rm -f "$archive/dtb.bin"
448 fi
449}
450
451get_scp_opt() {
452 (
453 name="${1:?}"
454 if config_valid "$scp_config_file"; then
455 source "$scp_config_file"
456 echo "${!name}"
457 fi
458 )
459}
460
461get_tftf_opt() {
462 (
463 name="${1:?}"
464 if config_valid "$tftf_config_file"; then
465 source "$tftf_config_file"
466 echo "${!name}"
467 fi
468 )
469}
470
471get_tf_opt() {
472 (
473 name="${1:?}"
474 if config_valid "$tf_config_file"; then
475 source "$tf_config_file"
476 echo "${!name}"
477 fi
478 )
479}
480
481build_tf() {
482 (
483 env_file="$workspace/tf.env"
484 config_file="${tf_build_config:-$tf_config_file}"
485
486 # Build fiptool and all targets by default
Harrison Mutai32de9d02023-06-12 14:23:37 +0100487 build_targets="${tf_build_targets:-fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200488
489 source "$config_file"
490
491 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000492 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100493 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
494 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200495 mbedtls_dir="$workspace/mbedtls"
496 if [ ! -d "$mbedtls_dir" ]; then
497 mbedtls_ar="$workspace/mbedtls.tar.gz"
498
499 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
500 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500501 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200502 fi
503
504 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
505 fi
Jimmy Brisson0d5e12c2023-05-16 14:51:51 -0500506 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
507 not_upon "${TF_M_TESTS_PATH}"; then
508 emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests"
509 fi
510 if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] &&
511 not_upon "${TF_M_EXTRAS_PATH}"; then
512 emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras"
513 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200514 if [ -f "$env_file" ]; then
515 set -a
516 source "$env_file"
517 set +a
518 fi
519
Harrison Mutai013f6332022-02-16 16:06:33 +0000520 if is_arm_jenkins_env || upon "$local_ci"; then
521 path_list=(
522 "$llvm_dir/bin"
523 )
524 extend_path "PATH" "path_list"
525 fi
526
Fathi Boudra422bf772019-12-02 11:10:16 +0200527 cd "$tf_root"
528
529 # Always distclean when running on Jenkins. Skip distclean when running
530 # locally and explicitly requested.
531 if upon "$jenkins_run" || not_upon "$dont_clean"; then
532 make distclean &>>"$build_log" || fail_build
533 fi
534
535 # Log build command line. It is left unfolded on purpose to assist
536 # copying to clipboard.
537 cat <<EOF | log_separator >/dev/null
538
539Build command line:
540 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
541
Paul Sokolovsky7f71b072023-10-16 12:59:09 +0300542CC version:
543$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200544EOF
545
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000546 if not_upon "$local_ci"; then
547 connect_debugger=0
548 fi
549
Fathi Boudra422bf772019-12-02 11:10:16 +0200550 # Build TF. Since build output is being directed to the build log, have
551 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000552 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000553 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200554 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100555
Harrison Mutai6dafb5f2023-07-18 15:21:48 +0100556 if [ "$build_targets" != "doc" ]; then
557 poetry run memory -sr "$tf_build_path" 2>&1 | tee -a "$build_log"
558 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200559 )
560}
561
562build_tftf() {
563 (
564 config_file="${tftf_build_config:-$tftf_config_file}"
565
566 # Build tftf target by default
567 build_targets="${tftf_build_targets:-all}"
568
569 source "$config_file"
570
571 cd "$tftf_root"
572
573 # Always distclean when running on Jenkins. Skip distclean when running
574 # locally and explicitly requested.
575 if upon "$jenkins_run" || not_upon "$dont_clean"; then
576 make distclean &>>"$build_log" || fail_build
577 fi
578
579 # TFTF build system cannot reliably deal with -j option, so we avoid
580 # using that.
581
582 # Log build command line
583 cat <<EOF | log_separator >/dev/null
584
585Build command line:
586 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
587
588EOF
589
590 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
591 $build_targets &>>"$build_log" || fail_build
592 )
593}
594
595build_scp() {
596 (
597 config_file="${scp_build_config:-$scp_config_file}"
598
599 source "$config_file"
600
601 cd "$scp_root"
602
603 # Always distclean when running on Jenkins. Skip distclean when running
604 # locally and explicitly requested.
605 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000606 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200607 fi
608
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000609 python3 -m venv .venv
610 . .venv/bin/activate
611
612 # Install extra tools used by CMake build system
613 pip install -r requirements.txt --timeout 30 --retries 15
614
Fathi Boudra422bf772019-12-02 11:10:16 +0200615 # Log build command line. It is left unfolded on purpose to assist
616 # copying to clipboard.
617 cat <<EOF | log_separator >/dev/null
618
619SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000620 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
621 TOOLCHAIN=GNU \
622 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000623 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000624 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200625
626EOF
627
628 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000629 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
630 TOOLCHAIN=GNU \
631 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000632 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000633 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200634 || fail_build
635 )
636}
637
Zelalem219df412020-05-17 19:21:20 -0500638clone_scp_tools() {
639
640 if [ ! -d "$scp_tools_root" ]; then
641 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
642
643 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
644 where="$scp_tools_root" \
645 refspec="${scp_tools_commit}"
646 clone_repo &>>"$build_log"
647 else
648 echo "Already cloned SCP-tools ..." |& log_separator
649 fi
650
651 show_head "$scp_tools_root"
652
653 cd "$scp_tools_root"
654
655 echo "Updating submodules"
656
657 git submodule init
658
659 git submodule update
660
Nicola Mazzucato9b171422023-08-29 15:50:49 +0100661 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 +0000662
Zelalem219df412020-05-17 19:21:20 -0500663 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000664 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500665
666 git show --quiet --no-color | sed 's/^/ > /g'
667}
668
669clone_tf_for_scp_tools() {
670 scp_tools_arm_tf="$scp_tools_root/arm-tf"
671
672 if [ ! -d "$scp_tools_arm_tf" ]; then
673 echo "Cloning TF-4-SCP-tools ..." |& log_separator
674
675 clone_url="$tf_for_scp_tools_src_repo_url"
676 where="$scp_tools_arm_tf"
677
678 git clone "$clone_url" "$where"
679
680 cd "$scp_tools_arm_tf"
681
Joel Goddard3ad03062021-03-16 16:47:42 +0000682 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500683
684 git show --quiet --no-color | sed 's/^/ > /g'
685
686 else
687 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
688 fi
689}
690
691build_scmi_lib_scp_tools() {
692 (
693 cd "$scp_tools_root"
694
695 cd "scmi"
696
697 scp_tools_arm_tf="$scp_tools_root/arm-tf"
698
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600699 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500700
701 std_libs="-I$scp_tools_arm_tf/include/common"
702 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
703 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
704 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
705 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
706 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
707 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
708 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
709 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
710 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
711 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
712 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
713 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
714 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
715
716 cflags="-Og -g"
717 cflags="$cflags -mgeneral-regs-only"
718 cflags="$cflags -mstrict-align"
719 cflags="$cflags -nostdinc"
720 cflags="$cflags -fno-inline"
721 cflags="$cflags -ffreestanding"
722 cflags="$cflags -ffunction-sections"
723 cflags="$cflags -fdata-sections"
724 cflags="$cflags -DAARCH64"
725 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000726 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500727
728 cflags="$cflags $std_libs"
729
Joel Goddard3ad03062021-03-16 16:47:42 +0000730 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500731
732 echo "Building SCMI library (SCP-tools) ..."
733
734 make "CROSS_COMPILE=$cross_compile" \
735 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000736 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500737 "PROTOCOLS=$protocols" \
738 "clean" \
739 "all"
740 )
741}
742
743build_tf_for_scp_tools() {
744
745 cd "$scp_tools_root/arm-tf"
746
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600747 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500748
749 if [ "$1" = "release" ]; then
750 echo "Build TF-4-SCP-Tools rls..."
751 else
752 echo "Build TF-4-SCP-Tools dbg..."
753
754 make realclean
755
756 make "BM_TEST=scmi" \
757 "ARM_BOARD_OPTIMISE_MEM=1" \
758 "BM_CSS=juno" \
759 "CSS_USE_SCMI_SDS_DRIVER=1" \
760 "PLAT=juno" \
761 "DEBUG=1" \
762 "PLATFORM=juno" \
763 "CROSS_COMPILE=$cross_compile" \
764 "BM_WORKSPACE=$scp_tools_root/baremetal"
765
766 archive_file "build/juno/debug/bl1.bin"
767
768 archive_file "build/juno/debug/bl2.bin"
769
770 archive_file "build/juno/debug/bl31.bin"
771 fi
772}
773
774build_fip_for_scp_tools() {
775
776 cd "$scp_tools_root/arm-tf"
777
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600778 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500779
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000780 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500781 make fiptool
782 echo "Make FIP 4 SCP-Tools rls..."
783
784 else
785 make fiptool
786 echo "Make FIP 4 SCP-Tools dbg..."
787
788 make "PLAT=juno" \
789 "all" \
790 "fip" \
791 "DEBUG=1" \
792 "CROSS_COMPILE=$cross_compile" \
793 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
794 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000795 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500796
797 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
798 fi
799}
800
801build_cc() {
802# Building code coverage plugin
803 ARM_DIR=/arm
804 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
805 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
806 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
807 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
808 exit -1
809 fi # Error if arm warehouse not found
810 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
811
812 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
813}
814
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100815build_spm() {
816 (
817 env_file="$workspace/spm.env"
818 config_file="${spm_build_config:-$spm_config_file}"
819
820 source "$config_file"
821
822 if [ -f "$env_file" ]; then
823 set -a
824 source "$env_file"
825 set +a
826 fi
827
828 cd "$spm_root"
829
830 # Always clean when running on Jenkins. Skip clean when running
831 # locally and explicitly requested.
832 if upon "$jenkins_run" || not_upon "$dont_clean"; then
833 # make clean fails on a fresh repo where the project has not
834 # yet been built. Hence only clean if out/reference directory
835 # already exists.
836 if [ -d "out/reference" ]; then
837 make clean &>>"$build_log" || fail_build
838 fi
839 fi
840
841 # Log build command line. It is left unfolded on purpose to assist
842 # copying to clipboard.
843 cat <<EOF | log_separator >/dev/null
844
845Build command line:
846 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
847
848EOF
849
850 # Build SPM. Since build output is being directed to the build log, have
851 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200852 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
853
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100854 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
855 || fail_build
856 )
857}
Zelalem219df412020-05-17 19:21:20 -0500858
Fathi Boudra422bf772019-12-02 11:10:16 +0200859# Set metadata for the whole package so that it can be used by both Jenkins and
860# shell
861set_package_var() {
862 env_file="$artefacts/env" emit_env "$@"
863}
864
865set_tf_build_targets() {
866 echo "Set build target to '${targets:?}'"
867 set_hook_var "tf_build_targets" "$targets"
868}
869
870set_tftf_build_targets() {
871 echo "Set build target to '${targets:?}'"
872 set_hook_var "tftf_build_targets" "$targets"
873}
874
875set_scp_build_targets() {
876 echo "Set build target to '${targets:?}'"
877 set_hook_var "scp_build_targets" "$targets"
878}
879
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100880set_spm_build_targets() {
881 echo "Set build target to '${targets:?}'"
882 set_hook_var "spm_build_targets" "$targets"
883}
884
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000885set_spm_out_dir() {
886 echo "Set SPMC binary build to '${out_dir:?}'"
887 set_hook_var "spm_secure_out_dir" "$out_dir"
888}
Fathi Boudra422bf772019-12-02 11:10:16 +0200889# Look under $archive directory for known files such as blX images, kernel, DTB,
890# initrd etc. For each known file foo, if foo.bin exists, then set variable
891# foo_bin to the path of the file. Make the path relative to the workspace so as
892# to remove any @ characters, which Jenkins inserts for parallel runs. If the
893# file doesn't exist, unset its path.
894set_default_bin_paths() {
895 local image image_name image_path path
896 local archive="${archive:?}"
897 local set_vars
898 local var
899
900 pushd "$archive"
901
902 for file in *.bin; do
903 # Get a shell variable from the file's stem
904 var_name="${file%%.*}_bin"
905 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
906
907 # Skip setting the variable if it's already
908 if [ "${!var_name}" ]; then
909 echo "Note: not setting $var_name; already set to ${!var_name}"
910 continue
911 else
912 set_vars+="$var_name "
913 fi
914
915 eval "$var_name=$file"
916 done
917
918 echo "Binary paths set for: "
919 {
920 for var in $set_vars; do
921 echo -n "\$$var "
922 done
923 } | fmt -80 | sed 's/^/ /'
924 echo
925
926 popd
927}
928
929gen_model_params() {
930 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000931 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200932
933 set_default_bin_paths
934 echo "Generating model parameter for $model..."
935 source "$ci_root/model/${model:?}.sh"
936 archive_file "$model_param_file"
937}
938
939set_model_path() {
940 set_run_env "model_path" "${1:?}"
941}
942
Zelalem1af7a7b2020-08-04 17:34:32 -0500943set_model_env() {
944 local var="${1:?}"
945 local val="${2?}"
946 local run_root="${archive:?}/run"
947
948 mkdir -p "$run_root"
949 echo "export $var=$val" >> "$run_root/model_env"
950}
Fathi Boudra422bf772019-12-02 11:10:16 +0200951set_run_env() {
952 local var="${1:?}"
953 local val="${2?}"
954 local run_root="${archive:?}/run"
955
956 mkdir -p "$run_root"
957 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
958}
959
960show_head() {
961 # Display HEAD descripton
962 pushd "$1"
963 git show --quiet --no-color | sed 's/^/ > /g'
964 echo
965 popd
966}
967
968# Choose debug binaries to run; by default, release binaries are chosen to run
969use_debug_bins() {
970 local run_root="${archive:?}/run"
971
972 echo "Choosing debug binaries for execution"
973 set_package_var "BIN_MODE" "debug"
974}
975
976assert_can_git_clone() {
977 local name="${1:?}"
978 local dir="${!name}"
979
980 # If it doesn't exist, it can be cloned into
981 if [ ! -e "$dir" ]; then
982 return 0
983 fi
984
985 # If it's a directory, it must be a Git clone already
986 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
987 # No need to clone again
988 echo "Using existing git clone for $name: $dir"
989 return 1
990 fi
991
992 die "Path $dir exists but is not a git clone"
993}
994
995clone_repo() {
996 if ! is_url "${clone_url?}"; then
997 # For --depth to take effect on local paths, it needs to use the
998 # file:// scheme.
999 clone_url="file://$clone_url"
1000 fi
1001
1002 git clone -q --depth 1 "$clone_url" "${where?}"
1003 if [ "$refspec" ]; then
1004 pushd "$where"
1005 git fetch -q --depth 1 origin "$refspec"
1006 git checkout -q FETCH_HEAD
1007 popd
1008 fi
1009}
1010
1011build_unstable() {
1012 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1013}
1014
1015undo_patch_record() {
1016 if [ ! -f "${patch_record:?}" ]; then
1017 return
1018 fi
1019
1020 # Undo patches in reverse
1021 echo
1022 for patch_name in $(tac "$patch_record"); do
1023 echo "Undoing $patch_name..."
1024 if ! git apply -R "$ci_root/patch/$patch_name"; then
1025 if upon "$local_ci"; then
1026 echo
1027 echo "Your local directory may have been dirtied."
1028 echo
1029 fi
1030 fail_build
1031 fi
1032 done
1033
1034 rm -f "$patch_record"
1035}
1036
1037undo_local_patches() {
1038 pushd "$tf_root"
1039 patch_record="$tf_patch_record" undo_patch_record
1040 popd
1041
1042 if [ -d "$tftf_root" ]; then
1043 pushd "$tftf_root"
1044 patch_record="$tftf_patch_record" undo_patch_record
1045 popd
1046 fi
1047}
1048
1049undo_tftf_patches() {
1050 pushd "$tftf_root"
1051 patch_record="$tftf_patch_record" undo_patch_record
1052 popd
1053}
1054
1055undo_tf_patches() {
1056 pushd "$tf_root"
1057 patch_record="$tf_patch_record" undo_patch_record
1058 popd
1059}
1060
1061apply_patch() {
1062 # If skip_patches is set, the developer has applied required patches
1063 # manually. They probably want to keep them applied for debugging
1064 # purposes too. This means we don't have to apply/revert them as part of
1065 # build process.
1066 if upon "$skip_patches"; then
1067 echo "Skipped applying ${1:?}..."
1068 return 0
1069 else
1070 echo "Applying ${1:?}..."
1071 fi
1072
Sandrine Bailleux4cb8c222023-09-13 13:48:15 +02001073 if git apply --reverse --check < "$ci_root/patch/$1" 2> /dev/null; then
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001074 echo "Skipping already applied ${1:?}"
1075 return 0
1076 fi
1077
Fathi Boudra422bf772019-12-02 11:10:16 +02001078 if git apply < "$ci_root/patch/$1"; then
1079 echo "$1" >> "${patch_record:?}"
1080 else
1081 if upon "$local_ci"; then
1082 undo_local_patches
1083 fi
1084 fail_build
1085 fi
1086}
1087
1088apply_tftf_patch() {
1089 pushd "$tftf_root"
1090 patch_record="$tftf_patch_record" apply_patch "$1"
1091 popd
1092}
1093
1094apply_tf_patch() {
1095 pushd "$tf_root"
1096 patch_record="$tf_patch_record" apply_patch "$1"
1097 popd
1098}
1099
1100# Clear workspace for a local run
1101if not_upon "$jenkins_run"; then
1102 rm -rf "$workspace"
1103
1104 # Clear residue from previous runs
1105 rm -rf "$archive"
1106fi
1107
1108mkdir -p "$workspace"
1109mkdir -p "$archive"
1110set_package_var "TEST_CONFIG" "$test_config"
1111
1112{
1113echo
1114echo "CONFIGURATION: $test_group/$test_config"
1115echo
1116} |& log_separator
1117
1118tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1119tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1120scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001121scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001122spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001123
1124test_config_file="$ci_root/group/$test_group/$test_config"
1125
1126tf_config_file="$ci_root/tf_config/$tf_config"
1127tftf_config_file="$ci_root/tftf_config/$tftf_config"
1128scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001129scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001130spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001131
1132# File that keeps track of applied patches
1133tf_patch_record="$workspace/tf_patches"
1134tftf_patch_record="$workspace/tftf_patches"
1135
1136pushd "$workspace"
1137
1138if ! config_valid "$tf_config"; then
1139 tf_config=
1140else
1141 echo "Trusted Firmware config:"
1142 echo
1143 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1144 echo
1145fi
1146
1147if ! config_valid "$tftf_config"; then
1148 tftf_config=
1149else
1150 echo "Trusted Firmware TF config:"
1151 echo
1152 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1153 echo
1154fi
1155
1156if ! config_valid "$scp_config"; then
1157 scp_config=
1158else
1159 echo "SCP firmware config:"
1160 echo
1161 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1162 echo
1163fi
1164
Zelalem219df412020-05-17 19:21:20 -05001165if ! config_valid "$scp_tools_config"; then
1166 scp_tools_config=
1167else
1168 echo "SCP Tools config:"
1169 echo
1170 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001171fi
1172
1173if ! config_valid "$spm_config"; then
1174 spm_config=
1175else
1176 echo "SPM config:"
1177 echo
1178 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001179 echo
1180fi
1181
Fathi Boudra422bf772019-12-02 11:10:16 +02001182if ! config_valid "$run_config"; then
1183 run_config=
1184fi
1185
1186if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1187 # If the Trusted Firmware repository has already been checked out, use
1188 # that location. Otherwise, clone one ourselves.
1189 echo "Cloning Trusted Firmware..."
1190 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1191 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1192 show_head "$tf_root"
1193fi
1194
1195if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1196 # If the Trusted Firmware TF repository has already been checked out,
1197 # use that location. Otherwise, clone one ourselves.
1198 echo "Cloning Trusted Firmware TF..."
1199 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1200 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1201 show_head "$tftf_root"
1202fi
1203
1204if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1205 # If the SCP firmware repository has already been checked out,
1206 # use that location. Otherwise, clone one ourselves.
1207 echo "Cloning SCP Firmware..."
1208 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1209 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1210
1211 pushd "$scp_root"
1212
1213 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001214 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001215 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1216 fi
1217
1218 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1219 # then to project filer if accessible.
1220 if [ -z "$cmsis_reference" ]; then
1221 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1222 if [ -d "$cmsis_ref_repo" ]; then
1223 cmsis_reference="--reference $cmsis_ref_repo"
1224 fi
1225 fi
1226
1227 git submodule -q update $cmsis_reference --init
1228
1229 popd
1230
1231 show_head "$scp_root"
1232fi
1233
Zelalem219df412020-05-17 19:21:20 -05001234if [ -n "$cc_config" ] ; then
1235 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1236 # Copy code coverage repository
1237 echo "Cloning Code Coverage..."
1238 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1239 show_head "$cc_root"
1240 fi
1241fi
1242
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001243if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1244 # If the SPM repository has already been checked out, use
1245 # that location. Otherwise, clone one ourselves.
1246 echo "Cloning SPM..."
1247 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1248 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1249
1250 # Query git submodules
1251 pushd "$spm_root"
1252 git submodule update --init
1253 popd
1254
1255 show_head "$spm_root"
1256fi
1257
Fathi Boudra422bf772019-12-02 11:10:16 +02001258if [ "$run_config" ]; then
1259 # Get candidates for run config
1260 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1261 "$run_config")"
1262 if [ -z "$run_config_candiates" ]; then
1263 die "No run config candidates!"
1264 else
1265 echo
1266 echo "Chosen fragments:"
1267 echo
1268 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1269 echo
1270 fi
1271fi
1272
1273call_hook "test_setup"
1274echo
1275
1276if upon "$local_ci"; then
1277 # For local runs, since each config is tried in sequence, it's
1278 # advantageous to run jobs in parallel
1279 if [ "$make_j" ]; then
1280 make_j_opts="-j $make_j"
1281 else
1282 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1283 if [ "$n_cores" ]; then
1284 make_j_opts="-j $n_cores"
1285 fi
1286 fi
1287fi
1288
Harrison Mutai07043e92023-07-06 09:41:12 +01001289# Install python build dependencies
1290if is_arm_jenkins_env; then
1291 source "$ci_root/script/install_python_deps.sh"
1292fi
1293
Fathi Boudra422bf772019-12-02 11:10:16 +02001294modes="${bin_mode:-debug release}"
1295for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001296 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001297 # Build with a temporary archive
1298 build_archive="$archive/$mode"
1299 mkdir "$build_archive"
1300
1301 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001302 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001303 DEBUG=1
1304 else
Zelalem219df412020-05-17 19:21:20 -05001305 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001306 DEBUG=0
1307 fi
1308
1309 # Perform builds in a subshell so as not to pollute the current and
1310 # subsequent builds' environment
1311
Zelalem219df412020-05-17 19:21:20 -05001312 if config_valid "$cc_config"; then
1313 # Build code coverage plugin
1314 build_cc
1315 fi
1316
Fathi Boudra422bf772019-12-02 11:10:16 +02001317 # SCP build
1318 if config_valid "$scp_config"; then
1319 (
1320 echo "##########"
1321
1322 # Source platform-specific utilities
1323 plat="$(get_scp_opt PRODUCT)"
1324 plat_utils="$ci_root/${plat}_utils.sh"
1325 if [ -f "$plat_utils" ]; then
1326 source "$plat_utils"
1327 fi
1328
1329 archive="$build_archive"
1330 scp_build_root="$scp_root/build"
1331
1332 echo "Building SCP Firmware ($mode) ..." |& log_separator
1333
1334 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001335 to="$archive" collect_scp_artefacts
1336
1337 echo "##########"
1338 echo
1339 )
1340 fi
1341
Zelalem219df412020-05-17 19:21:20 -05001342 # SCP-tools build
1343 if config_valid "$scp_tools_config"; then
1344 (
1345 echo "##########"
1346
1347 archive="$build_archive"
1348 scp_tools_build_root="$scp_tools_root/build"
1349
1350 clone_scp_tools
1351
1352 echo "##########"
1353 echo
1354
1355 echo "##########"
1356 clone_tf_for_scp_tools
1357 echo "##########"
1358 echo
1359 )
1360 fi
1361
Fathi Boudra422bf772019-12-02 11:10:16 +02001362 # TFTF build
1363 if config_valid "$tftf_config"; then
1364 (
1365 echo "##########"
1366
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001367 plat_utils="$(get_tf_opt PLAT_UTILS)"
1368 if [ -z ${plat_utils} ]; then
1369 # Source platform-specific utilities.
1370 plat="$(get_tftf_opt PLAT)"
1371 plat_utils="$ci_root/${plat}_utils.sh"
1372 else
1373 # Source platform-specific utilities by
1374 # using plat_utils name.
1375 plat_utils="$ci_root/${plat_utils}.sh"
1376 fi
1377
Fathi Boudra422bf772019-12-02 11:10:16 +02001378 if [ -f "$plat_utils" ]; then
1379 source "$plat_utils"
1380 fi
1381
1382 archive="$build_archive"
1383 tftf_build_root="$tftf_root/build"
1384
1385 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1386
1387 # Call pre-build hook
1388 call_hook pre_tftf_build
1389
1390 build_tftf
1391
1392 from="$tftf_build_root" to="$archive" collect_build_artefacts
1393
1394 # Clear any local changes made by applied patches
1395 undo_tftf_patches
1396
1397 echo "##########"
1398 echo
1399 )
1400 fi
1401
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001402 # SPM build
1403 if config_valid "$spm_config"; then
1404 (
1405 echo "##########"
1406
1407 # Get platform name from spm_config file
1408 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1409 plat_utils="$ci_root/${plat}_utils.sh"
1410 if [ -f "$plat_utils" ]; then
1411 source "$plat_utils"
1412 fi
1413
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001414 # Call pre-build hook
1415 call_hook pre_spm_build
1416
Manish Pandey1e7be852020-11-09 16:04:48 +00001417 # SPM build generates two sets of binaries, one for normal and other
1418 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001419 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001420 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1421 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001422
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001423 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001424 echo "Building SPM ($mode) ..." |& log_separator
1425
1426 # NOTE: mode has no effect on SPM build (for now), hence debug
1427 # mode is built but subsequent build using release mode just
1428 # goes through with "nothing to do".
1429 build_spm
1430
1431 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001432 cksum $spm_build_root/hafnium.bin
1433
1434 # Some platforms only have secure configuration enabled. Hence,
1435 # non secure hanfnium binary might not be built.
1436 if [ -f $hafnium_build_root/hafnium.bin ]; then
1437 cksum $hafnium_build_root/hafnium.bin
1438 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001439
Manish Pandey1e7be852020-11-09 16:04:48 +00001440 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001441
1442 echo "##########"
1443 echo
1444 )
1445 fi
1446
Fathi Boudra422bf772019-12-02 11:10:16 +02001447 # TF build
1448 if config_valid "$tf_config"; then
1449 (
1450 echo "##########"
1451
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001452 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001453 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1454
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001455 if [ -z ${plat_utils} ]; then
1456 # Source platform-specific utilities.
1457 plat="$(get_tf_opt PLAT)"
1458 plat_utils="$ci_root/${plat}_utils.sh"
1459 else
1460 # Source platform-specific utilities by
1461 # using plat_utils name.
1462 plat_utils="$ci_root/${plat_utils}.sh"
1463 fi
1464
Fathi Boudra422bf772019-12-02 11:10:16 +02001465 if [ -f "$plat_utils" ]; then
1466 source "$plat_utils"
1467 fi
1468
Chris Kaye5a486b2023-08-04 11:50:31 +00001469 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1470 fvp_tsram_size="${fvp_tsram_size:-256}"
1471
Harrison Mutai6361dbe2023-02-16 14:12:40 +00001472 poetry -C "$tf_root" install --without doc
Chris Kayd0837902021-11-17 10:17:52 +00001473
Fathi Boudra422bf772019-12-02 11:10:16 +02001474 archive="$build_archive"
1475 tf_build_root="$tf_root/build"
1476
1477 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1478
1479 # Call pre-build hook
1480 call_hook pre_tf_build
1481
1482 build_tf
1483
1484 # Call post-build hook
1485 call_hook post_tf_build
1486
1487 # Pre-archive hook
1488 call_hook pre_tf_archive
1489
1490 from="$tf_build_root" to="$archive" collect_build_artefacts
1491
1492 # Post-archive hook
1493 call_hook post_tf_archive
1494
1495 call_hook fetch_tf_resource
1496 call_hook post_fetch_tf_resource
1497
Chris Kay4e8aaf12022-09-01 15:21:55 +01001498 # Generate LAVA job files if necessary
1499 call_hook generate_lava_job_template
1500 call_hook generate_lava_job
1501
Fathi Boudra422bf772019-12-02 11:10:16 +02001502 # Clear any local changes made by applied patches
1503 undo_tf_patches
1504
1505 echo "##########"
1506 )
1507 fi
1508
1509 echo
1510 echo
1511done
1512
1513call_hook pre_package
1514
1515call_hook post_package
1516
1517if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001518 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001519fi
1520
1521echo
1522echo "Done"