blob: 5062e5de7e14c73a33fc14c19122131698ae706a [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
8set -u
9
10bl1_addr="${bl1_addr:-0x0}"
Zelalem219df412020-05-17 19:21:20 -050011bl31_addr="${bl31_addr:-0x04001000}"
Zelalem1b874612020-08-04 18:08:18 -050012bl32_addr="${bl32_addr:-0x04003000}"
Fathi Boudra422bf772019-12-02 11:10:16 +020013bl33_addr="${bl33_addr:-0x88000000}"
14dtb_addr="${dtb_addr:-0x82000000}"
15fip_addr="${fip_addr:-0x08000000}"
16initrd_addr="${initrd_addr:-0x84000000}"
17kernel_addr="${kernel_addr:-0x80080000}"
18el3_payload_addr="${el3_payload_addr:-0x80000000}"
19
Manish Pandey3c435582020-07-15 12:14:26 +010020# SPM requires following addresses for RESET_TO_BL31 case
21spm_addr="${spm_addr:-0x6000000}"
22spmc_manifest_addr="${spmc_addr:-0x0403f000}"
23sp1_addr="${sp1_addr:-0x7000000}"
24sp2_addr="${sp2_addr:-0x7100000}"
Olivier Deprez0b834092020-08-21 08:36:01 +020025sp3_addr="${sp3_addr:-0x7200000}"
Manish Pandey1e7be852020-11-09 16:04:48 +000026# SPM out directories
27export spm_secure_out_dir="${spm_secure_out_dir:-secure_aem_v8a_fvp_clang}"
28export spm_non_secure_out_dir="${spm_non_secure_out_dir:-aem_v8a_fvp_clang}"
Manish Pandey3c435582020-07-15 12:14:26 +010029
Fathi Boudra422bf772019-12-02 11:10:16 +020030ns_bl1u_addr="${ns_bl1u_addr:-0x0beb8000}"
31fwu_fip_addr="${fwu_fip_addr:-0x08400000}"
32backup_fip_addr="${backup_fip_addr:-0x09000000}"
33romlib_addr="${romlib_addr:-0x03ff2000}"
34
35uboot32_fip_url="$linaro_release/fvp32-latest-busybox-uboot/fip.bin"
36
Alexei Fedorove405cc32020-09-30 18:13:55 +010037rootfs_url="$linaro_release/lt-vexpress64-openembedded_minimal-armv8-gcc-5.2_20170127-761.img.gz"
Fathi Boudra422bf772019-12-02 11:10:16 +020038
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050039# Default FVP model variables
40default_model_dtb="fvp-base-gicv3-psci.dtb"
41
42# default to the fvp container containing most of the models and its corresponding base
43# directory
44default_model_name="fvp:fvp_arm_std_library_11.12_38"
45default_model_dir="/opt/model/FVP_ARM_Std_Library/models/Linux64_GCC-6.4"
46
47# This is intentionally black, so a the run config snippet MUST pass this the parameter
48# indicating the model's binary
49default_model_bin=""
50
Fathi Boudra422bf772019-12-02 11:10:16 +020051# FVP Kernel URLs
52declare -A fvp_kernels
53fvp_kernels=(
54[fvp-aarch32-zimage]="$linaro_release/fvp32-latest-busybox-uboot/Image"
55[fvp-busybox-uboot]="$linaro_release/fvp-latest-busybox-uboot/Image"
56[fvp-oe-uboot32]="$linaro_release/fvp32-latest-oe-uboot/Image"
57[fvp-oe-uboot]="$linaro_release/fvp-latest-oe-uboot/Image"
58[fvp-quad-busybox-uboot]="$tfa_downloads/quad_cluster/Image"
59)
60
Fathi Boudra422bf772019-12-02 11:10:16 +020061# FVP initrd URLs
62declare -A fvp_initrd_urls
63fvp_initrd_urls=(
64[aarch32-ramdisk]="$linaro_release/fvp32-latest-busybox-uboot/ramdisk.img"
Fathi Boudra422bf772019-12-02 11:10:16 +020065[dummy-ramdisk]="$linaro_release/fvp-latest-oe-uboot/ramdisk.img"
66[dummy-ramdisk32]="$linaro_release/fvp32-latest-oe-uboot/ramdisk.img"
67[default]="$linaro_release/fvp-latest-busybox-uboot/ramdisk.img"
68)
69
Fathi Boudra422bf772019-12-02 11:10:16 +020070get_optee_bin() {
71 url="$jenkins_url/job/tf-optee-build/PLATFORM_FLAVOR=fvp,label=arch-dev/lastSuccessfulBuild/artifact/artefacts/tee.bin" \
Zelalem219df412020-05-17 19:21:20 -050072 saveas="bl32.bin" fetch_file
Fathi Boudra422bf772019-12-02 11:10:16 +020073 archive_file "bl32.bin"
74}
75
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010076# For Measured Boot tests using a TA based on OPTEE, it is necessary to use a
77# specific build rather than the default one generated by Jenkins.
78get_ftpm_optee_bin() {
Javier Almansa Sobrinode647722020-10-08 19:17:44 +010079 url="$tfa_downloads/ftpm/optee/tee-header_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010080 saveas="bl32.bin" fetch_file
81 archive_file "bl32.bin"
82
Javier Almansa Sobrinode647722020-10-08 19:17:44 +010083 url="$tfa_downloads/ftpm/optee/tee-pager_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010084 saveas="bl32_extra1.bin" fetch_file
85 archive_file "bl32_extra1.bin"
86
Javier Almansa Sobrinode647722020-10-08 19:17:44 +010087 url="$tfa_downloads/ftpm/optee/tee-pageable_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +010088 saveas="bl32_extra2.bin" fetch_file
89 archive_file "bl32_extra2.bin"
90}
91
Fathi Boudra422bf772019-12-02 11:10:16 +020092get_uboot32_bin() {
93 local tmpdir="$(mktempdir)"
94
95 pushd "$tmpdir"
96 extract_fip "$uboot32_fip_url"
97 mv "nt-fw.bin" "uboot.bin"
98 archive_file "uboot.bin"
99 popd
100}
101
102get_uboot_bin() {
103 local uboot_url="$linaro_release/fvp-latest-busybox-uboot/bl33-uboot.bin"
104
105 url="$uboot_url" saveas="uboot.bin" fetch_file
106 archive_file "uboot.bin"
107}
108
109get_uefi_bin() {
Zelalem219df412020-05-17 19:21:20 -0500110 uefi_downloads="${uefi_downloads:-http://files.oss.arm.com/downloads/uefi}"
111 uefi_ci_bin_url="${uefi_ci_bin_url:-$uefi_downloads/Artifacts/Linux/github/fvp/static/DEBUG_GCC5/FVP_AARCH64_EFI.fd}"
Fathi Boudra422bf772019-12-02 11:10:16 +0200112
113 url=$uefi_ci_bin_url saveas="uefi.bin" fetch_file
114 archive_file "uefi.bin"
115}
116
117get_kernel() {
118 local kernel_type="${kernel_type:?}"
119 local url="${fvp_kernels[$kernel_type]}"
120
121 url="${url:?}" saveas="kernel.bin" fetch_file
122 archive_file "kernel.bin"
123}
124
125get_initrd() {
126 local initrd_type="${initrd_type:?}"
127 local url="${fvp_initrd_urls[$initrd_type]}"
128
129 url="${url:?}" saveas="initrd.bin" fetch_file
130 archive_file "initrd.bin"
131}
132
133get_dtb() {
134 local dtb_type="${dtb_type:?}"
135 local dtb_url
136 local dtb_saveas="$workspace/dtb.bin"
Zelalem219df412020-05-17 19:21:20 -0500137 local cc="$(get_tf_opt CROSS_COMPILE)"
138 local pp_flags="-P -nostdinc -undef -x assembler-with-cpp"
Fathi Boudra422bf772019-12-02 11:10:16 +0200139
140 case "$dtb_type" in
141 "fvp-base-quad-cluster-gicv3-psci")
142 # Get the quad-cluster FDT from pdsw area
143 dtb_url="$tfa_downloads/quad_cluster/fvp-base-quad-cluster-gicv3-psci.dtb"
144 url="$dtb_url" saveas="$dtb_saveas" fetch_file
145 ;;
146 "sgm775")
147 # Get the SGM775 FDT from pdsw area
148 dtb_url="$sgm_prebuilts/sgm775.dtb"
149 url="$dtb_url" saveas="$dtb_saveas" fetch_file
150 ;;
151 *)
Zelalem219df412020-05-17 19:21:20 -0500152 # Preprocess DTS file
153 ${cc}gcc -E ${pp_flags} -I"$tf_root/fdts" -I"$tf_root/include" \
154 -o "$workspace/${dtb_type}.pre.dts" \
155 "$tf_root/fdts/${dtb_type}.dts"
156 # Generate DTB file from DTS
Fathi Boudra422bf772019-12-02 11:10:16 +0200157 dtc -I dts -O dtb \
Zelalem219df412020-05-17 19:21:20 -0500158 "$workspace/${dtb_type}.pre.dts" -o "$dtb_saveas"
Fathi Boudra422bf772019-12-02 11:10:16 +0200159 esac
160
161 archive_file "$dtb_saveas"
162}
163
164get_rootfs() {
165 local tmpdir
166 local fs_base="$(echo $(basename $rootfs_url) | sed 's/\.gz$//')"
167 local cached="$project_filer/ci-files/$fs_base"
168
169 if upon "$jenkins_run" && [ -f "$cached" ]; then
170 # Job workspace is limited in size, and the root file system is
171 # quite large. This means, parallel runs of root file system
172 # tests could fail. So, for Jenkins runs, copy and use the root
173 # file system image from the $CI_SCRATCH location
174 local private="$CI_SCRATCH/$JOB_NAME-$BUILD_NUMBER"
175 mkdir -p "$private"
176 rm -f "$private/rootfs.bin"
177 url="$cached" saveas="$private/rootfs.bin" fetch_file
178 ln -s "$private/rootfs.bin" "$archive/rootfs.bin"
179 return
180 fi
181
182 tmpdir="$(mktempdir)"
183 pushd "$tmpdir"
184 url="$rootfs_url" saveas="rootfs.bin" fetch_file
185
186 # Possibly, the filesystem image we just downloaded is compressed.
187 # Decompress it if required.
188 if file "rootfs.bin" | grep -iq 'gzip compressed data'; then
189 echo "Decompressing root file system image rootfs.bin ..."
190 gunzip --stdout "rootfs.bin" > uncompressed_fs.bin
191 mv uncompressed_fs.bin "rootfs.bin"
192 fi
193
194 archive_file "rootfs.bin"
195 popd
196}
197
Zelalem219df412020-05-17 19:21:20 -0500198fvp_romlib_jmptbl_backup="$(mktempdir)/jmptbl.i"
199
Fathi Boudra422bf772019-12-02 11:10:16 +0200200fvp_romlib_runtime() {
201 local tmpdir="$(mktempdir)"
202
203 # Save BL1 and romlib binaries from original build
204 mv "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin" "$tmpdir/romlib.bin"
205 mv "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin" "$tmpdir/bl1.bin"
206
207 # Patch index file
Zelalem219df412020-05-17 19:21:20 -0500208 cp "${tf_root:?}/plat/arm/board/fvp/jmptbl.i" "$fvp_romlib_jmptbl_backup"
209 sed -i '/fdt/ s/.$/&\ patch/' ${tf_root:?}/plat/arm/board/fvp/jmptbl.i
Fathi Boudra422bf772019-12-02 11:10:16 +0200210
211 # Rebuild with patched file
212 echo "Building patched romlib:"
213 build_tf
214
Fathi Boudra422bf772019-12-02 11:10:16 +0200215 # Retrieve original BL1 and romlib binaries
216 mv "$tmpdir/romlib.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin"
217 mv "$tmpdir/bl1.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin"
218}
219
Zelalem219df412020-05-17 19:21:20 -0500220fvp_romlib_cleanup() {
221 # Restore original index
222 mv "$fvp_romlib_jmptbl_backup" "${tf_root:?}/plat/arm/board/fvp/jmptbl.i"
223}
224
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500225
226fvp_gen_bin_url() {
227 local bin_mode="${bin_mode:?}"
228 local bin="${1:?}"
229
230 if upon "$jenkins_run"; then
231 echo "$jenkins_url/job/$JOB_NAME/$BUILD_NUMBER/artifact/artefacts/$bin_mode/$bin"
232 else
233 echo "file://$workspace/artefacts/$bin_mode/$bin"
234 fi
235}
236
237gen_fvp_yaml_template() {
238 local yaml_template_file="$workspace/fvp_template.yaml"
239
240 # must parameters for yaml generation
241 local payload_type="${payload_type:?}"
242
243 "$ci_root/script/gen_fvp_${payload_type}_yaml.sh" > "$yaml_template_file"
244
245 archive_file "$yaml_template_file"
246}
247
248gen_fvp_yaml() {
249 local yaml_template_file="$workspace/fvp_template.yaml"
250 local yaml_file="$workspace/fvp.yaml"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500251 local yaml_job_file="$workspace/job.yaml"
252 local lava_model_params="$workspace/lava_model_params"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500253
Leonardo Sandovalfda4f292020-10-06 15:59:26 -0500254 # this function expects a template, quit if it is not present
255 if [ ! -f "$yaml_template_file" ]; then
256 return
257 fi
258
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500259 # must parameters for yaml generation
260 local model="${model:?}"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500261
262 # optional parameters, defaults to globals
263 local model_name="${model_name:-$default_model_name}"
264 local model_dtb="${model_dtb:-$default_model_dtb}"
265 local model_dir="${model_dir:-$default_model_dir}"
266 local model_bin="${model_bin:-$default_model_bin}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500267
268 # general artefacts
269 bl1="$(fvp_gen_bin_url bl1.bin)"
270 fip="$(fvp_gen_bin_url fip.bin)"
271
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500272 dtb="$(fvp_gen_bin_url ${model_dtb})"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500273 image="$(fvp_gen_bin_url kernel.bin)"
274 ramdisk="$(fvp_gen_bin_url initrd.bin)"
275
Leonardo Sandoval44ac9aa2020-11-09 12:55:57 -0600276 # tftf's ns_bl[1|2]u.bin and el3_payload artefacts
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500277 ns_bl1u="$(fvp_gen_bin_url ns_bl1u.bin)"
278 ns_bl2u="$(fvp_gen_bin_url ns_bl2u.bin)"
Leonardo Sandoval44ac9aa2020-11-09 12:55:57 -0600279 el3_payload="$(fvp_gen_bin_url el3_payload.bin)"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500280
281 docker_registry="${docker_registry:-}"
282 docker_registry="$(docker_registry_append)"
283
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500284 docker_name="${docker_registry}$model_name"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500285
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500286 # generic version string
287 local version_string="\"Fast Models"' [^\\n]+'"\""
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500288
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500289 sed -e "s|\${ARMLMD_LICENSE_FILE}|${armlmd_license_file}|" \
290 -e "s|\${ACTIONS_DEPLOY_IMAGES_BL1}|${bl1}|" \
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500291 -e "s|\${ACTIONS_DEPLOY_IMAGES_FIP}|${fip}|" \
292 -e "s|\${ACTIONS_DEPLOY_IMAGES_DTB}|${dtb}|" \
293 -e "s|\${ACTIONS_DEPLOY_IMAGES_IMAGE}|${image}|" \
294 -e "s|\${ACTIONS_DEPLOY_IMAGES_RAMDISK}|${ramdisk}|" \
295 -e "s|\${ACTIONS_DEPLOY_IMAGES_NS_BL1U}|${ns_bl1u}|" \
296 -e "s|\${ACTIONS_DEPLOY_IMAGES_NS_BL2U}|${ns_bl2u}|" \
Leonardo Sandoval44ac9aa2020-11-09 12:55:57 -0600297 -e "s|\${ACTIONS_DEPLOY_IMAGES_EL3_PAYLOAD}|${el3_payload}|" \
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500298 -e "s|\${BOOT_DOCKER_NAME}|${docker_name}|" \
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500299 -e "s|\${BOOT_IMAGE_DIR}|${model_dir}|" \
300 -e "s|\${BOOT_IMAGE_BIN}|${model_bin}|" \
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500301 -e "s|\${BOOT_VERSION_STRING}|${version_string}|" \
302 < "$yaml_template_file" \
303 > "$yaml_file"
304
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500305 # LAVA expects 'macro' names for binaries, so replace them
306 sed -e "s|bl1.bin|{BL1}|" \
307 -e "s|fip.bin|{FIP}|" \
Leonardo Sandoval44ac9aa2020-11-09 12:55:57 -0600308 -e "s|ns_bl1u.bin|{NS_BL1U}|" \
309 -e "s|ns_bl2u.bin|{NS_BL2U}|" \
310 -e "s|el3_payload.bin|{EL3_PAYLOAD}|" \
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500311 -e "s|kernel.bin|{IMAGE}|" \
312 -e "s|initrd.bin|{RAMDISK}|" \
313 < "$archive/model_params" \
314 > "$lava_model_params"
315
316
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500317 # include the model parameters
318 while read -r line; do
319 if [ -n "$line" ]; then
320 yaml_line="- \"${line}\""
321 sed -i -e "/\${BOOT_ARGUMENTS}/i \ \ \ \ $yaml_line" "$yaml_file"
322 fi
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500323 done < "$lava_model_params"
324
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500325 sed -i -e '/\${BOOT_ARGUMENTS}/d' "$yaml_file"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500326 cp "$yaml_file" "$yaml_job_file"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500327
328 archive_file "$yaml_file"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500329 archive_file "$yaml_job_file"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500330}
331
332docker_registry_append() {
333 # if docker_registry is empty, just use local docker registry
334 [ -z "$docker_registry" ] && return
335
336 local last=-1
337 local last_char="${docker_registry:last}"
338
339 if [ "$last_char" != '/' ]; then
340 docker_registry="${docker_registry}/";
341 fi
342 echo "$docker_registry"
343}
344
Fathi Boudra422bf772019-12-02 11:10:16 +0200345set +u