blob: 340d0899e71f27f30a11ce436327dd93e152e635 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Zelalem219df412020-05-17 19:21:20 -05003# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
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
16ci_root="${ci_root:-$CI_ROOT}"
17ci_root="${ci_root:?}"
18
Sandrine Bailleuxaaaffe02020-08-07 11:15:55 +020019# Optionally source a file containing environmental settings.
20if [ -n "$host_env" ]; then
21 source "$host_env"
22else
23 # Are we running on Arm infrastructure?
Sandrine Bailleuxf3dfafb2020-08-10 10:55:10 +020024 if echo "$JENKINS_URL" | grep -q "arm.com"; then
Sandrine Bailleuxaaaffe02020-08-07 11:15:55 +020025 source "$ci_root/arm-env.sh"
26 fi
27fi
28
Fathi Boudra422bf772019-12-02 11:10:16 +020029# Storage area to host toolchains, rootfs, tools, models, binaries, etc...
30nfs_volume="${nfs_volume:-$NFS_VOLUME}"
31nfs_volume="${nfs_volume:?}"
32
33# Override workspace for local runs
34workspace="${workspace:-$WORKSPACE}"
35workspace="${workspace:?}"
36workspace="$(readlink -f "$workspace")"
37artefacts="$workspace/artefacts"
38
39# pushd and popd outputs the directory stack every time, which could be
40# confusing when shown on the log. Suppress its output.
41pushd() {
42 builtin pushd "$1" &>/dev/null
43}
44popd() {
45 builtin popd &>/dev/null
46}
47
48# Copy a file to the $archive directory
49archive_file() {
50 local f out target md5
51 f="${1:?}"
52
53 out="${archive:?}"
54 [ ! -d "$out" ] && die "$out is not a directory"
55
56 target="$out/$(basename $f)"
57 if [ -f "$target" ]; then
58 # Prevent same file error
59 if [ "$(stat --format=%i "$target")" = \
60 "$(stat --format=%i "$f")" ]; then
61 return
62 fi
63 fi
64
65 md5="$(md5sum "$f" | awk '{print $1}')"
66 cp -t "$out" "$f"
67 echo "Archived: $f (md5: $md5)"
68}
69
70die() {
71 [ "$1" ] && echo "$1" >&2
72 exit 1
73}
74
75# Emit environment variables for the purpose of sourcing from shells and as
76# Jenkins property files. Whether the RHS is quoted depends on "$quote".
77emit_env() {
78 local env_file="${env_file:?}"
79 local var="${1:?}"
80
81 # Value parameter is mandatory, but allow for it to be empty
82 local val="${2?}"
83
84 if upon "$quote"; then
85 val="\"$val\""
86 else
87 # If RHS is not required to be quoted, any white space in it
88 # won't go well with a shell sourcing this file.
89 if echo "$var" | grep -q '\s'; then
90 die "$var: value '$val' has white space"
91 fi
92 fi
93
94 echo "$var=$val" >> "$env_file"
95}
96
Fathi Boudra422bf772019-12-02 11:10:16 +020097fetch_directory() {
98 local base="$(basename "${url:?}")"
99 local sa
100
Fathi Boudradd31e7b2020-01-29 15:44:42 +0200101 case "${url}" in
102 http*://*)
103 # Have exactly one trailing /
104 local modified_url="$(echo "${url}" | sed 's#/*$##')/"
Fathi Boudra422bf772019-12-02 11:10:16 +0200105
Fathi Boudradd31e7b2020-01-29 15:44:42 +0200106 # Figure out the number of components between hostname and the
107 # final one
108 local cut_dirs="$(echo "$modified_url" | awk -F/ '{print NF - 5}')"
109 sa="${saveas:-$base}"
110 echo "Fetch: $modified_url -> $sa"
111 wget -rq -nH --cut-dirs="$cut_dirs" --no-parent \
112 --reject="index.html*" "$modified_url"
113 if [ "$sa" != "$base" ]; then
114 mv "$base" "$sa"
115 fi
116 ;;
117 file://*)
118 sa="${saveas:-.}"
119 echo "Fetch: ${url} -> $sa"
120 cp -r "${url#file://}" "$sa"
121 ;;
122 *)
123 sa="${saveas:-.}"
124 echo "Fetch: ${url} -> $sa"
125 cp -r "${url}" "$sa"
126 ;;
127 esac
Fathi Boudra422bf772019-12-02 11:10:16 +0200128}
129
130fetch_file() {
131 local url="${url:?}"
132 local sa
133 local saveas
134
135 if is_url "$url"; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200136 saveas="${saveas-"$(basename "$url")"}"
Sandrine Bailleux3da4bd12020-08-06 16:18:36 +0200137 sa="${saveas+-o $saveas}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200138 echo "Fetch: $url -> $saveas"
139 # Use curl to support file protocol
Sandrine Bailleuxfd011be2020-08-06 13:17:39 +0200140 curl -sLS $sa "$url"
Fathi Boudra422bf772019-12-02 11:10:16 +0200141 else
142 sa="${saveas-.}"
143 echo "Fetch: $url -> $sa"
144 cp "$url" "$sa"
145 fi
146}
147
148# Make a temporary directory/file insdie workspace, so that it doesn't need to
149# be cleaned up. Jenkins is setup to clean up workspace before a job runs.
150mktempdir() {
151 local ws="${workspace:?}"
152
153 mktemp -d --tmpdir="$ws"
154}
155mktempfile() {
156 local ws="${workspace:?}"
157
158 mktemp --tmpdir="$ws"
159}
160
161not_upon() {
162 ! upon "$1"
163}
164
165# Use "$1" as a boolean
166upon() {
167 case "$1" in
168 "" | "0" | "false") return 1;;
169 *) return 0;;
170 esac
171}
172
173# Check if the argument is a URL
174is_url() {
175 echo "$1" | grep -q "://"
176}
177
178# Check if a path is absolute
179is_abs() {
180 [ "${1:0:1}" = "/" ]
181}
182
183# Unset a variable based on its boolean value
184# If foo=, foo will be unset
185# If foo=blah, then leave it as is
186reset_var() {
187 local var="$1"
188 local val="${!var}"
189
190 if [ -z "$val" ]; then
191 unset "$var"
192 else
193 var="$val"
194 fi
195}
196
197default_var() {
198 local var="$1"
199 local val="${!var}"
200 local default="$2"
201
202 if [ -z "$val" ]; then
203 eval "$var=$default"
204 fi
205}
206
207# String various items joined by ":" to form a path. Items are prepended by
208# default; or 'op' can be set to 'append' to have them appended.
209# For example, to set: PATH=foo:bar:baz:$PATH
210extend_path() {
211 local path_var="$1"
212 local array_var="$2"
Leonardo Sandoval2af93202020-07-16 17:29:18 -0500213 local path_val="${!path_var}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200214 local op="${op:-prepend}"
Leonardo Sandoval2af93202020-07-16 17:29:18 -0500215 local sep=':'
216 local array_val
Fathi Boudra422bf772019-12-02 11:10:16 +0200217
Leonardo Sandoval2af93202020-07-16 17:29:18 -0500218 eval "array_val=\"\${$array_var[@]}\""
219 array_val="$(echo ${array_val// /:})"
220
221 [ -z "$path_val" ] && sep=''
222
223 if [ "$op" = "prepend" ]; then
224 array_val="${array_val}${sep}${path_val}"
225 elif [ "$op" = "append" ]; then
226 array_val="${path_val}${sep}${array_val}"
227 fi
228
229 eval "$path_var=\"$array_val\""
Fathi Boudra422bf772019-12-02 11:10:16 +0200230}
231
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500232# Extract files from compressed archive to target directory. Supports .zip and
233# .tar.gz format
234extract_tarball() {
235 local archive="$1"
236 local target_dir="$2"
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500237 local extra_params="${3:-}"
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500238
239 pushd "$target_dir"
240 case $(file --mime-type -b "$archive") in
241 application/gzip)
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500242 tar -xz $extra_params -f $archive
Zelalem219df412020-05-17 19:21:20 -0500243 ;;
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500244 application/zip)
Leonardo Sandovalec9e16c2020-09-09 14:32:40 -0500245 unzip -q $extra_params $archive
Zelalem219df412020-05-17 19:21:20 -0500246 ;;
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500247 esac
Zelalem219df412020-05-17 19:21:20 -0500248 popd "$target_dir"
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500249}
250
Leonardo Sandoval795b6212020-08-14 16:20:00 -0500251# Check if execution is done by Jenkins. If called with a parameter,
252# representing a 'domain', i.e. arm.com, it will also check if
253# JENKINS_URL contains the latter.
254is_jenkins_env () {
255 local domain="${1-}"
256
257 # check if running under Jenkins, if not, return non-zero
258 # the checks assumes Jenkins executing if JENKINS_HOME is set
259 [ -z "$JENKINS_HOME" ] && return 1
260
261 # if no parameter passed, no more checks, quit
262 [ -z "$domain" ] && return 0
263
264 if echo "$JENKINS_URL" | grep -q "$domain"; then
265 return 0
266 fi
267
268 return 1
269}
270
271
272# Check if execution is under ARM's jenkins
273is_arm_jenkins_env() {
274 local arm_domain="arm.com"
275 return $(is_jenkins_env "$arm_domain")
276}
277
Leonardo Sandovalfeae3a22020-11-17 16:53:59 -0600278
279# Provide correct linaro cross toolchain based on environment
280set_cross_compile_gcc_linaro_toolchain() {
281 local cross_compile_path="/home/buildslave/tools"
282
283 # if under arm enviroment, overide cross-compilation path
284 is_arm_jenkins_env && cross_compile_path="/arm/pdsw/tools"
285
286 echo "${cross_compile_path}/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-"
287}
288
Leonardo Sandoval795b6212020-08-14 16:20:00 -0500289if is_jenkins_env; then
Fathi Boudra422bf772019-12-02 11:10:16 +0200290 jenkins_run=1
291 umask 0002
292else
293 unset jenkins_run
294fi
295
296# Project scratch location for Trusted Firmware CI
297project_filer="${nfs_volume}/projectscratch/ssg/trusted-fw"
298project_scratch="${PROJECT_SCRATCH:-$project_filer/ci-workspace}"
299warehouse="${nfs_volume}/warehouse"
300jenkins_url="${JENKINS_URL%/*}"
301jenkins_url="${jenkins_url:-https://ci.trustedfirmware.org/}"
302
303# Model revisions
Manish V Badarkhe89370562020-09-17 05:45:20 +0100304model_version="${model_version:-11.12}"
Manish V Badarkhe074eb952020-09-23 05:38:07 +0100305model_build="${model_build:-38}"
Zelalem219df412020-05-17 19:21:20 -0500306model_flavour="${model_flavour:-Linux64_GCC-6.4}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200307
308# Model snapshots from filer are not normally not accessible from developer
309# systems. Ignore failures from picking real path for local runs.
310pinned_cortex="$(readlink -f ${pinned_cortex:-$project_filer/models/cortex})" || true
311pinned_css="$(readlink -f ${pinned_css:-$project_filer/models/css})" || true
312
Fathi Boudra422bf772019-12-02 11:10:16 +0200313tforg_gerrit_url="review.trustedfirmware.org"
314
315# Repository URLs. We're using anonymous HTTP as they appear to be faster rather
316# than any scheme with authentication.
Fathi Boudra422bf772019-12-02 11:10:16 +0200317tf_src_repo_url="${tf_src_repo_url:-$TF_SRC_REPO_URL}"
318tf_src_repo_url="${tf_src_repo_url:-https://$tforg_gerrit_url/TF-A/trusted-firmware-a}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200319tftf_src_repo_url="${tftf_src_repo_url:-$TFTF_SRC_REPO_URL}"
320tftf_src_repo_url="${tftf_src_repo_url:-https://$tforg_gerrit_url/TF-A/tf-a-tests}"
Jimmy Brisson29ca0a02020-09-22 16:15:35 -0500321ci_src_repo_url="${ci_src_repo_url:-$CI_SRC_REPO_URL}"
322ci_src_repo_url="${ci_src_repo_url:-https://$tforg_gerrit_url/ci/tf-a-ci-scripts}"
Zelalemdd655272020-10-06 16:29:05 -0500323tf_ci_repo_url="$ci_src_repo_url"
Fathi Boudra422bf772019-12-02 11:10:16 +0200324scp_src_repo_url="${scp_src_repo_url:-$SCP_SRC_REPO_URL}"
Girish Pathak97f7ad42020-08-27 11:38:15 +0100325scp_src_repo_url="${scp_src_repo_url:-$scp_src_repo_default}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200326
327# FIXME set a sane default for tfa_downloads
328tfa_downloads="${tfa_downloads:-file:///downloads/tf-a}"
329css_downloads="${css_downloads:-$tfa_downloads/css}"
330
Alexei Fedorov9e4473d2020-11-04 10:13:07 +0000331# SCP/MCP v2.7.0 release binaries
332# Linux files from https://releases.linaro.org/members/arm/platforms/20.01
333css_downloads_270="${css_downloads_270:-$tfa_downloads/css_scp_2.7.0}"
334
Alexei Fedorove405cc32020-09-30 18:13:55 +0100335linaro_2001_release="$tfa_downloads/linaro/20.01"
336linaro_release="${linaro_release:-$linaro_2001_release}"
Zelalem219df412020-05-17 19:21:20 -0500337
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500338# mbedTLS archive public hosting available at github.com
Alexei Fedorovf9dccd32020-09-21 13:21:04 +0100339mbedtls_archive="${mbedtls_archive:-https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.24.0.tar.gz}"
340# The tar file contains mbedtls-mbedtls-2.24.0 repo which holds the necessary
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500341# source files of mbedTLS project
Alexei Fedorovf9dccd32020-09-21 13:21:04 +0100342mbedtls_repo_name="${mbedtls_repo_name:-mbedtls-mbedtls-2.24.0}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200343
Zelalem219df412020-05-17 19:21:20 -0500344coverity_path="${coverity_path:-${nfs_volume}/tools/coverity/static-analysis/2019.09}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200345coverity_default_checkers=(
346"--all"
347"--checker-option DEADCODE:no_dead_default:true"
Fathi Boudra422bf772019-12-02 11:10:16 +0200348"--enable AUDIT.SPECULATIVE_EXECUTION_DATA_LEAK"
Zelalem219df412020-05-17 19:21:20 -0500349"--enable ENUM_AS_BOOLEAN"
Fathi Boudra422bf772019-12-02 11:10:16 +0200350"--enable-constraint-fpp"
Fathi Boudra422bf772019-12-02 11:10:16 +0200351"--ticker-mode none"
Zelalem219df412020-05-17 19:21:20 -0500352"--hfa"
Fathi Boudra422bf772019-12-02 11:10:16 +0200353)
354
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500355docker_registry="${docker_registry:-}"
356
Leonardo Sandoval1c24ae52020-07-08 11:47:23 -0500357# Define toolchain version and toolchain binary paths
358toolchain_version="9.2-2019.12"
359
360aarch64_none_elf_dir="${nfs_volume}/pdsw/tools/gcc-arm-${toolchain_version}-x86_64-aarch64-none-elf"
361aarch64_none_elf_prefix="aarch64-none-elf-"
362
363arm_none_eabi_dir="${nfs_volume}/pdsw/tools/gcc-arm-${toolchain_version}-x86_64-arm-none-eabi"
364arm_none_eabi_prefix="arm-none-eabi-"
365
Fathi Boudra422bf772019-12-02 11:10:16 +0200366path_list=(
Leonardo Sandoval1c24ae52020-07-08 11:47:23 -0500367 "${aarch64_none_elf_dir}/bin"
368 "${arm_none_eabi_dir}/bin"
369 "${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin"
370 "$coverity_path/bin"
Fathi Boudra422bf772019-12-02 11:10:16 +0200371)
372
373ld_library_path_list=(
374)
375
Sandrine Bailleuxa6a1d6e2020-08-07 10:24:17 +0200376license_path_list=${license_path_list-(
377)}
Fathi Boudra422bf772019-12-02 11:10:16 +0200378
379# Setup various paths
380if upon "$retain_paths"; then
381 # If explicitly requested, retain local paths; apppend CI paths to the
382 # existing ones.
383 op="append" extend_path "PATH" "path_list"
384 op="append" extend_path "LD_LIBRARY_PATH" "ld_library_path_list"
385 op="append" extend_path "LM_LICENSE_FILE" "license_path_list"
386else
387 # Otherwise, prepend CI paths so that they take effect before local ones
388 extend_path "PATH" "path_list"
389 extend_path "LD_LIBRARY_PATH" "ld_library_path_list"
390 extend_path "LM_LICENSE_FILE" "license_path_list"
391fi
392
393export LD_LIBRARY_PATH
394export LM_LICENSE_FILE
Fathi Boudra422bf772019-12-02 11:10:16 +0200395export ARM_TOOL_VARIANT=ult
396
397# vim: set tw=80 sw=8 noet: