blob: 0c90bb7532938cab8384fced7d7426f8b43cc8cd [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Rupinderjit Singh385f17d2022-07-18 20:28:10 +01003# Copyright (c) 2020-2022, 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}"
Olivier Deprezdd9ed332021-07-02 12:07:17 +020026sp4_addr="${sp4_addr:-0x7600000}"
Manish Pandey1e7be852020-11-09 16:04:48 +000027# SPM out directories
28export spm_secure_out_dir="${spm_secure_out_dir:-secure_aem_v8a_fvp_clang}"
29export spm_non_secure_out_dir="${spm_non_secure_out_dir:-aem_v8a_fvp_clang}"
Manish Pandey3c435582020-07-15 12:14:26 +010030
Fathi Boudra422bf772019-12-02 11:10:16 +020031ns_bl1u_addr="${ns_bl1u_addr:-0x0beb8000}"
32fwu_fip_addr="${fwu_fip_addr:-0x08400000}"
33backup_fip_addr="${backup_fip_addr:-0x09000000}"
34romlib_addr="${romlib_addr:-0x03ff2000}"
35
36uboot32_fip_url="$linaro_release/fvp32-latest-busybox-uboot/fip.bin"
37
Alexei Fedorove405cc32020-09-30 18:13:55 +010038rootfs_url="$linaro_release/lt-vexpress64-openembedded_minimal-armv8-gcc-5.2_20170127-761.img.gz"
Fathi Boudra422bf772019-12-02 11:10:16 +020039
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050040# Default FVP model variables
Leonardo Sandovale1460662021-05-27 16:05:38 -050041default_model_dtb="dtb.bin"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050042
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060043# FVP containers and model paths
laurenw-arm35faeaa2021-05-03 14:28:17 -050044fvp_arm_std_library_11_12="fvp:fvp_arm_std_library_${model_version_11_12}_${model_build_11_12};/opt/model/FVP_ARM_Std_Library/models/${model_flavour_11_12}"
laurenw-armafdc3bc2022-09-14 15:31:42 -050045fvp_arm_std_library_11_16="fvp:fvp_arm_std_library_${model_version_11_16}_${model_build_11_16};/opt/model/FVP_ARM_Std_Library/FVP_Base"
46fvp_arm_std_library_11_17="fvp:fvp_arm_std_library_${model_version_11_17}_${model_build_11_17};/opt/model/FVP_ARM_Std_Library/FVP_Base"
Maksims Svecovs284a50d2021-11-02 11:09:47 +000047fvp_arm_std_library="fvp:fvp_arm_std_library_${model_version}_${model_build};/opt/model/FVP_ARM_Std_Library/FVP_Base"
laurenw-armafdc3bc2022-09-14 15:31:42 -050048fvp_base_aemva="fvp:fvp_base_aemva_${model_version}_${model_build};/opt/model/FVP_Base_AEMvA/models/${model_flavour}"
laurenw-armf414aba2021-04-26 15:58:56 -050049fvp_base_revc_2xaemva="fvp:fvp_base_revc-2xaemva_${model_version}_${model_build};/opt/model/Base_RevC_AEMvA_pkg/models/${model_flavour}"
laurenw-armafdc3bc2022-09-14 15:31:42 -050050fvp_base_aemv8a_gic600ae="fvp:fvp_base_aemv8a-gic600ae_${model_version_11_17}_${model_build_11_17};/opt/model/FVP_Base_AEMv8A-GIC600AE_pkg/models/${model_flavour_11_17}"
51fvp_base_aemv8a_aemv8a_aemv8a_aemv8a_ccn502="fvp:fvp_base_aemv8a-aemv8a-aemv8a-aemv8a-ccn502_${model_version_11_17}_${model_build_11_17};/opt/model/FVP_Base_AEMv8A-AEMv8A-AEMv8A-AEMv8A-CCN502_pkg/models/${model_flavour_11_17}"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060052foundation_platform="fvp:foundation_platform_${model_version}_${model_build};/opt/model/Foundation_Platformpkg/models/${model_flavour}"
johpow01936638d2021-11-08 18:22:24 -060053fvp_base_aemv8r="fvp:fvp_base_aemv8r_${model_version}_${model_build};/opt/model/AEMv8R_base_pkg/models/${model_flavour}"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050054
Manish V Badarkhef65f9a32022-11-04 10:07:19 +000055# CSS model list
56fvp_morello="fvp:fvp_morello_0.11_33;/opt/model/FVP_Morello/models/Linux64_GCC-6.4"
57fvp_rd_e1_edge="fvp:fvp_rd_e1_edge_11.17_29;/opt/model/FVP_RD_E1_edge/models/${model_flavour}"
58fvp_rd_n1_edge="fvp:fvp_rd_n1_edge_11.17_29;/opt/model/FVP_RD_N1_edge/models/${model_flavour}"
59fvp_rd_v1="fvp:fvp_rd_v1_11.17_29;/opt/model/FVP_RD_V1/models/${model_flavour}"
60fvp_tc0="fvp:fvp_tc0_11.17_18;/opt/model/FVP_TC0/models/${model_flavour}"
61fvp_tc1="fvp:fvp_tc1_11.17_33;/opt/model/FVP_TC1/models/${model_flavour}"
62fvp_tc2="fvp:fvp_tc2_11.18_28;/opt/model/FVP_TC2/models/${model_flavour}"
63
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060064# FVP associate array, run_config are keys and fvp container parameters are the values
65# Container parameters syntax: <model name>;<model dir>;<model bin>
66# FIXMEs: fix those ;;; values with real values
67
68declare -A fvp_models
69fvp_models=(
Manish V Badarkhe253a1602022-11-09 09:22:44 +000070[base-aemv8a-quad]="${fvp_base_aemv8a_aemv8a_aemv8a_aemv8a_ccn502};FVP_Base_AEMv8A-AEMv8A-AEMv8A-AEMv8A-CCN502"
laurenw-armafdc3bc2022-09-14 15:31:42 -050071[base-aemv8a-revb]="${fvp_arm_std_library};FVP_Base_AEMvA-AEMvA"
72[base-aemv8a-latest-revb]="${fvp_arm_std_library};FVP_Base_AEMvA-AEMvA"
Manish V Badarkhe253a1602022-11-09 09:22:44 +000073[base-aemva]="${fvp_base_aemva};FVP_Base_AEMvA"
74[base-aemv8a-gic600ae]="${fvp_base_aemv8a_gic600ae};FVP_Base_AEMv8A-GIC600AE"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060075[foundationv8]="${foundation_platform};Foundation_Platform"
laurenw-armf414aba2021-04-26 15:58:56 -050076[base-aemv8a]="${fvp_base_revc_2xaemva};FVP_Base_RevC-2xAEMvA"
laurenw-arm35faeaa2021-05-03 14:28:17 -050077[cortex-a32x4]="${fvp_arm_std_library_11_12};FVP_Base_Cortex-A32x4"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060078[cortex-a35x4]="${fvp_arm_std_library};FVP_Base_Cortex-A35x4"
79[cortex-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A53x4"
laurenw-armafdc3bc2022-09-14 15:31:42 -050080[cortex-a55x4]="${fvp_arm_std_library};FVP_Base_Cortex-A55"
Leonardo Sandoval95f896b2021-02-22 10:16:29 -060081[cortex-a55x4-a75x4]="${fvp_arm_std_library};FVP_Base_Cortex-A55x4+Cortex-A75x4"
82[cortex-a55x4-a76x2]="${fvp_arm_std_library};FVP_Base_Cortex-A55x4+Cortex-A76x2"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060083[cortex-a57x1-a53x1]="${fvp_arm_std_library};FVP_Base_Cortex-A57x1-A53x1"
84[cortex-a57x2-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57x2-A53x4"
85[cortex-a57x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57x4"
86[cortex-a57x4-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57x4-A53x4"
laurenw-armafdc3bc2022-09-14 15:31:42 -050087[cortex-a65aex8]="${fvp_arm_std_library};FVP_Base_Cortex-A65AE"
88[cortex-a65x4]="${fvp_arm_std_library};FVP_Base_Cortex-A65"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060089[cortex-a72x4]="${fvp_arm_std_library};FVP_Base_Cortex-A72x4"
90[cortex-a72x4-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A72x4-A53x4"
91[cortex-a73x4]="${fvp_arm_std_library};FVP_Base_Cortex-A73x4"
92[cortex-a73x4-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A73x4-A53x4"
laurenw-armafdc3bc2022-09-14 15:31:42 -050093[cortex-a75x4]="${fvp_arm_std_library};FVP_Base_Cortex-A75"
94[cortex-a76aex4]="${fvp_arm_std_library};FVP_Base_Cortex-A76AE"
95[cortex-a76aex2]="${fvp_arm_std_library};FVP_Base_Cortex-A76AE"
96[cortex-a76x4]="${fvp_arm_std_library};FVP_Base_Cortex-A76"
97[cortex-a77x4]="${fvp_arm_std_library};FVP_Base_Cortex-A77"
98[cortex-a78x4]="${fvp_arm_std_library};FVP_Base_Cortex-A78"
99[cortex-a78cx4]="${fvp_arm_std_library};FVP_Base_Cortex-A78C"
100[cortex-x2]="${fvp_arm_std_library_11_17};FVP_Base_Cortex-X2x4"
101[cortex-a710]="${fvp_arm_std_library_11_17};FVP_Base_Cortex-A710x4"
102[neoverse_e1x1]="${fvp_arm_std_library};FVP_Base_Neoverse-E1"
103[neoverse_e1x2]="${fvp_arm_std_library};FVP_Base_Neoverse-E1"
104[neoverse_e1x4]="${fvp_arm_std_library};FVP_Base_Neoverse-E1"
105[neoverse_n1]="${fvp_arm_std_library};FVP_Base_Neoverse-N1"
106[neoverse_n2]="${fvp_arm_std_library_11_16};FVP_Base_Neoverse-N1x4"
107[neoverse-v1x4]="${fvp_arm_std_library};FVP_Base_Neoverse-V1"
Manish V Badarkhef65f9a32022-11-04 10:07:19 +0000108[morello]="${fvp_morello};FVP_Morello"
109[css-rde1edge]="${fvp_rd_e1_edge};FVP_RD_E1_edge"
110[css-rdn1edgex2]="${fvp_rd_n1_edge};FVP_RD_N1_edge_dual"
111[css-rdv1]="${fvp_rd_v1};FVP_RD_V1"
112[tc0]="${fvp_tc0};FVP_TC0"
113[tc1]="${fvp_tc1};FVP_TC1"
114[tc2]="${fvp_tc2};FVP_TC2"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600115)
116
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500117
Fathi Boudra422bf772019-12-02 11:10:16 +0200118# FVP Kernel URLs
119declare -A fvp_kernels
120fvp_kernels=(
121[fvp-aarch32-zimage]="$linaro_release/fvp32-latest-busybox-uboot/Image"
122[fvp-busybox-uboot]="$linaro_release/fvp-latest-busybox-uboot/Image"
123[fvp-oe-uboot32]="$linaro_release/fvp32-latest-oe-uboot/Image"
124[fvp-oe-uboot]="$linaro_release/fvp-latest-oe-uboot/Image"
125[fvp-quad-busybox-uboot]="$tfa_downloads/quad_cluster/Image"
126)
127
Fathi Boudra422bf772019-12-02 11:10:16 +0200128# FVP initrd URLs
129declare -A fvp_initrd_urls
130fvp_initrd_urls=(
131[aarch32-ramdisk]="$linaro_release/fvp32-latest-busybox-uboot/ramdisk.img"
Fathi Boudra422bf772019-12-02 11:10:16 +0200132[dummy-ramdisk]="$linaro_release/fvp-latest-oe-uboot/ramdisk.img"
133[dummy-ramdisk32]="$linaro_release/fvp32-latest-oe-uboot/ramdisk.img"
134[default]="$linaro_release/fvp-latest-busybox-uboot/ramdisk.img"
135)
136
Fathi Boudra422bf772019-12-02 11:10:16 +0200137get_optee_bin() {
Sandrine Bailleux25ff2942021-02-25 14:00:10 +0100138 url="$tfa_downloads/optee/tee.bin" \
139 saveas="bl32.bin" fetch_file
Fathi Boudra422bf772019-12-02 11:10:16 +0200140 archive_file "bl32.bin"
141}
142
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100143# For Measured Boot tests using a TA based on OPTEE, it is necessary to use a
144# specific build rather than the default one generated by Jenkins.
145get_ftpm_optee_bin() {
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100146 url="$tfa_downloads/ftpm/optee/tee-header_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100147 saveas="bl32.bin" fetch_file
148 archive_file "bl32.bin"
149
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100150 url="$tfa_downloads/ftpm/optee/tee-pager_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100151 saveas="bl32_extra1.bin" fetch_file
152 archive_file "bl32_extra1.bin"
153
Leonardo Sandovalda5f78d2021-03-18 11:09:30 -0600154 # tee-pageable_v2.bin is just a empty file, named as bl32_extra2.bin,
155 # so just create the file
156 touch "bl32_extra2.bin"
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100157 archive_file "bl32_extra2.bin"
158}
159
Fathi Boudra422bf772019-12-02 11:10:16 +0200160get_uboot32_bin() {
161 local tmpdir="$(mktempdir)"
162
163 pushd "$tmpdir"
164 extract_fip "$uboot32_fip_url"
165 mv "nt-fw.bin" "uboot.bin"
166 archive_file "uboot.bin"
167 popd
168}
169
170get_uboot_bin() {
171 local uboot_url="$linaro_release/fvp-latest-busybox-uboot/bl33-uboot.bin"
172
173 url="$uboot_url" saveas="uboot.bin" fetch_file
174 archive_file "uboot.bin"
175}
176
177get_uefi_bin() {
Zelalem219df412020-05-17 19:21:20 -0500178 uefi_downloads="${uefi_downloads:-http://files.oss.arm.com/downloads/uefi}"
179 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 +0200180
181 url=$uefi_ci_bin_url saveas="uefi.bin" fetch_file
182 archive_file "uefi.bin"
183}
184
185get_kernel() {
186 local kernel_type="${kernel_type:?}"
187 local url="${fvp_kernels[$kernel_type]}"
188
189 url="${url:?}" saveas="kernel.bin" fetch_file
190 archive_file "kernel.bin"
191}
192
193get_initrd() {
194 local initrd_type="${initrd_type:?}"
195 local url="${fvp_initrd_urls[$initrd_type]}"
196
197 url="${url:?}" saveas="initrd.bin" fetch_file
198 archive_file "initrd.bin"
199}
200
201get_dtb() {
202 local dtb_type="${dtb_type:?}"
203 local dtb_url
204 local dtb_saveas="$workspace/dtb.bin"
Zelalem219df412020-05-17 19:21:20 -0500205 local cc="$(get_tf_opt CROSS_COMPILE)"
206 local pp_flags="-P -nostdinc -undef -x assembler-with-cpp"
Fathi Boudra422bf772019-12-02 11:10:16 +0200207
208 case "$dtb_type" in
209 "fvp-base-quad-cluster-gicv3-psci")
210 # Get the quad-cluster FDT from pdsw area
211 dtb_url="$tfa_downloads/quad_cluster/fvp-base-quad-cluster-gicv3-psci.dtb"
212 url="$dtb_url" saveas="$dtb_saveas" fetch_file
213 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200214 *)
Zelalem219df412020-05-17 19:21:20 -0500215 # Preprocess DTS file
216 ${cc}gcc -E ${pp_flags} -I"$tf_root/fdts" -I"$tf_root/include" \
217 -o "$workspace/${dtb_type}.pre.dts" \
218 "$tf_root/fdts/${dtb_type}.dts"
219 # Generate DTB file from DTS
Fathi Boudra422bf772019-12-02 11:10:16 +0200220 dtc -I dts -O dtb \
Zelalem219df412020-05-17 19:21:20 -0500221 "$workspace/${dtb_type}.pre.dts" -o "$dtb_saveas"
Fathi Boudra422bf772019-12-02 11:10:16 +0200222 esac
223
224 archive_file "$dtb_saveas"
225}
226
227get_rootfs() {
228 local tmpdir
229 local fs_base="$(echo $(basename $rootfs_url) | sed 's/\.gz$//')"
230 local cached="$project_filer/ci-files/$fs_base"
231
232 if upon "$jenkins_run" && [ -f "$cached" ]; then
233 # Job workspace is limited in size, and the root file system is
234 # quite large. This means, parallel runs of root file system
235 # tests could fail. So, for Jenkins runs, copy and use the root
236 # file system image from the $CI_SCRATCH location
237 local private="$CI_SCRATCH/$JOB_NAME-$BUILD_NUMBER"
238 mkdir -p "$private"
239 rm -f "$private/rootfs.bin"
240 url="$cached" saveas="$private/rootfs.bin" fetch_file
241 ln -s "$private/rootfs.bin" "$archive/rootfs.bin"
242 return
243 fi
244
245 tmpdir="$(mktempdir)"
246 pushd "$tmpdir"
247 url="$rootfs_url" saveas="rootfs.bin" fetch_file
248
249 # Possibly, the filesystem image we just downloaded is compressed.
250 # Decompress it if required.
251 if file "rootfs.bin" | grep -iq 'gzip compressed data'; then
252 echo "Decompressing root file system image rootfs.bin ..."
253 gunzip --stdout "rootfs.bin" > uncompressed_fs.bin
254 mv uncompressed_fs.bin "rootfs.bin"
255 fi
256
257 archive_file "rootfs.bin"
258 popd
259}
260
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200261fvp_romlib_jmptbl_backup="$(mktempdir)/jmptbl.i"
262
Fathi Boudra422bf772019-12-02 11:10:16 +0200263fvp_romlib_runtime() {
264 local tmpdir="$(mktempdir)"
265
266 # Save BL1 and romlib binaries from original build
267 mv "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin" "$tmpdir/romlib.bin"
268 mv "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin" "$tmpdir/bl1.bin"
269
270 # Patch index file
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200271 cp "${tf_root:?}/plat/arm/board/fvp/jmptbl.i" "$fvp_romlib_jmptbl_backup"
272 sed -i '/fdt/ s/.$/&\ patch/' ${tf_root:?}/plat/arm/board/fvp/jmptbl.i
Fathi Boudra422bf772019-12-02 11:10:16 +0200273
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200274 # Rebuild with patched file
275 echo "Building patched romlib:"
276 build_tf
Fathi Boudra422bf772019-12-02 11:10:16 +0200277
Fathi Boudra422bf772019-12-02 11:10:16 +0200278 # Retrieve original BL1 and romlib binaries
279 mv "$tmpdir/romlib.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin"
280 mv "$tmpdir/bl1.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin"
281}
282
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200283fvp_romlib_cleanup() {
284 # Restore original index
285 mv "$fvp_romlib_jmptbl_backup" "${tf_root:?}/plat/arm/board/fvp/jmptbl.i"
286}
287
288
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500289fvp_gen_bin_url() {
290 local bin_mode="${bin_mode:?}"
291 local bin="${1:?}"
292
293 if upon "$jenkins_run"; then
294 echo "$jenkins_url/job/$JOB_NAME/$BUILD_NUMBER/artifact/artefacts/$bin_mode/$bin"
295 else
296 echo "file://$workspace/artefacts/$bin_mode/$bin"
297 fi
298}
299
Chris Kayfbbf1322022-10-05 13:13:32 +0100300# Generates the template for YAML-based LAVA job definitions from a file
301# corresponding to the currently-selected payload, e.g.:
302#
303# - `lava-templates/fvp-linux.yaml`
304# - `lava-templates/fvp-tftf.yaml`
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500305gen_fvp_yaml_template() {
Chris Kayfbbf1322022-10-05 13:13:32 +0100306 local yaml_template_file="${workspace}/fvp_template.yaml"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500307
Chris Kayc9523b12022-10-10 18:32:20 +0100308 cp "${ci_root}/script/lava-templates/fvp-${payload_type:?}.yaml" \
309 "${yaml_template_file}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500310
Chris Kayfbbf1322022-10-05 13:13:32 +0100311 archive_file "${yaml_template_file}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500312}
313
Chris Kayc9523b12022-10-10 18:32:20 +0100314# Generates the final YAML-based LAVA job definition from a template file.
315#
316# The job definition template is expanded with visibility of all variables that
317# are available from within the function, including those with local scope.
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500318gen_fvp_yaml() {
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600319 local model="${model:?}"
320
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500321 local yaml_template_file="$workspace/fvp_template.yaml"
322 local yaml_file="$workspace/fvp.yaml"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500323 local yaml_job_file="$workspace/job.yaml"
324 local lava_model_params="$workspace/lava_model_params"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500325
Leonardo Sandovalfda4f292020-10-06 15:59:26 -0500326 # this function expects a template, quit if it is not present
327 if [ ! -f "$yaml_template_file" ]; then
328 return
329 fi
330
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600331 local model_params="${fvp_models[$model]}"
332 local model_name="$(echo "${model_params}" | awk -F ';' '{print $1}')"
333 local model_dir="$(echo "${model_params}" | awk -F ';' '{print $2}')"
334 local model_bin="$(echo "${model_params}" | awk -F ';' '{print $3}')"
335
336 # model params are required for correct yaml creation, quit if empty
337 if [ -z "${model_name}" ]; then
338 echo "FVP model param 'model_name' variable empty, yaml not produced"
339 return
340 elif [ -z "${model_dir}" ]; then
341 echo "FVP model param 'model_dir' variable empty, yaml not produced"
342 return
343 elif [ -z "${model_bin}" ]; then
344 echo "FVP model param 'model_bin' variable empty, yaml not produced"
345 return
346 fi
347
348 echo "FVP model params: model_name=$model_name model_dir=$model_dir model_bin=$model_bin"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500349
350 # optional parameters, defaults to globals
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500351 local model_dtb="${model_dtb:-$default_model_dtb}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500352
Chris Kayc9523b12022-10-10 18:32:20 +0100353 if [ -n "${GERRIT_CHANGE_NUMBER}" ]; then
354 local gerrit_url="https://review.trustedfirmware.org/c/${GERRIT_CHANGE_NUMBER}/${GERRIT_PATCHSET_NUMBER}"
355 elif [ -n "${GERRIT_REFSPEC}" ]; then
356 local gerrit_url=$(echo ${GERRIT_REFSPEC} |
357 awk -F/ '{print "https://review.trustedfirmware.org/c/" $4 "/" $5}')
358 fi
359
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500360 docker_registry="${docker_registry:-}"
361 docker_registry="$(docker_registry_append)"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500362 docker_name="${docker_registry}$model_name"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600363 prompt1='/ #'
364 prompt2='root@genericarmv8:~#'
365 version_string="\"Fast Models"' [^\\n]+'"\""
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500366
Leonardo Sandoval5d87b702021-05-10 11:53:13 -0500367 test_config="${TEST_CONFIG}"
368
Chris Kay4eb9ded2022-10-10 15:51:40 +0100369 declare -A artefact_filters=(
370 [backup_fip]="backup_fip.bin"
371 [bl1]="bl1.bin"
372 [bl2]="bl2.bin"
373 [bl31]="bl31.bin"
374 [bl32]="bl32.bin"
375 [busybox]="busybox.bin"
376 [cactus_primary]="cactus-primary.pkg"
377 [cactus_secondary]="cactus-secondary.pkg"
378 [cactus_tertiary]="cactus-tertiary.pkg"
379 [coverage_trace_plugin]="coverage_trace.so"
380 [dtb]="dtb.bin"
381 [el3_payload]="el3_payload.bin"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000382 [ete_trace]="libete-plugin.so"
383 [etm_trace]="ETMv4ExamplePlugin.so"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100384 [fip_gpt]="fip_gpt.bin"
385 [fip]="fip.bin"
386 [fvp_spmc_manifest_dtb]="=fvp_spmc_manifest.dtb"
387 [fwu_fip]="fwu_fip.bin"
388 [generic_trace]="GenericTrace.so"
389 [hafnium]="hafnium.bin"
390 [image]="kernel.bin"
391 [ivy]="ivy.pkg"
392 [manifest_dtb]="=manifest.dtb"
Chris Kayfbdd0142022-11-08 12:24:30 +0000393 [mcp_fw]="mcp_fw.bin"
Manish V Badarkhe18c59782022-11-09 10:14:48 +0000394 [mcp_ram]="mcp_ram.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100395 [mcp_rom_hyphen]="mcp-rom.bin"
396 [mcp_rom]="mcp_rom.bin"
397 [ns_bl1u]="ns_bl1u.bin"
398 [ns_bl2u]="ns_bl2u.bin"
399 [ramdisk]="initrd.bin|initrd.img"
400 [romlib]="romlib.bin"
401 [rootfs]="rootfs.bin"
Manish V Badarkhe93093dd2022-11-09 10:29:27 +0000402 [rss_flash]="rss_flash.bin"
403 [rss_rom]="rss_rom.bin"
Chris Kayfbdd0142022-11-08 12:24:30 +0000404 [scp_fw]="scp_fw.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100405 [scp_ram_hyphen]="scp-ram.bin"
406 [scp_ram]="scp_ram.bin"
407 [scp_rom_hyphen]="scp-rom.bin"
408 [scp_rom]="scp_rom.bin"
409 [secure_hafnium]="secure_hafnium.bin"
410 [spm]="spm.bin"
411 [tftf]="tftf.bin"
412 [tmp]="tmp.bin"
413 [uboot]="uboot.bin"
414 )
415
Chris Kayc14743a2022-10-13 11:33:26 +0100416 declare -A artefact_urls=(
417 [backup_fip]="$(fvp_gen_bin_url backup_fip.bin)"
418 [bl1]="$(fvp_gen_bin_url bl1.bin)"
419 [bl2]="$(fvp_gen_bin_url bl2.bin)"
420 [bl31]="$(fvp_gen_bin_url bl31.bin)"
421 [bl32]="$(fvp_gen_bin_url bl32.bin)"
422 [busybox]="$(fvp_gen_bin_url busybox.bin.gz)"
423 [cactus_primary]="$(fvp_gen_bin_url cactus-primary.pkg)"
424 [cactus_secondary]="$(fvp_gen_bin_url cactus-secondary.pkg)"
425 [cactus_tertiary]="$(fvp_gen_bin_url cactus-tertiary.pkg)"
426 [coverage_trace_plugin]="${coverage_trace_plugin}"
427 [dtb]="$(fvp_gen_bin_url ${model_dtb})"
428 [el3_payload]="$(fvp_gen_bin_url el3_payload.bin)"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000429 [ete_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/libete-plugin.so"
430 [etm_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/ETMv4ExamplePlugin.so"
Chris Kayc14743a2022-10-13 11:33:26 +0100431 [fip]="$(fvp_gen_bin_url fip.bin)"
432 [fip_gpt]="$(fvp_gen_bin_url fip_gpt.bin)"
433 [fvp_spmc_manifest_dtb]="$(fvp_gen_bin_url fvp_spmc_manifest.dtb)"
434 [fwu_fip]="$(fvp_gen_bin_url fwu_fip.bin)"
435 [generic_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/GenericTrace.so"
436 [hafnium]="$(fvp_gen_bin_url hafnium.bin)"
437 [image]="$(fvp_gen_bin_url kernel.bin)"
438 [ivy]="$(fvp_gen_bin_url ivy.pkg)"
439 [manifest_dtb]="$(fvp_gen_bin_url manifest.dtb)"
Chris Kayfbdd0142022-11-08 12:24:30 +0000440 [mcp_fw]="$(fvp_gen_bin_url mcp_fw.bin)"
Manish V Badarkhe18c59782022-11-09 10:14:48 +0000441 [mcp_ram]="$(fvp_gen_bin_url mcp_ram.bin)"
Chris Kayc14743a2022-10-13 11:33:26 +0100442 [mcp_rom]="$(fvp_gen_bin_url mcp_rom.bin)"
443 [mcp_rom_hyphen]="$(fvp_gen_bin_url mcp-rom.bin)"
444 [ns_bl1u]="$(fvp_gen_bin_url ns_bl1u.bin)"
445 [ns_bl2u]="$(fvp_gen_bin_url ns_bl2u.bin)"
446 [ramdisk]="$(fvp_gen_bin_url initrd.bin)"
447 [romlib]="$(fvp_gen_bin_url romlib.bin)"
448 [rootfs]="$(fvp_gen_bin_url rootfs.bin.gz)"
Manish V Badarkhe93093dd2022-11-09 10:29:27 +0000449 [rss_flash]="$(fvp_gen_bin_url rss_flash.bin)"
450 [rss_rom]="$(fvp_gen_bin_url rss_rom.bin)"
Chris Kayc14743a2022-10-13 11:33:26 +0100451 [secure_hafnium]="$(fvp_gen_bin_url secure_hafnium.bin)"
Chris Kayfbdd0142022-11-08 12:24:30 +0000452 [scp_fw]="$(fvp_gen_bin_url scp_fw.bin)"
Chris Kayc14743a2022-10-13 11:33:26 +0100453 [scp_ram]="$(fvp_gen_bin_url scp_ram.bin)"
454 [scp_ram_hyphen]="$(fvp_gen_bin_url scp-ram.bin)"
455 [scp_rom]="$(fvp_gen_bin_url scp_rom.bin)"
456 [scp_rom_hyphen]="$(fvp_gen_bin_url scp-rom.bin)"
457 [spm]="$(fvp_gen_bin_url spm.bin)"
458 [tftf]="$(fvp_gen_bin_url tftf.bin)"
459 [tmp]="$(fvp_gen_bin_url tmp.bin)"
460 [uboot]="$(fvp_gen_bin_url uboot.bin)"
461 )
462
Chris Kay5d550d82022-10-12 17:20:31 +0100463 # In LAVA we don't provide the paths to the artefacts directly, but instead
464 # use macros of the form `{XYZ}`. This is a list of regular expression
465 # replacements to run on the model parameters file before we add them to the
466 # LAVA job definition.
467 declare -A artefact_macros=(
468 ["[= ]backup_fip.bin"]="={BACKUP_FIP}"
469 ["[= ]bl1.bin"]="={BL1}"
470 ["[= ]bl2.bin"]="={BL2}"
471 ["[= ]bl31.bin"]="={BL31}"
472 ["[= ]bl32.bin"]="={BL32}"
473 ["[= ]cactus-primary.pkg"]="={CACTUS_PRIMARY}"
474 ["[= ]cactus-secondary.pkg"]="={CACTUS_SECONDARY}"
475 ["[= ]cactus-tertiary.pkg"]="={CACTUS_TERTIARY}"
476 ["[= ].*coverage_trace.so"]="={COVERAGE_TRACE_PLUGIN}"
477 ["[= ]fvp_spmc_manifest.dtb"]="={FVP_SPMC_MANIFEST_DTB}"
478 ["[= ]busybox.bin"]="={BUSYBOX}"
479 ["[= ]dtb.bin"]="={DTB}"
480 ["[= ]el3_payload.bin"]="={EL3_PAYLOAD}"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000481 ["[= ].*libete-plugin.so"]="={ETE_TRACE}"
482 ["[= ].*ETMv4ExamplePlugin.so"]="={ETM_TRACE}"
Chris Kay5d550d82022-10-12 17:20:31 +0100483 ["[= ]fip_gpt.bin"]="={FIP_GPT}"
484 ["[= ]fwu_fip.bin"]="={FWU_FIP}"
485 ["[= ]fip.bin"]="={FIP}"
486 ["[= ].*GenericTrace.so"]="={GENERIC_TRACE}"
487 ["[= ].*/hafnium.bin"]="={HAFNIUM}"
488 ["[= ]kernel.bin"]="={IMAGE}"
489 ["[= ]ivy.pkg"]="={IVY}"
490 ["[= ]manifest.dtb"]="={MANIFEST_DTB}"
Chris Kayfbdd0142022-11-08 12:24:30 +0000491 ["[= ]mcp_fw.bin"]="={MCP_FW}"
Manish V Badarkhe18c59782022-11-09 10:14:48 +0000492 ["[= ]mcp_ram.bin"]="={MCP_RAM}"
Chris Kayef9cc802022-11-08 12:11:58 +0000493 ["[= ]mcp_rom.bin"]="={MCP_ROM}"
494 ["[= ]mcp-rom.bin"]="={MCP_ROM_HYPHEN}"
Chris Kay5d550d82022-10-12 17:20:31 +0100495 ["[= ]ns_bl1u.bin"]="={NS_BL1U}"
496 ["[= ]ns_bl2u.bin"]="={NS_BL2U}"
497 ["[= ]initrd.bin"]="={RAMDISK}"
498 ["[= ]initrd.img"]="={RAMDISK}"
499 ["[= ]romlib.bin"]="={ROMLIB}"
500 ["[= ]rootfs.bin"]="={ROOTFS}"
Manish V Badarkhe93093dd2022-11-09 10:29:27 +0000501 ["[= ]rss_flash.bin"]="={RSS_FLASH}"
502 ["[= ]rss_rom.bin"]="={RSS_ROM}"
Chris Kay5d550d82022-10-12 17:20:31 +0100503 ["[= ].*/secure_hafnium.bin"]="={SECURE_HAFNIUM}"
Chris Kayfbdd0142022-11-08 12:24:30 +0000504 ["[= ]scp_fw.bin"]="={SCP_FW}"
Chris Kay5d550d82022-10-12 17:20:31 +0100505 ["[= ]scp_ram.bin"]="={SCP_RAM}"
506 ["[= ]scp-ram.bin"]="={SCP_RAM_HYPHEN}"
507 ["[= ]scp_rom.bin"]="={SCP_ROM}"
508 ["[= ]scp-rom.bin"]="={SCP_ROM_HYPHEN}"
509 ["[= ]spm.bin"]="={SPM}"
510 ["[= ]tftf.bin"]="={TFTF}"
511 ["[= ].*/tmp.bin"]="={TMP}"
512 ["[= ]uboot.bin"]="={UBOOT}"
513 )
514
Chris Kay4eb9ded2022-10-10 15:51:40 +0100515 declare -a artefacts=()
516
517 for artefact in "${!artefact_filters[@]}"; do
518 if grep -E -q "${artefact_filters[${artefact}]}" "${archive}/model_params"; then
519 artefacts+=("${artefact}")
520 fi
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600521 done
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500522
Chris Kayc92d9fc2022-10-13 11:19:27 +0100523 # Derive LAVA model parameters from the non-LAVA ones
524 cp "${archive}/model_params" "${lava_model_params}"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600525
Chris Kayf07d3392022-10-26 15:42:48 +0100526 # Ensure braces in the FVP model parameters are not accidentally interpreted
527 # as LAVA macros.
528 sed -i -e 's/{/{{/g' "${lava_model_params}"
529 sed -i -e 's/}/}}/g' "${lava_model_params}"
530
Chris Kay5d550d82022-10-12 17:20:31 +0100531 # LAVA expects FVP binary paths as macros, i.e. `{X}` instead of `x.bin`, so
532 # replace the file paths in our pre-generated model parameters.
533 for regex in "${!artefact_macros[@]}"; do
534 sed -i -e "s!${regex}!${artefact_macros[${regex}]}!" \
535 "${lava_model_params}"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600536 done
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500537
Chris Kayc92d9fc2022-10-13 11:19:27 +0100538 # Read boot arguments into an array so that the job template file can
539 # iterate over them.
540 readarray -t boot_arguments < "${lava_model_params}"
541
Chris Kay04b70192022-10-19 17:03:37 +0100542 # Source runtime environment variables now so that they are accessible from
543 # the LAVA job template.
544 local run_root="${archive}/run"
545 local run_env="${run_root}/env"
546
547 if [ -f "${run_env}" ]; then
548 source "${run_env}"
549 fi
550
Chris Kayc92d9fc2022-10-13 11:19:27 +0100551 # Generate the LAVA job definition, minus the test expectations
552 expand_template "${yaml_template_file}" > "${yaml_file}"
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500553
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500554 # Append expect commands into the job definition through test-interactive commands
555 gen_fvp_yaml_expect >> "$yaml_file"
556
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600557 # create job.yaml
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500558 cp "$yaml_file" "$yaml_job_file"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500559
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600560 # archive both yamls
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500561 archive_file "$yaml_file"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500562 archive_file "$yaml_job_file"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500563}
564
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500565gen_fvp_yaml_expect() {
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500566 # Loop through all uarts expect files
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500567 for expect_file in $(find $run_root -name expect); do
Chris Kay04b70192022-10-19 17:03:37 +0100568 local uart_number=$(basename "$(dirname ${expect_file})")
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500569
Chris Kay04b70192022-10-19 17:03:37 +0100570 # Only handle the primary UART through LAVA. The remaining UARTs are
571 # validated after LAVA returns by the post-expect script.
Chris Kay03ffbe72022-11-17 18:53:50 +0000572 if [ "${uart_number:?}" != "uart$(get_primary_uart "${archive}")" ]; then
Chris Kay04b70192022-10-19 17:03:37 +0100573 continue
574 fi
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500575
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500576 # Array containing "interactive" or "monitor" expect strings and populated during run config execution.
577 # Interactive expect scripts are converted into LAVA Interactive Test Actions (see
578 # https://tf.validation.linaro.org/static/docs/v2/interactive.html#writing-tests-interactive) and
579 # monitor expect scripts are converted into LAVA Monitor Test Actions (see
580 # https://validation.linaro.org/static/docs/v2/actions-test.html#monitor)
581 #
582 # Interactive Expect strings have the format 'i;<prompt>;<succeses>;<failures>;<commands>'
583 # where multiple successes or failures or commands are separated by @
584 #
585 # Monitor Expect strings have the format 'm;<start>;<end>;<patterns>'
586 # where multiple patterns are separated by @
587 #
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500588 expect_string=()
589
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500590 # Get the real name of the expect file
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500591 expect_file=$(cat $expect_file)
592
593 # Source the run_config enviroment variables
594 env=$run_root/$uart_number/env
595 if [ -e $env ]; then
596 source $env
597 fi
598
599 # Get all expect strings
Chris Kay047af3e2022-09-30 17:10:28 +0100600 expect_dir="${ci_root}/expect-lava"
601 expect_file="${expect_dir}/${expect_file}"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500602
Chris Kay047af3e2022-09-30 17:10:28 +0100603 # Allow the expectations to be provided directly in LAVA's job YAML
604 # format, rather than converting it from a pseudo-Expect Bash script in
605 # the block below.
606 if [ -f "${expect_file/.exp/.yaml}" ]; then
607 pushd "${expect_dir}"
608 expand_template "${expect_file/.exp/.yaml}"
609 popd
610
611 continue
612 else
613 source "${expect_file}"
614 fi
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500615
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500616 if [ ${#expect_string[@]} -gt 0 ]; then
617
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500618 # expect loop
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500619 for key in "${!expect_string[@]}"; do
620
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500621 # single raw expect string
622 es="${expect_string[${key}]}"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500623
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500624 # action type: either m or i
625 action="$(echo "${es}" | awk -F ';' '{print $1}')"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500626
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500627 if [ "${action}" = "m" ]; then
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500628
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500629 start="$(echo "${es}" | awk -F ';' '{print $2}')"
630 end="$(echo "${es}" | awk -F ';' '{print $3}')"
631 patterns="$(echo "${es}" | awk -F ';' '{print $4}')"
632
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500633 cat << EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500634- test:
635 monitors:
636 - name: tests
637 start: '${start}'
638 end: '${end}'
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500639EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500640 # Patterns are separated by '@'
641 OLD_IFS=$IFS; IFS=$'@'
642 for p in ${patterns}; do
643 cat << EOF
644 pattern: '$p'
645EOF
646 done
647 IFS=$OLD_IFS
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500648 cat << EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500649 fixupdict:
650 PASS: pass
651 FAIL: fail
652EOF
653 fi # end of monitor action
654
655 if [ "${action}" = "i" ]; then
656
657 prompts="$(echo "${es}" | awk -F ';' '{print $2}')"
658 successes="$(echo "${es}" | awk -F ';' '{print $3}')"
659 failures="$(echo "${es}" | awk -F ';' '{print $4}')"
660 commands="$(echo "${es}" | awk -F ';' '{print $5}')"
661
662 cat << EOF
663- test:
664 interactive:
665EOF
666 OLD_IFS=$IFS; IFS=$'@'
667
668 if [[ -n "${prompts}" && -n "${successes}" && -n "${failures}" ]]; then
669 cat << EOF
670 - name: interactive_${uart_number}_${key}
671 prompts: ['${prompts}']
672 script:
673EOF
674 if [ -z "${commands}" ]; then
675 cat <<EOF
676 - name: interactive_command_${uart_number}_${key}
677 command:
678EOF
679 else
680 for c in ${commands}; do
681 cat <<EOF
682 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300683 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500684EOF
685 done
686 fi
687 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500688 successes:
689EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500690 for s in ${successes}; do
691 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500692 - message: '$s'
693EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500694 done
695 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500696 failures:
697EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500698 for f in ${failures}; do
699 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500700 - message: '$f'
701EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500702 done
703 elif [[ -n "${prompts}" && -n "${successes}" ]]; then
704 cat << EOF
705 - name: interactive_${uart_number}_${key}
706 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500707 script:
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500708EOF
709
710 if [ -z "${commands}" ]; then
711 cat <<EOF
712 - name: interactive_command_${uart_number}_${key}
713 command:
714EOF
715 else
716 for c in ${commands}; do
717 cat <<EOF
718 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300719 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500720EOF
721 done
722 fi
723 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500724 successes:
725EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500726 for s in ${successes}; do
727 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500728 - message: '$s'
729EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500730 done
731
732 elif [[ -n "${prompts}" && -n "${failures}" ]]; then
733 cat << EOF
734 - name: interactive_${uart_number}_${key}
735 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500736 script:
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500737EOF
738 if [ -z "${commands}" ]; then
739 cat <<EOF
740 - name: interactive_command_${uart_number}_${key}
741 command:
742EOF
743 else
744 for c in ${commands}; do
745 cat <<EOF
746 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300747 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500748EOF
749 done
750 fi
751 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500752 failures:
753EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500754 for f in ${failures}; do
755 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500756 - message: '$f'
757EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500758 done
759 else
760 cat << EOF
761 - name: interactive_${uart_number}_${key}
762 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500763 script:
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500764EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500765 if [ -z "${commands}" ]; then
766 cat <<EOF
767 - name: interactive_command_${uart_number}_${key}
768 command:
769EOF
770 else
771 for c in ${commands}; do
772 cat <<EOF
773 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300774 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500775EOF
776 done
777 fi
778 fi
779
780 IFS=$OLD_IFS
781 fi # end of interactive action
782
783 done # end of expect loop
784
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500785 fi
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500786 done # end of uart loop
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500787}
788
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500789docker_registry_append() {
790 # if docker_registry is empty, just use local docker registry
791 [ -z "$docker_registry" ] && return
792
793 local last=-1
794 local last_char="${docker_registry:last}"
795
796 if [ "$last_char" != '/' ]; then
797 docker_registry="${docker_registry}/";
798 fi
799 echo "$docker_registry"
800}
801
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000802# generate GPT image and archive it
803gen_gpt_bin() {
804 raw_image="fip_gpt.bin"
805 img_uuid="FB90808A-BA9A-4D42-B9A2-A7A937144AEE"
806 img_bank_uuid=`uuidgen`
807 disk_uuid=`uuidgen`
808 bin="${1:?}"
809
810 # maximum FIP size 2MB
811 fip_max_size=2097152
812 start_sector=34
813 sector_size=512
814 num_sectors=$(($fip_max_size/$sector_size))
815 bin_size=$(stat -c %s $bin)
816
817 if [[ $fip_max_size -lt $bin_size ]]
818 then
Manish V Badarkhe3640b062022-11-16 11:36:36 +0000819 echo "FIP binary ($bin_size bytes) larger than max partition 1" \
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000820 "size ($fip_max_size byte)"
821 return
822 fi
823
824 # create raw 5MB image
825 dd if=/dev/zero of=$raw_image bs=5M count=1
826
827 # create GPT image
828 sgdisk -a 1 -U $disk_uuid -n 1:$start_sector:+$num_sectors \
829 -c 1:FIP_A -t 1:$img_uuid $raw_image -u $img_bank_uuid
830
831 echo "write binary $bin at sector $start_sector"
832 dd if=$bin of=$raw_image bs=$sector_size seek=$start_sector \
833 count=$num_sectors conv=notrunc
834
835 archive_file "fip_gpt.bin"
836}
837
Fathi Boudra422bf772019-12-02 11:10:16 +0200838set +u