blob: 75d302498db2fba6e05c17146c30271aacf750b9 [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() {
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500210 if [ -d "${non_secure_from:?}" ]; then
211 find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +
Manish Pandey1e7be852020-11-09 16:04:48 +0000212 fi
213
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -0500214 if [ -d "${secure_from:?}" ]; then
215 for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done
216 fi
Manish Pandey1e7be852020-11-09 16:04:48 +0000217}
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.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200808 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
809
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100810 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
811 || fail_build
812 )
813}
Zelalem219df412020-05-17 19:21:20 -0500814
Fathi Boudra422bf772019-12-02 11:10:16 +0200815# Set metadata for the whole package so that it can be used by both Jenkins and
816# shell
817set_package_var() {
818 env_file="$artefacts/env" emit_env "$@"
819}
820
821set_tf_build_targets() {
822 echo "Set build target to '${targets:?}'"
823 set_hook_var "tf_build_targets" "$targets"
824}
825
826set_tftf_build_targets() {
827 echo "Set build target to '${targets:?}'"
828 set_hook_var "tftf_build_targets" "$targets"
829}
830
831set_scp_build_targets() {
832 echo "Set build target to '${targets:?}'"
833 set_hook_var "scp_build_targets" "$targets"
834}
835
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100836set_spm_build_targets() {
837 echo "Set build target to '${targets:?}'"
838 set_hook_var "spm_build_targets" "$targets"
839}
840
Fathi Boudra422bf772019-12-02 11:10:16 +0200841# Look under $archive directory for known files such as blX images, kernel, DTB,
842# initrd etc. For each known file foo, if foo.bin exists, then set variable
843# foo_bin to the path of the file. Make the path relative to the workspace so as
844# to remove any @ characters, which Jenkins inserts for parallel runs. If the
845# file doesn't exist, unset its path.
846set_default_bin_paths() {
847 local image image_name image_path path
848 local archive="${archive:?}"
849 local set_vars
850 local var
851
852 pushd "$archive"
853
854 for file in *.bin; do
855 # Get a shell variable from the file's stem
856 var_name="${file%%.*}_bin"
857 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
858
859 # Skip setting the variable if it's already
860 if [ "${!var_name}" ]; then
861 echo "Note: not setting $var_name; already set to ${!var_name}"
862 continue
863 else
864 set_vars+="$var_name "
865 fi
866
867 eval "$var_name=$file"
868 done
869
870 echo "Binary paths set for: "
871 {
872 for var in $set_vars; do
873 echo -n "\$$var "
874 done
875 } | fmt -80 | sed 's/^/ /'
876 echo
877
878 popd
879}
880
881gen_model_params() {
882 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000883 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200884
885 set_default_bin_paths
886 echo "Generating model parameter for $model..."
887 source "$ci_root/model/${model:?}.sh"
888 archive_file "$model_param_file"
889}
890
891set_model_path() {
892 set_run_env "model_path" "${1:?}"
893}
894
Zelalem1af7a7b2020-08-04 17:34:32 -0500895set_model_env() {
896 local var="${1:?}"
897 local val="${2?}"
898 local run_root="${archive:?}/run"
899
900 mkdir -p "$run_root"
901 echo "export $var=$val" >> "$run_root/model_env"
902}
Fathi Boudra422bf772019-12-02 11:10:16 +0200903set_run_env() {
904 local var="${1:?}"
905 local val="${2?}"
906 local run_root="${archive:?}/run"
907
908 mkdir -p "$run_root"
909 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
910}
911
912show_head() {
913 # Display HEAD descripton
914 pushd "$1"
915 git show --quiet --no-color | sed 's/^/ > /g'
916 echo
917 popd
918}
919
920# Choose debug binaries to run; by default, release binaries are chosen to run
921use_debug_bins() {
922 local run_root="${archive:?}/run"
923
924 echo "Choosing debug binaries for execution"
925 set_package_var "BIN_MODE" "debug"
926}
927
928assert_can_git_clone() {
929 local name="${1:?}"
930 local dir="${!name}"
931
932 # If it doesn't exist, it can be cloned into
933 if [ ! -e "$dir" ]; then
934 return 0
935 fi
936
937 # If it's a directory, it must be a Git clone already
938 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
939 # No need to clone again
940 echo "Using existing git clone for $name: $dir"
941 return 1
942 fi
943
944 die "Path $dir exists but is not a git clone"
945}
946
947clone_repo() {
948 if ! is_url "${clone_url?}"; then
949 # For --depth to take effect on local paths, it needs to use the
950 # file:// scheme.
951 clone_url="file://$clone_url"
952 fi
953
954 git clone -q --depth 1 "$clone_url" "${where?}"
955 if [ "$refspec" ]; then
956 pushd "$where"
957 git fetch -q --depth 1 origin "$refspec"
958 git checkout -q FETCH_HEAD
959 popd
960 fi
961}
962
963build_unstable() {
964 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
965}
966
967undo_patch_record() {
968 if [ ! -f "${patch_record:?}" ]; then
969 return
970 fi
971
972 # Undo patches in reverse
973 echo
974 for patch_name in $(tac "$patch_record"); do
975 echo "Undoing $patch_name..."
976 if ! git apply -R "$ci_root/patch/$patch_name"; then
977 if upon "$local_ci"; then
978 echo
979 echo "Your local directory may have been dirtied."
980 echo
981 fi
982 fail_build
983 fi
984 done
985
986 rm -f "$patch_record"
987}
988
989undo_local_patches() {
990 pushd "$tf_root"
991 patch_record="$tf_patch_record" undo_patch_record
992 popd
993
994 if [ -d "$tftf_root" ]; then
995 pushd "$tftf_root"
996 patch_record="$tftf_patch_record" undo_patch_record
997 popd
998 fi
999}
1000
1001undo_tftf_patches() {
1002 pushd "$tftf_root"
1003 patch_record="$tftf_patch_record" undo_patch_record
1004 popd
1005}
1006
1007undo_tf_patches() {
1008 pushd "$tf_root"
1009 patch_record="$tf_patch_record" undo_patch_record
1010 popd
1011}
1012
1013apply_patch() {
1014 # If skip_patches is set, the developer has applied required patches
1015 # manually. They probably want to keep them applied for debugging
1016 # purposes too. This means we don't have to apply/revert them as part of
1017 # build process.
1018 if upon "$skip_patches"; then
1019 echo "Skipped applying ${1:?}..."
1020 return 0
1021 else
1022 echo "Applying ${1:?}..."
1023 fi
1024
1025 if git apply < "$ci_root/patch/$1"; then
1026 echo "$1" >> "${patch_record:?}"
1027 else
1028 if upon "$local_ci"; then
1029 undo_local_patches
1030 fi
1031 fail_build
1032 fi
1033}
1034
1035apply_tftf_patch() {
1036 pushd "$tftf_root"
1037 patch_record="$tftf_patch_record" apply_patch "$1"
1038 popd
1039}
1040
1041apply_tf_patch() {
1042 pushd "$tf_root"
1043 patch_record="$tf_patch_record" apply_patch "$1"
1044 popd
1045}
1046
1047# Clear workspace for a local run
1048if not_upon "$jenkins_run"; then
1049 rm -rf "$workspace"
1050
1051 # Clear residue from previous runs
1052 rm -rf "$archive"
1053fi
1054
1055mkdir -p "$workspace"
1056mkdir -p "$archive"
1057set_package_var "TEST_CONFIG" "$test_config"
1058
1059{
1060echo
1061echo "CONFIGURATION: $test_group/$test_config"
1062echo
1063} |& log_separator
1064
1065tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1066tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1067scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001068scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001069spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001070
1071test_config_file="$ci_root/group/$test_group/$test_config"
1072
1073tf_config_file="$ci_root/tf_config/$tf_config"
1074tftf_config_file="$ci_root/tftf_config/$tftf_config"
1075scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001076scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001077spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001078
1079# File that keeps track of applied patches
1080tf_patch_record="$workspace/tf_patches"
1081tftf_patch_record="$workspace/tftf_patches"
1082
1083pushd "$workspace"
1084
1085if ! config_valid "$tf_config"; then
1086 tf_config=
1087else
1088 echo "Trusted Firmware config:"
1089 echo
1090 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1091 echo
1092fi
1093
1094if ! config_valid "$tftf_config"; then
1095 tftf_config=
1096else
1097 echo "Trusted Firmware TF config:"
1098 echo
1099 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1100 echo
1101fi
1102
1103if ! config_valid "$scp_config"; then
1104 scp_config=
1105else
1106 echo "SCP firmware config:"
1107 echo
1108 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1109 echo
1110fi
1111
Zelalem219df412020-05-17 19:21:20 -05001112if ! config_valid "$scp_tools_config"; then
1113 scp_tools_config=
1114else
1115 echo "SCP Tools config:"
1116 echo
1117 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001118fi
1119
1120if ! config_valid "$spm_config"; then
1121 spm_config=
1122else
1123 echo "SPM config:"
1124 echo
1125 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001126 echo
1127fi
1128
Fathi Boudra422bf772019-12-02 11:10:16 +02001129if ! config_valid "$run_config"; then
1130 run_config=
1131fi
1132
1133if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1134 # If the Trusted Firmware repository has already been checked out, use
1135 # that location. Otherwise, clone one ourselves.
1136 echo "Cloning Trusted Firmware..."
1137 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1138 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1139 show_head "$tf_root"
1140fi
1141
1142if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1143 # If the Trusted Firmware TF repository has already been checked out,
1144 # use that location. Otherwise, clone one ourselves.
1145 echo "Cloning Trusted Firmware TF..."
1146 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1147 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1148 show_head "$tftf_root"
1149fi
1150
1151if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1152 # If the SCP firmware repository has already been checked out,
1153 # use that location. Otherwise, clone one ourselves.
1154 echo "Cloning SCP Firmware..."
1155 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1156 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1157
1158 pushd "$scp_root"
1159
1160 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001161 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001162 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1163 fi
1164
1165 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1166 # then to project filer if accessible.
1167 if [ -z "$cmsis_reference" ]; then
1168 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1169 if [ -d "$cmsis_ref_repo" ]; then
1170 cmsis_reference="--reference $cmsis_ref_repo"
1171 fi
1172 fi
1173
1174 git submodule -q update $cmsis_reference --init
1175
1176 popd
1177
1178 show_head "$scp_root"
1179fi
1180
Zelalem219df412020-05-17 19:21:20 -05001181if [ -n "$cc_config" ] ; then
1182 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1183 # Copy code coverage repository
1184 echo "Cloning Code Coverage..."
1185 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1186 show_head "$cc_root"
1187 fi
1188fi
1189
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001190if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1191 # If the SPM repository has already been checked out, use
1192 # that location. Otherwise, clone one ourselves.
1193 echo "Cloning SPM..."
1194 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1195 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1196
1197 # Query git submodules
1198 pushd "$spm_root"
1199 git submodule update --init
1200 popd
1201
1202 show_head "$spm_root"
1203fi
1204
Fathi Boudra422bf772019-12-02 11:10:16 +02001205if [ "$run_config" ]; then
1206 # Get candidates for run config
1207 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1208 "$run_config")"
1209 if [ -z "$run_config_candiates" ]; then
1210 die "No run config candidates!"
1211 else
1212 echo
1213 echo "Chosen fragments:"
1214 echo
1215 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1216 echo
1217 fi
1218fi
1219
1220call_hook "test_setup"
1221echo
1222
1223if upon "$local_ci"; then
1224 # For local runs, since each config is tried in sequence, it's
1225 # advantageous to run jobs in parallel
1226 if [ "$make_j" ]; then
1227 make_j_opts="-j $make_j"
1228 else
1229 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1230 if [ "$n_cores" ]; then
1231 make_j_opts="-j $n_cores"
1232 fi
1233 fi
1234fi
1235
1236modes="${bin_mode:-debug release}"
1237for mode in $modes; do
1238 # Build with a temporary archive
1239 build_archive="$archive/$mode"
1240 mkdir "$build_archive"
1241
1242 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001243 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001244 DEBUG=1
1245 else
Zelalem219df412020-05-17 19:21:20 -05001246 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001247 DEBUG=0
1248 fi
1249
1250 # Perform builds in a subshell so as not to pollute the current and
1251 # subsequent builds' environment
1252
Zelalem219df412020-05-17 19:21:20 -05001253 if config_valid "$cc_config"; then
1254 # Build code coverage plugin
1255 build_cc
1256 fi
1257
Fathi Boudra422bf772019-12-02 11:10:16 +02001258 # SCP build
1259 if config_valid "$scp_config"; then
1260 (
1261 echo "##########"
1262
1263 # Source platform-specific utilities
1264 plat="$(get_scp_opt PRODUCT)"
1265 plat_utils="$ci_root/${plat}_utils.sh"
1266 if [ -f "$plat_utils" ]; then
1267 source "$plat_utils"
1268 fi
1269
1270 archive="$build_archive"
1271 scp_build_root="$scp_root/build"
1272
1273 echo "Building SCP Firmware ($mode) ..." |& log_separator
1274
1275 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001276 to="$archive" collect_scp_artefacts
1277
1278 echo "##########"
1279 echo
1280 )
1281 fi
1282
Zelalem219df412020-05-17 19:21:20 -05001283 # SCP-tools build
1284 if config_valid "$scp_tools_config"; then
1285 (
1286 echo "##########"
1287
1288 archive="$build_archive"
1289 scp_tools_build_root="$scp_tools_root/build"
1290
1291 clone_scp_tools
1292
1293 echo "##########"
1294 echo
1295
1296 echo "##########"
1297 clone_tf_for_scp_tools
1298 echo "##########"
1299 echo
1300 )
1301 fi
1302
Fathi Boudra422bf772019-12-02 11:10:16 +02001303 # TFTF build
1304 if config_valid "$tftf_config"; then
1305 (
1306 echo "##########"
1307
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001308 plat_utils="$(get_tf_opt PLAT_UTILS)"
1309 if [ -z ${plat_utils} ]; then
1310 # Source platform-specific utilities.
1311 plat="$(get_tftf_opt PLAT)"
1312 plat_utils="$ci_root/${plat}_utils.sh"
1313 else
1314 # Source platform-specific utilities by
1315 # using plat_utils name.
1316 plat_utils="$ci_root/${plat_utils}.sh"
1317 fi
1318
Fathi Boudra422bf772019-12-02 11:10:16 +02001319 if [ -f "$plat_utils" ]; then
1320 source "$plat_utils"
1321 fi
1322
1323 archive="$build_archive"
1324 tftf_build_root="$tftf_root/build"
1325
1326 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1327
1328 # Call pre-build hook
1329 call_hook pre_tftf_build
1330
1331 build_tftf
1332
1333 from="$tftf_build_root" to="$archive" collect_build_artefacts
1334
1335 # Clear any local changes made by applied patches
1336 undo_tftf_patches
1337
1338 echo "##########"
1339 echo
1340 )
1341 fi
1342
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001343 # SPM build
1344 if config_valid "$spm_config"; then
1345 (
1346 echo "##########"
1347
1348 # Get platform name from spm_config file
1349 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1350 plat_utils="$ci_root/${plat}_utils.sh"
1351 if [ -f "$plat_utils" ]; then
1352 source "$plat_utils"
1353 fi
1354
Manish Pandey1e7be852020-11-09 16:04:48 +00001355 # SPM build generates two sets of binaries, one for normal and other
1356 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001357 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001358 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1359 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001360
1361 echo "Building SPM ($mode) ..." |& log_separator
1362
1363 # NOTE: mode has no effect on SPM build (for now), hence debug
1364 # mode is built but subsequent build using release mode just
1365 # goes through with "nothing to do".
1366 build_spm
1367
1368 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001369 cksum $spm_build_root/hafnium.bin
1370
1371 # Some platforms only have secure configuration enabled. Hence,
1372 # non secure hanfnium binary might not be built.
1373 if [ -f $hafnium_build_root/hafnium.bin ]; then
1374 cksum $hafnium_build_root/hafnium.bin
1375 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001376
Manish Pandey1e7be852020-11-09 16:04:48 +00001377 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001378
1379 echo "##########"
1380 echo
1381 )
1382 fi
1383
Fathi Boudra422bf772019-12-02 11:10:16 +02001384 # TF build
1385 if config_valid "$tf_config"; then
1386 (
1387 echo "##########"
1388
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001389 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001390 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1391
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001392 if [ -z ${plat_utils} ]; then
1393 # Source platform-specific utilities.
1394 plat="$(get_tf_opt PLAT)"
1395 plat_utils="$ci_root/${plat}_utils.sh"
1396 else
1397 # Source platform-specific utilities by
1398 # using plat_utils name.
1399 plat_utils="$ci_root/${plat_utils}.sh"
1400 fi
1401
Fathi Boudra422bf772019-12-02 11:10:16 +02001402 if [ -f "$plat_utils" ]; then
1403 source "$plat_utils"
1404 fi
1405
Chris Kayd0837902021-11-17 10:17:52 +00001406 source "$ci_root/script/install_python_deps_tf.sh"
1407
Fathi Boudra422bf772019-12-02 11:10:16 +02001408 archive="$build_archive"
1409 tf_build_root="$tf_root/build"
1410
1411 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1412
1413 # Call pre-build hook
1414 call_hook pre_tf_build
1415
1416 build_tf
1417
1418 # Call post-build hook
1419 call_hook post_tf_build
1420
1421 # Pre-archive hook
1422 call_hook pre_tf_archive
1423
1424 from="$tf_build_root" to="$archive" collect_build_artefacts
1425
1426 # Post-archive hook
1427 call_hook post_tf_archive
1428
1429 call_hook fetch_tf_resource
1430 call_hook post_fetch_tf_resource
1431
1432 # Clear any local changes made by applied patches
1433 undo_tf_patches
1434
1435 echo "##########"
1436 )
1437 fi
1438
1439 echo
1440 echo
1441done
1442
1443call_hook pre_package
1444
1445call_hook post_package
1446
1447if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001448 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001449fi
1450
1451echo
1452echo "Done"