blob: 099a82a18370799aacfa9a26123a223dcbca3b5b [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
Joel Goddard3ad03062021-03-16 16:47:42 +0000630 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500631
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\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000674 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500675
676 cflags="$cflags $std_libs"
677
Joel Goddard3ad03062021-03-16 16:47:42 +0000678 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500679
680 echo "Building SCMI library (SCP-tools) ..."
681
682 make "CROSS_COMPILE=$cross_compile" \
683 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000684 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500685 "PROTOCOLS=$protocols" \
686 "clean" \
687 "all"
688 )
689}
690
691build_tf_for_scp_tools() {
692
693 cd "$scp_tools_root/arm-tf"
694
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600695 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500696
697 if [ "$1" = "release" ]; then
698 echo "Build TF-4-SCP-Tools rls..."
699 else
700 echo "Build TF-4-SCP-Tools dbg..."
701
702 make realclean
703
704 make "BM_TEST=scmi" \
705 "ARM_BOARD_OPTIMISE_MEM=1" \
706 "BM_CSS=juno" \
707 "CSS_USE_SCMI_SDS_DRIVER=1" \
708 "PLAT=juno" \
709 "DEBUG=1" \
710 "PLATFORM=juno" \
711 "CROSS_COMPILE=$cross_compile" \
712 "BM_WORKSPACE=$scp_tools_root/baremetal"
713
714 archive_file "build/juno/debug/bl1.bin"
715
716 archive_file "build/juno/debug/bl2.bin"
717
718 archive_file "build/juno/debug/bl31.bin"
719 fi
720}
721
722build_fip_for_scp_tools() {
723
724 cd "$scp_tools_root/arm-tf"
725
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600726 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500727
728 if [ ! -d "$scp_root/build/product/juno/scp_ramfw/debug" ]; then
729 make fiptool
730 echo "Make FIP 4 SCP-Tools rls..."
731
732 else
733 make fiptool
734 echo "Make FIP 4 SCP-Tools dbg..."
735
736 make "PLAT=juno" \
737 "all" \
738 "fip" \
739 "DEBUG=1" \
740 "CROSS_COMPILE=$cross_compile" \
741 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
742 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
743 "SCP_BL2=$scp_root/build/product/juno/scp_ramfw/debug/bin/firmware.bin"
744
745 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
746 fi
747}
748
749build_cc() {
750# Building code coverage plugin
751 ARM_DIR=/arm
752 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
753 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
754 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
755 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
756 exit -1
757 fi # Error if arm warehouse not found
758 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
759
760 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
761}
762
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100763build_spm() {
764 (
765 env_file="$workspace/spm.env"
766 config_file="${spm_build_config:-$spm_config_file}"
767
768 source "$config_file"
769
770 if [ -f "$env_file" ]; then
771 set -a
772 source "$env_file"
773 set +a
774 fi
775
776 cd "$spm_root"
777
778 # Always clean when running on Jenkins. Skip clean when running
779 # locally and explicitly requested.
780 if upon "$jenkins_run" || not_upon "$dont_clean"; then
781 # make clean fails on a fresh repo where the project has not
782 # yet been built. Hence only clean if out/reference directory
783 # already exists.
784 if [ -d "out/reference" ]; then
785 make clean &>>"$build_log" || fail_build
786 fi
787 fi
788
789 # Log build command line. It is left unfolded on purpose to assist
790 # copying to clipboard.
791 cat <<EOF | log_separator >/dev/null
792
793Build command line:
794 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
795
796EOF
797
798 # Build SPM. Since build output is being directed to the build log, have
799 # descriptor 3 point to the current terminal for build wrappers to vent.
800 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
801 || fail_build
802 )
803}
Zelalem219df412020-05-17 19:21:20 -0500804
Fathi Boudra422bf772019-12-02 11:10:16 +0200805# Set metadata for the whole package so that it can be used by both Jenkins and
806# shell
807set_package_var() {
808 env_file="$artefacts/env" emit_env "$@"
809}
810
811set_tf_build_targets() {
812 echo "Set build target to '${targets:?}'"
813 set_hook_var "tf_build_targets" "$targets"
814}
815
816set_tftf_build_targets() {
817 echo "Set build target to '${targets:?}'"
818 set_hook_var "tftf_build_targets" "$targets"
819}
820
821set_scp_build_targets() {
822 echo "Set build target to '${targets:?}'"
823 set_hook_var "scp_build_targets" "$targets"
824}
825
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100826set_spm_build_targets() {
827 echo "Set build target to '${targets:?}'"
828 set_hook_var "spm_build_targets" "$targets"
829}
830
Fathi Boudra422bf772019-12-02 11:10:16 +0200831# Look under $archive directory for known files such as blX images, kernel, DTB,
832# initrd etc. For each known file foo, if foo.bin exists, then set variable
833# foo_bin to the path of the file. Make the path relative to the workspace so as
834# to remove any @ characters, which Jenkins inserts for parallel runs. If the
835# file doesn't exist, unset its path.
836set_default_bin_paths() {
837 local image image_name image_path path
838 local archive="${archive:?}"
839 local set_vars
840 local var
841
842 pushd "$archive"
843
844 for file in *.bin; do
845 # Get a shell variable from the file's stem
846 var_name="${file%%.*}_bin"
847 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
848
849 # Skip setting the variable if it's already
850 if [ "${!var_name}" ]; then
851 echo "Note: not setting $var_name; already set to ${!var_name}"
852 continue
853 else
854 set_vars+="$var_name "
855 fi
856
857 eval "$var_name=$file"
858 done
859
860 echo "Binary paths set for: "
861 {
862 for var in $set_vars; do
863 echo -n "\$$var "
864 done
865 } | fmt -80 | sed 's/^/ /'
866 echo
867
868 popd
869}
870
871gen_model_params() {
872 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000873 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200874
875 set_default_bin_paths
876 echo "Generating model parameter for $model..."
877 source "$ci_root/model/${model:?}.sh"
878 archive_file "$model_param_file"
879}
880
881set_model_path() {
882 set_run_env "model_path" "${1:?}"
883}
884
Zelalem1af7a7b2020-08-04 17:34:32 -0500885set_model_env() {
886 local var="${1:?}"
887 local val="${2?}"
888 local run_root="${archive:?}/run"
889
890 mkdir -p "$run_root"
891 echo "export $var=$val" >> "$run_root/model_env"
892}
Fathi Boudra422bf772019-12-02 11:10:16 +0200893set_run_env() {
894 local var="${1:?}"
895 local val="${2?}"
896 local run_root="${archive:?}/run"
897
898 mkdir -p "$run_root"
899 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
900}
901
902show_head() {
903 # Display HEAD descripton
904 pushd "$1"
905 git show --quiet --no-color | sed 's/^/ > /g'
906 echo
907 popd
908}
909
910# Choose debug binaries to run; by default, release binaries are chosen to run
911use_debug_bins() {
912 local run_root="${archive:?}/run"
913
914 echo "Choosing debug binaries for execution"
915 set_package_var "BIN_MODE" "debug"
916}
917
918assert_can_git_clone() {
919 local name="${1:?}"
920 local dir="${!name}"
921
922 # If it doesn't exist, it can be cloned into
923 if [ ! -e "$dir" ]; then
924 return 0
925 fi
926
927 # If it's a directory, it must be a Git clone already
928 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
929 # No need to clone again
930 echo "Using existing git clone for $name: $dir"
931 return 1
932 fi
933
934 die "Path $dir exists but is not a git clone"
935}
936
937clone_repo() {
938 if ! is_url "${clone_url?}"; then
939 # For --depth to take effect on local paths, it needs to use the
940 # file:// scheme.
941 clone_url="file://$clone_url"
942 fi
943
944 git clone -q --depth 1 "$clone_url" "${where?}"
945 if [ "$refspec" ]; then
946 pushd "$where"
947 git fetch -q --depth 1 origin "$refspec"
948 git checkout -q FETCH_HEAD
949 popd
950 fi
951}
952
953build_unstable() {
954 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
955}
956
957undo_patch_record() {
958 if [ ! -f "${patch_record:?}" ]; then
959 return
960 fi
961
962 # Undo patches in reverse
963 echo
964 for patch_name in $(tac "$patch_record"); do
965 echo "Undoing $patch_name..."
966 if ! git apply -R "$ci_root/patch/$patch_name"; then
967 if upon "$local_ci"; then
968 echo
969 echo "Your local directory may have been dirtied."
970 echo
971 fi
972 fail_build
973 fi
974 done
975
976 rm -f "$patch_record"
977}
978
979undo_local_patches() {
980 pushd "$tf_root"
981 patch_record="$tf_patch_record" undo_patch_record
982 popd
983
984 if [ -d "$tftf_root" ]; then
985 pushd "$tftf_root"
986 patch_record="$tftf_patch_record" undo_patch_record
987 popd
988 fi
989}
990
991undo_tftf_patches() {
992 pushd "$tftf_root"
993 patch_record="$tftf_patch_record" undo_patch_record
994 popd
995}
996
997undo_tf_patches() {
998 pushd "$tf_root"
999 patch_record="$tf_patch_record" undo_patch_record
1000 popd
1001}
1002
1003apply_patch() {
1004 # If skip_patches is set, the developer has applied required patches
1005 # manually. They probably want to keep them applied for debugging
1006 # purposes too. This means we don't have to apply/revert them as part of
1007 # build process.
1008 if upon "$skip_patches"; then
1009 echo "Skipped applying ${1:?}..."
1010 return 0
1011 else
1012 echo "Applying ${1:?}..."
1013 fi
1014
1015 if git apply < "$ci_root/patch/$1"; then
1016 echo "$1" >> "${patch_record:?}"
1017 else
1018 if upon "$local_ci"; then
1019 undo_local_patches
1020 fi
1021 fail_build
1022 fi
1023}
1024
1025apply_tftf_patch() {
1026 pushd "$tftf_root"
1027 patch_record="$tftf_patch_record" apply_patch "$1"
1028 popd
1029}
1030
1031apply_tf_patch() {
1032 pushd "$tf_root"
1033 patch_record="$tf_patch_record" apply_patch "$1"
1034 popd
1035}
1036
1037# Clear workspace for a local run
1038if not_upon "$jenkins_run"; then
1039 rm -rf "$workspace"
1040
1041 # Clear residue from previous runs
1042 rm -rf "$archive"
1043fi
1044
1045mkdir -p "$workspace"
1046mkdir -p "$archive"
1047set_package_var "TEST_CONFIG" "$test_config"
1048
1049{
1050echo
1051echo "CONFIGURATION: $test_group/$test_config"
1052echo
1053} |& log_separator
1054
1055tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1056tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1057scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001058scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001059spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001060
1061test_config_file="$ci_root/group/$test_group/$test_config"
1062
1063tf_config_file="$ci_root/tf_config/$tf_config"
1064tftf_config_file="$ci_root/tftf_config/$tftf_config"
1065scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001066scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001067spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001068
1069# File that keeps track of applied patches
1070tf_patch_record="$workspace/tf_patches"
1071tftf_patch_record="$workspace/tftf_patches"
1072
1073pushd "$workspace"
1074
1075if ! config_valid "$tf_config"; then
1076 tf_config=
1077else
1078 echo "Trusted Firmware config:"
1079 echo
1080 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1081 echo
1082fi
1083
1084if ! config_valid "$tftf_config"; then
1085 tftf_config=
1086else
1087 echo "Trusted Firmware TF config:"
1088 echo
1089 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1090 echo
1091fi
1092
1093if ! config_valid "$scp_config"; then
1094 scp_config=
1095else
1096 echo "SCP firmware config:"
1097 echo
1098 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1099 echo
1100fi
1101
Zelalem219df412020-05-17 19:21:20 -05001102if ! config_valid "$scp_tools_config"; then
1103 scp_tools_config=
1104else
1105 echo "SCP Tools config:"
1106 echo
1107 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001108fi
1109
1110if ! config_valid "$spm_config"; then
1111 spm_config=
1112else
1113 echo "SPM config:"
1114 echo
1115 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001116 echo
1117fi
1118
Fathi Boudra422bf772019-12-02 11:10:16 +02001119if ! config_valid "$run_config"; then
1120 run_config=
1121fi
1122
1123if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1124 # If the Trusted Firmware repository has already been checked out, use
1125 # that location. Otherwise, clone one ourselves.
1126 echo "Cloning Trusted Firmware..."
1127 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1128 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1129 show_head "$tf_root"
1130fi
1131
1132if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1133 # If the Trusted Firmware TF repository has already been checked out,
1134 # use that location. Otherwise, clone one ourselves.
1135 echo "Cloning Trusted Firmware TF..."
1136 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1137 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1138 show_head "$tftf_root"
1139fi
1140
1141if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1142 # If the SCP firmware repository has already been checked out,
1143 # use that location. Otherwise, clone one ourselves.
1144 echo "Cloning SCP Firmware..."
1145 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1146 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1147
1148 pushd "$scp_root"
1149
1150 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001151 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001152 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1153 fi
1154
1155 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1156 # then to project filer if accessible.
1157 if [ -z "$cmsis_reference" ]; then
1158 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1159 if [ -d "$cmsis_ref_repo" ]; then
1160 cmsis_reference="--reference $cmsis_ref_repo"
1161 fi
1162 fi
1163
1164 git submodule -q update $cmsis_reference --init
1165
1166 popd
1167
1168 show_head "$scp_root"
1169fi
1170
Zelalem219df412020-05-17 19:21:20 -05001171if [ -n "$cc_config" ] ; then
1172 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1173 # Copy code coverage repository
1174 echo "Cloning Code Coverage..."
1175 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1176 show_head "$cc_root"
1177 fi
1178fi
1179
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001180if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1181 # If the SPM repository has already been checked out, use
1182 # that location. Otherwise, clone one ourselves.
1183 echo "Cloning SPM..."
1184 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1185 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1186
1187 # Query git submodules
1188 pushd "$spm_root"
1189 git submodule update --init
1190 popd
1191
1192 show_head "$spm_root"
1193fi
1194
Fathi Boudra422bf772019-12-02 11:10:16 +02001195if [ "$run_config" ]; then
1196 # Get candidates for run config
1197 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1198 "$run_config")"
1199 if [ -z "$run_config_candiates" ]; then
1200 die "No run config candidates!"
1201 else
1202 echo
1203 echo "Chosen fragments:"
1204 echo
1205 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1206 echo
1207 fi
1208fi
1209
1210call_hook "test_setup"
1211echo
1212
1213if upon "$local_ci"; then
1214 # For local runs, since each config is tried in sequence, it's
1215 # advantageous to run jobs in parallel
1216 if [ "$make_j" ]; then
1217 make_j_opts="-j $make_j"
1218 else
1219 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1220 if [ "$n_cores" ]; then
1221 make_j_opts="-j $n_cores"
1222 fi
1223 fi
1224fi
1225
1226modes="${bin_mode:-debug release}"
1227for mode in $modes; do
1228 # Build with a temporary archive
1229 build_archive="$archive/$mode"
1230 mkdir "$build_archive"
1231
1232 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001233 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001234 DEBUG=1
1235 else
Zelalem219df412020-05-17 19:21:20 -05001236 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001237 DEBUG=0
1238 fi
1239
1240 # Perform builds in a subshell so as not to pollute the current and
1241 # subsequent builds' environment
1242
Zelalem219df412020-05-17 19:21:20 -05001243 if config_valid "$cc_config"; then
1244 # Build code coverage plugin
1245 build_cc
1246 fi
1247
Fathi Boudra422bf772019-12-02 11:10:16 +02001248 # SCP build
1249 if config_valid "$scp_config"; then
1250 (
1251 echo "##########"
1252
1253 # Source platform-specific utilities
1254 plat="$(get_scp_opt PRODUCT)"
1255 plat_utils="$ci_root/${plat}_utils.sh"
1256 if [ -f "$plat_utils" ]; then
1257 source "$plat_utils"
1258 fi
1259
1260 archive="$build_archive"
1261 scp_build_root="$scp_root/build"
1262
1263 echo "Building SCP Firmware ($mode) ..." |& log_separator
1264
1265 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001266 to="$archive" collect_scp_artefacts
1267
1268 echo "##########"
1269 echo
1270 )
1271 fi
1272
Zelalem219df412020-05-17 19:21:20 -05001273 # SCP-tools build
1274 if config_valid "$scp_tools_config"; then
1275 (
1276 echo "##########"
1277
1278 archive="$build_archive"
1279 scp_tools_build_root="$scp_tools_root/build"
1280
1281 clone_scp_tools
1282
1283 echo "##########"
1284 echo
1285
1286 echo "##########"
1287 clone_tf_for_scp_tools
1288 echo "##########"
1289 echo
1290 )
1291 fi
1292
Fathi Boudra422bf772019-12-02 11:10:16 +02001293 # TFTF build
1294 if config_valid "$tftf_config"; then
1295 (
1296 echo "##########"
1297
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001298 plat_utils="$(get_tf_opt PLAT_UTILS)"
1299 if [ -z ${plat_utils} ]; then
1300 # Source platform-specific utilities.
1301 plat="$(get_tftf_opt PLAT)"
1302 plat_utils="$ci_root/${plat}_utils.sh"
1303 else
1304 # Source platform-specific utilities by
1305 # using plat_utils name.
1306 plat_utils="$ci_root/${plat_utils}.sh"
1307 fi
1308
Fathi Boudra422bf772019-12-02 11:10:16 +02001309 if [ -f "$plat_utils" ]; then
1310 source "$plat_utils"
1311 fi
1312
1313 archive="$build_archive"
1314 tftf_build_root="$tftf_root/build"
1315
1316 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1317
1318 # Call pre-build hook
1319 call_hook pre_tftf_build
1320
1321 build_tftf
1322
1323 from="$tftf_build_root" to="$archive" collect_build_artefacts
1324
1325 # Clear any local changes made by applied patches
1326 undo_tftf_patches
1327
1328 echo "##########"
1329 echo
1330 )
1331 fi
1332
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001333 # SPM build
1334 if config_valid "$spm_config"; then
1335 (
1336 echo "##########"
1337
1338 # Get platform name from spm_config file
1339 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1340 plat_utils="$ci_root/${plat}_utils.sh"
1341 if [ -f "$plat_utils" ]; then
1342 source "$plat_utils"
1343 fi
1344
Manish Pandey1e7be852020-11-09 16:04:48 +00001345 # SPM build generates two sets of binaries, one for normal and other
1346 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001347 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001348 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1349 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001350
1351 echo "Building SPM ($mode) ..." |& log_separator
1352
1353 # NOTE: mode has no effect on SPM build (for now), hence debug
1354 # mode is built but subsequent build using release mode just
1355 # goes through with "nothing to do".
1356 build_spm
1357
1358 # Show SPM/Hafnium binary details
Manish Pandey1e7be852020-11-09 16:04:48 +00001359 cksum $spm_build_root/hafnium.bin $hafnium_build_root/hafnium.bin
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001360
Manish Pandey1e7be852020-11-09 16:04:48 +00001361 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001362
1363 echo "##########"
1364 echo
1365 )
1366 fi
1367
Fathi Boudra422bf772019-12-02 11:10:16 +02001368 # TF build
1369 if config_valid "$tf_config"; then
1370 (
1371 echo "##########"
1372
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001373 plat_utils="$(get_tf_opt PLAT_UTILS)"
1374 if [ -z ${plat_utils} ]; then
1375 # Source platform-specific utilities.
1376 plat="$(get_tf_opt PLAT)"
1377 plat_utils="$ci_root/${plat}_utils.sh"
1378 else
1379 # Source platform-specific utilities by
1380 # using plat_utils name.
1381 plat_utils="$ci_root/${plat_utils}.sh"
1382 fi
1383
Fathi Boudra422bf772019-12-02 11:10:16 +02001384 if [ -f "$plat_utils" ]; then
1385 source "$plat_utils"
1386 fi
1387
1388 archive="$build_archive"
1389 tf_build_root="$tf_root/build"
1390
1391 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1392
1393 # Call pre-build hook
1394 call_hook pre_tf_build
1395
1396 build_tf
1397
1398 # Call post-build hook
1399 call_hook post_tf_build
1400
1401 # Pre-archive hook
1402 call_hook pre_tf_archive
1403
1404 from="$tf_build_root" to="$archive" collect_build_artefacts
1405
1406 # Post-archive hook
1407 call_hook post_tf_archive
1408
1409 call_hook fetch_tf_resource
1410 call_hook post_fetch_tf_resource
1411
1412 # Clear any local changes made by applied patches
1413 undo_tf_patches
1414
1415 echo "##########"
1416 )
1417 fi
1418
1419 echo
1420 echo
1421done
1422
1423call_hook pre_package
1424
1425call_hook post_package
1426
1427if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001428 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001429fi
1430
1431echo
1432echo "Done"