blob: e15eaf48d3761d373f810737ce17b8ff5f3cc063 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05003# Copyright (c) 2019-2021 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
Madhukar Pappireddy1e953722021-11-08 15:23:02 -0600271
272 # UART used by payload(such as tftf, Linux) may not be the same as the
273 # primary UART. Set a run environment variable to track the payload
274 # UART which is tracked to check if the test has finished sucessfully.
275 if upon "$set_payload_uart"; then
276 echo "Payload uses UART$uart."
277 set_run_env "payload_uart" "$uart"
278 fi
Fathi Boudra422bf772019-12-02 11:10:16 +0200279}
280
281# Extract a FIP in $1 using fiptool
282extract_fip() {
283 local fip="$1"
284
285 if is_url "$1"; then
286 url="$1" fetch_file
287 fip="$(basename "$1")"
288 fi
289
290 "$fiptool" unpack "$fip"
291 echo "Extracted FIP: $fip"
292}
293
294# Report build failure by printing a the tail end of build log. Archive the
295# build log for later inspection
296fail_build() {
297 local log_path
298
299 if upon "$jenkins_run"; then
300 log_path="$BUILD_URL/artifact/artefacts/build.log"
301 else
302 log_path="$build_log"
303 fi
304
305 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600306 echo "Build failed! Full build log below:"
Fathi Boudra422bf772019-12-02 11:10:16 +0200307 echo "[...]"
308 echo
Leonardo Sandovalae97eda2020-11-12 10:07:03 -0600309 cat "$build_log"
Fathi Boudra422bf772019-12-02 11:10:16 +0200310 echo
311 echo "See $log_path for full output"
312 echo
313 cp -t "$archive" "$build_log"
314 exit 1;
315}
316
317# Build a FIP with supplied arguments
318build_fip() {
319 (
320 echo "Building FIP with arguments: $@"
321 local tf_env="$workspace/tf.env"
322
323 if [ -f "$tf_env" ]; then
324 set -a
325 source "$tf_env"
326 set +a
327 fi
328
329 make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \
330 ${fip_targets:-fip} &>>"$build_log" || fail_build
331 )
332}
333
334fip_update() {
335 # Before the update process, check if the given image is supported by
336 # the fiptool. It's assumed that both fiptool and cert_create move in
337 # tandem, and therfore, if one has support, the other has it too.
338 if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then
339 return 1
340 fi
341
342 if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then
343 echo "Updating FIP image: $bin_name"
344 # Update HW config. Without TBBR, it's only a matter of using
345 # the update sub-command of fiptool
346 "$fiptool" update "--$bin_name" "${src:-}" \
347 "$archive/fip.bin"
348 else
349 echo "Updating FIP image (TBBR): $bin_name"
350 # With TBBR, we need to unpack, re-create certificates, and then
351 # recreate the FIP.
352 local fip_dir="$(mktempdir)"
353 local bin common_args stem
354 local rot_key="$(get_tf_opt ROT_KEY)"
355
356 rot_key="${rot_key:?}"
357 if ! is_abs "$rot_key"; then
358 rot_key="$tf_root/$rot_key"
359 fi
360
361 # Arguments only for cert_create
362 local cert_args="-n"
363 cert_args+=" --tfw-nvctr ${nvctr:-31}"
364 cert_args+=" --ntfw-nvctr ${nvctr:-223}"
365 cert_args+=" --key-alg ${KEY_ALG:-rsa}"
366 cert_args+=" --rot-key $rot_key"
367
368 local dyn_config_opts=(
Zelalem1af7a7b2020-08-04 17:34:32 -0500369 "fw-config"
Fathi Boudra422bf772019-12-02 11:10:16 +0200370 "hw-config"
371 "tb-fw-config"
372 "nt-fw-config"
373 "soc-fw-config"
374 "tos-fw-config"
375 )
376
377 # Binaries without key certificates
378 declare -A has_no_key_cert
379 for bin in "tb-fw" "${dyn_config_opts[@]}"; do
380 has_no_key_cert["$bin"]="1"
381 done
382
383 # Binaries without certificates
384 declare -A has_no_cert
385 for bin in "hw-config" "${dyn_config_opts[@]}"; do
386 has_no_cert["$bin"]="1"
387 done
388
389 pushd "$fip_dir"
390
391 # Unpack FIP
392 "$fiptool" unpack "$archive/fip.bin" &>>"$build_log"
393
394 # Remove all existing certificates
395 rm -f *-cert.bin
396
397 # Copy the binary to be updated
398 cp -f "$src" "${bin_name}.bin"
399
400 # FIP unpack dumps binaries with the same name as the option
401 # used to pack it; likewise for certificates. Reverse-engineer
402 # the command line from the binary output.
403 common_args="--trusted-key-cert trusted_key.crt"
404 for bin in *.bin; do
405 stem="${bin%%.bin}"
406 common_args+=" --$stem $bin"
407 if not_upon "${has_no_cert[$stem]}"; then
408 common_args+=" --$stem-cert $stem.crt"
409 fi
410 if not_upon "${has_no_key_cert[$stem]}"; then
411 common_args+=" --$stem-key-cert $stem-key.crt"
412 fi
413 done
414
415 # Create certificates
416 "$cert_create" $cert_args $common_args &>>"$build_log"
417
418 # Recreate and archive FIP
419 "$fiptool" create $common_args "fip.bin" &>>"$build_log"
420 archive_file "fip.bin"
421
422 popd
423 fi
424}
425
426# Update hw-config in FIP, and remove the original DTB afterwards.
427update_fip_hw_config() {
428 # The DTB needs to be loaded by the model (and not updated in the FIP)
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600429 # in configs:
430 # 1. Where BL2 isn't present
431 # 2. Where we boot to Linux directly as BL33
Fathi Boudra422bf772019-12-02 11:10:16 +0200432 case "1" in
433 "$(get_tf_opt RESET_TO_BL31)" | \
Madhukar Pappireddy9062ebf2021-03-02 17:07:06 -0600434 "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \
Fathi Boudra422bf772019-12-02 11:10:16 +0200435 "$(get_tf_opt RESET_TO_SP_MIN)" | \
436 "$(get_tf_opt BL2_AT_EL3)")
437 return 0;;
438 esac
439
440 if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then
441 # Remove the DTB so that model won't load it
442 rm -f "$archive/dtb.bin"
443 fi
444}
445
446get_scp_opt() {
447 (
448 name="${1:?}"
449 if config_valid "$scp_config_file"; then
450 source "$scp_config_file"
451 echo "${!name}"
452 fi
453 )
454}
455
456get_tftf_opt() {
457 (
458 name="${1:?}"
459 if config_valid "$tftf_config_file"; then
460 source "$tftf_config_file"
461 echo "${!name}"
462 fi
463 )
464}
465
466get_tf_opt() {
467 (
468 name="${1:?}"
469 if config_valid "$tf_config_file"; then
470 source "$tf_config_file"
471 echo "${!name}"
472 fi
473 )
474}
475
476build_tf() {
477 (
478 env_file="$workspace/tf.env"
479 config_file="${tf_build_config:-$tf_config_file}"
480
481 # Build fiptool and all targets by default
482 build_targets="${tf_build_targets:-fiptool all}"
483
484 source "$config_file"
485
486 # If it is a TBBR build, extract the MBED TLS library from archive
487 if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ]; then
488 mbedtls_dir="$workspace/mbedtls"
489 if [ ! -d "$mbedtls_dir" ]; then
490 mbedtls_ar="$workspace/mbedtls.tar.gz"
491
492 url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file
493 mkdir "$mbedtls_dir"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500494 extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200495 fi
496
497 emit_env "MBEDTLS_DIR" "$mbedtls_dir"
498 fi
499
500 if [ -f "$env_file" ]; then
501 set -a
502 source "$env_file"
503 set +a
504 fi
505
506 cd "$tf_root"
507
508 # Always distclean when running on Jenkins. Skip distclean when running
509 # locally and explicitly requested.
510 if upon "$jenkins_run" || not_upon "$dont_clean"; then
511 make distclean &>>"$build_log" || fail_build
512 fi
513
514 # Log build command line. It is left unfolded on purpose to assist
515 # copying to clipboard.
516 cat <<EOF | log_separator >/dev/null
517
518Build command line:
519 $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
520
521EOF
522
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000523 if not_upon "$local_ci"; then
524 connect_debugger=0
525 fi
526
Fathi Boudra422bf772019-12-02 11:10:16 +0200527 # Build TF. Since build output is being directed to the build log, have
528 # descriptor 3 point to the current terminal for build wrappers to vent.
529 $tf_build_wrapper make $make_j_opts $(cat "$config_file") \
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000530 DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \
Fathi Boudra422bf772019-12-02 11:10:16 +0200531 $build_targets 3>&1 &>>"$build_log" || fail_build
532 )
533}
534
535build_tftf() {
536 (
537 config_file="${tftf_build_config:-$tftf_config_file}"
538
539 # Build tftf target by default
540 build_targets="${tftf_build_targets:-all}"
541
542 source "$config_file"
543
544 cd "$tftf_root"
545
546 # Always distclean when running on Jenkins. Skip distclean when running
547 # locally and explicitly requested.
548 if upon "$jenkins_run" || not_upon "$dont_clean"; then
549 make distclean &>>"$build_log" || fail_build
550 fi
551
552 # TFTF build system cannot reliably deal with -j option, so we avoid
553 # using that.
554
555 # Log build command line
556 cat <<EOF | log_separator >/dev/null
557
558Build command line:
559 make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets
560
561EOF
562
563 make $(cat "$config_file") DEBUG="$DEBUG" V=1 \
564 $build_targets &>>"$build_log" || fail_build
565 )
566}
567
568build_scp() {
569 (
570 config_file="${scp_build_config:-$scp_config_file}"
571
572 source "$config_file"
573
574 cd "$scp_root"
575
576 # Always distclean when running on Jenkins. Skip distclean when running
577 # locally and explicitly requested.
578 if upon "$jenkins_run" || not_upon "$dont_clean"; then
579 make clean &>>"$build_log" || fail_build
580 fi
581
582 # Log build command line. It is left unfolded on purpose to assist
583 # copying to clipboard.
584 cat <<EOF | log_separator >/dev/null
585
586SCP build command line:
587 make $(cat "$config_file" | tr '\n' ' ') MODE=$mode V=1
588
589EOF
590
591 # Build SCP
592 make $(cat "$config_file") MODE="$mode" V=1 &>>"$build_log" \
593 || fail_build
594 )
595}
596
Zelalem219df412020-05-17 19:21:20 -0500597clone_scp_tools() {
598
599 if [ ! -d "$scp_tools_root" ]; then
600 echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator
601
602 clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \
603 where="$scp_tools_root" \
604 refspec="${scp_tools_commit}"
605 clone_repo &>>"$build_log"
606 else
607 echo "Already cloned SCP-tools ..." |& log_separator
608 fi
609
610 show_head "$scp_tools_root"
611
612 cd "$scp_tools_root"
613
614 echo "Updating submodules"
615
616 git submodule init
617
618 git submodule update
619
620 cd "scmi"
621
622 git show --quiet --no-color | sed 's/^/ > /g'
623}
624
625clone_tf_for_scp_tools() {
626 scp_tools_arm_tf="$scp_tools_root/arm-tf"
627
628 if [ ! -d "$scp_tools_arm_tf" ]; then
629 echo "Cloning TF-4-SCP-tools ..." |& log_separator
630
631 clone_url="$tf_for_scp_tools_src_repo_url"
632 where="$scp_tools_arm_tf"
633
634 git clone "$clone_url" "$where"
635
636 cd "$scp_tools_arm_tf"
637
Joel Goddard3ad03062021-03-16 16:47:42 +0000638 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500639
640 git show --quiet --no-color | sed 's/^/ > /g'
641
642 else
643 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
644 fi
645}
646
647build_scmi_lib_scp_tools() {
648 (
649 cd "$scp_tools_root"
650
651 cd "scmi"
652
653 scp_tools_arm_tf="$scp_tools_root/arm-tf"
654
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600655 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500656
657 std_libs="-I$scp_tools_arm_tf/include/common"
658 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
659 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
660 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
661 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
662 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
663 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
664 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
665 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
666 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
667 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
668 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
669 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
670 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
671
672 cflags="-Og -g"
673 cflags="$cflags -mgeneral-regs-only"
674 cflags="$cflags -mstrict-align"
675 cflags="$cflags -nostdinc"
676 cflags="$cflags -fno-inline"
677 cflags="$cflags -ffreestanding"
678 cflags="$cflags -ffunction-sections"
679 cflags="$cflags -fdata-sections"
680 cflags="$cflags -DAARCH64"
681 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000682 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500683
684 cflags="$cflags $std_libs"
685
Joel Goddard3ad03062021-03-16 16:47:42 +0000686 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500687
688 echo "Building SCMI library (SCP-tools) ..."
689
690 make "CROSS_COMPILE=$cross_compile" \
691 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000692 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500693 "PROTOCOLS=$protocols" \
694 "clean" \
695 "all"
696 )
697}
698
699build_tf_for_scp_tools() {
700
701 cd "$scp_tools_root/arm-tf"
702
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600703 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500704
705 if [ "$1" = "release" ]; then
706 echo "Build TF-4-SCP-Tools rls..."
707 else
708 echo "Build TF-4-SCP-Tools dbg..."
709
710 make realclean
711
712 make "BM_TEST=scmi" \
713 "ARM_BOARD_OPTIMISE_MEM=1" \
714 "BM_CSS=juno" \
715 "CSS_USE_SCMI_SDS_DRIVER=1" \
716 "PLAT=juno" \
717 "DEBUG=1" \
718 "PLATFORM=juno" \
719 "CROSS_COMPILE=$cross_compile" \
720 "BM_WORKSPACE=$scp_tools_root/baremetal"
721
722 archive_file "build/juno/debug/bl1.bin"
723
724 archive_file "build/juno/debug/bl2.bin"
725
726 archive_file "build/juno/debug/bl31.bin"
727 fi
728}
729
730build_fip_for_scp_tools() {
731
732 cd "$scp_tools_root/arm-tf"
733
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600734 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500735
736 if [ ! -d "$scp_root/build/product/juno/scp_ramfw/debug" ]; then
737 make fiptool
738 echo "Make FIP 4 SCP-Tools rls..."
739
740 else
741 make fiptool
742 echo "Make FIP 4 SCP-Tools dbg..."
743
744 make "PLAT=juno" \
745 "all" \
746 "fip" \
747 "DEBUG=1" \
748 "CROSS_COMPILE=$cross_compile" \
749 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
750 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
751 "SCP_BL2=$scp_root/build/product/juno/scp_ramfw/debug/bin/firmware.bin"
752
753 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
754 fi
755}
756
757build_cc() {
758# Building code coverage plugin
759 ARM_DIR=/arm
760 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
761 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
762 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
763 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
764 exit -1
765 fi # Error if arm warehouse not found
766 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
767
768 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
769}
770
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100771build_spm() {
772 (
773 env_file="$workspace/spm.env"
774 config_file="${spm_build_config:-$spm_config_file}"
775
776 source "$config_file"
777
778 if [ -f "$env_file" ]; then
779 set -a
780 source "$env_file"
781 set +a
782 fi
783
784 cd "$spm_root"
785
786 # Always clean when running on Jenkins. Skip clean when running
787 # locally and explicitly requested.
788 if upon "$jenkins_run" || not_upon "$dont_clean"; then
789 # make clean fails on a fresh repo where the project has not
790 # yet been built. Hence only clean if out/reference directory
791 # already exists.
792 if [ -d "out/reference" ]; then
793 make clean &>>"$build_log" || fail_build
794 fi
795 fi
796
797 # Log build command line. It is left unfolded on purpose to assist
798 # copying to clipboard.
799 cat <<EOF | log_separator >/dev/null
800
801Build command line:
802 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
803
804EOF
805
806 # Build SPM. Since build output is being directed to the build log, have
807 # descriptor 3 point to the current terminal for build wrappers to vent.
808 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
809 || fail_build
810 )
811}
Zelalem219df412020-05-17 19:21:20 -0500812
Fathi Boudra422bf772019-12-02 11:10:16 +0200813# Set metadata for the whole package so that it can be used by both Jenkins and
814# shell
815set_package_var() {
816 env_file="$artefacts/env" emit_env "$@"
817}
818
819set_tf_build_targets() {
820 echo "Set build target to '${targets:?}'"
821 set_hook_var "tf_build_targets" "$targets"
822}
823
824set_tftf_build_targets() {
825 echo "Set build target to '${targets:?}'"
826 set_hook_var "tftf_build_targets" "$targets"
827}
828
829set_scp_build_targets() {
830 echo "Set build target to '${targets:?}'"
831 set_hook_var "scp_build_targets" "$targets"
832}
833
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100834set_spm_build_targets() {
835 echo "Set build target to '${targets:?}'"
836 set_hook_var "spm_build_targets" "$targets"
837}
838
Fathi Boudra422bf772019-12-02 11:10:16 +0200839# Look under $archive directory for known files such as blX images, kernel, DTB,
840# initrd etc. For each known file foo, if foo.bin exists, then set variable
841# foo_bin to the path of the file. Make the path relative to the workspace so as
842# to remove any @ characters, which Jenkins inserts for parallel runs. If the
843# file doesn't exist, unset its path.
844set_default_bin_paths() {
845 local image image_name image_path path
846 local archive="${archive:?}"
847 local set_vars
848 local var
849
850 pushd "$archive"
851
852 for file in *.bin; do
853 # Get a shell variable from the file's stem
854 var_name="${file%%.*}_bin"
855 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
856
857 # Skip setting the variable if it's already
858 if [ "${!var_name}" ]; then
859 echo "Note: not setting $var_name; already set to ${!var_name}"
860 continue
861 else
862 set_vars+="$var_name "
863 fi
864
865 eval "$var_name=$file"
866 done
867
868 echo "Binary paths set for: "
869 {
870 for var in $set_vars; do
871 echo -n "\$$var "
872 done
873 } | fmt -80 | sed 's/^/ /'
874 echo
875
876 popd
877}
878
879gen_model_params() {
880 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000881 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200882
883 set_default_bin_paths
884 echo "Generating model parameter for $model..."
885 source "$ci_root/model/${model:?}.sh"
886 archive_file "$model_param_file"
887}
888
889set_model_path() {
890 set_run_env "model_path" "${1:?}"
891}
892
Zelalem1af7a7b2020-08-04 17:34:32 -0500893set_model_env() {
894 local var="${1:?}"
895 local val="${2?}"
896 local run_root="${archive:?}/run"
897
898 mkdir -p "$run_root"
899 echo "export $var=$val" >> "$run_root/model_env"
900}
Fathi Boudra422bf772019-12-02 11:10:16 +0200901set_run_env() {
902 local var="${1:?}"
903 local val="${2?}"
904 local run_root="${archive:?}/run"
905
906 mkdir -p "$run_root"
907 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
908}
909
910show_head() {
911 # Display HEAD descripton
912 pushd "$1"
913 git show --quiet --no-color | sed 's/^/ > /g'
914 echo
915 popd
916}
917
918# Choose debug binaries to run; by default, release binaries are chosen to run
919use_debug_bins() {
920 local run_root="${archive:?}/run"
921
922 echo "Choosing debug binaries for execution"
923 set_package_var "BIN_MODE" "debug"
924}
925
926assert_can_git_clone() {
927 local name="${1:?}"
928 local dir="${!name}"
929
930 # If it doesn't exist, it can be cloned into
931 if [ ! -e "$dir" ]; then
932 return 0
933 fi
934
935 # If it's a directory, it must be a Git clone already
936 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
937 # No need to clone again
938 echo "Using existing git clone for $name: $dir"
939 return 1
940 fi
941
942 die "Path $dir exists but is not a git clone"
943}
944
945clone_repo() {
946 if ! is_url "${clone_url?}"; then
947 # For --depth to take effect on local paths, it needs to use the
948 # file:// scheme.
949 clone_url="file://$clone_url"
950 fi
951
952 git clone -q --depth 1 "$clone_url" "${where?}"
953 if [ "$refspec" ]; then
954 pushd "$where"
955 git fetch -q --depth 1 origin "$refspec"
956 git checkout -q FETCH_HEAD
957 popd
958 fi
959}
960
961build_unstable() {
962 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
963}
964
965undo_patch_record() {
966 if [ ! -f "${patch_record:?}" ]; then
967 return
968 fi
969
970 # Undo patches in reverse
971 echo
972 for patch_name in $(tac "$patch_record"); do
973 echo "Undoing $patch_name..."
974 if ! git apply -R "$ci_root/patch/$patch_name"; then
975 if upon "$local_ci"; then
976 echo
977 echo "Your local directory may have been dirtied."
978 echo
979 fi
980 fail_build
981 fi
982 done
983
984 rm -f "$patch_record"
985}
986
987undo_local_patches() {
988 pushd "$tf_root"
989 patch_record="$tf_patch_record" undo_patch_record
990 popd
991
992 if [ -d "$tftf_root" ]; then
993 pushd "$tftf_root"
994 patch_record="$tftf_patch_record" undo_patch_record
995 popd
996 fi
997}
998
999undo_tftf_patches() {
1000 pushd "$tftf_root"
1001 patch_record="$tftf_patch_record" undo_patch_record
1002 popd
1003}
1004
1005undo_tf_patches() {
1006 pushd "$tf_root"
1007 patch_record="$tf_patch_record" undo_patch_record
1008 popd
1009}
1010
1011apply_patch() {
1012 # If skip_patches is set, the developer has applied required patches
1013 # manually. They probably want to keep them applied for debugging
1014 # purposes too. This means we don't have to apply/revert them as part of
1015 # build process.
1016 if upon "$skip_patches"; then
1017 echo "Skipped applying ${1:?}..."
1018 return 0
1019 else
1020 echo "Applying ${1:?}..."
1021 fi
1022
1023 if git apply < "$ci_root/patch/$1"; then
1024 echo "$1" >> "${patch_record:?}"
1025 else
1026 if upon "$local_ci"; then
1027 undo_local_patches
1028 fi
1029 fail_build
1030 fi
1031}
1032
1033apply_tftf_patch() {
1034 pushd "$tftf_root"
1035 patch_record="$tftf_patch_record" apply_patch "$1"
1036 popd
1037}
1038
1039apply_tf_patch() {
1040 pushd "$tf_root"
1041 patch_record="$tf_patch_record" apply_patch "$1"
1042 popd
1043}
1044
1045# Clear workspace for a local run
1046if not_upon "$jenkins_run"; then
1047 rm -rf "$workspace"
1048
1049 # Clear residue from previous runs
1050 rm -rf "$archive"
1051fi
1052
1053mkdir -p "$workspace"
1054mkdir -p "$archive"
1055set_package_var "TEST_CONFIG" "$test_config"
1056
1057{
1058echo
1059echo "CONFIGURATION: $test_group/$test_config"
1060echo
1061} |& log_separator
1062
1063tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1064tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1065scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001066scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001067spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001068
1069test_config_file="$ci_root/group/$test_group/$test_config"
1070
1071tf_config_file="$ci_root/tf_config/$tf_config"
1072tftf_config_file="$ci_root/tftf_config/$tftf_config"
1073scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001074scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001075spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001076
1077# File that keeps track of applied patches
1078tf_patch_record="$workspace/tf_patches"
1079tftf_patch_record="$workspace/tftf_patches"
1080
1081pushd "$workspace"
1082
1083if ! config_valid "$tf_config"; then
1084 tf_config=
1085else
1086 echo "Trusted Firmware config:"
1087 echo
1088 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1089 echo
1090fi
1091
1092if ! config_valid "$tftf_config"; then
1093 tftf_config=
1094else
1095 echo "Trusted Firmware TF config:"
1096 echo
1097 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1098 echo
1099fi
1100
1101if ! config_valid "$scp_config"; then
1102 scp_config=
1103else
1104 echo "SCP firmware config:"
1105 echo
1106 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1107 echo
1108fi
1109
Zelalem219df412020-05-17 19:21:20 -05001110if ! config_valid "$scp_tools_config"; then
1111 scp_tools_config=
1112else
1113 echo "SCP Tools config:"
1114 echo
1115 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001116fi
1117
1118if ! config_valid "$spm_config"; then
1119 spm_config=
1120else
1121 echo "SPM config:"
1122 echo
1123 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001124 echo
1125fi
1126
Fathi Boudra422bf772019-12-02 11:10:16 +02001127if ! config_valid "$run_config"; then
1128 run_config=
1129fi
1130
1131if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1132 # If the Trusted Firmware repository has already been checked out, use
1133 # that location. Otherwise, clone one ourselves.
1134 echo "Cloning Trusted Firmware..."
1135 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1136 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1137 show_head "$tf_root"
1138fi
1139
1140if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1141 # If the Trusted Firmware TF repository has already been checked out,
1142 # use that location. Otherwise, clone one ourselves.
1143 echo "Cloning Trusted Firmware TF..."
1144 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1145 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1146 show_head "$tftf_root"
1147fi
1148
1149if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1150 # If the SCP firmware repository has already been checked out,
1151 # use that location. Otherwise, clone one ourselves.
1152 echo "Cloning SCP Firmware..."
1153 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1154 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1155
1156 pushd "$scp_root"
1157
1158 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001159 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001160 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1161 fi
1162
1163 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1164 # then to project filer if accessible.
1165 if [ -z "$cmsis_reference" ]; then
1166 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1167 if [ -d "$cmsis_ref_repo" ]; then
1168 cmsis_reference="--reference $cmsis_ref_repo"
1169 fi
1170 fi
1171
1172 git submodule -q update $cmsis_reference --init
1173
1174 popd
1175
1176 show_head "$scp_root"
1177fi
1178
Zelalem219df412020-05-17 19:21:20 -05001179if [ -n "$cc_config" ] ; then
1180 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1181 # Copy code coverage repository
1182 echo "Cloning Code Coverage..."
1183 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1184 show_head "$cc_root"
1185 fi
1186fi
1187
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001188if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1189 # If the SPM repository has already been checked out, use
1190 # that location. Otherwise, clone one ourselves.
1191 echo "Cloning SPM..."
1192 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1193 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1194
1195 # Query git submodules
1196 pushd "$spm_root"
1197 git submodule update --init
1198 popd
1199
1200 show_head "$spm_root"
1201fi
1202
Fathi Boudra422bf772019-12-02 11:10:16 +02001203if [ "$run_config" ]; then
1204 # Get candidates for run config
1205 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1206 "$run_config")"
1207 if [ -z "$run_config_candiates" ]; then
1208 die "No run config candidates!"
1209 else
1210 echo
1211 echo "Chosen fragments:"
1212 echo
1213 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1214 echo
1215 fi
1216fi
1217
1218call_hook "test_setup"
1219echo
1220
1221if upon "$local_ci"; then
1222 # For local runs, since each config is tried in sequence, it's
1223 # advantageous to run jobs in parallel
1224 if [ "$make_j" ]; then
1225 make_j_opts="-j $make_j"
1226 else
1227 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1228 if [ "$n_cores" ]; then
1229 make_j_opts="-j $n_cores"
1230 fi
1231 fi
1232fi
1233
1234modes="${bin_mode:-debug release}"
1235for mode in $modes; do
1236 # Build with a temporary archive
1237 build_archive="$archive/$mode"
1238 mkdir "$build_archive"
1239
1240 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001241 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001242 DEBUG=1
1243 else
Zelalem219df412020-05-17 19:21:20 -05001244 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001245 DEBUG=0
1246 fi
1247
1248 # Perform builds in a subshell so as not to pollute the current and
1249 # subsequent builds' environment
1250
Zelalem219df412020-05-17 19:21:20 -05001251 if config_valid "$cc_config"; then
1252 # Build code coverage plugin
1253 build_cc
1254 fi
1255
Fathi Boudra422bf772019-12-02 11:10:16 +02001256 # SCP build
1257 if config_valid "$scp_config"; then
1258 (
1259 echo "##########"
1260
1261 # Source platform-specific utilities
1262 plat="$(get_scp_opt PRODUCT)"
1263 plat_utils="$ci_root/${plat}_utils.sh"
1264 if [ -f "$plat_utils" ]; then
1265 source "$plat_utils"
1266 fi
1267
1268 archive="$build_archive"
1269 scp_build_root="$scp_root/build"
1270
1271 echo "Building SCP Firmware ($mode) ..." |& log_separator
1272
1273 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001274 to="$archive" collect_scp_artefacts
1275
1276 echo "##########"
1277 echo
1278 )
1279 fi
1280
Zelalem219df412020-05-17 19:21:20 -05001281 # SCP-tools build
1282 if config_valid "$scp_tools_config"; then
1283 (
1284 echo "##########"
1285
1286 archive="$build_archive"
1287 scp_tools_build_root="$scp_tools_root/build"
1288
1289 clone_scp_tools
1290
1291 echo "##########"
1292 echo
1293
1294 echo "##########"
1295 clone_tf_for_scp_tools
1296 echo "##########"
1297 echo
1298 )
1299 fi
1300
Fathi Boudra422bf772019-12-02 11:10:16 +02001301 # TFTF build
1302 if config_valid "$tftf_config"; then
1303 (
1304 echo "##########"
1305
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001306 plat_utils="$(get_tf_opt PLAT_UTILS)"
1307 if [ -z ${plat_utils} ]; then
1308 # Source platform-specific utilities.
1309 plat="$(get_tftf_opt PLAT)"
1310 plat_utils="$ci_root/${plat}_utils.sh"
1311 else
1312 # Source platform-specific utilities by
1313 # using plat_utils name.
1314 plat_utils="$ci_root/${plat_utils}.sh"
1315 fi
1316
Fathi Boudra422bf772019-12-02 11:10:16 +02001317 if [ -f "$plat_utils" ]; then
1318 source "$plat_utils"
1319 fi
1320
1321 archive="$build_archive"
1322 tftf_build_root="$tftf_root/build"
1323
1324 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1325
1326 # Call pre-build hook
1327 call_hook pre_tftf_build
1328
1329 build_tftf
1330
1331 from="$tftf_build_root" to="$archive" collect_build_artefacts
1332
1333 # Clear any local changes made by applied patches
1334 undo_tftf_patches
1335
1336 echo "##########"
1337 echo
1338 )
1339 fi
1340
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001341 # SPM build
1342 if config_valid "$spm_config"; then
1343 (
1344 echo "##########"
1345
1346 # Get platform name from spm_config file
1347 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1348 plat_utils="$ci_root/${plat}_utils.sh"
1349 if [ -f "$plat_utils" ]; then
1350 source "$plat_utils"
1351 fi
1352
Manish Pandey1e7be852020-11-09 16:04:48 +00001353 # SPM build generates two sets of binaries, one for normal and other
1354 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001355 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001356 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1357 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001358
1359 echo "Building SPM ($mode) ..." |& log_separator
1360
1361 # NOTE: mode has no effect on SPM build (for now), hence debug
1362 # mode is built but subsequent build using release mode just
1363 # goes through with "nothing to do".
1364 build_spm
1365
1366 # Show SPM/Hafnium binary details
Manish Pandey1e7be852020-11-09 16:04:48 +00001367 cksum $spm_build_root/hafnium.bin $hafnium_build_root/hafnium.bin
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001368
Manish Pandey1e7be852020-11-09 16:04:48 +00001369 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001370
1371 echo "##########"
1372 echo
1373 )
1374 fi
1375
Fathi Boudra422bf772019-12-02 11:10:16 +02001376 # TF build
1377 if config_valid "$tf_config"; then
1378 (
1379 echo "##########"
1380
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001381 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001382 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1383
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001384 if [ -z ${plat_utils} ]; then
1385 # Source platform-specific utilities.
1386 plat="$(get_tf_opt PLAT)"
1387 plat_utils="$ci_root/${plat}_utils.sh"
1388 else
1389 # Source platform-specific utilities by
1390 # using plat_utils name.
1391 plat_utils="$ci_root/${plat_utils}.sh"
1392 fi
1393
Fathi Boudra422bf772019-12-02 11:10:16 +02001394 if [ -f "$plat_utils" ]; then
1395 source "$plat_utils"
1396 fi
1397
Chris Kayd0837902021-11-17 10:17:52 +00001398 source "$ci_root/script/install_python_deps_tf.sh"
1399
Fathi Boudra422bf772019-12-02 11:10:16 +02001400 archive="$build_archive"
1401 tf_build_root="$tf_root/build"
1402
1403 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1404
1405 # Call pre-build hook
1406 call_hook pre_tf_build
1407
1408 build_tf
1409
1410 # Call post-build hook
1411 call_hook post_tf_build
1412
1413 # Pre-archive hook
1414 call_hook pre_tf_archive
1415
1416 from="$tf_build_root" to="$archive" collect_build_artefacts
1417
1418 # Post-archive hook
1419 call_hook post_tf_archive
1420
1421 call_hook fetch_tf_resource
1422 call_hook post_fetch_tf_resource
1423
1424 # Clear any local changes made by applied patches
1425 undo_tf_patches
1426
1427 echo "##########"
1428 )
1429 fi
1430
1431 echo
1432 echo
1433done
1434
1435call_hook pre_package
1436
1437call_hook post_package
1438
1439if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001440 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001441fi
1442
1443echo
1444echo "Done"