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