blob: c2a70587c12715bef8e8ea28cb31a1477e339934 [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"
259
260 echo "UART$uart to be tracked with $file; timeout ${timeout}s"
261
262 # The run script assumes UART0 to be primary. If we're asked to set any
263 # other UART to be primary, set a run environment variable to signal
264 # that to the run script
265 if upon "$set_primary"; then
266 echo "Primary UART set to UART$uart."
267 set_run_env "primary_uart" "$uart"
268 fi
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600269
270 # UART used by payload(such as tftf, Linux) may not be the same as the
271 # primary UART. Set a run environment variable to track the payload
272 # UART which is tracked to check if the test has finished sucessfully.
273 if upon "$set_payload_uart"; then
274 echo "Payload uses UART$uart."
275 set_run_env "payload_uart" "$uart"
276 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200277}
278
279# Extract a FIP in $1 using fiptool
280extract_fip() {
281 local fip="$1"
282
283 if is_url "$1"; then
284 url="$1" fetch_file
285 fip="$(basename "$1")"
286 fi
287
288 "$fiptool" unpack "$fip"
289 echo "Extracted FIP: $fip"
290}
291
292# Report build failure by printing a the tail end of build log. Archive the
293# build log for later inspection
294fail_build() {
295 local log_path
296
297 if upon "$jenkins_run"; then
298 log_path="$BUILD_URL/artifact/artefacts/build.log"
299 else
300 log_path="$build_log"
301 fi
302
303 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600304 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200305 echo "[...]"
306 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600307 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200308 echo
309 echo "See $log_path for full output"
310 echo
311 cp -t "$archive" "$build_log"
312 exit 1;
313}
314
315# Build a FIP with supplied arguments
316build_fip() {
317 (
318 echo "Building FIP with arguments: $@"
319 local tf_env="$workspace/tf.env"
320
321 if [ -f "$tf_env" ]; then
322 set -a
323 source "$tf_env"
324 set +a
325 fi
326
327 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
328 ${fip_targets:-fip} &>>"$build_log" || fail_build
329 )
330}
331
332fip_update() {
333 # Before the update process, check if the given image is supported by
334 # the fiptool. It's assumed that both fiptool and cert_create move in
335 # tandem, and therfore, if one has support, the other has it too.
336 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
337 return 1
338 fi
339
340 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
341 echo "Updating FIP image: $bin_name"
342 # Update HW config. Without TBBR, it's only a matter of using
343 # the update sub-command of fiptool
344 "$fiptool" update "--$bin_name" "${src:-}" \
345 "$archive/fip.bin"
346 else
347 echo "Updating FIP image (TBBR): $bin_name"
348 # With TBBR, we need to unpack, re-create certificates, and then
349 # recreate the FIP.
350 local fip_dir="$(mktempdir)"
351 local bin common_args stem
352 local rot_key="$(get_tf_opt ROT_KEY)"
353
354 rot_key="${rot_key:?}"
355 if ! is_abs "$rot_key"; then
356 rot_key="$tf_root/$rot_key"
357 fi
358
359 # Arguments only for cert_create
360 local cert_args="-n"
361 cert_args+=" --tfw-nvctr ${nvctr:-31}"
362 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
363 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
364 cert_args+=" --rot-key $rot_key"
365
366 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500367 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200368 "hw-config"
369 "tb-fw-config"
370 "nt-fw-config"
371 "soc-fw-config"
372 "tos-fw-config"
373 )
374
375 # Binaries without key certificates
376 declare -A has_no_key_cert
377 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
378 has_no_key_cert["$bin"]="1"
379 done
380
381 # Binaries without certificates
382 declare -A has_no_cert
383 for bin in "hw-config" "${dyn_config_opts[@]}"; do
384 has_no_cert["$bin"]="1"
385 done
386
387 pushd "$fip_dir"
388
389 # Unpack FIP
390 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
391
392 # Remove all existing certificates
393 rm -f *-cert.bin
394
395 # Copy the binary to be updated
396 cp -f "$src" "${bin_name}.bin"
397
398 # FIP unpack dumps binaries with the same name as the option
399 # used to pack it; likewise for certificates. Reverse-engineer
400 # the command line from the binary output.
401 common_args="--trusted-key-cert trusted_key.crt"
402 for bin in *.bin; do
403 stem="${bin%%.bin}"
404 common_args+=" --$stem $bin"
405 if not_upon "${has_no_cert[$stem]}"; then
406 common_args+=" --$stem-cert $stem.crt"
407 fi
408 if not_upon "${has_no_key_cert[$stem]}"; then
409 common_args+=" --$stem-key-cert $stem-key.crt"
410 fi
411 done
412
413 # Create certificates
414 "$cert_create" $cert_args $common_args &>>"$build_log"
415
416 # Recreate and archive FIP
417 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
418 archive_file "fip.bin"
419
420 popd
421 fi
422}
423
424# Update hw-config in FIP, and remove the original DTB afterwards.
425update_fip_hw_config() {
426 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600427 # in configs:
428 # 1. Where BL2 isn't present
429 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200430 case "1" in
431 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600432 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200433 "$(get_tf_opt RESET_TO_SP_MIN)" | \
434 "$(get_tf_opt BL2_AT_EL3)")
435 return 0;;
436 esac
437
438 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
439 # Remove the DTB so that model won't load it
440 rm -f "$archive/dtb.bin"
441 fi
442}
443
444get_scp_opt() {
445 (
446 name="${1:?}"
447 if config_valid "$scp_config_file"; then
448 source "$scp_config_file"
449 echo "${!name}"
450 fi
451 )
452}
453
454get_tftf_opt() {
455 (
456 name="${1:?}"
457 if config_valid "$tftf_config_file"; then
458 source "$tftf_config_file"
459 echo "${!name}"
460 fi
461 )
462}
463
464get_tf_opt() {
465 (
466 name="${1:?}"
467 if config_valid "$tf_config_file"; then
468 source "$tf_config_file"
469 echo "${!name}"
470 fi
471 )
472}
473
474build_tf() {
475 (
476 env_file="$workspace/tf.env"
477 config_file="${tf_build_config:-$tf_config_file}"
478
479 # Build fiptool and all targets by default
Manish V Badarkhe57bea362022-07-12 22:43:30 +0100480 build_targets="${tf_build_targets:-memmap fiptool all}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200481
482 source "$config_file"
483
484 # If it is a TBBR build, extract the MBED TLS library from archive
Manish V Badarkhe8f125012021-12-21 05:47:52 +0000485 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] ||
Manish V Badarkhef43e3f52022-06-21 20:37:25 +0100486 [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] ||
487 [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200488 mbedtls_dir="$workspace/mbedtls"
489 if [ ! -d "$mbedtls_dir" ]; then
490 mbedtls_ar="$workspace/mbedtls.tar.gz"
491
492 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
493 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500494 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200495 fi
496
497 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
498 fi
499
500 if [ -f "$env_file" ]; then
501 set -a
502 source "$env_file"
503 set +a
504 fi
505
Harrison Mutai013f6332022-02-16 16:06:33 +0000506 if is_arm_jenkins_env || upon "$local_ci"; then
507 path_list=(
508 "$llvm_dir/bin"
509 )
510 extend_path "PATH" "path_list"
511 fi
512
Fathi Boudra422bf772019-12-02 11:10:16 +0200513 cd "$tf_root"
514
515 # Always distclean when running on Jenkins. Skip distclean when running
516 # locally and explicitly requested.
517 if upon "$jenkins_run" || not_upon "$dont_clean"; then
518 make distclean &>>"$build_log" || fail_build
519 fi
520
521 # Log build command line. It is left unfolded on purpose to assist
522 # copying to clipboard.
523 cat <<EOF | log_separator >/dev/null
524
525Build command line:
526 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
527
528EOF
529
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000530 if not_upon "$local_ci"; then
531 connect_debugger=0
532 fi
533
Fathi Boudra422bf772019-12-02 11:10:16 +0200534 # Build TF. Since build output is being directed to the build log, have
535 # descriptor 3 point to the current terminal for build wrappers to vent.
536 $tf_build_wrapper make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000537 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200538 $build_targets 3>&1 &>>"$build_log" || fail_build
539 )
540}
541
542build_tftf() {
543 (
544 config_file="${tftf_build_config:-$tftf_config_file}"
545
546 # Build tftf target by default
547 build_targets="${tftf_build_targets:-all}"
548
549 source "$config_file"
550
551 cd "$tftf_root"
552
553 # Always distclean when running on Jenkins. Skip distclean when running
554 # locally and explicitly requested.
555 if upon "$jenkins_run" || not_upon "$dont_clean"; then
556 make distclean &>>"$build_log" || fail_build
557 fi
558
559 # TFTF build system cannot reliably deal with -j option, so we avoid
560 # using that.
561
562 # Log build command line
563 cat <<EOF | log_separator >/dev/null
564
565Build command line:
566 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
567
568EOF
569
570 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
571 $build_targets &>>"$build_log" || fail_build
572 )
573}
574
575build_scp() {
576 (
577 config_file="${scp_build_config:-$scp_config_file}"
578
579 source "$config_file"
580
581 cd "$scp_root"
582
583 # Always distclean when running on Jenkins. Skip distclean when running
584 # locally and explicitly requested.
585 if upon "$jenkins_run" || not_upon "$dont_clean"; then
586 make clean &>>"$build_log" || fail_build
587 fi
588
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000589 python3 -m venv .venv
590 . .venv/bin/activate
591
592 # Install extra tools used by CMake build system
593 pip install -r requirements.txt --timeout 30 --retries 15
594
Fathi Boudra422bf772019-12-02 11:10:16 +0200595 # Log build command line. It is left unfolded on purpose to assist
596 # copying to clipboard.
597 cat <<EOF | log_separator >/dev/null
598
599SCP build command line:
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000600 make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \
601 TOOLCHAIN=GNU \
602 MODE="$mode" \
Nicola Mazzucato506b5802021-12-24 14:23:25 +0000603 EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000604 V=1 &>>"$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200605
606EOF
607
608 # Build SCP
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 || fail_build
615 )
616}
617
Zelalem219df412020-05-17 19:21:20 -0500618clone_scp_tools() {
619
620 if [ ! -d "$scp_tools_root" ]; then
621 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
622
623 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
624 where="$scp_tools_root" \
625 refspec="${scp_tools_commit}"
626 clone_repo &>>"$build_log"
627 else
628 echo "Already cloned SCP-tools ..." |& log_separator
629 fi
630
631 show_head "$scp_tools_root"
632
633 cd "$scp_tools_root"
634
635 echo "Updating submodules"
636
637 git submodule init
638
639 git submodule update
640
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000641 lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'")
642
Zelalem219df412020-05-17 19:21:20 -0500643 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000644 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500645
646 git show --quiet --no-color | sed 's/^/ > /g'
647}
648
649clone_tf_for_scp_tools() {
650 scp_tools_arm_tf="$scp_tools_root/arm-tf"
651
652 if [ ! -d "$scp_tools_arm_tf" ]; then
653 echo "Cloning TF-4-SCP-tools ..." |& log_separator
654
655 clone_url="$tf_for_scp_tools_src_repo_url"
656 where="$scp_tools_arm_tf"
657
658 git clone "$clone_url" "$where"
659
660 cd "$scp_tools_arm_tf"
661
Joel Goddard3ad03062021-03-16 16:47:42 +0000662 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500663
664 git show --quiet --no-color | sed 's/^/ > /g'
665
666 else
667 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
668 fi
669}
670
671build_scmi_lib_scp_tools() {
672 (
673 cd "$scp_tools_root"
674
675 cd "scmi"
676
677 scp_tools_arm_tf="$scp_tools_root/arm-tf"
678
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600679 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500680
681 std_libs="-I$scp_tools_arm_tf/include/common"
682 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
683 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
684 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
685 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
686 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
687 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
688 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
689 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
690 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
691 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
692 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
693 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
694 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
695
696 cflags="-Og -g"
697 cflags="$cflags -mgeneral-regs-only"
698 cflags="$cflags -mstrict-align"
699 cflags="$cflags -nostdinc"
700 cflags="$cflags -fno-inline"
701 cflags="$cflags -ffreestanding"
702 cflags="$cflags -ffunction-sections"
703 cflags="$cflags -fdata-sections"
704 cflags="$cflags -DAARCH64"
705 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000706 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500707
708 cflags="$cflags $std_libs"
709
Joel Goddard3ad03062021-03-16 16:47:42 +0000710 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500711
712 echo "Building SCMI library (SCP-tools) ..."
713
714 make "CROSS_COMPILE=$cross_compile" \
715 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000716 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500717 "PROTOCOLS=$protocols" \
718 "clean" \
719 "all"
720 )
721}
722
723build_tf_for_scp_tools() {
724
725 cd "$scp_tools_root/arm-tf"
726
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600727 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500728
729 if [ "$1" = "release" ]; then
730 echo "Build TF-4-SCP-Tools rls..."
731 else
732 echo "Build TF-4-SCP-Tools dbg..."
733
734 make realclean
735
736 make "BM_TEST=scmi" \
737 "ARM_BOARD_OPTIMISE_MEM=1" \
738 "BM_CSS=juno" \
739 "CSS_USE_SCMI_SDS_DRIVER=1" \
740 "PLAT=juno" \
741 "DEBUG=1" \
742 "PLATFORM=juno" \
743 "CROSS_COMPILE=$cross_compile" \
744 "BM_WORKSPACE=$scp_tools_root/baremetal"
745
746 archive_file "build/juno/debug/bl1.bin"
747
748 archive_file "build/juno/debug/bl2.bin"
749
750 archive_file "build/juno/debug/bl31.bin"
751 fi
752}
753
754build_fip_for_scp_tools() {
755
756 cd "$scp_tools_root/arm-tf"
757
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600758 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500759
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000760 if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then
Zelalem219df412020-05-17 19:21:20 -0500761 make fiptool
762 echo "Make FIP 4 SCP-Tools rls..."
763
764 else
765 make fiptool
766 echo "Make FIP 4 SCP-Tools dbg..."
767
768 make "PLAT=juno" \
769 "all" \
770 "fip" \
771 "DEBUG=1" \
772 "CROSS_COMPILE=$cross_compile" \
773 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
774 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
Joel Goddard9bdfe3c2021-02-25 10:15:14 +0000775 "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin"
Zelalem219df412020-05-17 19:21:20 -0500776
777 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
778 fi
779}
780
781build_cc() {
782# Building code coverage plugin
783 ARM_DIR=/arm
784 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
785 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
786 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
787 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
788 exit -1
789 fi # Error if arm warehouse not found
790 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
791
792 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
793}
794
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100795build_spm() {
796 (
797 env_file="$workspace/spm.env"
798 config_file="${spm_build_config:-$spm_config_file}"
799
800 source "$config_file"
801
802 if [ -f "$env_file" ]; then
803 set -a
804 source "$env_file"
805 set +a
806 fi
807
808 cd "$spm_root"
809
810 # Always clean when running on Jenkins. Skip clean when running
811 # locally and explicitly requested.
812 if upon "$jenkins_run" || not_upon "$dont_clean"; then
813 # make clean fails on a fresh repo where the project has not
814 # yet been built. Hence only clean if out/reference directory
815 # already exists.
816 if [ -d "out/reference" ]; then
817 make clean &>>"$build_log" || fail_build
818 fi
819 fi
820
821 # Log build command line. It is left unfolded on purpose to assist
822 # copying to clipboard.
823 cat <<EOF | log_separator >/dev/null
824
825Build command line:
826 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
827
828EOF
829
830 # Build SPM. Since build output is being directed to the build log, have
831 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200832 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
833
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100834 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
835 || fail_build
836 )
837}
Zelalem219df412020-05-17 19:21:20 -0500838
Fathi Boudra422bf772019-12-02 11:10:16 +0200839# Set metadata for the whole package so that it can be used by both Jenkins and
840# shell
841set_package_var() {
842 env_file="$artefacts/env" emit_env "$@"
843}
844
845set_tf_build_targets() {
846 echo "Set build target to '${targets:?}'"
847 set_hook_var "tf_build_targets" "$targets"
848}
849
850set_tftf_build_targets() {
851 echo "Set build target to '${targets:?}'"
852 set_hook_var "tftf_build_targets" "$targets"
853}
854
855set_scp_build_targets() {
856 echo "Set build target to '${targets:?}'"
857 set_hook_var "scp_build_targets" "$targets"
858}
859
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100860set_spm_build_targets() {
861 echo "Set build target to '${targets:?}'"
862 set_hook_var "spm_build_targets" "$targets"
863}
864
Daniel Boulbyb8d2a462022-03-07 13:55:25 +0000865set_spm_out_dir() {
866 echo "Set SPMC binary build to '${out_dir:?}'"
867 set_hook_var "spm_secure_out_dir" "$out_dir"
868}
Fathi Boudra422bf772019-12-02 11:10:16 +0200869# Look under $archive directory for known files such as blX images, kernel, DTB,
870# initrd etc. For each known file foo, if foo.bin exists, then set variable
871# foo_bin to the path of the file. Make the path relative to the workspace so as
872# to remove any @ characters, which Jenkins inserts for parallel runs. If the
873# file doesn't exist, unset its path.
874set_default_bin_paths() {
875 local image image_name image_path path
876 local archive="${archive:?}"
877 local set_vars
878 local var
879
880 pushd "$archive"
881
882 for file in *.bin; do
883 # Get a shell variable from the file's stem
884 var_name="${file%%.*}_bin"
885 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
886
887 # Skip setting the variable if it's already
888 if [ "${!var_name}" ]; then
889 echo "Note: not setting $var_name; already set to ${!var_name}"
890 continue
891 else
892 set_vars+="$var_name "
893 fi
894
895 eval "$var_name=$file"
896 done
897
898 echo "Binary paths set for: "
899 {
900 for var in $set_vars; do
901 echo -n "\$$var "
902 done
903 } | fmt -80 | sed 's/^/ /'
904 echo
905
906 popd
907}
908
909gen_model_params() {
910 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000911 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200912
913 set_default_bin_paths
914 echo "Generating model parameter for $model..."
915 source "$ci_root/model/${model:?}.sh"
916 archive_file "$model_param_file"
917}
918
919set_model_path() {
920 set_run_env "model_path" "${1:?}"
921}
922
Zelalem1af7a7b2020-08-04 17:34:32 -0500923set_model_env() {
924 local var="${1:?}"
925 local val="${2?}"
926 local run_root="${archive:?}/run"
927
928 mkdir -p "$run_root"
929 echo "export $var=$val" >> "$run_root/model_env"
930}
Fathi Boudra422bf772019-12-02 11:10:16 +0200931set_run_env() {
932 local var="${1:?}"
933 local val="${2?}"
934 local run_root="${archive:?}/run"
935
936 mkdir -p "$run_root"
937 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
938}
939
940show_head() {
941 # Display HEAD descripton
942 pushd "$1"
943 git show --quiet --no-color | sed 's/^/ > /g'
944 echo
945 popd
946}
947
948# Choose debug binaries to run; by default, release binaries are chosen to run
949use_debug_bins() {
950 local run_root="${archive:?}/run"
951
952 echo "Choosing debug binaries for execution"
953 set_package_var "BIN_MODE" "debug"
954}
955
956assert_can_git_clone() {
957 local name="${1:?}"
958 local dir="${!name}"
959
960 # If it doesn't exist, it can be cloned into
961 if [ ! -e "$dir" ]; then
962 return 0
963 fi
964
965 # If it's a directory, it must be a Git clone already
966 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
967 # No need to clone again
968 echo "Using existing git clone for $name: $dir"
969 return 1
970 fi
971
972 die "Path $dir exists but is not a git clone"
973}
974
975clone_repo() {
976 if ! is_url "${clone_url?}"; then
977 # For --depth to take effect on local paths, it needs to use the
978 # file:// scheme.
979 clone_url="file://$clone_url"
980 fi
981
982 git clone -q --depth 1 "$clone_url" "${where?}"
983 if [ "$refspec" ]; then
984 pushd "$where"
985 git fetch -q --depth 1 origin "$refspec"
986 git checkout -q FETCH_HEAD
987 popd
988 fi
989}
990
991build_unstable() {
992 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
993}
994
995undo_patch_record() {
996 if [ ! -f "${patch_record:?}" ]; then
997 return
998 fi
999
1000 # Undo patches in reverse
1001 echo
1002 for patch_name in $(tac "$patch_record"); do
1003 echo "Undoing $patch_name..."
1004 if ! git apply -R "$ci_root/patch/$patch_name"; then
1005 if upon "$local_ci"; then
1006 echo
1007 echo "Your local directory may have been dirtied."
1008 echo
1009 fi
1010 fail_build
1011 fi
1012 done
1013
1014 rm -f "$patch_record"
1015}
1016
1017undo_local_patches() {
1018 pushd "$tf_root"
1019 patch_record="$tf_patch_record" undo_patch_record
1020 popd
1021
1022 if [ -d "$tftf_root" ]; then
1023 pushd "$tftf_root"
1024 patch_record="$tftf_patch_record" undo_patch_record
1025 popd
1026 fi
1027}
1028
1029undo_tftf_patches() {
1030 pushd "$tftf_root"
1031 patch_record="$tftf_patch_record" undo_patch_record
1032 popd
1033}
1034
1035undo_tf_patches() {
1036 pushd "$tf_root"
1037 patch_record="$tf_patch_record" undo_patch_record
1038 popd
1039}
1040
1041apply_patch() {
1042 # If skip_patches is set, the developer has applied required patches
1043 # manually. They probably want to keep them applied for debugging
1044 # purposes too. This means we don't have to apply/revert them as part of
1045 # build process.
1046 if upon "$skip_patches"; then
1047 echo "Skipped applying ${1:?}..."
1048 return 0
1049 else
1050 echo "Applying ${1:?}..."
1051 fi
1052
1053 if git apply < "$ci_root/patch/$1"; then
1054 echo "$1" >> "${patch_record:?}"
1055 else
1056 if upon "$local_ci"; then
1057 undo_local_patches
1058 fi
1059 fail_build
1060 fi
1061}
1062
1063apply_tftf_patch() {
1064 pushd "$tftf_root"
1065 patch_record="$tftf_patch_record" apply_patch "$1"
1066 popd
1067}
1068
1069apply_tf_patch() {
1070 pushd "$tf_root"
1071 patch_record="$tf_patch_record" apply_patch "$1"
1072 popd
1073}
1074
1075# Clear workspace for a local run
1076if not_upon "$jenkins_run"; then
1077 rm -rf "$workspace"
1078
1079 # Clear residue from previous runs
1080 rm -rf "$archive"
1081fi
1082
1083mkdir -p "$workspace"
1084mkdir -p "$archive"
1085set_package_var "TEST_CONFIG" "$test_config"
1086
1087{
1088echo
1089echo "CONFIGURATION: $test_group/$test_config"
1090echo
1091} |& log_separator
1092
1093tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1094tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1095scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001096scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001097spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001098
1099test_config_file="$ci_root/group/$test_group/$test_config"
1100
1101tf_config_file="$ci_root/tf_config/$tf_config"
1102tftf_config_file="$ci_root/tftf_config/$tftf_config"
1103scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001104scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001105spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001106
1107# File that keeps track of applied patches
1108tf_patch_record="$workspace/tf_patches"
1109tftf_patch_record="$workspace/tftf_patches"
1110
1111pushd "$workspace"
1112
1113if ! config_valid "$tf_config"; then
1114 tf_config=
1115else
1116 echo "Trusted Firmware config:"
1117 echo
1118 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1119 echo
1120fi
1121
1122if ! config_valid "$tftf_config"; then
1123 tftf_config=
1124else
1125 echo "Trusted Firmware TF config:"
1126 echo
1127 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1128 echo
1129fi
1130
1131if ! config_valid "$scp_config"; then
1132 scp_config=
1133else
1134 echo "SCP firmware config:"
1135 echo
1136 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1137 echo
1138fi
1139
Zelalem219df412020-05-17 19:21:20 -05001140if ! config_valid "$scp_tools_config"; then
1141 scp_tools_config=
1142else
1143 echo "SCP Tools config:"
1144 echo
1145 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001146fi
1147
1148if ! config_valid "$spm_config"; then
1149 spm_config=
1150else
1151 echo "SPM config:"
1152 echo
1153 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001154 echo
1155fi
1156
Fathi Boudra422bf772019-12-02 11:10:16 +02001157if ! config_valid "$run_config"; then
1158 run_config=
1159fi
1160
1161if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1162 # If the Trusted Firmware repository has already been checked out, use
1163 # that location. Otherwise, clone one ourselves.
1164 echo "Cloning Trusted Firmware..."
1165 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1166 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1167 show_head "$tf_root"
1168fi
1169
1170if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1171 # If the Trusted Firmware TF repository has already been checked out,
1172 # use that location. Otherwise, clone one ourselves.
1173 echo "Cloning Trusted Firmware TF..."
1174 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1175 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1176 show_head "$tftf_root"
1177fi
1178
1179if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1180 # If the SCP firmware repository has already been checked out,
1181 # use that location. Otherwise, clone one ourselves.
1182 echo "Cloning SCP Firmware..."
1183 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1184 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1185
1186 pushd "$scp_root"
1187
1188 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001189 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001190 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1191 fi
1192
1193 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1194 # then to project filer if accessible.
1195 if [ -z "$cmsis_reference" ]; then
1196 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1197 if [ -d "$cmsis_ref_repo" ]; then
1198 cmsis_reference="--reference $cmsis_ref_repo"
1199 fi
1200 fi
1201
1202 git submodule -q update $cmsis_reference --init
1203
1204 popd
1205
1206 show_head "$scp_root"
1207fi
1208
Zelalem219df412020-05-17 19:21:20 -05001209if [ -n "$cc_config" ] ; then
1210 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1211 # Copy code coverage repository
1212 echo "Cloning Code Coverage..."
1213 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1214 show_head "$cc_root"
1215 fi
1216fi
1217
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001218if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1219 # If the SPM repository has already been checked out, use
1220 # that location. Otherwise, clone one ourselves.
1221 echo "Cloning SPM..."
1222 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1223 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1224
1225 # Query git submodules
1226 pushd "$spm_root"
1227 git submodule update --init
1228 popd
1229
1230 show_head "$spm_root"
1231fi
1232
Fathi Boudra422bf772019-12-02 11:10:16 +02001233if [ "$run_config" ]; then
1234 # Get candidates for run config
1235 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1236 "$run_config")"
1237 if [ -z "$run_config_candiates" ]; then
1238 die "No run config candidates!"
1239 else
1240 echo
1241 echo "Chosen fragments:"
1242 echo
1243 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1244 echo
1245 fi
1246fi
1247
1248call_hook "test_setup"
1249echo
1250
1251if upon "$local_ci"; then
1252 # For local runs, since each config is tried in sequence, it's
1253 # advantageous to run jobs in parallel
1254 if [ "$make_j" ]; then
1255 make_j_opts="-j $make_j"
1256 else
1257 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1258 if [ "$n_cores" ]; then
1259 make_j_opts="-j $n_cores"
1260 fi
1261 fi
1262fi
1263
1264modes="${bin_mode:-debug release}"
1265for mode in $modes; do
Paul Sokolovskye9962cd2021-12-17 18:39:40 +03001266 echo "===== Building package in mode: $mode ====="
Fathi Boudra422bf772019-12-02 11:10:16 +02001267 # Build with a temporary archive
1268 build_archive="$archive/$mode"
1269 mkdir "$build_archive"
1270
1271 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001272 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001273 DEBUG=1
1274 else
Zelalem219df412020-05-17 19:21:20 -05001275 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001276 DEBUG=0
1277 fi
1278
1279 # Perform builds in a subshell so as not to pollute the current and
1280 # subsequent builds' environment
1281
Zelalem219df412020-05-17 19:21:20 -05001282 if config_valid "$cc_config"; then
1283 # Build code coverage plugin
1284 build_cc
1285 fi
1286
Fathi Boudra422bf772019-12-02 11:10:16 +02001287 # SCP build
1288 if config_valid "$scp_config"; then
1289 (
1290 echo "##########"
1291
1292 # Source platform-specific utilities
1293 plat="$(get_scp_opt PRODUCT)"
1294 plat_utils="$ci_root/${plat}_utils.sh"
1295 if [ -f "$plat_utils" ]; then
1296 source "$plat_utils"
1297 fi
1298
1299 archive="$build_archive"
1300 scp_build_root="$scp_root/build"
1301
1302 echo "Building SCP Firmware ($mode) ..." |& log_separator
1303
1304 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001305 to="$archive" collect_scp_artefacts
1306
1307 echo "##########"
1308 echo
1309 )
1310 fi
1311
Zelalem219df412020-05-17 19:21:20 -05001312 # SCP-tools build
1313 if config_valid "$scp_tools_config"; then
1314 (
1315 echo "##########"
1316
1317 archive="$build_archive"
1318 scp_tools_build_root="$scp_tools_root/build"
1319
1320 clone_scp_tools
1321
1322 echo "##########"
1323 echo
1324
1325 echo "##########"
1326 clone_tf_for_scp_tools
1327 echo "##########"
1328 echo
1329 )
1330 fi
1331
Fathi Boudra422bf772019-12-02 11:10:16 +02001332 # TFTF build
1333 if config_valid "$tftf_config"; then
1334 (
1335 echo "##########"
1336
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001337 plat_utils="$(get_tf_opt PLAT_UTILS)"
1338 if [ -z ${plat_utils} ]; then
1339 # Source platform-specific utilities.
1340 plat="$(get_tftf_opt PLAT)"
1341 plat_utils="$ci_root/${plat}_utils.sh"
1342 else
1343 # Source platform-specific utilities by
1344 # using plat_utils name.
1345 plat_utils="$ci_root/${plat_utils}.sh"
1346 fi
1347
Fathi Boudra422bf772019-12-02 11:10:16 +02001348 if [ -f "$plat_utils" ]; then
1349 source "$plat_utils"
1350 fi
1351
1352 archive="$build_archive"
1353 tftf_build_root="$tftf_root/build"
1354
1355 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1356
1357 # Call pre-build hook
1358 call_hook pre_tftf_build
1359
1360 build_tftf
1361
1362 from="$tftf_build_root" to="$archive" collect_build_artefacts
1363
1364 # Clear any local changes made by applied patches
1365 undo_tftf_patches
1366
1367 echo "##########"
1368 echo
1369 )
1370 fi
1371
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001372 # SPM build
1373 if config_valid "$spm_config"; then
1374 (
1375 echo "##########"
1376
1377 # Get platform name from spm_config file
1378 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1379 plat_utils="$ci_root/${plat}_utils.sh"
1380 if [ -f "$plat_utils" ]; then
1381 source "$plat_utils"
1382 fi
1383
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001384 # Call pre-build hook
1385 call_hook pre_spm_build
1386
Manish Pandey1e7be852020-11-09 16:04:48 +00001387 # SPM build generates two sets of binaries, one for normal and other
1388 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001389 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001390 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1391 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001392
Daniel Boulbyb8d2a462022-03-07 13:55:25 +00001393 echo "spm_build_root is $spm_build_root"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001394 echo "Building SPM ($mode) ..." |& log_separator
1395
1396 # NOTE: mode has no effect on SPM build (for now), hence debug
1397 # mode is built but subsequent build using release mode just
1398 # goes through with "nothing to do".
1399 build_spm
1400
1401 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001402 cksum $spm_build_root/hafnium.bin
1403
1404 # Some platforms only have secure configuration enabled. Hence,
1405 # non secure hanfnium binary might not be built.
1406 if [ -f $hafnium_build_root/hafnium.bin ]; then
1407 cksum $hafnium_build_root/hafnium.bin
1408 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001409
Manish Pandey1e7be852020-11-09 16:04:48 +00001410 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001411
1412 echo "##########"
1413 echo
1414 )
1415 fi
1416
Fathi Boudra422bf772019-12-02 11:10:16 +02001417 # TF build
1418 if config_valid "$tf_config"; then
1419 (
1420 echo "##########"
1421
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001422 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001423 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1424
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001425 if [ -z ${plat_utils} ]; then
1426 # Source platform-specific utilities.
1427 plat="$(get_tf_opt PLAT)"
1428 plat_utils="$ci_root/${plat}_utils.sh"
1429 else
1430 # Source platform-specific utilities by
1431 # using plat_utils name.
1432 plat_utils="$ci_root/${plat_utils}.sh"
1433 fi
1434
Fathi Boudra422bf772019-12-02 11:10:16 +02001435 if [ -f "$plat_utils" ]; then
1436 source "$plat_utils"
1437 fi
1438
Chris Kayd0837902021-11-17 10:17:52 +00001439 source "$ci_root/script/install_python_deps_tf.sh"
1440
Fathi Boudra422bf772019-12-02 11:10:16 +02001441 archive="$build_archive"
1442 tf_build_root="$tf_root/build"
1443
1444 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1445
1446 # Call pre-build hook
1447 call_hook pre_tf_build
1448
1449 build_tf
1450
1451 # Call post-build hook
1452 call_hook post_tf_build
1453
1454 # Pre-archive hook
1455 call_hook pre_tf_archive
1456
1457 from="$tf_build_root" to="$archive" collect_build_artefacts
1458
1459 # Post-archive hook
1460 call_hook post_tf_archive
1461
1462 call_hook fetch_tf_resource
1463 call_hook post_fetch_tf_resource
1464
Chris Kay4e8aaf12022-09-01 15:21:55 +01001465 # Generate LAVA job files if necessary
1466 call_hook generate_lava_job_template
1467 call_hook generate_lava_job
1468
Fathi Boudra422bf772019-12-02 11:10:16 +02001469 # Clear any local changes made by applied patches
1470 undo_tf_patches
1471
1472 echo "##########"
1473 )
1474 fi
1475
1476 echo
1477 echo
1478done
1479
1480call_hook pre_package
1481
1482call_hook post_package
1483
1484if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001485 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001486fi
1487
1488echo
1489echo "Done"