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