blob: a99adec1adbad2a084d6fae75432314fe11cb790 [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
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000620 lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'")
621
Zelalem219df412020-05-17 19:21:20 -0500622 cd "scmi"
Nicola Mazzucato7302cd32021-12-14 13:36:57 +0000623 git checkout $lib_commit
Zelalem219df412020-05-17 19:21:20 -0500624
625 git show --quiet --no-color | sed 's/^/ > /g'
626}
627
628clone_tf_for_scp_tools() {
629 scp_tools_arm_tf="$scp_tools_root/arm-tf"
630
631 if [ ! -d "$scp_tools_arm_tf" ]; then
632 echo "Cloning TF-4-SCP-tools ..." |& log_separator
633
634 clone_url="$tf_for_scp_tools_src_repo_url"
635 where="$scp_tools_arm_tf"
636
637 git clone "$clone_url" "$where"
638
639 cd "$scp_tools_arm_tf"
640
Joel Goddard3ad03062021-03-16 16:47:42 +0000641 git checkout --track origin/juno-v4.3
Zelalem219df412020-05-17 19:21:20 -0500642
643 git show --quiet --no-color | sed 's/^/ > /g'
644
645 else
646 echo "Already cloned TF-4-SCP-tools ..." |& log_separator
647 fi
648}
649
650build_scmi_lib_scp_tools() {
651 (
652 cd "$scp_tools_root"
653
654 cd "scmi"
655
656 scp_tools_arm_tf="$scp_tools_root/arm-tf"
657
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600658 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500659
660 std_libs="-I$scp_tools_arm_tf/include/common"
661 std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr"
662 std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm"
663 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib"
664 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64"
665 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib"
666 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys"
667 std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables"
668 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common"
669 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common"
670 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common"
671 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common"
672 std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common"
673 std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include"
674
675 cflags="-Og -g"
676 cflags="$cflags -mgeneral-regs-only"
677 cflags="$cflags -mstrict-align"
678 cflags="$cflags -nostdinc"
679 cflags="$cflags -fno-inline"
680 cflags="$cflags -ffreestanding"
681 cflags="$cflags -ffunction-sections"
682 cflags="$cflags -fdata-sections"
683 cflags="$cflags -DAARCH64"
684 cflags="$cflags -DPRId32=\"ld\""
Joel Goddard3ad03062021-03-16 16:47:42 +0000685 cflags="$cflags -DVERBOSE_LEVEL=3"
Zelalem219df412020-05-17 19:21:20 -0500686
687 cflags="$cflags $std_libs"
688
Joel Goddard3ad03062021-03-16 16:47:42 +0000689 protocols="performance,power_domain,system_power,reset"
Zelalem219df412020-05-17 19:21:20 -0500690
691 echo "Building SCMI library (SCP-tools) ..."
692
693 make "CROSS_COMPILE=$cross_compile" \
694 "CFLAGS=$cflags" \
Joel Goddard3ad03062021-03-16 16:47:42 +0000695 "PLAT=baremetal" \
Zelalem219df412020-05-17 19:21:20 -0500696 "PROTOCOLS=$protocols" \
697 "clean" \
698 "all"
699 )
700}
701
702build_tf_for_scp_tools() {
703
704 cd "$scp_tools_root/arm-tf"
705
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600706 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500707
708 if [ "$1" = "release" ]; then
709 echo "Build TF-4-SCP-Tools rls..."
710 else
711 echo "Build TF-4-SCP-Tools dbg..."
712
713 make realclean
714
715 make "BM_TEST=scmi" \
716 "ARM_BOARD_OPTIMISE_MEM=1" \
717 "BM_CSS=juno" \
718 "CSS_USE_SCMI_SDS_DRIVER=1" \
719 "PLAT=juno" \
720 "DEBUG=1" \
721 "PLATFORM=juno" \
722 "CROSS_COMPILE=$cross_compile" \
723 "BM_WORKSPACE=$scp_tools_root/baremetal"
724
725 archive_file "build/juno/debug/bl1.bin"
726
727 archive_file "build/juno/debug/bl2.bin"
728
729 archive_file "build/juno/debug/bl31.bin"
730 fi
731}
732
733build_fip_for_scp_tools() {
734
735 cd "$scp_tools_root/arm-tf"
736
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600737 cross_compile="$(set_cross_compile_gcc_linaro_toolchain)"
Zelalem219df412020-05-17 19:21:20 -0500738
739 if [ ! -d "$scp_root/build/product/juno/scp_ramfw/debug" ]; then
740 make fiptool
741 echo "Make FIP 4 SCP-Tools rls..."
742
743 else
744 make fiptool
745 echo "Make FIP 4 SCP-Tools dbg..."
746
747 make "PLAT=juno" \
748 "all" \
749 "fip" \
750 "DEBUG=1" \
751 "CROSS_COMPILE=$cross_compile" \
752 "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \
753 "BL33=$scp_tools_root/baremetal/dummy_bl33" \
754 "SCP_BL2=$scp_root/build/product/juno/scp_ramfw/debug/bin/firmware.bin"
755
756 archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin"
757 fi
758}
759
760build_cc() {
761# Building code coverage plugin
762 ARM_DIR=/arm
763 pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk")
764 PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external
765 if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then
766 echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder"
767 exit -1
768 fi # Error if arm warehouse not found
769 cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov"
770
771 make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log"
772}
773
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100774build_spm() {
775 (
776 env_file="$workspace/spm.env"
777 config_file="${spm_build_config:-$spm_config_file}"
778
779 source "$config_file"
780
781 if [ -f "$env_file" ]; then
782 set -a
783 source "$env_file"
784 set +a
785 fi
786
787 cd "$spm_root"
788
789 # Always clean when running on Jenkins. Skip clean when running
790 # locally and explicitly requested.
791 if upon "$jenkins_run" || not_upon "$dont_clean"; then
792 # make clean fails on a fresh repo where the project has not
793 # yet been built. Hence only clean if out/reference directory
794 # already exists.
795 if [ -d "out/reference" ]; then
796 make clean &>>"$build_log" || fail_build
797 fi
798 fi
799
800 # Log build command line. It is left unfolded on purpose to assist
801 # copying to clipboard.
802 cat <<EOF | log_separator >/dev/null
803
804Build command line:
805 make $make_j_opts $(cat "$config_file" | tr '\n' ' ')
806
807EOF
808
809 # Build SPM. Since build output is being directed to the build log, have
810 # descriptor 3 point to the current terminal for build wrappers to vent.
Olivier Deprezf34d1d32021-10-11 09:45:32 +0200811 export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH
812
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100813 make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \
814 || fail_build
815 )
816}
Zelalem219df412020-05-17 19:21:20 -0500817
Fathi Boudra422bf772019-12-02 11:10:16 +0200818# Set metadata for the whole package so that it can be used by both Jenkins and
819# shell
820set_package_var() {
821 env_file="$artefacts/env" emit_env "$@"
822}
823
824set_tf_build_targets() {
825 echo "Set build target to '${targets:?}'"
826 set_hook_var "tf_build_targets" "$targets"
827}
828
829set_tftf_build_targets() {
830 echo "Set build target to '${targets:?}'"
831 set_hook_var "tftf_build_targets" "$targets"
832}
833
834set_scp_build_targets() {
835 echo "Set build target to '${targets:?}'"
836 set_hook_var "scp_build_targets" "$targets"
837}
838
Olivier Deprez0a9a3482019-12-16 14:10:31 +0100839set_spm_build_targets() {
840 echo "Set build target to '${targets:?}'"
841 set_hook_var "spm_build_targets" "$targets"
842}
843
Fathi Boudra422bf772019-12-02 11:10:16 +0200844# Look under $archive directory for known files such as blX images, kernel, DTB,
845# initrd etc. For each known file foo, if foo.bin exists, then set variable
846# foo_bin to the path of the file. Make the path relative to the workspace so as
847# to remove any @ characters, which Jenkins inserts for parallel runs. If the
848# file doesn't exist, unset its path.
849set_default_bin_paths() {
850 local image image_name image_path path
851 local archive="${archive:?}"
852 local set_vars
853 local var
854
855 pushd "$archive"
856
857 for file in *.bin; do
858 # Get a shell variable from the file's stem
859 var_name="${file%%.*}_bin"
860 var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')"
861
862 # Skip setting the variable if it's already
863 if [ "${!var_name}" ]; then
864 echo "Note: not setting $var_name; already set to ${!var_name}"
865 continue
866 else
867 set_vars+="$var_name "
868 fi
869
870 eval "$var_name=$file"
871 done
872
873 echo "Binary paths set for: "
874 {
875 for var in $set_vars; do
876 echo -n "\$$var "
877 done
878 } | fmt -80 | sed 's/^/ /'
879 echo
880
881 popd
882}
883
884gen_model_params() {
885 local model_param_file="$archive/model_params"
Javier Almansa Sobrinoe8363182020-11-10 16:40:53 +0000886 [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1
Fathi Boudra422bf772019-12-02 11:10:16 +0200887
888 set_default_bin_paths
889 echo "Generating model parameter for $model..."
890 source "$ci_root/model/${model:?}.sh"
891 archive_file "$model_param_file"
892}
893
894set_model_path() {
895 set_run_env "model_path" "${1:?}"
896}
897
Zelalem1af7a7b2020-08-04 17:34:32 -0500898set_model_env() {
899 local var="${1:?}"
900 local val="${2?}"
901 local run_root="${archive:?}/run"
902
903 mkdir -p "$run_root"
904 echo "export $var=$val" >> "$run_root/model_env"
905}
Fathi Boudra422bf772019-12-02 11:10:16 +0200906set_run_env() {
907 local var="${1:?}"
908 local val="${2?}"
909 local run_root="${archive:?}/run"
910
911 mkdir -p "$run_root"
912 env_file="$run_root/env" quote="1" emit_env "$var" "$val"
913}
914
915show_head() {
916 # Display HEAD descripton
917 pushd "$1"
918 git show --quiet --no-color | sed 's/^/ > /g'
919 echo
920 popd
921}
922
923# Choose debug binaries to run; by default, release binaries are chosen to run
924use_debug_bins() {
925 local run_root="${archive:?}/run"
926
927 echo "Choosing debug binaries for execution"
928 set_package_var "BIN_MODE" "debug"
929}
930
931assert_can_git_clone() {
932 local name="${1:?}"
933 local dir="${!name}"
934
935 # If it doesn't exist, it can be cloned into
936 if [ ! -e "$dir" ]; then
937 return 0
938 fi
939
940 # If it's a directory, it must be a Git clone already
941 if [ -d "$dir" ] && [ -d "$dir/.git" ]; then
942 # No need to clone again
943 echo "Using existing git clone for $name: $dir"
944 return 1
945 fi
946
947 die "Path $dir exists but is not a git clone"
948}
949
950clone_repo() {
951 if ! is_url "${clone_url?}"; then
952 # For --depth to take effect on local paths, it needs to use the
953 # file:// scheme.
954 clone_url="file://$clone_url"
955 fi
956
957 git clone -q --depth 1 "$clone_url" "${where?}"
958 if [ "$refspec" ]; then
959 pushd "$where"
960 git fetch -q --depth 1 origin "$refspec"
961 git checkout -q FETCH_HEAD
962 popd
963 fi
964}
965
966build_unstable() {
967 echo "--BUILD UNSTABLE--" | tee -a "$build_log"
968}
969
970undo_patch_record() {
971 if [ ! -f "${patch_record:?}" ]; then
972 return
973 fi
974
975 # Undo patches in reverse
976 echo
977 for patch_name in $(tac "$patch_record"); do
978 echo "Undoing $patch_name..."
979 if ! git apply -R "$ci_root/patch/$patch_name"; then
980 if upon "$local_ci"; then
981 echo
982 echo "Your local directory may have been dirtied."
983 echo
984 fi
985 fail_build
986 fi
987 done
988
989 rm -f "$patch_record"
990}
991
992undo_local_patches() {
993 pushd "$tf_root"
994 patch_record="$tf_patch_record" undo_patch_record
995 popd
996
997 if [ -d "$tftf_root" ]; then
998 pushd "$tftf_root"
999 patch_record="$tftf_patch_record" undo_patch_record
1000 popd
1001 fi
1002}
1003
1004undo_tftf_patches() {
1005 pushd "$tftf_root"
1006 patch_record="$tftf_patch_record" undo_patch_record
1007 popd
1008}
1009
1010undo_tf_patches() {
1011 pushd "$tf_root"
1012 patch_record="$tf_patch_record" undo_patch_record
1013 popd
1014}
1015
1016apply_patch() {
1017 # If skip_patches is set, the developer has applied required patches
1018 # manually. They probably want to keep them applied for debugging
1019 # purposes too. This means we don't have to apply/revert them as part of
1020 # build process.
1021 if upon "$skip_patches"; then
1022 echo "Skipped applying ${1:?}..."
1023 return 0
1024 else
1025 echo "Applying ${1:?}..."
1026 fi
1027
1028 if git apply < "$ci_root/patch/$1"; then
1029 echo "$1" >> "${patch_record:?}"
1030 else
1031 if upon "$local_ci"; then
1032 undo_local_patches
1033 fi
1034 fail_build
1035 fi
1036}
1037
1038apply_tftf_patch() {
1039 pushd "$tftf_root"
1040 patch_record="$tftf_patch_record" apply_patch "$1"
1041 popd
1042}
1043
1044apply_tf_patch() {
1045 pushd "$tf_root"
1046 patch_record="$tf_patch_record" apply_patch "$1"
1047 popd
1048}
1049
1050# Clear workspace for a local run
1051if not_upon "$jenkins_run"; then
1052 rm -rf "$workspace"
1053
1054 # Clear residue from previous runs
1055 rm -rf "$archive"
1056fi
1057
1058mkdir -p "$workspace"
1059mkdir -p "$archive"
1060set_package_var "TEST_CONFIG" "$test_config"
1061
1062{
1063echo
1064echo "CONFIGURATION: $test_group/$test_config"
1065echo
1066} |& log_separator
1067
1068tf_config="$(echo "$build_configs" | awk -F, '{print $1}')"
1069tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')"
1070scp_config="$(echo "$build_configs" | awk -F, '{print $3}')"
Zelalem219df412020-05-17 19:21:20 -05001071scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001072spm_config="$(echo "$build_configs" | awk -F, '{print $5}')"
Fathi Boudra422bf772019-12-02 11:10:16 +02001073
1074test_config_file="$ci_root/group/$test_group/$test_config"
1075
1076tf_config_file="$ci_root/tf_config/$tf_config"
1077tftf_config_file="$ci_root/tftf_config/$tftf_config"
1078scp_config_file="$ci_root/scp_config/$scp_config"
Zelalem219df412020-05-17 19:21:20 -05001079scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001080spm_config_file="$ci_root/spm_config/$spm_config"
Fathi Boudra422bf772019-12-02 11:10:16 +02001081
1082# File that keeps track of applied patches
1083tf_patch_record="$workspace/tf_patches"
1084tftf_patch_record="$workspace/tftf_patches"
1085
1086pushd "$workspace"
1087
1088if ! config_valid "$tf_config"; then
1089 tf_config=
1090else
1091 echo "Trusted Firmware config:"
1092 echo
1093 sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/'
1094 echo
1095fi
1096
1097if ! config_valid "$tftf_config"; then
1098 tftf_config=
1099else
1100 echo "Trusted Firmware TF config:"
1101 echo
1102 sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/'
1103 echo
1104fi
1105
1106if ! config_valid "$scp_config"; then
1107 scp_config=
1108else
1109 echo "SCP firmware config:"
1110 echo
1111 sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/'
1112 echo
1113fi
1114
Zelalem219df412020-05-17 19:21:20 -05001115if ! config_valid "$scp_tools_config"; then
1116 scp_tools_config=
1117else
1118 echo "SCP Tools config:"
1119 echo
1120 sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/'
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001121fi
1122
1123if ! config_valid "$spm_config"; then
1124 spm_config=
1125else
1126 echo "SPM config:"
1127 echo
1128 sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/'
Zelalem219df412020-05-17 19:21:20 -05001129 echo
1130fi
1131
Fathi Boudra422bf772019-12-02 11:10:16 +02001132if ! config_valid "$run_config"; then
1133 run_config=
1134fi
1135
1136if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then
1137 # If the Trusted Firmware repository has already been checked out, use
1138 # that location. Otherwise, clone one ourselves.
1139 echo "Cloning Trusted Firmware..."
1140 clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \
1141 refspec="$TF_REFSPEC" clone_repo &>>"$build_log"
1142 show_head "$tf_root"
1143fi
1144
1145if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then
1146 # If the Trusted Firmware TF repository has already been checked out,
1147 # use that location. Otherwise, clone one ourselves.
1148 echo "Cloning Trusted Firmware TF..."
1149 clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \
1150 refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log"
1151 show_head "$tftf_root"
1152fi
1153
1154if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then
1155 # If the SCP firmware repository has already been checked out,
1156 # use that location. Otherwise, clone one ourselves.
1157 echo "Cloning SCP Firmware..."
1158 clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \
1159 refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log"
1160
1161 pushd "$scp_root"
1162
1163 # Use filer submodule as a reference if it exists
Girish Pathak31b824e2021-03-03 20:58:21 +00001164 if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then
Fathi Boudra422bf772019-12-02 11:10:16 +02001165 cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis"
1166 fi
1167
1168 # If we don't have a reference yet, fall back to $cmsis_root if set, or
1169 # then to project filer if accessible.
1170 if [ -z "$cmsis_reference" ]; then
1171 cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}"
1172 if [ -d "$cmsis_ref_repo" ]; then
1173 cmsis_reference="--reference $cmsis_ref_repo"
1174 fi
1175 fi
1176
1177 git submodule -q update $cmsis_reference --init
1178
1179 popd
1180
1181 show_head "$scp_root"
1182fi
1183
Zelalem219df412020-05-17 19:21:20 -05001184if [ -n "$cc_config" ] ; then
1185 if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then
1186 # Copy code coverage repository
1187 echo "Cloning Code Coverage..."
1188 git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null
1189 show_head "$cc_root"
1190 fi
1191fi
1192
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001193if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then
1194 # If the SPM repository has already been checked out, use
1195 # that location. Otherwise, clone one ourselves.
1196 echo "Cloning SPM..."
1197 clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \
1198 refspec="$SPM_REFSPEC" clone_repo &>>"$build_log"
1199
1200 # Query git submodules
1201 pushd "$spm_root"
1202 git submodule update --init
1203 popd
1204
1205 show_head "$spm_root"
1206fi
1207
Fathi Boudra422bf772019-12-02 11:10:16 +02001208if [ "$run_config" ]; then
1209 # Get candidates for run config
1210 run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \
1211 "$run_config")"
1212 if [ -z "$run_config_candiates" ]; then
1213 die "No run config candidates!"
1214 else
1215 echo
1216 echo "Chosen fragments:"
1217 echo
1218 echo "$run_config_candiates" | sed 's/^\|\n/\t/g'
1219 echo
1220 fi
1221fi
1222
1223call_hook "test_setup"
1224echo
1225
1226if upon "$local_ci"; then
1227 # For local runs, since each config is tried in sequence, it's
1228 # advantageous to run jobs in parallel
1229 if [ "$make_j" ]; then
1230 make_j_opts="-j $make_j"
1231 else
1232 n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true
1233 if [ "$n_cores" ]; then
1234 make_j_opts="-j $n_cores"
1235 fi
1236 fi
1237fi
1238
1239modes="${bin_mode:-debug release}"
1240for mode in $modes; do
1241 # Build with a temporary archive
1242 build_archive="$archive/$mode"
1243 mkdir "$build_archive"
1244
1245 if [ "$mode" = "debug" ]; then
Zelalem219df412020-05-17 19:21:20 -05001246 export bin_mode="debug"
Fathi Boudra422bf772019-12-02 11:10:16 +02001247 DEBUG=1
1248 else
Zelalem219df412020-05-17 19:21:20 -05001249 export bin_mode="release"
Fathi Boudra422bf772019-12-02 11:10:16 +02001250 DEBUG=0
1251 fi
1252
1253 # Perform builds in a subshell so as not to pollute the current and
1254 # subsequent builds' environment
1255
Zelalem219df412020-05-17 19:21:20 -05001256 if config_valid "$cc_config"; then
1257 # Build code coverage plugin
1258 build_cc
1259 fi
1260
Fathi Boudra422bf772019-12-02 11:10:16 +02001261 # SCP build
1262 if config_valid "$scp_config"; then
1263 (
1264 echo "##########"
1265
1266 # Source platform-specific utilities
1267 plat="$(get_scp_opt PRODUCT)"
1268 plat_utils="$ci_root/${plat}_utils.sh"
1269 if [ -f "$plat_utils" ]; then
1270 source "$plat_utils"
1271 fi
1272
1273 archive="$build_archive"
1274 scp_build_root="$scp_root/build"
1275
1276 echo "Building SCP Firmware ($mode) ..." |& log_separator
1277
1278 build_scp
Fathi Boudra422bf772019-12-02 11:10:16 +02001279 to="$archive" collect_scp_artefacts
1280
1281 echo "##########"
1282 echo
1283 )
1284 fi
1285
Zelalem219df412020-05-17 19:21:20 -05001286 # SCP-tools build
1287 if config_valid "$scp_tools_config"; then
1288 (
1289 echo "##########"
1290
1291 archive="$build_archive"
1292 scp_tools_build_root="$scp_tools_root/build"
1293
1294 clone_scp_tools
1295
1296 echo "##########"
1297 echo
1298
1299 echo "##########"
1300 clone_tf_for_scp_tools
1301 echo "##########"
1302 echo
1303 )
1304 fi
1305
Fathi Boudra422bf772019-12-02 11:10:16 +02001306 # TFTF build
1307 if config_valid "$tftf_config"; then
1308 (
1309 echo "##########"
1310
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001311 plat_utils="$(get_tf_opt PLAT_UTILS)"
1312 if [ -z ${plat_utils} ]; then
1313 # Source platform-specific utilities.
1314 plat="$(get_tftf_opt PLAT)"
1315 plat_utils="$ci_root/${plat}_utils.sh"
1316 else
1317 # Source platform-specific utilities by
1318 # using plat_utils name.
1319 plat_utils="$ci_root/${plat_utils}.sh"
1320 fi
1321
Fathi Boudra422bf772019-12-02 11:10:16 +02001322 if [ -f "$plat_utils" ]; then
1323 source "$plat_utils"
1324 fi
1325
1326 archive="$build_archive"
1327 tftf_build_root="$tftf_root/build"
1328
1329 echo "Building Trusted Firmware TF ($mode) ..." |& log_separator
1330
1331 # Call pre-build hook
1332 call_hook pre_tftf_build
1333
1334 build_tftf
1335
1336 from="$tftf_build_root" to="$archive" collect_build_artefacts
1337
1338 # Clear any local changes made by applied patches
1339 undo_tftf_patches
1340
1341 echo "##########"
1342 echo
1343 )
1344 fi
1345
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001346 # SPM build
1347 if config_valid "$spm_config"; then
1348 (
1349 echo "##########"
1350
1351 # Get platform name from spm_config file
1352 plat="$(echo "$spm_config" | awk -F- '{print $1}')"
1353 plat_utils="$ci_root/${plat}_utils.sh"
1354 if [ -f "$plat_utils" ]; then
1355 source "$plat_utils"
1356 fi
1357
Manish Pandey1e7be852020-11-09 16:04:48 +00001358 # SPM build generates two sets of binaries, one for normal and other
1359 # for Secure world. We need both set of binaries for CI.
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001360 archive="$build_archive"
Manish Pandey1e7be852020-11-09 16:04:48 +00001361 spm_build_root="$spm_root/out/reference/$spm_secure_out_dir"
1362 hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir"
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001363
1364 echo "Building SPM ($mode) ..." |& log_separator
1365
1366 # NOTE: mode has no effect on SPM build (for now), hence debug
1367 # mode is built but subsequent build using release mode just
1368 # goes through with "nothing to do".
1369 build_spm
1370
1371 # Show SPM/Hafnium binary details
Madhukar Pappireddyc683cf62021-11-01 14:38:32 -05001372 cksum $spm_build_root/hafnium.bin
1373
1374 # Some platforms only have secure configuration enabled. Hence,
1375 # non secure hanfnium binary might not be built.
1376 if [ -f $hafnium_build_root/hafnium.bin ]; then
1377 cksum $hafnium_build_root/hafnium.bin
1378 fi
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001379
Manish Pandey1e7be852020-11-09 16:04:48 +00001380 secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts
Olivier Deprez0a9a3482019-12-16 14:10:31 +01001381
1382 echo "##########"
1383 echo
1384 )
1385 fi
1386
Fathi Boudra422bf772019-12-02 11:10:16 +02001387 # TF build
1388 if config_valid "$tf_config"; then
1389 (
1390 echo "##########"
1391
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001392 plat_utils="$(get_tf_opt PLAT_UTILS)"
Madhukar Pappireddy2f284e12021-08-30 16:06:14 -05001393 export plat_variant="$(get_tf_opt TARGET_PLATFORM)"
1394
Manish V Badarkhe3bd3fea2020-11-08 15:17:00 +00001395 if [ -z ${plat_utils} ]; then
1396 # Source platform-specific utilities.
1397 plat="$(get_tf_opt PLAT)"
1398 plat_utils="$ci_root/${plat}_utils.sh"
1399 else
1400 # Source platform-specific utilities by
1401 # using plat_utils name.
1402 plat_utils="$ci_root/${plat_utils}.sh"
1403 fi
1404
Fathi Boudra422bf772019-12-02 11:10:16 +02001405 if [ -f "$plat_utils" ]; then
1406 source "$plat_utils"
1407 fi
1408
Chris Kayd0837902021-11-17 10:17:52 +00001409 source "$ci_root/script/install_python_deps_tf.sh"
1410
Fathi Boudra422bf772019-12-02 11:10:16 +02001411 archive="$build_archive"
1412 tf_build_root="$tf_root/build"
1413
1414 echo "Building Trusted Firmware ($mode) ..." |& log_separator
1415
1416 # Call pre-build hook
1417 call_hook pre_tf_build
1418
1419 build_tf
1420
1421 # Call post-build hook
1422 call_hook post_tf_build
1423
1424 # Pre-archive hook
1425 call_hook pre_tf_archive
1426
1427 from="$tf_build_root" to="$archive" collect_build_artefacts
1428
1429 # Post-archive hook
1430 call_hook post_tf_archive
1431
1432 call_hook fetch_tf_resource
1433 call_hook post_fetch_tf_resource
1434
1435 # Clear any local changes made by applied patches
1436 undo_tf_patches
1437
1438 echo "##########"
1439 )
1440 fi
1441
1442 echo
1443 echo
1444done
1445
1446call_hook pre_package
1447
1448call_hook post_package
1449
1450if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then
Zelalem219df412020-05-17 19:21:20 -05001451 source "$CI_ROOT/script/send_artefacts.sh" "artefacts"
Fathi Boudra422bf772019-12-02 11:10:16 +02001452fi
1453
1454echo
1455echo "Done"