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