blob: 3e76899fdde6e2e6a8377d1d6651b569efbe91da [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#!/bin/bash
2#
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
19# Storage area to host toolchains, rootfs, tools, models, binaries, etc...
20nfs_volume="${nfs_volume:-$NFS_VOLUME}"
21nfs_volume="${nfs_volume:?}"
22
23# Override workspace for local runs
24workspace="${workspace:-$WORKSPACE}"
25workspace="${workspace:?}"
26workspace="$(readlink -f "$workspace")"
27artefacts="$workspace/artefacts"
28
29# pushd and popd outputs the directory stack every time, which could be
30# confusing when shown on the log. Suppress its output.
31pushd() {
32 builtin pushd "$1" &>/dev/null
33}
34popd() {
35 builtin popd &>/dev/null
36}
37
38# Copy a file to the $archive directory
39archive_file() {
40 local f out target md5
41 f="${1:?}"
42
43 out="${archive:?}"
44 [ ! -d "$out" ] && die "$out is not a directory"
45
46 target="$out/$(basename $f)"
47 if [ -f "$target" ]; then
48 # Prevent same file error
49 if [ "$(stat --format=%i "$target")" = \
50 "$(stat --format=%i "$f")" ]; then
51 return
52 fi
53 fi
54
55 md5="$(md5sum "$f" | awk '{print $1}')"
56 cp -t "$out" "$f"
57 echo "Archived: $f (md5: $md5)"
58}
59
60die() {
61 [ "$1" ] && echo "$1" >&2
62 exit 1
63}
64
65# Emit environment variables for the purpose of sourcing from shells and as
66# Jenkins property files. Whether the RHS is quoted depends on "$quote".
67emit_env() {
68 local env_file="${env_file:?}"
69 local var="${1:?}"
70
71 # Value parameter is mandatory, but allow for it to be empty
72 local val="${2?}"
73
74 if upon "$quote"; then
75 val="\"$val\""
76 else
77 # If RHS is not required to be quoted, any white space in it
78 # won't go well with a shell sourcing this file.
79 if echo "$var" | grep -q '\s'; then
80 die "$var: value '$val' has white space"
81 fi
82 fi
83
84 echo "$var=$val" >> "$env_file"
85}
86
Fathi Boudra422bf772019-12-02 11:10:16 +020087fetch_directory() {
88 local base="$(basename "${url:?}")"
89 local sa
90
Fathi Boudradd31e7b2020-01-29 15:44:42 +020091 case "${url}" in
92 http*://*)
93 # Have exactly one trailing /
94 local modified_url="$(echo "${url}" | sed 's#/*$##')/"
Fathi Boudra422bf772019-12-02 11:10:16 +020095
Fathi Boudradd31e7b2020-01-29 15:44:42 +020096 # Figure out the number of components between hostname and the
97 # final one
98 local cut_dirs="$(echo "$modified_url" | awk -F/ '{print NF - 5}')"
99 sa="${saveas:-$base}"
100 echo "Fetch: $modified_url -> $sa"
101 wget -rq -nH --cut-dirs="$cut_dirs" --no-parent \
102 --reject="index.html*" "$modified_url"
103 if [ "$sa" != "$base" ]; then
104 mv "$base" "$sa"
105 fi
106 ;;
107 file://*)
108 sa="${saveas:-.}"
109 echo "Fetch: ${url} -> $sa"
110 cp -r "${url#file://}" "$sa"
111 ;;
112 *)
113 sa="${saveas:-.}"
114 echo "Fetch: ${url} -> $sa"
115 cp -r "${url}" "$sa"
116 ;;
117 esac
Fathi Boudra422bf772019-12-02 11:10:16 +0200118}
119
120fetch_file() {
121 local url="${url:?}"
122 local sa
123 local saveas
124
125 if is_url "$url"; then
126 sa="${saveas+-o $saveas}"
127 saveas="${saveas-"$(basename "$url")"}"
128 echo "Fetch: $url -> $saveas"
129 # Use curl to support file protocol
130 curl -sLS -C - $sa "$url"
131 else
132 sa="${saveas-.}"
133 echo "Fetch: $url -> $sa"
134 cp "$url" "$sa"
135 fi
136}
137
138# Make a temporary directory/file insdie workspace, so that it doesn't need to
139# be cleaned up. Jenkins is setup to clean up workspace before a job runs.
140mktempdir() {
141 local ws="${workspace:?}"
142
143 mktemp -d --tmpdir="$ws"
144}
145mktempfile() {
146 local ws="${workspace:?}"
147
148 mktemp --tmpdir="$ws"
149}
150
151not_upon() {
152 ! upon "$1"
153}
154
155# Use "$1" as a boolean
156upon() {
157 case "$1" in
158 "" | "0" | "false") return 1;;
159 *) return 0;;
160 esac
161}
162
163# Check if the argument is a URL
164is_url() {
165 echo "$1" | grep -q "://"
166}
167
168# Check if a path is absolute
169is_abs() {
170 [ "${1:0:1}" = "/" ]
171}
172
173# Unset a variable based on its boolean value
174# If foo=, foo will be unset
175# If foo=blah, then leave it as is
176reset_var() {
177 local var="$1"
178 local val="${!var}"
179
180 if [ -z "$val" ]; then
181 unset "$var"
182 else
183 var="$val"
184 fi
185}
186
187default_var() {
188 local var="$1"
189 local val="${!var}"
190 local default="$2"
191
192 if [ -z "$val" ]; then
193 eval "$var=$default"
194 fi
195}
196
197# String various items joined by ":" to form a path. Items are prepended by
198# default; or 'op' can be set to 'append' to have them appended.
199# For example, to set: PATH=foo:bar:baz:$PATH
200extend_path() {
201 local path_var="$1"
202 local array_var="$2"
203 local tmp_path="${!path_var}"
204 local tmp_array
205 local item
206 local op="${op:-prepend}"
207
208 eval "tmp_array=\"\${$array_var[@]}\""
209 for item in $tmp_array; do
210 if [ "$op" = "prepend" ]; then
211 tmp_path="$item${tmp_path+:}$tmp_path"
212 elif [ "$op" = "append" ]; then
213 tmp_path="$tmp_path${tmp_path+:}$item"
214 fi
215 done
216 eval "$path_var=\"$tmp_path\""
217}
218
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500219# Extract files from compressed archive to target directory. Supports .zip and
220# .tar.gz format
221extract_tarball() {
222 local archive="$1"
223 local target_dir="$2"
224
225 pushd "$target_dir"
226 case $(file --mime-type -b "$archive") in
227 application/gzip)
Zelalem219df412020-05-17 19:21:20 -0500228 tar -xzf $archive
229 ;;
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500230 application/zip)
Zelalem219df412020-05-17 19:21:20 -0500231 unzip -q $archive
232 ;;
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500233 esac
Zelalem219df412020-05-17 19:21:20 -0500234 popd "$target_dir"
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500235}
236
Fathi Boudra422bf772019-12-02 11:10:16 +0200237# Assume running on Jenkins if JENKINS_HOME is set
238if [ "$JENKINS_HOME" ]; then
239 jenkins_run=1
240 umask 0002
241else
242 unset jenkins_run
243fi
244
245# Project scratch location for Trusted Firmware CI
246project_filer="${nfs_volume}/projectscratch/ssg/trusted-fw"
247project_scratch="${PROJECT_SCRATCH:-$project_filer/ci-workspace}"
248warehouse="${nfs_volume}/warehouse"
249jenkins_url="${JENKINS_URL%/*}"
250jenkins_url="${jenkins_url:-https://ci.trustedfirmware.org/}"
251
252# Model revisions
Zelalem219df412020-05-17 19:21:20 -0500253model_version="${model_version:-11.9}"
254model_build="${model_build:-41}"
255model_flavour="${model_flavour:-Linux64_GCC-6.4}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200256
257# Model snapshots from filer are not normally not accessible from developer
258# systems. Ignore failures from picking real path for local runs.
259pinned_cortex="$(readlink -f ${pinned_cortex:-$project_filer/models/cortex})" || true
260pinned_css="$(readlink -f ${pinned_css:-$project_filer/models/css})" || true
261
262#arm_gerrit_url="gerrit.oss.arm.com"
263tforg_gerrit_url="review.trustedfirmware.org"
264
265# Repository URLs. We're using anonymous HTTP as they appear to be faster rather
266# than any scheme with authentication.
267#tf_ci_repo_url="http://$arm_gerrit_url/pdswinf/ci/pdcs-platforms/platform-ci"
268tf_src_repo_url="${tf_src_repo_url:-$TF_SRC_REPO_URL}"
269tf_src_repo_url="${tf_src_repo_url:-https://$tforg_gerrit_url/TF-A/trusted-firmware-a}"
270#tf_arm_gerrit_repo="ssh://$arm_gerrit_url:29418/pdcs-platforms/ap/tf-topics.git"
271tftf_src_repo_url="${tftf_src_repo_url:-$TFTF_SRC_REPO_URL}"
272tftf_src_repo_url="${tftf_src_repo_url:-https://$tforg_gerrit_url/TF-A/tf-a-tests}"
273#tftf_arm_gerrit_repo="ssh://$arm_gerrit_url:29418/trusted-firmware/tf-a-tests.git"
274scp_src_repo_url="${scp_src_repo_url:-$SCP_SRC_REPO_URL}"
Zelalem219df412020-05-17 19:21:20 -0500275#cc_src_repo_url="${cc_src_repo_url:-https://$arm_gerrit_url/tests/lava/test-definitions.git}"
276#cc_src_repo_tag="${cc_src_repo_tag:-kernel-team-workflow_2019-09-20}"
277
278#scp_tools_src_repo_url="${scp_tools_src_repo_url:-http://$arm_gerrit_url/scp/tools-non-public}"
279#tf_for_scp_tools_src_repo_url="https://gerrit.oss.arm.com/scp/test-framework"
Fathi Boudra422bf772019-12-02 11:10:16 +0200280
281# FIXME set a sane default for tfa_downloads
282tfa_downloads="${tfa_downloads:-file:///downloads/tf-a}"
283css_downloads="${css_downloads:-$tfa_downloads/css}"
284
Zelalem219df412020-05-17 19:21:20 -0500285linaro_1906_release="$tfa_downloads/linaro/19.06"
286linaro_release="${linaro_release:-$linaro_1906_release}"
287
Madhukar Pappireddy4b686cf2020-03-31 13:05:14 -0500288# mbedTLS archive public hosting available at github.com
289mbedtls_archive="${mbedtls_archive:-https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.18.0.zip}"
290# The tar file contains mbedtls-mbedtls-2.18.0 repo which holds the necessary
291# source files of mbedTLS project
292mbedtls_repo_name="${mbedtls_repo_name:-mbedtls-mbedtls-2.18.0}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200293
Zelalem219df412020-05-17 19:21:20 -0500294coverity_path="${coverity_path:-${nfs_volume}/tools/coverity/static-analysis/2019.09}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200295#coverity_host="${coverity_host:-coverity.cambridge.arm.com}"
296coverity_default_checkers=(
297"--all"
298"--checker-option DEADCODE:no_dead_default:true"
Fathi Boudra422bf772019-12-02 11:10:16 +0200299"--enable AUDIT.SPECULATIVE_EXECUTION_DATA_LEAK"
Zelalem219df412020-05-17 19:21:20 -0500300"--enable ENUM_AS_BOOLEAN"
Fathi Boudra422bf772019-12-02 11:10:16 +0200301"--enable-constraint-fpp"
Fathi Boudra422bf772019-12-02 11:10:16 +0200302"--ticker-mode none"
Zelalem219df412020-05-17 19:21:20 -0500303"--hfa"
Fathi Boudra422bf772019-12-02 11:10:16 +0200304)
305
306#export coverity_host
307
308path_list=(
Zelalem219df412020-05-17 19:21:20 -0500309#Need to upgrade gcc to the following version
310#"/arm/pdsw/tools/gcc-arm-9.2-2019.12-x86_64-aarch64-none-elf/bin"
311#"/arm/pdsw/tools/gcc-arm-9.2-2019.12-x86_64-arm-none-eabi/bin"
Fathi Boudra422bf772019-12-02 11:10:16 +0200312"${nfs_volume}/pdsw/tools/gcc-linaro-6.2.1-2016.11-x86_64_aarch64-linux-gnu/bin"
313"${nfs_volume}/pdsw/tools/gcc-linaro-6.2.1-2016.11-x86_64_arm-linux-gnueabihf/bin"
314"${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin"
315"$coverity_path/bin"
316)
317
318ld_library_path_list=(
319)
320
321license_path_list=(
322)
323
324# Setup various paths
325if upon "$retain_paths"; then
326 # If explicitly requested, retain local paths; apppend CI paths to the
327 # existing ones.
328 op="append" extend_path "PATH" "path_list"
329 op="append" extend_path "LD_LIBRARY_PATH" "ld_library_path_list"
330 op="append" extend_path "LM_LICENSE_FILE" "license_path_list"
331else
332 # Otherwise, prepend CI paths so that they take effect before local ones
333 extend_path "PATH" "path_list"
334 extend_path "LD_LIBRARY_PATH" "ld_library_path_list"
335 extend_path "LM_LICENSE_FILE" "license_path_list"
336fi
337
338export LD_LIBRARY_PATH
339export LM_LICENSE_FILE
340export ARMLMD_LICENSE_FILE="$LM_LICENSE_FILE"
341export ARM_TOOL_VARIANT=ult
342
343# vim: set tw=80 sw=8 noet: