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