blob: 5825712692fbdd6d0d07ffa3f8535c56ab9e949c [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]=";;;"
101[css-rdn1edge]=";;;"
102[css-rdn1edgex2]=";;;"
103[css-sgi575]=";;;"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600104[tc0]=";;;"
Usama Arifcba711d2021-08-04 15:53:42 +0100105[tc1]=";;;"
Rupinderjit Singh385f17d2022-07-18 20:28:10 +0100106[tc2]=";;;"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600107)
108
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500109
Fathi Boudra422bf772019-12-02 11:10:16 +0200110# FVP Kernel URLs
111declare -A fvp_kernels
112fvp_kernels=(
113[fvp-aarch32-zimage]="$linaro_release/fvp32-latest-busybox-uboot/Image"
114[fvp-busybox-uboot]="$linaro_release/fvp-latest-busybox-uboot/Image"
115[fvp-oe-uboot32]="$linaro_release/fvp32-latest-oe-uboot/Image"
116[fvp-oe-uboot]="$linaro_release/fvp-latest-oe-uboot/Image"
117[fvp-quad-busybox-uboot]="$tfa_downloads/quad_cluster/Image"
118)
119
Fathi Boudra422bf772019-12-02 11:10:16 +0200120# FVP initrd URLs
121declare -A fvp_initrd_urls
122fvp_initrd_urls=(
123[aarch32-ramdisk]="$linaro_release/fvp32-latest-busybox-uboot/ramdisk.img"
Fathi Boudra422bf772019-12-02 11:10:16 +0200124[dummy-ramdisk]="$linaro_release/fvp-latest-oe-uboot/ramdisk.img"
125[dummy-ramdisk32]="$linaro_release/fvp32-latest-oe-uboot/ramdisk.img"
126[default]="$linaro_release/fvp-latest-busybox-uboot/ramdisk.img"
127)
128
Fathi Boudra422bf772019-12-02 11:10:16 +0200129get_optee_bin() {
Sandrine Bailleux25ff2942021-02-25 14:00:10 +0100130 url="$tfa_downloads/optee/tee.bin" \
131 saveas="bl32.bin" fetch_file
Fathi Boudra422bf772019-12-02 11:10:16 +0200132 archive_file "bl32.bin"
133}
134
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100135# For Measured Boot tests using a TA based on OPTEE, it is necessary to use a
136# specific build rather than the default one generated by Jenkins.
137get_ftpm_optee_bin() {
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100138 url="$tfa_downloads/ftpm/optee/tee-header_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100139 saveas="bl32.bin" fetch_file
140 archive_file "bl32.bin"
141
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100142 url="$tfa_downloads/ftpm/optee/tee-pager_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100143 saveas="bl32_extra1.bin" fetch_file
144 archive_file "bl32_extra1.bin"
145
Leonardo Sandovalda5f78d2021-03-18 11:09:30 -0600146 # tee-pageable_v2.bin is just a empty file, named as bl32_extra2.bin,
147 # so just create the file
148 touch "bl32_extra2.bin"
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100149 archive_file "bl32_extra2.bin"
150}
151
Fathi Boudra422bf772019-12-02 11:10:16 +0200152get_uboot32_bin() {
153 local tmpdir="$(mktempdir)"
154
155 pushd "$tmpdir"
156 extract_fip "$uboot32_fip_url"
157 mv "nt-fw.bin" "uboot.bin"
158 archive_file "uboot.bin"
159 popd
160}
161
162get_uboot_bin() {
163 local uboot_url="$linaro_release/fvp-latest-busybox-uboot/bl33-uboot.bin"
164
165 url="$uboot_url" saveas="uboot.bin" fetch_file
166 archive_file "uboot.bin"
167}
168
169get_uefi_bin() {
Zelalem219df412020-05-17 19:21:20 -0500170 uefi_downloads="${uefi_downloads:-http://files.oss.arm.com/downloads/uefi}"
171 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 +0200172
173 url=$uefi_ci_bin_url saveas="uefi.bin" fetch_file
174 archive_file "uefi.bin"
175}
176
177get_kernel() {
178 local kernel_type="${kernel_type:?}"
179 local url="${fvp_kernels[$kernel_type]}"
180
181 url="${url:?}" saveas="kernel.bin" fetch_file
182 archive_file "kernel.bin"
183}
184
185get_initrd() {
186 local initrd_type="${initrd_type:?}"
187 local url="${fvp_initrd_urls[$initrd_type]}"
188
189 url="${url:?}" saveas="initrd.bin" fetch_file
190 archive_file "initrd.bin"
191}
192
193get_dtb() {
194 local dtb_type="${dtb_type:?}"
195 local dtb_url
196 local dtb_saveas="$workspace/dtb.bin"
Zelalem219df412020-05-17 19:21:20 -0500197 local cc="$(get_tf_opt CROSS_COMPILE)"
198 local pp_flags="-P -nostdinc -undef -x assembler-with-cpp"
Fathi Boudra422bf772019-12-02 11:10:16 +0200199
200 case "$dtb_type" in
201 "fvp-base-quad-cluster-gicv3-psci")
202 # Get the quad-cluster FDT from pdsw area
203 dtb_url="$tfa_downloads/quad_cluster/fvp-base-quad-cluster-gicv3-psci.dtb"
204 url="$dtb_url" saveas="$dtb_saveas" fetch_file
205 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200206 *)
Zelalem219df412020-05-17 19:21:20 -0500207 # Preprocess DTS file
208 ${cc}gcc -E ${pp_flags} -I"$tf_root/fdts" -I"$tf_root/include" \
209 -o "$workspace/${dtb_type}.pre.dts" \
210 "$tf_root/fdts/${dtb_type}.dts"
211 # Generate DTB file from DTS
Fathi Boudra422bf772019-12-02 11:10:16 +0200212 dtc -I dts -O dtb \
Zelalem219df412020-05-17 19:21:20 -0500213 "$workspace/${dtb_type}.pre.dts" -o "$dtb_saveas"
Fathi Boudra422bf772019-12-02 11:10:16 +0200214 esac
215
216 archive_file "$dtb_saveas"
217}
218
219get_rootfs() {
220 local tmpdir
221 local fs_base="$(echo $(basename $rootfs_url) | sed 's/\.gz$//')"
222 local cached="$project_filer/ci-files/$fs_base"
223
224 if upon "$jenkins_run" && [ -f "$cached" ]; then
225 # Job workspace is limited in size, and the root file system is
226 # quite large. This means, parallel runs of root file system
227 # tests could fail. So, for Jenkins runs, copy and use the root
228 # file system image from the $CI_SCRATCH location
229 local private="$CI_SCRATCH/$JOB_NAME-$BUILD_NUMBER"
230 mkdir -p "$private"
231 rm -f "$private/rootfs.bin"
232 url="$cached" saveas="$private/rootfs.bin" fetch_file
233 ln -s "$private/rootfs.bin" "$archive/rootfs.bin"
234 return
235 fi
236
237 tmpdir="$(mktempdir)"
238 pushd "$tmpdir"
239 url="$rootfs_url" saveas="rootfs.bin" fetch_file
240
241 # Possibly, the filesystem image we just downloaded is compressed.
242 # Decompress it if required.
243 if file "rootfs.bin" | grep -iq 'gzip compressed data'; then
244 echo "Decompressing root file system image rootfs.bin ..."
245 gunzip --stdout "rootfs.bin" > uncompressed_fs.bin
246 mv uncompressed_fs.bin "rootfs.bin"
247 fi
248
249 archive_file "rootfs.bin"
250 popd
251}
252
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200253fvp_romlib_jmptbl_backup="$(mktempdir)/jmptbl.i"
254
Fathi Boudra422bf772019-12-02 11:10:16 +0200255fvp_romlib_runtime() {
256 local tmpdir="$(mktempdir)"
257
258 # Save BL1 and romlib binaries from original build
259 mv "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin" "$tmpdir/romlib.bin"
260 mv "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin" "$tmpdir/bl1.bin"
261
262 # Patch index file
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200263 cp "${tf_root:?}/plat/arm/board/fvp/jmptbl.i" "$fvp_romlib_jmptbl_backup"
264 sed -i '/fdt/ s/.$/&\ patch/' ${tf_root:?}/plat/arm/board/fvp/jmptbl.i
Fathi Boudra422bf772019-12-02 11:10:16 +0200265
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200266 # Rebuild with patched file
267 echo "Building patched romlib:"
268 build_tf
Fathi Boudra422bf772019-12-02 11:10:16 +0200269
Fathi Boudra422bf772019-12-02 11:10:16 +0200270 # Retrieve original BL1 and romlib binaries
271 mv "$tmpdir/romlib.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin"
272 mv "$tmpdir/bl1.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin"
273}
274
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200275fvp_romlib_cleanup() {
276 # Restore original index
277 mv "$fvp_romlib_jmptbl_backup" "${tf_root:?}/plat/arm/board/fvp/jmptbl.i"
278}
279
280
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500281fvp_gen_bin_url() {
282 local bin_mode="${bin_mode:?}"
283 local bin="${1:?}"
284
285 if upon "$jenkins_run"; then
286 echo "$jenkins_url/job/$JOB_NAME/$BUILD_NUMBER/artifact/artefacts/$bin_mode/$bin"
287 else
288 echo "file://$workspace/artefacts/$bin_mode/$bin"
289 fi
290}
291
Chris Kayfbbf1322022-10-05 13:13:32 +0100292# Generates the template for YAML-based LAVA job definitions from a file
293# corresponding to the currently-selected payload, e.g.:
294#
295# - `lava-templates/fvp-linux.yaml`
296# - `lava-templates/fvp-tftf.yaml`
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500297gen_fvp_yaml_template() {
Chris Kayfbbf1322022-10-05 13:13:32 +0100298 local yaml_template_file="${workspace}/fvp_template.yaml"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500299
Chris Kayc9523b12022-10-10 18:32:20 +0100300 cp "${ci_root}/script/lava-templates/fvp-${payload_type:?}.yaml" \
301 "${yaml_template_file}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500302
Chris Kayfbbf1322022-10-05 13:13:32 +0100303 archive_file "${yaml_template_file}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500304}
305
Chris Kayc9523b12022-10-10 18:32:20 +0100306# Generates the final YAML-based LAVA job definition from a template file.
307#
308# The job definition template is expanded with visibility of all variables that
309# are available from within the function, including those with local scope.
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500310gen_fvp_yaml() {
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600311 local model="${model:?}"
312
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500313 local yaml_template_file="$workspace/fvp_template.yaml"
314 local yaml_file="$workspace/fvp.yaml"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500315 local yaml_job_file="$workspace/job.yaml"
316 local lava_model_params="$workspace/lava_model_params"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500317
Leonardo Sandovalfda4f292020-10-06 15:59:26 -0500318 # this function expects a template, quit if it is not present
319 if [ ! -f "$yaml_template_file" ]; then
320 return
321 fi
322
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600323 local model_params="${fvp_models[$model]}"
324 local model_name="$(echo "${model_params}" | awk -F ';' '{print $1}')"
325 local model_dir="$(echo "${model_params}" | awk -F ';' '{print $2}')"
326 local model_bin="$(echo "${model_params}" | awk -F ';' '{print $3}')"
327
328 # model params are required for correct yaml creation, quit if empty
329 if [ -z "${model_name}" ]; then
330 echo "FVP model param 'model_name' variable empty, yaml not produced"
331 return
332 elif [ -z "${model_dir}" ]; then
333 echo "FVP model param 'model_dir' variable empty, yaml not produced"
334 return
335 elif [ -z "${model_bin}" ]; then
336 echo "FVP model param 'model_bin' variable empty, yaml not produced"
337 return
338 fi
339
340 echo "FVP model params: model_name=$model_name model_dir=$model_dir model_bin=$model_bin"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500341
342 # optional parameters, defaults to globals
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500343 local model_dtb="${model_dtb:-$default_model_dtb}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500344
Chris Kayc9523b12022-10-10 18:32:20 +0100345 if [ -n "${GERRIT_CHANGE_NUMBER}" ]; then
346 local gerrit_url="https://review.trustedfirmware.org/c/${GERRIT_CHANGE_NUMBER}/${GERRIT_PATCHSET_NUMBER}"
347 elif [ -n "${GERRIT_REFSPEC}" ]; then
348 local gerrit_url=$(echo ${GERRIT_REFSPEC} |
349 awk -F/ '{print "https://review.trustedfirmware.org/c/" $4 "/" $5}')
350 fi
351
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500352 docker_registry="${docker_registry:-}"
353 docker_registry="$(docker_registry_append)"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500354 docker_name="${docker_registry}$model_name"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600355 prompt1='/ #'
356 prompt2='root@genericarmv8:~#'
357 version_string="\"Fast Models"' [^\\n]+'"\""
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500358
Leonardo Sandoval5d87b702021-05-10 11:53:13 -0500359 test_config="${TEST_CONFIG}"
360
Chris Kay4eb9ded2022-10-10 15:51:40 +0100361 declare -A artefact_filters=(
362 [backup_fip]="backup_fip.bin"
363 [bl1]="bl1.bin"
364 [bl2]="bl2.bin"
365 [bl31]="bl31.bin"
366 [bl32]="bl32.bin"
367 [busybox]="busybox.bin"
368 [cactus_primary]="cactus-primary.pkg"
369 [cactus_secondary]="cactus-secondary.pkg"
370 [cactus_tertiary]="cactus-tertiary.pkg"
371 [coverage_trace_plugin]="coverage_trace.so"
372 [dtb]="dtb.bin"
373 [el3_payload]="el3_payload.bin"
374 [fip_gpt]="fip_gpt.bin"
375 [fip]="fip.bin"
376 [fvp_spmc_manifest_dtb]="=fvp_spmc_manifest.dtb"
377 [fwu_fip]="fwu_fip.bin"
378 [generic_trace]="GenericTrace.so"
379 [hafnium]="hafnium.bin"
380 [image]="kernel.bin"
381 [ivy]="ivy.pkg"
382 [manifest_dtb]="=manifest.dtb"
383 [mcp_rom_hyphen]="mcp-rom.bin"
384 [mcp_rom]="mcp_rom.bin"
385 [ns_bl1u]="ns_bl1u.bin"
386 [ns_bl2u]="ns_bl2u.bin"
387 [ramdisk]="initrd.bin|initrd.img"
388 [romlib]="romlib.bin"
389 [rootfs]="rootfs.bin"
390 [scp_ram_hyphen]="scp-ram.bin"
391 [scp_ram]="scp_ram.bin"
392 [scp_rom_hyphen]="scp-rom.bin"
393 [scp_rom]="scp_rom.bin"
394 [secure_hafnium]="secure_hafnium.bin"
395 [spm]="spm.bin"
396 [tftf]="tftf.bin"
397 [tmp]="tmp.bin"
398 [uboot]="uboot.bin"
399 )
400
Chris Kayc14743a2022-10-13 11:33:26 +0100401 declare -A artefact_urls=(
402 [backup_fip]="$(fvp_gen_bin_url backup_fip.bin)"
403 [bl1]="$(fvp_gen_bin_url bl1.bin)"
404 [bl2]="$(fvp_gen_bin_url bl2.bin)"
405 [bl31]="$(fvp_gen_bin_url bl31.bin)"
406 [bl32]="$(fvp_gen_bin_url bl32.bin)"
407 [busybox]="$(fvp_gen_bin_url busybox.bin.gz)"
408 [cactus_primary]="$(fvp_gen_bin_url cactus-primary.pkg)"
409 [cactus_secondary]="$(fvp_gen_bin_url cactus-secondary.pkg)"
410 [cactus_tertiary]="$(fvp_gen_bin_url cactus-tertiary.pkg)"
411 [coverage_trace_plugin]="${coverage_trace_plugin}"
412 [dtb]="$(fvp_gen_bin_url ${model_dtb})"
413 [el3_payload]="$(fvp_gen_bin_url el3_payload.bin)"
414 [fip]="$(fvp_gen_bin_url fip.bin)"
415 [fip_gpt]="$(fvp_gen_bin_url fip_gpt.bin)"
416 [fvp_spmc_manifest_dtb]="$(fvp_gen_bin_url fvp_spmc_manifest.dtb)"
417 [fwu_fip]="$(fvp_gen_bin_url fwu_fip.bin)"
418 [generic_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/GenericTrace.so"
419 [hafnium]="$(fvp_gen_bin_url hafnium.bin)"
420 [image]="$(fvp_gen_bin_url kernel.bin)"
421 [ivy]="$(fvp_gen_bin_url ivy.pkg)"
422 [manifest_dtb]="$(fvp_gen_bin_url manifest.dtb)"
423 [mcp_rom]="$(fvp_gen_bin_url mcp_rom.bin)"
424 [mcp_rom_hyphen]="$(fvp_gen_bin_url mcp-rom.bin)"
425 [ns_bl1u]="$(fvp_gen_bin_url ns_bl1u.bin)"
426 [ns_bl2u]="$(fvp_gen_bin_url ns_bl2u.bin)"
427 [ramdisk]="$(fvp_gen_bin_url initrd.bin)"
428 [romlib]="$(fvp_gen_bin_url romlib.bin)"
429 [rootfs]="$(fvp_gen_bin_url rootfs.bin.gz)"
430 [secure_hafnium]="$(fvp_gen_bin_url secure_hafnium.bin)"
431 [scp_ram]="$(fvp_gen_bin_url scp_ram.bin)"
432 [scp_ram_hyphen]="$(fvp_gen_bin_url scp-ram.bin)"
433 [scp_rom]="$(fvp_gen_bin_url scp_rom.bin)"
434 [scp_rom_hyphen]="$(fvp_gen_bin_url scp-rom.bin)"
435 [spm]="$(fvp_gen_bin_url spm.bin)"
436 [tftf]="$(fvp_gen_bin_url tftf.bin)"
437 [tmp]="$(fvp_gen_bin_url tmp.bin)"
438 [uboot]="$(fvp_gen_bin_url uboot.bin)"
439 )
440
Chris Kay5d550d82022-10-12 17:20:31 +0100441 # In LAVA we don't provide the paths to the artefacts directly, but instead
442 # use macros of the form `{XYZ}`. This is a list of regular expression
443 # replacements to run on the model parameters file before we add them to the
444 # LAVA job definition.
445 declare -A artefact_macros=(
446 ["[= ]backup_fip.bin"]="={BACKUP_FIP}"
447 ["[= ]bl1.bin"]="={BL1}"
448 ["[= ]bl2.bin"]="={BL2}"
449 ["[= ]bl31.bin"]="={BL31}"
450 ["[= ]bl32.bin"]="={BL32}"
451 ["[= ]cactus-primary.pkg"]="={CACTUS_PRIMARY}"
452 ["[= ]cactus-secondary.pkg"]="={CACTUS_SECONDARY}"
453 ["[= ]cactus-tertiary.pkg"]="={CACTUS_TERTIARY}"
454 ["[= ].*coverage_trace.so"]="={COVERAGE_TRACE_PLUGIN}"
455 ["[= ]fvp_spmc_manifest.dtb"]="={FVP_SPMC_MANIFEST_DTB}"
456 ["[= ]busybox.bin"]="={BUSYBOX}"
457 ["[= ]dtb.bin"]="={DTB}"
458 ["[= ]el3_payload.bin"]="={EL3_PAYLOAD}"
459 ["[= ]fip_gpt.bin"]="={FIP_GPT}"
460 ["[= ]fwu_fip.bin"]="={FWU_FIP}"
461 ["[= ]fip.bin"]="={FIP}"
462 ["[= ].*GenericTrace.so"]="={GENERIC_TRACE}"
463 ["[= ].*/hafnium.bin"]="={HAFNIUM}"
464 ["[= ]kernel.bin"]="={IMAGE}"
465 ["[= ]ivy.pkg"]="={IVY}"
466 ["[= ]manifest.dtb"]="={MANIFEST_DTB}"
467 ["[= ]mcp-rom.bin"]="={MCP_ROM}"
468 ["[= ]mcp_rom_hyphen.bin"]="={MCP_ROM_HYPHEN}"
469 ["[= ]ns_bl1u.bin"]="={NS_BL1U}"
470 ["[= ]ns_bl2u.bin"]="={NS_BL2U}"
471 ["[= ]initrd.bin"]="={RAMDISK}"
472 ["[= ]initrd.img"]="={RAMDISK}"
473 ["[= ]romlib.bin"]="={ROMLIB}"
474 ["[= ]rootfs.bin"]="={ROOTFS}"
475 ["[= ].*/secure_hafnium.bin"]="={SECURE_HAFNIUM}"
476 ["[= ]scp_ram.bin"]="={SCP_RAM}"
477 ["[= ]scp-ram.bin"]="={SCP_RAM_HYPHEN}"
478 ["[= ]scp_rom.bin"]="={SCP_ROM}"
479 ["[= ]scp-rom.bin"]="={SCP_ROM_HYPHEN}"
480 ["[= ]spm.bin"]="={SPM}"
481 ["[= ]tftf.bin"]="={TFTF}"
482 ["[= ].*/tmp.bin"]="={TMP}"
483 ["[= ]uboot.bin"]="={UBOOT}"
484 )
485
Chris Kay4eb9ded2022-10-10 15:51:40 +0100486 declare -a artefacts=()
487
488 for artefact in "${!artefact_filters[@]}"; do
489 if grep -E -q "${artefact_filters[${artefact}]}" "${archive}/model_params"; then
490 artefacts+=("${artefact}")
491 fi
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600492 done
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500493
Chris Kayc92d9fc2022-10-13 11:19:27 +0100494 # Derive LAVA model parameters from the non-LAVA ones
495 cp "${archive}/model_params" "${lava_model_params}"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600496
Chris Kayf07d3392022-10-26 15:42:48 +0100497 # Ensure braces in the FVP model parameters are not accidentally interpreted
498 # as LAVA macros.
499 sed -i -e 's/{/{{/g' "${lava_model_params}"
500 sed -i -e 's/}/}}/g' "${lava_model_params}"
501
Chris Kay5d550d82022-10-12 17:20:31 +0100502 # LAVA expects FVP binary paths as macros, i.e. `{X}` instead of `x.bin`, so
503 # replace the file paths in our pre-generated model parameters.
504 for regex in "${!artefact_macros[@]}"; do
505 sed -i -e "s!${regex}!${artefact_macros[${regex}]}!" \
506 "${lava_model_params}"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600507 done
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500508
Chris Kayc92d9fc2022-10-13 11:19:27 +0100509 # Read boot arguments into an array so that the job template file can
510 # iterate over them.
511 readarray -t boot_arguments < "${lava_model_params}"
512
513 # Generate the LAVA job definition, minus the test expectations
514 expand_template "${yaml_template_file}" > "${yaml_file}"
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500515
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500516 # Append expect commands into the job definition through test-interactive commands
517 gen_fvp_yaml_expect >> "$yaml_file"
518
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600519 # create job.yaml
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500520 cp "$yaml_file" "$yaml_job_file"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500521
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600522 # archive both yamls
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500523 archive_file "$yaml_file"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500524 archive_file "$yaml_job_file"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500525}
526
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500527gen_fvp_yaml_expect() {
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500528
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500529 run_root="$archive/run"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500530
531 # Loop through all uarts expect files
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500532 for expect_file in $(find $run_root -name expect); do
533
534 # TODO: currently, only handle UART 0
535 case $expect_file in
536 *uart0* )
537 uart_number=uart0
538 ;;
539 *)
540 continue
541 ;;
542 esac
543
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500544 # Array containing "interactive" or "monitor" expect strings and populated during run config execution.
545 # Interactive expect scripts are converted into LAVA Interactive Test Actions (see
546 # https://tf.validation.linaro.org/static/docs/v2/interactive.html#writing-tests-interactive) and
547 # monitor expect scripts are converted into LAVA Monitor Test Actions (see
548 # https://validation.linaro.org/static/docs/v2/actions-test.html#monitor)
549 #
550 # Interactive Expect strings have the format 'i;<prompt>;<succeses>;<failures>;<commands>'
551 # where multiple successes or failures or commands are separated by @
552 #
553 # Monitor Expect strings have the format 'm;<start>;<end>;<patterns>'
554 # where multiple patterns are separated by @
555 #
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500556 expect_string=()
557
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500558 # Get the real name of the expect file
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500559 expect_file=$(cat $expect_file)
560
561 # Source the run_config enviroment variables
562 env=$run_root/$uart_number/env
563 if [ -e $env ]; then
564 source $env
565 fi
566
567 # Get all expect strings
Chris Kay047af3e2022-09-30 17:10:28 +0100568 expect_dir="${ci_root}/expect-lava"
569 expect_file="${expect_dir}/${expect_file}"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500570
Chris Kay047af3e2022-09-30 17:10:28 +0100571 # Allow the expectations to be provided directly in LAVA's job YAML
572 # format, rather than converting it from a pseudo-Expect Bash script in
573 # the block below.
574 if [ -f "${expect_file/.exp/.yaml}" ]; then
575 pushd "${expect_dir}"
576 expand_template "${expect_file/.exp/.yaml}"
577 popd
578
579 continue
580 else
581 source "${expect_file}"
582 fi
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500583
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500584 if [ ${#expect_string[@]} -gt 0 ]; then
585
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500586 # expect loop
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500587 for key in "${!expect_string[@]}"; do
588
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500589 # single raw expect string
590 es="${expect_string[${key}]}"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500591
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500592 # action type: either m or i
593 action="$(echo "${es}" | awk -F ';' '{print $1}')"
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500594
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500595 if [ "${action}" = "m" ]; then
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500596
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500597 start="$(echo "${es}" | awk -F ';' '{print $2}')"
598 end="$(echo "${es}" | awk -F ';' '{print $3}')"
599 patterns="$(echo "${es}" | awk -F ';' '{print $4}')"
600
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500601 cat << EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500602- test:
603 monitors:
604 - name: tests
605 start: '${start}'
606 end: '${end}'
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500607EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500608 # Patterns are separated by '@'
609 OLD_IFS=$IFS; IFS=$'@'
610 for p in ${patterns}; do
611 cat << EOF
612 pattern: '$p'
613EOF
614 done
615 IFS=$OLD_IFS
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500616 cat << EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500617 fixupdict:
618 PASS: pass
619 FAIL: fail
620EOF
621 fi # end of monitor action
622
623 if [ "${action}" = "i" ]; then
624
625 prompts="$(echo "${es}" | awk -F ';' '{print $2}')"
626 successes="$(echo "${es}" | awk -F ';' '{print $3}')"
627 failures="$(echo "${es}" | awk -F ';' '{print $4}')"
628 commands="$(echo "${es}" | awk -F ';' '{print $5}')"
629
630 cat << EOF
631- test:
632 interactive:
633EOF
634 OLD_IFS=$IFS; IFS=$'@'
635
636 if [[ -n "${prompts}" && -n "${successes}" && -n "${failures}" ]]; then
637 cat << EOF
638 - name: interactive_${uart_number}_${key}
639 prompts: ['${prompts}']
640 script:
641EOF
642 if [ -z "${commands}" ]; then
643 cat <<EOF
644 - name: interactive_command_${uart_number}_${key}
645 command:
646EOF
647 else
648 for c in ${commands}; do
649 cat <<EOF
650 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300651 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500652EOF
653 done
654 fi
655 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500656 successes:
657EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500658 for s in ${successes}; do
659 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500660 - message: '$s'
661EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500662 done
663 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500664 failures:
665EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500666 for f in ${failures}; do
667 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500668 - message: '$f'
669EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500670 done
671 elif [[ -n "${prompts}" && -n "${successes}" ]]; then
672 cat << EOF
673 - name: interactive_${uart_number}_${key}
674 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500675 script:
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500676EOF
677
678 if [ -z "${commands}" ]; then
679 cat <<EOF
680 - name: interactive_command_${uart_number}_${key}
681 command:
682EOF
683 else
684 for c in ${commands}; do
685 cat <<EOF
686 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300687 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500688EOF
689 done
690 fi
691 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500692 successes:
693EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500694 for s in ${successes}; do
695 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500696 - message: '$s'
697EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500698 done
699
700 elif [[ -n "${prompts}" && -n "${failures}" ]]; then
701 cat << EOF
702 - name: interactive_${uart_number}_${key}
703 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500704 script:
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500705EOF
706 if [ -z "${commands}" ]; then
707 cat <<EOF
708 - name: interactive_command_${uart_number}_${key}
709 command:
710EOF
711 else
712 for c in ${commands}; do
713 cat <<EOF
714 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300715 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500716EOF
717 done
718 fi
719 cat << EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500720 failures:
721EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500722 for f in ${failures}; do
723 cat <<EOF
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500724 - message: '$f'
725EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500726 done
727 else
728 cat << EOF
729 - name: interactive_${uart_number}_${key}
730 prompts: ['${prompts}']
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500731 script:
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500732EOF
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500733 if [ -z "${commands}" ]; then
734 cat <<EOF
735 - name: interactive_command_${uart_number}_${key}
736 command:
737EOF
738 else
739 for c in ${commands}; do
740 cat <<EOF
741 - name: interactive_command_${uart_number}_${key}
Paul Sokolovskydf445242021-12-15 16:57:51 +0300742 command: "$c"
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500743EOF
744 done
745 fi
746 fi
747
748 IFS=$OLD_IFS
749 fi # end of interactive action
750
751 done # end of expect loop
752
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500753 fi
Leonardo Sandoval5cfc11f2021-09-08 16:08:13 -0500754 done # end of uart loop
Leonardo Sandovalcd06bf42021-04-08 11:53:39 -0500755}
756
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500757docker_registry_append() {
758 # if docker_registry is empty, just use local docker registry
759 [ -z "$docker_registry" ] && return
760
761 local last=-1
762 local last_char="${docker_registry:last}"
763
764 if [ "$last_char" != '/' ]; then
765 docker_registry="${docker_registry}/";
766 fi
767 echo "$docker_registry"
768}
769
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000770# generate GPT image and archive it
771gen_gpt_bin() {
772 raw_image="fip_gpt.bin"
773 img_uuid="FB90808A-BA9A-4D42-B9A2-A7A937144AEE"
774 img_bank_uuid=`uuidgen`
775 disk_uuid=`uuidgen`
776 bin="${1:?}"
777
778 # maximum FIP size 2MB
779 fip_max_size=2097152
780 start_sector=34
781 sector_size=512
782 num_sectors=$(($fip_max_size/$sector_size))
783 bin_size=$(stat -c %s $bin)
784
785 if [[ $fip_max_size -lt $bin_size ]]
786 then
787 echo "FIP binary ($bin_size bytes) larger than max partition 1"
788 "size ($fip_max_size byte)"
789 return
790 fi
791
792 # create raw 5MB image
793 dd if=/dev/zero of=$raw_image bs=5M count=1
794
795 # create GPT image
796 sgdisk -a 1 -U $disk_uuid -n 1:$start_sector:+$num_sectors \
797 -c 1:FIP_A -t 1:$img_uuid $raw_image -u $img_bank_uuid
798
799 echo "write binary $bin at sector $start_sector"
800 dd if=$bin of=$raw_image bs=$sector_size seek=$start_sector \
801 count=$num_sectors conv=notrunc
802
803 archive_file "fip_gpt.bin"
804}
805
Fathi Boudra422bf772019-12-02 11:10:16 +0200806set +u