blob: 188f27432e63d0dbc21bf20d2f9223190cb01955 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Anurag Koulbaedf932021-12-09 12:49:56 +00003# Copyright (c) 2019-2022 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 Sokolovsky49b4a732024-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
Javier Almansa Sobrinof98dbd82020-09-30 19:29:27 +0100178 if ! find "$from" \( -name "*.bin" -o -name '*.elf' -o -name '*.dtb' -o -name '*.axf' \) -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 Sokolovsky5f4b4042023-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 Sokolovsky5f4b4042023-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 Kay3a968862022-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
Govindraj Raja228091f2024-05-07 15:41:58 -0500346 if [ "$(get_tf_opt DEBUG)" = 0 ]; then
347 DEBUG=0
348 fi
349
Fathi Boudra422bf772019-12-02 11:10:16 +0200350 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
351 ${fip_targets:-fip} &>>"$build_log" || fail_build
352 )
353}
354
355fip_update() {
356 # Before the update process, check if the given image is supported by
357 # the fiptool. It's assumed that both fiptool and cert_create move in
358 # tandem, and therfore, if one has support, the other has it too.
359 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
360 return 1
361 fi
362
363 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
364 echo "Updating FIP image: $bin_name"
365 # Update HW config. Without TBBR, it's only a matter of using
366 # the update sub-command of fiptool
367 "$fiptool" update "--$bin_name" "${src:-}" \
368 "$archive/fip.bin"
369 else
370 echo "Updating FIP image (TBBR): $bin_name"
371 # With TBBR, we need to unpack, re-create certificates, and then
372 # recreate the FIP.
373 local fip_dir="$(mktempdir)"
374 local bin common_args stem
375 local rot_key="$(get_tf_opt ROT_KEY)"
376
377 rot_key="${rot_key:?}"
378 if ! is_abs "$rot_key"; then
379 rot_key="$tf_root/$rot_key"
380 fi
381
382 # Arguments only for cert_create
383 local cert_args="-n"
384 cert_args+=" --tfw-nvctr ${nvctr:-31}"
385 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
386 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
387 cert_args+=" --rot-key $rot_key"
388
389 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500390 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200391 "hw-config"
392 "tb-fw-config"
393 "nt-fw-config"
394 "soc-fw-config"
395 "tos-fw-config"
396 )
397
398 # Binaries without key certificates
399 declare -A has_no_key_cert
400 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
401 has_no_key_cert["$bin"]="1"
402 done
403
404 # Binaries without certificates
405 declare -A has_no_cert
406 for bin in "hw-config" "${dyn_config_opts[@]}"; do
407 has_no_cert["$bin"]="1"
408 done
409
410 pushd "$fip_dir"
411
412 # Unpack FIP
413 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
414
415 # Remove all existing certificates
416 rm -f *-cert.bin
417
418 # Copy the binary to be updated
419 cp -f "$src" "${bin_name}.bin"
420
421 # FIP unpack dumps binaries with the same name as the option
422 # used to pack it; likewise for certificates. Reverse-engineer
423 # the command line from the binary output.
424 common_args="--trusted-key-cert trusted_key.crt"
425 for bin in *.bin; do
426 stem="${bin%%.bin}"
427 common_args+=" --$stem $bin"
428 if not_upon "${has_no_cert[$stem]}"; then
429 common_args+=" --$stem-cert $stem.crt"
430 fi
431 if not_upon "${has_no_key_cert[$stem]}"; then
432 common_args+=" --$stem-key-cert $stem-key.crt"
433 fi
434 done
435
436 # Create certificates
437 "$cert_create" $cert_args $common_args &>>"$build_log"
438
439 # Recreate and archive FIP
440 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
441 archive_file "fip.bin"
442
443 popd
444 fi
445}
446
447# Update hw-config in FIP, and remove the original DTB afterwards.
448update_fip_hw_config() {
449 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600450 # in configs:
451 # 1. Where BL2 isn't present
452 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200453 case "1" in
454 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600455 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200456 "$(get_tf_opt RESET_TO_SP_MIN)" | \
457 "$(get_tf_opt BL2_AT_EL3)")
458 return 0;;
459 esac
460
461 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
462 # Remove the DTB so that model won't load it
463 rm -f "$archive/dtb.bin"
464 fi
465}
466
467get_scp_opt() {
468 (
469 name="${1:?}"
470 if config_valid "$scp_config_file"; then
471 source "$scp_config_file"
472 echo "${!name}"
473 fi
474 )
475}
476
477get_tftf_opt() {
478 (
479 name="${1:?}"
480 if config_valid "$tftf_config_file"; then
481 source "$tftf_config_file"
482 echo "${!name}"
483 fi
484 )
485}
486
487get_tf_opt() {
488 (
489 name="${1:?}"
490 if config_valid "$tf_config_file"; then
491 source "$tf_config_file"
492 echo "${!name}"
493 fi
494 )
495}
496
497build_tf() {
498 (
499 env_file="$workspace/tf.env"
500 config_file="${tf_build_config:-$tf_config_file}"
501
502 # Build fiptool and all targets by default
Manish V Badarkhe57bea362022-07-12 22:43:30 +0100503 build_targets="${tf_build_targets:-memmap fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200504
505 source "$config_file"
506
507 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000508 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100509 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
510 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200511 mbedtls_dir="$workspace/mbedtls"
512 if [ ! -d "$mbedtls_dir" ]; then
513 mbedtls_ar="$workspace/mbedtls.tar.gz"
514
515 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
516 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500517 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200518 fi
519
520 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
521 fi
522
523 if [ -f "$env_file" ]; then
524 set -a
525 source "$env_file"
526 set +a
527 fi
528
Harrison Mutai013f6332022-02-16 16:06:33 +0000529 if is_arm_jenkins_env || upon "$local_ci"; then
530 path_list=(
531 "$llvm_dir/bin"
532 )
533 extend_path "PATH" "path_list"
534 fi
535
Fathi Boudra422bf772019-12-02 11:10:16 +0200536 cd "$tf_root"
537
538 # Always distclean when running on Jenkins. Skip distclean when running
539 # locally and explicitly requested.
540 if upon "$jenkins_run" || not_upon "$dont_clean"; then
541 make distclean &>>"$build_log" || fail_build
542 fi
543
544 # Log build command line. It is left unfolded on purpose to assist
545 # copying to clipboard.
546 cat <<EOF | log_separator >/dev/null
547
548Build command line:
549 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
550
Paul Sokolovsky5815bcf2023-10-16 12:59:09 +0300551CC version:
552$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200553EOF
554
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000555 if not_upon "$local_ci"; then
556 connect_debugger=0
557 fi
558
Fathi Boudra422bf772019-12-02 11:10:16 +0200559 # Build TF. Since build output is being directed to the build log, have
560 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutaib76cecf2023-02-16 14:12:40 +0000561 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000562 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200563 $build_targets 3>&1 &>>"$build_log" || fail_build
564 )
565}
566
567build_tftf() {
568 (
569 config_file="${tftf_build_config:-$tftf_config_file}"
570
571 # Build tftf target by default
572 build_targets="${tftf_build_targets:-all}"
573
574 source "$config_file"
575
576 cd "$tftf_root"
577
578 # Always distclean when running on Jenkins. Skip distclean when running
579 # locally and explicitly requested.
580 if upon "$jenkins_run" || not_upon "$dont_clean"; then
581 make distclean &>>"$build_log" || fail_build
582 fi
583
584 # TFTF build system cannot reliably deal with -j option, so we avoid
585 # using that.
586
587 # Log build command line
588 cat <<EOF | log_separator >/dev/null
589
590Build command line:
591 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
592
593EOF
594
595 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
596 $build_targets &>>"$build_log" || fail_build
597 )
598}
599
600build_scp() {
601 (
602 config_file="${scp_build_config:-$scp_config_file}"
603
604 source "$config_file"
605
606 cd "$scp_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
Leandro Belli49f78672022-12-29 13:50:47 +0000611 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200612 fi
613
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000614 python3 -m venv .venv
615 . .venv/bin/activate
616
617 # Install extra tools used by CMake build system
618 pip install -r requirements.txt --timeout 30 --retries 15
619
Fathi Boudra422bf772019-12-02 11:10:16 +0200620 # Log build command line. It is left unfolded on purpose to assist
621 # copying to clipboard.
622 cat <<EOF | log_separator >/dev/null
623
624SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000625 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
626 TOOLCHAIN=GNU \
627 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000628 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000629 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200630
631EOF
632
633 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000634 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
635 TOOLCHAIN=GNU \
636 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000637 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000638 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200639 || fail_build
640 )
641}
642
Zelalem219df412020-05-17 19:21:20 -0500643clone_scp_tools() {
644
645 if [ ! -d "$scp_tools_root" ]; then
646 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
647
648 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
649 where="$scp_tools_root" \
650 refspec="${scp_tools_commit}"
651 clone_repo &>>"$build_log"
652 else
653 echo "Already cloned SCP-tools ..." |& log_separator
654 fi
655
656 show_head "$scp_tools_root"
657
658 cd "$scp_tools_root"
659
660 echo "Updating submodules"
661
662 git submodule init
663
664 git submodule update
665
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000666 lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'")
667
Zelalem219df412020-05-17 19:21:20 -0500668 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000669 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500670
671 git show --quiet --no-color | sed 's/^/ > /g'
672}
673
674clone_tf_for_scp_tools() {
675 scp_tools_arm_tf="$scp_tools_root/arm-tf"
676
677 if [ ! -d "$scp_tools_arm_tf" ]; then
678 echo "Cloning TF-4-SCP-tools ..." |& log_separator
679
680 clone_url="$tf_for_scp_tools_src_repo_url"
681 where="$scp_tools_arm_tf"
682
683 git clone "$clone_url" "$where"
684
685 cd "$scp_tools_arm_tf"
686
Joel Goddard3ad03062021-03-16 16:47:42 +0000687 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500688
689 git show --quiet --no-color | sed 's/^/ > /g'
690
691 else
692 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
693 fi
694}
695
696build_scmi_lib_scp_tools() {
697 (
698 cd "$scp_tools_root"
699
700 cd "scmi"
701
702 scp_tools_arm_tf="$scp_tools_root/arm-tf"
703
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600704 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500705
706 std_libs="-I$scp_tools_arm_tf/include/common"
707 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
708 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
709 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
710 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
711 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
712 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
713 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
714 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
715 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
716 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
717 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
718 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
719 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
720
721 cflags="-Og -g"
722 cflags="$cflags -mgeneral-regs-only"
723 cflags="$cflags -mstrict-align"
724 cflags="$cflags -nostdinc"
725 cflags="$cflags -fno-inline"
726 cflags="$cflags -ffreestanding"
727 cflags="$cflags -ffunction-sections"
728 cflags="$cflags -fdata-sections"
729 cflags="$cflags -DAARCH64"
730 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000731 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500732
733 cflags="$cflags $std_libs"
734
Joel Goddard3ad03062021-03-16 16:47:42 +0000735 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500736
737 echo "Building SCMI library (SCP-tools) ..."
738
739 make "CROSS_COMPILE=$cross_compile" \
740 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000741 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500742 "PROTOCOLS=$protocols" \
743 "clean" \
744 "all"
745 )
746}
747
748build_tf_for_scp_tools() {
749
750 cd "$scp_tools_root/arm-tf"
751
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600752 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500753
754 if [ "$1" = "release" ]; then
755 echo "Build TF-4-SCP-Tools rls..."
756 else
757 echo "Build TF-4-SCP-Tools dbg..."
758
759 make realclean
760
761 make "BM_TEST=scmi" \
762 "ARM_BOARD_OPTIMISE_MEM=1" \
763 "BM_CSS=juno" \
764 "CSS_USE_SCMI_SDS_DRIVER=1" \
765 "PLAT=juno" \
766 "DEBUG=1" \
767 "PLATFORM=juno" \
768 "CROSS_COMPILE=$cross_compile" \
769 "BM_WORKSPACE=$scp_tools_root/baremetal"
770
771 archive_file "build/juno/debug/bl1.bin"
772
773 archive_file "build/juno/debug/bl2.bin"
774
775 archive_file "build/juno/debug/bl31.bin"
776 fi
777}
778
779build_fip_for_scp_tools() {
780
781 cd "$scp_tools_root/arm-tf"
782
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600783 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500784
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000785 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500786 make fiptool
787 echo "Make FIP 4 SCP-Tools rls..."
788
789 else
790 make fiptool
791 echo "Make FIP 4 SCP-Tools dbg..."
792
793 make "PLAT=juno" \
794 "all" \
795 "fip" \
796 "DEBUG=1" \
797 "CROSS_COMPILE=$cross_compile" \
798 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
799 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000800 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500801
802 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
803 fi
804}
805
806build_cc() {
807# Building code coverage plugin
808 ARM_DIR=/arm
809 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
810 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
811 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
812 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
813 exit -1
814 fi # Error if arm warehouse not found
815 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
816
817 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
818}
819
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100820build_spm() {
821 (
822 env_file="$workspace/spm.env"
823 config_file="${spm_build_config:-$spm_config_file}"
824
825 source "$config_file"
826
827 if [ -f "$env_file" ]; then
828 set -a
829 source "$env_file"
830 set +a
831 fi
832
833 cd "$spm_root"
834
835 # Always clean when running on Jenkins. Skip clean when running
836 # locally and explicitly requested.
837 if upon "$jenkins_run" || not_upon "$dont_clean"; then
838 # make clean fails on a fresh repo where the project has not
839 # yet been built. Hence only clean if out/reference directory
840 # already exists.
841 if [ -d "out/reference" ]; then
842 make clean &>>"$build_log" || fail_build
843 fi
844 fi
845
846 # Log build command line. It is left unfolded on purpose to assist
847 # copying to clipboard.
848 cat <<EOF | log_separator >/dev/null
849
850Build command line:
851 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
852
853EOF
854
855 # Build SPM. Since build output is being directed to the build log, have
856 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200857 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
858
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100859 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
860 || fail_build
861 )
862}
Zelalem219df412020-05-17 19:21:20 -0500863
Fathi Boudra422bf772019-12-02 11:10:16 +0200864# Set metadata for the whole package so that it can be used by both Jenkins and
865# shell
866set_package_var() {
867 env_file="$artefacts/env" emit_env "$@"
868}
869
870set_tf_build_targets() {
871 echo "Set build target to '${targets:?}'"
872 set_hook_var "tf_build_targets" "$targets"
873}
874
875set_tftf_build_targets() {
876 echo "Set build target to '${targets:?}'"
877 set_hook_var "tftf_build_targets" "$targets"
878}
879
880set_scp_build_targets() {
881 echo "Set build target to '${targets:?}'"
882 set_hook_var "scp_build_targets" "$targets"
883}
884
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100885set_spm_build_targets() {
886 echo "Set build target to '${targets:?}'"
887 set_hook_var "spm_build_targets" "$targets"
888}
889
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000890set_spm_out_dir() {
891 echo "Set SPMC binary build to '${out_dir:?}'"
892 set_hook_var "spm_secure_out_dir" "$out_dir"
893}
Fathi Boudra422bf772019-12-02 11:10:16 +0200894# Look under $archive directory for known files such as blX images, kernel, DTB,
895# initrd etc. For each known file foo, if foo.bin exists, then set variable
896# foo_bin to the path of the file. Make the path relative to the workspace so as
897# to remove any @ characters, which Jenkins inserts for parallel runs. If the
898# file doesn't exist, unset its path.
899set_default_bin_paths() {
900 local image image_name image_path path
901 local archive="${archive:?}"
902 local set_vars
903 local var
904
905 pushd "$archive"
906
907 for file in *.bin; do
908 # Get a shell variable from the file's stem
909 var_name="${file%%.*}_bin"
910 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
911
912 # Skip setting the variable if it's already
913 if [ "${!var_name}" ]; then
914 echo "Note: not setting $var_name; already set to ${!var_name}"
915 continue
916 else
917 set_vars+="$var_name "
918 fi
919
920 eval "$var_name=$file"
921 done
922
923 echo "Binary paths set for: "
924 {
925 for var in $set_vars; do
926 echo -n "\$$var "
927 done
928 } | fmt -80 | sed 's/^/ /'
929 echo
930
931 popd
932}
933
934gen_model_params() {
935 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000936 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200937
938 set_default_bin_paths
939 echo "Generating model parameter for $model..."
940 source "$ci_root/model/${model:?}.sh"
941 archive_file "$model_param_file"
942}
943
944set_model_path() {
945 set_run_env "model_path" "${1:?}"
946}
947
Zelalem1af7a7b2020-08-04 17:34:32 -0500948set_model_env() {
949 local var="${1:?}"
950 local val="${2?}"
951 local run_root="${archive:?}/run"
952
953 mkdir -p "$run_root"
954 echo "export $var=$val" >> "$run_root/model_env"
955}
Fathi Boudra422bf772019-12-02 11:10:16 +0200956set_run_env() {
957 local var="${1:?}"
958 local val="${2?}"
959 local run_root="${archive:?}/run"
960
961 mkdir -p "$run_root"
962 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
963}
964
965show_head() {
966 # Display HEAD descripton
967 pushd "$1"
968 git show --quiet --no-color | sed 's/^/ > /g'
969 echo
970 popd
971}
972
973# Choose debug binaries to run; by default, release binaries are chosen to run
974use_debug_bins() {
975 local run_root="${archive:?}/run"
976
977 echo "Choosing debug binaries for execution"
978 set_package_var "BIN_MODE" "debug"
979}
980
981assert_can_git_clone() {
982 local name="${1:?}"
983 local dir="${!name}"
984
985 # If it doesn't exist, it can be cloned into
986 if [ ! -e "$dir" ]; then
987 return 0
988 fi
989
990 # If it's a directory, it must be a Git clone already
991 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
992 # No need to clone again
993 echo "Using existing git clone for $name: $dir"
994 return 1
995 fi
996
997 die "Path $dir exists but is not a git clone"
998}
999
1000clone_repo() {
1001 if ! is_url "${clone_url?}"; then
1002 # For --depth to take effect on local paths, it needs to use the
1003 # file:// scheme.
1004 clone_url="file://$clone_url"
1005 fi
1006
1007 git clone -q --depth 1 "$clone_url" "${where?}"
1008 if [ "$refspec" ]; then
1009 pushd "$where"
1010 git fetch -q --depth 1 origin "$refspec"
1011 git checkout -q FETCH_HEAD
1012 popd
1013 fi
1014}
1015
1016build_unstable() {
1017 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1018}
1019
1020undo_patch_record() {
1021 if [ ! -f "${patch_record:?}" ]; then
1022 return
1023 fi
1024
1025 # Undo patches in reverse
1026 echo
1027 for patch_name in $(tac "$patch_record"); do
1028 echo "Undoing $patch_name..."
1029 if ! git apply -R "$ci_root/patch/$patch_name"; then
1030 if upon "$local_ci"; then
1031 echo
1032 echo "Your local directory may have been dirtied."
1033 echo
1034 fi
1035 fail_build
1036 fi
1037 done
1038
1039 rm -f "$patch_record"
1040}
1041
1042undo_local_patches() {
1043 pushd "$tf_root"
1044 patch_record="$tf_patch_record" undo_patch_record
1045 popd
1046
1047 if [ -d "$tftf_root" ]; then
1048 pushd "$tftf_root"
1049 patch_record="$tftf_patch_record" undo_patch_record
1050 popd
1051 fi
1052}
1053
1054undo_tftf_patches() {
1055 pushd "$tftf_root"
1056 patch_record="$tftf_patch_record" undo_patch_record
1057 popd
1058}
1059
1060undo_tf_patches() {
1061 pushd "$tf_root"
1062 patch_record="$tf_patch_record" undo_patch_record
1063 popd
1064}
1065
1066apply_patch() {
1067 # If skip_patches is set, the developer has applied required patches
1068 # manually. They probably want to keep them applied for debugging
1069 # purposes too. This means we don't have to apply/revert them as part of
1070 # build process.
1071 if upon "$skip_patches"; then
1072 echo "Skipped applying ${1:?}..."
1073 return 0
1074 else
1075 echo "Applying ${1:?}..."
1076 fi
1077
1078 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
Daniel Boulby71d8e8a2023-12-14 14:36:25 +00001243if [ "$spm_config" ] ; then
1244 if assert_can_git_clone "spm_root"; then
1245 # If the SPM repository has already been checked out, use
1246 # that location. Otherwise, clone one ourselves.
1247 echo "Cloning SPM..."
1248 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1249 where="$spm_root" refspec="$SPM_REFSPEC" \
1250 clone_repo &>>"$build_log"
1251 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001252
1253 # Query git submodules
1254 pushd "$spm_root"
Daniel Boulby71d8e8a2023-12-14 14:36:25 +00001255 # Check if submodules need initialising
Paul Sokolovskyddfe02b2024-09-01 10:27:56 +03001256
1257 # This handling is needed to reliably fetch submodules
1258 # in CI environment.
1259 for subm in $(git submodule status | awk '/^-/ {print $2}'); do
1260 for i in $(seq 1 7); do
1261 git submodule init $subm
1262 if git submodule update $subm; then
1263 break
1264 fi
1265 git submodule deinit --force $subm
1266 echo "Retrying $subm"
1267 sleep $((RANDOM % 10 + 5))
1268 done
1269 done
1270
1271 git submodule status
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001272 popd
1273
1274 show_head "$spm_root"
1275fi
1276
Fathi Boudra422bf772019-12-02 11:10:16 +02001277if [ "$run_config" ]; then
1278 # Get candidates for run config
1279 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1280 "$run_config")"
1281 if [ -z "$run_config_candiates" ]; then
1282 die "No run config candidates!"
1283 else
1284 echo
1285 echo "Chosen fragments:"
1286 echo
1287 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1288 echo
1289 fi
1290fi
1291
1292call_hook "test_setup"
1293echo
1294
1295if upon "$local_ci"; then
1296 # For local runs, since each config is tried in sequence, it's
1297 # advantageous to run jobs in parallel
1298 if [ "$make_j" ]; then
1299 make_j_opts="-j $make_j"
1300 else
1301 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1302 if [ "$n_cores" ]; then
1303 make_j_opts="-j $n_cores"
1304 fi
1305 fi
1306fi
1307
1308modes="${bin_mode:-debug release}"
1309for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001310 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001311 # Build with a temporary archive
1312 build_archive="$archive/$mode"
1313 mkdir "$build_archive"
1314
1315 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001316 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001317 DEBUG=1
1318 else
Zelalem219df412020-05-17 19:21:20 -05001319 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001320 DEBUG=0
1321 fi
1322
1323 # Perform builds in a subshell so as not to pollute the current and
1324 # subsequent builds' environment
1325
Zelalem219df412020-05-17 19:21:20 -05001326 if config_valid "$cc_config"; then
1327 # Build code coverage plugin
1328 build_cc
1329 fi
1330
Fathi Boudra422bf772019-12-02 11:10:16 +02001331 # SCP build
1332 if config_valid "$scp_config"; then
1333 (
1334 echo "##########"
1335
1336 # Source platform-specific utilities
1337 plat="$(get_scp_opt PRODUCT)"
1338 plat_utils="$ci_root/${plat}_utils.sh"
1339 if [ -f "$plat_utils" ]; then
1340 source "$plat_utils"
1341 fi
1342
1343 archive="$build_archive"
1344 scp_build_root="$scp_root/build"
1345
1346 echo "Building SCP Firmware ($mode) ..." |& log_separator
1347
1348 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001349 to="$archive" collect_scp_artefacts
1350
1351 echo "##########"
1352 echo
1353 )
1354 fi
1355
Zelalem219df412020-05-17 19:21:20 -05001356 # SCP-tools build
1357 if config_valid "$scp_tools_config"; then
1358 (
1359 echo "##########"
1360
1361 archive="$build_archive"
1362 scp_tools_build_root="$scp_tools_root/build"
1363
1364 clone_scp_tools
1365
1366 echo "##########"
1367 echo
1368
1369 echo "##########"
1370 clone_tf_for_scp_tools
1371 echo "##########"
1372 echo
1373 )
1374 fi
1375
Fathi Boudra422bf772019-12-02 11:10:16 +02001376 # TFTF build
1377 if config_valid "$tftf_config"; then
1378 (
1379 echo "##########"
1380
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001381 plat_utils="$(get_tf_opt PLAT_UTILS)"
1382 if [ -z ${plat_utils} ]; then
1383 # Source platform-specific utilities.
1384 plat="$(get_tftf_opt PLAT)"
1385 plat_utils="$ci_root/${plat}_utils.sh"
1386 else
1387 # Source platform-specific utilities by
1388 # using plat_utils name.
1389 plat_utils="$ci_root/${plat_utils}.sh"
1390 fi
1391
Fathi Boudra422bf772019-12-02 11:10:16 +02001392 if [ -f "$plat_utils" ]; then
1393 source "$plat_utils"
1394 fi
1395
1396 archive="$build_archive"
1397 tftf_build_root="$tftf_root/build"
1398
1399 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1400
1401 # Call pre-build hook
1402 call_hook pre_tftf_build
1403
1404 build_tftf
1405
1406 from="$tftf_build_root" to="$archive" collect_build_artefacts
1407
1408 # Clear any local changes made by applied patches
1409 undo_tftf_patches
1410
1411 echo "##########"
1412 echo
1413 )
1414 fi
1415
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001416 # SPM build
1417 if config_valid "$spm_config"; then
1418 (
1419 echo "##########"
1420
1421 # Get platform name from spm_config file
1422 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1423 plat_utils="$ci_root/${plat}_utils.sh"
1424 if [ -f "$plat_utils" ]; then
1425 source "$plat_utils"
1426 fi
1427
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001428 # Call pre-build hook
1429 call_hook pre_spm_build
1430
Manish Pandey1e7be852020-11-09 16:04:48 +00001431 # SPM build generates two sets of binaries, one for normal and other
1432 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001433 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001434 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1435 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001436
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001437 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001438 echo "Building SPM ($mode) ..." |& log_separator
1439
1440 # NOTE: mode has no effect on SPM build (for now), hence debug
1441 # mode is built but subsequent build using release mode just
1442 # goes through with "nothing to do".
1443 build_spm
1444
1445 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001446 cksum $spm_build_root/hafnium.bin
1447
1448 # Some platforms only have secure configuration enabled. Hence,
1449 # non secure hanfnium binary might not be built.
1450 if [ -f $hafnium_build_root/hafnium.bin ]; then
1451 cksum $hafnium_build_root/hafnium.bin
1452 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001453
Manish Pandey1e7be852020-11-09 16:04:48 +00001454 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001455
1456 echo "##########"
1457 echo
1458 )
1459 fi
1460
Fathi Boudra422bf772019-12-02 11:10:16 +02001461 # TF build
1462 if config_valid "$tf_config"; then
1463 (
1464 echo "##########"
1465
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001466 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001467 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1468
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001469 if [ -z ${plat_utils} ]; then
1470 # Source platform-specific utilities.
1471 plat="$(get_tf_opt PLAT)"
1472 plat_utils="$ci_root/${plat}_utils.sh"
1473 else
1474 # Source platform-specific utilities by
1475 # using plat_utils name.
1476 plat_utils="$ci_root/${plat_utils}.sh"
1477 fi
1478
Fathi Boudra422bf772019-12-02 11:10:16 +02001479 if [ -f "$plat_utils" ]; then
1480 source "$plat_utils"
1481 fi
1482
Harrison Mutaib76cecf2023-02-16 14:12:40 +00001483 # Install python build dependencies
1484 if is_arm_jenkins_env; then
1485 source "$ci_root/script/install_python_deps_tf.sh"
1486 fi
1487
1488 poetry -C "$tf_root" install --without doc
Chris Kayd0837902021-11-17 10:17:52 +00001489
Chris Kay48c50de2023-08-04 11:50:31 +00001490 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1491 fvp_tsram_size="${fvp_tsram_size:-256}"
1492
Fathi Boudra422bf772019-12-02 11:10:16 +02001493 archive="$build_archive"
1494 tf_build_root="$tf_root/build"
1495
1496 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1497
1498 # Call pre-build hook
1499 call_hook pre_tf_build
1500
1501 build_tf
1502
1503 # Call post-build hook
1504 call_hook post_tf_build
1505
1506 # Pre-archive hook
1507 call_hook pre_tf_archive
1508
1509 from="$tf_build_root" to="$archive" collect_build_artefacts
1510
1511 # Post-archive hook
1512 call_hook post_tf_archive
1513
1514 call_hook fetch_tf_resource
1515 call_hook post_fetch_tf_resource
1516
Chris Kay4e8aaf12022-09-01 15:21:55 +01001517 # Generate LAVA job files if necessary
1518 call_hook generate_lava_job_template
1519 call_hook generate_lava_job
1520
Fathi Boudra422bf772019-12-02 11:10:16 +02001521 # Clear any local changes made by applied patches
1522 undo_tf_patches
1523
1524 echo "##########"
1525 )
1526 fi
1527
1528 echo
1529 echo
1530done
1531
1532call_hook pre_package
1533
1534call_hook post_package
1535
1536if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001537 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001538fi
1539
1540echo
1541echo "Done"