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