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