blob: 307d79310f60e50539cc0494ec577a0a8776f20b [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
542EOF
543
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000544 if not_upon "$local_ci"; then
545 connect_debugger=0
546 fi
547
Fathi Boudra422bf772019-12-02 11:10:16 +0200548 # Build TF. Since build output is being directed to the build log, have
549 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutai6361dbe2023-02-16 14:12:40 +0000550 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000551 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200552 $build_targets 3>&1 &>>"$build_log" || fail_build
Harrison Mutai32de9d02023-06-12 14:23:37 +0100553
554 poetry run memory -sr "$tf_build_path" 2>&1 | tee -a "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200555 )
556}
557
558build_tftf() {
559 (
560 config_file="${tftf_build_config:-$tftf_config_file}"
561
562 # Build tftf target by default
563 build_targets="${tftf_build_targets:-all}"
564
565 source "$config_file"
566
567 cd "$tftf_root"
568
569 # Always distclean when running on Jenkins. Skip distclean when running
570 # locally and explicitly requested.
571 if upon "$jenkins_run" || not_upon "$dont_clean"; then
572 make distclean &>>"$build_log" || fail_build
573 fi
574
575 # TFTF build system cannot reliably deal with -j option, so we avoid
576 # using that.
577
578 # Log build command line
579 cat <<EOF | log_separator >/dev/null
580
581Build command line:
582 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
583
584EOF
585
586 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
587 $build_targets &>>"$build_log" || fail_build
588 )
589}
590
591build_scp() {
592 (
593 config_file="${scp_build_config:-$scp_config_file}"
594
595 source "$config_file"
596
597 cd "$scp_root"
598
599 # Always distclean when running on Jenkins. Skip distclean when running
600 # locally and explicitly requested.
601 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli99e20b22022-12-29 13:50:47 +0000602 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200603 fi
604
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000605 python3 -m venv .venv
606 . .venv/bin/activate
607
608 # Install extra tools used by CMake build system
609 pip install -r requirements.txt --timeout 30 --retries 15
610
Fathi Boudra422bf772019-12-02 11:10:16 +0200611 # Log build command line. It is left unfolded on purpose to assist
612 # copying to clipboard.
613 cat <<EOF | log_separator >/dev/null
614
615SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000616 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
617 TOOLCHAIN=GNU \
618 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000619 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000620 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200621
622EOF
623
624 # Build SCP
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 || fail_build
631 )
632}
633
Zelalem219df412020-05-17 19:21:20 -0500634clone_scp_tools() {
635
636 if [ ! -d "$scp_tools_root" ]; then
637 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
638
639 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
640 where="$scp_tools_root" \
641 refspec="${scp_tools_commit}"
642 clone_repo &>>"$build_log"
643 else
644 echo "Already cloned SCP-tools ..." |& log_separator
645 fi
646
647 show_head "$scp_tools_root"
648
649 cd "$scp_tools_root"
650
651 echo "Updating submodules"
652
653 git submodule init
654
655 git submodule update
656
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000657 lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'")
658
Zelalem219df412020-05-17 19:21:20 -0500659 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000660 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500661
662 git show --quiet --no-color | sed 's/^/ > /g'
663}
664
665clone_tf_for_scp_tools() {
666 scp_tools_arm_tf="$scp_tools_root/arm-tf"
667
668 if [ ! -d "$scp_tools_arm_tf" ]; then
669 echo "Cloning TF-4-SCP-tools ..." |& log_separator
670
671 clone_url="$tf_for_scp_tools_src_repo_url"
672 where="$scp_tools_arm_tf"
673
674 git clone "$clone_url" "$where"
675
676 cd "$scp_tools_arm_tf"
677
Joel Goddard3ad03062021-03-16 16:47:42 +0000678 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500679
680 git show --quiet --no-color | sed 's/^/ > /g'
681
682 else
683 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
684 fi
685}
686
687build_scmi_lib_scp_tools() {
688 (
689 cd "$scp_tools_root"
690
691 cd "scmi"
692
693 scp_tools_arm_tf="$scp_tools_root/arm-tf"
694
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600695 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500696
697 std_libs="-I$scp_tools_arm_tf/include/common"
698 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
699 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
700 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
701 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
702 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
703 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
704 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
705 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
706 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
707 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
708 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
709 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
710 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
711
712 cflags="-Og -g"
713 cflags="$cflags -mgeneral-regs-only"
714 cflags="$cflags -mstrict-align"
715 cflags="$cflags -nostdinc"
716 cflags="$cflags -fno-inline"
717 cflags="$cflags -ffreestanding"
718 cflags="$cflags -ffunction-sections"
719 cflags="$cflags -fdata-sections"
720 cflags="$cflags -DAARCH64"
721 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000722 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500723
724 cflags="$cflags $std_libs"
725
Joel Goddard3ad03062021-03-16 16:47:42 +0000726 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500727
728 echo "Building SCMI library (SCP-tools) ..."
729
730 make "CROSS_COMPILE=$cross_compile" \
731 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000732 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500733 "PROTOCOLS=$protocols" \
734 "clean" \
735 "all"
736 )
737}
738
739build_tf_for_scp_tools() {
740
741 cd "$scp_tools_root/arm-tf"
742
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600743 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500744
745 if [ "$1" = "release" ]; then
746 echo "Build TF-4-SCP-Tools rls..."
747 else
748 echo "Build TF-4-SCP-Tools dbg..."
749
750 make realclean
751
752 make "BM_TEST=scmi" \
753 "ARM_BOARD_OPTIMISE_MEM=1" \
754 "BM_CSS=juno" \
755 "CSS_USE_SCMI_SDS_DRIVER=1" \
756 "PLAT=juno" \
757 "DEBUG=1" \
758 "PLATFORM=juno" \
759 "CROSS_COMPILE=$cross_compile" \
760 "BM_WORKSPACE=$scp_tools_root/baremetal"
761
762 archive_file "build/juno/debug/bl1.bin"
763
764 archive_file "build/juno/debug/bl2.bin"
765
766 archive_file "build/juno/debug/bl31.bin"
767 fi
768}
769
770build_fip_for_scp_tools() {
771
772 cd "$scp_tools_root/arm-tf"
773
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600774 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500775
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000776 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500777 make fiptool
778 echo "Make FIP 4 SCP-Tools rls..."
779
780 else
781 make fiptool
782 echo "Make FIP 4 SCP-Tools dbg..."
783
784 make "PLAT=juno" \
785 "all" \
786 "fip" \
787 "DEBUG=1" \
788 "CROSS_COMPILE=$cross_compile" \
789 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
790 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000791 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500792
793 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
794 fi
795}
796
797build_cc() {
798# Building code coverage plugin
799 ARM_DIR=/arm
800 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
801 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
802 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
803 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
804 exit -1
805 fi # Error if arm warehouse not found
806 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
807
808 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
809}
810
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100811build_spm() {
812 (
813 env_file="$workspace/spm.env"
814 config_file="${spm_build_config:-$spm_config_file}"
815
816 source "$config_file"
817
818 if [ -f "$env_file" ]; then
819 set -a
820 source "$env_file"
821 set +a
822 fi
823
824 cd "$spm_root"
825
826 # Always clean when running on Jenkins. Skip clean when running
827 # locally and explicitly requested.
828 if upon "$jenkins_run" || not_upon "$dont_clean"; then
829 # make clean fails on a fresh repo where the project has not
830 # yet been built. Hence only clean if out/reference directory
831 # already exists.
832 if [ -d "out/reference" ]; then
833 make clean &>>"$build_log" || fail_build
834 fi
835 fi
836
837 # Log build command line. It is left unfolded on purpose to assist
838 # copying to clipboard.
839 cat <<EOF | log_separator >/dev/null
840
841Build command line:
842 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
843
844EOF
845
846 # Build SPM. Since build output is being directed to the build log, have
847 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200848 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
849
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100850 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
851 || fail_build
852 )
853}
Zelalem219df412020-05-17 19:21:20 -0500854
Fathi Boudra422bf772019-12-02 11:10:16 +0200855# Set metadata for the whole package so that it can be used by both Jenkins and
856# shell
857set_package_var() {
858 env_file="$artefacts/env" emit_env "$@"
859}
860
861set_tf_build_targets() {
862 echo "Set build target to '${targets:?}'"
863 set_hook_var "tf_build_targets" "$targets"
864}
865
866set_tftf_build_targets() {
867 echo "Set build target to '${targets:?}'"
868 set_hook_var "tftf_build_targets" "$targets"
869}
870
871set_scp_build_targets() {
872 echo "Set build target to '${targets:?}'"
873 set_hook_var "scp_build_targets" "$targets"
874}
875
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100876set_spm_build_targets() {
877 echo "Set build target to '${targets:?}'"
878 set_hook_var "spm_build_targets" "$targets"
879}
880
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000881set_spm_out_dir() {
882 echo "Set SPMC binary build to '${out_dir:?}'"
883 set_hook_var "spm_secure_out_dir" "$out_dir"
884}
Fathi Boudra422bf772019-12-02 11:10:16 +0200885# Look under $archive directory for known files such as blX images, kernel, DTB,
886# initrd etc. For each known file foo, if foo.bin exists, then set variable
887# foo_bin to the path of the file. Make the path relative to the workspace so as
888# to remove any @ characters, which Jenkins inserts for parallel runs. If the
889# file doesn't exist, unset its path.
890set_default_bin_paths() {
891 local image image_name image_path path
892 local archive="${archive:?}"
893 local set_vars
894 local var
895
896 pushd "$archive"
897
898 for file in *.bin; do
899 # Get a shell variable from the file's stem
900 var_name="${file%%.*}_bin"
901 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
902
903 # Skip setting the variable if it's already
904 if [ "${!var_name}" ]; then
905 echo "Note: not setting $var_name; already set to ${!var_name}"
906 continue
907 else
908 set_vars+="$var_name "
909 fi
910
911 eval "$var_name=$file"
912 done
913
914 echo "Binary paths set for: "
915 {
916 for var in $set_vars; do
917 echo -n "\$$var "
918 done
919 } | fmt -80 | sed 's/^/ /'
920 echo
921
922 popd
923}
924
925gen_model_params() {
926 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000927 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200928
929 set_default_bin_paths
930 echo "Generating model parameter for $model..."
931 source "$ci_root/model/${model:?}.sh"
932 archive_file "$model_param_file"
933}
934
935set_model_path() {
936 set_run_env "model_path" "${1:?}"
937}
938
Zelalem1af7a7b2020-08-04 17:34:32 -0500939set_model_env() {
940 local var="${1:?}"
941 local val="${2?}"
942 local run_root="${archive:?}/run"
943
944 mkdir -p "$run_root"
945 echo "export $var=$val" >> "$run_root/model_env"
946}
Fathi Boudra422bf772019-12-02 11:10:16 +0200947set_run_env() {
948 local var="${1:?}"
949 local val="${2?}"
950 local run_root="${archive:?}/run"
951
952 mkdir -p "$run_root"
953 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
954}
955
956show_head() {
957 # Display HEAD descripton
958 pushd "$1"
959 git show --quiet --no-color | sed 's/^/ > /g'
960 echo
961 popd
962}
963
964# Choose debug binaries to run; by default, release binaries are chosen to run
965use_debug_bins() {
966 local run_root="${archive:?}/run"
967
968 echo "Choosing debug binaries for execution"
969 set_package_var "BIN_MODE" "debug"
970}
971
972assert_can_git_clone() {
973 local name="${1:?}"
974 local dir="${!name}"
975
976 # If it doesn't exist, it can be cloned into
977 if [ ! -e "$dir" ]; then
978 return 0
979 fi
980
981 # If it's a directory, it must be a Git clone already
982 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
983 # No need to clone again
984 echo "Using existing git clone for $name: $dir"
985 return 1
986 fi
987
988 die "Path $dir exists but is not a git clone"
989}
990
991clone_repo() {
992 if ! is_url "${clone_url?}"; then
993 # For --depth to take effect on local paths, it needs to use the
994 # file:// scheme.
995 clone_url="file://$clone_url"
996 fi
997
998 git clone -q --depth 1 "$clone_url" "${where?}"
999 if [ "$refspec" ]; then
1000 pushd "$where"
1001 git fetch -q --depth 1 origin "$refspec"
1002 git checkout -q FETCH_HEAD
1003 popd
1004 fi
1005}
1006
1007build_unstable() {
1008 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1009}
1010
1011undo_patch_record() {
1012 if [ ! -f "${patch_record:?}" ]; then
1013 return
1014 fi
1015
1016 # Undo patches in reverse
1017 echo
1018 for patch_name in $(tac "$patch_record"); do
1019 echo "Undoing $patch_name..."
1020 if ! git apply -R "$ci_root/patch/$patch_name"; then
1021 if upon "$local_ci"; then
1022 echo
1023 echo "Your local directory may have been dirtied."
1024 echo
1025 fi
1026 fail_build
1027 fi
1028 done
1029
1030 rm -f "$patch_record"
1031}
1032
1033undo_local_patches() {
1034 pushd "$tf_root"
1035 patch_record="$tf_patch_record" undo_patch_record
1036 popd
1037
1038 if [ -d "$tftf_root" ]; then
1039 pushd "$tftf_root"
1040 patch_record="$tftf_patch_record" undo_patch_record
1041 popd
1042 fi
1043}
1044
1045undo_tftf_patches() {
1046 pushd "$tftf_root"
1047 patch_record="$tftf_patch_record" undo_patch_record
1048 popd
1049}
1050
1051undo_tf_patches() {
1052 pushd "$tf_root"
1053 patch_record="$tf_patch_record" undo_patch_record
1054 popd
1055}
1056
1057apply_patch() {
1058 # If skip_patches is set, the developer has applied required patches
1059 # manually. They probably want to keep them applied for debugging
1060 # purposes too. This means we don't have to apply/revert them as part of
1061 # build process.
1062 if upon "$skip_patches"; then
1063 echo "Skipped applying ${1:?}..."
1064 return 0
1065 else
1066 echo "Applying ${1:?}..."
1067 fi
1068
Jimmy Brissonf134e4c2023-03-22 13:20:20 -05001069 if git apply --reverse --check < "$ci_root/patch/$1"; then
1070 echo "Skipping already applied ${1:?}"
1071 return 0
1072 fi
1073
Fathi Boudra422bf772019-12-02 11:10:16 +02001074 if git apply < "$ci_root/patch/$1"; then
1075 echo "$1" >> "${patch_record:?}"
1076 else
1077 if upon "$local_ci"; then
1078 undo_local_patches
1079 fi
1080 fail_build
1081 fi
1082}
1083
1084apply_tftf_patch() {
1085 pushd "$tftf_root"
1086 patch_record="$tftf_patch_record" apply_patch "$1"
1087 popd
1088}
1089
1090apply_tf_patch() {
1091 pushd "$tf_root"
1092 patch_record="$tf_patch_record" apply_patch "$1"
1093 popd
1094}
1095
1096# Clear workspace for a local run
1097if not_upon "$jenkins_run"; then
1098 rm -rf "$workspace"
1099
1100 # Clear residue from previous runs
1101 rm -rf "$archive"
1102fi
1103
1104mkdir -p "$workspace"
1105mkdir -p "$archive"
1106set_package_var "TEST_CONFIG" "$test_config"
1107
1108{
1109echo
1110echo "CONFIGURATION: $test_group/$test_config"
1111echo
1112} |& log_separator
1113
1114tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1115tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1116scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001117scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001118spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001119
1120test_config_file="$ci_root/group/$test_group/$test_config"
1121
1122tf_config_file="$ci_root/tf_config/$tf_config"
1123tftf_config_file="$ci_root/tftf_config/$tftf_config"
1124scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001125scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001126spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001127
1128# File that keeps track of applied patches
1129tf_patch_record="$workspace/tf_patches"
1130tftf_patch_record="$workspace/tftf_patches"
1131
1132pushd "$workspace"
1133
1134if ! config_valid "$tf_config"; then
1135 tf_config=
1136else
1137 echo "Trusted Firmware config:"
1138 echo
1139 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1140 echo
1141fi
1142
1143if ! config_valid "$tftf_config"; then
1144 tftf_config=
1145else
1146 echo "Trusted Firmware TF config:"
1147 echo
1148 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1149 echo
1150fi
1151
1152if ! config_valid "$scp_config"; then
1153 scp_config=
1154else
1155 echo "SCP firmware config:"
1156 echo
1157 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1158 echo
1159fi
1160
Zelalem219df412020-05-17 19:21:20 -05001161if ! config_valid "$scp_tools_config"; then
1162 scp_tools_config=
1163else
1164 echo "SCP Tools config:"
1165 echo
1166 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001167fi
1168
1169if ! config_valid "$spm_config"; then
1170 spm_config=
1171else
1172 echo "SPM config:"
1173 echo
1174 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001175 echo
1176fi
1177
Fathi Boudra422bf772019-12-02 11:10:16 +02001178if ! config_valid "$run_config"; then
1179 run_config=
1180fi
1181
1182if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1183 # If the Trusted Firmware repository has already been checked out, use
1184 # that location. Otherwise, clone one ourselves.
1185 echo "Cloning Trusted Firmware..."
1186 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1187 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1188 show_head "$tf_root"
1189fi
1190
1191if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1192 # If the Trusted Firmware TF repository has already been checked out,
1193 # use that location. Otherwise, clone one ourselves.
1194 echo "Cloning Trusted Firmware TF..."
1195 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1196 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1197 show_head "$tftf_root"
1198fi
1199
1200if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1201 # If the SCP firmware repository has already been checked out,
1202 # use that location. Otherwise, clone one ourselves.
1203 echo "Cloning SCP Firmware..."
1204 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1205 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1206
1207 pushd "$scp_root"
1208
1209 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001210 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001211 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1212 fi
1213
1214 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1215 # then to project filer if accessible.
1216 if [ -z "$cmsis_reference" ]; then
1217 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1218 if [ -d "$cmsis_ref_repo" ]; then
1219 cmsis_reference="--reference $cmsis_ref_repo"
1220 fi
1221 fi
1222
1223 git submodule -q update $cmsis_reference --init
1224
1225 popd
1226
1227 show_head "$scp_root"
1228fi
1229
Zelalem219df412020-05-17 19:21:20 -05001230if [ -n "$cc_config" ] ; then
1231 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1232 # Copy code coverage repository
1233 echo "Cloning Code Coverage..."
1234 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1235 show_head "$cc_root"
1236 fi
1237fi
1238
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001239if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1240 # If the SPM repository has already been checked out, use
1241 # that location. Otherwise, clone one ourselves.
1242 echo "Cloning SPM..."
1243 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1244 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1245
1246 # Query git submodules
1247 pushd "$spm_root"
1248 git submodule update --init
1249 popd
1250
1251 show_head "$spm_root"
1252fi
1253
Fathi Boudra422bf772019-12-02 11:10:16 +02001254if [ "$run_config" ]; then
1255 # Get candidates for run config
1256 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1257 "$run_config")"
1258 if [ -z "$run_config_candiates" ]; then
1259 die "No run config candidates!"
1260 else
1261 echo
1262 echo "Chosen fragments:"
1263 echo
1264 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1265 echo
1266 fi
1267fi
1268
1269call_hook "test_setup"
1270echo
1271
1272if upon "$local_ci"; then
1273 # For local runs, since each config is tried in sequence, it's
1274 # advantageous to run jobs in parallel
1275 if [ "$make_j" ]; then
1276 make_j_opts="-j $make_j"
1277 else
1278 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1279 if [ "$n_cores" ]; then
1280 make_j_opts="-j $n_cores"
1281 fi
1282 fi
1283fi
1284
Harrison Mutai07043e92023-07-06 09:41:12 +01001285# Install python build dependencies
1286if is_arm_jenkins_env; then
1287 source "$ci_root/script/install_python_deps.sh"
1288fi
1289
Fathi Boudra422bf772019-12-02 11:10:16 +02001290modes="${bin_mode:-debug release}"
1291for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001292 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001293 # Build with a temporary archive
1294 build_archive="$archive/$mode"
1295 mkdir "$build_archive"
1296
1297 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001298 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001299 DEBUG=1
1300 else
Zelalem219df412020-05-17 19:21:20 -05001301 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001302 DEBUG=0
1303 fi
1304
1305 # Perform builds in a subshell so as not to pollute the current and
1306 # subsequent builds' environment
1307
Zelalem219df412020-05-17 19:21:20 -05001308 if config_valid "$cc_config"; then
1309 # Build code coverage plugin
1310 build_cc
1311 fi
1312
Fathi Boudra422bf772019-12-02 11:10:16 +02001313 # SCP build
1314 if config_valid "$scp_config"; then
1315 (
1316 echo "##########"
1317
1318 # Source platform-specific utilities
1319 plat="$(get_scp_opt PRODUCT)"
1320 plat_utils="$ci_root/${plat}_utils.sh"
1321 if [ -f "$plat_utils" ]; then
1322 source "$plat_utils"
1323 fi
1324
1325 archive="$build_archive"
1326 scp_build_root="$scp_root/build"
1327
1328 echo "Building SCP Firmware ($mode) ..." |& log_separator
1329
1330 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001331 to="$archive" collect_scp_artefacts
1332
1333 echo "##########"
1334 echo
1335 )
1336 fi
1337
Zelalem219df412020-05-17 19:21:20 -05001338 # SCP-tools build
1339 if config_valid "$scp_tools_config"; then
1340 (
1341 echo "##########"
1342
1343 archive="$build_archive"
1344 scp_tools_build_root="$scp_tools_root/build"
1345
1346 clone_scp_tools
1347
1348 echo "##########"
1349 echo
1350
1351 echo "##########"
1352 clone_tf_for_scp_tools
1353 echo "##########"
1354 echo
1355 )
1356 fi
1357
Fathi Boudra422bf772019-12-02 11:10:16 +02001358 # TFTF build
1359 if config_valid "$tftf_config"; then
1360 (
1361 echo "##########"
1362
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001363 plat_utils="$(get_tf_opt PLAT_UTILS)"
1364 if [ -z ${plat_utils} ]; then
1365 # Source platform-specific utilities.
1366 plat="$(get_tftf_opt PLAT)"
1367 plat_utils="$ci_root/${plat}_utils.sh"
1368 else
1369 # Source platform-specific utilities by
1370 # using plat_utils name.
1371 plat_utils="$ci_root/${plat_utils}.sh"
1372 fi
1373
Fathi Boudra422bf772019-12-02 11:10:16 +02001374 if [ -f "$plat_utils" ]; then
1375 source "$plat_utils"
1376 fi
1377
1378 archive="$build_archive"
1379 tftf_build_root="$tftf_root/build"
1380
1381 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1382
1383 # Call pre-build hook
1384 call_hook pre_tftf_build
1385
1386 build_tftf
1387
1388 from="$tftf_build_root" to="$archive" collect_build_artefacts
1389
1390 # Clear any local changes made by applied patches
1391 undo_tftf_patches
1392
1393 echo "##########"
1394 echo
1395 )
1396 fi
1397
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001398 # SPM build
1399 if config_valid "$spm_config"; then
1400 (
1401 echo "##########"
1402
1403 # Get platform name from spm_config file
1404 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1405 plat_utils="$ci_root/${plat}_utils.sh"
1406 if [ -f "$plat_utils" ]; then
1407 source "$plat_utils"
1408 fi
1409
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001410 # Call pre-build hook
1411 call_hook pre_spm_build
1412
Manish Pandey1e7be852020-11-09 16:04:48 +00001413 # SPM build generates two sets of binaries, one for normal and other
1414 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001415 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001416 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1417 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001418
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001419 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001420 echo "Building SPM ($mode) ..." |& log_separator
1421
1422 # NOTE: mode has no effect on SPM build (for now), hence debug
1423 # mode is built but subsequent build using release mode just
1424 # goes through with "nothing to do".
1425 build_spm
1426
1427 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001428 cksum $spm_build_root/hafnium.bin
1429
1430 # Some platforms only have secure configuration enabled. Hence,
1431 # non secure hanfnium binary might not be built.
1432 if [ -f $hafnium_build_root/hafnium.bin ]; then
1433 cksum $hafnium_build_root/hafnium.bin
1434 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001435
Manish Pandey1e7be852020-11-09 16:04:48 +00001436 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001437
1438 echo "##########"
1439 echo
1440 )
1441 fi
1442
Fathi Boudra422bf772019-12-02 11:10:16 +02001443 # TF build
1444 if config_valid "$tf_config"; then
1445 (
1446 echo "##########"
1447
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001448 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001449 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1450
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001451 if [ -z ${plat_utils} ]; then
1452 # Source platform-specific utilities.
1453 plat="$(get_tf_opt PLAT)"
1454 plat_utils="$ci_root/${plat}_utils.sh"
1455 else
1456 # Source platform-specific utilities by
1457 # using plat_utils name.
1458 plat_utils="$ci_root/${plat_utils}.sh"
1459 fi
1460
Fathi Boudra422bf772019-12-02 11:10:16 +02001461 if [ -f "$plat_utils" ]; then
1462 source "$plat_utils"
1463 fi
1464
Harrison Mutai6361dbe2023-02-16 14:12:40 +00001465 poetry -C "$tf_root" install --without doc
Chris Kayd0837902021-11-17 10:17:52 +00001466
Fathi Boudra422bf772019-12-02 11:10:16 +02001467 archive="$build_archive"
1468 tf_build_root="$tf_root/build"
1469
1470 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1471
1472 # Call pre-build hook
1473 call_hook pre_tf_build
1474
1475 build_tf
1476
1477 # Call post-build hook
1478 call_hook post_tf_build
1479
1480 # Pre-archive hook
1481 call_hook pre_tf_archive
1482
1483 from="$tf_build_root" to="$archive" collect_build_artefacts
1484
1485 # Post-archive hook
1486 call_hook post_tf_archive
1487
1488 call_hook fetch_tf_resource
1489 call_hook post_fetch_tf_resource
1490
Chris Kay4e8aaf12022-09-01 15:21:55 +01001491 # Generate LAVA job files if necessary
1492 call_hook generate_lava_job_template
1493 call_hook generate_lava_job
1494
Fathi Boudra422bf772019-12-02 11:10:16 +02001495 # Clear any local changes made by applied patches
1496 undo_tf_patches
1497
1498 echo "##########"
1499 )
1500 fi
1501
1502 echo
1503 echo
1504done
1505
1506call_hook pre_package
1507
1508call_hook post_package
1509
1510if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001511 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001512fi
1513
1514echo
1515echo "Done"