blob: 12eddae37ac862a3c8f3183d92fb0decac197e92 [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
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)" | \
441 "$(get_tf_opt BL2_AT_EL3)")
442 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
Manish V Badarkhe57bea362022-07-12 22:43:30 +0100487 build_targets="${tf_build_targets:-memmap 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
506
507 if [ -f "$env_file" ]; then
508 set -a
509 source "$env_file"
510 set +a
511 fi
512
Harrison Mutai013f6332022-02-16 16:06:33 +0000513 if is_arm_jenkins_env || upon "$local_ci"; then
514 path_list=(
515 "$llvm_dir/bin"
516 )
517 extend_path "PATH" "path_list"
518 fi
519
Fathi Boudra422bf772019-12-02 11:10:16 +0200520 cd "$tf_root"
521
522 # Always distclean when running on Jenkins. Skip distclean when running
523 # locally and explicitly requested.
524 if upon "$jenkins_run" || not_upon "$dont_clean"; then
525 make distclean &>>"$build_log" || fail_build
526 fi
527
528 # Log build command line. It is left unfolded on purpose to assist
529 # copying to clipboard.
530 cat <<EOF | log_separator >/dev/null
531
532Build command line:
533 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
534
Paul Sokolovsky5815bcf2023-10-16 12:59:09 +0300535CC version:
536$(${CC-${CROSS_COMPILE}gcc} -v 2>&1)
Fathi Boudra422bf772019-12-02 11:10:16 +0200537EOF
538
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000539 if not_upon "$local_ci"; then
540 connect_debugger=0
541 fi
542
Fathi Boudra422bf772019-12-02 11:10:16 +0200543 # Build TF. Since build output is being directed to the build log, have
544 # descriptor 3 point to the current terminal for build wrappers to vent.
Harrison Mutaib76cecf2023-02-16 14:12:40 +0000545 $tf_build_wrapper poetry run make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000546 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200547 $build_targets 3>&1 &>>"$build_log" || fail_build
548 )
549}
550
551build_tftf() {
552 (
553 config_file="${tftf_build_config:-$tftf_config_file}"
554
555 # Build tftf target by default
556 build_targets="${tftf_build_targets:-all}"
557
558 source "$config_file"
559
560 cd "$tftf_root"
561
562 # Always distclean when running on Jenkins. Skip distclean when running
563 # locally and explicitly requested.
564 if upon "$jenkins_run" || not_upon "$dont_clean"; then
565 make distclean &>>"$build_log" || fail_build
566 fi
567
568 # TFTF build system cannot reliably deal with -j option, so we avoid
569 # using that.
570
571 # Log build command line
572 cat <<EOF | log_separator >/dev/null
573
574Build command line:
575 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
576
577EOF
578
579 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
580 $build_targets &>>"$build_log" || fail_build
581 )
582}
583
584build_scp() {
585 (
586 config_file="${scp_build_config:-$scp_config_file}"
587
588 source "$config_file"
589
590 cd "$scp_root"
591
592 # Always distclean when running on Jenkins. Skip distclean when running
593 # locally and explicitly requested.
594 if upon "$jenkins_run" || not_upon "$dont_clean"; then
Leandro Belli49f78672022-12-29 13:50:47 +0000595 make -f Makefile.cmake clean &>>"$build_log" || fail_build
Fathi Boudra422bf772019-12-02 11:10:16 +0200596 fi
597
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000598 python3 -m venv .venv
599 . .venv/bin/activate
600
601 # Install extra tools used by CMake build system
602 pip install -r requirements.txt --timeout 30 --retries 15
603
Fathi Boudra422bf772019-12-02 11:10:16 +0200604 # Log build command line. It is left unfolded on purpose to assist
605 # copying to clipboard.
606 cat <<EOF | log_separator >/dev/null
607
608SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000609 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
610 TOOLCHAIN=GNU \
611 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000612 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000613 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200614
615EOF
616
617 # Build SCP
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000618 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
619 TOOLCHAIN=GNU \
620 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000621 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000622 V=1 &>>"$build_log" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200623 || fail_build
624 )
625}
626
Zelalem219df412020-05-17 19:21:20 -0500627clone_scp_tools() {
628
629 if [ ! -d "$scp_tools_root" ]; then
630 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
631
632 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
633 where="$scp_tools_root" \
634 refspec="${scp_tools_commit}"
635 clone_repo &>>"$build_log"
636 else
637 echo "Already cloned SCP-tools ..." |& log_separator
638 fi
639
640 show_head "$scp_tools_root"
641
642 cd "$scp_tools_root"
643
644 echo "Updating submodules"
645
646 git submodule init
647
648 git submodule update
649
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000650 lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'")
651
Zelalem219df412020-05-17 19:21:20 -0500652 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000653 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500654
655 git show --quiet --no-color | sed 's/^/ > /g'
656}
657
658clone_tf_for_scp_tools() {
659 scp_tools_arm_tf="$scp_tools_root/arm-tf"
660
661 if [ ! -d "$scp_tools_arm_tf" ]; then
662 echo "Cloning TF-4-SCP-tools ..." |& log_separator
663
664 clone_url="$tf_for_scp_tools_src_repo_url"
665 where="$scp_tools_arm_tf"
666
667 git clone "$clone_url" "$where"
668
669 cd "$scp_tools_arm_tf"
670
Joel Goddard3ad03062021-03-16 16:47:42 +0000671 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500672
673 git show --quiet --no-color | sed 's/^/ > /g'
674
675 else
676 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
677 fi
678}
679
680build_scmi_lib_scp_tools() {
681 (
682 cd "$scp_tools_root"
683
684 cd "scmi"
685
686 scp_tools_arm_tf="$scp_tools_root/arm-tf"
687
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600688 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500689
690 std_libs="-I$scp_tools_arm_tf/include/common"
691 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
692 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
693 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
694 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
695 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
696 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
697 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
698 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
699 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
700 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
701 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
702 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
703 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
704
705 cflags="-Og -g"
706 cflags="$cflags -mgeneral-regs-only"
707 cflags="$cflags -mstrict-align"
708 cflags="$cflags -nostdinc"
709 cflags="$cflags -fno-inline"
710 cflags="$cflags -ffreestanding"
711 cflags="$cflags -ffunction-sections"
712 cflags="$cflags -fdata-sections"
713 cflags="$cflags -DAARCH64"
714 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000715 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500716
717 cflags="$cflags $std_libs"
718
Joel Goddard3ad03062021-03-16 16:47:42 +0000719 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500720
721 echo "Building SCMI library (SCP-tools) ..."
722
723 make "CROSS_COMPILE=$cross_compile" \
724 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000725 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500726 "PROTOCOLS=$protocols" \
727 "clean" \
728 "all"
729 )
730}
731
732build_tf_for_scp_tools() {
733
734 cd "$scp_tools_root/arm-tf"
735
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600736 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500737
738 if [ "$1" = "release" ]; then
739 echo "Build TF-4-SCP-Tools rls..."
740 else
741 echo "Build TF-4-SCP-Tools dbg..."
742
743 make realclean
744
745 make "BM_TEST=scmi" \
746 "ARM_BOARD_OPTIMISE_MEM=1" \
747 "BM_CSS=juno" \
748 "CSS_USE_SCMI_SDS_DRIVER=1" \
749 "PLAT=juno" \
750 "DEBUG=1" \
751 "PLATFORM=juno" \
752 "CROSS_COMPILE=$cross_compile" \
753 "BM_WORKSPACE=$scp_tools_root/baremetal"
754
755 archive_file "build/juno/debug/bl1.bin"
756
757 archive_file "build/juno/debug/bl2.bin"
758
759 archive_file "build/juno/debug/bl31.bin"
760 fi
761}
762
763build_fip_for_scp_tools() {
764
765 cd "$scp_tools_root/arm-tf"
766
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600767 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500768
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000769 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500770 make fiptool
771 echo "Make FIP 4 SCP-Tools rls..."
772
773 else
774 make fiptool
775 echo "Make FIP 4 SCP-Tools dbg..."
776
777 make "PLAT=juno" \
778 "all" \
779 "fip" \
780 "DEBUG=1" \
781 "CROSS_COMPILE=$cross_compile" \
782 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
783 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000784 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500785
786 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
787 fi
788}
789
790build_cc() {
791# Building code coverage plugin
792 ARM_DIR=/arm
793 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
794 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
795 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
796 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
797 exit -1
798 fi # Error if arm warehouse not found
799 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
800
801 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
802}
803
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100804build_spm() {
805 (
806 env_file="$workspace/spm.env"
807 config_file="${spm_build_config:-$spm_config_file}"
808
809 source "$config_file"
810
811 if [ -f "$env_file" ]; then
812 set -a
813 source "$env_file"
814 set +a
815 fi
816
817 cd "$spm_root"
818
819 # Always clean when running on Jenkins. Skip clean when running
820 # locally and explicitly requested.
821 if upon "$jenkins_run" || not_upon "$dont_clean"; then
822 # make clean fails on a fresh repo where the project has not
823 # yet been built. Hence only clean if out/reference directory
824 # already exists.
825 if [ -d "out/reference" ]; then
826 make clean &>>"$build_log" || fail_build
827 fi
828 fi
829
830 # Log build command line. It is left unfolded on purpose to assist
831 # copying to clipboard.
832 cat <<EOF | log_separator >/dev/null
833
834Build command line:
835 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
836
837EOF
838
839 # Build SPM. Since build output is being directed to the build log, have
840 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200841 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
842
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100843 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
844 || fail_build
845 )
846}
Zelalem219df412020-05-17 19:21:20 -0500847
Fathi Boudra422bf772019-12-02 11:10:16 +0200848# Set metadata for the whole package so that it can be used by both Jenkins and
849# shell
850set_package_var() {
851 env_file="$artefacts/env" emit_env "$@"
852}
853
854set_tf_build_targets() {
855 echo "Set build target to '${targets:?}'"
856 set_hook_var "tf_build_targets" "$targets"
857}
858
859set_tftf_build_targets() {
860 echo "Set build target to '${targets:?}'"
861 set_hook_var "tftf_build_targets" "$targets"
862}
863
864set_scp_build_targets() {
865 echo "Set build target to '${targets:?}'"
866 set_hook_var "scp_build_targets" "$targets"
867}
868
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100869set_spm_build_targets() {
870 echo "Set build target to '${targets:?}'"
871 set_hook_var "spm_build_targets" "$targets"
872}
873
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000874set_spm_out_dir() {
875 echo "Set SPMC binary build to '${out_dir:?}'"
876 set_hook_var "spm_secure_out_dir" "$out_dir"
877}
Fathi Boudra422bf772019-12-02 11:10:16 +0200878# Look under $archive directory for known files such as blX images, kernel, DTB,
879# initrd etc. For each known file foo, if foo.bin exists, then set variable
880# foo_bin to the path of the file. Make the path relative to the workspace so as
881# to remove any @ characters, which Jenkins inserts for parallel runs. If the
882# file doesn't exist, unset its path.
883set_default_bin_paths() {
884 local image image_name image_path path
885 local archive="${archive:?}"
886 local set_vars
887 local var
888
889 pushd "$archive"
890
891 for file in *.bin; do
892 # Get a shell variable from the file's stem
893 var_name="${file%%.*}_bin"
894 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
895
896 # Skip setting the variable if it's already
897 if [ "${!var_name}" ]; then
898 echo "Note: not setting $var_name; already set to ${!var_name}"
899 continue
900 else
901 set_vars+="$var_name "
902 fi
903
904 eval "$var_name=$file"
905 done
906
907 echo "Binary paths set for: "
908 {
909 for var in $set_vars; do
910 echo -n "\$$var "
911 done
912 } | fmt -80 | sed 's/^/ /'
913 echo
914
915 popd
916}
917
918gen_model_params() {
919 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000920 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200921
922 set_default_bin_paths
923 echo "Generating model parameter for $model..."
924 source "$ci_root/model/${model:?}.sh"
925 archive_file "$model_param_file"
926}
927
928set_model_path() {
929 set_run_env "model_path" "${1:?}"
930}
931
Zelalem1af7a7b2020-08-04 17:34:32 -0500932set_model_env() {
933 local var="${1:?}"
934 local val="${2?}"
935 local run_root="${archive:?}/run"
936
937 mkdir -p "$run_root"
938 echo "export $var=$val" >> "$run_root/model_env"
939}
Fathi Boudra422bf772019-12-02 11:10:16 +0200940set_run_env() {
941 local var="${1:?}"
942 local val="${2?}"
943 local run_root="${archive:?}/run"
944
945 mkdir -p "$run_root"
946 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
947}
948
949show_head() {
950 # Display HEAD descripton
951 pushd "$1"
952 git show --quiet --no-color | sed 's/^/ > /g'
953 echo
954 popd
955}
956
957# Choose debug binaries to run; by default, release binaries are chosen to run
958use_debug_bins() {
959 local run_root="${archive:?}/run"
960
961 echo "Choosing debug binaries for execution"
962 set_package_var "BIN_MODE" "debug"
963}
964
965assert_can_git_clone() {
966 local name="${1:?}"
967 local dir="${!name}"
968
969 # If it doesn't exist, it can be cloned into
970 if [ ! -e "$dir" ]; then
971 return 0
972 fi
973
974 # If it's a directory, it must be a Git clone already
975 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
976 # No need to clone again
977 echo "Using existing git clone for $name: $dir"
978 return 1
979 fi
980
981 die "Path $dir exists but is not a git clone"
982}
983
984clone_repo() {
985 if ! is_url "${clone_url?}"; then
986 # For --depth to take effect on local paths, it needs to use the
987 # file:// scheme.
988 clone_url="file://$clone_url"
989 fi
990
991 git clone -q --depth 1 "$clone_url" "${where?}"
992 if [ "$refspec" ]; then
993 pushd "$where"
994 git fetch -q --depth 1 origin "$refspec"
995 git checkout -q FETCH_HEAD
996 popd
997 fi
998}
999
1000build_unstable() {
1001 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
1002}
1003
1004undo_patch_record() {
1005 if [ ! -f "${patch_record:?}" ]; then
1006 return
1007 fi
1008
1009 # Undo patches in reverse
1010 echo
1011 for patch_name in $(tac "$patch_record"); do
1012 echo "Undoing $patch_name..."
1013 if ! git apply -R "$ci_root/patch/$patch_name"; then
1014 if upon "$local_ci"; then
1015 echo
1016 echo "Your local directory may have been dirtied."
1017 echo
1018 fi
1019 fail_build
1020 fi
1021 done
1022
1023 rm -f "$patch_record"
1024}
1025
1026undo_local_patches() {
1027 pushd "$tf_root"
1028 patch_record="$tf_patch_record" undo_patch_record
1029 popd
1030
1031 if [ -d "$tftf_root" ]; then
1032 pushd "$tftf_root"
1033 patch_record="$tftf_patch_record" undo_patch_record
1034 popd
1035 fi
1036}
1037
1038undo_tftf_patches() {
1039 pushd "$tftf_root"
1040 patch_record="$tftf_patch_record" undo_patch_record
1041 popd
1042}
1043
1044undo_tf_patches() {
1045 pushd "$tf_root"
1046 patch_record="$tf_patch_record" undo_patch_record
1047 popd
1048}
1049
1050apply_patch() {
1051 # If skip_patches is set, the developer has applied required patches
1052 # manually. They probably want to keep them applied for debugging
1053 # purposes too. This means we don't have to apply/revert them as part of
1054 # build process.
1055 if upon "$skip_patches"; then
1056 echo "Skipped applying ${1:?}..."
1057 return 0
1058 else
1059 echo "Applying ${1:?}..."
1060 fi
1061
1062 if git apply < "$ci_root/patch/$1"; then
1063 echo "$1" >> "${patch_record:?}"
1064 else
1065 if upon "$local_ci"; then
1066 undo_local_patches
1067 fi
1068 fail_build
1069 fi
1070}
1071
1072apply_tftf_patch() {
1073 pushd "$tftf_root"
1074 patch_record="$tftf_patch_record" apply_patch "$1"
1075 popd
1076}
1077
1078apply_tf_patch() {
1079 pushd "$tf_root"
1080 patch_record="$tf_patch_record" apply_patch "$1"
1081 popd
1082}
1083
1084# Clear workspace for a local run
1085if not_upon "$jenkins_run"; then
1086 rm -rf "$workspace"
1087
1088 # Clear residue from previous runs
1089 rm -rf "$archive"
1090fi
1091
1092mkdir -p "$workspace"
1093mkdir -p "$archive"
1094set_package_var "TEST_CONFIG" "$test_config"
1095
1096{
1097echo
1098echo "CONFIGURATION: $test_group/$test_config"
1099echo
1100} |& log_separator
1101
1102tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1103tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1104scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001105scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001106spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001107
1108test_config_file="$ci_root/group/$test_group/$test_config"
1109
1110tf_config_file="$ci_root/tf_config/$tf_config"
1111tftf_config_file="$ci_root/tftf_config/$tftf_config"
1112scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001113scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001114spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001115
1116# File that keeps track of applied patches
1117tf_patch_record="$workspace/tf_patches"
1118tftf_patch_record="$workspace/tftf_patches"
1119
1120pushd "$workspace"
1121
1122if ! config_valid "$tf_config"; then
1123 tf_config=
1124else
1125 echo "Trusted Firmware config:"
1126 echo
1127 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1128 echo
1129fi
1130
1131if ! config_valid "$tftf_config"; then
1132 tftf_config=
1133else
1134 echo "Trusted Firmware TF config:"
1135 echo
1136 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1137 echo
1138fi
1139
1140if ! config_valid "$scp_config"; then
1141 scp_config=
1142else
1143 echo "SCP firmware config:"
1144 echo
1145 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1146 echo
1147fi
1148
Zelalem219df412020-05-17 19:21:20 -05001149if ! config_valid "$scp_tools_config"; then
1150 scp_tools_config=
1151else
1152 echo "SCP Tools config:"
1153 echo
1154 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001155fi
1156
1157if ! config_valid "$spm_config"; then
1158 spm_config=
1159else
1160 echo "SPM config:"
1161 echo
1162 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001163 echo
1164fi
1165
Fathi Boudra422bf772019-12-02 11:10:16 +02001166if ! config_valid "$run_config"; then
1167 run_config=
1168fi
1169
1170if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1171 # If the Trusted Firmware repository has already been checked out, use
1172 # that location. Otherwise, clone one ourselves.
1173 echo "Cloning Trusted Firmware..."
1174 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1175 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1176 show_head "$tf_root"
1177fi
1178
1179if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1180 # If the Trusted Firmware TF repository has already been checked out,
1181 # use that location. Otherwise, clone one ourselves.
1182 echo "Cloning Trusted Firmware TF..."
1183 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1184 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1185 show_head "$tftf_root"
1186fi
1187
1188if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1189 # If the SCP firmware repository has already been checked out,
1190 # use that location. Otherwise, clone one ourselves.
1191 echo "Cloning SCP Firmware..."
1192 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1193 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1194
1195 pushd "$scp_root"
1196
1197 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001198 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001199 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1200 fi
1201
1202 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1203 # then to project filer if accessible.
1204 if [ -z "$cmsis_reference" ]; then
1205 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1206 if [ -d "$cmsis_ref_repo" ]; then
1207 cmsis_reference="--reference $cmsis_ref_repo"
1208 fi
1209 fi
1210
1211 git submodule -q update $cmsis_reference --init
1212
1213 popd
1214
1215 show_head "$scp_root"
1216fi
1217
Zelalem219df412020-05-17 19:21:20 -05001218if [ -n "$cc_config" ] ; then
1219 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1220 # Copy code coverage repository
1221 echo "Cloning Code Coverage..."
1222 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1223 show_head "$cc_root"
1224 fi
1225fi
1226
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001227if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1228 # If the SPM repository has already been checked out, use
1229 # that location. Otherwise, clone one ourselves.
1230 echo "Cloning SPM..."
1231 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1232 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1233
1234 # Query git submodules
1235 pushd "$spm_root"
1236 git submodule update --init
1237 popd
1238
1239 show_head "$spm_root"
1240fi
1241
Fathi Boudra422bf772019-12-02 11:10:16 +02001242if [ "$run_config" ]; then
1243 # Get candidates for run config
1244 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1245 "$run_config")"
1246 if [ -z "$run_config_candiates" ]; then
1247 die "No run config candidates!"
1248 else
1249 echo
1250 echo "Chosen fragments:"
1251 echo
1252 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1253 echo
1254 fi
1255fi
1256
1257call_hook "test_setup"
1258echo
1259
1260if upon "$local_ci"; then
1261 # For local runs, since each config is tried in sequence, it's
1262 # advantageous to run jobs in parallel
1263 if [ "$make_j" ]; then
1264 make_j_opts="-j $make_j"
1265 else
1266 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1267 if [ "$n_cores" ]; then
1268 make_j_opts="-j $n_cores"
1269 fi
1270 fi
1271fi
1272
1273modes="${bin_mode:-debug release}"
1274for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001275 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001276 # Build with a temporary archive
1277 build_archive="$archive/$mode"
1278 mkdir "$build_archive"
1279
1280 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001281 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001282 DEBUG=1
1283 else
Zelalem219df412020-05-17 19:21:20 -05001284 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001285 DEBUG=0
1286 fi
1287
1288 # Perform builds in a subshell so as not to pollute the current and
1289 # subsequent builds' environment
1290
Zelalem219df412020-05-17 19:21:20 -05001291 if config_valid "$cc_config"; then
1292 # Build code coverage plugin
1293 build_cc
1294 fi
1295
Fathi Boudra422bf772019-12-02 11:10:16 +02001296 # SCP build
1297 if config_valid "$scp_config"; then
1298 (
1299 echo "##########"
1300
1301 # Source platform-specific utilities
1302 plat="$(get_scp_opt PRODUCT)"
1303 plat_utils="$ci_root/${plat}_utils.sh"
1304 if [ -f "$plat_utils" ]; then
1305 source "$plat_utils"
1306 fi
1307
1308 archive="$build_archive"
1309 scp_build_root="$scp_root/build"
1310
1311 echo "Building SCP Firmware ($mode) ..." |& log_separator
1312
1313 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001314 to="$archive" collect_scp_artefacts
1315
1316 echo "##########"
1317 echo
1318 )
1319 fi
1320
Zelalem219df412020-05-17 19:21:20 -05001321 # SCP-tools build
1322 if config_valid "$scp_tools_config"; then
1323 (
1324 echo "##########"
1325
1326 archive="$build_archive"
1327 scp_tools_build_root="$scp_tools_root/build"
1328
1329 clone_scp_tools
1330
1331 echo "##########"
1332 echo
1333
1334 echo "##########"
1335 clone_tf_for_scp_tools
1336 echo "##########"
1337 echo
1338 )
1339 fi
1340
Fathi Boudra422bf772019-12-02 11:10:16 +02001341 # TFTF build
1342 if config_valid "$tftf_config"; then
1343 (
1344 echo "##########"
1345
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001346 plat_utils="$(get_tf_opt PLAT_UTILS)"
1347 if [ -z ${plat_utils} ]; then
1348 # Source platform-specific utilities.
1349 plat="$(get_tftf_opt PLAT)"
1350 plat_utils="$ci_root/${plat}_utils.sh"
1351 else
1352 # Source platform-specific utilities by
1353 # using plat_utils name.
1354 plat_utils="$ci_root/${plat_utils}.sh"
1355 fi
1356
Fathi Boudra422bf772019-12-02 11:10:16 +02001357 if [ -f "$plat_utils" ]; then
1358 source "$plat_utils"
1359 fi
1360
1361 archive="$build_archive"
1362 tftf_build_root="$tftf_root/build"
1363
1364 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1365
1366 # Call pre-build hook
1367 call_hook pre_tftf_build
1368
1369 build_tftf
1370
1371 from="$tftf_build_root" to="$archive" collect_build_artefacts
1372
1373 # Clear any local changes made by applied patches
1374 undo_tftf_patches
1375
1376 echo "##########"
1377 echo
1378 )
1379 fi
1380
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001381 # SPM build
1382 if config_valid "$spm_config"; then
1383 (
1384 echo "##########"
1385
1386 # Get platform name from spm_config file
1387 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1388 plat_utils="$ci_root/${plat}_utils.sh"
1389 if [ -f "$plat_utils" ]; then
1390 source "$plat_utils"
1391 fi
1392
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001393 # Call pre-build hook
1394 call_hook pre_spm_build
1395
Manish Pandey1e7be852020-11-09 16:04:48 +00001396 # SPM build generates two sets of binaries, one for normal and other
1397 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001398 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001399 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1400 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001401
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001402 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001403 echo "Building SPM ($mode) ..." |& log_separator
1404
1405 # NOTE: mode has no effect on SPM build (for now), hence debug
1406 # mode is built but subsequent build using release mode just
1407 # goes through with "nothing to do".
1408 build_spm
1409
1410 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001411 cksum $spm_build_root/hafnium.bin
1412
1413 # Some platforms only have secure configuration enabled. Hence,
1414 # non secure hanfnium binary might not be built.
1415 if [ -f $hafnium_build_root/hafnium.bin ]; then
1416 cksum $hafnium_build_root/hafnium.bin
1417 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001418
Manish Pandey1e7be852020-11-09 16:04:48 +00001419 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001420
1421 echo "##########"
1422 echo
1423 )
1424 fi
1425
Fathi Boudra422bf772019-12-02 11:10:16 +02001426 # TF build
1427 if config_valid "$tf_config"; then
1428 (
1429 echo "##########"
1430
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001431 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001432 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1433
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001434 if [ -z ${plat_utils} ]; then
1435 # Source platform-specific utilities.
1436 plat="$(get_tf_opt PLAT)"
1437 plat_utils="$ci_root/${plat}_utils.sh"
1438 else
1439 # Source platform-specific utilities by
1440 # using plat_utils name.
1441 plat_utils="$ci_root/${plat_utils}.sh"
1442 fi
1443
Fathi Boudra422bf772019-12-02 11:10:16 +02001444 if [ -f "$plat_utils" ]; then
1445 source "$plat_utils"
1446 fi
1447
Harrison Mutaib76cecf2023-02-16 14:12:40 +00001448 # Install python build dependencies
1449 if is_arm_jenkins_env; then
1450 source "$ci_root/script/install_python_deps_tf.sh"
1451 fi
1452
1453 poetry -C "$tf_root" install --without doc
Chris Kayd0837902021-11-17 10:17:52 +00001454
Chris Kay48c50de2023-08-04 11:50:31 +00001455 fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)"
1456 fvp_tsram_size="${fvp_tsram_size:-256}"
1457
Fathi Boudra422bf772019-12-02 11:10:16 +02001458 archive="$build_archive"
1459 tf_build_root="$tf_root/build"
1460
1461 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1462
1463 # Call pre-build hook
1464 call_hook pre_tf_build
1465
1466 build_tf
1467
1468 # Call post-build hook
1469 call_hook post_tf_build
1470
1471 # Pre-archive hook
1472 call_hook pre_tf_archive
1473
1474 from="$tf_build_root" to="$archive" collect_build_artefacts
1475
1476 # Post-archive hook
1477 call_hook post_tf_archive
1478
1479 call_hook fetch_tf_resource
1480 call_hook post_fetch_tf_resource
1481
Chris Kay4e8aaf12022-09-01 15:21:55 +01001482 # Generate LAVA job files if necessary
1483 call_hook generate_lava_job_template
1484 call_hook generate_lava_job
1485
Fathi Boudra422bf772019-12-02 11:10:16 +02001486 # Clear any local changes made by applied patches
1487 undo_tf_patches
1488
1489 echo "##########"
1490 )
1491 fi
1492
1493 echo
1494 echo
1495done
1496
1497call_hook pre_package
1498
1499call_hook post_package
1500
1501if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001502 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001503fi
1504
1505echo
1506echo "Done"