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