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}" |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 22 | export rfa_root="${rfa_root:-$workspace/rusted-firmware-a}" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 23 | export tftf_root="${tftf_root:-$workspace/trusted_firmware_tf}" |
| 24 | export scp_root="${scp_root:-$workspace/scp}" |
| 25 | scp_tools_root="${scp_tools_root:-$workspace/scp_tools}" |
| 26 | cc_root="${cc_root:-$ccpathspec}" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 27 | spm_root="${spm_root:-$workspace/spm}" |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 28 | rmm_root="${rmm_root:-$workspace/tf-rmm}" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 29 | |
| 30 | scp_tf_tools_root="$scp_tools_root/scp_tf_tools" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 31 | |
| 32 | # Refspecs |
| 33 | tf_refspec="$TF_REFSPEC" |
| 34 | tftf_refspec="$TFTF_REFSPEC" |
| 35 | scp_refspec="$SCP_REFSPEC" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 36 | scp_tools_commit="${SCP_TOOLS_COMMIT:-master}" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 37 | spm_refspec="$SPM_REFSPEC" |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 38 | rmm_refspec="$RMM_REFSPEC" |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 39 | rfa_refspec="$RFA_REFSPEC" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 40 | |
| 41 | test_config="${TEST_CONFIG:?}" |
| 42 | test_group="${TEST_GROUP:?}" |
| 43 | build_configs="${BUILD_CONFIG:?}" |
| 44 | run_config="${RUN_CONFIG:?}" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 45 | cc_config="${CC_ENABLE:-}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 46 | |
| 47 | archive="$artefacts" |
| 48 | build_log="$artefacts/build.log" |
| 49 | fiptool="$tf_root/tools/fiptool/fiptool" |
| 50 | cert_create="$tf_root/tools/cert_create/cert_create" |
| 51 | |
| 52 | # Validate $bin_mode |
| 53 | case "$bin_mode" in |
| 54 | "" | debug | release) |
| 55 | ;; |
| 56 | *) |
| 57 | die "Invalid value for bin_mode: $bin_mode" |
| 58 | ;; |
| 59 | esac |
| 60 | |
| 61 | # File to save any environem |
| 62 | hook_env_file="$(mktempfile)" |
| 63 | |
| 64 | # Check if a config is valid |
| 65 | config_valid() { |
| 66 | local config="${1?}" |
| 67 | if [ -z "$config" ] || [ "$(basename "$config")" = "nil" ]; then |
| 68 | return 1 |
| 69 | fi |
| 70 | |
| 71 | return 0 |
| 72 | } |
| 73 | |
| 74 | # Echo from a build wrapper. Print to descriptor 3 that's opened by the build |
| 75 | # function. |
| 76 | echo_w() { |
| 77 | echo $echo_flags "$@" >&3 |
| 78 | } |
| 79 | |
| 80 | # Print a separator to the log file. Intended to be used at the tail end of a pipe |
| 81 | log_separator() { |
| 82 | { |
| 83 | echo |
| 84 | echo "----------" |
| 85 | } >> "$build_log" |
| 86 | |
| 87 | tee -a "$build_log" |
| 88 | |
| 89 | { |
| 90 | echo "----------" |
| 91 | echo |
| 92 | } >> "$build_log" |
| 93 | } |
| 94 | |
| 95 | # Call function $1 if it's defined |
| 96 | call_func() { |
| 97 | if type "${1:?}" &>/dev/null; then |
| 98 | echo |
| 99 | echo "> ${2:?}:$1()" |
| 100 | eval "$1" |
| 101 | echo "< $2:$1()" |
| 102 | fi |
| 103 | } |
| 104 | |
Paul Sokolovsky | be6510c | 2024-08-15 21:54:00 +0300 | [diff] [blame] | 105 | # Retry a command a number of times if it fails. Intended for I/O commands |
| 106 | # in a CI environment which may be flaky. |
| 107 | function retry() { |
| 108 | for i in $(seq 1 3); do |
| 109 | if "$@"; then |
| 110 | return 0 |
| 111 | fi |
| 112 | sleep $(( i * 5 )) |
| 113 | done |
| 114 | return 1 |
| 115 | } |
| 116 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 117 | # Call hook $1 in all chosen fragments if it's defined. Hooks are invoked from |
| 118 | # within a subshell, so any variables set within a hook are lost. Should a |
| 119 | # variable needs to be set from within a hook, the function 'set_hook_var' |
| 120 | # should be used |
| 121 | call_hook() { |
| 122 | local func="$1" |
| 123 | local config_fragment |
| 124 | |
| 125 | [ -z "$func" ] && return 0 |
| 126 | |
Paul Sokolovsky | e9962cd | 2021-12-17 18:39:40 +0300 | [diff] [blame] | 127 | echo "=== Calling hooks: $1 ===" |
| 128 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 129 | : >"$hook_env_file" |
| 130 | |
Nicola Mazzucato | 7fc5abd | 2024-02-23 21:32:48 +0000 | [diff] [blame] | 131 | if [ "$run_config_candidates" ]; then |
| 132 | for config_fragment in $run_config_candidates; do |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 133 | ( |
| 134 | source "$ci_root/run_config/$config_fragment" |
| 135 | call_func "$func" "$config_fragment" |
| 136 | ) |
| 137 | done |
| 138 | fi |
| 139 | |
| 140 | # Also source test config file |
| 141 | ( |
| 142 | unset "$func" |
| 143 | source "$test_config_file" |
| 144 | call_func "$func" "$(basename $test_config_file)" |
| 145 | ) |
| 146 | |
| 147 | # Have any variables set take effect |
| 148 | source "$hook_env_file" |
Paul Sokolovsky | e9962cd | 2021-12-17 18:39:40 +0300 | [diff] [blame] | 149 | |
| 150 | echo "=== End calling hooks: $1 ===" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | # Set a variable from within a hook |
| 154 | set_hook_var() { |
| 155 | echo "export $1=\"${2?}\"" >> "$hook_env_file" |
| 156 | } |
| 157 | |
| 158 | # Append to an array from within a hook |
| 159 | append_hook_var() { |
| 160 | echo "export $1+=\"${2?}\"" >> "$hook_env_file" |
| 161 | } |
| 162 | |
| 163 | # Have the main build script source a file |
| 164 | source_later() { |
| 165 | echo "source ${1?}" >> "$hook_env_file" |
| 166 | } |
| 167 | |
| 168 | # Setup TF build wrapper function by pointing to a script containing a function |
| 169 | # that will be called with the TF build commands. |
| 170 | setup_tf_build_wrapper() { |
| 171 | source_later "$ci_root/script/${wrapper?}_wrapper.sh" |
| 172 | set_hook_var "tf_build_wrapper" "${wrapper}_wrapper" |
| 173 | echo "Setup $wrapper build wrapper." |
| 174 | } |
| 175 | |
| 176 | # Collect .bin files for archiving |
| 177 | collect_build_artefacts() { |
| 178 | if [ ! -d "${from:?}" ]; then |
| 179 | return |
| 180 | fi |
| 181 | |
Yann Gautier | 7e9d6cf | 2023-03-08 14:24:38 +0100 | [diff] [blame] | 182 | 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] | 183 | echo "You probably are running local CI on local repositories." |
| 184 | echo "Did you set 'dont_clean' but forgot to run 'distclean'?" |
| 185 | die |
| 186 | fi |
| 187 | } |
| 188 | |
| 189 | # SCP and MCP binaries are named firmware.{bin,elf}, and are placed under |
| 190 | # scp/mcp_ramfw and scp/mcp_romfw directories, so can't be collected by |
| 191 | # collect_build_artefacts function. |
| 192 | collect_scp_artefacts() { |
| 193 | to="${to:?}" \ |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 194 | 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] | 195 | for file; do |
| 196 | ext="$(echo $file | awk -F. "{print \$NF}")" |
| 197 | case $file in |
Anurag Koul | baedf93 | 2021-12-09 12:49:56 +0000 | [diff] [blame] | 198 | */firmware-scp_ramfw/bin/*|*/firmware-scp_ramfw_fvp/bin/*) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 199 | cp $file $to/scp_ram.$ext |
| 200 | ;; |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 201 | */firmware-scp_romfw/bin/*) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 202 | cp $file $to/scp_rom.$ext |
| 203 | ;; |
Anurag Koul | baedf93 | 2021-12-09 12:49:56 +0000 | [diff] [blame] | 204 | */firmware-mcp_ramfw/bin/*|*/firmware-mcp_ramfw_fvp/bin/*) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 205 | cp $file $to/mcp_ram.$ext |
| 206 | ;; |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 207 | */firmware-mcp_romfw/bin/*) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 208 | cp $file $to/mcp_rom.$ext |
| 209 | ;; |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 210 | */firmware-scp_romfw_bypass/bin/*) |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 211 | cp $file $to/scp_rom_bypass.$ext |
| 212 | ;; |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 213 | *) |
| 214 | echo "Unknown SCP binary: $file" >&2 |
| 215 | ;; |
| 216 | esac |
| 217 | done |
| 218 | ' bash '{}' + |
| 219 | } |
| 220 | |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 221 | # Collect SPM/hafnium artefacts with "secure_" appended to the files |
| 222 | # generated for SPM(secure hafnium). |
| 223 | collect_spm_artefacts() { |
Madhukar Pappireddy | c683cf6 | 2021-11-01 14:38:32 -0500 | [diff] [blame] | 224 | if [ -d "${non_secure_from:?}" ]; then |
| 225 | 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] | 226 | fi |
| 227 | |
Madhukar Pappireddy | c683cf6 | 2021-11-01 14:38:32 -0500 | [diff] [blame] | 228 | if [ -d "${secure_from:?}" ]; then |
| 229 | for f in $(find "$secure_from" \( -name "*.bin" -o -name '*.elf' \)); do cp -- "$f" "${to:?}"/secure_$(basename $f); done |
| 230 | fi |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Sandrine Afsa | 07d2bd7 | 2025-04-16 17:03:12 +0200 | [diff] [blame] | 233 | collect_rfa_artefacts() { |
| 234 | if [ ! -d "${from:?}" ]; then |
| 235 | return |
| 236 | fi |
| 237 | |
| 238 | if ! find "$from" -maxdepth 1 \( -name "*.bin" -o -name '*.elf' \) -exec cp -t "${to:?}" '{}' +; then |
| 239 | echo "You probably are running local CI on local repositories." |
| 240 | echo "Did you set 'dont_clean' but forgot to run 'distclean'?" |
| 241 | die |
| 242 | fi |
| 243 | } |
| 244 | |
Javier Almansa Sobrino | 412d361 | 2020-05-22 17:53:12 +0100 | [diff] [blame] | 245 | # Map the UART ID used for expect with the UART descriptor and port |
| 246 | # used by the FPGA automation tools. |
| 247 | map_uart() { |
| 248 | local port="${port:?}" |
| 249 | local descriptor="${descriptor:?}" |
| 250 | local baudrate="${baudrate:?}" |
| 251 | local run_root="${archive:?}/run" |
| 252 | |
| 253 | local uart_dir="$run_root/uart${uart:?}" |
| 254 | mkdir -p "$uart_dir" |
| 255 | |
| 256 | echo "$port" > "$uart_dir/port" |
| 257 | echo "$descriptor" > "$uart_dir/descriptor" |
| 258 | echo "$baudrate" > "$uart_dir/baudrate" |
| 259 | |
| 260 | echo "UART${uart} mapped to port ${port} with descriptor ${descriptor} and baudrate ${baudrate}" |
| 261 | } |
| 262 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 263 | # Arrange environment varibles to be set when expect scripts are launched |
| 264 | set_expect_variable() { |
| 265 | local var="${1:?}" |
| 266 | local val="${2?}" |
| 267 | |
| 268 | local run_root="${archive:?}/run" |
| 269 | local uart_dir="$run_root/uart${uart:?}" |
| 270 | mkdir -p "$uart_dir" |
| 271 | |
| 272 | env_file="$uart_dir/env" quote="1" emit_env "$var" "$val" |
| 273 | echo "UART$uart: env has $@" |
| 274 | } |
| 275 | |
| 276 | # Place the binary package a pointer to expect script, and its parameters |
| 277 | track_expect() { |
| 278 | local file="${file:?}" |
| 279 | local timeout="${timeout-600}" |
| 280 | local run_root="${archive:?}/run" |
| 281 | |
| 282 | local uart_dir="$run_root/uart${uart:?}" |
| 283 | mkdir -p "$uart_dir" |
| 284 | |
| 285 | echo "$file" > "$uart_dir/expect" |
| 286 | echo "$timeout" > "$uart_dir/timeout" |
Paul Sokolovsky | bfa8bab | 2023-01-25 19:34:51 +0700 | [diff] [blame] | 287 | if [ -n "$lava_timeout" ]; then |
| 288 | set_run_env "lava_timeout" "$lava_timeout" |
| 289 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 290 | |
Paul Sokolovsky | bfa8bab | 2023-01-25 19:34:51 +0700 | [diff] [blame] | 291 | 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] | 292 | |
Chris Kay | fab6edc | 2022-11-17 19:18:32 +0000 | [diff] [blame] | 293 | if [ ! -z "${port}" ]; then |
| 294 | echo "${port}" > "$uart_dir/port" |
| 295 | fi |
| 296 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 297 | # The run script assumes UART0 to be primary. If we're asked to set any |
| 298 | # other UART to be primary, set a run environment variable to signal |
| 299 | # that to the run script |
| 300 | if upon "$set_primary"; then |
| 301 | echo "Primary UART set to UART$uart." |
| 302 | set_run_env "primary_uart" "$uart" |
| 303 | fi |
Madhukar Pappireddy | 1e95372 | 2021-11-08 15:23:02 -0600 | [diff] [blame] | 304 | |
| 305 | # UART used by payload(such as tftf, Linux) may not be the same as the |
| 306 | # primary UART. Set a run environment variable to track the payload |
| 307 | # UART which is tracked to check if the test has finished sucessfully. |
| 308 | if upon "$set_payload_uart"; then |
| 309 | echo "Payload uses UART$uart." |
| 310 | set_run_env "payload_uart" "$uart" |
| 311 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | # Extract a FIP in $1 using fiptool |
| 315 | extract_fip() { |
| 316 | local fip="$1" |
| 317 | |
| 318 | if is_url "$1"; then |
| 319 | url="$1" fetch_file |
| 320 | fip="$(basename "$1")" |
| 321 | fi |
| 322 | |
| 323 | "$fiptool" unpack "$fip" |
| 324 | echo "Extracted FIP: $fip" |
| 325 | } |
| 326 | |
| 327 | # Report build failure by printing a the tail end of build log. Archive the |
| 328 | # build log for later inspection |
| 329 | fail_build() { |
| 330 | local log_path |
| 331 | |
| 332 | if upon "$jenkins_run"; then |
| 333 | log_path="$BUILD_URL/artifact/artefacts/build.log" |
| 334 | else |
| 335 | log_path="$build_log" |
| 336 | fi |
| 337 | |
| 338 | echo |
Leonardo Sandoval | ae97eda | 2020-11-12 10:07:03 -0600 | [diff] [blame] | 339 | echo "Build failed! Full build log below:" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 340 | echo "[...]" |
| 341 | echo |
Leonardo Sandoval | ae97eda | 2020-11-12 10:07:03 -0600 | [diff] [blame] | 342 | cat "$build_log" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 343 | echo |
| 344 | echo "See $log_path for full output" |
| 345 | echo |
| 346 | cp -t "$archive" "$build_log" |
| 347 | exit 1; |
| 348 | } |
| 349 | |
| 350 | # Build a FIP with supplied arguments |
| 351 | build_fip() { |
| 352 | ( |
| 353 | echo "Building FIP with arguments: $@" |
| 354 | local tf_env="$workspace/tf.env" |
| 355 | |
| 356 | if [ -f "$tf_env" ]; then |
| 357 | set -a |
| 358 | source "$tf_env" |
| 359 | set +a |
| 360 | fi |
| 361 | |
| 362 | make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \ |
| 363 | ${fip_targets:-fip} &>>"$build_log" || fail_build |
| 364 | ) |
| 365 | } |
| 366 | |
Sandrine Bailleux | 189fdb3 | 2023-10-20 13:41:22 +0200 | [diff] [blame] | 367 | # Build any extra rule from TF-A makefile with supplied arguments. |
| 368 | # |
| 369 | # This is useful in case you need to build something else than firmware binaries |
| 370 | # or the FIP. |
| 371 | build_tf_extra() { |
| 372 | ( |
| 373 | tf_extra_rules=${tf_extra_rules:?} |
| 374 | echo "Building extra TF rule(s): $tf_extra_rules" |
| 375 | echo " Arguments: $@" |
| 376 | |
| 377 | local tf_env="$workspace/tf.env" |
| 378 | |
| 379 | if [ -f "$tf_env" ]; then |
| 380 | set -a |
| 381 | source "$tf_env" |
| 382 | set +a |
| 383 | fi |
| 384 | |
| 385 | make -C "$tf_root" $(cat "$tf_config_file") DEBUG="$DEBUG" V=1 "$@" \ |
| 386 | ${tf_extra_rules} &>>"$build_log" || fail_build |
| 387 | ) |
| 388 | } |
| 389 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 390 | fip_update() { |
| 391 | # Before the update process, check if the given image is supported by |
| 392 | # 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] | 393 | # tandem, and therefore, if one has support, the other has it too. |
| 394 | if ! ("$fiptool" update 2>&1 || true) | grep -qe "\s\+--${bin_name:?}"; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 395 | return 1 |
| 396 | fi |
| 397 | |
| 398 | if not_upon "$(get_tf_opt TRUSTED_BOARD_BOOT)"; then |
| 399 | echo "Updating FIP image: $bin_name" |
| 400 | # Update HW config. Without TBBR, it's only a matter of using |
| 401 | # the update sub-command of fiptool |
| 402 | "$fiptool" update "--$bin_name" "${src:-}" \ |
| 403 | "$archive/fip.bin" |
| 404 | else |
| 405 | echo "Updating FIP image (TBBR): $bin_name" |
| 406 | # With TBBR, we need to unpack, re-create certificates, and then |
| 407 | # recreate the FIP. |
| 408 | local fip_dir="$(mktempdir)" |
| 409 | local bin common_args stem |
| 410 | local rot_key="$(get_tf_opt ROT_KEY)" |
| 411 | |
| 412 | rot_key="${rot_key:?}" |
| 413 | if ! is_abs "$rot_key"; then |
| 414 | rot_key="$tf_root/$rot_key" |
| 415 | fi |
| 416 | |
| 417 | # Arguments only for cert_create |
| 418 | local cert_args="-n" |
| 419 | cert_args+=" --tfw-nvctr ${nvctr:-31}" |
| 420 | cert_args+=" --ntfw-nvctr ${nvctr:-223}" |
| 421 | cert_args+=" --key-alg ${KEY_ALG:-rsa}" |
| 422 | cert_args+=" --rot-key $rot_key" |
| 423 | |
| 424 | local dyn_config_opts=( |
Zelalem | 1af7a7b | 2020-08-04 17:34:32 -0500 | [diff] [blame] | 425 | "fw-config" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 426 | "hw-config" |
| 427 | "tb-fw-config" |
| 428 | "nt-fw-config" |
| 429 | "soc-fw-config" |
| 430 | "tos-fw-config" |
| 431 | ) |
| 432 | |
| 433 | # Binaries without key certificates |
| 434 | declare -A has_no_key_cert |
| 435 | for bin in "tb-fw" "${dyn_config_opts[@]}"; do |
| 436 | has_no_key_cert["$bin"]="1" |
| 437 | done |
| 438 | |
| 439 | # Binaries without certificates |
| 440 | declare -A has_no_cert |
| 441 | for bin in "hw-config" "${dyn_config_opts[@]}"; do |
| 442 | has_no_cert["$bin"]="1" |
| 443 | done |
| 444 | |
| 445 | pushd "$fip_dir" |
| 446 | |
| 447 | # Unpack FIP |
| 448 | "$fiptool" unpack "$archive/fip.bin" &>>"$build_log" |
| 449 | |
| 450 | # Remove all existing certificates |
| 451 | rm -f *-cert.bin |
| 452 | |
| 453 | # Copy the binary to be updated |
| 454 | cp -f "$src" "${bin_name}.bin" |
| 455 | |
| 456 | # FIP unpack dumps binaries with the same name as the option |
| 457 | # used to pack it; likewise for certificates. Reverse-engineer |
| 458 | # the command line from the binary output. |
| 459 | common_args="--trusted-key-cert trusted_key.crt" |
| 460 | for bin in *.bin; do |
| 461 | stem="${bin%%.bin}" |
| 462 | common_args+=" --$stem $bin" |
| 463 | if not_upon "${has_no_cert[$stem]}"; then |
| 464 | common_args+=" --$stem-cert $stem.crt" |
| 465 | fi |
| 466 | if not_upon "${has_no_key_cert[$stem]}"; then |
| 467 | common_args+=" --$stem-key-cert $stem-key.crt" |
| 468 | fi |
| 469 | done |
| 470 | |
| 471 | # Create certificates |
| 472 | "$cert_create" $cert_args $common_args &>>"$build_log" |
| 473 | |
| 474 | # Recreate and archive FIP |
| 475 | "$fiptool" create $common_args "fip.bin" &>>"$build_log" |
| 476 | archive_file "fip.bin" |
| 477 | |
| 478 | popd |
| 479 | fi |
| 480 | } |
| 481 | |
| 482 | # Update hw-config in FIP, and remove the original DTB afterwards. |
| 483 | update_fip_hw_config() { |
| 484 | # 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] | 485 | # in configs: |
| 486 | # 1. Where BL2 isn't present |
| 487 | # 2. Where we boot to Linux directly as BL33 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 488 | case "1" in |
| 489 | "$(get_tf_opt RESET_TO_BL31)" | \ |
Madhukar Pappireddy | 9062ebf | 2021-03-02 17:07:06 -0600 | [diff] [blame] | 490 | "$(get_tf_opt ARM_LINUX_KERNEL_AS_BL33)" | \ |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 491 | "$(get_tf_opt RESET_TO_SP_MIN)" | \ |
Maksims Svecovs | 7a0da52 | 2023-03-06 16:28:27 +0000 | [diff] [blame] | 492 | "$(get_tf_opt RESET_TO_BL2)") |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 493 | return 0;; |
| 494 | esac |
| 495 | |
| 496 | if bin_name="hw-config" src="$archive/dtb.bin" fip_update; then |
| 497 | # Remove the DTB so that model won't load it |
| 498 | rm -f "$archive/dtb.bin" |
| 499 | fi |
| 500 | } |
| 501 | |
| 502 | get_scp_opt() { |
| 503 | ( |
| 504 | name="${1:?}" |
| 505 | if config_valid "$scp_config_file"; then |
| 506 | source "$scp_config_file" |
| 507 | echo "${!name}" |
| 508 | fi |
| 509 | ) |
| 510 | } |
| 511 | |
| 512 | get_tftf_opt() { |
| 513 | ( |
| 514 | name="${1:?}" |
| 515 | if config_valid "$tftf_config_file"; then |
| 516 | source "$tftf_config_file" |
| 517 | echo "${!name}" |
| 518 | fi |
| 519 | ) |
| 520 | } |
| 521 | |
| 522 | get_tf_opt() { |
| 523 | ( |
| 524 | name="${1:?}" |
| 525 | if config_valid "$tf_config_file"; then |
| 526 | source "$tf_config_file" |
| 527 | echo "${!name}" |
| 528 | fi |
| 529 | ) |
| 530 | } |
| 531 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 532 | get_rfa_opt() { |
| 533 | ( |
| 534 | name="${1:?}" |
| 535 | if config_valid "$rfa_config_file"; then |
| 536 | source "$rfa_config_file" |
| 537 | echo "${!name}" |
| 538 | fi |
| 539 | ) |
| 540 | } |
| 541 | |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 542 | get_rmm_opt() { |
| 543 | ( |
| 544 | name="${1:?}" |
| 545 | if config_valid "$rmm_config_file"; then |
| 546 | source "$rmm_config_file" |
| 547 | echo "${!name}" |
| 548 | fi |
| 549 | ) |
| 550 | } |
| 551 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 552 | build_tf() { |
| 553 | ( |
| 554 | env_file="$workspace/tf.env" |
| 555 | config_file="${tf_build_config:-$tf_config_file}" |
| 556 | |
| 557 | # Build fiptool and all targets by default |
Harrison Mutai | 32de9d0 | 2023-06-12 14:23:37 +0100 | [diff] [blame] | 558 | build_targets="${tf_build_targets:-fiptool all}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 559 | |
| 560 | source "$config_file" |
| 561 | |
| 562 | # 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] | 563 | if [ "$(get_tf_opt TRUSTED_BOARD_BOOT)" = 1 ] || |
Manish V Badarkhe | f43e3f5 | 2022-06-21 20:37:25 +0100 | [diff] [blame] | 564 | [ "$(get_tf_opt MEASURED_BOOT)" = 1 ] || |
| 565 | [ "$(get_tf_opt DRTM_SUPPORT)" = 1 ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 566 | mbedtls_dir="$workspace/mbedtls" |
| 567 | if [ ! -d "$mbedtls_dir" ]; then |
| 568 | mbedtls_ar="$workspace/mbedtls.tar.gz" |
| 569 | |
| 570 | url="$mbedtls_archive" saveas="$mbedtls_ar" fetch_file |
| 571 | mkdir "$mbedtls_dir" |
Leonardo Sandoval | ec9e16c | 2020-09-09 14:32:40 -0500 | [diff] [blame] | 572 | extract_tarball $mbedtls_ar $mbedtls_dir --strip-components=1 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 573 | fi |
| 574 | |
| 575 | emit_env "MBEDTLS_DIR" "$mbedtls_dir" |
| 576 | fi |
Jimmy Brisson | 0d5e12c | 2023-05-16 14:51:51 -0500 | [diff] [blame] | 577 | if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] && |
| 578 | not_upon "${TF_M_TESTS_PATH}"; then |
| 579 | emit_env "TF_M_TESTS_PATH" "$WORKSPACE/tf-m-tests" |
| 580 | fi |
| 581 | if [ "$(get_tf_opt PLATFORM_TEST)" = "tfm-testsuite" ] && |
| 582 | not_upon "${TF_M_EXTRAS_PATH}"; then |
| 583 | emit_env "TF_M_EXTRAS_PATH" "$WORKSPACE/tf-m-extras" |
| 584 | fi |
David Vincze | 82db693 | 2024-02-21 12:05:50 +0100 | [diff] [blame] | 585 | if [ "$(get_tf_opt DICE_PROTECTION_ENVIRONMENT)" = 1 ] && |
| 586 | not_upon "${QCBOR_DIR}"; then |
| 587 | emit_env "QCBOR_DIR" "$WORKSPACE/qcbor" |
| 588 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 589 | if [ -f "$env_file" ]; then |
| 590 | set -a |
| 591 | source "$env_file" |
| 592 | set +a |
| 593 | fi |
| 594 | |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 595 | if is_arm_jenkins_env || upon "$local_ci"; then |
| 596 | path_list=( |
| 597 | "$llvm_dir/bin" |
| 598 | ) |
| 599 | extend_path "PATH" "path_list" |
| 600 | fi |
| 601 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 602 | cd "$tf_root" |
| 603 | |
| 604 | # Always distclean when running on Jenkins. Skip distclean when running |
| 605 | # locally and explicitly requested. |
| 606 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
| 607 | make distclean &>>"$build_log" || fail_build |
| 608 | fi |
| 609 | |
| 610 | # Log build command line. It is left unfolded on purpose to assist |
| 611 | # copying to clipboard. |
| 612 | cat <<EOF | log_separator >/dev/null |
| 613 | |
| 614 | Build command line: |
| 615 | $tf_build_wrapper make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets |
| 616 | |
Paul Sokolovsky | 7f71b07 | 2023-10-16 12:59:09 +0300 | [diff] [blame] | 617 | CC version: |
| 618 | $(${CC-${CROSS_COMPILE}gcc} -v 2>&1) |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 619 | EOF |
| 620 | |
Javier Almansa Sobrino | e836318 | 2020-11-10 16:40:53 +0000 | [diff] [blame] | 621 | if not_upon "$local_ci"; then |
| 622 | connect_debugger=0 |
| 623 | fi |
| 624 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 625 | # Build TF. Since build output is being directed to the build log, have |
| 626 | # descriptor 3 point to the current terminal for build wrappers to vent. |
Harrison Mutai | 6361dbe | 2023-02-16 14:12:40 +0000 | [diff] [blame] | 627 | $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] | 628 | DEBUG="$DEBUG" V=1 SPIN_ON_BL1_EXIT="$connect_debugger" \ |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 629 | $build_targets 3>&1 &>>"$build_log" || fail_build |
Harrison Mutai | 32de9d0 | 2023-06-12 14:23:37 +0100 | [diff] [blame] | 630 | |
Harrison Mutai | 6dafb5f | 2023-07-18 15:21:48 +0100 | [diff] [blame] | 631 | if [ "$build_targets" != "doc" ]; then |
Harrison Mutai | 2c2c917 | 2024-04-12 11:24:27 +0000 | [diff] [blame] | 632 | (poetry run memory -sr "$tf_build_root" 2>&1 || true) | tee -a "$build_log" |
Harrison Mutai | 6dafb5f | 2023-07-18 15:21:48 +0100 | [diff] [blame] | 633 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 634 | ) |
| 635 | } |
| 636 | |
Sandrine Afsa | 07d2bd7 | 2025-04-16 17:03:12 +0200 | [diff] [blame] | 637 | build_rfa() { |
| 638 | ( |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 639 | config_file="${rfa_build_config:-$rfa_config_file}" |
Sandrine Afsa | 07d2bd7 | 2025-04-16 17:03:12 +0200 | [diff] [blame] | 640 | |
| 641 | # Build the 'all' target by default. |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 642 | build_targets="${rfa_build_targets:-all}" |
Sandrine Afsa | 07d2bd7 | 2025-04-16 17:03:12 +0200 | [diff] [blame] | 643 | |
| 644 | source "$config_file" |
| 645 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 646 | cd "$rfa_root" |
Sandrine Afsa | 07d2bd7 | 2025-04-16 17:03:12 +0200 | [diff] [blame] | 647 | |
| 648 | # Always distclean when running on Jenkins. Skip distclean when running |
| 649 | # locally and explicitly requested. |
| 650 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
| 651 | echo "Cleaning TF-A..." |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 652 | make -C "$tf_root" distclean &>>"$build_log" || fail_build |
Sandrine Afsa | 07d2bd7 | 2025-04-16 17:03:12 +0200 | [diff] [blame] | 653 | |
| 654 | echo 'Cleaning RF-A...' |
| 655 | cargo clean &>>"$build_log" || fail_build |
| 656 | fi |
| 657 | |
| 658 | # Log build command line. It is left unfolded on purpose to assist |
| 659 | # copying to clipboard. |
| 660 | cat <<EOF | log_separator >/dev/null |
| 661 | |
| 662 | Build command line: |
| 663 | make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG $build_targets |
| 664 | |
| 665 | cargo version: |
| 666 | $(cargo --version 2>&1) |
| 667 | EOF |
| 668 | |
| 669 | # Build RF-A and TF-A. Since build output is being directed to the build |
| 670 | # log, have descriptor 3 point to the current terminal for build |
| 671 | # wrappers to vent. |
Tomás González | 72aca67 | 2025-06-11 11:26:00 +0100 | [diff] [blame] | 672 | eval make $make_j_opts $(cat "$config_file") \ |
| 673 | DEBUG="$DEBUG" \ |
Sandrine Afsa | 07d2bd7 | 2025-04-16 17:03:12 +0200 | [diff] [blame] | 674 | $build_targets 3>&1 &>>"$build_log" || fail_build |
| 675 | ) |
| 676 | } |
| 677 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 678 | build_tftf() { |
| 679 | ( |
| 680 | config_file="${tftf_build_config:-$tftf_config_file}" |
| 681 | |
| 682 | # Build tftf target by default |
| 683 | build_targets="${tftf_build_targets:-all}" |
| 684 | |
| 685 | source "$config_file" |
| 686 | |
| 687 | cd "$tftf_root" |
| 688 | |
| 689 | # Always distclean when running on Jenkins. Skip distclean when running |
| 690 | # locally and explicitly requested. |
| 691 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
| 692 | make distclean &>>"$build_log" || fail_build |
| 693 | fi |
| 694 | |
| 695 | # TFTF build system cannot reliably deal with -j option, so we avoid |
| 696 | # using that. |
| 697 | |
| 698 | # Log build command line |
| 699 | cat <<EOF | log_separator >/dev/null |
| 700 | |
| 701 | Build command line: |
Boyan Karatotev | 51060ba | 2024-10-29 16:55:10 +0000 | [diff] [blame] | 702 | make $make_j_opts $(cat "$config_file" | tr '\n' ' ') DEBUG=$DEBUG V=1 $build_targets |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 703 | |
| 704 | EOF |
| 705 | |
Boyan Karatotev | 51060ba | 2024-10-29 16:55:10 +0000 | [diff] [blame] | 706 | make $make_j_opts $(cat "$config_file") DEBUG="$DEBUG" V=1 \ |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 707 | $build_targets &>>"$build_log" || fail_build |
| 708 | ) |
| 709 | } |
| 710 | |
| 711 | build_scp() { |
| 712 | ( |
| 713 | config_file="${scp_build_config:-$scp_config_file}" |
| 714 | |
| 715 | source "$config_file" |
| 716 | |
| 717 | cd "$scp_root" |
| 718 | |
| 719 | # Always distclean when running on Jenkins. Skip distclean when running |
| 720 | # locally and explicitly requested. |
| 721 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
Leandro Belli | 99e20b2 | 2022-12-29 13:50:47 +0000 | [diff] [blame] | 722 | make -f Makefile.cmake clean &>>"$build_log" || fail_build |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 723 | fi |
| 724 | |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 725 | python3 -m venv .venv |
| 726 | . .venv/bin/activate |
| 727 | |
| 728 | # Install extra tools used by CMake build system |
| 729 | pip install -r requirements.txt --timeout 30 --retries 15 |
| 730 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 731 | # Log build command line. It is left unfolded on purpose to assist |
| 732 | # copying to clipboard. |
| 733 | cat <<EOF | log_separator >/dev/null |
| 734 | |
| 735 | SCP build command line: |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 736 | make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \ |
| 737 | TOOLCHAIN=GNU \ |
| 738 | MODE="$mode" \ |
Nicola Mazzucato | 506b580 | 2021-12-24 14:23:25 +0000 | [diff] [blame] | 739 | EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \ |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 740 | V=1 &>>"$build_log" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 741 | |
| 742 | EOF |
| 743 | |
| 744 | # Build SCP |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 745 | make -f Makefile.cmake $(cat "$config_file" | tr '\n' ' ') \ |
| 746 | TOOLCHAIN=GNU \ |
| 747 | MODE="$mode" \ |
Nicola Mazzucato | 506b580 | 2021-12-24 14:23:25 +0000 | [diff] [blame] | 748 | EXTRA_CONFIG_ARGS+=-DDISABLE_CPPCHECK=true \ |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 749 | V=1 &>>"$build_log" \ |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 750 | || fail_build |
| 751 | ) |
| 752 | } |
| 753 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 754 | clone_scp_tools() { |
| 755 | |
| 756 | if [ ! -d "$scp_tools_root" ]; then |
| 757 | echo "Cloning SCP-tools ... $scp_tools_commit" |& log_separator |
| 758 | |
| 759 | clone_url="${SCP_TOOLS_CHECKOUT_LOC:-$scp_tools_src_repo_url}" \ |
| 760 | where="$scp_tools_root" \ |
| 761 | refspec="${scp_tools_commit}" |
| 762 | clone_repo &>>"$build_log" |
| 763 | else |
| 764 | echo "Already cloned SCP-tools ..." |& log_separator |
| 765 | fi |
| 766 | |
| 767 | show_head "$scp_tools_root" |
| 768 | |
| 769 | cd "$scp_tools_root" |
| 770 | |
| 771 | echo "Updating submodules" |
| 772 | |
| 773 | git submodule init |
| 774 | |
| 775 | git submodule update |
| 776 | |
Nicola Mazzucato | 9b17142 | 2023-08-29 15:50:49 +0100 | [diff] [blame] | 777 | 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] | 778 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 779 | cd "scmi" |
Nicola Mazzucato | 7302cd3 | 2021-12-14 13:36:57 +0000 | [diff] [blame] | 780 | git checkout $lib_commit |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 781 | |
| 782 | git show --quiet --no-color | sed 's/^/ > /g' |
| 783 | } |
| 784 | |
| 785 | clone_tf_for_scp_tools() { |
| 786 | scp_tools_arm_tf="$scp_tools_root/arm-tf" |
| 787 | |
| 788 | if [ ! -d "$scp_tools_arm_tf" ]; then |
| 789 | echo "Cloning TF-4-SCP-tools ..." |& log_separator |
| 790 | |
| 791 | clone_url="$tf_for_scp_tools_src_repo_url" |
| 792 | where="$scp_tools_arm_tf" |
| 793 | |
| 794 | git clone "$clone_url" "$where" |
| 795 | |
| 796 | cd "$scp_tools_arm_tf" |
| 797 | |
Joel Goddard | 3ad0306 | 2021-03-16 16:47:42 +0000 | [diff] [blame] | 798 | git checkout --track origin/juno-v4.3 |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 799 | |
| 800 | git show --quiet --no-color | sed 's/^/ > /g' |
| 801 | |
| 802 | else |
| 803 | echo "Already cloned TF-4-SCP-tools ..." |& log_separator |
| 804 | fi |
| 805 | } |
| 806 | |
| 807 | build_scmi_lib_scp_tools() { |
| 808 | ( |
| 809 | cd "$scp_tools_root" |
| 810 | |
| 811 | cd "scmi" |
| 812 | |
| 813 | scp_tools_arm_tf="$scp_tools_root/arm-tf" |
| 814 | |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 815 | cross_compile="$(set_cross_compile_gcc_linaro_toolchain)" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 816 | |
| 817 | std_libs="-I$scp_tools_arm_tf/include/common" |
| 818 | std_libs="$std_libs -I$scp_tools_arm_tf/include/common/tbbr" |
| 819 | std_libs="$std_libs -I$scp_tools_arm_tf/include/drivers/arm" |
| 820 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib" |
| 821 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/aarch64" |
| 822 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib" |
| 823 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/stdlib/sys" |
| 824 | std_libs="$std_libs -I$scp_tools_arm_tf/include/lib/xlat_tables" |
| 825 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/common" |
| 826 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/common" |
| 827 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/css/common" |
| 828 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/board/common" |
| 829 | std_libs="$std_libs -I$scp_tools_arm_tf/include/plat/arm/soc/common" |
| 830 | std_libs="$std_libs -I$scp_tools_arm_tf/plat/arm/board/juno/include" |
| 831 | |
| 832 | cflags="-Og -g" |
| 833 | cflags="$cflags -mgeneral-regs-only" |
| 834 | cflags="$cflags -mstrict-align" |
| 835 | cflags="$cflags -nostdinc" |
| 836 | cflags="$cflags -fno-inline" |
| 837 | cflags="$cflags -ffreestanding" |
| 838 | cflags="$cflags -ffunction-sections" |
| 839 | cflags="$cflags -fdata-sections" |
| 840 | cflags="$cflags -DAARCH64" |
| 841 | cflags="$cflags -DPRId32=\"ld\"" |
Joel Goddard | 3ad0306 | 2021-03-16 16:47:42 +0000 | [diff] [blame] | 842 | cflags="$cflags -DVERBOSE_LEVEL=3" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 843 | |
| 844 | cflags="$cflags $std_libs" |
| 845 | |
Joel Goddard | 3ad0306 | 2021-03-16 16:47:42 +0000 | [diff] [blame] | 846 | protocols="performance,power_domain,system_power,reset" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 847 | |
| 848 | echo "Building SCMI library (SCP-tools) ..." |
| 849 | |
| 850 | make "CROSS_COMPILE=$cross_compile" \ |
| 851 | "CFLAGS=$cflags" \ |
Joel Goddard | 3ad0306 | 2021-03-16 16:47:42 +0000 | [diff] [blame] | 852 | "PLAT=baremetal" \ |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 853 | "PROTOCOLS=$protocols" \ |
| 854 | "clean" \ |
| 855 | "all" |
| 856 | ) |
| 857 | } |
| 858 | |
| 859 | build_tf_for_scp_tools() { |
| 860 | |
| 861 | cd "$scp_tools_root/arm-tf" |
| 862 | |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 863 | cross_compile="$(set_cross_compile_gcc_linaro_toolchain)" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 864 | |
| 865 | if [ "$1" = "release" ]; then |
| 866 | echo "Build TF-4-SCP-Tools rls..." |
| 867 | else |
| 868 | echo "Build TF-4-SCP-Tools dbg..." |
| 869 | |
| 870 | make realclean |
| 871 | |
| 872 | make "BM_TEST=scmi" \ |
| 873 | "ARM_BOARD_OPTIMISE_MEM=1" \ |
| 874 | "BM_CSS=juno" \ |
| 875 | "CSS_USE_SCMI_SDS_DRIVER=1" \ |
| 876 | "PLAT=juno" \ |
| 877 | "DEBUG=1" \ |
| 878 | "PLATFORM=juno" \ |
| 879 | "CROSS_COMPILE=$cross_compile" \ |
| 880 | "BM_WORKSPACE=$scp_tools_root/baremetal" |
| 881 | |
| 882 | archive_file "build/juno/debug/bl1.bin" |
| 883 | |
| 884 | archive_file "build/juno/debug/bl2.bin" |
| 885 | |
| 886 | archive_file "build/juno/debug/bl31.bin" |
| 887 | fi |
| 888 | } |
| 889 | |
| 890 | build_fip_for_scp_tools() { |
| 891 | |
| 892 | cd "$scp_tools_root/arm-tf" |
| 893 | |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 894 | cross_compile="$(set_cross_compile_gcc_linaro_toolchain)" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 895 | |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 896 | if [ ! -d "$scp_root/build/juno/GNU/debug/firmware-scp_ramfw" ]; then |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 897 | make fiptool |
| 898 | echo "Make FIP 4 SCP-Tools rls..." |
| 899 | |
| 900 | else |
| 901 | make fiptool |
| 902 | echo "Make FIP 4 SCP-Tools dbg..." |
| 903 | |
| 904 | make "PLAT=juno" \ |
| 905 | "all" \ |
| 906 | "fip" \ |
| 907 | "DEBUG=1" \ |
| 908 | "CROSS_COMPILE=$cross_compile" \ |
| 909 | "BL31=$scp_tools_root/arm-tf/build/juno/debug/bl31.bin" \ |
| 910 | "BL33=$scp_tools_root/baremetal/dummy_bl33" \ |
Joel Goddard | 9bdfe3c | 2021-02-25 10:15:14 +0000 | [diff] [blame] | 911 | "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] | 912 | |
| 913 | archive_file "$scp_tools_root/arm-tf/build/juno/debug/fip.bin" |
| 914 | fi |
| 915 | } |
| 916 | |
| 917 | build_cc() { |
| 918 | # Building code coverage plugin |
| 919 | ARM_DIR=/arm |
| 920 | pvlibversion=$(/arm/devsys-tools/abs/detag "SysGen:PVModelLib:$model_version::trunk") |
| 921 | PVLIB_HOME=$warehouse/SysGen/PVModelLib/$model_version/${pvlibversion}/external |
| 922 | if [ -n "$(find "$ARM_DIR" -maxdepth 0 -type d -empty 2>/dev/null)" ]; then |
| 923 | echo "Error: Arm warehouse not mounted. Please mount the Arm warehouse to your /arm local folder" |
| 924 | exit -1 |
| 925 | fi # Error if arm warehouse not found |
| 926 | cd "$ccpathspec/scripts/tools/code_coverage/fastmodel_baremetal/bmcov" |
| 927 | |
| 928 | make -C model-plugin PVLIB_HOME=$PVLIB_HOME &>>"$build_log" |
| 929 | } |
| 930 | |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 931 | build_spm() { |
| 932 | ( |
| 933 | env_file="$workspace/spm.env" |
| 934 | config_file="${spm_build_config:-$spm_config_file}" |
| 935 | |
| 936 | source "$config_file" |
| 937 | |
| 938 | if [ -f "$env_file" ]; then |
| 939 | set -a |
| 940 | source "$env_file" |
| 941 | set +a |
| 942 | fi |
| 943 | |
| 944 | cd "$spm_root" |
| 945 | |
| 946 | # Always clean when running on Jenkins. Skip clean when running |
| 947 | # locally and explicitly requested. |
| 948 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
| 949 | # make clean fails on a fresh repo where the project has not |
| 950 | # yet been built. Hence only clean if out/reference directory |
| 951 | # already exists. |
| 952 | if [ -d "out/reference" ]; then |
| 953 | make clean &>>"$build_log" || fail_build |
| 954 | fi |
| 955 | fi |
| 956 | |
| 957 | # Log build command line. It is left unfolded on purpose to assist |
| 958 | # copying to clipboard. |
| 959 | cat <<EOF | log_separator >/dev/null |
| 960 | |
| 961 | Build command line: |
| 962 | make $make_j_opts $(cat "$config_file" | tr '\n' ' ') |
| 963 | |
| 964 | EOF |
| 965 | |
| 966 | # Build SPM. Since build output is being directed to the build log, have |
| 967 | # descriptor 3 point to the current terminal for build wrappers to vent. |
| 968 | make $make_j_opts $(cat "$config_file") 3>&1 &>>"$build_log" \ |
| 969 | || fail_build |
| 970 | ) |
| 971 | } |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 972 | |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 973 | build_rmm() { |
| 974 | ( |
| 975 | env_file="$workspace/rmm.env" |
| 976 | config_file="${rmm_build_config:-$rmm_config_file}" |
| 977 | |
| 978 | # Build fiptool and all targets by default |
| 979 | build_targets="${rmm_build_targets}" |
| 980 | export CROSS_COMPILE="${aarch64_none_elf_prefix}" |
| 981 | |
| 982 | source "$config_file" |
| 983 | |
| 984 | if [ -f "$env_file" ]; then |
| 985 | set -a |
| 986 | source "$env_file" |
| 987 | set +a |
| 988 | fi |
| 989 | |
| 990 | cd "$rmm_root" |
| 991 | |
| 992 | if [ -f "$rmm_root/requirements.txt" ]; then |
| 993 | export PATH="$HOME/.local/bin:$PATH" |
| 994 | python3 -m pip install --upgrade pip |
| 995 | python3 -m pip install -r "$rmm_root/requirements.txt" |
| 996 | fi |
| 997 | |
| 998 | # Always distclean when running on Jenkins. Skip distclean when running |
| 999 | # locally and explicitly requested. |
| 1000 | if upon "$jenkins_run" || not_upon "$dont_clean"; then |
| 1001 | # Remove 'rmm\build' folder |
| 1002 | echo "Removing $rmm_build_root..." |
| 1003 | rm -rf $rmm_build_root |
| 1004 | fi |
| 1005 | |
| 1006 | # Log build command line. It is left unfolded on purpose to assist |
| 1007 | # copying to clipboard. |
| 1008 | cat <<EOF | log_separator >/dev/null |
| 1009 | |
| 1010 | Build command line: |
| 1011 | cmake -DRMM_CONFIG=${plat}_defcfg $cmake_gen -S $rmm_root -B $rmm_build_root -DCMAKE_BUILD_TYPE=$cmake_build_type |
| 1012 | cmake --build $rmm_build_root $make_j_opts -v |
| 1013 | EOF |
| 1014 | if not_upon "$local_ci"; then |
| 1015 | connect_debugger=0 |
| 1016 | fi |
| 1017 | |
| 1018 | cmake -DRMM_CONFIG=${plat}_defcfg $cmake_gen -S $rmm_root -B $rmm_build_root -DCMAKE_BUILD_TYPE=$cmake_build_type |
| 1019 | cmake --build $rmm_build_root $make_j_opts -v 3>&1 &>>"$build_log" || fail_build |
| 1020 | ) |
| 1021 | } |
| 1022 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1023 | # Set metadata for the whole package so that it can be used by both Jenkins and |
| 1024 | # shell |
| 1025 | set_package_var() { |
| 1026 | env_file="$artefacts/env" emit_env "$@" |
| 1027 | } |
| 1028 | |
| 1029 | set_tf_build_targets() { |
| 1030 | echo "Set build target to '${targets:?}'" |
| 1031 | set_hook_var "tf_build_targets" "$targets" |
| 1032 | } |
| 1033 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1034 | set_rfa_build_targets() { |
| 1035 | echo "Set build target to '${targets:?}'" |
| 1036 | set_hook_var "rfa_build_targets" "$targets" |
| 1037 | } |
| 1038 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1039 | set_tftf_build_targets() { |
| 1040 | echo "Set build target to '${targets:?}'" |
| 1041 | set_hook_var "tftf_build_targets" "$targets" |
| 1042 | } |
| 1043 | |
| 1044 | set_scp_build_targets() { |
| 1045 | echo "Set build target to '${targets:?}'" |
| 1046 | set_hook_var "scp_build_targets" "$targets" |
| 1047 | } |
| 1048 | |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1049 | set_spm_build_targets() { |
| 1050 | echo "Set build target to '${targets:?}'" |
| 1051 | set_hook_var "spm_build_targets" "$targets" |
| 1052 | } |
| 1053 | |
Daniel Boulby | b8d2a46 | 2022-03-07 13:55:25 +0000 | [diff] [blame] | 1054 | set_spm_out_dir() { |
| 1055 | echo "Set SPMC binary build to '${out_dir:?}'" |
| 1056 | set_hook_var "spm_secure_out_dir" "$out_dir" |
| 1057 | } |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1058 | # Look under $archive directory for known files such as blX images, kernel, DTB, |
| 1059 | # initrd etc. For each known file foo, if foo.bin exists, then set variable |
| 1060 | # foo_bin to the path of the file. Make the path relative to the workspace so as |
| 1061 | # to remove any @ characters, which Jenkins inserts for parallel runs. If the |
| 1062 | # file doesn't exist, unset its path. |
| 1063 | set_default_bin_paths() { |
| 1064 | local image image_name image_path path |
| 1065 | local archive="${archive:?}" |
| 1066 | local set_vars |
| 1067 | local var |
| 1068 | |
| 1069 | pushd "$archive" |
| 1070 | |
| 1071 | for file in *.bin; do |
| 1072 | # Get a shell variable from the file's stem |
| 1073 | var_name="${file%%.*}_bin" |
| 1074 | var_name="$(echo "$var_name" | sed -r 's/[^[:alnum:]]/_/g')" |
| 1075 | |
| 1076 | # Skip setting the variable if it's already |
| 1077 | if [ "${!var_name}" ]; then |
| 1078 | echo "Note: not setting $var_name; already set to ${!var_name}" |
| 1079 | continue |
| 1080 | else |
| 1081 | set_vars+="$var_name " |
| 1082 | fi |
| 1083 | |
| 1084 | eval "$var_name=$file" |
| 1085 | done |
| 1086 | |
| 1087 | echo "Binary paths set for: " |
| 1088 | { |
| 1089 | for var in $set_vars; do |
| 1090 | echo -n "\$$var " |
| 1091 | done |
| 1092 | } | fmt -80 | sed 's/^/ /' |
| 1093 | echo |
| 1094 | |
| 1095 | popd |
| 1096 | } |
| 1097 | |
| 1098 | gen_model_params() { |
| 1099 | local model_param_file="$archive/model_params" |
Javier Almansa Sobrino | e836318 | 2020-11-10 16:40:53 +0000 | [diff] [blame] | 1100 | [ "$connect_debugger" ] && [ "$connect_debugger" -eq 1 ] && wait_debugger=1 |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1101 | |
| 1102 | set_default_bin_paths |
| 1103 | echo "Generating model parameter for $model..." |
| 1104 | source "$ci_root/model/${model:?}.sh" |
| 1105 | archive_file "$model_param_file" |
| 1106 | } |
| 1107 | |
| 1108 | set_model_path() { |
| 1109 | set_run_env "model_path" "${1:?}" |
| 1110 | } |
| 1111 | |
Zelalem | 1af7a7b | 2020-08-04 17:34:32 -0500 | [diff] [blame] | 1112 | set_model_env() { |
| 1113 | local var="${1:?}" |
| 1114 | local val="${2?}" |
| 1115 | local run_root="${archive:?}/run" |
| 1116 | |
| 1117 | mkdir -p "$run_root" |
| 1118 | echo "export $var=$val" >> "$run_root/model_env" |
| 1119 | } |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1120 | set_run_env() { |
| 1121 | local var="${1:?}" |
| 1122 | local val="${2?}" |
| 1123 | local run_root="${archive:?}/run" |
| 1124 | |
| 1125 | mkdir -p "$run_root" |
| 1126 | env_file="$run_root/env" quote="1" emit_env "$var" "$val" |
| 1127 | } |
| 1128 | |
| 1129 | show_head() { |
| 1130 | # Display HEAD descripton |
| 1131 | pushd "$1" |
| 1132 | git show --quiet --no-color | sed 's/^/ > /g' |
| 1133 | echo |
| 1134 | popd |
| 1135 | } |
| 1136 | |
| 1137 | # Choose debug binaries to run; by default, release binaries are chosen to run |
| 1138 | use_debug_bins() { |
| 1139 | local run_root="${archive:?}/run" |
| 1140 | |
| 1141 | echo "Choosing debug binaries for execution" |
| 1142 | set_package_var "BIN_MODE" "debug" |
| 1143 | } |
| 1144 | |
| 1145 | assert_can_git_clone() { |
| 1146 | local name="${1:?}" |
| 1147 | local dir="${!name}" |
| 1148 | |
| 1149 | # If it doesn't exist, it can be cloned into |
| 1150 | if [ ! -e "$dir" ]; then |
| 1151 | return 0 |
| 1152 | fi |
| 1153 | |
| 1154 | # If it's a directory, it must be a Git clone already |
| 1155 | if [ -d "$dir" ] && [ -d "$dir/.git" ]; then |
| 1156 | # No need to clone again |
| 1157 | echo "Using existing git clone for $name: $dir" |
| 1158 | return 1 |
| 1159 | fi |
| 1160 | |
| 1161 | die "Path $dir exists but is not a git clone" |
| 1162 | } |
| 1163 | |
| 1164 | clone_repo() { |
| 1165 | if ! is_url "${clone_url?}"; then |
| 1166 | # For --depth to take effect on local paths, it needs to use the |
| 1167 | # file:// scheme. |
| 1168 | clone_url="file://$clone_url" |
| 1169 | fi |
| 1170 | |
| 1171 | git clone -q --depth 1 "$clone_url" "${where?}" |
| 1172 | if [ "$refspec" ]; then |
| 1173 | pushd "$where" |
| 1174 | git fetch -q --depth 1 origin "$refspec" |
| 1175 | git checkout -q FETCH_HEAD |
| 1176 | popd |
| 1177 | fi |
| 1178 | } |
| 1179 | |
| 1180 | build_unstable() { |
| 1181 | echo "--BUILD UNSTABLE--" | tee -a "$build_log" |
| 1182 | } |
| 1183 | |
| 1184 | undo_patch_record() { |
| 1185 | if [ ! -f "${patch_record:?}" ]; then |
| 1186 | return |
| 1187 | fi |
| 1188 | |
| 1189 | # Undo patches in reverse |
| 1190 | echo |
| 1191 | for patch_name in $(tac "$patch_record"); do |
| 1192 | echo "Undoing $patch_name..." |
| 1193 | if ! git apply -R "$ci_root/patch/$patch_name"; then |
| 1194 | if upon "$local_ci"; then |
| 1195 | echo |
| 1196 | echo "Your local directory may have been dirtied." |
| 1197 | echo |
| 1198 | fi |
| 1199 | fail_build |
| 1200 | fi |
| 1201 | done |
| 1202 | |
| 1203 | rm -f "$patch_record" |
| 1204 | } |
| 1205 | |
| 1206 | undo_local_patches() { |
| 1207 | pushd "$tf_root" |
| 1208 | patch_record="$tf_patch_record" undo_patch_record |
| 1209 | popd |
| 1210 | |
| 1211 | if [ -d "$tftf_root" ]; then |
| 1212 | pushd "$tftf_root" |
| 1213 | patch_record="$tftf_patch_record" undo_patch_record |
| 1214 | popd |
| 1215 | fi |
| 1216 | } |
| 1217 | |
| 1218 | undo_tftf_patches() { |
| 1219 | pushd "$tftf_root" |
| 1220 | patch_record="$tftf_patch_record" undo_patch_record |
| 1221 | popd |
| 1222 | } |
| 1223 | |
| 1224 | undo_tf_patches() { |
| 1225 | pushd "$tf_root" |
| 1226 | patch_record="$tf_patch_record" undo_patch_record |
| 1227 | popd |
| 1228 | } |
| 1229 | |
| 1230 | apply_patch() { |
| 1231 | # If skip_patches is set, the developer has applied required patches |
| 1232 | # manually. They probably want to keep them applied for debugging |
| 1233 | # purposes too. This means we don't have to apply/revert them as part of |
| 1234 | # build process. |
| 1235 | if upon "$skip_patches"; then |
| 1236 | echo "Skipped applying ${1:?}..." |
| 1237 | return 0 |
| 1238 | else |
| 1239 | echo "Applying ${1:?}..." |
| 1240 | fi |
| 1241 | |
Sandrine Bailleux | 4cb8c22 | 2023-09-13 13:48:15 +0200 | [diff] [blame] | 1242 | 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] | 1243 | echo "Skipping already applied ${1:?}" |
| 1244 | return 0 |
| 1245 | fi |
| 1246 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1247 | if git apply < "$ci_root/patch/$1"; then |
| 1248 | echo "$1" >> "${patch_record:?}" |
| 1249 | else |
| 1250 | if upon "$local_ci"; then |
| 1251 | undo_local_patches |
| 1252 | fi |
| 1253 | fail_build |
| 1254 | fi |
| 1255 | } |
| 1256 | |
| 1257 | apply_tftf_patch() { |
| 1258 | pushd "$tftf_root" |
| 1259 | patch_record="$tftf_patch_record" apply_patch "$1" |
| 1260 | popd |
| 1261 | } |
| 1262 | |
| 1263 | apply_tf_patch() { |
| 1264 | pushd "$tf_root" |
| 1265 | patch_record="$tf_patch_record" apply_patch "$1" |
| 1266 | popd |
| 1267 | } |
| 1268 | |
| 1269 | # Clear workspace for a local run |
Leandro Belli | be7b8fa | 2024-07-18 10:14:22 +0100 | [diff] [blame] | 1270 | if not_upon "$jenkins_run" && not_upon "$dont_clean"; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1271 | rm -rf "$workspace" |
| 1272 | |
| 1273 | # Clear residue from previous runs |
| 1274 | rm -rf "$archive" |
| 1275 | fi |
| 1276 | |
| 1277 | mkdir -p "$workspace" |
| 1278 | mkdir -p "$archive" |
| 1279 | set_package_var "TEST_CONFIG" "$test_config" |
| 1280 | |
| 1281 | { |
| 1282 | echo |
| 1283 | echo "CONFIGURATION: $test_group/$test_config" |
| 1284 | echo |
| 1285 | } |& log_separator |
| 1286 | |
| 1287 | tf_config="$(echo "$build_configs" | awk -F, '{print $1}')" |
| 1288 | tftf_config="$(echo "$build_configs" | awk -F, '{print $2}')" |
| 1289 | scp_config="$(echo "$build_configs" | awk -F, '{print $3}')" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1290 | scp_tools_config="$(echo "$build_configs" | awk -F, '{print $4}')" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1291 | spm_config="$(echo "$build_configs" | awk -F, '{print $5}')" |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1292 | rmm_config="$(echo "$build_configs" | awk -F, '{print $6}')" |
Tomás González | fa3e24b | 2025-07-22 10:59:06 +0100 | [diff] [blame] | 1293 | rfa_config="$(echo "$build_configs" | awk -F, '{print $7}')" |
| 1294 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1295 | |
| 1296 | test_config_file="$ci_root/group/$test_group/$test_config" |
| 1297 | |
| 1298 | tf_config_file="$ci_root/tf_config/$tf_config" |
| 1299 | tftf_config_file="$ci_root/tftf_config/$tftf_config" |
| 1300 | scp_config_file="$ci_root/scp_config/$scp_config" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1301 | scp_tools_config_file="$ci_root/scp_tools_config/$scp_tools_config" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1302 | spm_config_file="$ci_root/spm_config/$spm_config" |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1303 | rmm_config_file="$ci_root/rmm_config/$rmm_config" |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1304 | rfa_config_file="$ci_root/rfa_config/$rfa_config" |
| 1305 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1306 | |
| 1307 | # File that keeps track of applied patches |
| 1308 | tf_patch_record="$workspace/tf_patches" |
| 1309 | tftf_patch_record="$workspace/tftf_patches" |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1310 | rfa_patch_record="$workspace/rfa_patches" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1311 | |
| 1312 | pushd "$workspace" |
| 1313 | |
| 1314 | if ! config_valid "$tf_config"; then |
| 1315 | tf_config= |
| 1316 | else |
| 1317 | echo "Trusted Firmware config:" |
| 1318 | echo |
| 1319 | sort "$tf_config_file" | sed '/^\s*$/d;s/^/\t/' |
| 1320 | echo |
| 1321 | fi |
| 1322 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1323 | if ! config_valid "$rfa_config"; then |
| 1324 | rfa_config= |
| 1325 | else |
| 1326 | echo "RF-A config:" |
| 1327 | echo |
| 1328 | sort "$rfa_config_file" | sed '/^\s*$/d;s/^/\t/' |
| 1329 | echo |
| 1330 | fi |
| 1331 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1332 | if ! config_valid "$tftf_config"; then |
| 1333 | tftf_config= |
| 1334 | else |
| 1335 | echo "Trusted Firmware TF config:" |
| 1336 | echo |
| 1337 | sort "$tftf_config_file" | sed '/^\s*$/d;s/^/\t/' |
| 1338 | echo |
| 1339 | fi |
| 1340 | |
| 1341 | if ! config_valid "$scp_config"; then |
| 1342 | scp_config= |
| 1343 | else |
| 1344 | echo "SCP firmware config:" |
| 1345 | echo |
| 1346 | sort "$scp_config_file" | sed '/^\s*$/d;s/^/\t/' |
| 1347 | echo |
| 1348 | fi |
| 1349 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1350 | if ! config_valid "$scp_tools_config"; then |
| 1351 | scp_tools_config= |
| 1352 | else |
| 1353 | echo "SCP Tools config:" |
| 1354 | echo |
| 1355 | sort "$scp_tools_config_file" | sed '/^\s*$/d;s/^/\t/' |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1356 | fi |
| 1357 | |
| 1358 | if ! config_valid "$spm_config"; then |
| 1359 | spm_config= |
| 1360 | else |
| 1361 | echo "SPM config:" |
| 1362 | echo |
| 1363 | sort "$spm_config_file" | sed '/^\s*$/d;s/^/\t/' |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1364 | echo |
| 1365 | fi |
| 1366 | |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1367 | # File that keeps track of applied patches |
| 1368 | rmm_patch_record="$workspace/rmm_patches" |
| 1369 | |
| 1370 | if ! config_valid "$rmm_config"; then |
| 1371 | rmm_config= |
| 1372 | else |
| 1373 | echo "Trusted Firmware RMM config:" |
| 1374 | echo |
| 1375 | sort "$rmm_config_file" | sed '/^\s*$/d;s/^/\t/' |
| 1376 | echo |
| 1377 | fi |
| 1378 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1379 | if ! config_valid "$run_config"; then |
| 1380 | run_config= |
| 1381 | fi |
| 1382 | |
| 1383 | if [ "$tf_config" ] && assert_can_git_clone "tf_root"; then |
| 1384 | # If the Trusted Firmware repository has already been checked out, use |
| 1385 | # that location. Otherwise, clone one ourselves. |
| 1386 | echo "Cloning Trusted Firmware..." |
| 1387 | clone_url="${TF_CHECKOUT_LOC:-$tf_src_repo_url}" where="$tf_root" \ |
| 1388 | refspec="$TF_REFSPEC" clone_repo &>>"$build_log" |
| 1389 | show_head "$tf_root" |
| 1390 | fi |
| 1391 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1392 | if [ "$rfa_config" ] && assert_can_git_clone "rfa_root"; then |
| 1393 | # If the Rusted Firmware repository has already been checked out, use |
| 1394 | # that location. Otherwise, clone one ourselves. |
| 1395 | echo "Cloning Rusted Firmware..." |
| 1396 | |
| 1397 | clone_url="${RFA_CHECKOUT_LOC:-$rfa_src_repo_url}" where="$rfa_root" \ |
| 1398 | refspec="$RFA_REFSPEC" clone_repo &>>"$build_log" |
| 1399 | show_head "$rfa_root" |
| 1400 | fi |
| 1401 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1402 | if [ "$tftf_config" ] && assert_can_git_clone "tftf_root"; then |
| 1403 | # If the Trusted Firmware TF repository has already been checked out, |
| 1404 | # use that location. Otherwise, clone one ourselves. |
| 1405 | echo "Cloning Trusted Firmware TF..." |
| 1406 | clone_url="${TFTF_CHECKOUT_LOC:-$tftf_src_repo_url}" where="$tftf_root" \ |
| 1407 | refspec="$TFTF_REFSPEC" clone_repo &>>"$build_log" |
| 1408 | show_head "$tftf_root" |
| 1409 | fi |
| 1410 | |
| 1411 | if [ "$scp_config" ] && assert_can_git_clone "scp_root"; then |
| 1412 | # If the SCP firmware repository has already been checked out, |
| 1413 | # use that location. Otherwise, clone one ourselves. |
| 1414 | echo "Cloning SCP Firmware..." |
| 1415 | clone_url="${SCP_CHECKOUT_LOC:-$scp_src_repo_url}" where="$scp_root" \ |
| 1416 | refspec="${SCP_REFSPEC-master-upstream}" clone_repo &>>"$build_log" |
| 1417 | |
| 1418 | pushd "$scp_root" |
| 1419 | |
| 1420 | # Use filer submodule as a reference if it exists |
Girish Pathak | 31b824e | 2021-03-03 20:58:21 +0000 | [diff] [blame] | 1421 | if [ -d "$SCP_CHECKOUT_LOC/cmsis" ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1422 | cmsis_reference="--reference $SCP_CHECKOUT_LOC/cmsis" |
| 1423 | fi |
| 1424 | |
| 1425 | # If we don't have a reference yet, fall back to $cmsis_root if set, or |
| 1426 | # then to project filer if accessible. |
| 1427 | if [ -z "$cmsis_reference" ]; then |
| 1428 | cmsis_ref_repo="${cmsis_root:-$project_filer/ref-repos/cmsis}" |
| 1429 | if [ -d "$cmsis_ref_repo" ]; then |
| 1430 | cmsis_reference="--reference $cmsis_ref_repo" |
| 1431 | fi |
| 1432 | fi |
| 1433 | |
| 1434 | git submodule -q update $cmsis_reference --init |
| 1435 | |
| 1436 | popd |
| 1437 | |
| 1438 | show_head "$scp_root" |
| 1439 | fi |
| 1440 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1441 | if [ -n "$cc_config" ] ; then |
| 1442 | if [ "$cc_config" -eq 1 ] && assert_can_git_clone "cc_root"; then |
| 1443 | # Copy code coverage repository |
| 1444 | echo "Cloning Code Coverage..." |
| 1445 | git clone -q $cc_src_repo_url cc_plugin --depth 1 -b $cc_src_repo_tag > /dev/null |
| 1446 | show_head "$cc_root" |
| 1447 | fi |
| 1448 | fi |
| 1449 | |
Daniel Boulby | 25385ab | 2023-12-14 14:36:25 +0000 | [diff] [blame] | 1450 | if [ "$spm_config" ] ; then |
| 1451 | if assert_can_git_clone "spm_root"; then |
| 1452 | # If the SPM repository has already been checked out, use |
| 1453 | # that location. Otherwise, clone one ourselves. |
| 1454 | echo "Cloning SPM..." |
| 1455 | clone_url="${SPM_CHECKOUT_LOC:-$spm_src_repo_url}" \ |
| 1456 | where="$spm_root" refspec="$SPM_REFSPEC" \ |
| 1457 | clone_repo &>>"$build_log" |
| 1458 | fi |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1459 | |
| 1460 | # Query git submodules |
| 1461 | pushd "$spm_root" |
Daniel Boulby | 25385ab | 2023-12-14 14:36:25 +0000 | [diff] [blame] | 1462 | # Check if submodules need initialising |
Paul Sokolovsky | ad27442 | 2024-09-01 10:27:56 +0300 | [diff] [blame] | 1463 | |
| 1464 | # This handling is needed to reliably fetch submodules |
| 1465 | # in CI environment. |
| 1466 | for subm in $(git submodule status | awk '/^-/ {print $2}'); do |
| 1467 | for i in $(seq 1 7); do |
| 1468 | git submodule init $subm |
| 1469 | if git submodule update $subm; then |
| 1470 | break |
| 1471 | fi |
| 1472 | git submodule deinit --force $subm |
| 1473 | echo "Retrying $subm" |
| 1474 | sleep $((RANDOM % 10 + 5)) |
| 1475 | done |
| 1476 | done |
| 1477 | |
| 1478 | git submodule status |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1479 | popd |
| 1480 | |
| 1481 | show_head "$spm_root" |
| 1482 | fi |
| 1483 | |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1484 | if [ "$rmm_config" ] && assert_can_git_clone "rmm_root"; then |
Manish V Badarkhe | 4190945 | 2025-04-11 12:06:45 +0100 | [diff] [blame] | 1485 | # If the RMM repository has already been checked out, |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1486 | # use that location. Otherwise, clone one ourselves. |
| 1487 | echo "Cloning TF-RMM..." |
| 1488 | clone_url="${RMM_CHECKOUT_LOC:-$rmm_src_repo_url}" where="$rmm_root" \ |
| 1489 | refspec="$RMM_REFSPEC" clone_repo &>>"$build_log" |
| 1490 | show_head "$rmm_root" |
| 1491 | fi |
| 1492 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1493 | if [ "$run_config" ]; then |
| 1494 | # Get candidates for run config |
Nicola Mazzucato | 7fc5abd | 2024-02-23 21:32:48 +0000 | [diff] [blame] | 1495 | run_config_candidates="$("$ci_root/script/gen_run_config_candidates.py" \ |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1496 | "$run_config")" |
Nicola Mazzucato | 7fc5abd | 2024-02-23 21:32:48 +0000 | [diff] [blame] | 1497 | if [ -z "$run_config_candidates" ]; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1498 | die "No run config candidates!" |
| 1499 | else |
| 1500 | echo |
| 1501 | echo "Chosen fragments:" |
| 1502 | echo |
Nicola Mazzucato | 7fc5abd | 2024-02-23 21:32:48 +0000 | [diff] [blame] | 1503 | echo "$run_config_candidates" | sed 's/^\|\n/\t/g' |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1504 | echo |
Harrison Mutai | 4dfe119 | 2024-07-03 12:35:38 +0000 | [diff] [blame] | 1505 | |
| 1506 | if [ ! -n "$bin_mode" ]; then |
| 1507 | if echo $run_config_candidates | grep -wq "debug"; then |
| 1508 | bin_mode="debug" |
| 1509 | else |
| 1510 | bin_mode="release" |
| 1511 | fi |
| 1512 | fi |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1513 | fi |
| 1514 | fi |
| 1515 | |
| 1516 | call_hook "test_setup" |
| 1517 | echo |
| 1518 | |
| 1519 | if upon "$local_ci"; then |
| 1520 | # For local runs, since each config is tried in sequence, it's |
| 1521 | # advantageous to run jobs in parallel |
| 1522 | if [ "$make_j" ]; then |
| 1523 | make_j_opts="-j $make_j" |
| 1524 | else |
| 1525 | n_cores="$(getconf _NPROCESSORS_ONLN)" 2>/dev/null || true |
| 1526 | if [ "$n_cores" ]; then |
| 1527 | make_j_opts="-j $n_cores" |
| 1528 | fi |
| 1529 | fi |
| 1530 | fi |
| 1531 | |
Harrison Mutai | 07043e9 | 2023-07-06 09:41:12 +0100 | [diff] [blame] | 1532 | # Install python build dependencies |
| 1533 | if is_arm_jenkins_env; then |
| 1534 | source "$ci_root/script/install_python_deps.sh" |
| 1535 | fi |
| 1536 | |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1537 | # Print CMake version |
| 1538 | cmake_ver=$(echo `cmake --version | sed -n '1p'`) |
| 1539 | echo "Using $cmake_ver" |
| 1540 | |
| 1541 | # Check for Ninja |
| 1542 | if [ -x "$(command -v ninja)" ]; then |
| 1543 | # Print Ninja version |
| 1544 | ninja_ver=$(echo `ninja --version | sed -n '1p'`) |
| 1545 | echo "Using ninja $ninja_ver" |
| 1546 | export cmake_gen="-G Ninja" |
| 1547 | else |
| 1548 | echo 'Ninja is not installed' |
| 1549 | export cmake_gen="" |
| 1550 | fi |
| 1551 | |
| 1552 | undo_rmm_patches() { |
| 1553 | pushd "$rmm_root" |
| 1554 | patch_record="$rmm_patch_record" undo_patch_record |
| 1555 | popd |
| 1556 | } |
| 1557 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1558 | modes="${bin_mode:-debug release}" |
| 1559 | for mode in $modes; do |
Paul Sokolovsky | e9962cd | 2021-12-17 18:39:40 +0300 | [diff] [blame] | 1560 | echo "===== Building package in mode: $mode =====" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1561 | # Build with a temporary archive |
| 1562 | build_archive="$archive/$mode" |
| 1563 | mkdir "$build_archive" |
| 1564 | |
| 1565 | if [ "$mode" = "debug" ]; then |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1566 | export bin_mode="debug" |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1567 | cmake_build_type="Debug" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1568 | DEBUG=1 |
| 1569 | else |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1570 | export bin_mode="release" |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1571 | cmake_build_type="Release" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1572 | DEBUG=0 |
| 1573 | fi |
| 1574 | |
| 1575 | # Perform builds in a subshell so as not to pollute the current and |
| 1576 | # subsequent builds' environment |
| 1577 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1578 | if config_valid "$cc_config"; then |
| 1579 | # Build code coverage plugin |
| 1580 | build_cc |
| 1581 | fi |
| 1582 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1583 | # SCP build |
| 1584 | if config_valid "$scp_config"; then |
| 1585 | ( |
| 1586 | echo "##########" |
| 1587 | |
| 1588 | # Source platform-specific utilities |
| 1589 | plat="$(get_scp_opt PRODUCT)" |
| 1590 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1591 | if [ -f "$plat_utils" ]; then |
| 1592 | source "$plat_utils" |
| 1593 | fi |
| 1594 | |
| 1595 | archive="$build_archive" |
| 1596 | scp_build_root="$scp_root/build" |
| 1597 | |
| 1598 | echo "Building SCP Firmware ($mode) ..." |& log_separator |
| 1599 | |
| 1600 | build_scp |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1601 | to="$archive" collect_scp_artefacts |
| 1602 | |
| 1603 | echo "##########" |
| 1604 | echo |
| 1605 | ) |
| 1606 | fi |
| 1607 | |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1608 | # SCP-tools build |
| 1609 | if config_valid "$scp_tools_config"; then |
| 1610 | ( |
| 1611 | echo "##########" |
| 1612 | |
| 1613 | archive="$build_archive" |
| 1614 | scp_tools_build_root="$scp_tools_root/build" |
| 1615 | |
| 1616 | clone_scp_tools |
| 1617 | |
| 1618 | echo "##########" |
| 1619 | echo |
| 1620 | |
| 1621 | echo "##########" |
| 1622 | clone_tf_for_scp_tools |
| 1623 | echo "##########" |
| 1624 | echo |
| 1625 | ) |
| 1626 | fi |
| 1627 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1628 | # TFTF build |
| 1629 | if config_valid "$tftf_config"; then |
| 1630 | ( |
| 1631 | echo "##########" |
| 1632 | |
Manish V Badarkhe | 3bd3fea | 2020-11-08 15:17:00 +0000 | [diff] [blame] | 1633 | plat_utils="$(get_tf_opt PLAT_UTILS)" |
| 1634 | if [ -z ${plat_utils} ]; then |
| 1635 | # Source platform-specific utilities. |
| 1636 | plat="$(get_tftf_opt PLAT)" |
| 1637 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1638 | else |
| 1639 | # Source platform-specific utilities by |
| 1640 | # using plat_utils name. |
| 1641 | plat_utils="$ci_root/${plat_utils}.sh" |
| 1642 | fi |
| 1643 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1644 | if [ -f "$plat_utils" ]; then |
| 1645 | source "$plat_utils" |
| 1646 | fi |
| 1647 | |
| 1648 | archive="$build_archive" |
| 1649 | tftf_build_root="$tftf_root/build" |
| 1650 | |
| 1651 | echo "Building Trusted Firmware TF ($mode) ..." |& log_separator |
| 1652 | |
| 1653 | # Call pre-build hook |
| 1654 | call_hook pre_tftf_build |
| 1655 | |
| 1656 | build_tftf |
| 1657 | |
| 1658 | from="$tftf_build_root" to="$archive" collect_build_artefacts |
| 1659 | |
| 1660 | # Clear any local changes made by applied patches |
| 1661 | undo_tftf_patches |
| 1662 | |
| 1663 | echo "##########" |
| 1664 | echo |
| 1665 | ) |
| 1666 | fi |
| 1667 | |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1668 | # SPM build |
| 1669 | if config_valid "$spm_config"; then |
| 1670 | ( |
| 1671 | echo "##########" |
| 1672 | |
| 1673 | # Get platform name from spm_config file |
| 1674 | plat="$(echo "$spm_config" | awk -F- '{print $1}')" |
| 1675 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1676 | if [ -f "$plat_utils" ]; then |
| 1677 | source "$plat_utils" |
| 1678 | fi |
| 1679 | |
Daniel Boulby | b8d2a46 | 2022-03-07 13:55:25 +0000 | [diff] [blame] | 1680 | # Call pre-build hook |
| 1681 | call_hook pre_spm_build |
| 1682 | |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 1683 | # SPM build generates two sets of binaries, one for normal and other |
| 1684 | # for Secure world. We need both set of binaries for CI. |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1685 | archive="$build_archive" |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 1686 | spm_build_root="$spm_root/out/reference/$spm_secure_out_dir" |
| 1687 | hafnium_build_root="$spm_root/out/reference/$spm_non_secure_out_dir" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1688 | |
Daniel Boulby | b8d2a46 | 2022-03-07 13:55:25 +0000 | [diff] [blame] | 1689 | echo "spm_build_root is $spm_build_root" |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1690 | echo "Building SPM ($mode) ..." |& log_separator |
| 1691 | |
| 1692 | # NOTE: mode has no effect on SPM build (for now), hence debug |
| 1693 | # mode is built but subsequent build using release mode just |
| 1694 | # goes through with "nothing to do". |
| 1695 | build_spm |
| 1696 | |
| 1697 | # Show SPM/Hafnium binary details |
Madhukar Pappireddy | c683cf6 | 2021-11-01 14:38:32 -0500 | [diff] [blame] | 1698 | cksum $spm_build_root/hafnium.bin |
| 1699 | |
| 1700 | # Some platforms only have secure configuration enabled. Hence, |
| 1701 | # non secure hanfnium binary might not be built. |
| 1702 | if [ -f $hafnium_build_root/hafnium.bin ]; then |
| 1703 | cksum $hafnium_build_root/hafnium.bin |
| 1704 | fi |
Olivier Deprez | 0a9a348 | 2019-12-16 14:10:31 +0100 | [diff] [blame] | 1705 | |
Manish Pandey | 1e7be85 | 2020-11-09 16:04:48 +0000 | [diff] [blame] | 1706 | 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] | 1707 | |
| 1708 | echo "##########" |
| 1709 | echo |
| 1710 | ) |
| 1711 | fi |
| 1712 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1713 | # TF RMM build |
| 1714 | if config_valid "$rmm_config"; then |
| 1715 | ( |
| 1716 | echo "##########" |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1717 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1718 | plat_utils="$(get_rmm_opt PLAT_UTILS)" |
| 1719 | if [ -z ${plat_utils} ]; then |
| 1720 | # Source platform-specific utilities. |
| 1721 | plat="$(get_rmm_opt PLAT)" |
| 1722 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1723 | else |
| 1724 | # Source platform-specific utilities by |
| 1725 | # using plat_utils name. |
| 1726 | plat_utils="$ci_root/${plat_utils}.sh" |
| 1727 | fi |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1728 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1729 | if [ -f "$plat_utils" ]; then |
| 1730 | source "$plat_utils" |
| 1731 | fi |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1732 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1733 | archive="$build_archive" |
| 1734 | rmm_build_root="$rmm_root/build" |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1735 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1736 | echo "Building Trusted Firmware RMM ($mode) ..." |& log_separator |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1737 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1738 | #call_hook pre_rmm_build |
| 1739 | build_rmm |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1740 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1741 | # Collect all rmm.* files: rmm.img, rmm.elf, rmm.dump, rmm.map |
| 1742 | from="$rmm_build_root" to="$archive" collect_build_artefacts |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1743 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1744 | # Clear any local changes made by applied patches |
| 1745 | undo_rmm_patches |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1746 | |
Tomás González | 0393e80 | 2025-07-22 11:06:41 +0100 | [diff] [blame] | 1747 | echo "##########" |
| 1748 | ) |
| 1749 | fi |
Manish V Badarkhe | d62aa5f | 2025-03-18 21:18:14 +0000 | [diff] [blame] | 1750 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1751 | # RF-A build |
| 1752 | if config_valid "$rfa_config"; then |
| 1753 | ( |
| 1754 | echo "##########" |
| 1755 | |
| 1756 | plat="$(get_rfa_opt PLAT)" |
| 1757 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1758 | if [ -f "$plat_utils" ]; then |
| 1759 | source "$plat_utils" |
| 1760 | fi |
| 1761 | |
| 1762 | fvp_tsram_size="$(get_rfa_opt FVP_TRUSTED_SRAM_SIZE)" |
| 1763 | fvp_tsram_size="${fvp_tsram_size:-256}" |
| 1764 | |
| 1765 | archive="$build_archive" |
| 1766 | |
| 1767 | # Clone TF-A repo if required. Save its path into the |
| 1768 | # special variable "TFA", which is used by RF-A build |
| 1769 | # system. |
| 1770 | export TFA="${TFA:-$tf_root}" |
| 1771 | if assert_can_git_clone "TFA"; then |
| 1772 | echo "Cloning TF-A..." |
| 1773 | clone_url="$tf_src_repo_url" where="$TFA" clone_repo |
| 1774 | fi |
| 1775 | show_head "$TFA" |
| 1776 | poetry -C "$TFA" install --without docs |
| 1777 | |
| 1778 | rfa_build_root="$rfa_root/target" |
| 1779 | echo "Building Rusted Firmware ($mode) ..." |& log_separator |
| 1780 | |
| 1781 | if not_upon "$local_ci"; then |
| 1782 | # In the CI Dockerfile, rustup is installed by the root user in the |
| 1783 | # non-default location /usr/local/rustup, so $RUSTUP_HOME is required to |
| 1784 | # access rust config e.g. default toolchains and run cargo |
| 1785 | # |
| 1786 | # Leave $CARGO_HOME blank so when this script is run in CI by the buildslave |
| 1787 | # user, it uses the default /home/buildslave/.cargo directory which it has |
| 1788 | # write permissions for - that allows it to download new crates during |
| 1789 | # compilation |
| 1790 | # |
| 1791 | # The buildslave user does not have write permissions to the default |
| 1792 | # $CARGO_HOME=/usr/local/cargo dir and so will error when trying to download |
| 1793 | # new crates otherwise |
| 1794 | # |
| 1795 | # note: $PATH still contains /usr/local/cargo/bin at this point so cargo is |
| 1796 | # still run via the root installation |
| 1797 | # |
| 1798 | # see https://github.com/rust-lang/rustup/issues/1085 |
| 1799 | set_hook_var "RUSTUP_HOME" "/usr/local/rustup" |
| 1800 | fi |
| 1801 | |
| 1802 | # Call pre-build hook |
| 1803 | call_hook pre_rfa_build |
| 1804 | |
| 1805 | build_rfa |
| 1806 | |
| 1807 | # Call post-build hook |
| 1808 | call_hook post_rfa_build |
| 1809 | |
| 1810 | # Pre-archive hook |
| 1811 | call_hook pre_rfa_archive |
| 1812 | |
| 1813 | from="$rfa_build_root" to="$archive" collect_rfa_artefacts |
| 1814 | |
| 1815 | # Post-archive hook |
| 1816 | call_hook post_rfa_archive |
| 1817 | |
| 1818 | call_hook fetch_rfa_resource |
| 1819 | call_hook post_fetch_rfa_resource |
| 1820 | |
| 1821 | # Generate LAVA job files if necessary |
| 1822 | call_hook generate_lava_job_template |
| 1823 | call_hook generate_lava_job |
| 1824 | |
| 1825 | echo "##########" |
| 1826 | ) |
| 1827 | fi |
| 1828 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1829 | # TF build |
| 1830 | if config_valid "$tf_config"; then |
| 1831 | ( |
| 1832 | echo "##########" |
| 1833 | |
Manish V Badarkhe | 3bd3fea | 2020-11-08 15:17:00 +0000 | [diff] [blame] | 1834 | plat_utils="$(get_tf_opt PLAT_UTILS)" |
Madhukar Pappireddy | 2f284e1 | 2021-08-30 16:06:14 -0500 | [diff] [blame] | 1835 | export plat_variant="$(get_tf_opt TARGET_PLATFORM)" |
| 1836 | |
Manish V Badarkhe | 3bd3fea | 2020-11-08 15:17:00 +0000 | [diff] [blame] | 1837 | if [ -z ${plat_utils} ]; then |
| 1838 | # Source platform-specific utilities. |
| 1839 | plat="$(get_tf_opt PLAT)" |
| 1840 | plat_utils="$ci_root/${plat}_utils.sh" |
| 1841 | else |
| 1842 | # Source platform-specific utilities by |
| 1843 | # using plat_utils name. |
| 1844 | plat_utils="$ci_root/${plat_utils}.sh" |
| 1845 | fi |
| 1846 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1847 | if [ -f "$plat_utils" ]; then |
| 1848 | source "$plat_utils" |
| 1849 | fi |
| 1850 | |
Chris Kay | e5a486b | 2023-08-04 11:50:31 +0000 | [diff] [blame] | 1851 | fvp_tsram_size="$(get_tf_opt FVP_TRUSTED_SRAM_SIZE)" |
| 1852 | fvp_tsram_size="${fvp_tsram_size:-256}" |
| 1853 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1854 | poetry -C "$tf_root" install --without docs |
Chris Kay | d083790 | 2021-11-17 10:17:52 +0000 | [diff] [blame] | 1855 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1856 | archive="$build_archive" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1857 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1858 | tf_build_root="$tf_root/build" |
| 1859 | echo "Building Trusted Firmware ($mode) ..." |& log_separator |
Tomás González | e72d538 | 2024-11-13 14:08:25 +0000 | [diff] [blame] | 1860 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1861 | # Call pre-build hook |
| 1862 | call_hook pre_tf_build |
| 1863 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1864 | build_tf |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1865 | |
| 1866 | # Call post-build hook |
| 1867 | call_hook post_tf_build |
| 1868 | |
| 1869 | # Pre-archive hook |
| 1870 | call_hook pre_tf_archive |
| 1871 | |
Tomás González | 866b23a | 2025-07-22 11:05:57 +0100 | [diff] [blame] | 1872 | from="$tf_build_root" to="$archive" collect_build_artefacts |
Zachary Leaf | 5494d73 | 2024-10-22 10:49:36 +0100 | [diff] [blame] | 1873 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1874 | # Post-archive hook |
| 1875 | call_hook post_tf_archive |
| 1876 | |
| 1877 | call_hook fetch_tf_resource |
| 1878 | call_hook post_fetch_tf_resource |
| 1879 | |
Chris Kay | 4e8aaf1 | 2022-09-01 15:21:55 +0100 | [diff] [blame] | 1880 | # Generate LAVA job files if necessary |
| 1881 | call_hook generate_lava_job_template |
| 1882 | call_hook generate_lava_job |
| 1883 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1884 | # Clear any local changes made by applied patches |
| 1885 | undo_tf_patches |
| 1886 | |
| 1887 | echo "##########" |
| 1888 | ) |
| 1889 | fi |
| 1890 | |
| 1891 | echo |
| 1892 | echo |
| 1893 | done |
| 1894 | |
| 1895 | call_hook pre_package |
| 1896 | |
| 1897 | call_hook post_package |
| 1898 | |
| 1899 | if upon "$jenkins_run" && upon "$artefacts_receiver" && [ -d "artefacts" ]; then |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 1900 | source "$CI_ROOT/script/send_artefacts.sh" "artefacts" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 1901 | fi |
| 1902 | |
| 1903 | echo |
| 1904 | echo "Done" |