blob: c3e601fd3d65502a1fc051ffd4d824a007c792e7 [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
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060055# FVP associate array, run_config are keys and fvp container parameters are the values
56# Container parameters syntax: <model name>;<model dir>;<model bin>
57# FIXMEs: fix those ;;; values with real values
58
59declare -A fvp_models
60fvp_models=(
61[base-aemv8a-quad]=";;;"
laurenw-armafdc3bc2022-09-14 15:31:42 -050062[base-aemv8a-revb]="${fvp_arm_std_library};FVP_Base_AEMvA-AEMvA"
63[base-aemv8a-latest-revb]="${fvp_arm_std_library};FVP_Base_AEMvA-AEMvA"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060064[base-aemva]=";;;"
Manish V Badarkhee4783832021-02-22 14:36:56 +000065[base-aemv8a-gic600ae]=";;;"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060066[foundationv8]="${foundation_platform};Foundation_Platform"
laurenw-armf414aba2021-04-26 15:58:56 -050067[base-aemv8a]="${fvp_base_revc_2xaemva};FVP_Base_RevC-2xAEMvA"
laurenw-arm35faeaa2021-05-03 14:28:17 -050068[cortex-a32x4]="${fvp_arm_std_library_11_12};FVP_Base_Cortex-A32x4"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060069[cortex-a35x4]="${fvp_arm_std_library};FVP_Base_Cortex-A35x4"
70[cortex-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A53x4"
laurenw-armafdc3bc2022-09-14 15:31:42 -050071[cortex-a55x4]="${fvp_arm_std_library};FVP_Base_Cortex-A55"
Leonardo Sandoval95f896b2021-02-22 10:16:29 -060072[cortex-a55x4-a75x4]="${fvp_arm_std_library};FVP_Base_Cortex-A55x4+Cortex-A75x4"
73[cortex-a55x4-a76x2]="${fvp_arm_std_library};FVP_Base_Cortex-A55x4+Cortex-A76x2"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060074[cortex-a57x1-a53x1]="${fvp_arm_std_library};FVP_Base_Cortex-A57x1-A53x1"
75[cortex-a57x2-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57x2-A53x4"
76[cortex-a57x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57x4"
77[cortex-a57x4-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57x4-A53x4"
laurenw-armafdc3bc2022-09-14 15:31:42 -050078[cortex-a65aex8]="${fvp_arm_std_library};FVP_Base_Cortex-A65AE"
79[cortex-a65x4]="${fvp_arm_std_library};FVP_Base_Cortex-A65"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060080[cortex-a72x4]="${fvp_arm_std_library};FVP_Base_Cortex-A72x4"
81[cortex-a72x4-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A72x4-A53x4"
82[cortex-a73x4]="${fvp_arm_std_library};FVP_Base_Cortex-A73x4"
83[cortex-a73x4-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A73x4-A53x4"
laurenw-armafdc3bc2022-09-14 15:31:42 -050084[cortex-a75x4]="${fvp_arm_std_library};FVP_Base_Cortex-A75"
85[cortex-a76aex4]="${fvp_arm_std_library};FVP_Base_Cortex-A76AE"
86[cortex-a76aex2]="${fvp_arm_std_library};FVP_Base_Cortex-A76AE"
87[cortex-a76x4]="${fvp_arm_std_library};FVP_Base_Cortex-A76"
88[cortex-a77x4]="${fvp_arm_std_library};FVP_Base_Cortex-A77"
89[cortex-a78x4]="${fvp_arm_std_library};FVP_Base_Cortex-A78"
90[cortex-a78cx4]="${fvp_arm_std_library};FVP_Base_Cortex-A78C"
91[cortex-x2]="${fvp_arm_std_library_11_17};FVP_Base_Cortex-X2x4"
92[cortex-a710]="${fvp_arm_std_library_11_17};FVP_Base_Cortex-A710x4"
93[neoverse_e1x1]="${fvp_arm_std_library};FVP_Base_Neoverse-E1"
94[neoverse_e1x2]="${fvp_arm_std_library};FVP_Base_Neoverse-E1"
95[neoverse_e1x4]="${fvp_arm_std_library};FVP_Base_Neoverse-E1"
96[neoverse_n1]="${fvp_arm_std_library};FVP_Base_Neoverse-N1"
97[neoverse_n2]="${fvp_arm_std_library_11_16};FVP_Base_Neoverse-N1x4"
98[neoverse-v1x4]="${fvp_arm_std_library};FVP_Base_Neoverse-V1"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060099[css-rdv1]=";;;"
100[css-rde1edge]=";;;"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600101[tc0]=";;;"
Usama Arifcba711d2021-08-04 15:53:42 +0100102[tc1]=";;;"
Rupinderjit Singh385f17d2022-07-18 20:28:10 +0100103[tc2]=";;;"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600104)
105
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500106
Fathi Boudra422bf772019-12-02 11:10:16 +0200107# FVP Kernel URLs
108declare -A fvp_kernels
109fvp_kernels=(
110[fvp-aarch32-zimage]="$linaro_release/fvp32-latest-busybox-uboot/Image"
111[fvp-busybox-uboot]="$linaro_release/fvp-latest-busybox-uboot/Image"
112[fvp-oe-uboot32]="$linaro_release/fvp32-latest-oe-uboot/Image"
113[fvp-oe-uboot]="$linaro_release/fvp-latest-oe-uboot/Image"
114[fvp-quad-busybox-uboot]="$tfa_downloads/quad_cluster/Image"
115)
116
Fathi Boudra422bf772019-12-02 11:10:16 +0200117# FVP initrd URLs
118declare -A fvp_initrd_urls
119fvp_initrd_urls=(
120[aarch32-ramdisk]="$linaro_release/fvp32-latest-busybox-uboot/ramdisk.img"
Fathi Boudra422bf772019-12-02 11:10:16 +0200121[dummy-ramdisk]="$linaro_release/fvp-latest-oe-uboot/ramdisk.img"
122[dummy-ramdisk32]="$linaro_release/fvp32-latest-oe-uboot/ramdisk.img"
123[default]="$linaro_release/fvp-latest-busybox-uboot/ramdisk.img"
124)
125
Fathi Boudra422bf772019-12-02 11:10:16 +0200126get_optee_bin() {
Sandrine Bailleux25ff2942021-02-25 14:00:10 +0100127 url="$tfa_downloads/optee/tee.bin" \
128 saveas="bl32.bin" fetch_file
Fathi Boudra422bf772019-12-02 11:10:16 +0200129 archive_file "bl32.bin"
130}
131
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100132# For Measured Boot tests using a TA based on OPTEE, it is necessary to use a
133# specific build rather than the default one generated by Jenkins.
134get_ftpm_optee_bin() {
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100135 url="$tfa_downloads/ftpm/optee/tee-header_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100136 saveas="bl32.bin" fetch_file
137 archive_file "bl32.bin"
138
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100139 url="$tfa_downloads/ftpm/optee/tee-pager_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100140 saveas="bl32_extra1.bin" fetch_file
141 archive_file "bl32_extra1.bin"
142
Leonardo Sandovalda5f78d2021-03-18 11:09:30 -0600143 # tee-pageable_v2.bin is just a empty file, named as bl32_extra2.bin,
144 # so just create the file
145 touch "bl32_extra2.bin"
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100146 archive_file "bl32_extra2.bin"
147}
148
Fathi Boudra422bf772019-12-02 11:10:16 +0200149get_uboot32_bin() {
150 local tmpdir="$(mktempdir)"
151
152 pushd "$tmpdir"
153 extract_fip "$uboot32_fip_url"
154 mv "nt-fw.bin" "uboot.bin"
155 archive_file "uboot.bin"
156 popd
157}
158
159get_uboot_bin() {
160 local uboot_url="$linaro_release/fvp-latest-busybox-uboot/bl33-uboot.bin"
161
162 url="$uboot_url" saveas="uboot.bin" fetch_file
163 archive_file "uboot.bin"
164}
165
166get_uefi_bin() {
Zelalem219df412020-05-17 19:21:20 -0500167 uefi_downloads="${uefi_downloads:-http://files.oss.arm.com/downloads/uefi}"
168 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 +0200169
170 url=$uefi_ci_bin_url saveas="uefi.bin" fetch_file
171 archive_file "uefi.bin"
172}
173
174get_kernel() {
175 local kernel_type="${kernel_type:?}"
176 local url="${fvp_kernels[$kernel_type]}"
177
178 url="${url:?}" saveas="kernel.bin" fetch_file
179 archive_file "kernel.bin"
180}
181
182get_initrd() {
183 local initrd_type="${initrd_type:?}"
184 local url="${fvp_initrd_urls[$initrd_type]}"
185
186 url="${url:?}" saveas="initrd.bin" fetch_file
187 archive_file "initrd.bin"
188}
189
190get_dtb() {
191 local dtb_type="${dtb_type:?}"
192 local dtb_url
193 local dtb_saveas="$workspace/dtb.bin"
Zelalem219df412020-05-17 19:21:20 -0500194 local cc="$(get_tf_opt CROSS_COMPILE)"
195 local pp_flags="-P -nostdinc -undef -x assembler-with-cpp"
Fathi Boudra422bf772019-12-02 11:10:16 +0200196
197 case "$dtb_type" in
198 "fvp-base-quad-cluster-gicv3-psci")
199 # Get the quad-cluster FDT from pdsw area
200 dtb_url="$tfa_downloads/quad_cluster/fvp-base-quad-cluster-gicv3-psci.dtb"
201 url="$dtb_url" saveas="$dtb_saveas" fetch_file
202 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200203 *)
Zelalem219df412020-05-17 19:21:20 -0500204 # Preprocess DTS file
205 ${cc}gcc -E ${pp_flags} -I"$tf_root/fdts" -I"$tf_root/include" \
206 -o "$workspace/${dtb_type}.pre.dts" \
207 "$tf_root/fdts/${dtb_type}.dts"
208 # Generate DTB file from DTS
Fathi Boudra422bf772019-12-02 11:10:16 +0200209 dtc -I dts -O dtb \
Zelalem219df412020-05-17 19:21:20 -0500210 "$workspace/${dtb_type}.pre.dts" -o "$dtb_saveas"
Fathi Boudra422bf772019-12-02 11:10:16 +0200211 esac
212
213 archive_file "$dtb_saveas"
214}
215
216get_rootfs() {
217 local tmpdir
218 local fs_base="$(echo $(basename $rootfs_url) | sed 's/\.gz$//')"
219 local cached="$project_filer/ci-files/$fs_base"
220
221 if upon "$jenkins_run" && [ -f "$cached" ]; then
222 # Job workspace is limited in size, and the root file system is
223 # quite large. This means, parallel runs of root file system
224 # tests could fail. So, for Jenkins runs, copy and use the root
225 # file system image from the $CI_SCRATCH location
226 local private="$CI_SCRATCH/$JOB_NAME-$BUILD_NUMBER"
227 mkdir -p "$private"
228 rm -f "$private/rootfs.bin"
229 url="$cached" saveas="$private/rootfs.bin" fetch_file
230 ln -s "$private/rootfs.bin" "$archive/rootfs.bin"
231 return
232 fi
233
234 tmpdir="$(mktempdir)"
235 pushd "$tmpdir"
236 url="$rootfs_url" saveas="rootfs.bin" fetch_file
237
238 # Possibly, the filesystem image we just downloaded is compressed.
239 # Decompress it if required.
240 if file "rootfs.bin" | grep -iq 'gzip compressed data'; then
241 echo "Decompressing root file system image rootfs.bin ..."
242 gunzip --stdout "rootfs.bin" > uncompressed_fs.bin
243 mv uncompressed_fs.bin "rootfs.bin"
244 fi
245
246 archive_file "rootfs.bin"
247 popd
248}
249
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200250fvp_romlib_jmptbl_backup="$(mktempdir)/jmptbl.i"
251
Fathi Boudra422bf772019-12-02 11:10:16 +0200252fvp_romlib_runtime() {
253 local tmpdir="$(mktempdir)"
254
255 # Save BL1 and romlib binaries from original build
256 mv "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin" "$tmpdir/romlib.bin"
257 mv "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin" "$tmpdir/bl1.bin"
258
259 # Patch index file
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200260 cp "${tf_root:?}/plat/arm/board/fvp/jmptbl.i" "$fvp_romlib_jmptbl_backup"
261 sed -i '/fdt/ s/.$/&\ patch/' ${tf_root:?}/plat/arm/board/fvp/jmptbl.i
Fathi Boudra422bf772019-12-02 11:10:16 +0200262
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200263 # Rebuild with patched file
264 echo "Building patched romlib:"
265 build_tf
Fathi Boudra422bf772019-12-02 11:10:16 +0200266
Fathi Boudra422bf772019-12-02 11:10:16 +0200267 # Retrieve original BL1 and romlib binaries
268 mv "$tmpdir/romlib.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin"
269 mv "$tmpdir/bl1.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin"
270}
271
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200272fvp_romlib_cleanup() {
273 # Restore original index
274 mv "$fvp_romlib_jmptbl_backup" "${tf_root:?}/plat/arm/board/fvp/jmptbl.i"
275}
276
277
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500278fvp_gen_bin_url() {
279 local bin_mode="${bin_mode:?}"
280 local bin="${1:?}"
281
282 if upon "$jenkins_run"; then
283 echo "$jenkins_url/job/$JOB_NAME/$BUILD_NUMBER/artifact/artefacts/$bin_mode/$bin"
284 else
285 echo "file://$workspace/artefacts/$bin_mode/$bin"
286 fi
287}
288
Chris Kayfbbf1322022-10-05 13:13:32 +0100289# Generates the template for YAML-based LAVA job definitions from a file
290# corresponding to the currently-selected payload, e.g.:
291#
292# - `lava-templates/fvp-linux.yaml`
293# - `lava-templates/fvp-tftf.yaml`
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500294gen_fvp_yaml_template() {
Chris Kayfbbf1322022-10-05 13:13:32 +0100295 local yaml_template_file="${workspace}/fvp_template.yaml"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500296
Chris Kayc9523b12022-10-10 18:32:20 +0100297 cp "${ci_root}/script/lava-templates/fvp-${payload_type:?}.yaml" \
298 "${yaml_template_file}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500299
Chris Kayfbbf1322022-10-05 13:13:32 +0100300 archive_file "${yaml_template_file}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500301}
302
Chris Kayc9523b12022-10-10 18:32:20 +0100303# Generates the final YAML-based LAVA job definition from a template file.
304#
305# The job definition template is expanded with visibility of all variables that
306# are available from within the function, including those with local scope.
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500307gen_fvp_yaml() {
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600308 local model="${model:?}"
309
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500310 local yaml_template_file="$workspace/fvp_template.yaml"
311 local yaml_file="$workspace/fvp.yaml"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500312 local yaml_job_file="$workspace/job.yaml"
313 local lava_model_params="$workspace/lava_model_params"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500314
Leonardo Sandovalfda4f292020-10-06 15:59:26 -0500315 # this function expects a template, quit if it is not present
316 if [ ! -f "$yaml_template_file" ]; then
317 return
318 fi
319
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600320 local model_params="${fvp_models[$model]}"
321 local model_name="$(echo "${model_params}" | awk -F ';' '{print $1}')"
322 local model_dir="$(echo "${model_params}" | awk -F ';' '{print $2}')"
323 local model_bin="$(echo "${model_params}" | awk -F ';' '{print $3}')"
324
325 # model params are required for correct yaml creation, quit if empty
326 if [ -z "${model_name}" ]; then
327 echo "FVP model param 'model_name' variable empty, yaml not produced"
328 return
329 elif [ -z "${model_dir}" ]; then
330 echo "FVP model param 'model_dir' variable empty, yaml not produced"
331 return
332 elif [ -z "${model_bin}" ]; then
333 echo "FVP model param 'model_bin' variable empty, yaml not produced"
334 return
335 fi
336
337 echo "FVP model params: model_name=$model_name model_dir=$model_dir model_bin=$model_bin"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500338
339 # optional parameters, defaults to globals
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500340 local model_dtb="${model_dtb:-$default_model_dtb}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500341
Chris Kayc9523b12022-10-10 18:32:20 +0100342 if [ -n "${GERRIT_CHANGE_NUMBER}" ]; then
343 local gerrit_url="https://review.trustedfirmware.org/c/${GERRIT_CHANGE_NUMBER}/${GERRIT_PATCHSET_NUMBER}"
344 elif [ -n "${GERRIT_REFSPEC}" ]; then
345 local gerrit_url=$(echo ${GERRIT_REFSPEC} |
346 awk -F/ '{print "https://review.trustedfirmware.org/c/" $4 "/" $5}')
347 fi
348
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500349 docker_registry="${docker_registry:-}"
350 docker_registry="$(docker_registry_append)"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500351 docker_name="${docker_registry}$model_name"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600352 prompt1='/ #'
353 prompt2='root@genericarmv8:~#'
354 version_string="\"Fast Models"' [^\\n]+'"\""
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500355
Leonardo Sandoval5d87b702021-05-10 11:53:13 -0500356 test_config="${TEST_CONFIG}"
357
Chris Kay4eb9ded2022-10-10 15:51:40 +0100358 declare -A artefact_filters=(
359 [backup_fip]="backup_fip.bin"
360 [bl1]="bl1.bin"
361 [bl2]="bl2.bin"
362 [bl31]="bl31.bin"
363 [bl32]="bl32.bin"
364 [busybox]="busybox.bin"
365 [cactus_primary]="cactus-primary.pkg"
366 [cactus_secondary]="cactus-secondary.pkg"
367 [cactus_tertiary]="cactus-tertiary.pkg"
368 [coverage_trace_plugin]="coverage_trace.so"
369 [dtb]="dtb.bin"
370 [el3_payload]="el3_payload.bin"
371 [fip_gpt]="fip_gpt.bin"
372 [fip]="fip.bin"
373 [fvp_spmc_manifest_dtb]="=fvp_spmc_manifest.dtb"
374 [fwu_fip]="fwu_fip.bin"
375 [generic_trace]="GenericTrace.so"
376 [hafnium]="hafnium.bin"
377 [image]="kernel.bin"
378 [ivy]="ivy.pkg"
379 [manifest_dtb]="=manifest.dtb"
380 [mcp_rom_hyphen]="mcp-rom.bin"
381 [mcp_rom]="mcp_rom.bin"
382 [ns_bl1u]="ns_bl1u.bin"
383 [ns_bl2u]="ns_bl2u.bin"
384 [ramdisk]="initrd.bin|initrd.img"
385 [romlib]="romlib.bin"
386 [rootfs]="rootfs.bin"
387 [scp_ram_hyphen]="scp-ram.bin"
388 [scp_ram]="scp_ram.bin"
389 [scp_rom_hyphen]="scp-rom.bin"
390 [scp_rom]="scp_rom.bin"
391 [secure_hafnium]="secure_hafnium.bin"
392 [spm]="spm.bin"
393 [tftf]="tftf.bin"
394 [tmp]="tmp.bin"
395 [uboot]="uboot.bin"
396 )
397
Chris Kayc14743a2022-10-13 11:33:26 +0100398 declare -A artefact_urls=(
399 [backup_fip]="$(fvp_gen_bin_url backup_fip.bin)"
400 [bl1]="$(fvp_gen_bin_url bl1.bin)"
401 [bl2]="$(fvp_gen_bin_url bl2.bin)"
402 [bl31]="$(fvp_gen_bin_url bl31.bin)"
403 [bl32]="$(fvp_gen_bin_url bl32.bin)"
404 [busybox]="$(fvp_gen_bin_url busybox.bin.gz)"
405 [cactus_primary]="$(fvp_gen_bin_url cactus-primary.pkg)"
406 [cactus_secondary]="$(fvp_gen_bin_url cactus-secondary.pkg)"
407 [cactus_tertiary]="$(fvp_gen_bin_url cactus-tertiary.pkg)"
408 [coverage_trace_plugin]="${coverage_trace_plugin}"
409 [dtb]="$(fvp_gen_bin_url ${model_dtb})"
410 [el3_payload]="$(fvp_gen_bin_url el3_payload.bin)"
411 [fip]="$(fvp_gen_bin_url fip.bin)"
412 [fip_gpt]="$(fvp_gen_bin_url fip_gpt.bin)"
413 [fvp_spmc_manifest_dtb]="$(fvp_gen_bin_url fvp_spmc_manifest.dtb)"
414 [fwu_fip]="$(fvp_gen_bin_url fwu_fip.bin)"
415 [generic_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/GenericTrace.so"
416 [hafnium]="$(fvp_gen_bin_url hafnium.bin)"
417 [image]="$(fvp_gen_bin_url kernel.bin)"
418 [ivy]="$(fvp_gen_bin_url ivy.pkg)"
419 [manifest_dtb]="$(fvp_gen_bin_url manifest.dtb)"
420 [mcp_rom]="$(fvp_gen_bin_url mcp_rom.bin)"
421 [mcp_rom_hyphen]="$(fvp_gen_bin_url mcp-rom.bin)"
422 [ns_bl1u]="$(fvp_gen_bin_url ns_bl1u.bin)"
423 [ns_bl2u]="$(fvp_gen_bin_url ns_bl2u.bin)"
424 [ramdisk]="$(fvp_gen_bin_url initrd.bin)"
425 [romlib]="$(fvp_gen_bin_url romlib.bin)"
426 [rootfs]="$(fvp_gen_bin_url rootfs.bin.gz)"
427 [secure_hafnium]="$(fvp_gen_bin_url secure_hafnium.bin)"
428 [scp_ram]="$(fvp_gen_bin_url scp_ram.bin)"
429 [scp_ram_hyphen]="$(fvp_gen_bin_url scp-ram.bin)"
430 [scp_rom]="$(fvp_gen_bin_url scp_rom.bin)"
431 [scp_rom_hyphen]="$(fvp_gen_bin_url scp-rom.bin)"
432 [spm]="$(fvp_gen_bin_url spm.bin)"
433 [tftf]="$(fvp_gen_bin_url tftf.bin)"
434 [tmp]="$(fvp_gen_bin_url tmp.bin)"
435 [uboot]="$(fvp_gen_bin_url uboot.bin)"
436 )
437
Chris Kay5d550d82022-10-12 17:20:31 +0100438 # In LAVA we don't provide the paths to the artefacts directly, but instead
439 # use macros of the form `{XYZ}`. This is a list of regular expression
440 # replacements to run on the model parameters file before we add them to the
441 # LAVA job definition.
442 declare -A artefact_macros=(
443 ["[= ]backup_fip.bin"]="={BACKUP_FIP}"
444 ["[= ]bl1.bin"]="={BL1}"
445 ["[= ]bl2.bin"]="={BL2}"
446 ["[= ]bl31.bin"]="={BL31}"
447 ["[= ]bl32.bin"]="={BL32}"
448 ["[= ]cactus-primary.pkg"]="={CACTUS_PRIMARY}"
449 ["[= ]cactus-secondary.pkg"]="={CACTUS_SECONDARY}"
450 ["[= ]cactus-tertiary.pkg"]="={CACTUS_TERTIARY}"
451 ["[= ].*coverage_trace.so"]="={COVERAGE_TRACE_PLUGIN}"
452 ["[= ]fvp_spmc_manifest.dtb"]="={FVP_SPMC_MANIFEST_DTB}"
453 ["[= ]busybox.bin"]="={BUSYBOX}"
454 ["[= ]dtb.bin"]="={DTB}"
455 ["[= ]el3_payload.bin"]="={EL3_PAYLOAD}"
456 ["[= ]fip_gpt.bin"]="={FIP_GPT}"
457 ["[= ]fwu_fip.bin"]="={FWU_FIP}"
458 ["[= ]fip.bin"]="={FIP}"
459 ["[= ].*GenericTrace.so"]="={GENERIC_TRACE}"
460 ["[= ].*/hafnium.bin"]="={HAFNIUM}"
461 ["[= ]kernel.bin"]="={IMAGE}"
462 ["[= ]ivy.pkg"]="={IVY}"
463 ["[= ]manifest.dtb"]="={MANIFEST_DTB}"
464 ["[= ]mcp-rom.bin"]="={MCP_ROM}"
465 ["[= ]mcp_rom_hyphen.bin"]="={MCP_ROM_HYPHEN}"
466 ["[= ]ns_bl1u.bin"]="={NS_BL1U}"
467 ["[= ]ns_bl2u.bin"]="={NS_BL2U}"
468 ["[= ]initrd.bin"]="={RAMDISK}"
469 ["[= ]initrd.img"]="={RAMDISK}"
470 ["[= ]romlib.bin"]="={ROMLIB}"
471 ["[= ]rootfs.bin"]="={ROOTFS}"
472 ["[= ].*/secure_hafnium.bin"]="={SECURE_HAFNIUM}"
473 ["[= ]scp_ram.bin"]="={SCP_RAM}"
474 ["[= ]scp-ram.bin"]="={SCP_RAM_HYPHEN}"
475 ["[= ]scp_rom.bin"]="={SCP_ROM}"
476 ["[= ]scp-rom.bin"]="={SCP_ROM_HYPHEN}"
477 ["[= ]spm.bin"]="={SPM}"
478 ["[= ]tftf.bin"]="={TFTF}"
479 ["[= ].*/tmp.bin"]="={TMP}"
480 ["[= ]uboot.bin"]="={UBOOT}"
481 )
482
Chris Kay4eb9ded2022-10-10 15:51:40 +0100483 declare -a artefacts=()
484
485 for artefact in "${!artefact_filters[@]}"; do
486 if grep -E -q "${artefact_filters[${artefact}]}" "${archive}/model_params"; then
487 artefacts+=("${artefact}")
488 fi
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600489 done
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500490
Chris Kayc92d9fc2022-10-13 11:19:27 +0100491 # Derive LAVA model parameters from the non-LAVA ones
492 cp "${archive}/model_params" "${lava_model_params}"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600493
Chris Kayf07d3392022-10-26 15:42:48 +0100494 # Ensure braces in the FVP model parameters are not accidentally interpreted
495 # as LAVA macros.
496 sed -i -e 's/{/{{/g' "${lava_model_params}"
497 sed -i -e 's/}/}}/g' "${lava_model_params}"
498
Chris Kay5d550d82022-10-12 17:20:31 +0100499 # LAVA expects FVP binary paths as macros, i.e. `{X}` instead of `x.bin`, so
500 # replace the file paths in our pre-generated model parameters.
501 for regex in "${!artefact_macros[@]}"; do
502 sed -i -e "s!${regex}!${artefact_macros[${regex}]}!" \
503 "${lava_model_params}"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600504 done
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500505
Chris Kayc92d9fc2022-10-13 11:19:27 +0100506 # Read boot arguments into an array so that the job template file can
507 # iterate over them.
508 readarray -t boot_arguments < "${lava_model_params}"
509
510 # Generate the LAVA job definition, minus the test expectations
511 expand_template "${yaml_template_file}" > "${yaml_file}"
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500512
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500513 # Append expect commands into the job definition through test-interactive commands
514 gen_fvp_yaml_expect >> "$yaml_file"
515
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600516 # create job.yaml
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500517 cp "$yaml_file" "$yaml_job_file"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500518
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600519 # archive both yamls
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500520 archive_file "$yaml_file"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500521 archive_file "$yaml_job_file"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500522}
523
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500524gen_fvp_yaml_expect() {
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500525
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500526 run_root="$archive/run"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500527
528 # Loop through all uarts expect files
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500529 for expect_file in $(find $run_root -name expect); do
530
531 # TODO: currently, only handle UART 0
532 case $expect_file in
533 *uart0* )
534 uart_number=uart0
535 ;;
536 *)
537 continue
538 ;;
539 esac
540
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500541 # Array containing "interactive" or "monitor" expect strings and populated during run config execution.
542 # Interactive expect scripts are converted into LAVA Interactive Test Actions (see
543 # https://tf.validation.linaro.org/static/docs/v2/interactive.html#writing-tests-interactive) and
544 # monitor expect scripts are converted into LAVA Monitor Test Actions (see
545 # https://validation.linaro.org/static/docs/v2/actions-test.html#monitor)
546 #
547 # Interactive Expect strings have the format 'i;<prompt>;<succeses>;<failures>;<commands>'
548 # where multiple successes or failures or commands are separated by @
549 #
550 # Monitor Expect strings have the format 'm;<start>;<end>;<patterns>'
551 # where multiple patterns are separated by @
552 #
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500553 expect_string=()
554
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500555 # Get the real name of the expect file
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500556 expect_file=$(cat $expect_file)
557
558 # Source the run_config enviroment variables
559 env=$run_root/$uart_number/env
560 if [ -e $env ]; then
561 source $env
562 fi
563
564 # Get all expect strings
Chris Kay047af3e2022-09-30 17:10:28 +0100565 expect_dir="${ci_root}/expect-lava"
566 expect_file="${expect_dir}/${expect_file}"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500567
Chris Kay047af3e2022-09-30 17:10:28 +0100568 # Allow the expectations to be provided directly in LAVA's job YAML
569 # format, rather than converting it from a pseudo-Expect Bash script in
570 # the block below.
571 if [ -f "${expect_file/.exp/.yaml}" ]; then
572 pushd "${expect_dir}"
573 expand_template "${expect_file/.exp/.yaml}"
574 popd
575
576 continue
577 else
578 source "${expect_file}"
579 fi
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500580
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500581 if [ ${#expect_string[@]} -gt 0 ]; then
582
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500583 # expect loop
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500584 for key in "${!expect_string[@]}"; do
585
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500586 # single raw expect string
587 es="${expect_string[${key}]}"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500588
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500589 # action type: either m or i
590 action="$(echo "${es}" | awk -F ';' '{print $1}')"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500591
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500592 if [ "${action}" = "m" ]; then
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500593
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500594 start="$(echo "${es}" | awk -F ';' '{print $2}')"
595 end="$(echo "${es}" | awk -F ';' '{print $3}')"
596 patterns="$(echo "${es}" | awk -F ';' '{print $4}')"
597
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500598 cat << EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500599- test:
600 monitors:
601 - name: tests
602 start: '${start}'
603 end: '${end}'
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500604EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500605 # Patterns are separated by '@'
606 OLD_IFS=$IFS; IFS=$'@'
607 for p in ${patterns}; do
608 cat << EOF
609 pattern: '$p'
610EOF
611 done
612 IFS=$OLD_IFS
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500613 cat << EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500614 fixupdict:
615 PASS: pass
616 FAIL: fail
617EOF
618 fi # end of monitor action
619
620 if [ "${action}" = "i" ]; then
621
622 prompts="$(echo "${es}" | awk -F ';' '{print $2}')"
623 successes="$(echo "${es}" | awk -F ';' '{print $3}')"
624 failures="$(echo "${es}" | awk -F ';' '{print $4}')"
625 commands="$(echo "${es}" | awk -F ';' '{print $5}')"
626
627 cat << EOF
628- test:
629 interactive:
630EOF
631 OLD_IFS=$IFS; IFS=$'@'
632
633 if [[ -n "${prompts}" && -n "${successes}" && -n "${failures}" ]]; then
634 cat << EOF
635 - name: interactive_${uart_number}_${key}
636 prompts: ['${prompts}']
637 script:
638EOF
639 if [ -z "${commands}" ]; then
640 cat <<EOF
641 - name: interactive_command_${uart_number}_${key}
642 command:
643EOF
644 else
645 for c in ${commands}; do
646 cat <<EOF
647 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300648 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500649EOF
650 done
651 fi
652 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500653 successes:
654EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500655 for s in ${successes}; do
656 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500657 - message: '$s'
658EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500659 done
660 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500661 failures:
662EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500663 for f in ${failures}; do
664 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500665 - message: '$f'
666EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500667 done
668 elif [[ -n "${prompts}" && -n "${successes}" ]]; then
669 cat << EOF
670 - name: interactive_${uart_number}_${key}
671 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500672 script:
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500673EOF
674
675 if [ -z "${commands}" ]; then
676 cat <<EOF
677 - name: interactive_command_${uart_number}_${key}
678 command:
679EOF
680 else
681 for c in ${commands}; do
682 cat <<EOF
683 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300684 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500685EOF
686 done
687 fi
688 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500689 successes:
690EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500691 for s in ${successes}; do
692 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500693 - message: '$s'
694EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500695 done
696
697 elif [[ -n "${prompts}" && -n "${failures}" ]]; then
698 cat << EOF
699 - name: interactive_${uart_number}_${key}
700 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500701 script:
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500702EOF
703 if [ -z "${commands}" ]; then
704 cat <<EOF
705 - name: interactive_command_${uart_number}_${key}
706 command:
707EOF
708 else
709 for c in ${commands}; do
710 cat <<EOF
711 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300712 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500713EOF
714 done
715 fi
716 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500717 failures:
718EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500719 for f in ${failures}; do
720 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500721 - message: '$f'
722EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500723 done
724 else
725 cat << EOF
726 - name: interactive_${uart_number}_${key}
727 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500728 script:
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500729EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500730 if [ -z "${commands}" ]; then
731 cat <<EOF
732 - name: interactive_command_${uart_number}_${key}
733 command:
734EOF
735 else
736 for c in ${commands}; do
737 cat <<EOF
738 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300739 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500740EOF
741 done
742 fi
743 fi
744
745 IFS=$OLD_IFS
746 fi # end of interactive action
747
748 done # end of expect loop
749
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500750 fi
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500751 done # end of uart loop
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500752}
753
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500754docker_registry_append() {
755 # if docker_registry is empty, just use local docker registry
756 [ -z "$docker_registry" ] && return
757
758 local last=-1
759 local last_char="${docker_registry:last}"
760
761 if [ "$last_char" != '/' ]; then
762 docker_registry="${docker_registry}/";
763 fi
764 echo "$docker_registry"
765}
766
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000767# generate GPT image and archive it
768gen_gpt_bin() {
769 raw_image="fip_gpt.bin"
770 img_uuid="FB90808A-BA9A-4D42-B9A2-A7A937144AEE"
771 img_bank_uuid=`uuidgen`
772 disk_uuid=`uuidgen`
773 bin="${1:?}"
774
775 # maximum FIP size 2MB
776 fip_max_size=2097152
777 start_sector=34
778 sector_size=512
779 num_sectors=$(($fip_max_size/$sector_size))
780 bin_size=$(stat -c %s $bin)
781
782 if [[ $fip_max_size -lt $bin_size ]]
783 then
784 echo "FIP binary ($bin_size bytes) larger than max partition 1"
785 "size ($fip_max_size byte)"
786 return
787 fi
788
789 # create raw 5MB image
790 dd if=/dev/zero of=$raw_image bs=5M count=1
791
792 # create GPT image
793 sgdisk -a 1 -U $disk_uuid -n 1:$start_sector:+$num_sectors \
794 -c 1:FIP_A -t 1:$img_uuid $raw_image -u $img_bank_uuid
795
796 echo "write binary $bin at sector $start_sector"
797 dd if=$bin of=$raw_image bs=$sector_size seek=$start_sector \
798 count=$num_sectors conv=notrunc
799
800 archive_file "fip_gpt.bin"
801}
802
Fathi Boudra422bf772019-12-02 11:10:16 +0200803set +u