Leonardo Sandoval | 9dfdd1b | 2020-08-06 17:08:11 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 2 | # |
Anurag Koul | baedf93 | 2021-12-09 12:49:56 +0000 | [diff] [blame] | 3 | # Copyright (c) 2019-2022 Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 4 | # |
| 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 | |
| 11 | set -e |
| 12 | |
| 13 | ci_root="$(readlink -f "$(dirname "$0")/..")" |
| 14 | source "$ci_root/utils.sh" |
| 15 | |
| 16 | if [ ! -d "$workspace" ]; then |
| 17 | die "Directory $workspace doesn't exist" |
| 18 | fi |
| 19 | |
| 20 | # Directory to where the source code e.g. for Trusted Firmware is checked out. |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 21 | export tf_root="${tf_root:-$workspace/trusted_firmware}" |
| 22 | export tftf_root="${tftf_root:-$workspace/trusted_firmware_tf}" |
| 23 | export scp_root="${scp_root:-$workspace/scp}" |
| 24 | scp_tools_root="${scp_tools_root:-$workspace/scp_tools}" |
| 25 | cc_root="${cc_root:-$ccpathspec}" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 26 | spm_root="${spm_root:-$workspace/spm}" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 27 | |
| 28 | scp_tf_tools_root="$scp_tools_root/scp_tf_tools" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 29 | |
| 30 | # Refspecs |
| 31 | tf_refspec="$TF_REFSPEC" |
| 32 | tftf_refspec="$TFTF_REFSPEC" |
| 33 | scp_refspec="$SCP_REFSPEC" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 34 | scp_tools_commit="${SCP_TOOLS_COMMIT:-master}" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 35 | spm_refspec="$SPM_REFSPEC" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 36 | |
| 37 | test_config="${TEST_CONFIG:?}" |
| 38 | test_group="${TEST_GROUP:?}" |
| 39 | build_configs="${BUILD_CONFIG:?}" |
| 40 | run_config="${RUN_CONFIG:?}" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 41 | cc_config="${CC_ENABLE:-}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 42 | |
| 43 | archive="$artefacts" |
| 44 | build_log="$artefacts/build.log" |
| 45 | fiptool="$tf_root/tools/fiptool/fiptool" |
| 46 | cert_create="$tf_root/tools/cert_create/cert_create" |
| 47 | |
| 48 | # Validate $bin_mode |
| 49 | case "$bin_mode" in |
| 50 | "" | debug | release) |
| 51 | ;; |
| 52 | *) |
| 53 | die "Invalid value for bin_mode: $bin_mode" |
| 54 | ;; |
| 55 | esac |
| 56 | |
| 57 | # File to save any environem |
| 58 | hook_env_file="$(mktempfile)" |
| 59 | |
| 60 | # Check if a config is valid |
| 61 | config_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. |
| 72 | echo_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 |
| 77 | log_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 |
| 92 | call_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 |
| 105 | call_hook() { |
| 106 | local func="$1" |
| 107 | local config_fragment |
| 108 | |
| 109 | [ -z "$func" ] && return 0 |
| 110 | |
Paul Sokolovsky | e9962cd | 2021-12-17 18:39:40 +0300 | [diff] [blame] | 111 | echo "=== Calling hooks: $1 ===" |
| 112 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 113 | : >"$hook_env_file" |
| 114 | |
| 115 | if [ "$run_config_candiates" ]; then |
| 116 | for config_fragment in $run_config_candiates; do |
| 117 | ( |
| 118 | source "$ci_root/run_config/$config_fragment" |
| 119 | call_func "$func" "$config_fragment" |
| 120 | ) |
| 121 | done |
| 122 | fi |
| 123 | |
| 124 | # Also source test config file |
| 125 | ( |
| 126 | unset "$func" |
| 127 | source "$test_config_file" |
| 128 | call_func "$func" "$(basename $test_config_file)" |
| 129 | ) |
| 130 | |
| 131 | # Have any variables set take effect |
| 132 | source "$hook_env_file" |
Paul Sokolovsky | e9962cd | 2021-12-17 18:39:40 +0300 | [diff] [blame] | 133 | |
| 134 | echo "=== End calling hooks: $1 ===" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | # Set a variable from within a hook |
| 138 | set_hook_var() { |
| 139 | echo "export $1=\"${2?}\"" >> "$hook_env_file" |
| 140 | } |
| 141 | |
| 142 | # Append to an array from within a hook |
| 143 | append_hook_var() { |
| 144 | echo "export $1+=\"${2?}\"" >> "$hook_env_file" |
| 145 | } |
| 146 | |
| 147 | # Have the main build script source a file |
| 148 | source_later() { |
| 149 | echo "source ${1?}" >> "$hook_env_file" |
| 150 | } |
| 151 | |
| 152 | # Setup TF build wrapper function by pointing to a script containing a function |
| 153 | # that will be called with the TF build commands. |
| 154 | setup_tf_build_wrapper() { |
| 155 | source_later "$ci_root/script/${wrapper?}_wrapper.sh" |
| 156 | set_hook_var "tf_build_wrapper" "${wrapper}_wrapper" |
| 157 | echo "Setup $wrapper build wrapper." |
| 158 | } |
| 159 | |
| 160 | # Collect .bin files for archiving |
| 161 | collect_build_artefacts() { |
| 162 | if [ ! -d "${from:?}" ]; then |
| 163 | return |
| 164 | fi |
| 165 | |
Javier Almansa Sobrino | f98dbd8 | 2020-09-30 19:29:27 +0100 | [diff] [blame] | 166 | if ! find "$from" \( -name "*.bin" -o -name '*.elf' -o -name '*.dtb' -o -name '*.axf' \) -exec cp -t "${to:?}" '{}' +; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 167 | echo "You probably are running local CI on local repositories." |
| 168 | echo "Did you set 'dont_clean' but forgot to run 'distclean'?" |
| 169 | die |
| 170 | fi |
| 171 | } |
| 172 | |
| 173 | # SCP and MCP binaries are named firmware.{bin,elf}, and are placed under |
| 174 | # scp/mcp_ramfw and scp/mcp_romfw directories, so can't be collected by |
| 175 | # collect_build_artefacts function. |
| 176 | collect_scp_artefacts() { |
| 177 | to="${to:?}" \ |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 178 | find "$scp_root" \( \( -name "*.bin" -o -name '*.elf' \) -and ! -name 'CMake*' \) -exec bash -c ' |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 179 | for file; do |
| 180 | ext="$(echo $file | awk -F. "{print \$NF}")" |
| 181 | case $file in |
Anurag Koul | baedf93 | 2021-12-09 12:49:56 +0000 | [diff] [blame] | 182 | */firmware-scp_ramfw/bin/*|*/firmware-scp_ramfw_fvp/bin/*) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 183 | cp $file $to/scp_ram.$ext |
| 184 | ;; |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 185 | */firmware-scp_romfw/bin/*) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 186 | cp $file $to/scp_rom.$ext |
| 187 | ;; |
Anurag Koul | baedf93 | 2021-12-09 12:49:56 +0000 | [diff] [blame] | 188 | */firmware-mcp_ramfw/bin/*|*/firmware-mcp_ramfw_fvp/bin/*) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 189 | cp $file $to/mcp_ram.$ext |
| 190 | ;; |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 191 | */firmware-mcp_romfw/bin/*) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 192 | cp $file $to/mcp_rom.$ext |
| 193 | ;; |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 194 | */firmware-scp_romfw_bypass/bin/*) |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 195 | cp $file $to/scp_rom_bypass.$ext |
| 196 | ;; |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 197 | *) |
| 198 | echo "Unknown SCP binary: $file" >&2 |
| 199 | ;; |
| 200 | esac |
| 201 | done |
| 202 | ' bash '{}' + |
| 203 | } |
| 204 | |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 205 | # Collect SPM/hafnium artefacts with "secure_" appended to the files |
| 206 | # generated for SPM(secure hafnium). |
| 207 | collect_spm_artefacts() { |
Madhukar Pappireddy | c683cf6 | 2021-11-01 14:38:32 -0500 | [diff] [blame] | 208 | if [ -d "${non_secure_from:?}" ]; then |
| 209 | find "$non_secure_from" \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' + |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 210 | fi |
| 211 | |
Madhukar Pappireddy | c683cf6 | 2021-11-01 14:38:32 -0500 | [diff] [blame] | 212 | if [ -d "${secure_from:?}" ]; then |
| 213 | for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done |
| 214 | fi |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Javier Almansa Sobrino | 412d361 | 2020-05-22 17:53:12 +0100 | [diff] [blame] | 217 | # Map the UART ID used for expect with the UART descriptor and port |
| 218 | # used by the FPGA automation tools. |
| 219 | map_uart() { |
| 220 | local port="${port:?}" |
| 221 | local descriptor="${descriptor:?}" |
| 222 | local baudrate="${baudrate:?}" |
| 223 | local run_root="${archive:?}/run" |
| 224 | |
| 225 | local uart_dir="$run_root/uart${uart:?}" |
| 226 | mkdir -p "$uart_dir" |
| 227 | |
| 228 | echo "$port" > "$uart_dir/port" |
| 229 | echo "$descriptor" > "$uart_dir/descriptor" |
| 230 | echo "$baudrate" > "$uart_dir/baudrate" |
| 231 | |
| 232 | echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}" |
| 233 | } |
| 234 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 235 | # Arrange environment varibles to be set when expect scripts are launched |
| 236 | set_expect_variable() { |
| 237 | local var="${1:?}" |
| 238 | local val="${2?}" |
| 239 | |
| 240 | local run_root="${archive:?}/run" |
| 241 | local uart_dir="$run_root/uart${uart:?}" |
| 242 | mkdir -p "$uart_dir" |
| 243 | |
| 244 | env_file="$uart_dir/env" quote="1" emit_env "$var" "$val" |
| 245 | echo "UART$uart: env has $@" |
| 246 | } |
| 247 | |
| 248 | # Place the binary package a pointer to expect script, and its parameters |
| 249 | track_expect() { |
| 250 | local file="${file:?}" |
| 251 | local timeout="${timeout-600}" |
| 252 | local run_root="${archive:?}/run" |
| 253 | |
| 254 | local uart_dir="$run_root/uart${uart:?}" |
| 255 | mkdir -p "$uart_dir" |
| 256 | |
| 257 | echo "$file" > "$uart_dir/expect" |
| 258 | echo "$timeout" > "$uart_dir/timeout" |
| 259 | |
| 260 | echo "UART$uart to be tracked with $file; timeout ${timeout}s" |
| 261 | |
Chris Kay | fab6edc | 2022-11-17 19:18:32 +0000 | [diff] [blame] | 262 | if [ ! -z "${port}" ]; then |
| 263 | echo "${port}" > "$uart_dir/port" |
| 264 | fi |
| 265 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 266 | # The run script assumes UART0 to be primary. If we're asked to set any |
| 267 | # other UART to be primary, set a run environment variable to signal |
| 268 | # that to the run script |
| 269 | if upon "$set_primary"; then |
| 270 | echo "Primary UART set to UART$uart." |
| 271 | set_run_env "primary_uart" "$uart" |
| 272 | fi |
Madhukar Pappireddy | 1e95372 | 2021-11-08 15:23:02 -0600 | [diff] [blame] | 273 | |
| 274 | # UART used by payload(such as tftf, Linux) may not be the same as the |
| 275 | # primary UART. Set a run environment variable to track the payload |
| 276 | # UART which is tracked to check if the test has finished sucessfully. |
| 277 | if upon "$set_payload_uart"; then |
| 278 | echo "Payload uses UART$uart." |
| 279 | set_run_env "payload_uart" "$uart" |
| 280 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | # Extract a FIP in $1 using fiptool |
| 284 | extract_fip() { |
| 285 | local fip="$1" |
| 286 | |
| 287 | if is_url "$1"; then |
| 288 | url="$1" fetch_file |
| 289 | fip="$(basename "$1")" |
| 290 | fi |
| 291 | |
| 292 | "$fiptool" unpack "$fip" |
| 293 | echo "Extracted FIP: $fip" |
| 294 | } |
| 295 | |
| 296 | # Report build failure by printing a the tail end of build log. Archive the |
| 297 | # build log for later inspection |
| 298 | fail_build() { |
| 299 | local log_path |
| 300 | |
| 301 | if upon "$jenkins_run"; then |
| 302 | log_path="$BUILD_URL/artifact/artefacts/build.log" |
| 303 | else |
| 304 | log_path="$build_log" |
| 305 | fi |
| 306 | |
| 307 | echo |
Leonardo Sandoval | ae97eda | 2020-11-12 10:07:03 -0600 | [diff] [blame] | 308 | echo "Build failed! Full build log below:" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 309 | echo "[...]" |
| 310 | echo |
Leonardo Sandoval | ae97eda | 2020-11-12 10:07:03 -0600 | [diff] [blame] | 311 | cat "$build_log" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 312 | echo |
| 313 | echo "See $log_path for full output" |
| 314 | echo |
| 315 | cp -t "$archive" "$build_log" |
| 316 | exit 1; |
| 317 | } |
| 318 | |
| 319 | # Build a FIP with supplied arguments |
| 320 | build_fip() { |
| 321 | ( |
| 322 | echo "Building FIP with arguments: $@" |
| 323 | local tf_env="$workspace/tf.env" |
| 324 | |
| 325 | if [ -f "$tf_env" ]; then |
| 326 | set -a |
| 327 | source "$tf_env" |
| 328 | set +a |
| 329 | fi |
| 330 | |
| 331 | make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \ |
| 332 | ${fip_targets:-fip} &>>"$build_log" || fail_build |
| 333 | ) |
| 334 | } |
| 335 | |
| 336 | fip_update() { |
| 337 | # Before the update process, check if the given image is supported by |
| 338 | # the fiptool. It's assumed that both fiptool and cert_create move in |
| 339 | # tandem, and therfore, if one has support, the other has it too. |
| 340 | if ! "$fiptool" update 2>&1 | grep -qe "\s\+--${bin_name:?}"; then |
| 341 | return 1 |
| 342 | fi |
| 343 | |
| 344 | if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then |
| 345 | echo "Updating FIP image: $bin_name" |
| 346 | # Update HW config. Without TBBR, it's only a matter of using |
| 347 | # the update sub-command of fiptool |
| 348 | "$fiptool" update "--$bin_name" "${src:-}" \ |
| 349 | "$archive/fip.bin" |
| 350 | else |
| 351 | echo "Updating FIP image (TBBR): $bin_name" |
| 352 | # With TBBR, we need to unpack, re-create certificates, and then |
| 353 | # recreate the FIP. |
| 354 | local fip_dir="$(mktempdir)" |
| 355 | local bin common_args stem |
| 356 | local rot_key="$(get_tf_opt ROT_KEY)" |
| 357 | |
| 358 | rot_key="${rot_key:?}" |
| 359 | if ! is_abs "$rot_key"; then |
| 360 | rot_key="$tf_root/$rot_key" |
| 361 | fi |
| 362 | |
| 363 | # Arguments only for cert_create |
| 364 | local cert_args="-n" |
| 365 | cert_args+=" --tfw-nvctr ${nvctr:-31}" |
| 366 | cert_args+=" --ntfw-nvctr ${nvctr:-223}" |
| 367 | cert_args+=" --key-alg ${KEY_ALG:-rsa}" |
| 368 | cert_args+=" --rot-key $rot_key" |
| 369 | |
| 370 | local dyn_config_opts=( |
Zelalem | 1af7a7b | 2020-08-04 17:34:32 -0500 | [diff] [blame] | 371 | "fw-config" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 372 | "hw-config" |
| 373 | "tb-fw-config" |
| 374 | "nt-fw-config" |
| 375 | "soc-fw-config" |
| 376 | "tos-fw-config" |
| 377 | ) |
| 378 | |
| 379 | # Binaries without key certificates |
| 380 | declare -A has_no_key_cert |
| 381 | for bin in "tb-fw" "${dyn_config_opts[@]}"; do |
| 382 | has_no_key_cert["$bin"]="1" |
| 383 | done |
| 384 | |
| 385 | # Binaries without certificates |
| 386 | declare -A has_no_cert |
| 387 | for bin in "hw-config" "${dyn_config_opts[@]}"; do |
| 388 | has_no_cert["$bin"]="1" |
| 389 | done |
| 390 | |
| 391 | pushd "$fip_dir" |
| 392 | |
| 393 | # Unpack FIP |
| 394 | "$fiptool" unpack "$archive/fip.bin" &>>"$build_log" |
| 395 | |
| 396 | # Remove all existing certificates |
| 397 | rm -f *-cert.bin |
| 398 | |
| 399 | # Copy the binary to be updated |
| 400 | cp -f "$src" "${bin_name}.bin" |
| 401 | |
| 402 | # FIP unpack dumps binaries with the same name as the option |
| 403 | # used to pack it; likewise for certificates. Reverse-engineer |
| 404 | # the command line from the binary output. |
| 405 | common_args="--trusted-key-cert trusted_key.crt" |
| 406 | for bin in *.bin; do |
| 407 | stem="${bin%%.bin}" |
| 408 | common_args+=" --$stem $bin" |
| 409 | if not_upon "${has_no_cert[$stem]}"; then |
| 410 | common_args+=" --$stem-cert $stem.crt" |
| 411 | fi |
| 412 | if not_upon "${has_no_key_cert[$stem]}"; then |
| 413 | common_args+=" --$stem-key-cert $stem-key.crt" |
| 414 | fi |
| 415 | done |
| 416 | |
| 417 | # Create certificates |
| 418 | "$cert_create" $cert_args $common_args &>>"$build_log" |
| 419 | |
| 420 | # Recreate and archive FIP |
| 421 | "$fiptool" create $common_args "fip.bin" &>>"$build_log" |
| 422 | archive_file "fip.bin" |
| 423 | |
| 424 | popd |
| 425 | fi |
| 426 | } |
| 427 | |
| 428 | # Update hw-config in FIP, and remove the original DTB afterwards. |
| 429 | update_fip_hw_config() { |
| 430 | # The DTB needs to be loaded by the model (and not updated in the FIP) |
Madhukar Pappireddy | 9062ebf | 2021-03-02 17:07:06 -0600 | [diff] [blame] | 431 | # in configs: |
| 432 | # 1. Where BL2 isn't present |
| 433 | # 2. Where we boot to Linux directly as BL33 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 434 | case "1" in |
| 435 | "$(get_tf_opt RESET_TO_BL31)" | \ |
Madhukar Pappireddy | 9062ebf | 2021-03-02 17:07:06 -0600 | [diff] [blame] | 436 | "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \ |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 437 | "$(get_tf_opt RESET_TO_SP_MIN)" | \ |
| 438 | "$(get_tf_opt BL2_AT_EL3)") |
| 439 | return 0;; |
| 440 | esac |
| 441 | |
| 442 | if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then |
| 443 | # Remove the DTB so that model won't load it |
| 444 | rm -f "$archive/dtb.bin" |
| 445 | fi |
| 446 | } |
| 447 | |
| 448 | get_scp_opt() { |
| 449 | ( |
| 450 | name="${1:?}" |
| 451 | if config_valid "$scp_config_file"; then |
| 452 | source "$scp_config_file" |
| 453 | echo "${!name}" |
| 454 | fi |
| 455 | ) |
| 456 | } |
| 457 | |
| 458 | get_tftf_opt() { |
| 459 | ( |
| 460 | name="${1:?}" |
| 461 | if config_valid "$tftf_config_file"; then |
| 462 | source "$tftf_config_file" |
| 463 | echo "${!name}" |
| 464 | fi |
| 465 | ) |
| 466 | } |
| 467 | |
| 468 | get_tf_opt() { |
| 469 | ( |
| 470 | name="${1:?}" |
| 471 | if config_valid "$tf_config_file"; then |
| 472 | source "$tf_config_file" |
| 473 | echo "${!name}" |
| 474 | fi |
| 475 | ) |
| 476 | } |
| 477 | |
| 478 | build_tf() { |
| 479 | ( |
| 480 | env_file="$workspace/tf.env" |
| 481 | config_file="${tf_build_config:-$tf_config_file}" |
| 482 | |
| 483 | # Build fiptool and all targets by default |
Manish V Badarkhe | 57bea36 | 2022-07-12 22:43:30 +0100 | [diff] [blame] | 484 | build_targets="${tf_build_targets:-memmap fiptool all}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 485 | |
| 486 | source "$config_file" |
| 487 | |
| 488 | # If it is a TBBR build, extract the MBED TLS library from archive |
Manish V Badarkhe | 8f12501 | 2021-12-21 05:47:52 +0000 | [diff] [blame] | 489 | if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] || |
Manish V Badarkhe | f43e3f5 | 2022-06-21 20:37:25 +0100 | [diff] [blame] | 490 | [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] || |
| 491 | [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 492 | mbedtls_dir="$workspace/mbedtls" |
| 493 | if [ ! -d "$mbedtls_dir" ]; then |
| 494 | mbedtls_ar="$workspace/mbedtls.tar.gz" |
| 495 | |
| 496 | url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file |
| 497 | mkdir "$mbedtls_dir" |
Leonardo Sandoval | ec9e16c | 2020-09-09 14:32:40 -0500 | [diff] [blame] | 498 | extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 499 | fi |
| 500 | |
| 501 | emit_env "MBEDTLS_DIR" "$mbedtls_dir" |
| 502 | fi |
| 503 | |
| 504 | if [ -f "$env_file" ]; then |
| 505 | set -a |
| 506 | source "$env_file" |
| 507 | set +a |
| 508 | fi |
| 509 | |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 510 | if is_arm_jenkins_env || upon "$local_ci"; then |
| 511 | path_list=( |
| 512 | "$llvm_dir/bin" |
| 513 | ) |
| 514 | extend_path "PATH" "path_list" |
| 515 | fi |
| 516 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 517 | cd "$tf_root" |
| 518 | |
| 519 | # Always distclean when running on Jenkins. Skip distclean when running |
| 520 | # locally and explicitly requested. |
| 521 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
| 522 | make distclean &>>"$build_log" || fail_build |
| 523 | fi |
| 524 | |
| 525 | # Log build command line. It is left unfolded on purpose to assist |
| 526 | # copying to clipboard. |
| 527 | cat <<EOF | log_separator >/dev/null |
| 528 | |
| 529 | Build command line: |
| 530 | $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets |
| 531 | |
| 532 | EOF |
| 533 | |
Javier Almansa Sobrino | e836318 | 2020-11-10 16:40:53 +0000 | [diff] [blame] | 534 | if not_upon "$local_ci"; then |
| 535 | connect_debugger=0 |
| 536 | fi |
| 537 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 538 | # Build TF. Since build output is being directed to the build log, have |
| 539 | # descriptor 3 point to the current terminal for build wrappers to vent. |
| 540 | $tf_build_wrapper make $make_j_opts $(cat "$config_file") \ |
Javier Almansa Sobrino | e836318 | 2020-11-10 16:40:53 +0000 | [diff] [blame] | 541 | DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \ |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 542 | $build_targets 3>&1 &>>"$build_log" || fail_build |
| 543 | ) |
| 544 | } |
| 545 | |
| 546 | build_tftf() { |
| 547 | ( |
| 548 | config_file="${tftf_build_config:-$tftf_config_file}" |
| 549 | |
| 550 | # Build tftf target by default |
| 551 | build_targets="${tftf_build_targets:-all}" |
| 552 | |
| 553 | source "$config_file" |
| 554 | |
| 555 | cd "$tftf_root" |
| 556 | |
| 557 | # Always distclean when running on Jenkins. Skip distclean when running |
| 558 | # locally and explicitly requested. |
| 559 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
| 560 | make distclean &>>"$build_log" || fail_build |
| 561 | fi |
| 562 | |
| 563 | # TFTF build system cannot reliably deal with -j option, so we avoid |
| 564 | # using that. |
| 565 | |
| 566 | # Log build command line |
| 567 | cat <<EOF | log_separator >/dev/null |
| 568 | |
| 569 | Build command line: |
| 570 | make $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets |
| 571 | |
| 572 | EOF |
| 573 | |
| 574 | make $(cat "$config_file") DEBUG="$DEBUG" V=1 \ |
| 575 | $build_targets &>>"$build_log" || fail_build |
| 576 | ) |
| 577 | } |
| 578 | |
| 579 | build_scp() { |
| 580 | ( |
| 581 | config_file="${scp_build_config:-$scp_config_file}" |
| 582 | |
| 583 | source "$config_file" |
| 584 | |
| 585 | cd "$scp_root" |
| 586 | |
| 587 | # Always distclean when running on Jenkins. Skip distclean when running |
| 588 | # locally and explicitly requested. |
| 589 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
Leandro Belli | 99e20b2 | 2022-12-29 13:50:47 +0000 | [diff] [blame] | 590 | make -f Makefile.cmake clean &>>"$build_log" || fail_build |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 591 | fi |
| 592 | |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 593 | python3 -m venv .venv |
| 594 | . .venv/bin/activate |
| 595 | |
| 596 | # Install extra tools used by CMake build system |
| 597 | pip install -r requirements.txt --timeout 30 --retries 15 |
| 598 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 599 | # Log build command line. It is left unfolded on purpose to assist |
| 600 | # copying to clipboard. |
| 601 | cat <<EOF | log_separator >/dev/null |
| 602 | |
| 603 | SCP build command line: |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 604 | make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \ |
| 605 | TOOLCHAIN=GNU \ |
| 606 | MODE="$mode" \ |
Nicola Mazzucato | 506b580 | 2021-12-24 14:23:25 +0000 | [diff] [blame] | 607 | EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \ |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 608 | V=1 &>>"$build_log" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 609 | |
| 610 | EOF |
| 611 | |
| 612 | # Build SCP |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 613 | make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \ |
| 614 | TOOLCHAIN=GNU \ |
| 615 | MODE="$mode" \ |
Nicola Mazzucato | 506b580 | 2021-12-24 14:23:25 +0000 | [diff] [blame] | 616 | EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \ |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 617 | V=1 &>>"$build_log" \ |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 618 | || fail_build |
| 619 | ) |
| 620 | } |
| 621 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 622 | clone_scp_tools() { |
| 623 | |
| 624 | if [ ! -d "$scp_tools_root" ]; then |
| 625 | echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator |
| 626 | |
| 627 | clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \ |
| 628 | where="$scp_tools_root" \ |
| 629 | refspec="${scp_tools_commit}" |
| 630 | clone_repo &>>"$build_log" |
| 631 | else |
| 632 | echo "Already cloned SCP-tools ..." |& log_separator |
| 633 | fi |
| 634 | |
| 635 | show_head "$scp_tools_root" |
| 636 | |
| 637 | cd "$scp_tools_root" |
| 638 | |
| 639 | echo "Updating submodules" |
| 640 | |
| 641 | git submodule init |
| 642 | |
| 643 | git submodule update |
| 644 | |
Nicola Mazzucato | 7302cd3 | 2021-12-14 13:36:57 +0000 | [diff] [blame] | 645 | lib_commit=$(grep "'scmi_lib_commit'" run_tests/settings.py | cut -d':' -f 2 | tr -d "'") |
| 646 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 647 | cd "scmi" |
Nicola Mazzucato | 7302cd3 | 2021-12-14 13:36:57 +0000 | [diff] [blame] | 648 | git checkout $lib_commit |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 649 | |
| 650 | git show --quiet --no-color | sed 's/^/ > /g' |
| 651 | } |
| 652 | |
| 653 | clone_tf_for_scp_tools() { |
| 654 | scp_tools_arm_tf="$scp_tools_root/arm-tf" |
| 655 | |
| 656 | if [ ! -d "$scp_tools_arm_tf" ]; then |
| 657 | echo "Cloning TF-4-SCP-tools ..." |& log_separator |
| 658 | |
| 659 | clone_url="$tf_for_scp_tools_src_repo_url" |
| 660 | where="$scp_tools_arm_tf" |
| 661 | |
| 662 | git clone "$clone_url" "$where" |
| 663 | |
| 664 | cd "$scp_tools_arm_tf" |
| 665 | |
Joel Goddard | 3ad0306 | 2021-03-16 16:47:42 +0000 | [diff] [blame] | 666 | git checkout --track origin/juno-v4.3 |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 667 | |
| 668 | git show --quiet --no-color | sed 's/^/ > /g' |
| 669 | |
| 670 | else |
| 671 | echo "Already cloned TF-4-SCP-tools ..." |& log_separator |
| 672 | fi |
| 673 | } |
| 674 | |
| 675 | build_scmi_lib_scp_tools() { |
| 676 | ( |
| 677 | cd "$scp_tools_root" |
| 678 | |
| 679 | cd "scmi" |
| 680 | |
| 681 | scp_tools_arm_tf="$scp_tools_root/arm-tf" |
| 682 | |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 683 | cross_compile="$(set_cross_compile_gcc_linaro_toolchain)" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 684 | |
| 685 | std_libs="-I$scp_tools_arm_tf/include/common" |
| 686 | std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr" |
| 687 | std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm" |
| 688 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib" |
| 689 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64" |
| 690 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib" |
| 691 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys" |
| 692 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables" |
| 693 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common" |
| 694 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common" |
| 695 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common" |
| 696 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common" |
| 697 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common" |
| 698 | std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include" |
| 699 | |
| 700 | cflags="-Og -g" |
| 701 | cflags="$cflags -mgeneral-regs-only" |
| 702 | cflags="$cflags -mstrict-align" |
| 703 | cflags="$cflags -nostdinc" |
| 704 | cflags="$cflags -fno-inline" |
| 705 | cflags="$cflags -ffreestanding" |
| 706 | cflags="$cflags -ffunction-sections" |
| 707 | cflags="$cflags -fdata-sections" |
| 708 | cflags="$cflags -DAARCH64" |
| 709 | cflags="$cflags -DPRId32=\"ld\"" |
Joel Goddard | 3ad0306 | 2021-03-16 16:47:42 +0000 | [diff] [blame] | 710 | cflags="$cflags -DVERBOSE_LEVEL=3" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 711 | |
| 712 | cflags="$cflags $std_libs" |
| 713 | |
Joel Goddard | 3ad0306 | 2021-03-16 16:47:42 +0000 | [diff] [blame] | 714 | protocols="performance,power_domain,system_power,reset" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 715 | |
| 716 | echo "Building SCMI library (SCP-tools) ..." |
| 717 | |
| 718 | make "CROSS_COMPILE=$cross_compile" \ |
| 719 | "CFLAGS=$cflags" \ |
Joel Goddard | 3ad0306 | 2021-03-16 16:47:42 +0000 | [diff] [blame] | 720 | "PLAT=baremetal" \ |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 721 | "PROTOCOLS=$protocols" \ |
| 722 | "clean" \ |
| 723 | "all" |
| 724 | ) |
| 725 | } |
| 726 | |
| 727 | build_tf_for_scp_tools() { |
| 728 | |
| 729 | cd "$scp_tools_root/arm-tf" |
| 730 | |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 731 | cross_compile="$(set_cross_compile_gcc_linaro_toolchain)" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 732 | |
| 733 | if [ "$1" = "release" ]; then |
| 734 | echo "Build TF-4-SCP-Tools rls..." |
| 735 | else |
| 736 | echo "Build TF-4-SCP-Tools dbg..." |
| 737 | |
| 738 | make realclean |
| 739 | |
| 740 | make "BM_TEST=scmi" \ |
| 741 | "ARM_BOARD_OPTIMISE_MEM=1" \ |
| 742 | "BM_CSS=juno" \ |
| 743 | "CSS_USE_SCMI_SDS_DRIVER=1" \ |
| 744 | "PLAT=juno" \ |
| 745 | "DEBUG=1" \ |
| 746 | "PLATFORM=juno" \ |
| 747 | "CROSS_COMPILE=$cross_compile" \ |
| 748 | "BM_WORKSPACE=$scp_tools_root/baremetal" |
| 749 | |
| 750 | archive_file "build/juno/debug/bl1.bin" |
| 751 | |
| 752 | archive_file "build/juno/debug/bl2.bin" |
| 753 | |
| 754 | archive_file "build/juno/debug/bl31.bin" |
| 755 | fi |
| 756 | } |
| 757 | |
| 758 | build_fip_for_scp_tools() { |
| 759 | |
| 760 | cd "$scp_tools_root/arm-tf" |
| 761 | |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 762 | cross_compile="$(set_cross_compile_gcc_linaro_toolchain)" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 763 | |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 764 | if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 765 | make fiptool |
| 766 | echo "Make FIP 4 SCP-Tools rls..." |
| 767 | |
| 768 | else |
| 769 | make fiptool |
| 770 | echo "Make FIP 4 SCP-Tools dbg..." |
| 771 | |
| 772 | make "PLAT=juno" \ |
| 773 | "all" \ |
| 774 | "fip" \ |
| 775 | "DEBUG=1" \ |
| 776 | "CROSS_COMPILE=$cross_compile" \ |
| 777 | "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \ |
| 778 | "BL33=$scp_tools_root/baremetal/dummy_bl33" \ |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 779 | "SCP_BL2=$scp_root/build/juno/GNU/$mode/firmware-scp_ramfw/bin/juno-bl2.bin" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 780 | |
| 781 | archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin" |
| 782 | fi |
| 783 | } |
| 784 | |
| 785 | build_cc() { |
| 786 | # Building code coverage plugin |
| 787 | ARM_DIR=/arm |
| 788 | pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk") |
| 789 | PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external |
| 790 | if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then |
| 791 | echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder" |
| 792 | exit -1 |
| 793 | fi # Error if arm warehouse not found |
| 794 | cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov" |
| 795 | |
| 796 | make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log" |
| 797 | } |
| 798 | |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 799 | build_spm() { |
| 800 | ( |
| 801 | env_file="$workspace/spm.env" |
| 802 | config_file="${spm_build_config:-$spm_config_file}" |
| 803 | |
| 804 | source "$config_file" |
| 805 | |
| 806 | if [ -f "$env_file" ]; then |
| 807 | set -a |
| 808 | source "$env_file" |
| 809 | set +a |
| 810 | fi |
| 811 | |
| 812 | cd "$spm_root" |
| 813 | |
| 814 | # Always clean when running on Jenkins. Skip clean when running |
| 815 | # locally and explicitly requested. |
| 816 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
| 817 | # make clean fails on a fresh repo where the project has not |
| 818 | # yet been built. Hence only clean if out/reference directory |
| 819 | # already exists. |
| 820 | if [ -d "out/reference" ]; then |
| 821 | make clean &>>"$build_log" || fail_build |
| 822 | fi |
| 823 | fi |
| 824 | |
| 825 | # Log build command line. It is left unfolded on purpose to assist |
| 826 | # copying to clipboard. |
| 827 | cat <<EOF | log_separator >/dev/null |
| 828 | |
| 829 | Build command line: |
| 830 | make $make_j_opts $(cat "$config_file" | tr '\n' ' ') |
| 831 | |
| 832 | EOF |
| 833 | |
| 834 | # Build SPM. Since build output is being directed to the build log, have |
| 835 | # descriptor 3 point to the current terminal for build wrappers to vent. |
Olivier Deprez | f34d1d3 | 2021-10-11 09:45:32 +0200 | [diff] [blame] | 836 | export PATH=$PWD/prebuilts/linux-x64/clang/bin:$PWD/prebuilts/linux-x64/dtc:$PATH |
| 837 | |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 838 | make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \ |
| 839 | || fail_build |
| 840 | ) |
| 841 | } |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 842 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 843 | # Set metadata for the whole package so that it can be used by both Jenkins and |
| 844 | # shell |
| 845 | set_package_var() { |
| 846 | env_file="$artefacts/env" emit_env "$@" |
| 847 | } |
| 848 | |
| 849 | set_tf_build_targets() { |
| 850 | echo "Set build target to '${targets:?}'" |
| 851 | set_hook_var "tf_build_targets" "$targets" |
| 852 | } |
| 853 | |
| 854 | set_tftf_build_targets() { |
| 855 | echo "Set build target to '${targets:?}'" |
| 856 | set_hook_var "tftf_build_targets" "$targets" |
| 857 | } |
| 858 | |
| 859 | set_scp_build_targets() { |
| 860 | echo "Set build target to '${targets:?}'" |
| 861 | set_hook_var "scp_build_targets" "$targets" |
| 862 | } |
| 863 | |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 864 | set_spm_build_targets() { |
| 865 | echo "Set build target to '${targets:?}'" |
| 866 | set_hook_var "spm_build_targets" "$targets" |
| 867 | } |
| 868 | |
Daniel Boulby | b8d2a46 | 2022-03-07 13:55:25 +0000 | [diff] [blame] | 869 | set_spm_out_dir() { |
| 870 | echo "Set SPMC binary build to '${out_dir:?}'" |
| 871 | set_hook_var "spm_secure_out_dir" "$out_dir" |
| 872 | } |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 873 | # Look under $archive directory for known files such as blX images, kernel, DTB, |
| 874 | # initrd etc. For each known file foo, if foo.bin exists, then set variable |
| 875 | # foo_bin to the path of the file. Make the path relative to the workspace so as |
| 876 | # to remove any @ characters, which Jenkins inserts for parallel runs. If the |
| 877 | # file doesn't exist, unset its path. |
| 878 | set_default_bin_paths() { |
| 879 | local image image_name image_path path |
| 880 | local archive="${archive:?}" |
| 881 | local set_vars |
| 882 | local var |
| 883 | |
| 884 | pushd "$archive" |
| 885 | |
| 886 | for file in *.bin; do |
| 887 | # Get a shell variable from the file's stem |
| 888 | var_name="${file%%.*}_bin" |
| 889 | var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')" |
| 890 | |
| 891 | # Skip setting the variable if it's already |
| 892 | if [ "${!var_name}" ]; then |
| 893 | echo "Note: not setting $var_name; already set to ${!var_name}" |
| 894 | continue |
| 895 | else |
| 896 | set_vars+="$var_name " |
| 897 | fi |
| 898 | |
| 899 | eval "$var_name=$file" |
| 900 | done |
| 901 | |
| 902 | echo "Binary paths set for: " |
| 903 | { |
| 904 | for var in $set_vars; do |
| 905 | echo -n "\$$var " |
| 906 | done |
| 907 | } | fmt -80 | sed 's/^/ /' |
| 908 | echo |
| 909 | |
| 910 | popd |
| 911 | } |
| 912 | |
| 913 | gen_model_params() { |
| 914 | local model_param_file="$archive/model_params" |
Javier Almansa Sobrino | e836318 | 2020-11-10 16:40:53 +0000 | [diff] [blame] | 915 | [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 916 | |
| 917 | set_default_bin_paths |
| 918 | echo "Generating model parameter for $model..." |
| 919 | source "$ci_root/model/${model:?}.sh" |
| 920 | archive_file "$model_param_file" |
| 921 | } |
| 922 | |
| 923 | set_model_path() { |
| 924 | set_run_env "model_path" "${1:?}" |
| 925 | } |
| 926 | |
Zelalem | 1af7a7b | 2020-08-04 17:34:32 -0500 | [diff] [blame] | 927 | set_model_env() { |
| 928 | local var="${1:?}" |
| 929 | local val="${2?}" |
| 930 | local run_root="${archive:?}/run" |
| 931 | |
| 932 | mkdir -p "$run_root" |
| 933 | echo "export $var=$val" >> "$run_root/model_env" |
| 934 | } |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 935 | set_run_env() { |
| 936 | local var="${1:?}" |
| 937 | local val="${2?}" |
| 938 | local run_root="${archive:?}/run" |
| 939 | |
| 940 | mkdir -p "$run_root" |
| 941 | env_file="$run_root/env" quote="1" emit_env "$var" "$val" |
| 942 | } |
| 943 | |
| 944 | show_head() { |
| 945 | # Display HEAD descripton |
| 946 | pushd "$1" |
| 947 | git show --quiet --no-color | sed 's/^/ > /g' |
| 948 | echo |
| 949 | popd |
| 950 | } |
| 951 | |
| 952 | # Choose debug binaries to run; by default, release binaries are chosen to run |
| 953 | use_debug_bins() { |
| 954 | local run_root="${archive:?}/run" |
| 955 | |
| 956 | echo "Choosing debug binaries for execution" |
| 957 | set_package_var "BIN_MODE" "debug" |
| 958 | } |
| 959 | |
| 960 | assert_can_git_clone() { |
| 961 | local name="${1:?}" |
| 962 | local dir="${!name}" |
| 963 | |
| 964 | # If it doesn't exist, it can be cloned into |
| 965 | if [ ! -e "$dir" ]; then |
| 966 | return 0 |
| 967 | fi |
| 968 | |
| 969 | # If it's a directory, it must be a Git clone already |
| 970 | if [ -d "$dir" ] && [ -d "$dir/.git" ]; then |
| 971 | # No need to clone again |
| 972 | echo "Using existing git clone for $name: $dir" |
| 973 | return 1 |
| 974 | fi |
| 975 | |
| 976 | die "Path $dir exists but is not a git clone" |
| 977 | } |
| 978 | |
| 979 | clone_repo() { |
| 980 | if ! is_url "${clone_url?}"; then |
| 981 | # For --depth to take effect on local paths, it needs to use the |
| 982 | # file:// scheme. |
| 983 | clone_url="file://$clone_url" |
| 984 | fi |
| 985 | |
| 986 | git clone -q --depth 1 "$clone_url" "${where?}" |
| 987 | if [ "$refspec" ]; then |
| 988 | pushd "$where" |
| 989 | git fetch -q --depth 1 origin "$refspec" |
| 990 | git checkout -q FETCH_HEAD |
| 991 | popd |
| 992 | fi |
| 993 | } |
| 994 | |
| 995 | build_unstable() { |
| 996 | echo "--BUILD UNSTABLE--" | tee -a "$build_log" |
| 997 | } |
| 998 | |
| 999 | undo_patch_record() { |
| 1000 | if [ ! -f "${patch_record:?}" ]; then |
| 1001 | return |
| 1002 | fi |
| 1003 | |
| 1004 | # Undo patches in reverse |
| 1005 | echo |
| 1006 | for patch_name in $(tac "$patch_record"); do |
| 1007 | echo "Undoing $patch_name..." |
| 1008 | if ! git apply -R "$ci_root/patch/$patch_name"; then |
| 1009 | if upon "$local_ci"; then |
| 1010 | echo |
| 1011 | echo "Your local directory may have been dirtied." |
| 1012 | echo |
| 1013 | fi |
| 1014 | fail_build |
| 1015 | fi |
| 1016 | done |
| 1017 | |
| 1018 | rm -f "$patch_record" |
| 1019 | } |
| 1020 | |
| 1021 | undo_local_patches() { |
| 1022 | pushd "$tf_root" |
| 1023 | patch_record="$tf_patch_record" undo_patch_record |
| 1024 | popd |
| 1025 | |
| 1026 | if [ -d "$tftf_root" ]; then |
| 1027 | pushd "$tftf_root" |
| 1028 | patch_record="$tftf_patch_record" undo_patch_record |
| 1029 | popd |
| 1030 | fi |
| 1031 | } |
| 1032 | |
| 1033 | undo_tftf_patches() { |
| 1034 | pushd "$tftf_root" |
| 1035 | patch_record="$tftf_patch_record" undo_patch_record |
| 1036 | popd |
| 1037 | } |
| 1038 | |
| 1039 | undo_tf_patches() { |
| 1040 | pushd "$tf_root" |
| 1041 | patch_record="$tf_patch_record" undo_patch_record |
| 1042 | popd |
| 1043 | } |
| 1044 | |
| 1045 | apply_patch() { |
| 1046 | # If skip_patches is set, the developer has applied required patches |
| 1047 | # manually. They probably want to keep them applied for debugging |
| 1048 | # purposes too. This means we don't have to apply/revert them as part of |
| 1049 | # build process. |
| 1050 | if upon "$skip_patches"; then |
| 1051 | echo "Skipped applying ${1:?}..." |
| 1052 | return 0 |
| 1053 | else |
| 1054 | echo "Applying ${1:?}..." |
| 1055 | fi |
| 1056 | |
| 1057 | if git apply < "$ci_root/patch/$1"; then |
| 1058 | echo "$1" >> "${patch_record:?}" |
| 1059 | else |
| 1060 | if upon "$local_ci"; then |
| 1061 | undo_local_patches |
| 1062 | fi |
| 1063 | fail_build |
| 1064 | fi |
| 1065 | } |
| 1066 | |
| 1067 | apply_tftf_patch() { |
| 1068 | pushd "$tftf_root" |
| 1069 | patch_record="$tftf_patch_record" apply_patch "$1" |
| 1070 | popd |
| 1071 | } |
| 1072 | |
| 1073 | apply_tf_patch() { |
| 1074 | pushd "$tf_root" |
| 1075 | patch_record="$tf_patch_record" apply_patch "$1" |
| 1076 | popd |
| 1077 | } |
| 1078 | |
| 1079 | # Clear workspace for a local run |
| 1080 | if not_upon "$jenkins_run"; then |
| 1081 | rm -rf "$workspace" |
| 1082 | |
| 1083 | # Clear residue from previous runs |
| 1084 | rm -rf "$archive" |
| 1085 | fi |
| 1086 | |
| 1087 | mkdir -p "$workspace" |
| 1088 | mkdir -p "$archive" |
| 1089 | set_package_var "TEST_CONFIG" "$test_config" |
| 1090 | |
| 1091 | { |
| 1092 | echo |
| 1093 | echo "CONFIGURATION: $test_group/$test_config" |
| 1094 | echo |
| 1095 | } |& log_separator |
| 1096 | |
| 1097 | tf_config="$(echo "$build_configs" | awk -F, '{print $1}')" |
| 1098 | tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')" |
| 1099 | scp_config="$(echo "$build_configs" | awk -F, '{print $3}')" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1100 | scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1101 | spm_config="$(echo "$build_configs" | awk -F, '{print $5}')" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1102 | |
| 1103 | test_config_file="$ci_root/group/$test_group/$test_config" |
| 1104 | |
| 1105 | tf_config_file="$ci_root/tf_config/$tf_config" |
| 1106 | tftf_config_file="$ci_root/tftf_config/$tftf_config" |
| 1107 | scp_config_file="$ci_root/scp_config/$scp_config" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1108 | scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1109 | spm_config_file="$ci_root/spm_config/$spm_config" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1110 | |
| 1111 | # File that keeps track of applied patches |
| 1112 | tf_patch_record="$workspace/tf_patches" |
| 1113 | tftf_patch_record="$workspace/tftf_patches" |
| 1114 | |
| 1115 | pushd "$workspace" |
| 1116 | |
| 1117 | if ! config_valid "$tf_config"; then |
| 1118 | tf_config= |
| 1119 | else |
| 1120 | echo "Trusted Firmware config:" |
| 1121 | echo |
| 1122 | sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/' |
| 1123 | echo |
| 1124 | fi |
| 1125 | |
| 1126 | if ! config_valid "$tftf_config"; then |
| 1127 | tftf_config= |
| 1128 | else |
| 1129 | echo "Trusted Firmware TF config:" |
| 1130 | echo |
| 1131 | sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/' |
| 1132 | echo |
| 1133 | fi |
| 1134 | |
| 1135 | if ! config_valid "$scp_config"; then |
| 1136 | scp_config= |
| 1137 | else |
| 1138 | echo "SCP firmware config:" |
| 1139 | echo |
| 1140 | sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/' |
| 1141 | echo |
| 1142 | fi |
| 1143 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1144 | if ! config_valid "$scp_tools_config"; then |
| 1145 | scp_tools_config= |
| 1146 | else |
| 1147 | echo "SCP Tools config:" |
| 1148 | echo |
| 1149 | sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/' |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1150 | fi |
| 1151 | |
| 1152 | if ! config_valid "$spm_config"; then |
| 1153 | spm_config= |
| 1154 | else |
| 1155 | echo "SPM config:" |
| 1156 | echo |
| 1157 | sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/' |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1158 | echo |
| 1159 | fi |
| 1160 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1161 | if ! config_valid "$run_config"; then |
| 1162 | run_config= |
| 1163 | fi |
| 1164 | |
| 1165 | if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then |
| 1166 | # If the Trusted Firmware repository has already been checked out, use |
| 1167 | # that location. Otherwise, clone one ourselves. |
| 1168 | echo "Cloning Trusted Firmware..." |
| 1169 | clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \ |
| 1170 | refspec="$TF_REFSPEC" clone_repo &>>"$build_log" |
| 1171 | show_head "$tf_root" |
| 1172 | fi |
| 1173 | |
| 1174 | if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then |
| 1175 | # If the Trusted Firmware TF repository has already been checked out, |
| 1176 | # use that location. Otherwise, clone one ourselves. |
| 1177 | echo "Cloning Trusted Firmware TF..." |
| 1178 | clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \ |
| 1179 | refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log" |
| 1180 | show_head "$tftf_root" |
| 1181 | fi |
| 1182 | |
| 1183 | if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then |
| 1184 | # If the SCP firmware repository has already been checked out, |
| 1185 | # use that location. Otherwise, clone one ourselves. |
| 1186 | echo "Cloning SCP Firmware..." |
| 1187 | clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \ |
| 1188 | refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log" |
| 1189 | |
| 1190 | pushd "$scp_root" |
| 1191 | |
| 1192 | # Use filer submodule as a reference if it exists |
Girish Pathak | 31b824e | 2021-03-03 20:58:21 +0000 | [diff] [blame] | 1193 | if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1194 | cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis" |
| 1195 | fi |
| 1196 | |
| 1197 | # If we don't have a reference yet, fall back to $cmsis_root if set, or |
| 1198 | # then to project filer if accessible. |
| 1199 | if [ -z "$cmsis_reference" ]; then |
| 1200 | cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}" |
| 1201 | if [ -d "$cmsis_ref_repo" ]; then |
| 1202 | cmsis_reference="--reference $cmsis_ref_repo" |
| 1203 | fi |
| 1204 | fi |
| 1205 | |
| 1206 | git submodule -q update $cmsis_reference --init |
| 1207 | |
| 1208 | popd |
| 1209 | |
| 1210 | show_head "$scp_root" |
| 1211 | fi |
| 1212 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1213 | if [ -n "$cc_config" ] ; then |
| 1214 | if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then |
| 1215 | # Copy code coverage repository |
| 1216 | echo "Cloning Code Coverage..." |
| 1217 | git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null |
| 1218 | show_head "$cc_root" |
| 1219 | fi |
| 1220 | fi |
| 1221 | |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1222 | if [ "$spm_config" ] && assert_can_git_clone "spm_root"; then |
| 1223 | # If the SPM repository has already been checked out, use |
| 1224 | # that location. Otherwise, clone one ourselves. |
| 1225 | echo "Cloning SPM..." |
| 1226 | clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" where="$spm_root" \ |
| 1227 | refspec="$SPM_REFSPEC" clone_repo &>>"$build_log" |
| 1228 | |
| 1229 | # Query git submodules |
| 1230 | pushd "$spm_root" |
| 1231 | git submodule update --init |
| 1232 | popd |
| 1233 | |
| 1234 | show_head "$spm_root" |
| 1235 | fi |
| 1236 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1237 | if [ "$run_config" ]; then |
| 1238 | # Get candidates for run config |
| 1239 | run_config_candiates="$("$ci_root/script/gen_run_config_candidates.py" \ |
| 1240 | "$run_config")" |
| 1241 | if [ -z "$run_config_candiates" ]; then |
| 1242 | die "No run config candidates!" |
| 1243 | else |
| 1244 | echo |
| 1245 | echo "Chosen fragments:" |
| 1246 | echo |
| 1247 | echo "$run_config_candiates" | sed 's/^\|\n/\t/g' |
| 1248 | echo |
| 1249 | fi |
| 1250 | fi |
| 1251 | |
| 1252 | call_hook "test_setup" |
| 1253 | echo |
| 1254 | |
| 1255 | if upon "$local_ci"; then |
| 1256 | # For local runs, since each config is tried in sequence, it's |
| 1257 | # advantageous to run jobs in parallel |
| 1258 | if [ "$make_j" ]; then |
| 1259 | make_j_opts="-j $make_j" |
| 1260 | else |
| 1261 | n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true |
| 1262 | if [ "$n_cores" ]; then |
| 1263 | make_j_opts="-j $n_cores" |
| 1264 | fi |
| 1265 | fi |
| 1266 | fi |
| 1267 | |
| 1268 | modes="${bin_mode:-debug release}" |
| 1269 | for mode in $modes; do |
Paul Sokolovsky | e9962cd | 2021-12-17 18:39:40 +0300 | [diff] [blame] | 1270 | echo "===== Building package in mode: $mode =====" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1271 | # Build with a temporary archive |
| 1272 | build_archive="$archive/$mode" |
| 1273 | mkdir "$build_archive" |
| 1274 | |
| 1275 | if [ "$mode" = "debug" ]; then |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1276 | export bin_mode="debug" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1277 | DEBUG=1 |
| 1278 | else |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1279 | export bin_mode="release" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1280 | DEBUG=0 |
| 1281 | fi |
| 1282 | |
| 1283 | # Perform builds in a subshell so as not to pollute the current and |
| 1284 | # subsequent builds' environment |
| 1285 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1286 | if config_valid "$cc_config"; then |
| 1287 | # Build code coverage plugin |
| 1288 | build_cc |
| 1289 | fi |
| 1290 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1291 | # SCP build |
| 1292 | if config_valid "$scp_config"; then |
| 1293 | ( |
| 1294 | echo "##########" |
| 1295 | |
| 1296 | # Source platform-specific utilities |
| 1297 | plat="$(get_scp_opt PRODUCT)" |
| 1298 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1299 | if [ -f "$plat_utils" ]; then |
| 1300 | source "$plat_utils" |
| 1301 | fi |
| 1302 | |
| 1303 | archive="$build_archive" |
| 1304 | scp_build_root="$scp_root/build" |
| 1305 | |
| 1306 | echo "Building SCP Firmware ($mode) ..." |& log_separator |
| 1307 | |
| 1308 | build_scp |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1309 | to="$archive" collect_scp_artefacts |
| 1310 | |
| 1311 | echo "##########" |
| 1312 | echo |
| 1313 | ) |
| 1314 | fi |
| 1315 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1316 | # SCP-tools build |
| 1317 | if config_valid "$scp_tools_config"; then |
| 1318 | ( |
| 1319 | echo "##########" |
| 1320 | |
| 1321 | archive="$build_archive" |
| 1322 | scp_tools_build_root="$scp_tools_root/build" |
| 1323 | |
| 1324 | clone_scp_tools |
| 1325 | |
| 1326 | echo "##########" |
| 1327 | echo |
| 1328 | |
| 1329 | echo "##########" |
| 1330 | clone_tf_for_scp_tools |
| 1331 | echo "##########" |
| 1332 | echo |
| 1333 | ) |
| 1334 | fi |
| 1335 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1336 | # TFTF build |
| 1337 | if config_valid "$tftf_config"; then |
| 1338 | ( |
| 1339 | echo "##########" |
| 1340 | |
Manish V Badarkhe | 3bd3fea | 2020-11-08 15:17:00 +0000 | [diff] [blame] | 1341 | plat_utils="$(get_tf_opt PLAT_UTILS)" |
| 1342 | if [ -z ${plat_utils} ]; then |
| 1343 | # Source platform-specific utilities. |
| 1344 | plat="$(get_tftf_opt PLAT)" |
| 1345 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1346 | else |
| 1347 | # Source platform-specific utilities by |
| 1348 | # using plat_utils name. |
| 1349 | plat_utils="$ci_root/${plat_utils}.sh" |
| 1350 | fi |
| 1351 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1352 | if [ -f "$plat_utils" ]; then |
| 1353 | source "$plat_utils" |
| 1354 | fi |
| 1355 | |
| 1356 | archive="$build_archive" |
| 1357 | tftf_build_root="$tftf_root/build" |
| 1358 | |
| 1359 | echo "Building Trusted Firmware TF ($mode) ..." |& log_separator |
| 1360 | |
| 1361 | # Call pre-build hook |
| 1362 | call_hook pre_tftf_build |
| 1363 | |
| 1364 | build_tftf |
| 1365 | |
| 1366 | from="$tftf_build_root" to="$archive" collect_build_artefacts |
| 1367 | |
| 1368 | # Clear any local changes made by applied patches |
| 1369 | undo_tftf_patches |
| 1370 | |
| 1371 | echo "##########" |
| 1372 | echo |
| 1373 | ) |
| 1374 | fi |
| 1375 | |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1376 | # SPM build |
| 1377 | if config_valid "$spm_config"; then |
| 1378 | ( |
| 1379 | echo "##########" |
| 1380 | |
| 1381 | # Get platform name from spm_config file |
| 1382 | plat="$(echo "$spm_config" | awk -F- '{print $1}')" |
| 1383 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1384 | if [ -f "$plat_utils" ]; then |
| 1385 | source "$plat_utils" |
| 1386 | fi |
| 1387 | |
Daniel Boulby | b8d2a46 | 2022-03-07 13:55:25 +0000 | [diff] [blame] | 1388 | # Call pre-build hook |
| 1389 | call_hook pre_spm_build |
| 1390 | |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 1391 | # SPM build generates two sets of binaries, one for normal and other |
| 1392 | # for Secure world. We need both set of binaries for CI. |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1393 | archive="$build_archive" |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 1394 | spm_build_root="$spm_root/out/reference/$spm_secure_out_dir" |
| 1395 | hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1396 | |
Daniel Boulby | b8d2a46 | 2022-03-07 13:55:25 +0000 | [diff] [blame] | 1397 | echo "spm_build_root is $spm_build_root" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1398 | echo "Building SPM ($mode) ..." |& log_separator |
| 1399 | |
| 1400 | # NOTE: mode has no effect on SPM build (for now), hence debug |
| 1401 | # mode is built but subsequent build using release mode just |
| 1402 | # goes through with "nothing to do". |
| 1403 | build_spm |
| 1404 | |
| 1405 | # Show SPM/Hafnium binary details |
Madhukar Pappireddy | c683cf6 | 2021-11-01 14:38:32 -0500 | [diff] [blame] | 1406 | cksum $spm_build_root/hafnium.bin |
| 1407 | |
| 1408 | # Some platforms only have secure configuration enabled. Hence, |
| 1409 | # non secure hanfnium binary might not be built. |
| 1410 | if [ -f $hafnium_build_root/hafnium.bin ]; then |
| 1411 | cksum $hafnium_build_root/hafnium.bin |
| 1412 | fi |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1413 | |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 1414 | secure_from="$spm_build_root" non_secure_from="$hafnium_build_root" to="$archive" collect_spm_artefacts |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1415 | |
| 1416 | echo "##########" |
| 1417 | echo |
| 1418 | ) |
| 1419 | fi |
| 1420 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1421 | # TF build |
| 1422 | if config_valid "$tf_config"; then |
| 1423 | ( |
| 1424 | echo "##########" |
| 1425 | |
Manish V Badarkhe | 3bd3fea | 2020-11-08 15:17:00 +0000 | [diff] [blame] | 1426 | plat_utils="$(get_tf_opt PLAT_UTILS)" |
Madhukar Pappireddy | 2f284e1 | 2021-08-30 16:06:14 -0500 | [diff] [blame] | 1427 | export plat_variant="$(get_tf_opt TARGET_PLATFORM)" |
| 1428 | |
Manish V Badarkhe | 3bd3fea | 2020-11-08 15:17:00 +0000 | [diff] [blame] | 1429 | if [ -z ${plat_utils} ]; then |
| 1430 | # Source platform-specific utilities. |
| 1431 | plat="$(get_tf_opt PLAT)" |
| 1432 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1433 | else |
| 1434 | # Source platform-specific utilities by |
| 1435 | # using plat_utils name. |
| 1436 | plat_utils="$ci_root/${plat_utils}.sh" |
| 1437 | fi |
| 1438 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1439 | if [ -f "$plat_utils" ]; then |
| 1440 | source "$plat_utils" |
| 1441 | fi |
| 1442 | |
Chris Kay | d083790 | 2021-11-17 10:17:52 +0000 | [diff] [blame] | 1443 | source "$ci_root/script/install_python_deps_tf.sh" |
| 1444 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1445 | archive="$build_archive" |
| 1446 | tf_build_root="$tf_root/build" |
| 1447 | |
| 1448 | echo "Building Trusted Firmware ($mode) ..." |& log_separator |
| 1449 | |
| 1450 | # Call pre-build hook |
| 1451 | call_hook pre_tf_build |
| 1452 | |
| 1453 | build_tf |
| 1454 | |
| 1455 | # Call post-build hook |
| 1456 | call_hook post_tf_build |
| 1457 | |
| 1458 | # Pre-archive hook |
| 1459 | call_hook pre_tf_archive |
| 1460 | |
| 1461 | from="$tf_build_root" to="$archive" collect_build_artefacts |
| 1462 | |
| 1463 | # Post-archive hook |
| 1464 | call_hook post_tf_archive |
| 1465 | |
| 1466 | call_hook fetch_tf_resource |
| 1467 | call_hook post_fetch_tf_resource |
| 1468 | |
Chris Kay | 4e8aaf1 | 2022-09-01 15:21:55 +0100 | [diff] [blame] | 1469 | # Generate LAVA job files if necessary |
| 1470 | call_hook generate_lava_job_template |
| 1471 | call_hook generate_lava_job |
| 1472 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1473 | # Clear any local changes made by applied patches |
| 1474 | undo_tf_patches |
| 1475 | |
| 1476 | echo "##########" |
| 1477 | ) |
| 1478 | fi |
| 1479 | |
| 1480 | echo |
| 1481 | echo |
| 1482 | done |
| 1483 | |
| 1484 | call_hook pre_package |
| 1485 | |
| 1486 | call_hook post_package |
| 1487 | |
| 1488 | if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1489 | source "$CI_ROOT/script/send_artefacts.sh" "artefacts" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1490 | fi |
| 1491 | |
| 1492 | echo |
| 1493 | echo "Done" |