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