blob: 5088d132ba6cba368b158f4735753cda7831bf63 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Leonardo Sandoval579c7372020-10-23 15:23:32 -05003# Copyright (c) 2019-2020 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
111 : >"$hook_env_file"
112
113 if [ "$run_config_candiates" ]; then
114 for config_fragment in $run_config_candiates; do
115 (
116 source "$ci_root/run_config/$config_fragment"
117 call_func "$func" "$config_fragment"
118 )
119 done
120 fi
121
122 # Also source test config file
123 (
124 unset "$func"
125 source "$test_config_file"
126 call_func "$func" "$(basename $test_config_file)"
127 )
128
129 # Have any variables set take effect
130 source "$hook_env_file"
131}
132
133# Set a variable from within a hook
134set_hook_var() {
135 echo "export $1=\"${2?}\"" >> "$hook_env_file"
136}
137
138# Append to an array from within a hook
139append_hook_var() {
140 echo "export $1+=\"${2?}\"" >> "$hook_env_file"
141}
142
143# Have the main build script source a file
144source_later() {
145 echo "source ${1?}" >> "$hook_env_file"
146}
147
148# Setup TF build wrapper function by pointing to a script containing a function
149# that will be called with the TF build commands.
150setup_tf_build_wrapper() {
151 source_later "$ci_root/script/${wrapper?}_wrapper.sh"
152 set_hook_var "tf_build_wrapper" "${wrapper}_wrapper"
153 echo "Setup $wrapper build wrapper."
154}
155
156# Collect .bin files for archiving
157collect_build_artefacts() {
158 if [ ! -d "${from:?}" ]; then
159 return
160 fi
161
Javier Almansa Sobrinof98dbd82020-09-30 19:29:27 +0100162 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 +0200163 echo "You probably are running local CI on local repositories."
164 echo "Did you set 'dont_clean' but forgot to run 'distclean'?"
165 die
166 fi
167}
168
169# SCP and MCP binaries are named firmware.{bin,elf}, and are placed under
170# scp/mcp_ramfw and scp/mcp_romfw directories, so can't be collected by
171# collect_build_artefacts function.
172collect_scp_artefacts() {
173 to="${to:?}" \
174 find "$scp_root" \( -name "*.bin" -o -name '*.elf' \) -exec bash -c '
175 for file; do
176 ext="$(echo $file | awk -F. "{print \$NF}")"
177 case $file in
178 */scp_ramfw/*)
179 cp $file $to/scp_ram.$ext
180 ;;
Anurag Koulc7f61ce2021-02-24 19:11:06 +0000181 */scp_ramfw_fvp/*)
182 cp $file $to/scp_ramfw_fvp.$ext
183 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200184 */scp_romfw/*)
185 cp $file $to/scp_rom.$ext
186 ;;
187 */mcp_ramfw/*)
188 cp $file $to/mcp_ram.$ext
189 ;;
Anurag Koulc7f61ce2021-02-24 19:11:06 +0000190 */mcp_ramfw_fvp/*)
191 cp $file $to/mcp_ramfw_fvp.$ext
192 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200193 */mcp_romfw/*)
194 cp $file $to/mcp_rom.$ext
195 ;;
Zelalem219df412020-05-17 19:21:20 -0500196 */scp_romfw_bypass/*)
197 cp $file $to/scp_rom_bypass.$ext
198 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200199 *)
200 echo "Unknown SCP binary: $file" >&2
201 ;;
202 esac
203 done
204 ' bash '{}' +
205}
206
Manish Pandey1e7be852020-11-09 16:04:48 +0000207# Collect SPM/hafnium artefacts with "secure_" appended to the files
208# generated for SPM(secure hafnium).
209collect_spm_artefacts() {
210 if [ ! -d "${non_secure_from:?}" ] || [ ! -d "${secure_from:?}" ]; then
211 return
212 fi
213
214 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
215
216 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
217}
218
Javier Almansa Sobrino412d3612020-05-22 17:53:12 +0100219# Map the UART ID used for expect with the UART descriptor and port
220# used by the FPGA automation tools.
221map_uart() {
222 local port="${port:?}"
223 local descriptor="${descriptor:?}"
224 local baudrate="${baudrate:?}"
225 local run_root="${archive:?}/run"
226
227 local uart_dir="$run_root/uart${uart:?}"
228 mkdir -p "$uart_dir"
229
230 echo "$port" > "$uart_dir/port"
231 echo "$descriptor" > "$uart_dir/descriptor"
232 echo "$baudrate" > "$uart_dir/baudrate"
233
234 echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}"
235}
236
Fathi Boudra422bf772019-12-02 11:10:16 +0200237# Arrange environment varibles to be set when expect scripts are launched
238set_expect_variable() {
239 local var="${1:?}"
240 local val="${2?}"
241
242 local run_root="${archive:?}/run"
243 local uart_dir="$run_root/uart${uart:?}"
244 mkdir -p "$uart_dir"
245
246 env_file="$uart_dir/env" quote="1" emit_env "$var" "$val"
247 echo "UART$uart: env has $@"
248}
249
250# Place the binary package a pointer to expect script, and its parameters
251track_expect() {
252 local file="${file:?}"
253 local timeout="${timeout-600}"
254 local run_root="${archive:?}/run"
255
256 local uart_dir="$run_root/uart${uart:?}"
257 mkdir -p "$uart_dir"
258
259 echo "$file" > "$uart_dir/expect"
260 echo "$timeout" > "$uart_dir/timeout"
261
262 echo "UART$uart to be tracked with $file; timeout ${timeout}s"
263
264 # The run script assumes UART0 to be primary. If we're asked to set any
265 # other UART to be primary, set a run environment variable to signal
266 # that to the run script
267 if upon "$set_primary"; then
268 echo "Primary UART set to UART$uart."
269 set_run_env "primary_uart" "$uart"
270 fi
271}
272
273# Extract a FIP in $1 using fiptool
274extract_fip() {
275 local fip="$1"
276
277 if is_url "$1"; then
278 url="$1" fetch_file
279 fip="$(basename "$1")"
280 fi
281
282 "$fiptool" unpack "$fip"
283 echo "Extracted FIP: $fip"
284}
285
286# Report build failure by printing a the tail end of build log. Archive the
287# build log for later inspection
288fail_build() {
289 local log_path
290
291 if upon "$jenkins_run"; then
292 log_path="$BUILD_URL/artifact/artefacts/build.log"
293 else
294 log_path="$build_log"
295 fi
296
297 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600298 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200299 echo "[...]"
300 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600301 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200302 echo
303 echo "See $log_path for full output"
304 echo
305 cp -t "$archive" "$build_log"
306 exit 1;
307}
308
309# Build a FIP with supplied arguments
310build_fip() {
311 (
312 echo "Building FIP with arguments: $@"
313 local tf_env="$workspace/tf.env"
314
315 if [ -f "$tf_env" ]; then
316 set -a
317 source "$tf_env"
318 set +a
319 fi
320
321 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
322 ${fip_targets:-fip} &>>"$build_log" || fail_build
323 )
324}
325
326fip_update() {
327 # Before the update process, check if the given image is supported by
328 # the fiptool. It's assumed that both fiptool and cert_create move in
329 # tandem, and therfore, if one has support, the other has it too.
330 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
331 return 1
332 fi
333
334 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
335 echo "Updating FIP image: $bin_name"
336 # Update HW config. Without TBBR, it's only a matter of using
337 # the update sub-command of fiptool
338 "$fiptool" update "--$bin_name" "${src:-}" \
339 "$archive/fip.bin"
340 else
341 echo "Updating FIP image (TBBR): $bin_name"
342 # With TBBR, we need to unpack, re-create certificates, and then
343 # recreate the FIP.
344 local fip_dir="$(mktempdir)"
345 local bin common_args stem
346 local rot_key="$(get_tf_opt ROT_KEY)"
347
348 rot_key="${rot_key:?}"
349 if ! is_abs "$rot_key"; then
350 rot_key="$tf_root/$rot_key"
351 fi
352
353 # Arguments only for cert_create
354 local cert_args="-n"
355 cert_args+=" --tfw-nvctr ${nvctr:-31}"
356 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
357 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
358 cert_args+=" --rot-key $rot_key"
359
360 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500361 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200362 "hw-config"
363 "tb-fw-config"
364 "nt-fw-config"
365 "soc-fw-config"
366 "tos-fw-config"
367 )
368
369 # Binaries without key certificates
370 declare -A has_no_key_cert
371 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
372 has_no_key_cert["$bin"]="1"
373 done
374
375 # Binaries without certificates
376 declare -A has_no_cert
377 for bin in "hw-config" "${dyn_config_opts[@]}"; do
378 has_no_cert["$bin"]="1"
379 done
380
381 pushd "$fip_dir"
382
383 # Unpack FIP
384 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
385
386 # Remove all existing certificates
387 rm -f *-cert.bin
388
389 # Copy the binary to be updated
390 cp -f "$src" "${bin_name}.bin"
391
392 # FIP unpack dumps binaries with the same name as the option
393 # used to pack it; likewise for certificates. Reverse-engineer
394 # the command line from the binary output.
395 common_args="--trusted-key-cert trusted_key.crt"
396 for bin in *.bin; do
397 stem="${bin%%.bin}"
398 common_args+=" --$stem $bin"
399 if not_upon "${has_no_cert[$stem]}"; then
400 common_args+=" --$stem-cert $stem.crt"
401 fi
402 if not_upon "${has_no_key_cert[$stem]}"; then
403 common_args+=" --$stem-key-cert $stem-key.crt"
404 fi
405 done
406
407 # Create certificates
408 "$cert_create" $cert_args $common_args &>>"$build_log"
409
410 # Recreate and archive FIP
411 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
412 archive_file "fip.bin"
413
414 popd
415 fi
416}
417
418# Update hw-config in FIP, and remove the original DTB afterwards.
419update_fip_hw_config() {
420 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600421 # in configs:
422 # 1. Where BL2 isn't present
423 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200424 case "1" in
425 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600426 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200427 "$(get_tf_opt RESET_TO_SP_MIN)" | \
428 "$(get_tf_opt BL2_AT_EL3)")
429 return 0;;
430 esac
431
432 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
433 # Remove the DTB so that model won't load it
434 rm -f "$archive/dtb.bin"
435 fi
436}
437
438get_scp_opt() {
439 (
440 name="${1:?}"
441 if config_valid "$scp_config_file"; then
442 source "$scp_config_file"
443 echo "${!name}"
444 fi
445 )
446}
447
448get_tftf_opt() {
449 (
450 name="${1:?}"
451 if config_valid "$tftf_config_file"; then
452 source "$tftf_config_file"
453 echo "${!name}"
454 fi
455 )
456}
457
458get_tf_opt() {
459 (
460 name="${1:?}"
461 if config_valid "$tf_config_file"; then
462 source "$tf_config_file"
463 echo "${!name}"
464 fi
465 )
466}
467
468build_tf() {
469 (
470 env_file="$workspace/tf.env"
471 config_file="${tf_build_config:-$tf_config_file}"
472
473 # Build fiptool and all targets by default
474 build_targets="${tf_build_targets:-fiptool all}"
475
476 source "$config_file"
477
478 # If it is a TBBR build, extract the MBED TLS library from archive
479 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ]; then
480 mbedtls_dir="$workspace/mbedtls"
481 if [ ! -d "$mbedtls_dir" ]; then
482 mbedtls_ar="$workspace/mbedtls.tar.gz"
483
484 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
485 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500486 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200487 fi
488
489 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
490 fi
491
492 if [ -f "$env_file" ]; then
493 set -a
494 source "$env_file"
495 set +a
496 fi
497
498 cd "$tf_root"
499
500 # Always distclean when running on Jenkins. Skip distclean when running
501 # locally and explicitly requested.
502 if upon "$jenkins_run" || not_upon "$dont_clean"; then
503 make distclean &>>"$build_log" || fail_build
504 fi
505
506 # Log build command line. It is left unfolded on purpose to assist
507 # copying to clipboard.
508 cat <<EOF | log_separator >/dev/null
509
510Build command line:
511 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
512
513EOF
514
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000515 if not_upon "$local_ci"; then
516 connect_debugger=0
517 fi
518
Fathi Boudra422bf772019-12-02 11:10:16 +0200519 # Build TF. Since build output is being directed to the build log, have
520 # descriptor 3 point to the current terminal for build wrappers to vent.
521 $tf_build_wrapper make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000522 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200523 $build_targets 3>&1 &>>"$build_log" || fail_build
524 )
525}
526
527build_tftf() {
528 (
529 config_file="${tftf_build_config:-$tftf_config_file}"
530
531 # Build tftf target by default
532 build_targets="${tftf_build_targets:-all}"
533
534 source "$config_file"
535
536 cd "$tftf_root"
537
538 # Always distclean when running on Jenkins. Skip distclean when running
539 # locally and explicitly requested.
540 if upon "$jenkins_run" || not_upon "$dont_clean"; then
541 make distclean &>>"$build_log" || fail_build
542 fi
543
544 # TFTF build system cannot reliably deal with -j option, so we avoid
545 # using that.
546
547 # Log build command line
548 cat <<EOF | log_separator >/dev/null
549
550Build command line:
551 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
552
553EOF
554
555 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
556 $build_targets &>>"$build_log" || fail_build
557 )
558}
559
560build_scp() {
561 (
562 config_file="${scp_build_config:-$scp_config_file}"
563
564 source "$config_file"
565
566 cd "$scp_root"
567
568 # Always distclean when running on Jenkins. Skip distclean when running
569 # locally and explicitly requested.
570 if upon "$jenkins_run" || not_upon "$dont_clean"; then
571 make clean &>>"$build_log" || fail_build
572 fi
573
574 # Log build command line. It is left unfolded on purpose to assist
575 # copying to clipboard.
576 cat <<EOF | log_separator >/dev/null
577
578SCP build command line:
579 make $(cat "$config_file" | tr '\n' ' ') MODE=$mode V=1
580
581EOF
582
583 # Build SCP
584 make $(cat "$config_file") MODE="$mode" V=1 &>>"$build_log" \
585 || fail_build
586 )
587}
588
Zelalem219df412020-05-17 19:21:20 -0500589clone_scp_tools() {
590
591 if [ ! -d "$scp_tools_root" ]; then
592 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
593
594 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
595 where="$scp_tools_root" \
596 refspec="${scp_tools_commit}"
597 clone_repo &>>"$build_log"
598 else
599 echo "Already cloned SCP-tools ..." |& log_separator
600 fi
601
602 show_head "$scp_tools_root"
603
604 cd "$scp_tools_root"
605
606 echo "Updating submodules"
607
608 git submodule init
609
610 git submodule update
611
612 cd "scmi"
613
614 git show --quiet --no-color | sed 's/^/ > /g'
615}
616
617clone_tf_for_scp_tools() {
618 scp_tools_arm_tf="$scp_tools_root/arm-tf"
619
620 if [ ! -d "$scp_tools_arm_tf" ]; then
621 echo "Cloning TF-4-SCP-tools ..." |& log_separator
622
623 clone_url="$tf_for_scp_tools_src_repo_url"
624 where="$scp_tools_arm_tf"
625
626 git clone "$clone_url" "$where"
627
628 cd "$scp_tools_arm_tf"
629
630 git checkout --track origin/dev/pedro/juno
631
632 git show --quiet --no-color | sed 's/^/ > /g'
633
634 else
635 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
636 fi
637}
638
639build_scmi_lib_scp_tools() {
640 (
641 cd "$scp_tools_root"
642
643 cd "scmi"
644
645 scp_tools_arm_tf="$scp_tools_root/arm-tf"
646
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600647 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500648
649 std_libs="-I$scp_tools_arm_tf/include/common"
650 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
651 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
652 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
653 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
654 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
655 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
656 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
657 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
658 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
659 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
660 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
661 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
662 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
663
664 cflags="-Og -g"
665 cflags="$cflags -mgeneral-regs-only"
666 cflags="$cflags -mstrict-align"
667 cflags="$cflags -nostdinc"
668 cflags="$cflags -fno-inline"
669 cflags="$cflags -ffreestanding"
670 cflags="$cflags -ffunction-sections"
671 cflags="$cflags -fdata-sections"
672 cflags="$cflags -DAARCH64"
673 cflags="$cflags -DPRId32=\"ld\""
674
675 cflags="$cflags $std_libs"
676
677 protocols="power,system_power,performance,sensor"
678
679 echo "Building SCMI library (SCP-tools) ..."
680
681 make "CROSS_COMPILE=$cross_compile" \
682 "CFLAGS=$cflags" \
683 "PROTOCOLS=$protocols" \
684 "clean" \
685 "all"
686 )
687}
688
689build_tf_for_scp_tools() {
690
691 cd "$scp_tools_root/arm-tf"
692
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600693 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500694
695 if [ "$1" = "release" ]; then
696 echo "Build TF-4-SCP-Tools rls..."
697 else
698 echo "Build TF-4-SCP-Tools dbg..."
699
700 make realclean
701
702 make "BM_TEST=scmi" \
703 "ARM_BOARD_OPTIMISE_MEM=1" \
704 "BM_CSS=juno" \
705 "CSS_USE_SCMI_SDS_DRIVER=1" \
706 "PLAT=juno" \
707 "DEBUG=1" \
708 "PLATFORM=juno" \
709 "CROSS_COMPILE=$cross_compile" \
710 "BM_WORKSPACE=$scp_tools_root/baremetal"
711
712 archive_file "build/juno/debug/bl1.bin"
713
714 archive_file "build/juno/debug/bl2.bin"
715
716 archive_file "build/juno/debug/bl31.bin"
717 fi
718}
719
720build_fip_for_scp_tools() {
721
722 cd "$scp_tools_root/arm-tf"
723
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600724 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500725
726 if [ ! -d "$scp_root/build/product/juno/scp_ramfw/debug" ]; then
727 make fiptool
728 echo "Make FIP 4 SCP-Tools rls..."
729
730 else
731 make fiptool
732 echo "Make FIP 4 SCP-Tools dbg..."
733
734 make "PLAT=juno" \
735 "all" \
736 "fip" \
737 "DEBUG=1" \
738 "CROSS_COMPILE=$cross_compile" \
739 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
740 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
741 "SCP_BL2=$scp_root/build/product/juno/scp_ramfw/debug/bin/firmware.bin"
742
743 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
744 fi
745}
746
747build_cc() {
748# Building code coverage plugin
749 ARM_DIR=/arm
750 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
751 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
752 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
753 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
754 exit -1
755 fi # Error if arm warehouse not found
756 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
757
758 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
759}
760
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100761build_spm() {
762 (
763 env_file="$workspace/spm.env"
764 config_file="${spm_build_config:-$spm_config_file}"
765
766 source "$config_file"
767
768 if [ -f "$env_file" ]; then
769 set -a
770 source "$env_file"
771 set +a
772 fi
773
774 cd "$spm_root"
775
776 # Always clean when running on Jenkins. Skip clean when running
777 # locally and explicitly requested.
778 if upon "$jenkins_run" || not_upon "$dont_clean"; then
779 # make clean fails on a fresh repo where the project has not
780 # yet been built. Hence only clean if out/reference directory
781 # already exists.
782 if [ -d "out/reference" ]; then
783 make clean &>>"$build_log" || fail_build
784 fi
785 fi
786
787 # Log build command line. It is left unfolded on purpose to assist
788 # copying to clipboard.
789 cat <<EOF | log_separator >/dev/null
790
791Build command line:
792 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
793
794EOF
795
796 # Build SPM. Since build output is being directed to the build log, have
797 # descriptor 3 point to the current terminal for build wrappers to vent.
798 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
799 || fail_build
800 )
801}
Zelalem219df412020-05-17 19:21:20 -0500802
Fathi Boudra422bf772019-12-02 11:10:16 +0200803# Set metadata for the whole package so that it can be used by both Jenkins and
804# shell
805set_package_var() {
806 env_file="$artefacts/env" emit_env "$@"
807}
808
809set_tf_build_targets() {
810 echo "Set build target to '${targets:?}'"
811 set_hook_var "tf_build_targets" "$targets"
812}
813
814set_tftf_build_targets() {
815 echo "Set build target to '${targets:?}'"
816 set_hook_var "tftf_build_targets" "$targets"
817}
818
819set_scp_build_targets() {
820 echo "Set build target to '${targets:?}'"
821 set_hook_var "scp_build_targets" "$targets"
822}
823
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100824set_spm_build_targets() {
825 echo "Set build target to '${targets:?}'"
826 set_hook_var "spm_build_targets" "$targets"
827}
828
Fathi Boudra422bf772019-12-02 11:10:16 +0200829# Look under $archive directory for known files such as blX images, kernel, DTB,
830# initrd etc. For each known file foo, if foo.bin exists, then set variable
831# foo_bin to the path of the file. Make the path relative to the workspace so as
832# to remove any @ characters, which Jenkins inserts for parallel runs. If the
833# file doesn't exist, unset its path.
834set_default_bin_paths() {
835 local image image_name image_path path
836 local archive="${archive:?}"
837 local set_vars
838 local var
839
840 pushd "$archive"
841
842 for file in *.bin; do
843 # Get a shell variable from the file's stem
844 var_name="${file%%.*}_bin"
845 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
846
847 # Skip setting the variable if it's already
848 if [ "${!var_name}" ]; then
849 echo "Note: not setting $var_name; already set to ${!var_name}"
850 continue
851 else
852 set_vars+="$var_name "
853 fi
854
855 eval "$var_name=$file"
856 done
857
858 echo "Binary paths set for: "
859 {
860 for var in $set_vars; do
861 echo -n "\$$var "
862 done
863 } | fmt -80 | sed 's/^/ /'
864 echo
865
866 popd
867}
868
869gen_model_params() {
870 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000871 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200872
873 set_default_bin_paths
874 echo "Generating model parameter for $model..."
875 source "$ci_root/model/${model:?}.sh"
876 archive_file "$model_param_file"
877}
878
879set_model_path() {
880 set_run_env "model_path" "${1:?}"
881}
882
Zelalem1af7a7b2020-08-04 17:34:32 -0500883set_model_env() {
884 local var="${1:?}"
885 local val="${2?}"
886 local run_root="${archive:?}/run"
887
888 mkdir -p "$run_root"
889 echo "export $var=$val" >> "$run_root/model_env"
890}
Fathi Boudra422bf772019-12-02 11:10:16 +0200891set_run_env() {
892 local var="${1:?}"
893 local val="${2?}"
894 local run_root="${archive:?}/run"
895
896 mkdir -p "$run_root"
897 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
898}
899
900show_head() {
901 # Display HEAD descripton
902 pushd "$1"
903 git show --quiet --no-color | sed 's/^/ > /g'
904 echo
905 popd
906}
907
908# Choose debug binaries to run; by default, release binaries are chosen to run
909use_debug_bins() {
910 local run_root="${archive:?}/run"
911
912 echo "Choosing debug binaries for execution"
913 set_package_var "BIN_MODE" "debug"
914}
915
916assert_can_git_clone() {
917 local name="${1:?}"
918 local dir="${!name}"
919
920 # If it doesn't exist, it can be cloned into
921 if [ ! -e "$dir" ]; then
922 return 0
923 fi
924
925 # If it's a directory, it must be a Git clone already
926 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
927 # No need to clone again
928 echo "Using existing git clone for $name: $dir"
929 return 1
930 fi
931
932 die "Path $dir exists but is not a git clone"
933}
934
935clone_repo() {
936 if ! is_url "${clone_url?}"; then
937 # For --depth to take effect on local paths, it needs to use the
938 # file:// scheme.
939 clone_url="file://$clone_url"
940 fi
941
942 git clone -q --depth 1 "$clone_url" "${where?}"
943 if [ "$refspec" ]; then
944 pushd "$where"
945 git fetch -q --depth 1 origin "$refspec"
946 git checkout -q FETCH_HEAD
947 popd
948 fi
949}
950
951build_unstable() {
952 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
953}
954
955undo_patch_record() {
956 if [ ! -f "${patch_record:?}" ]; then
957 return
958 fi
959
960 # Undo patches in reverse
961 echo
962 for patch_name in $(tac "$patch_record"); do
963 echo "Undoing $patch_name..."
964 if ! git apply -R "$ci_root/patch/$patch_name"; then
965 if upon "$local_ci"; then
966 echo
967 echo "Your local directory may have been dirtied."
968 echo
969 fi
970 fail_build
971 fi
972 done
973
974 rm -f "$patch_record"
975}
976
977undo_local_patches() {
978 pushd "$tf_root"
979 patch_record="$tf_patch_record" undo_patch_record
980 popd
981
982 if [ -d "$tftf_root" ]; then
983 pushd "$tftf_root"
984 patch_record="$tftf_patch_record" undo_patch_record
985 popd
986 fi
987}
988
989undo_tftf_patches() {
990 pushd "$tftf_root"
991 patch_record="$tftf_patch_record" undo_patch_record
992 popd
993}
994
995undo_tf_patches() {
996 pushd "$tf_root"
997 patch_record="$tf_patch_record" undo_patch_record
998 popd
999}
1000
1001apply_patch() {
1002 # If skip_patches is set, the developer has applied required patches
1003 # manually. They probably want to keep them applied for debugging
1004 # purposes too. This means we don't have to apply/revert them as part of
1005 # build process.
1006 if upon "$skip_patches"; then
1007 echo "Skipped applying ${1:?}..."
1008 return 0
1009 else
1010 echo "Applying ${1:?}..."
1011 fi
1012
1013 if git apply < "$ci_root/patch/$1"; then
1014 echo "$1" >> "${patch_record:?}"
1015 else
1016 if upon "$local_ci"; then
1017 undo_local_patches
1018 fi
1019 fail_build
1020 fi
1021}
1022
1023apply_tftf_patch() {
1024 pushd "$tftf_root"
1025 patch_record="$tftf_patch_record" apply_patch "$1"
1026 popd
1027}
1028
1029apply_tf_patch() {
1030 pushd "$tf_root"
1031 patch_record="$tf_patch_record" apply_patch "$1"
1032 popd
1033}
1034
1035# Clear workspace for a local run
1036if not_upon "$jenkins_run"; then
1037 rm -rf "$workspace"
1038
1039 # Clear residue from previous runs
1040 rm -rf "$archive"
1041fi
1042
1043mkdir -p "$workspace"
1044mkdir -p "$archive"
1045set_package_var "TEST_CONFIG" "$test_config"
1046
1047{
1048echo
1049echo "CONFIGURATION: $test_group/$test_config"
1050echo
1051} |& log_separator
1052
1053tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1054tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1055scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001056scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001057spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001058
1059test_config_file="$ci_root/group/$test_group/$test_config"
1060
1061tf_config_file="$ci_root/tf_config/$tf_config"
1062tftf_config_file="$ci_root/tftf_config/$tftf_config"
1063scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001064scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001065spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001066
1067# File that keeps track of applied patches
1068tf_patch_record="$workspace/tf_patches"
1069tftf_patch_record="$workspace/tftf_patches"
1070
1071pushd "$workspace"
1072
1073if ! config_valid "$tf_config"; then
1074 tf_config=
1075else
1076 echo "Trusted Firmware config:"
1077 echo
1078 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1079 echo
1080fi
1081
1082if ! config_valid "$tftf_config"; then
1083 tftf_config=
1084else
1085 echo "Trusted Firmware TF config:"
1086 echo
1087 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1088 echo
1089fi
1090
1091if ! config_valid "$scp_config"; then
1092 scp_config=
1093else
1094 echo "SCP firmware config:"
1095 echo
1096 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1097 echo
1098fi
1099
Zelalem219df412020-05-17 19:21:20 -05001100if ! config_valid "$scp_tools_config"; then
1101 scp_tools_config=
1102else
1103 echo "SCP Tools config:"
1104 echo
1105 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001106fi
1107
1108if ! config_valid "$spm_config"; then
1109 spm_config=
1110else
1111 echo "SPM config:"
1112 echo
1113 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001114 echo
1115fi
1116
Fathi Boudra422bf772019-12-02 11:10:16 +02001117if ! config_valid "$run_config"; then
1118 run_config=
1119fi
1120
1121if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1122 # If the Trusted Firmware repository has already been checked out, use
1123 # that location. Otherwise, clone one ourselves.
1124 echo "Cloning Trusted Firmware..."
1125 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1126 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1127 show_head "$tf_root"
1128fi
1129
1130if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1131 # If the Trusted Firmware TF repository has already been checked out,
1132 # use that location. Otherwise, clone one ourselves.
1133 echo "Cloning Trusted Firmware TF..."
1134 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1135 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1136 show_head "$tftf_root"
1137fi
1138
1139if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1140 # If the SCP firmware repository has already been checked out,
1141 # use that location. Otherwise, clone one ourselves.
1142 echo "Cloning SCP Firmware..."
1143 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1144 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1145
1146 pushd "$scp_root"
1147
1148 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001149 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001150 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1151 fi
1152
1153 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1154 # then to project filer if accessible.
1155 if [ -z "$cmsis_reference" ]; then
1156 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1157 if [ -d "$cmsis_ref_repo" ]; then
1158 cmsis_reference="--reference $cmsis_ref_repo"
1159 fi
1160 fi
1161
1162 git submodule -q update $cmsis_reference --init
1163
1164 popd
1165
1166 show_head "$scp_root"
1167fi
1168
Zelalem219df412020-05-17 19:21:20 -05001169if [ -n "$cc_config" ] ; then
1170 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1171 # Copy code coverage repository
1172 echo "Cloning Code Coverage..."
1173 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1174 show_head "$cc_root"
1175 fi
1176fi
1177
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001178if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1179 # If the SPM repository has already been checked out, use
1180 # that location. Otherwise, clone one ourselves.
1181 echo "Cloning SPM..."
1182 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1183 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1184
1185 # Query git submodules
1186 pushd "$spm_root"
1187 git submodule update --init
1188 popd
1189
1190 show_head "$spm_root"
1191fi
1192
Fathi Boudra422bf772019-12-02 11:10:16 +02001193if [ "$run_config" ]; then
1194 # Get candidates for run config
1195 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1196 "$run_config")"
1197 if [ -z "$run_config_candiates" ]; then
1198 die "No run config candidates!"
1199 else
1200 echo
1201 echo "Chosen fragments:"
1202 echo
1203 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1204 echo
1205 fi
1206fi
1207
1208call_hook "test_setup"
1209echo
1210
1211if upon "$local_ci"; then
1212 # For local runs, since each config is tried in sequence, it's
1213 # advantageous to run jobs in parallel
1214 if [ "$make_j" ]; then
1215 make_j_opts="-j $make_j"
1216 else
1217 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1218 if [ "$n_cores" ]; then
1219 make_j_opts="-j $n_cores"
1220 fi
1221 fi
1222fi
1223
1224modes="${bin_mode:-debug release}"
1225for mode in $modes; do
1226 # Build with a temporary archive
1227 build_archive="$archive/$mode"
1228 mkdir "$build_archive"
1229
1230 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001231 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001232 DEBUG=1
1233 else
Zelalem219df412020-05-17 19:21:20 -05001234 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001235 DEBUG=0
1236 fi
1237
1238 # Perform builds in a subshell so as not to pollute the current and
1239 # subsequent builds' environment
1240
Zelalem219df412020-05-17 19:21:20 -05001241 if config_valid "$cc_config"; then
1242 # Build code coverage plugin
1243 build_cc
1244 fi
1245
Fathi Boudra422bf772019-12-02 11:10:16 +02001246 # SCP build
1247 if config_valid "$scp_config"; then
1248 (
1249 echo "##########"
1250
1251 # Source platform-specific utilities
1252 plat="$(get_scp_opt PRODUCT)"
1253 plat_utils="$ci_root/${plat}_utils.sh"
1254 if [ -f "$plat_utils" ]; then
1255 source "$plat_utils"
1256 fi
1257
1258 archive="$build_archive"
1259 scp_build_root="$scp_root/build"
1260
1261 echo "Building SCP Firmware ($mode) ..." |& log_separator
1262
1263 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001264 to="$archive" collect_scp_artefacts
1265
1266 echo "##########"
1267 echo
1268 )
1269 fi
1270
Zelalem219df412020-05-17 19:21:20 -05001271 # SCP-tools build
1272 if config_valid "$scp_tools_config"; then
1273 (
1274 echo "##########"
1275
1276 archive="$build_archive"
1277 scp_tools_build_root="$scp_tools_root/build"
1278
1279 clone_scp_tools
1280
1281 echo "##########"
1282 echo
1283
1284 echo "##########"
1285 clone_tf_for_scp_tools
1286 echo "##########"
1287 echo
1288 )
1289 fi
1290
Fathi Boudra422bf772019-12-02 11:10:16 +02001291 # TFTF build
1292 if config_valid "$tftf_config"; then
1293 (
1294 echo "##########"
1295
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001296 plat_utils="$(get_tf_opt PLAT_UTILS)"
1297 if [ -z ${plat_utils} ]; then
1298 # Source platform-specific utilities.
1299 plat="$(get_tftf_opt PLAT)"
1300 plat_utils="$ci_root/${plat}_utils.sh"
1301 else
1302 # Source platform-specific utilities by
1303 # using plat_utils name.
1304 plat_utils="$ci_root/${plat_utils}.sh"
1305 fi
1306
Fathi Boudra422bf772019-12-02 11:10:16 +02001307 if [ -f "$plat_utils" ]; then
1308 source "$plat_utils"
1309 fi
1310
1311 archive="$build_archive"
1312 tftf_build_root="$tftf_root/build"
1313
1314 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1315
1316 # Call pre-build hook
1317 call_hook pre_tftf_build
1318
1319 build_tftf
1320
1321 from="$tftf_build_root" to="$archive" collect_build_artefacts
1322
1323 # Clear any local changes made by applied patches
1324 undo_tftf_patches
1325
1326 echo "##########"
1327 echo
1328 )
1329 fi
1330
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001331 # SPM build
1332 if config_valid "$spm_config"; then
1333 (
1334 echo "##########"
1335
1336 # Get platform name from spm_config file
1337 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1338 plat_utils="$ci_root/${plat}_utils.sh"
1339 if [ -f "$plat_utils" ]; then
1340 source "$plat_utils"
1341 fi
1342
Manish Pandey1e7be852020-11-09 16:04:48 +00001343 # SPM build generates two sets of binaries, one for normal and other
1344 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001345 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001346 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1347 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001348
1349 echo "Building SPM ($mode) ..." |& log_separator
1350
1351 # NOTE: mode has no effect on SPM build (for now), hence debug
1352 # mode is built but subsequent build using release mode just
1353 # goes through with "nothing to do".
1354 build_spm
1355
1356 # Show SPM/Hafnium binary details
Manish Pandey1e7be852020-11-09 16:04:48 +00001357 cksum $spm_build_root/hafnium.bin $hafnium_build_root/hafnium.bin
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001358
Manish Pandey1e7be852020-11-09 16:04:48 +00001359 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001360
1361 echo "##########"
1362 echo
1363 )
1364 fi
1365
Fathi Boudra422bf772019-12-02 11:10:16 +02001366 # TF build
1367 if config_valid "$tf_config"; then
1368 (
1369 echo "##########"
1370
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001371 plat_utils="$(get_tf_opt PLAT_UTILS)"
1372 if [ -z ${plat_utils} ]; then
1373 # Source platform-specific utilities.
1374 plat="$(get_tf_opt PLAT)"
1375 plat_utils="$ci_root/${plat}_utils.sh"
1376 else
1377 # Source platform-specific utilities by
1378 # using plat_utils name.
1379 plat_utils="$ci_root/${plat_utils}.sh"
1380 fi
1381
Fathi Boudra422bf772019-12-02 11:10:16 +02001382 if [ -f "$plat_utils" ]; then
1383 source "$plat_utils"
1384 fi
1385
1386 archive="$build_archive"
1387 tf_build_root="$tf_root/build"
1388
1389 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1390
1391 # Call pre-build hook
1392 call_hook pre_tf_build
1393
1394 build_tf
1395
1396 # Call post-build hook
1397 call_hook post_tf_build
1398
1399 # Pre-archive hook
1400 call_hook pre_tf_archive
1401
1402 from="$tf_build_root" to="$archive" collect_build_artefacts
1403
1404 # Post-archive hook
1405 call_hook post_tf_archive
1406
1407 call_hook fetch_tf_resource
1408 call_hook post_fetch_tf_resource
1409
1410 # Clear any local changes made by applied patches
1411 undo_tf_patches
1412
1413 echo "##########"
1414 )
1415 fi
1416
1417 echo
1418 echo
1419done
1420
1421call_hook pre_package
1422
1423call_hook post_package
1424
1425if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001426 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001427fi
1428
1429echo
1430echo "Done"