blob: 7291f35c20f6dd1e960dc968a5649e3d17dd93a6 [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
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
Javier Almansa Sobrinof98dbd82020-09-30 19:29:27 +0100166 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 +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 Sokolovsky5f4b4042023-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 Sokolovsky5f4b4042023-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 Kay3a968862022-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
Govindraj Raja228091f2024-05-07 15:41:58 -0500334 if [ "$(get_tf_opt DEBUG)" = 0 ]; then
335 DEBUG=0
336 fi
337
Fathi Boudra422bf772019-12-02 11:10:16 +0200338 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
339 ${fip_targets:-fip} &>>"$build_log" || fail_build
340 )
341}
342
343fip_update() {
344 # Before the update process, check if the given image is supported by
345 # the fiptool. It's assumed that both fiptool and cert_create move in
346 # tandem, and therfore, if one has support, the other has it too.
347 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
348 return 1
349 fi
350
351 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
352 echo "Updating FIP image: $bin_name"
353 # Update HW config. Without TBBR, it's only a matter of using
354 # the update sub-command of fiptool
355 "$fiptool" update "--$bin_name" "${src:-}" \
356 "$archive/fip.bin"
357 else
358 echo "Updating FIP image (TBBR): $bin_name"
359 # With TBBR, we need to unpack, re-create certificates, and then
360 # recreate the FIP.
361 local fip_dir="$(mktempdir)"
362 local bin common_args stem
363 local rot_key="$(get_tf_opt ROT_KEY)"
364
365 rot_key="${rot_key:?}"
366 if ! is_abs "$rot_key"; then
367 rot_key="$tf_root/$rot_key"
368 fi
369
370 # Arguments only for cert_create
371 local cert_args="-n"
372 cert_args+=" --tfw-nvctr ${nvctr:-31}"
373 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
374 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
375 cert_args+=" --rot-key $rot_key"
376
377 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500378 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200379 "hw-config"
380 "tb-fw-config"
381 "nt-fw-config"
382 "soc-fw-config"
383 "tos-fw-config"
384 )
385
386 # Binaries without key certificates
387 declare -A has_no_key_cert
388 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
389 has_no_key_cert["$bin"]="1"
390 done
391
392 # Binaries without certificates
393 declare -A has_no_cert
394 for bin in "hw-config" "${dyn_config_opts[@]}"; do
395 has_no_cert["$bin"]="1"
396 done
397
398 pushd "$fip_dir"
399
400 # Unpack FIP
401 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
402
403 # Remove all existing certificates
404 rm -f *-cert.bin
405
406 # Copy the binary to be updated
407 cp -f "$src" "${bin_name}.bin"
408
409 # FIP unpack dumps binaries with the same name as the option
410 # used to pack it; likewise for certificates. Reverse-engineer
411 # the command line from the binary output.
412 common_args="--trusted-key-cert trusted_key.crt"
413 for bin in *.bin; do
414 stem="${bin%%.bin}"
415 common_args+=" --$stem $bin"
416 if not_upon "${has_no_cert[$stem]}"; then
417 common_args+=" --$stem-cert $stem.crt"
418 fi
419 if not_upon "${has_no_key_cert[$stem]}"; then
420 common_args+=" --$stem-key-cert $stem-key.crt"
421 fi
422 done
423
424 # Create certificates
425 "$cert_create" $cert_args $common_args &>>"$build_log"
426
427 # Recreate and archive FIP
428 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
429 archive_file "fip.bin"
430
431 popd
432 fi
433}
434
435# Update hw-config in FIP, and remove the original DTB afterwards.
436update_fip_hw_config() {
437 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600438 # in configs:
439 # 1. Where BL2 isn't present
440 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200441 case "1" in
442 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600443 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200444 "$(get_tf_opt RESET_TO_SP_MIN)" | \
445 "$(get_tf_opt BL2_AT_EL3)")
446 return 0;;
447 esac
448
449 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
450 # Remove the DTB so that model won't load it
451 rm -f "$archive/dtb.bin"
452 fi
453}
454
455get_scp_opt() {
456 (
457 name="${1:?}"
458 if config_valid "$scp_config_file"; then
459 source "$scp_config_file"
460 echo "${!name}"
461 fi
462 )
463}
464
465get_tftf_opt() {
466 (
467 name="${1:?}"
468 if config_valid "$tftf_config_file"; then
469 source "$tftf_config_file"
470 echo "${!name}"
471 fi
472 )
473}
474
475get_tf_opt() {
476 (
477 name="${1:?}"
478 if config_valid "$tf_config_file"; then
479 source "$tf_config_file"
480 echo "${!name}"
481 fi
482 )
483}
484
485build_tf() {
486 (
487 env_file="$workspace/tf.env"
488 config_file="${tf_build_config:-$tf_config_file}"
489
490 # Build fiptool and all targets by default
Manish V Badarkhe57bea362022-07-12 22:43:30 +0100491 build_targets="${tf_build_targets:-memmap fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200492
493 source "$config_file"
494
495 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000496 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100497 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
498 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200499 mbedtls_dir="$workspace/mbedtls"
500 if [ ! -d "$mbedtls_dir" ]; then
501 mbedtls_ar="$workspace/mbedtls.tar.gz"
502
503 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
504 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500505 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200506 fi
507
508 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
509 fi
510
511 if [ -f "$env_file" ]; then
512 set -a
513 source "$env_file"
514 set +a
515 fi
516
Harrison Mutai013f6332022-02-16 16:06:33 +0000517 if is_arm_jenkins_env || upon "$local_ci"; then
518 path_list=(
519 "$llvm_dir/bin"
520 )
521 extend_path "PATH" "path_list"
522 fi
523
Fathi Boudra422bf772019-12-02 11:10:16 +0200524 cd "$tf_root"
525
526 # Always distclean when running on Jenkins. Skip distclean when running
527 # locally and explicitly requested.
528 if upon "$jenkins_run" || not_upon "$dont_clean"; then
529 make distclean &>>"$build_log" || fail_build
530 fi
531
532 # Log build command line. It is left unfolded on purpose to assist
533 # copying to clipboard.
534 cat <<EOF | log_separator >/dev/null
535
536Build command line:
537 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
538
Paul Sokolovsky5815bcf2023-10-16 12:59:09 +0300539CC version:
540$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200541EOF
542
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000543 if not_upon "$local_ci"; then
544 connect_debugger=0
545 fi
546
Fathi Boudra422bf772019-12-02 11:10:16 +0200547 # Build TF. Since build output is being directed to the build log, have
548 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutaib76cecf2023-02-16 14:12:40 +0000549 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000550 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200551 $build_targets 3>&1 &>>"$build_log" || fail_build
552 )
553}
554
555build_tftf() {
556 (
557 config_file="${tftf_build_config:-$tftf_config_file}"
558
559 # Build tftf target by default
560 build_targets="${tftf_build_targets:-all}"
561
562 source "$config_file"
563
564 cd "$tftf_root"
565
566 # Always distclean when running on Jenkins. Skip distclean when running
567 # locally and explicitly requested.
568 if upon "$jenkins_run" || not_upon "$dont_clean"; then
569 make distclean &>>"$build_log" || fail_build
570 fi
571
572 # TFTF build system cannot reliably deal with -j option, so we avoid
573 # using that.
574
575 # Log build command line
576 cat <<EOF | log_separator >/dev/null
577
578Build command line:
579 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
580
581EOF
582
583 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
584 $build_targets &>>"$build_log" || fail_build
585 )
586}
587
588build_scp() {
589 (
590 config_file="${scp_build_config:-$scp_config_file}"
591
592 source "$config_file"
593
594 cd "$scp_root"
595
596 # Always distclean when running on Jenkins. Skip distclean when running
597 # locally and explicitly requested.
598 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli49f78672022-12-29 13:50:47 +0000599 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200600 fi
601
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000602 python3 -m venv .venv
603 . .venv/bin/activate
604
605 # Install extra tools used by CMake build system
606 pip install -r requirements.txt --timeout 30 --retries 15
607
Fathi Boudra422bf772019-12-02 11:10:16 +0200608 # Log build command line. It is left unfolded on purpose to assist
609 # copying to clipboard.
610 cat <<EOF | log_separator >/dev/null
611
612SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000613 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
614 TOOLCHAIN=GNU \
615 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000616 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000617 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200618
619EOF
620
621 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000622 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
623 TOOLCHAIN=GNU \
624 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000625 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000626 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200627 || fail_build
628 )
629}
630
Zelalem219df412020-05-17 19:21:20 -0500631clone_scp_tools() {
632
633 if [ ! -d "$scp_tools_root" ]; then
634 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
635
636 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
637 where="$scp_tools_root" \
638 refspec="${scp_tools_commit}"
639 clone_repo &>>"$build_log"
640 else
641 echo "Already cloned SCP-tools ..." |& log_separator
642 fi
643
644 show_head "$scp_tools_root"
645
646 cd "$scp_tools_root"
647
648 echo "Updating submodules"
649
650 git submodule init
651
652 git submodule update
653
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000654 lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'")
655
Zelalem219df412020-05-17 19:21:20 -0500656 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000657 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500658
659 git show --quiet --no-color | sed 's/^/ > /g'
660}
661
662clone_tf_for_scp_tools() {
663 scp_tools_arm_tf="$scp_tools_root/arm-tf"
664
665 if [ ! -d "$scp_tools_arm_tf" ]; then
666 echo "Cloning TF-4-SCP-tools ..." |& log_separator
667
668 clone_url="$tf_for_scp_tools_src_repo_url"
669 where="$scp_tools_arm_tf"
670
671 git clone "$clone_url" "$where"
672
673 cd "$scp_tools_arm_tf"
674
Joel Goddard3ad03062021-03-16 16:47:42 +0000675 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500676
677 git show --quiet --no-color | sed 's/^/ > /g'
678
679 else
680 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
681 fi
682}
683
684build_scmi_lib_scp_tools() {
685 (
686 cd "$scp_tools_root"
687
688 cd "scmi"
689
690 scp_tools_arm_tf="$scp_tools_root/arm-tf"
691
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600692 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500693
694 std_libs="-I$scp_tools_arm_tf/include/common"
695 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
696 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
697 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
698 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
699 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
700 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
701 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
702 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
703 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
704 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
705 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
706 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
707 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
708
709 cflags="-Og -g"
710 cflags="$cflags -mgeneral-regs-only"
711 cflags="$cflags -mstrict-align"
712 cflags="$cflags -nostdinc"
713 cflags="$cflags -fno-inline"
714 cflags="$cflags -ffreestanding"
715 cflags="$cflags -ffunction-sections"
716 cflags="$cflags -fdata-sections"
717 cflags="$cflags -DAARCH64"
718 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000719 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500720
721 cflags="$cflags $std_libs"
722
Joel Goddard3ad03062021-03-16 16:47:42 +0000723 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500724
725 echo "Building SCMI library (SCP-tools) ..."
726
727 make "CROSS_COMPILE=$cross_compile" \
728 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000729 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500730 "PROTOCOLS=$protocols" \
731 "clean" \
732 "all"
733 )
734}
735
736build_tf_for_scp_tools() {
737
738 cd "$scp_tools_root/arm-tf"
739
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600740 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500741
742 if [ "$1" = "release" ]; then
743 echo "Build TF-4-SCP-Tools rls..."
744 else
745 echo "Build TF-4-SCP-Tools dbg..."
746
747 make realclean
748
749 make "BM_TEST=scmi" \
750 "ARM_BOARD_OPTIMISE_MEM=1" \
751 "BM_CSS=juno" \
752 "CSS_USE_SCMI_SDS_DRIVER=1" \
753 "PLAT=juno" \
754 "DEBUG=1" \
755 "PLATFORM=juno" \
756 "CROSS_COMPILE=$cross_compile" \
757 "BM_WORKSPACE=$scp_tools_root/baremetal"
758
759 archive_file "build/juno/debug/bl1.bin"
760
761 archive_file "build/juno/debug/bl2.bin"
762
763 archive_file "build/juno/debug/bl31.bin"
764 fi
765}
766
767build_fip_for_scp_tools() {
768
769 cd "$scp_tools_root/arm-tf"
770
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600771 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500772
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000773 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500774 make fiptool
775 echo "Make FIP 4 SCP-Tools rls..."
776
777 else
778 make fiptool
779 echo "Make FIP 4 SCP-Tools dbg..."
780
781 make "PLAT=juno" \
782 "all" \
783 "fip" \
784 "DEBUG=1" \
785 "CROSS_COMPILE=$cross_compile" \
786 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
787 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000788 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500789
790 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
791 fi
792}
793
794build_cc() {
795# Building code coverage plugin
796 ARM_DIR=/arm
797 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
798 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
799 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
800 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
801 exit -1
802 fi # Error if arm warehouse not found
803 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
804
805 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
806}
807
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100808build_spm() {
809 (
810 env_file="$workspace/spm.env"
811 config_file="${spm_build_config:-$spm_config_file}"
812
813 source "$config_file"
814
815 if [ -f "$env_file" ]; then
816 set -a
817 source "$env_file"
818 set +a
819 fi
820
821 cd "$spm_root"
822
823 # Always clean when running on Jenkins. Skip clean when running
824 # locally and explicitly requested.
825 if upon "$jenkins_run" || not_upon "$dont_clean"; then
826 # make clean fails on a fresh repo where the project has not
827 # yet been built. Hence only clean if out/reference directory
828 # already exists.
829 if [ -d "out/reference" ]; then
830 make clean &>>"$build_log" || fail_build
831 fi
832 fi
833
834 # Log build command line. It is left unfolded on purpose to assist
835 # copying to clipboard.
836 cat <<EOF | log_separator >/dev/null
837
838Build command line:
839 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
840
841EOF
842
843 # Build SPM. Since build output is being directed to the build log, have
844 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200845 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
846
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100847 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
848 || fail_build
849 )
850}
Zelalem219df412020-05-17 19:21:20 -0500851
Fathi Boudra422bf772019-12-02 11:10:16 +0200852# Set metadata for the whole package so that it can be used by both Jenkins and
853# shell
854set_package_var() {
855 env_file="$artefacts/env" emit_env "$@"
856}
857
858set_tf_build_targets() {
859 echo "Set build target to '${targets:?}'"
860 set_hook_var "tf_build_targets" "$targets"
861}
862
863set_tftf_build_targets() {
864 echo "Set build target to '${targets:?}'"
865 set_hook_var "tftf_build_targets" "$targets"
866}
867
868set_scp_build_targets() {
869 echo "Set build target to '${targets:?}'"
870 set_hook_var "scp_build_targets" "$targets"
871}
872
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100873set_spm_build_targets() {
874 echo "Set build target to '${targets:?}'"
875 set_hook_var "spm_build_targets" "$targets"
876}
877
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000878set_spm_out_dir() {
879 echo "Set SPMC binary build to '${out_dir:?}'"
880 set_hook_var "spm_secure_out_dir" "$out_dir"
881}
Fathi Boudra422bf772019-12-02 11:10:16 +0200882# Look under $archive directory for known files such as blX images, kernel, DTB,
883# initrd etc. For each known file foo, if foo.bin exists, then set variable
884# foo_bin to the path of the file. Make the path relative to the workspace so as
885# to remove any @ characters, which Jenkins inserts for parallel runs. If the
886# file doesn't exist, unset its path.
887set_default_bin_paths() {
888 local image image_name image_path path
889 local archive="${archive:?}"
890 local set_vars
891 local var
892
893 pushd "$archive"
894
895 for file in *.bin; do
896 # Get a shell variable from the file's stem
897 var_name="${file%%.*}_bin"
898 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
899
900 # Skip setting the variable if it's already
901 if [ "${!var_name}" ]; then
902 echo "Note: not setting $var_name; already set to ${!var_name}"
903 continue
904 else
905 set_vars+="$var_name "
906 fi
907
908 eval "$var_name=$file"
909 done
910
911 echo "Binary paths set for: "
912 {
913 for var in $set_vars; do
914 echo -n "\$$var "
915 done
916 } | fmt -80 | sed 's/^/ /'
917 echo
918
919 popd
920}
921
922gen_model_params() {
923 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000924 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200925
926 set_default_bin_paths
927 echo "Generating model parameter for $model..."
928 source "$ci_root/model/${model:?}.sh"
929 archive_file "$model_param_file"
930}
931
932set_model_path() {
933 set_run_env "model_path" "${1:?}"
934}
935
Zelalem1af7a7b2020-08-04 17:34:32 -0500936set_model_env() {
937 local var="${1:?}"
938 local val="${2?}"
939 local run_root="${archive:?}/run"
940
941 mkdir -p "$run_root"
942 echo "export $var=$val" >> "$run_root/model_env"
943}
Fathi Boudra422bf772019-12-02 11:10:16 +0200944set_run_env() {
945 local var="${1:?}"
946 local val="${2?}"
947 local run_root="${archive:?}/run"
948
949 mkdir -p "$run_root"
950 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
951}
952
953show_head() {
954 # Display HEAD descripton
955 pushd "$1"
956 git show --quiet --no-color | sed 's/^/ > /g'
957 echo
958 popd
959}
960
961# Choose debug binaries to run; by default, release binaries are chosen to run
962use_debug_bins() {
963 local run_root="${archive:?}/run"
964
965 echo "Choosing debug binaries for execution"
966 set_package_var "BIN_MODE" "debug"
967}
968
969assert_can_git_clone() {
970 local name="${1:?}"
971 local dir="${!name}"
972
973 # If it doesn't exist, it can be cloned into
974 if [ ! -e "$dir" ]; then
975 return 0
976 fi
977
978 # If it's a directory, it must be a Git clone already
979 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
980 # No need to clone again
981 echo "Using existing git clone for $name: $dir"
982 return 1
983 fi
984
985 die "Path $dir exists but is not a git clone"
986}
987
988clone_repo() {
989 if ! is_url "${clone_url?}"; then
990 # For --depth to take effect on local paths, it needs to use the
991 # file:// scheme.
992 clone_url="file://$clone_url"
993 fi
994
995 git clone -q --depth 1 "$clone_url" "${where?}"
996 if [ "$refspec" ]; then
997 pushd "$where"
998 git fetch -q --depth 1 origin "$refspec"
999 git checkout -q FETCH_HEAD
1000 popd
1001 fi
1002}
1003
1004build_unstable() {
1005 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1006}
1007
1008undo_patch_record() {
1009 if [ ! -f "${patch_record:?}" ]; then
1010 return
1011 fi
1012
1013 # Undo patches in reverse
1014 echo
1015 for patch_name in $(tac "$patch_record"); do
1016 echo "Undoing $patch_name..."
1017 if ! git apply -R "$ci_root/patch/$patch_name"; then
1018 if upon "$local_ci"; then
1019 echo
1020 echo "Your local directory may have been dirtied."
1021 echo
1022 fi
1023 fail_build
1024 fi
1025 done
1026
1027 rm -f "$patch_record"
1028}
1029
1030undo_local_patches() {
1031 pushd "$tf_root"
1032 patch_record="$tf_patch_record" undo_patch_record
1033 popd
1034
1035 if [ -d "$tftf_root" ]; then
1036 pushd "$tftf_root"
1037 patch_record="$tftf_patch_record" undo_patch_record
1038 popd
1039 fi
1040}
1041
1042undo_tftf_patches() {
1043 pushd "$tftf_root"
1044 patch_record="$tftf_patch_record" undo_patch_record
1045 popd
1046}
1047
1048undo_tf_patches() {
1049 pushd "$tf_root"
1050 patch_record="$tf_patch_record" undo_patch_record
1051 popd
1052}
1053
1054apply_patch() {
1055 # If skip_patches is set, the developer has applied required patches
1056 # manually. They probably want to keep them applied for debugging
1057 # purposes too. This means we don't have to apply/revert them as part of
1058 # build process.
1059 if upon "$skip_patches"; then
1060 echo "Skipped applying ${1:?}..."
1061 return 0
1062 else
1063 echo "Applying ${1:?}..."
1064 fi
1065
1066 if git apply < "$ci_root/patch/$1"; then
1067 echo "$1" >> "${patch_record:?}"
1068 else
1069 if upon "$local_ci"; then
1070 undo_local_patches
1071 fi
1072 fail_build
1073 fi
1074}
1075
1076apply_tftf_patch() {
1077 pushd "$tftf_root"
1078 patch_record="$tftf_patch_record" apply_patch "$1"
1079 popd
1080}
1081
1082apply_tf_patch() {
1083 pushd "$tf_root"
1084 patch_record="$tf_patch_record" apply_patch "$1"
1085 popd
1086}
1087
1088# Clear workspace for a local run
1089if not_upon "$jenkins_run"; then
1090 rm -rf "$workspace"
1091
1092 # Clear residue from previous runs
1093 rm -rf "$archive"
1094fi
1095
1096mkdir -p "$workspace"
1097mkdir -p "$archive"
1098set_package_var "TEST_CONFIG" "$test_config"
1099
1100{
1101echo
1102echo "CONFIGURATION: $test_group/$test_config"
1103echo
1104} |& log_separator
1105
1106tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1107tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1108scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001109scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001110spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001111
1112test_config_file="$ci_root/group/$test_group/$test_config"
1113
1114tf_config_file="$ci_root/tf_config/$tf_config"
1115tftf_config_file="$ci_root/tftf_config/$tftf_config"
1116scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001117scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001118spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001119
1120# File that keeps track of applied patches
1121tf_patch_record="$workspace/tf_patches"
1122tftf_patch_record="$workspace/tftf_patches"
1123
1124pushd "$workspace"
1125
1126if ! config_valid "$tf_config"; then
1127 tf_config=
1128else
1129 echo "Trusted Firmware config:"
1130 echo
1131 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1132 echo
1133fi
1134
1135if ! config_valid "$tftf_config"; then
1136 tftf_config=
1137else
1138 echo "Trusted Firmware TF config:"
1139 echo
1140 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1141 echo
1142fi
1143
1144if ! config_valid "$scp_config"; then
1145 scp_config=
1146else
1147 echo "SCP firmware config:"
1148 echo
1149 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1150 echo
1151fi
1152
Zelalem219df412020-05-17 19:21:20 -05001153if ! config_valid "$scp_tools_config"; then
1154 scp_tools_config=
1155else
1156 echo "SCP Tools config:"
1157 echo
1158 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001159fi
1160
1161if ! config_valid "$spm_config"; then
1162 spm_config=
1163else
1164 echo "SPM config:"
1165 echo
1166 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001167 echo
1168fi
1169
Fathi Boudra422bf772019-12-02 11:10:16 +02001170if ! config_valid "$run_config"; then
1171 run_config=
1172fi
1173
1174if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1175 # If the Trusted Firmware repository has already been checked out, use
1176 # that location. Otherwise, clone one ourselves.
1177 echo "Cloning Trusted Firmware..."
1178 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1179 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1180 show_head "$tf_root"
1181fi
1182
1183if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1184 # If the Trusted Firmware TF repository has already been checked out,
1185 # use that location. Otherwise, clone one ourselves.
1186 echo "Cloning Trusted Firmware TF..."
1187 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1188 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1189 show_head "$tftf_root"
1190fi
1191
1192if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1193 # If the SCP firmware repository has already been checked out,
1194 # use that location. Otherwise, clone one ourselves.
1195 echo "Cloning SCP Firmware..."
1196 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1197 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1198
1199 pushd "$scp_root"
1200
1201 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001202 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001203 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1204 fi
1205
1206 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1207 # then to project filer if accessible.
1208 if [ -z "$cmsis_reference" ]; then
1209 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1210 if [ -d "$cmsis_ref_repo" ]; then
1211 cmsis_reference="--reference $cmsis_ref_repo"
1212 fi
1213 fi
1214
1215 git submodule -q update $cmsis_reference --init
1216
1217 popd
1218
1219 show_head "$scp_root"
1220fi
1221
Zelalem219df412020-05-17 19:21:20 -05001222if [ -n "$cc_config" ] ; then
1223 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1224 # Copy code coverage repository
1225 echo "Cloning Code Coverage..."
1226 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1227 show_head "$cc_root"
1228 fi
1229fi
1230
Daniel Boulby71d8e8a2023-12-14 14:36:25 +00001231if [ "$spm_config" ] ; then
1232 if assert_can_git_clone "spm_root"; then
1233 # If the SPM repository has already been checked out, use
1234 # that location. Otherwise, clone one ourselves.
1235 echo "Cloning SPM..."
1236 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \
1237 where="$spm_root" refspec="$SPM_REFSPEC" \
1238 clone_repo &>>"$build_log"
1239 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001240
1241 # Query git submodules
1242 pushd "$spm_root"
Daniel Boulby71d8e8a2023-12-14 14:36:25 +00001243 # Check if submodules need initialising
1244 if git submodule status | grep '^-'; then
1245 git submodule update --init
1246 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001247 popd
1248
1249 show_head "$spm_root"
1250fi
1251
Fathi Boudra422bf772019-12-02 11:10:16 +02001252if [ "$run_config" ]; then
1253 # Get candidates for run config
1254 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1255 "$run_config")"
1256 if [ -z "$run_config_candiates" ]; then
1257 die "No run config candidates!"
1258 else
1259 echo
1260 echo "Chosen fragments:"
1261 echo
1262 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1263 echo
1264 fi
1265fi
1266
1267call_hook "test_setup"
1268echo
1269
1270if upon "$local_ci"; then
1271 # For local runs, since each config is tried in sequence, it's
1272 # advantageous to run jobs in parallel
1273 if [ "$make_j" ]; then
1274 make_j_opts="-j $make_j"
1275 else
1276 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1277 if [ "$n_cores" ]; then
1278 make_j_opts="-j $n_cores"
1279 fi
1280 fi
1281fi
1282
1283modes="${bin_mode:-debug release}"
1284for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001285 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001286 # Build with a temporary archive
1287 build_archive="$archive/$mode"
1288 mkdir "$build_archive"
1289
1290 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001291 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001292 DEBUG=1
1293 else
Zelalem219df412020-05-17 19:21:20 -05001294 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001295 DEBUG=0
1296 fi
1297
1298 # Perform builds in a subshell so as not to pollute the current and
1299 # subsequent builds' environment
1300
Zelalem219df412020-05-17 19:21:20 -05001301 if config_valid "$cc_config"; then
1302 # Build code coverage plugin
1303 build_cc
1304 fi
1305
Fathi Boudra422bf772019-12-02 11:10:16 +02001306 # SCP build
1307 if config_valid "$scp_config"; then
1308 (
1309 echo "##########"
1310
1311 # Source platform-specific utilities
1312 plat="$(get_scp_opt PRODUCT)"
1313 plat_utils="$ci_root/${plat}_utils.sh"
1314 if [ -f "$plat_utils" ]; then
1315 source "$plat_utils"
1316 fi
1317
1318 archive="$build_archive"
1319 scp_build_root="$scp_root/build"
1320
1321 echo "Building SCP Firmware ($mode) ..." |& log_separator
1322
1323 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001324 to="$archive" collect_scp_artefacts
1325
1326 echo "##########"
1327 echo
1328 )
1329 fi
1330
Zelalem219df412020-05-17 19:21:20 -05001331 # SCP-tools build
1332 if config_valid "$scp_tools_config"; then
1333 (
1334 echo "##########"
1335
1336 archive="$build_archive"
1337 scp_tools_build_root="$scp_tools_root/build"
1338
1339 clone_scp_tools
1340
1341 echo "##########"
1342 echo
1343
1344 echo "##########"
1345 clone_tf_for_scp_tools
1346 echo "##########"
1347 echo
1348 )
1349 fi
1350
Fathi Boudra422bf772019-12-02 11:10:16 +02001351 # TFTF build
1352 if config_valid "$tftf_config"; then
1353 (
1354 echo "##########"
1355
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001356 plat_utils="$(get_tf_opt PLAT_UTILS)"
1357 if [ -z ${plat_utils} ]; then
1358 # Source platform-specific utilities.
1359 plat="$(get_tftf_opt PLAT)"
1360 plat_utils="$ci_root/${plat}_utils.sh"
1361 else
1362 # Source platform-specific utilities by
1363 # using plat_utils name.
1364 plat_utils="$ci_root/${plat_utils}.sh"
1365 fi
1366
Fathi Boudra422bf772019-12-02 11:10:16 +02001367 if [ -f "$plat_utils" ]; then
1368 source "$plat_utils"
1369 fi
1370
1371 archive="$build_archive"
1372 tftf_build_root="$tftf_root/build"
1373
1374 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1375
1376 # Call pre-build hook
1377 call_hook pre_tftf_build
1378
1379 build_tftf
1380
1381 from="$tftf_build_root" to="$archive" collect_build_artefacts
1382
1383 # Clear any local changes made by applied patches
1384 undo_tftf_patches
1385
1386 echo "##########"
1387 echo
1388 )
1389 fi
1390
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001391 # SPM build
1392 if config_valid "$spm_config"; then
1393 (
1394 echo "##########"
1395
1396 # Get platform name from spm_config file
1397 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1398 plat_utils="$ci_root/${plat}_utils.sh"
1399 if [ -f "$plat_utils" ]; then
1400 source "$plat_utils"
1401 fi
1402
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001403 # Call pre-build hook
1404 call_hook pre_spm_build
1405
Manish Pandey1e7be852020-11-09 16:04:48 +00001406 # SPM build generates two sets of binaries, one for normal and other
1407 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001408 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001409 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1410 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001411
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001412 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001413 echo "Building SPM ($mode) ..." |& log_separator
1414
1415 # NOTE: mode has no effect on SPM build (for now), hence debug
1416 # mode is built but subsequent build using release mode just
1417 # goes through with "nothing to do".
1418 build_spm
1419
1420 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001421 cksum $spm_build_root/hafnium.bin
1422
1423 # Some platforms only have secure configuration enabled. Hence,
1424 # non secure hanfnium binary might not be built.
1425 if [ -f $hafnium_build_root/hafnium.bin ]; then
1426 cksum $hafnium_build_root/hafnium.bin
1427 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001428
Manish Pandey1e7be852020-11-09 16:04:48 +00001429 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001430
1431 echo "##########"
1432 echo
1433 )
1434 fi
1435
Fathi Boudra422bf772019-12-02 11:10:16 +02001436 # TF build
1437 if config_valid "$tf_config"; then
1438 (
1439 echo "##########"
1440
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001441 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001442 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1443
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001444 if [ -z ${plat_utils} ]; then
1445 # Source platform-specific utilities.
1446 plat="$(get_tf_opt PLAT)"
1447 plat_utils="$ci_root/${plat}_utils.sh"
1448 else
1449 # Source platform-specific utilities by
1450 # using plat_utils name.
1451 plat_utils="$ci_root/${plat_utils}.sh"
1452 fi
1453
Fathi Boudra422bf772019-12-02 11:10:16 +02001454 if [ -f "$plat_utils" ]; then
1455 source "$plat_utils"
1456 fi
1457
Harrison Mutaib76cecf2023-02-16 14:12:40 +00001458 # Install python build dependencies
1459 if is_arm_jenkins_env; then
1460 source "$ci_root/script/install_python_deps_tf.sh"
1461 fi
1462
1463 poetry -C "$tf_root" install --without doc
Chris Kayd0837902021-11-17 10:17:52 +00001464
Chris Kay48c50de2023-08-04 11:50:31 +00001465 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1466 fvp_tsram_size="${fvp_tsram_size:-256}"
1467
Fathi Boudra422bf772019-12-02 11:10:16 +02001468 archive="$build_archive"
1469 tf_build_root="$tf_root/build"
1470
1471 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1472
1473 # Call pre-build hook
1474 call_hook pre_tf_build
1475
1476 build_tf
1477
1478 # Call post-build hook
1479 call_hook post_tf_build
1480
1481 # Pre-archive hook
1482 call_hook pre_tf_archive
1483
1484 from="$tf_build_root" to="$archive" collect_build_artefacts
1485
1486 # Post-archive hook
1487 call_hook post_tf_archive
1488
1489 call_hook fetch_tf_resource
1490 call_hook post_fetch_tf_resource
1491
Chris Kay4e8aaf12022-09-01 15:21:55 +01001492 # Generate LAVA job files if necessary
1493 call_hook generate_lava_job_template
1494 call_hook generate_lava_job
1495
Fathi Boudra422bf772019-12-02 11:10:16 +02001496 # Clear any local changes made by applied patches
1497 undo_tf_patches
1498
1499 echo "##########"
1500 )
1501 fi
1502
1503 echo
1504 echo
1505done
1506
1507call_hook pre_package
1508
1509call_hook post_package
1510
1511if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001512 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001513fi
1514
1515echo
1516echo "Done"