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 | # |
laurenw-arm | 92881b9 | 2024-03-28 12:57:42 -0500 | [diff] [blame] | 3 | # Copyright (c) 2019-2024, Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | # This file is meant to be SOURCED only after setting $ci_root. $ci_root must be |
| 9 | # the absolute path to the root of the CI repository |
| 10 | # |
| 11 | # A convenient way to set ci_root from the calling script like this: |
| 12 | # ci_root="$(readlink -f "$(dirname "$0")/..")" |
| 13 | # |
| 14 | |
Chris Kay | 197b102 | 2023-08-16 21:31:41 +0100 | [diff] [blame] | 15 | set -ETe -o pipefail |
| 16 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 17 | # Accept root of CI location from $CI_ROOT or $ci_root, in that order |
| 18 | ci_root="${ci_root:-$CI_ROOT}" |
| 19 | ci_root="${ci_root:?}" |
| 20 | |
Chris Kay | 197b102 | 2023-08-16 21:31:41 +0100 | [diff] [blame] | 21 | source "${ci_root}/backtrace.sh" && trap backtrace ERR |
Harrison Mutai | 9b09989 | 2023-01-13 11:34:36 +0000 | [diff] [blame] | 22 | source "${ci_root}/lava_utils.sh" |
| 23 | |
Sandrine Bailleux | aaaffe0 | 2020-08-07 11:15:55 +0200 | [diff] [blame] | 24 | # Optionally source a file containing environmental settings. |
| 25 | if [ -n "$host_env" ]; then |
| 26 | source "$host_env" |
| 27 | else |
| 28 | # Are we running on Arm infrastructure? |
Gary Morrison | 999a9d7 | 2022-03-14 18:29:06 -0500 | [diff] [blame] | 29 | if echo "$JENKINS_URL" | grep -q "oss.arm.com"; then |
Sandrine Bailleux | aaaffe0 | 2020-08-07 11:15:55 +0200 | [diff] [blame] | 30 | source "$ci_root/arm-env.sh" |
Chris Kay | 7c542f2 | 2022-11-18 11:42:59 +0000 | [diff] [blame] | 31 | elif echo "$JENKINS_URL" | grep -q "ci.trustedfirmware.org"; then |
Paul Sokolovsky | c90cb77 | 2023-07-31 14:28:41 +0300 | [diff] [blame] | 32 | if echo "$TF_GERRIT_BRANCH" | grep -q "lts-v2.8"; then |
laurenw-arm | 8f595d0 | 2023-07-10 15:05:43 -0500 | [diff] [blame] | 33 | source "$ci_root/openci-lts-v2.8-env.sh" |
laurenw-arm | 92881b9 | 2024-03-28 12:57:42 -0500 | [diff] [blame] | 34 | elif echo "$TF_GERRIT_BRANCH" | grep -q "lts-v2.10"; then |
| 35 | source "$ci_root/openci-lts-v2.10-env.sh" |
laurenw-arm | 8f595d0 | 2023-07-10 15:05:43 -0500 | [diff] [blame] | 36 | else |
| 37 | source "$ci_root/openci-env.sh" |
| 38 | fi |
Chris Kay | 73a91b0 | 2022-12-19 16:56:51 +0000 | [diff] [blame] | 39 | elif echo "$JENKINS_URL" | grep -q "ci.staging.trustedfirmware.org"; then |
| 40 | source "$ci_root/openci-staging-env.sh" |
Sandrine Bailleux | aaaffe0 | 2020-08-07 11:15:55 +0200 | [diff] [blame] | 41 | fi |
| 42 | fi |
| 43 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 44 | # Storage area to host toolchains, rootfs, tools, models, binaries, etc... |
| 45 | nfs_volume="${nfs_volume:-$NFS_VOLUME}" |
| 46 | nfs_volume="${nfs_volume:?}" |
| 47 | |
| 48 | # Override workspace for local runs |
| 49 | workspace="${workspace:-$WORKSPACE}" |
| 50 | workspace="${workspace:?}" |
| 51 | workspace="$(readlink -f "$workspace")" |
| 52 | artefacts="$workspace/artefacts" |
| 53 | |
| 54 | # pushd and popd outputs the directory stack every time, which could be |
| 55 | # confusing when shown on the log. Suppress its output. |
| 56 | pushd() { |
| 57 | builtin pushd "$1" &>/dev/null |
| 58 | } |
| 59 | popd() { |
| 60 | builtin popd &>/dev/null |
| 61 | } |
| 62 | |
| 63 | # Copy a file to the $archive directory |
| 64 | archive_file() { |
| 65 | local f out target md5 |
| 66 | f="${1:?}" |
| 67 | |
| 68 | out="${archive:?}" |
| 69 | [ ! -d "$out" ] && die "$out is not a directory" |
| 70 | |
| 71 | target="$out/$(basename $f)" |
| 72 | if [ -f "$target" ]; then |
| 73 | # Prevent same file error |
| 74 | if [ "$(stat --format=%i "$target")" = \ |
| 75 | "$(stat --format=%i "$f")" ]; then |
| 76 | return |
| 77 | fi |
| 78 | fi |
| 79 | |
| 80 | md5="$(md5sum "$f" | awk '{print $1}')" |
| 81 | cp -t "$out" "$f" |
| 82 | echo "Archived: $f (md5: $md5)" |
| 83 | } |
| 84 | |
| 85 | die() { |
| 86 | [ "$1" ] && echo "$1" >&2 |
| 87 | exit 1 |
| 88 | } |
| 89 | |
| 90 | # Emit environment variables for the purpose of sourcing from shells and as |
| 91 | # Jenkins property files. Whether the RHS is quoted depends on "$quote". |
| 92 | emit_env() { |
| 93 | local env_file="${env_file:?}" |
| 94 | local var="${1:?}" |
| 95 | |
| 96 | # Value parameter is mandatory, but allow for it to be empty |
| 97 | local val="${2?}" |
| 98 | |
| 99 | if upon "$quote"; then |
| 100 | val="\"$val\"" |
| 101 | else |
| 102 | # If RHS is not required to be quoted, any white space in it |
| 103 | # won't go well with a shell sourcing this file. |
| 104 | if echo "$var" | grep -q '\s'; then |
| 105 | die "$var: value '$val' has white space" |
| 106 | fi |
| 107 | fi |
| 108 | |
| 109 | echo "$var=$val" >> "$env_file" |
| 110 | } |
| 111 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 112 | fetch_directory() { |
| 113 | local base="$(basename "${url:?}")" |
| 114 | local sa |
| 115 | |
Fathi Boudra | dd31e7b | 2020-01-29 15:44:42 +0200 | [diff] [blame] | 116 | case "${url}" in |
| 117 | http*://*) |
| 118 | # Have exactly one trailing / |
| 119 | local modified_url="$(echo "${url}" | sed 's#/*$##')/" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 120 | |
Fathi Boudra | dd31e7b | 2020-01-29 15:44:42 +0200 | [diff] [blame] | 121 | # Figure out the number of components between hostname and the |
| 122 | # final one |
| 123 | local cut_dirs="$(echo "$modified_url" | awk -F/ '{print NF - 5}')" |
| 124 | sa="${saveas:-$base}" |
| 125 | echo "Fetch: $modified_url -> $sa" |
laurenw-arm | 2d62c71 | 2022-09-13 14:27:15 -0500 | [diff] [blame] | 126 | wget -rq -nH --cut-dirs="$cut_dirs" --no-parent -e robots=off \ |
Fathi Boudra | dd31e7b | 2020-01-29 15:44:42 +0200 | [diff] [blame] | 127 | --reject="index.html*" "$modified_url" |
| 128 | if [ "$sa" != "$base" ]; then |
| 129 | mv "$base" "$sa" |
| 130 | fi |
| 131 | ;; |
| 132 | file://*) |
| 133 | sa="${saveas:-.}" |
| 134 | echo "Fetch: ${url} -> $sa" |
| 135 | cp -r "${url#file://}" "$sa" |
| 136 | ;; |
| 137 | *) |
| 138 | sa="${saveas:-.}" |
| 139 | echo "Fetch: ${url} -> $sa" |
| 140 | cp -r "${url}" "$sa" |
| 141 | ;; |
| 142 | esac |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | fetch_file() { |
| 146 | local url="${url:?}" |
| 147 | local sa |
| 148 | local saveas |
| 149 | |
| 150 | if is_url "$url"; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 151 | saveas="${saveas-"$(basename "$url")"}" |
Sandrine Bailleux | 3da4bd1 | 2020-08-06 16:18:36 +0200 | [diff] [blame] | 152 | sa="${saveas+-o $saveas}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 153 | echo "Fetch: $url -> $saveas" |
| 154 | # Use curl to support file protocol |
Paul Sokolovsky | 532a488 | 2023-05-22 15:50:04 +0300 | [diff] [blame] | 155 | curl --fail --no-progress-meter --connect-timeout 10 --retry 6 -LS $sa "$url" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 156 | else |
| 157 | sa="${saveas-.}" |
| 158 | echo "Fetch: $url -> $sa" |
| 159 | cp "$url" "$sa" |
| 160 | fi |
| 161 | } |
| 162 | |
Harrison Mutai | a197d5d | 2022-09-15 13:45:21 +0100 | [diff] [blame] | 163 | fetch_and_archive() { |
| 164 | url=${url:?} |
| 165 | filename=${filename:-basename $url} |
| 166 | |
| 167 | url="$url" saveas="$filename" fetch_file |
| 168 | archive_file "$filename" |
| 169 | } |
| 170 | |
| 171 | filter_artefacts(){ |
| 172 | local model_param_file="${model_param_file-$archive/model_params}" |
| 173 | |
| 174 | # Bash doesn't have array values, we have to create references to the |
| 175 | # array of artefacts and the artefact filters. |
| 176 | declare -ga "$1" |
| 177 | declare -n artefacts="$1" |
| 178 | declare -n filters="$2" |
| 179 | |
| 180 | for artefact in "${!filters[@]}"; do |
| 181 | if grep -E -q "${filters[${artefact}]}" "$model_param_file"; then |
| 182 | artefacts+=("${artefact}") |
| 183 | fi |
| 184 | done |
| 185 | } |
| 186 | |
Harrison Mutai | a197d5d | 2022-09-15 13:45:21 +0100 | [diff] [blame] | 187 | # Generate link to an archived binary. |
| 188 | gen_bin_url() { |
| 189 | local bin_mode="${bin_mode:?}" |
| 190 | local bin="${1:?}" |
| 191 | |
| 192 | if upon "$jenkins_run"; then |
| 193 | echo "$jenkins_url/job/$JOB_NAME/$BUILD_NUMBER/artifact/artefacts/$bin_mode/$bin" |
| 194 | else |
| 195 | echo "file://$workspace/artefacts/$bin_mode/$bin" |
| 196 | fi |
| 197 | } |
| 198 | |
Harrison Mutai | d993ce1 | 2023-03-27 13:21:28 +0100 | [diff] [blame] | 199 | get_boot_image() { |
| 200 | local image=${image:?} |
| 201 | local type=${type:?} |
Harrison Mutai | a197d5d | 2022-09-15 13:45:21 +0100 | [diff] [blame] | 202 | |
Harrison Mutai | d993ce1 | 2023-03-27 13:21:28 +0100 | [diff] [blame] | 203 | declare -n image_list=${image_list-${image}_list} |
| 204 | |
| 205 | local url="${image_list[${type}]}" |
| 206 | |
| 207 | url="${url:?}" filename="${image}.bin" fetch_and_archive |
Harrison Mutai | a197d5d | 2022-09-15 13:45:21 +0100 | [diff] [blame] | 208 | } |
| 209 | |
Harrison Mutai | d993ce1 | 2023-03-27 13:21:28 +0100 | [diff] [blame] | 210 | get_boot_image_from_fip() {( |
| 211 | local url="${url:?}" |
| 212 | local image="${image:?}" |
| 213 | local output_name="${output_name-bl32.bin}" |
| 214 | |
| 215 | cd "$(mktempdir)" |
| 216 | |
| 217 | extract_fip "$url" |
| 218 | mv "$image" "$output_name" |
| 219 | archive_file "$output_name" |
| 220 | )} |
| 221 | |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 222 | # Get the path to the run environment variables file. |
| 223 | # |
| 224 | # Run environment variables are the test-specific environment variables |
| 225 | #Â configured by the CI's test configuration. |
| 226 | # |
| 227 | # Usage: get_run_env_path <archive> |
| 228 | get_run_env_path() { |
| 229 | echo "${1:?}/run/env" |
| 230 | } |
| 231 | |
| 232 | # Get a run environment variable. |
| 233 | # |
| 234 | # Run environment variables are the test-specific environment variables |
| 235 | #Â configured by the CI's test configuration. |
| 236 | # |
| 237 | # Usage: get_run_env <archive> <variable> [default] |
| 238 | get_run_env() { |
| 239 | if [ -f "$(get_run_env_path "${1:?}")" ] && [ ! -v "${2:?}" ]; then |
| 240 | . "$(get_run_env_path "${1:?}")" |
| 241 | fi |
| 242 | |
| 243 | echo "${!2:-${3}}" |
| 244 | } |
| 245 | |
| 246 | # Get the number of UARTs configured by the current test configuration. This |
| 247 | # defaults to `4`. |
| 248 | # |
| 249 | # Usage: get_num_uarts <archive> [default] |
| 250 | get_num_uarts() { |
| 251 | local default=4 |
| 252 | |
| 253 | get_run_env "${1:?}" num_uarts "${2-${default}}" |
| 254 | } |
| 255 | |
| 256 | #Â Get the ports script configured by the current test configuration. This |
| 257 | # defaults to `script/default-ports-script.awk`. |
| 258 | # |
| 259 | # Usage: get_ports_script <archive> [default] |
| 260 | get_ports_script() { |
| 261 | local default="${ci_root}/script/default-ports-script.awk" |
| 262 | |
| 263 | get_run_env "${1:?}" ports_script "${2-${default}}" |
| 264 | } |
| 265 | |
| 266 | #Â Get the primary UART configured by the current test configuration. This |
| 267 | #Â defaults to `0`. |
| 268 | # |
| 269 | # Usage: get_primary_uart <archive> [default] |
| 270 | get_primary_uart() { |
| 271 | local default=0 |
| 272 | |
| 273 | get_run_env "${1:?}" primary_uart "${2-${default}}" |
| 274 | } |
| 275 | |
| 276 | #Â Get the payload UART configured by the current test configuration. This |
| 277 | #Â defaults to the primary UART. |
| 278 | # |
| 279 | # Usage: get_payload_uart <archive> [default] |
| 280 | get_payload_uart() { |
| 281 | local default="$(get_primary_uart "${1:?}")" |
| 282 | |
| 283 | get_run_env "${1:?}" payload_uart "${2-${default}}" |
| 284 | } |
| 285 | |
| 286 | # Get the path to a UART's environment variable directory. |
| 287 | # |
| 288 | # UART environment variables are the UART-specific environment variables |
| 289 | #Â configured by the CI's test configuration. |
| 290 | # |
| 291 | # Usage: get_uart_env_path <archive> <uart> |
| 292 | get_uart_env_path() { |
| 293 | echo "${1:?}/run/uart${2:?}" |
| 294 | } |
| 295 | |
| 296 | # Get a UART environment variable. |
| 297 | # |
| 298 | # UART environment variables are the UART-specific environment variables |
| 299 | #Â configured by the CI's test configuration. |
| 300 | # |
| 301 | # Usage: get_uart_env <archive> <uart> <variable> [default] |
| 302 | get_uart_env() { |
| 303 | if [ ! -v "${3:?}" ] && [ -f "$(get_uart_env_path "${1:?}" "${2:?}")/${3:?}" ]; then |
| 304 | cat "$(get_uart_env_path "${1:?}" "${2:?}")/${3:?}" |
| 305 | else |
Chris Kay | fab6edc | 2022-11-17 19:18:32 +0000 | [diff] [blame] | 306 | echo "${!3-${4}}" |
Chris Kay | 03ffbe7 | 2022-11-17 18:53:50 +0000 | [diff] [blame] | 307 | fi |
| 308 | } |
| 309 | |
| 310 | # Get the path to the Expect script for a given UART. This defaults to nothing. |
| 311 | # |
| 312 | # Usage: get_uart_expect_script <archive> <uart> [default] |
| 313 | get_uart_expect_script() { |
| 314 | local default= |
| 315 | |
| 316 | get_uart_env "${1:?}" "${2:?}" expect "${3-${default}}" |
| 317 | } |
| 318 | |
| 319 | # Get the FVP port for a given UART. This defaults to `5000 + ${uart}`. |
| 320 | # |
| 321 | # Usage: get_uart_port <archive> <uart> [default] |
| 322 | get_uart_port() { |
| 323 | local default="$(( 5000 + "${2:?}" ))" |
| 324 | |
| 325 | get_uart_env "${1:?}" "${2:?}" port "${3-${default}}" |
| 326 | } |
| 327 | |
Chris Kay | 24d039f | 2022-11-23 12:53:30 +0000 | [diff] [blame] | 328 | # Set a UART environment variable. |
| 329 | # |
| 330 | # UART environment variables are the UART-specific environment variables |
| 331 | #Â configured by the CI's test configuration. |
| 332 | # |
| 333 | # Usage: set_uart_env <archive> <uart> <variable> <value> |
| 334 | set_uart_env() { |
| 335 | local path="$(get_uart_env_path "${1:?}" "${2:?}")" |
| 336 | |
| 337 | mkdir -p "${path}" && \ |
| 338 | echo "${4:?}" > "${path}/${3:?}" |
| 339 | } |
| 340 | |
| 341 | # Set the FVP port for a given UART. |
| 342 | # |
| 343 | # Usage: set_uart_port <archive> <uart> <port> |
| 344 | set_uart_port() { |
| 345 | set_uart_env "${1:?}" "${2:?}" port "${3:?}" |
| 346 | } |
| 347 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 348 | # Make a temporary directory/file insdie workspace, so that it doesn't need to |
| 349 | # be cleaned up. Jenkins is setup to clean up workspace before a job runs. |
| 350 | mktempdir() { |
| 351 | local ws="${workspace:?}" |
| 352 | |
| 353 | mktemp -d --tmpdir="$ws" |
| 354 | } |
| 355 | mktempfile() { |
| 356 | local ws="${workspace:?}" |
| 357 | |
| 358 | mktemp --tmpdir="$ws" |
| 359 | } |
| 360 | |
| 361 | not_upon() { |
| 362 | ! upon "$1" |
| 363 | } |
| 364 | |
| 365 | # Use "$1" as a boolean |
| 366 | upon() { |
| 367 | case "$1" in |
| 368 | "" | "0" | "false") return 1;; |
| 369 | *) return 0;; |
| 370 | esac |
| 371 | } |
| 372 | |
| 373 | # Check if the argument is a URL |
| 374 | is_url() { |
| 375 | echo "$1" | grep -q "://" |
| 376 | } |
| 377 | |
| 378 | # Check if a path is absolute |
| 379 | is_abs() { |
| 380 | [ "${1:0:1}" = "/" ] |
| 381 | } |
| 382 | |
| 383 | # Unset a variable based on its boolean value |
| 384 | # If foo=, foo will be unset |
| 385 | # If foo=blah, then leave it as is |
| 386 | reset_var() { |
| 387 | local var="$1" |
| 388 | local val="${!var}" |
| 389 | |
| 390 | if [ -z "$val" ]; then |
| 391 | unset "$var" |
| 392 | else |
| 393 | var="$val" |
| 394 | fi |
| 395 | } |
| 396 | |
| 397 | default_var() { |
| 398 | local var="$1" |
| 399 | local val="${!var}" |
| 400 | local default="$2" |
| 401 | |
| 402 | if [ -z "$val" ]; then |
| 403 | eval "$var=$default" |
| 404 | fi |
| 405 | } |
| 406 | |
| 407 | # String various items joined by ":" to form a path. Items are prepended by |
| 408 | # default; or 'op' can be set to 'append' to have them appended. |
| 409 | # For example, to set: PATH=foo:bar:baz:$PATH |
| 410 | extend_path() { |
| 411 | local path_var="$1" |
| 412 | local array_var="$2" |
Leonardo Sandoval | 2af9320 | 2020-07-16 17:29:18 -0500 | [diff] [blame] | 413 | local path_val="${!path_var}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 414 | local op="${op:-prepend}" |
Leonardo Sandoval | 2af9320 | 2020-07-16 17:29:18 -0500 | [diff] [blame] | 415 | local sep=':' |
| 416 | local array_val |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 417 | |
Leonardo Sandoval | 2af9320 | 2020-07-16 17:29:18 -0500 | [diff] [blame] | 418 | eval "array_val=\"\${$array_var[@]}\"" |
| 419 | array_val="$(echo ${array_val// /:})" |
| 420 | |
| 421 | [ -z "$path_val" ] && sep='' |
| 422 | |
| 423 | if [ "$op" = "prepend" ]; then |
| 424 | array_val="${array_val}${sep}${path_val}" |
| 425 | elif [ "$op" = "append" ]; then |
| 426 | array_val="${path_val}${sep}${array_val}" |
| 427 | fi |
| 428 | |
| 429 | eval "$path_var=\"$array_val\"" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 430 | } |
| 431 | |
Chris Kay | 3d80788 | 2022-08-31 16:00:02 +0100 | [diff] [blame] | 432 | #Â Expand and evaluate Bash variables and expressions in a file, whose path is |
| 433 | #Â given by the first parameter. |
| 434 | # |
| 435 | # For example, to expand a file containing the following: |
| 436 | # |
| 437 | # My name is ${name}! |
| 438 | # |
| 439 | # You might use: |
| 440 | # |
| 441 | # name="Chris" expand_template "path-to-my-file.txt" |
| 442 | # |
| 443 | # This would yield: |
| 444 | # |
| 445 | # My name is Chris! |
| 446 | # |
| 447 | # If you need to run multiple expansions on a file (e.g. to fill out information |
| 448 | # incrementally), then you can escape expansion of a variable with a backslash, |
| 449 | # e.g. `\${name}`. |
| 450 | # |
| 451 | #Â The expanded output is printed to the standard output stream. |
| 452 | expand_template() { |
| 453 | local path="$1" |
| 454 | |
| 455 | eval "cat <<-EOF |
| 456 | $(<${path}) |
| 457 | EOF" |
| 458 | } |
| 459 | |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 460 | # Fetch and extract the latest supported version of the LLVM toolchain from |
| 461 | # a compressed archive file to a target directory, if it is required. |
| 462 | setup_llvm_toolchain() { |
| 463 | link="${1:-$llvm_archive}" |
| 464 | archive="${2:-"$workspace/llvm.tar.xz"}" |
| 465 | target_dir="${3:-$llvm_dir}" |
| 466 | |
| 467 | if is_arm_jenkins_env || upon "$local_ci"; then |
| 468 | url="$link" saveas="$archive" fetch_file |
| 469 | mkdir -p $target_dir |
| 470 | extract_tarball $archive $target_dir --strip-components=1 -k |
| 471 | fi |
| 472 | } |
| 473 | |
| 474 | # Extract files from compressed archive to target directory. Supports .zip, |
| 475 | # .tar.gz, and tar.xf format |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 476 | extract_tarball() { |
| 477 | local archive="$1" |
| 478 | local target_dir="$2" |
Leonardo Sandoval | ec9e16c | 2020-09-09 14:32:40 -0500 | [diff] [blame] | 479 | local extra_params="${3:-}" |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 480 | |
| 481 | pushd "$target_dir" |
| 482 | case $(file --mime-type -b "$archive") in |
| 483 | application/gzip) |
Leonardo Sandoval | ec9e16c | 2020-09-09 14:32:40 -0500 | [diff] [blame] | 484 | tar -xz $extra_params -f $archive |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 485 | ;; |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 486 | application/zip) |
Leonardo Sandoval | ec9e16c | 2020-09-09 14:32:40 -0500 | [diff] [blame] | 487 | unzip -q $extra_params $archive |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 488 | ;; |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 489 | application/x-xz) |
| 490 | tar -x $extra_params -f $archive |
| 491 | ;; |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 492 | esac |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 493 | popd "$target_dir" |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 494 | } |
| 495 | |
Gary Morrison | 999a9d7 | 2022-03-14 18:29:06 -0500 | [diff] [blame] | 496 | # See if execution is done by Jenkins. If called with a parameter, |
| 497 | # representing a 'domain', e.g. arm.com, it will also check if |
Leonardo Sandoval | 795b621 | 2020-08-14 16:20:00 -0500 | [diff] [blame] | 498 | # JENKINS_URL contains the latter. |
| 499 | is_jenkins_env () { |
| 500 | local domain="${1-}" |
| 501 | |
| 502 | # check if running under Jenkins, if not, return non-zero |
| 503 | # the checks assumes Jenkins executing if JENKINS_HOME is set |
| 504 | [ -z "$JENKINS_HOME" ] && return 1 |
| 505 | |
| 506 | # if no parameter passed, no more checks, quit |
| 507 | [ -z "$domain" ] && return 0 |
| 508 | |
| 509 | if echo "$JENKINS_URL" | grep -q "$domain"; then |
| 510 | return 0 |
| 511 | fi |
| 512 | |
| 513 | return 1 |
| 514 | } |
| 515 | |
| 516 | |
| 517 | # Check if execution is under ARM's jenkins |
| 518 | is_arm_jenkins_env() { |
| 519 | local arm_domain="arm.com" |
| 520 | return $(is_jenkins_env "$arm_domain") |
| 521 | } |
| 522 | |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 523 | |
| 524 | # Provide correct linaro cross toolchain based on environment |
| 525 | set_cross_compile_gcc_linaro_toolchain() { |
| 526 | local cross_compile_path="/home/buildslave/tools" |
| 527 | |
| 528 | # if under arm enviroment, overide cross-compilation path |
Madhukar Pappireddy | 21a5e67 | 2021-03-08 17:49:45 -0600 | [diff] [blame] | 529 | is_arm_jenkins_env || upon "$local_ci" && cross_compile_path="/arm/pdsw/tools" |
Leonardo Sandoval | feae3a2 | 2020-11-17 16:53:59 -0600 | [diff] [blame] | 530 | |
| 531 | echo "${cross_compile_path}/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-" |
| 532 | } |
| 533 | |
Leonardo Sandoval | 795b621 | 2020-08-14 16:20:00 -0500 | [diff] [blame] | 534 | if is_jenkins_env; then |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 535 | jenkins_run=1 |
| 536 | umask 0002 |
| 537 | else |
| 538 | unset jenkins_run |
| 539 | fi |
| 540 | |
| 541 | # Project scratch location for Trusted Firmware CI |
| 542 | project_filer="${nfs_volume}/projectscratch/ssg/trusted-fw" |
| 543 | project_scratch="${PROJECT_SCRATCH:-$project_filer/ci-workspace}" |
| 544 | warehouse="${nfs_volume}/warehouse" |
| 545 | jenkins_url="${JENKINS_URL%/*}" |
| 546 | jenkins_url="${jenkins_url:-https://ci.trustedfirmware.org/}" |
| 547 | |
| 548 | # Model revisions |
Govindraj Raja | 02e14fa | 2024-06-18 13:34:17 -0500 | [diff] [blame] | 549 | model_version_11_24="${model_version:-11.24}" |
| 550 | model_build_11_24="${model_build:-24}" |
| 551 | |
Govindraj Raja | 8962c45 | 2024-06-04 14:50:28 -0500 | [diff] [blame] | 552 | model_version="${model_version:-11.26}" |
| 553 | model_build="${model_build:-11}" |
Maksims Svecovs | 5c54251 | 2022-03-29 10:13:05 +0100 | [diff] [blame] | 554 | model_flavour="${model_flavour:-Linux64_GCC-9.3}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 555 | |
| 556 | # Model snapshots from filer are not normally not accessible from developer |
| 557 | # systems. Ignore failures from picking real path for local runs. |
| 558 | pinned_cortex="$(readlink -f ${pinned_cortex:-$project_filer/models/cortex})" || true |
| 559 | pinned_css="$(readlink -f ${pinned_css:-$project_filer/models/css})" || true |
| 560 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 561 | tforg_gerrit_url="review.trustedfirmware.org" |
| 562 | |
| 563 | # Repository URLs. We're using anonymous HTTP as they appear to be faster rather |
| 564 | # than any scheme with authentication. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 565 | tf_src_repo_url="${tf_src_repo_url:-$TF_SRC_REPO_URL}" |
| 566 | tf_src_repo_url="${tf_src_repo_url:-https://$tforg_gerrit_url/TF-A/trusted-firmware-a}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 567 | tftf_src_repo_url="${tftf_src_repo_url:-$TFTF_SRC_REPO_URL}" |
| 568 | tftf_src_repo_url="${tftf_src_repo_url:-https://$tforg_gerrit_url/TF-A/tf-a-tests}" |
Jimmy Brisson | 29ca0a0 | 2020-09-22 16:15:35 -0500 | [diff] [blame] | 569 | ci_src_repo_url="${ci_src_repo_url:-$CI_SRC_REPO_URL}" |
| 570 | ci_src_repo_url="${ci_src_repo_url:-https://$tforg_gerrit_url/ci/tf-a-ci-scripts}" |
Zelalem | dd65527 | 2020-10-06 16:29:05 -0500 | [diff] [blame] | 571 | tf_ci_repo_url="$ci_src_repo_url" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 572 | scp_src_repo_url="${scp_src_repo_url:-$SCP_SRC_REPO_URL}" |
Girish Pathak | 97f7ad4 | 2020-08-27 11:38:15 +0100 | [diff] [blame] | 573 | scp_src_repo_url="${scp_src_repo_url:-$scp_src_repo_default}" |
Olivier Deprez | 965a779 | 2019-12-16 14:09:03 +0100 | [diff] [blame] | 574 | spm_src_repo_url="${spm_src_repo_url:-$SPM_SRC_REPO_URL}" |
| 575 | spm_src_repo_url="${spm_src_repo_url:-https://$tforg_gerrit_url/hafnium/hafnium}" |
Jimmy Brisson | 0d5e12c | 2023-05-16 14:51:51 -0500 | [diff] [blame] | 576 | tf_m_tests_src_repo_url="${tf_m_tests_src_repo_url:-$TF_M_TESTS_REPO_URL}" |
| 577 | tf_m_tests_src_repo_url="${tf_m_tests_src_repo_url:-https://$tforg_gerrit_url/TF-M/tf-m-tests}" |
| 578 | tf_m_extras_src_repo_url="${tf_m_extras_src_repo_url:-$TF_M_EXTRAS_REPO_URL}" |
| 579 | tf_m_extras_src_repo_url="${tf_m_extras_src_repo_url:-https://$tforg_gerrit_url/TF-M/tf-m-extras}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 580 | |
Leonardo Sandoval | d98f833 | 2021-04-13 16:46:38 -0500 | [diff] [blame] | 581 | tf_downloads="${tf_downloads:-file:///downloads/}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 582 | tfa_downloads="${tfa_downloads:-file:///downloads/tf-a}" |
| 583 | css_downloads="${css_downloads:-$tfa_downloads/css}" |
| 584 | |
Chris Kay | 52b8d43 | 2023-04-27 16:10:57 +0100 | [diff] [blame] | 585 | # SCP/MCP release binaries. |
Ryan Everett | 3836c6d | 2024-10-09 17:03:39 +0100 | [diff] [blame] | 586 | scp_mcp_downloads="${scp_mcp_downloads:-$tfa_downloads/css_scp_2.15.0}" |
Alexei Fedorov | 9e4473d | 2020-11-04 10:13:07 +0000 | [diff] [blame] | 587 | |
Leonardo Sandoval | 1567606 | 2020-11-19 11:58:09 -0600 | [diff] [blame] | 588 | linaro_2001_release="${linaro_2001_release:-$tfa_downloads/linaro/20.01}" |
Alexei Fedorov | e405cc3 | 2020-09-30 18:13:55 +0100 | [diff] [blame] | 589 | linaro_release="${linaro_release:-$linaro_2001_release}" |
Ryan Everett | 69845de | 2024-09-13 11:52:23 +0100 | [diff] [blame] | 590 | mbedtls_version="${mbedtls_version:-3.6.1}" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 591 | |
Madhukar Pappireddy | 4b686cf | 2020-03-31 13:05:14 -0500 | [diff] [blame] | 592 | # mbedTLS archive public hosting available at github.com |
Govindraj Raja | 827823f | 2023-02-28 14:19:00 +0000 | [diff] [blame] | 593 | mbedtls_archive="${mbedtls_archive:-https://github.com/Mbed-TLS/mbedtls/archive/mbedtls-${mbedtls_version}.tar.gz}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 594 | |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 595 | # FIXME: workaround to allow all on-prem host machines to access the latest LLVM |
| 596 | # LLVM archive public hosting available at github.com |
| 597 | llvm_version="${llvm_version:-14.0.0}" |
| 598 | llvm_dir="$workspace/llvm-$llvm_version" |
| 599 | llvm_archive="${llvm_archive:-https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version/clang+llvm-$llvm_version-x86_64-linux-gnu-ubuntu-18.04.tar.xz}" |
| 600 | |
Mark Dykes | 30138ad | 2021-11-09 16:48:17 -0600 | [diff] [blame] | 601 | coverity_path="${coverity_path:-${nfs_volume}/tools/coverity/static-analysis/2020.12}" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 602 | coverity_default_checkers=( |
| 603 | "--all" |
| 604 | "--checker-option DEADCODE:no_dead_default:true" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 605 | "--enable AUDIT.SPECULATIVE_EXECUTION_DATA_LEAK" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 606 | "--enable ENUM_AS_BOOLEAN" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 607 | "--enable-constraint-fpp" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 608 | "--ticker-mode none" |
Zelalem | 219df41 | 2020-05-17 19:21:20 -0500 | [diff] [blame] | 609 | "--hfa" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 610 | ) |
| 611 | |
Leonardo Sandoval | d76d1e2 | 2020-10-06 16:02:52 -0500 | [diff] [blame] | 612 | docker_registry="${docker_registry:-}" |
| 613 | |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 614 | # Define toolchain version and toolchain binary paths |
Jayanth Dodderi Chidanand | 3feb299 | 2024-09-30 18:11:54 +0100 | [diff] [blame] | 615 | toolchain_version="13.3.rel1" |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 616 | |
Jayanth Dodderi Chidanand | cc4d234 | 2022-09-12 14:44:21 +0100 | [diff] [blame] | 617 | aarch64_none_elf_dir="${nfs_volume}/pdsw/tools/arm-gnu-toolchain-${toolchain_version}-x86_64-aarch64-none-elf" |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 618 | aarch64_none_elf_prefix="aarch64-none-elf-" |
| 619 | |
Jayanth Dodderi Chidanand | cc4d234 | 2022-09-12 14:44:21 +0100 | [diff] [blame] | 620 | arm_none_eabi_dir="${nfs_volume}/pdsw/tools/arm-gnu-toolchain-${toolchain_version}-x86_64-arm-none-eabi" |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 621 | arm_none_eabi_prefix="arm-none-eabi-" |
| 622 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 623 | path_list=( |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 624 | "${aarch64_none_elf_dir}/bin" |
| 625 | "${arm_none_eabi_dir}/bin" |
Harrison Mutai | 013f633 | 2022-02-16 16:06:33 +0000 | [diff] [blame] | 626 | "${llvm_dir}/bin" |
Leonardo Sandoval | 1c24ae5 | 2020-07-08 11:47:23 -0500 | [diff] [blame] | 627 | "${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin" |
| 628 | "$coverity_path/bin" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 629 | ) |
| 630 | |
| 631 | ld_library_path_list=( |
| 632 | ) |
| 633 | |
Sandrine Bailleux | a6a1d6e | 2020-08-07 10:24:17 +0200 | [diff] [blame] | 634 | license_path_list=${license_path_list-( |
| 635 | )} |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 636 | |
| 637 | # Setup various paths |
| 638 | if upon "$retain_paths"; then |
| 639 | # If explicitly requested, retain local paths; apppend CI paths to the |
| 640 | # existing ones. |
| 641 | op="append" extend_path "PATH" "path_list" |
| 642 | op="append" extend_path "LD_LIBRARY_PATH" "ld_library_path_list" |
| 643 | op="append" extend_path "LM_LICENSE_FILE" "license_path_list" |
| 644 | else |
| 645 | # Otherwise, prepend CI paths so that they take effect before local ones |
| 646 | extend_path "PATH" "path_list" |
| 647 | extend_path "LD_LIBRARY_PATH" "ld_library_path_list" |
| 648 | extend_path "LM_LICENSE_FILE" "license_path_list" |
| 649 | fi |
| 650 | |
| 651 | export LD_LIBRARY_PATH |
| 652 | export LM_LICENSE_FILE |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 653 | export ARM_TOOL_VARIANT=ult |
| 654 | |
| 655 | # vim: set tw=80 sw=8 noet: |