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