blob: 0e186b012032e8380ce98f3d6472574d01f2e9be [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Govindraj Raja1d208f72025-02-11 12:20:32 -06003# Copyright (c) 2020-2025, 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}"
Harrison Mutai3dcd1fe2025-03-24 13:19:29 +000018boot_script_addr="${boot_script_addr:-0x8fb00000}"
Fathi Boudra422bf772019-12-02 11:10:16 +020019el3_payload_addr="${el3_payload_addr:-0x80000000}"
20
Manish Pandey3c435582020-07-15 12:14:26 +010021# SPM requires following addresses for RESET_TO_BL31 case
22spm_addr="${spm_addr:-0x6000000}"
23spmc_manifest_addr="${spmc_addr:-0x0403f000}"
24sp1_addr="${sp1_addr:-0x7000000}"
25sp2_addr="${sp2_addr:-0x7100000}"
Olivier Deprez0b834092020-08-21 08:36:01 +020026sp3_addr="${sp3_addr:-0x7200000}"
Olivier Deprezdd9ed332021-07-02 12:07:17 +020027sp4_addr="${sp4_addr:-0x7600000}"
Manish Pandey1e7be852020-11-09 16:04:48 +000028# SPM out directories
J-Alves12d796c2023-02-27 10:30:58 +000029export spm_secure_out_dir="${spm_secure_out_dir:-secure_aem_v8a_fvp_vhe_clang}"
30export spm_non_secure_out_dir="${spm_non_secure_out_dir:-aem_v8a_fvp_vhe_clang}"
Manish Pandey3c435582020-07-15 12:14:26 +010031
Fathi Boudra422bf772019-12-02 11:10:16 +020032ns_bl1u_addr="${ns_bl1u_addr:-0x0beb8000}"
33fwu_fip_addr="${fwu_fip_addr:-0x08400000}"
34backup_fip_addr="${backup_fip_addr:-0x09000000}"
35romlib_addr="${romlib_addr:-0x03ff2000}"
36
Harrison Mutai6f4fd6c2023-03-27 13:22:41 +010037uefi_downloads="${uefi_downloads:-http://files.oss.arm.com/downloads/uefi}"
38uefi_ci_bin_url="${uefi_ci_bin_url:-$uefi_downloads/Artifacts/Linux/github/fvp/static/DEBUG_GCC5/FVP_AARCH64_EFI.fd}"
39
Fathi Boudra422bf772019-12-02 11:10:16 +020040uboot32_fip_url="$linaro_release/fvp32-latest-busybox-uboot/fip.bin"
Harrison Mutai3dcd1fe2025-03-24 13:19:29 +000041if [[ "$test_config" == *handoff* ]]; then
42 uboot_url="${tfa_downloads}/handoff/fvp/u-boot.bin"
43else
44 uboot_url="$linaro_release/fvp-latest-busybox-uboot/bl33-uboot.bin"
45fi
46uboot_script_url="${tfa_downloads}/linux_boot/fvp/boot.scr"
Fathi Boudra422bf772019-12-02 11:10:16 +020047
Alexei Fedorove405cc32020-09-30 18:13:55 +010048rootfs_url="$linaro_release/lt-vexpress64-openembedded_minimal-armv8-gcc-5.2_20170127-761.img.gz"
Fathi Boudra422bf772019-12-02 11:10:16 +020049
Harrison Mutaiae6fbf12025-04-11 15:18:21 +000050optee_version="4.5.0"
Harrison Mutai0a3e6282024-10-11 14:03:20 +000051optee_path=$tfa_downloads/optee/${optee_version}
52
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050053# Default FVP model variables
Leonardo Sandovale1460662021-05-27 16:05:38 -050054default_model_dtb="dtb.bin"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050055
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060056# FVP containers and model paths
Maksims Svecovs284a50d2021-11-02 11:09:47 +000057fvp_arm_std_library="fvp:fvp_arm_std_library_${model_version}_${model_build};/opt/model/FVP_ARM_Std_Library/FVP_Base"
laurenw-armf414aba2021-04-26 15:58:56 -050058fvp_base_revc_2xaemva="fvp:fvp_base_revc-2xaemva_${model_version}_${model_build};/opt/model/Base_RevC_AEMvA_pkg/models/${model_flavour}"
johpow01936638d2021-11-08 18:22:24 -060059fvp_base_aemv8r="fvp:fvp_base_aemv8r_${model_version}_${model_build};/opt/model/AEMv8R_base_pkg/models/${model_flavour}"
Govindraj Rajafa86cf62025-02-19 14:55:48 -060060fvp_rd_1_ae="fvp:fvp_rd_1_ae_${model_version}_${model_build};/opt/model/FVP_RD_1_AE/models/${model_flavour}"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050061
Manish V Badarkhef65f9a32022-11-04 10:07:19 +000062# CSS model list
Govindraj Rajafa86cf62025-02-19 14:55:48 -060063fvp_tc4="fvp:fvp_tc4_${model_version}_${model_build};/opt/model/FVP_TC4/models/${model_flavour}"
Manish V Badarkhef65f9a32022-11-04 10:07:19 +000064
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060065# FVP associate array, run_config are keys and fvp container parameters are the values
66# Container parameters syntax: <model name>;<model dir>;<model bin>
67# FIXMEs: fix those ;;; values with real values
68
69declare -A fvp_models
70fvp_models=(
laurenw-armafdc3bc2022-09-14 15:31:42 -050071[base-aemv8a-revb]="${fvp_arm_std_library};FVP_Base_AEMvA-AEMvA"
Manish Pandeya60d8072024-03-11 09:58:53 +000072[base-aemva]="${fvp_base_revc_2xaemva};FVP_Base_RevC-2xAEMvA"
laurenw-armf414aba2021-04-26 15:58:56 -050073[base-aemv8a]="${fvp_base_revc_2xaemva};FVP_Base_RevC-2xAEMvA"
Govindraj Rajafa86cf62025-02-19 14:55:48 -060074[cortex-a32x4]="${fvp_arm_std_library};FVP_Base_Cortex-A32"
75[cortex-a35x4]="${fvp_arm_std_library};FVP_Base_Cortex-A35"
76[cortex-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A53"
laurenw-armafdc3bc2022-09-14 15:31:42 -050077[cortex-a55x4]="${fvp_arm_std_library};FVP_Base_Cortex-A55"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060078[cortex-a57x1-a53x1]="${fvp_arm_std_library};FVP_Base_Cortex-A57x1-A53x1"
79[cortex-a57x2-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57x2-A53x4"
Govindraj Rajafa86cf62025-02-19 14:55:48 -060080[cortex-a57x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060081[cortex-a57x4-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A57x4-A53x4"
Govindraj Rajafa86cf62025-02-19 14:55:48 -060082[cortex-a65aex8]="${fvp_arm_std_library};FVP_Base_Cortex-A65AE"
83[cortex-a65x4]="${fvp_arm_std_library};FVP_Base_Cortex-A65"
84[cortex-a72x4]="${fvp_arm_std_library};FVP_Base_Cortex-A72"
85[cortex-a73x4]="${fvp_arm_std_library};FVP_Base_Cortex-A73"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060086[cortex-a73x4-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A73x4-A53x4"
laurenw-armafdc3bc2022-09-14 15:31:42 -050087[cortex-a75x4]="${fvp_arm_std_library};FVP_Base_Cortex-A75"
88[cortex-a76aex4]="${fvp_arm_std_library};FVP_Base_Cortex-A76AE"
laurenw-armafdc3bc2022-09-14 15:31:42 -050089[cortex-a76x4]="${fvp_arm_std_library};FVP_Base_Cortex-A76"
90[cortex-a77x4]="${fvp_arm_std_library};FVP_Base_Cortex-A77"
91[cortex-a78x4]="${fvp_arm_std_library};FVP_Base_Cortex-A78"
Juan Pablo Conded52a4752023-03-21 14:52:10 -050092[cortex-a78aex4]="${fvp_arm_std_library};FVP_Base_Cortex-A78AE"
laurenw-armafdc3bc2022-09-14 15:31:42 -050093[cortex-a78cx4]="${fvp_arm_std_library};FVP_Base_Cortex-A78C"
Govindraj Raja8962c452024-06-04 14:50:28 -050094[cortex-x2]="${fvp_arm_std_library};FVP_Base_Cortex-X2"
Govindraj Raja1d208f72025-02-11 12:20:32 -060095[cortex-x4]="${fvp_arm_std_library};FVP_Base_Cortex-X4"
96[cortex-x925]="${fvp_arm_std_library};FVP_Base_Cortex-X925"
Govindraj Raja268a2be2024-07-01 14:31:31 -050097[cortex-a710x8]="${fvp_arm_std_library};FVP_Base_Cortex-A710"
Govindraj Rajafa86cf62025-02-19 14:55:48 -060098[neoverse_e1]="${fvp_arm_std_library};FVP_Base_Neoverse-E1"
laurenw-armafdc3bc2022-09-14 15:31:42 -050099[neoverse_n1]="${fvp_arm_std_library};FVP_Base_Neoverse-N1"
Govindraj Raja8962c452024-06-04 14:50:28 -0500100[neoverse_n2]="${fvp_arm_std_library};FVP_Base_Neoverse-N2"
laurenw-armafdc3bc2022-09-14 15:31:42 -0500101[neoverse-v1x4]="${fvp_arm_std_library};FVP_Base_Neoverse-V1"
Icen Zeyadab68a5612024-11-08 07:35:44 +0000102[tc4]="${fvp_tc4};FVP_TC4"
Divin Rajb0071052023-07-04 14:35:07 +0100103[baser-aemv8r]="${fvp_base_aemv8r};FVP_BaseR_AEMv8R"
Divin Raj5eb69482024-10-02 11:36:04 +0100104[rd1ae]="${fvp_rd_1_ae};FVP_RD_1_AE"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600105)
106
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500107
Fathi Boudra422bf772019-12-02 11:10:16 +0200108# FVP Kernel URLs
Harrison Mutai6f4fd6c2023-03-27 13:22:41 +0100109declare -A kernel_list
110kernel_list=(
Fathi Boudra422bf772019-12-02 11:10:16 +0200111[fvp-aarch32-zimage]="$linaro_release/fvp32-latest-busybox-uboot/Image"
112[fvp-busybox-uboot]="$linaro_release/fvp-latest-busybox-uboot/Image"
113[fvp-oe-uboot32]="$linaro_release/fvp32-latest-oe-uboot/Image"
114[fvp-oe-uboot]="$linaro_release/fvp-latest-oe-uboot/Image"
115[fvp-quad-busybox-uboot]="$tfa_downloads/quad_cluster/Image"
116)
117
Fathi Boudra422bf772019-12-02 11:10:16 +0200118# FVP initrd URLs
Harrison Mutai6f4fd6c2023-03-27 13:22:41 +0100119declare -A initrd_list
120initrd_list=(
Fathi Boudra422bf772019-12-02 11:10:16 +0200121[aarch32-ramdisk]="$linaro_release/fvp32-latest-busybox-uboot/ramdisk.img"
Fathi Boudra422bf772019-12-02 11:10:16 +0200122[dummy-ramdisk]="$linaro_release/fvp-latest-oe-uboot/ramdisk.img"
123[dummy-ramdisk32]="$linaro_release/fvp32-latest-oe-uboot/ramdisk.img"
124[default]="$linaro_release/fvp-latest-busybox-uboot/ramdisk.img"
125)
126
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100127# For Measured Boot tests using a TA based on OPTEE, it is necessary to use a
128# specific build rather than the default one generated by Jenkins.
129get_ftpm_optee_bin() {
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100130 url="$tfa_downloads/ftpm/optee/tee-header_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100131 saveas="bl32.bin" fetch_file
132 archive_file "bl32.bin"
133
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100134 url="$tfa_downloads/ftpm/optee/tee-pager_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100135 saveas="bl32_extra1.bin" fetch_file
136 archive_file "bl32_extra1.bin"
137
Leonardo Sandovalda5f78d2021-03-18 11:09:30 -0600138 # tee-pageable_v2.bin is just a empty file, named as bl32_extra2.bin,
139 # so just create the file
140 touch "bl32_extra2.bin"
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100141 archive_file "bl32_extra2.bin"
142}
143
Fathi Boudra422bf772019-12-02 11:10:16 +0200144get_dtb() {
145 local dtb_type="${dtb_type:?}"
146 local dtb_url
147 local dtb_saveas="$workspace/dtb.bin"
Zelalem219df412020-05-17 19:21:20 -0500148 local cc="$(get_tf_opt CROSS_COMPILE)"
149 local pp_flags="-P -nostdinc -undef -x assembler-with-cpp"
Fathi Boudra422bf772019-12-02 11:10:16 +0200150
151 case "$dtb_type" in
152 "fvp-base-quad-cluster-gicv3-psci")
153 # Get the quad-cluster FDT from pdsw area
154 dtb_url="$tfa_downloads/quad_cluster/fvp-base-quad-cluster-gicv3-psci.dtb"
155 url="$dtb_url" saveas="$dtb_saveas" fetch_file
156 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200157 *)
Zelalem219df412020-05-17 19:21:20 -0500158 # Preprocess DTS file
159 ${cc}gcc -E ${pp_flags} -I"$tf_root/fdts" -I"$tf_root/include" \
160 -o "$workspace/${dtb_type}.pre.dts" \
161 "$tf_root/fdts/${dtb_type}.dts"
162 # Generate DTB file from DTS
Fathi Boudra422bf772019-12-02 11:10:16 +0200163 dtc -I dts -O dtb \
Zelalem219df412020-05-17 19:21:20 -0500164 "$workspace/${dtb_type}.pre.dts" -o "$dtb_saveas"
Fathi Boudra422bf772019-12-02 11:10:16 +0200165 esac
166
167 archive_file "$dtb_saveas"
168}
169
170get_rootfs() {
171 local tmpdir
172 local fs_base="$(echo $(basename $rootfs_url) | sed 's/\.gz$//')"
173 local cached="$project_filer/ci-files/$fs_base"
174
175 if upon "$jenkins_run" && [ -f "$cached" ]; then
176 # Job workspace is limited in size, and the root file system is
177 # quite large. This means, parallel runs of root file system
178 # tests could fail. So, for Jenkins runs, copy and use the root
179 # file system image from the $CI_SCRATCH location
180 local private="$CI_SCRATCH/$JOB_NAME-$BUILD_NUMBER"
181 mkdir -p "$private"
182 rm -f "$private/rootfs.bin"
183 url="$cached" saveas="$private/rootfs.bin" fetch_file
184 ln -s "$private/rootfs.bin" "$archive/rootfs.bin"
185 return
186 fi
187
188 tmpdir="$(mktempdir)"
189 pushd "$tmpdir"
190 url="$rootfs_url" saveas="rootfs.bin" fetch_file
191
192 # Possibly, the filesystem image we just downloaded is compressed.
193 # Decompress it if required.
194 if file "rootfs.bin" | grep -iq 'gzip compressed data'; then
195 echo "Decompressing root file system image rootfs.bin ..."
196 gunzip --stdout "rootfs.bin" > uncompressed_fs.bin
197 mv uncompressed_fs.bin "rootfs.bin"
198 fi
199
200 archive_file "rootfs.bin"
201 popd
202}
203
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200204fvp_romlib_jmptbl_backup="$(mktempdir)/jmptbl.i"
205
Fathi Boudra422bf772019-12-02 11:10:16 +0200206fvp_romlib_runtime() {
207 local tmpdir="$(mktempdir)"
208
209 # Save BL1 and romlib binaries from original build
210 mv "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin" "$tmpdir/romlib.bin"
211 mv "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin" "$tmpdir/bl1.bin"
212
213 # Patch index file
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200214 cp "${tf_root:?}/plat/arm/board/fvp/jmptbl.i" "$fvp_romlib_jmptbl_backup"
215 sed -i '/fdt/ s/.$/&\ patch/' ${tf_root:?}/plat/arm/board/fvp/jmptbl.i
Fathi Boudra422bf772019-12-02 11:10:16 +0200216
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200217 # Rebuild with patched file
218 echo "Building patched romlib:"
219 build_tf
Fathi Boudra422bf772019-12-02 11:10:16 +0200220
Fathi Boudra422bf772019-12-02 11:10:16 +0200221 # Retrieve original BL1 and romlib binaries
222 mv "$tmpdir/romlib.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin"
223 mv "$tmpdir/bl1.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin"
224}
225
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200226fvp_romlib_cleanup() {
227 # Restore original index
228 mv "$fvp_romlib_jmptbl_backup" "${tf_root:?}/plat/arm/board/fvp/jmptbl.i"
229}
230
231
Chris Kayc9523b12022-10-10 18:32:20 +0100232# Generates the final YAML-based LAVA job definition from a template file.
233#
234# The job definition template is expanded with visibility of all variables that
235# are available from within the function, including those with local scope.
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500236gen_fvp_yaml() {
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600237 local model="${model:?}"
238
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500239 local yaml_template_file="$workspace/fvp_template.yaml"
240 local yaml_file="$workspace/fvp.yaml"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500241 local yaml_job_file="$workspace/job.yaml"
242 local lava_model_params="$workspace/lava_model_params"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500243
Leonardo Sandovalfda4f292020-10-06 15:59:26 -0500244 # this function expects a template, quit if it is not present
245 if [ ! -f "$yaml_template_file" ]; then
Paul Sokolovskya3c5a4c2023-01-24 18:33:58 +0700246 echo "warning: gen_fvp_yaml: template $yaml_template_file not available, skipping generating LAVA job"
Leonardo Sandovalfda4f292020-10-06 15:59:26 -0500247 return
248 fi
249
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600250 local model_params="${fvp_models[$model]}"
251 local model_name="$(echo "${model_params}" | awk -F ';' '{print $1}')"
252 local model_dir="$(echo "${model_params}" | awk -F ';' '{print $2}')"
253 local model_bin="$(echo "${model_params}" | awk -F ';' '{print $3}')"
254
255 # model params are required for correct yaml creation, quit if empty
256 if [ -z "${model_name}" ]; then
257 echo "FVP model param 'model_name' variable empty, yaml not produced"
258 return
259 elif [ -z "${model_dir}" ]; then
260 echo "FVP model param 'model_dir' variable empty, yaml not produced"
261 return
262 elif [ -z "${model_bin}" ]; then
263 echo "FVP model param 'model_bin' variable empty, yaml not produced"
264 return
265 fi
266
267 echo "FVP model params: model_name=$model_name model_dir=$model_dir model_bin=$model_bin"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500268
269 # optional parameters, defaults to globals
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500270 local model_dtb="${model_dtb:-$default_model_dtb}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500271
Chris Kayc9523b12022-10-10 18:32:20 +0100272 if [ -n "${GERRIT_CHANGE_NUMBER}" ]; then
273 local gerrit_url="https://review.trustedfirmware.org/c/${GERRIT_CHANGE_NUMBER}/${GERRIT_PATCHSET_NUMBER}"
274 elif [ -n "${GERRIT_REFSPEC}" ]; then
275 local gerrit_url=$(echo ${GERRIT_REFSPEC} |
276 awk -F/ '{print "https://review.trustedfirmware.org/c/" $4 "/" $5}')
277 fi
278
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500279 docker_registry="${docker_registry:-}"
280 docker_registry="$(docker_registry_append)"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500281 docker_name="${docker_registry}$model_name"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600282 prompt1='/ #'
283 prompt2='root@genericarmv8:~#'
284 version_string="\"Fast Models"' [^\\n]+'"\""
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500285
Leonardo Sandoval5d87b702021-05-10 11:53:13 -0500286 test_config="${TEST_CONFIG}"
287
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100288 declare -A fvp_artefact_filters=(
Chris Kay4eb9ded2022-10-10 15:51:40 +0100289 [backup_fip]="backup_fip.bin"
290 [bl1]="bl1.bin"
291 [bl2]="bl2.bin"
292 [bl31]="bl31.bin"
293 [bl32]="bl32.bin"
294 [busybox]="busybox.bin"
Harrison Mutai3dcd1fe2025-03-24 13:19:29 +0000295 [boot_script]="boot_script.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100296 [cactus_primary]="cactus-primary.pkg"
297 [cactus_secondary]="cactus-secondary.pkg"
298 [cactus_tertiary]="cactus-tertiary.pkg"
299 [coverage_trace_plugin]="coverage_trace.so"
300 [dtb]="dtb.bin"
301 [el3_payload]="el3_payload.bin"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000302 [etm_trace]="ETMv4ExamplePlugin.so"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100303 [fip_gpt]="fip_gpt.bin"
304 [fip]="fip.bin"
305 [fvp_spmc_manifest_dtb]="=fvp_spmc_manifest.dtb"
306 [fwu_fip]="fwu_fip.bin"
307 [generic_trace]="GenericTrace.so"
308 [hafnium]="hafnium.bin"
309 [image]="kernel.bin"
310 [ivy]="ivy.pkg"
311 [manifest_dtb]="=manifest.dtb"
Chris Kayfbdd0142022-11-08 12:24:30 +0000312 [mcp_fw]="mcp_fw.bin"
Manish V Badarkhe18c59782022-11-09 10:14:48 +0000313 [mcp_ram]="mcp_ram.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100314 [mcp_rom_hyphen]="mcp-rom.bin"
315 [mcp_rom]="mcp_rom.bin"
316 [ns_bl1u]="ns_bl1u.bin"
317 [ns_bl2u]="ns_bl2u.bin"
318 [ramdisk]="initrd.bin|initrd.img"
319 [romlib]="romlib.bin"
320 [rootfs]="rootfs.bin"
laurenw-arm60de2742023-03-08 10:50:15 -0600321 [host_flash_fip]="host_flash_fip.bin"
Divin Raj5eb69482024-10-02 11:36:04 +0100322 [rse_flash]="rse_flash.bin"
David Vinczed8ed5622024-02-23 17:00:12 +0100323 [rse_rom]="rse_rom.bin"
324 [rse_encrypted_cm_provisioning_bundle_0]="rse_encrypted_cm_provisioning_bundle_0.bin"
325 [rse_encrypted_dm_provisioning_bundle]="rse_encrypted_dm_provisioning_bundle.bin"
Chris Kayfbdd0142022-11-08 12:24:30 +0000326 [scp_fw]="scp_fw.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100327 [scp_ram_hyphen]="scp-ram.bin"
328 [scp_ram]="scp_ram.bin"
329 [scp_rom_hyphen]="scp-rom.bin"
330 [scp_rom]="scp_rom.bin"
331 [secure_hafnium]="secure_hafnium.bin"
332 [spm]="spm.bin"
Manish V Badarkhe9589d402024-01-29 16:46:41 +0000333 [tc_fitimage]="tc_fitimage.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100334 [tftf]="tftf.bin"
Harrison Mutai3ad377a2024-05-20 15:28:52 +0000335 [tl]="tl.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100336 [tmp]="tmp.bin"
337 [uboot]="uboot.bin"
338 )
339
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100340 declare -A fvp_artefact_urls=(
Harrison Mutaie5122542023-03-27 13:14:18 +0100341 [backup_fip]="$(gen_bin_url backup_fip.bin)"
342 [bl1]="$(gen_bin_url bl1.bin)"
343 [bl2]="$(gen_bin_url bl2.bin)"
344 [bl31]="$(gen_bin_url bl31.bin)"
345 [bl32]="$(gen_bin_url bl32.bin)"
346 [busybox]="$(gen_bin_url busybox.bin.gz)"
Harrison Mutai3dcd1fe2025-03-24 13:19:29 +0000347 [boot_script]="$(gen_bin_url boot_script.bin)"
Harrison Mutaie5122542023-03-27 13:14:18 +0100348 [cactus_primary]="$(gen_bin_url cactus-primary.pkg)"
349 [cactus_secondary]="$(gen_bin_url cactus-secondary.pkg)"
350 [cactus_tertiary]="$(gen_bin_url cactus-tertiary.pkg)"
Thaddeus Gonzalez-Serna211688c2025-03-21 19:12:37 -0500351 [coverage_trace_plugin]="$(gen_cc_url)"
Harrison Mutaie5122542023-03-27 13:14:18 +0100352 [dtb]="$(gen_bin_url ${model_dtb})"
353 [el3_payload]="$(gen_bin_url el3_payload.bin)"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000354 [etm_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/ETMv4ExamplePlugin.so"
Harrison Mutaie5122542023-03-27 13:14:18 +0100355 [fip]="$(gen_bin_url fip.bin)"
356 [fip_gpt]="$(gen_bin_url fip_gpt.bin)"
357 [fvp_spmc_manifest_dtb]="$(gen_bin_url fvp_spmc_manifest.dtb)"
358 [fwu_fip]="$(gen_bin_url fwu_fip.bin)"
Chris Kayc14743a2022-10-13 11:33:26 +0100359 [generic_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/GenericTrace.so"
Harrison Mutaie5122542023-03-27 13:14:18 +0100360 [hafnium]="$(gen_bin_url hafnium.bin)"
361 [image]="$(gen_bin_url kernel.bin)"
362 [ivy]="$(gen_bin_url ivy.pkg)"
363 [manifest_dtb]="$(gen_bin_url manifest.dtb)"
364 [mcp_fw]="$(gen_bin_url mcp_fw.bin)"
365 [mcp_ram]="$(gen_bin_url mcp_ram.bin)"
366 [mcp_rom]="$(gen_bin_url mcp_rom.bin)"
367 [mcp_rom_hyphen]="$(gen_bin_url mcp-rom.bin)"
368 [ns_bl1u]="$(gen_bin_url ns_bl1u.bin)"
369 [ns_bl2u]="$(gen_bin_url ns_bl2u.bin)"
370 [ramdisk]="$(gen_bin_url initrd.bin)"
371 [romlib]="$(gen_bin_url romlib.bin)"
372 [rootfs]="$(gen_bin_url rootfs.bin.gz)"
373 [host_flash_fip]="$(gen_bin_url host_flash_fip.bin)"
Divin Raj5eb69482024-10-02 11:36:04 +0100374 [rse_flash]="$(gen_bin_url rse_flash.bin)"
David Vinczed8ed5622024-02-23 17:00:12 +0100375 [rse_rom]="$(gen_bin_url rse_rom.bin)"
376 [rse_encrypted_cm_provisioning_bundle_0]="$(gen_bin_url rse_encrypted_cm_provisioning_bundle_0.bin)"
377 [rse_encrypted_dm_provisioning_bundle]="$(gen_bin_url rse_encrypted_dm_provisioning_bundle.bin)"
Harrison Mutaie5122542023-03-27 13:14:18 +0100378 [secure_hafnium]="$(gen_bin_url secure_hafnium.bin)"
379 [scp_fw]="$(gen_bin_url scp_fw.bin)"
380 [scp_ram]="$(gen_bin_url scp_ram.bin)"
381 [scp_ram_hyphen]="$(gen_bin_url scp-ram.bin)"
382 [scp_rom]="$(gen_bin_url scp_rom.bin)"
383 [scp_rom_hyphen]="$(gen_bin_url scp-rom.bin)"
384 [spm]="$(gen_bin_url spm.bin)"
Manish V Badarkhe9589d402024-01-29 16:46:41 +0000385 [tc_fitimage]="$(gen_bin_url tc_fitimage.bin)"
Harrison Mutaie5122542023-03-27 13:14:18 +0100386 [tftf]="$(gen_bin_url tftf.bin)"
Harrison Mutai3ad377a2024-05-20 15:28:52 +0000387 [tl]="$(gen_bin_url tl.bin)"
Harrison Mutaie5122542023-03-27 13:14:18 +0100388 [tmp]="$(gen_bin_url tmp.bin)"
389 [uboot]="$(gen_bin_url uboot.bin)"
Chris Kayc14743a2022-10-13 11:33:26 +0100390 )
391
Chris Kay5d550d82022-10-12 17:20:31 +0100392 # In LAVA we don't provide the paths to the artefacts directly, but instead
393 # use macros of the form `{XYZ}`. This is a list of regular expression
394 # replacements to run on the model parameters file before we add them to the
395 # LAVA job definition.
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100396 declare -A fvp_artefact_macros=(
Chris Kay5d550d82022-10-12 17:20:31 +0100397 ["[= ]backup_fip.bin"]="={BACKUP_FIP}"
398 ["[= ]bl1.bin"]="={BL1}"
399 ["[= ]bl2.bin"]="={BL2}"
400 ["[= ]bl31.bin"]="={BL31}"
401 ["[= ]bl32.bin"]="={BL32}"
Harrison Mutai3dcd1fe2025-03-24 13:19:29 +0000402 ["[= ]boot_script.bin"]="={BOOT_SCRIPT}"
Chris Kay5d550d82022-10-12 17:20:31 +0100403 ["[= ]cactus-primary.pkg"]="={CACTUS_PRIMARY}"
404 ["[= ]cactus-secondary.pkg"]="={CACTUS_SECONDARY}"
405 ["[= ]cactus-tertiary.pkg"]="={CACTUS_TERTIARY}"
406 ["[= ].*coverage_trace.so"]="={COVERAGE_TRACE_PLUGIN}"
407 ["[= ]fvp_spmc_manifest.dtb"]="={FVP_SPMC_MANIFEST_DTB}"
408 ["[= ]busybox.bin"]="={BUSYBOX}"
409 ["[= ]dtb.bin"]="={DTB}"
410 ["[= ]el3_payload.bin"]="={EL3_PAYLOAD}"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000411 ["[= ].*ETMv4ExamplePlugin.so"]="={ETM_TRACE}"
Chris Kay5d550d82022-10-12 17:20:31 +0100412 ["[= ]fip_gpt.bin"]="={FIP_GPT}"
413 ["[= ]fwu_fip.bin"]="={FWU_FIP}"
414 ["[= ]fip.bin"]="={FIP}"
415 ["[= ].*GenericTrace.so"]="={GENERIC_TRACE}"
416 ["[= ].*/hafnium.bin"]="={HAFNIUM}"
417 ["[= ]kernel.bin"]="={IMAGE}"
418 ["[= ]ivy.pkg"]="={IVY}"
419 ["[= ]manifest.dtb"]="={MANIFEST_DTB}"
Chris Kayfbdd0142022-11-08 12:24:30 +0000420 ["[= ]mcp_fw.bin"]="={MCP_FW}"
Manish V Badarkhe18c59782022-11-09 10:14:48 +0000421 ["[= ]mcp_ram.bin"]="={MCP_RAM}"
Chris Kayef9cc802022-11-08 12:11:58 +0000422 ["[= ]mcp_rom.bin"]="={MCP_ROM}"
423 ["[= ]mcp-rom.bin"]="={MCP_ROM_HYPHEN}"
Chris Kay5d550d82022-10-12 17:20:31 +0100424 ["[= ]ns_bl1u.bin"]="={NS_BL1U}"
425 ["[= ]ns_bl2u.bin"]="={NS_BL2U}"
426 ["[= ]initrd.bin"]="={RAMDISK}"
427 ["[= ]initrd.img"]="={RAMDISK}"
428 ["[= ]romlib.bin"]="={ROMLIB}"
429 ["[= ]rootfs.bin"]="={ROOTFS}"
laurenw-arm60de2742023-03-08 10:50:15 -0600430 ["[= ]host_flash_fip.bin"]="={HOST_FLASH_FIP}"
Divin Raj5eb69482024-10-02 11:36:04 +0100431 ["[= ]rse_flash.bin"]="={RSE_FLASH}"
David Vinczed8ed5622024-02-23 17:00:12 +0100432 ["[= ]rse_rom.bin"]="={RSE_ROM}"
433 ["[= ]rse_encrypted_cm_provisioning_bundle_0.bin"]="={RSE_ENCRYPTED_CM_PROVISIONING_BUNDLE_0}"
434 ["[= ]rse_encrypted_dm_provisioning_bundle.bin"]="={RSE_ENCRYPTED_DM_PROVISIONING_BUNDLE}"
Chris Kay5d550d82022-10-12 17:20:31 +0100435 ["[= ].*/secure_hafnium.bin"]="={SECURE_HAFNIUM}"
Chris Kayfbdd0142022-11-08 12:24:30 +0000436 ["[= ]scp_fw.bin"]="={SCP_FW}"
Chris Kay5d550d82022-10-12 17:20:31 +0100437 ["[= ]scp_ram.bin"]="={SCP_RAM}"
438 ["[= ]scp-ram.bin"]="={SCP_RAM_HYPHEN}"
439 ["[= ]scp_rom.bin"]="={SCP_ROM}"
440 ["[= ]scp-rom.bin"]="={SCP_ROM_HYPHEN}"
441 ["[= ]spm.bin"]="={SPM}"
Manish V Badarkhe9589d402024-01-29 16:46:41 +0000442 ["[= ]tc_fitimage.bin"]="={TC_FITIMAGE}"
Chris Kay5d550d82022-10-12 17:20:31 +0100443 ["[= ]tftf.bin"]="={TFTF}"
Harrison Mutai3ad377a2024-05-20 15:28:52 +0000444 ["[= ]tl.bin"]="={TL}"
Chris Kay5d550d82022-10-12 17:20:31 +0100445 ["[= ].*/tmp.bin"]="={TMP}"
446 ["[= ]uboot.bin"]="={UBOOT}"
447 )
448
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100449 declare -a fvp_artefacts
450 filter_artefacts fvp_artefacts fvp_artefact_filters
Chris Kay4eb9ded2022-10-10 15:51:40 +0100451
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100452 lava_model_params="${lava_model_params}" \
453 gen_lava_model_params fvp_artefact_macros
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500454
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100455 yaml_template_file="$yaml_template_file" \
456 yaml_file="$yaml_file" \
457 yaml_job_file="$yaml_job_file" \
458 gen_lava_job_def fvp_artefacts fvp_artefact_urls
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500459}
460
461docker_registry_append() {
462 # if docker_registry is empty, just use local docker registry
463 [ -z "$docker_registry" ] && return
464
465 local last=-1
466 local last_char="${docker_registry:last}"
467
468 if [ "$last_char" != '/' ]; then
469 docker_registry="${docker_registry}/";
470 fi
471 echo "$docker_registry"
472}
473
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000474# generate GPT image and archive it
475gen_gpt_bin() {
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000476 fip_bin="$1"
477 gpt_image="fip_gpt.bin"
478 # the FIP partition type is not standardized, so generate one
479 fip_type_uuid=`uuidgen --sha1 --namespace @dns --name "fip_type_uuid"`
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000480 # metadata partition type UUID, specified by the document:
481 # Platform Security Firmware Update for the A-profile Arm Architecture
482 # version: 1.0BET0
483 metadata_type_uuid="8a7a84a0-8387-40f6-ab41-a8b9a5a60d23"
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000484 location_uuid=`uuidgen`
485 FIP_A_uuid=`uuidgen`
486 FIP_B_uuid=`uuidgen`
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000487
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000488 fip_max_size=$2
Manish V Badarkhee79bc952024-01-25 14:34:37 +0000489 partition_alignment=${3:-1}
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000490 fip_bin_size=$(stat -c %s $fip_bin)
491 if [ $fip_max_size -lt $fip_bin_size ]; then
492 bberror "fip.bin ($fip_bin_size bytes) is larger than the GPT partition ($fip_max_size bytes)"
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000493 fi
494
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000495 # maximum metadata size 512B.
496 # This is the current size of the metadata rounded up to an integer number of sectors.
497 metadata_max_size=512
498 metadata_file="metadata.bin"
499
500 # generate_fwu_metadata.py --metadata_file <file> \
501 # --image_data "[(image_type_uuid, location_uuid, [image_uuid1, image_uuid2,...])]"
502 python3 $ci_root/generate_fwu_metadata.py --metadata_file $metadata_file \
503 --image_data "[('$fip_type_uuid', '$location_uuid', ['$FIP_A_uuid', '$FIP_B_uuid'])]"
504
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000505 # create GPT image. The GPT contains 1 FIP partition: FIP_A.
506 # the GPT layout is the following:
507 #
508 # +----------------------+
509 # LBA0 | Protective MBR |
510 # ------------------------
511 # LBA1 | Primary GPT Header |
512 # ------------------------
513 # LBA34| FIP_A |
514 # ------------------------
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000515 # | FIP_B |
516 # ------------------------
517 # | FWU-Metadata |
518 # ------------------------
519 # | Bkup-FWU-Metadata |
520 # ------------------------
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000521 # LBA-1| Secondary GPT Header |
522 # +----------------------+
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000523
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000524 sector_size=512 # in bytes
525 gpt_header_size=33 # in sectors
526 num_sectors_fip=`expr $fip_max_size / $sector_size`
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000527 num_sectors_metadata=`expr $metadata_max_size / $sector_size`
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000528 start_sector_1=`expr 1 + $gpt_header_size` # size of MBR is 1 sector
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000529 start_sector_2=`expr $start_sector_1 + $num_sectors_fip`
530 start_sector_3=`expr $start_sector_2 + $num_sectors_fip`
531 start_sector_4=`expr $start_sector_3 + $num_sectors_metadata`
532 num_sectors_gpt=`expr $start_sector_4 + $num_sectors_metadata + $gpt_header_size`
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000533 gpt_size=`expr $num_sectors_gpt \* $sector_size`
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000534
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000535 # create raw image
536 dd if=/dev/zero of=$gpt_image bs=$gpt_size count=1
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000537
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000538 # create the GPT layout
539 sgdisk $gpt_image \
Manish V Badarkhee79bc952024-01-25 14:34:37 +0000540 --set-alignment $partition_alignment \
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000541 --disk-guid $location_uuid \
542 \
543 --new 1:$start_sector_1:+$num_sectors_fip \
544 --change-name 1:FIP_A \
545 --typecode 1:$fip_type_uuid \
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000546 --partition-guid 1:$FIP_A_uuid \
547 \
548 --new 2:$start_sector_2:+$num_sectors_fip \
549 --change-name 2:FIP_B \
550 --typecode 2:$fip_type_uuid \
551 --partition-guid 2:$FIP_B_uuid \
552 \
553 --new 3:$start_sector_3:+$num_sectors_metadata \
554 --change-name 3:FWU-Metadata \
555 --typecode 3:$metadata_type_uuid \
556 \
557 --new 4:$start_sector_4:+$num_sectors_metadata \
558 --change-name 4:Bkup-FWU-Metadata \
559 --typecode 4:$metadata_type_uuid
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000560
561 # populate the GPT partitions
562 dd if=$fip_bin of=$gpt_image bs=$sector_size seek=$(gdisk -l $gpt_image | grep " FIP_A$" | awk '{print $2}') count=$num_sectors_fip conv=notrunc
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000563 dd if=$fip_bin of=$gpt_image bs=$sector_size seek=$(gdisk -l $gpt_image | grep " FIP_B$" | awk '{print $2}') count=$num_sectors_fip conv=notrunc
564 dd if=$metadata_file of=$gpt_image bs=$sector_size seek=$(gdisk -l $gpt_image | grep " FWU-Metadata$" | awk '{print $2}') count=$num_sectors_metadata conv=notrunc
565 dd if=$metadata_file of=$gpt_image bs=$sector_size seek=$(gdisk -l $gpt_image | grep " Bkup-FWU-Metadata$" | awk '{print $2}') count=$num_sectors_metadata conv=notrunc
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000566
567 echo "Built $gpt_image"
568
569 archive_file "$gpt_image"
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000570}
571
Govindraj Raja67501732023-09-22 16:27:06 -0500572#corrupt GPT image header and archive it
573corrupt_gpt_bin() {
574 bin="${1:?}"
laurenw-arm2c6665f2024-02-09 16:08:34 -0600575 corrupt_data=$2
Govindraj Raja67501732023-09-22 16:27:06 -0500576
laurenw-arm2c6665f2024-02-09 16:08:34 -0600577 # Check if parameters are provided
578 if [ -z "$bin" ] || [ -z "$corrupt_data" ]; then
579 echo "Usage: corrupt_gpt_bin <bin> <corrupt_data>"
580 return 1
581 fi
582
583 case "$corrupt_data" in
584 "header")
585 # Primary GPT header is present in LBA-1 second block after MBR
586 # empty the primary GPT header forcing to use backup GPT header
587 # and backup GPT entries.
588 seek=1
589 count=1
590 ;;
591 "partition-entries")
592 # GPT partition entry array is present in LBA-2 through LBA-34
593 # blocks empty the GPT partition entry array forcing to use backup
594 # GPT header and backup GPT entries.
595 seek=2
596 count=32
597 ;;
Manish V Badarkheb473c402024-02-14 16:50:08 +0000598 "fwu-metadata")
599 # Get the LBA number for the FWU metadata. Size of which is always
600 # 1 sector (512 bytes).
601 seek=$(gdisk -l $bin | grep " FWU-Metadata$" | awk '{print $2}')
602 count=1
603 ;;
laurenw-arm2c6665f2024-02-09 16:08:34 -0600604 *)
605 echo "Invalid $corrupt_data. Use 'header', 'partition-entries'"
606 return 1
607 ;;
608 esac
609
610 # Use parameters in the dd command
611 dd if=/dev/zero of=$bin bs=512 seek=$seek count=$count conv=notrunc
Govindraj Raja67501732023-09-22 16:27:06 -0500612}
613
Fathi Boudra422bf772019-12-02 11:10:16 +0200614set +u