blob: e2733193cb7d338ec6a38ac56b0b820f2d040bf8 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Manish V Badarkhe048c9682024-01-22 10:11:49 +00003# Copyright (c) 2020-2024, 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
J-Alves12d796c2023-02-27 10:30:58 +000028export spm_secure_out_dir="${spm_secure_out_dir:-secure_aem_v8a_fvp_vhe_clang}"
29export spm_non_secure_out_dir="${spm_non_secure_out_dir:-aem_v8a_fvp_vhe_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
Harrison Mutai6f4fd6c2023-03-27 13:22:41 +010036uefi_downloads="${uefi_downloads:-http://files.oss.arm.com/downloads/uefi}"
37uefi_ci_bin_url="${uefi_ci_bin_url:-$uefi_downloads/Artifacts/Linux/github/fvp/static/DEBUG_GCC5/FVP_AARCH64_EFI.fd}"
38
Fathi Boudra422bf772019-12-02 11:10:16 +020039uboot32_fip_url="$linaro_release/fvp32-latest-busybox-uboot/fip.bin"
Harrison Mutai6f4fd6c2023-03-27 13:22:41 +010040uboot_url="$linaro_release/fvp-latest-busybox-uboot/bl33-uboot.bin"
Fathi Boudra422bf772019-12-02 11:10:16 +020041
Alexei Fedorove405cc32020-09-30 18:13:55 +010042rootfs_url="$linaro_release/lt-vexpress64-openembedded_minimal-armv8-gcc-5.2_20170127-761.img.gz"
Fathi Boudra422bf772019-12-02 11:10:16 +020043
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050044# Default FVP model variables
Leonardo Sandovale1460662021-05-27 16:05:38 -050045default_model_dtb="dtb.bin"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -050046
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060047# FVP containers and model paths
Govindraj Raja02e14fa2024-06-18 13:34:17 -050048fvp_arm_std_library_11_24="fvp:fvp_arm_std_library_${model_version_11_24}_${model_build_11_24};/opt/model/FVP_ARM_Std_Library/FVP_Base"
49
Maksims Svecovs284a50d2021-11-02 11:09:47 +000050fvp_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 -050051fvp_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 -060052fvp_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 -050053
Manish V Badarkhef65f9a32022-11-04 10:07:19 +000054# CSS model list
55fvp_morello="fvp:fvp_morello_0.11_33;/opt/model/FVP_Morello/models/Linux64_GCC-6.4"
Chris Kay363b9342023-07-26 17:58:15 +010056fvp_rd_v1="fvp:fvp_rd_v1_${model_version}_${model_build};/opt/model/FVP_RD_V1/models/${model_flavour}"
Manish V Badarkhee1720172024-01-29 15:29:39 +000057fvp_tc2="fvp:fvp_tc2_11.23_17;/opt/model/FVP_TC2/models/${model_flavour}"
Chris Kay2892b522024-04-12 10:38:48 +000058fvp_tc3="fvp:fvp_tc3_0.0_8192;/opt/model/FVP_TC3/models/${model_flavour}"
Manish V Badarkhef65f9a32022-11-04 10:07:19 +000059
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060060# FVP associate array, run_config are keys and fvp container parameters are the values
61# Container parameters syntax: <model name>;<model dir>;<model bin>
62# FIXMEs: fix those ;;; values with real values
63
64declare -A fvp_models
65fvp_models=(
laurenw-armafdc3bc2022-09-14 15:31:42 -050066[base-aemv8a-revb]="${fvp_arm_std_library};FVP_Base_AEMvA-AEMvA"
67[base-aemv8a-latest-revb]="${fvp_arm_std_library};FVP_Base_AEMvA-AEMvA"
Manish Pandeya60d8072024-03-11 09:58:53 +000068[base-aemva]="${fvp_base_revc_2xaemva};FVP_Base_RevC-2xAEMvA"
laurenw-armf414aba2021-04-26 15:58:56 -050069[base-aemv8a]="${fvp_base_revc_2xaemva};FVP_Base_RevC-2xAEMvA"
Olivier Deprezf648faf2024-04-18 12:25:42 +020070[cortex-a32x4]="${fvp_arm_std_library};FVP_Base_Cortex-A32x4"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -060071[cortex-a35x4]="${fvp_arm_std_library};FVP_Base_Cortex-A35x4"
72[cortex-a53x4]="${fvp_arm_std_library};FVP_Base_Cortex-A53x4"
laurenw-armafdc3bc2022-09-14 15:31:42 -050073[cortex-a55x4]="${fvp_arm_std_library};FVP_Base_Cortex-A55"
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"
Govindraj Raja02e14fa2024-06-18 13:34:17 -050078[cortex-a65aex8]="${fvp_arm_std_library_11_24};FVP_Base_Cortex-A65AE"
79[cortex-a65x4]="${fvp_arm_std_library_11_24};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"
Juan Pablo Conded52a4752023-03-21 14:52:10 -050090[cortex-a78aex4]="${fvp_arm_std_library};FVP_Base_Cortex-A78AE"
laurenw-armafdc3bc2022-09-14 15:31:42 -050091[cortex-a78cx4]="${fvp_arm_std_library};FVP_Base_Cortex-A78C"
Govindraj Raja8962c452024-06-04 14:50:28 -050092[cortex-x2]="${fvp_arm_std_library};FVP_Base_Cortex-X2"
93[cortex-a710]="${fvp_arm_std_library};FVP_Base_Cortex-A710"
Govindraj Raja820d06a2024-06-26 17:34:56 -050094[neoverse_e1]="${fvp_arm_std_library_11_24};FVP_Base_Neoverse-E1"
laurenw-armafdc3bc2022-09-14 15:31:42 -050095[neoverse_n1]="${fvp_arm_std_library};FVP_Base_Neoverse-N1"
Govindraj Raja8962c452024-06-04 14:50:28 -050096[neoverse_n2]="${fvp_arm_std_library};FVP_Base_Neoverse-N2"
laurenw-armafdc3bc2022-09-14 15:31:42 -050097[neoverse-v1x4]="${fvp_arm_std_library};FVP_Base_Neoverse-V1"
Manish V Badarkhef65f9a32022-11-04 10:07:19 +000098[morello]="${fvp_morello};FVP_Morello"
Manish V Badarkhef65f9a32022-11-04 10:07:19 +000099[css-rdv1]="${fvp_rd_v1};FVP_RD_V1"
Manish V Badarkhef65f9a32022-11-04 10:07:19 +0000100[tc2]="${fvp_tc2};FVP_TC2"
Chris Kay2892b522024-04-12 10:38:48 +0000101[tc3]="${fvp_tc3};FVP_TC3"
Divin Rajb0071052023-07-04 14:35:07 +0100102[baser-aemv8r]="${fvp_base_aemv8r};FVP_BaseR_AEMv8R"
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600103)
104
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500105
Fathi Boudra422bf772019-12-02 11:10:16 +0200106# FVP Kernel URLs
Harrison Mutai6f4fd6c2023-03-27 13:22:41 +0100107declare -A kernel_list
108kernel_list=(
Fathi Boudra422bf772019-12-02 11:10:16 +0200109[fvp-aarch32-zimage]="$linaro_release/fvp32-latest-busybox-uboot/Image"
110[fvp-busybox-uboot]="$linaro_release/fvp-latest-busybox-uboot/Image"
111[fvp-oe-uboot32]="$linaro_release/fvp32-latest-oe-uboot/Image"
112[fvp-oe-uboot]="$linaro_release/fvp-latest-oe-uboot/Image"
113[fvp-quad-busybox-uboot]="$tfa_downloads/quad_cluster/Image"
114)
115
Fathi Boudra422bf772019-12-02 11:10:16 +0200116# FVP initrd URLs
Harrison Mutai6f4fd6c2023-03-27 13:22:41 +0100117declare -A initrd_list
118initrd_list=(
Fathi Boudra422bf772019-12-02 11:10:16 +0200119[aarch32-ramdisk]="$linaro_release/fvp32-latest-busybox-uboot/ramdisk.img"
Fathi Boudra422bf772019-12-02 11:10:16 +0200120[dummy-ramdisk]="$linaro_release/fvp-latest-oe-uboot/ramdisk.img"
121[dummy-ramdisk32]="$linaro_release/fvp32-latest-oe-uboot/ramdisk.img"
122[default]="$linaro_release/fvp-latest-busybox-uboot/ramdisk.img"
123)
124
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100125# For Measured Boot tests using a TA based on OPTEE, it is necessary to use a
126# specific build rather than the default one generated by Jenkins.
127get_ftpm_optee_bin() {
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100128 url="$tfa_downloads/ftpm/optee/tee-header_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100129 saveas="bl32.bin" fetch_file
130 archive_file "bl32.bin"
131
Javier Almansa Sobrinode647722020-10-08 19:17:44 +0100132 url="$tfa_downloads/ftpm/optee/tee-pager_v2.bin" \
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100133 saveas="bl32_extra1.bin" fetch_file
134 archive_file "bl32_extra1.bin"
135
Leonardo Sandovalda5f78d2021-03-18 11:09:30 -0600136 # tee-pageable_v2.bin is just a empty file, named as bl32_extra2.bin,
137 # so just create the file
138 touch "bl32_extra2.bin"
Javier Almansa Sobrino98de5032020-09-17 12:47:05 +0100139 archive_file "bl32_extra2.bin"
140}
141
Fathi Boudra422bf772019-12-02 11:10:16 +0200142get_dtb() {
143 local dtb_type="${dtb_type:?}"
144 local dtb_url
145 local dtb_saveas="$workspace/dtb.bin"
Zelalem219df412020-05-17 19:21:20 -0500146 local cc="$(get_tf_opt CROSS_COMPILE)"
147 local pp_flags="-P -nostdinc -undef -x assembler-with-cpp"
Fathi Boudra422bf772019-12-02 11:10:16 +0200148
149 case "$dtb_type" in
150 "fvp-base-quad-cluster-gicv3-psci")
151 # Get the quad-cluster FDT from pdsw area
152 dtb_url="$tfa_downloads/quad_cluster/fvp-base-quad-cluster-gicv3-psci.dtb"
153 url="$dtb_url" saveas="$dtb_saveas" fetch_file
154 ;;
Fathi Boudra422bf772019-12-02 11:10:16 +0200155 *)
Zelalem219df412020-05-17 19:21:20 -0500156 # Preprocess DTS file
157 ${cc}gcc -E ${pp_flags} -I"$tf_root/fdts" -I"$tf_root/include" \
158 -o "$workspace/${dtb_type}.pre.dts" \
159 "$tf_root/fdts/${dtb_type}.dts"
160 # Generate DTB file from DTS
Fathi Boudra422bf772019-12-02 11:10:16 +0200161 dtc -I dts -O dtb \
Zelalem219df412020-05-17 19:21:20 -0500162 "$workspace/${dtb_type}.pre.dts" -o "$dtb_saveas"
Fathi Boudra422bf772019-12-02 11:10:16 +0200163 esac
164
165 archive_file "$dtb_saveas"
166}
167
168get_rootfs() {
169 local tmpdir
170 local fs_base="$(echo $(basename $rootfs_url) | sed 's/\.gz$//')"
171 local cached="$project_filer/ci-files/$fs_base"
172
173 if upon "$jenkins_run" && [ -f "$cached" ]; then
174 # Job workspace is limited in size, and the root file system is
175 # quite large. This means, parallel runs of root file system
176 # tests could fail. So, for Jenkins runs, copy and use the root
177 # file system image from the $CI_SCRATCH location
178 local private="$CI_SCRATCH/$JOB_NAME-$BUILD_NUMBER"
179 mkdir -p "$private"
180 rm -f "$private/rootfs.bin"
181 url="$cached" saveas="$private/rootfs.bin" fetch_file
182 ln -s "$private/rootfs.bin" "$archive/rootfs.bin"
183 return
184 fi
185
186 tmpdir="$(mktempdir)"
187 pushd "$tmpdir"
188 url="$rootfs_url" saveas="rootfs.bin" fetch_file
189
190 # Possibly, the filesystem image we just downloaded is compressed.
191 # Decompress it if required.
192 if file "rootfs.bin" | grep -iq 'gzip compressed data'; then
193 echo "Decompressing root file system image rootfs.bin ..."
194 gunzip --stdout "rootfs.bin" > uncompressed_fs.bin
195 mv uncompressed_fs.bin "rootfs.bin"
196 fi
197
198 archive_file "rootfs.bin"
199 popd
200}
201
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200202fvp_romlib_jmptbl_backup="$(mktempdir)/jmptbl.i"
203
Fathi Boudra422bf772019-12-02 11:10:16 +0200204fvp_romlib_runtime() {
205 local tmpdir="$(mktempdir)"
206
207 # Save BL1 and romlib binaries from original build
208 mv "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin" "$tmpdir/romlib.bin"
209 mv "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin" "$tmpdir/bl1.bin"
210
211 # Patch index file
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200212 cp "${tf_root:?}/plat/arm/board/fvp/jmptbl.i" "$fvp_romlib_jmptbl_backup"
213 sed -i '/fdt/ s/.$/&\ patch/' ${tf_root:?}/plat/arm/board/fvp/jmptbl.i
Fathi Boudra422bf772019-12-02 11:10:16 +0200214
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200215 # Rebuild with patched file
216 echo "Building patched romlib:"
217 build_tf
Fathi Boudra422bf772019-12-02 11:10:16 +0200218
Fathi Boudra422bf772019-12-02 11:10:16 +0200219 # Retrieve original BL1 and romlib binaries
220 mv "$tmpdir/romlib.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/romlib/romlib.bin"
221 mv "$tmpdir/bl1.bin" "${tf_build_root:?}/${plat:?}/${mode:?}/bl1.bin"
222}
223
Sandrine Bailleux14a692d2022-06-29 15:39:42 +0200224fvp_romlib_cleanup() {
225 # Restore original index
226 mv "$fvp_romlib_jmptbl_backup" "${tf_root:?}/plat/arm/board/fvp/jmptbl.i"
227}
228
229
Chris Kayc9523b12022-10-10 18:32:20 +0100230# Generates the final YAML-based LAVA job definition from a template file.
231#
232# The job definition template is expanded with visibility of all variables that
233# are available from within the function, including those with local scope.
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500234gen_fvp_yaml() {
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600235 local model="${model:?}"
236
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500237 local yaml_template_file="$workspace/fvp_template.yaml"
238 local yaml_file="$workspace/fvp.yaml"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500239 local yaml_job_file="$workspace/job.yaml"
240 local lava_model_params="$workspace/lava_model_params"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500241
Leonardo Sandovalfda4f292020-10-06 15:59:26 -0500242 # this function expects a template, quit if it is not present
243 if [ ! -f "$yaml_template_file" ]; then
Paul Sokolovskya3c5a4c2023-01-24 18:33:58 +0700244 echo "warning: gen_fvp_yaml: template $yaml_template_file not available, skipping generating LAVA job"
Leonardo Sandovalfda4f292020-10-06 15:59:26 -0500245 return
246 fi
247
Leonardo Sandoval00ced1f2020-12-07 12:55:08 -0600248 local model_params="${fvp_models[$model]}"
249 local model_name="$(echo "${model_params}" | awk -F ';' '{print $1}')"
250 local model_dir="$(echo "${model_params}" | awk -F ';' '{print $2}')"
251 local model_bin="$(echo "${model_params}" | awk -F ';' '{print $3}')"
252
253 # model params are required for correct yaml creation, quit if empty
254 if [ -z "${model_name}" ]; then
255 echo "FVP model param 'model_name' variable empty, yaml not produced"
256 return
257 elif [ -z "${model_dir}" ]; then
258 echo "FVP model param 'model_dir' variable empty, yaml not produced"
259 return
260 elif [ -z "${model_bin}" ]; then
261 echo "FVP model param 'model_bin' variable empty, yaml not produced"
262 return
263 fi
264
265 echo "FVP model params: model_name=$model_name model_dir=$model_dir model_bin=$model_bin"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500266
267 # optional parameters, defaults to globals
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500268 local model_dtb="${model_dtb:-$default_model_dtb}"
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500269
Chris Kayc9523b12022-10-10 18:32:20 +0100270 if [ -n "${GERRIT_CHANGE_NUMBER}" ]; then
271 local gerrit_url="https://review.trustedfirmware.org/c/${GERRIT_CHANGE_NUMBER}/${GERRIT_PATCHSET_NUMBER}"
272 elif [ -n "${GERRIT_REFSPEC}" ]; then
273 local gerrit_url=$(echo ${GERRIT_REFSPEC} |
274 awk -F/ '{print "https://review.trustedfirmware.org/c/" $4 "/" $5}')
275 fi
276
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500277 docker_registry="${docker_registry:-}"
278 docker_registry="$(docker_registry_append)"
Leonardo Sandoval5d90dff2020-10-12 17:59:39 -0500279 docker_name="${docker_registry}$model_name"
Leonardo Sandoval850a4862021-02-16 13:56:18 -0600280 prompt1='/ #'
281 prompt2='root@genericarmv8:~#'
282 version_string="\"Fast Models"' [^\\n]+'"\""
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500283
Leonardo Sandoval5d87b702021-05-10 11:53:13 -0500284 test_config="${TEST_CONFIG}"
285
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100286 declare -A fvp_artefact_filters=(
Chris Kay4eb9ded2022-10-10 15:51:40 +0100287 [backup_fip]="backup_fip.bin"
288 [bl1]="bl1.bin"
289 [bl2]="bl2.bin"
290 [bl31]="bl31.bin"
291 [bl32]="bl32.bin"
292 [busybox]="busybox.bin"
293 [cactus_primary]="cactus-primary.pkg"
294 [cactus_secondary]="cactus-secondary.pkg"
295 [cactus_tertiary]="cactus-tertiary.pkg"
296 [coverage_trace_plugin]="coverage_trace.so"
297 [dtb]="dtb.bin"
298 [el3_payload]="el3_payload.bin"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000299 [ete_trace]="libete-plugin.so"
300 [etm_trace]="ETMv4ExamplePlugin.so"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100301 [fip_gpt]="fip_gpt.bin"
302 [fip]="fip.bin"
303 [fvp_spmc_manifest_dtb]="=fvp_spmc_manifest.dtb"
304 [fwu_fip]="fwu_fip.bin"
305 [generic_trace]="GenericTrace.so"
306 [hafnium]="hafnium.bin"
307 [image]="kernel.bin"
308 [ivy]="ivy.pkg"
309 [manifest_dtb]="=manifest.dtb"
Chris Kayfbdd0142022-11-08 12:24:30 +0000310 [mcp_fw]="mcp_fw.bin"
Manish V Badarkhe18c59782022-11-09 10:14:48 +0000311 [mcp_ram]="mcp_ram.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100312 [mcp_rom_hyphen]="mcp-rom.bin"
313 [mcp_rom]="mcp_rom.bin"
314 [ns_bl1u]="ns_bl1u.bin"
315 [ns_bl2u]="ns_bl2u.bin"
316 [ramdisk]="initrd.bin|initrd.img"
317 [romlib]="romlib.bin"
318 [rootfs]="rootfs.bin"
laurenw-arm60de2742023-03-08 10:50:15 -0600319 [host_flash_fip]="host_flash_fip.bin"
David Vinczed8ed5622024-02-23 17:00:12 +0100320 [rse_rom]="rse_rom.bin"
321 [rse_encrypted_cm_provisioning_bundle_0]="rse_encrypted_cm_provisioning_bundle_0.bin"
322 [rse_encrypted_dm_provisioning_bundle]="rse_encrypted_dm_provisioning_bundle.bin"
Chris Kayfbdd0142022-11-08 12:24:30 +0000323 [scp_fw]="scp_fw.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100324 [scp_ram_hyphen]="scp-ram.bin"
325 [scp_ram]="scp_ram.bin"
326 [scp_rom_hyphen]="scp-rom.bin"
327 [scp_rom]="scp_rom.bin"
328 [secure_hafnium]="secure_hafnium.bin"
329 [spm]="spm.bin"
Manish V Badarkhe9589d402024-01-29 16:46:41 +0000330 [tc_fitimage]="tc_fitimage.bin"
Chris Kay4eb9ded2022-10-10 15:51:40 +0100331 [tftf]="tftf.bin"
332 [tmp]="tmp.bin"
333 [uboot]="uboot.bin"
334 )
335
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100336 declare -A fvp_artefact_urls=(
Harrison Mutaie5122542023-03-27 13:14:18 +0100337 [backup_fip]="$(gen_bin_url backup_fip.bin)"
338 [bl1]="$(gen_bin_url bl1.bin)"
339 [bl2]="$(gen_bin_url bl2.bin)"
340 [bl31]="$(gen_bin_url bl31.bin)"
341 [bl32]="$(gen_bin_url bl32.bin)"
342 [busybox]="$(gen_bin_url busybox.bin.gz)"
343 [cactus_primary]="$(gen_bin_url cactus-primary.pkg)"
344 [cactus_secondary]="$(gen_bin_url cactus-secondary.pkg)"
345 [cactus_tertiary]="$(gen_bin_url cactus-tertiary.pkg)"
Chris Kayc14743a2022-10-13 11:33:26 +0100346 [coverage_trace_plugin]="${coverage_trace_plugin}"
Harrison Mutaie5122542023-03-27 13:14:18 +0100347 [dtb]="$(gen_bin_url ${model_dtb})"
348 [el3_payload]="$(gen_bin_url el3_payload.bin)"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000349 [ete_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/libete-plugin.so"
350 [etm_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/ETMv4ExamplePlugin.so"
Harrison Mutaie5122542023-03-27 13:14:18 +0100351 [fip]="$(gen_bin_url fip.bin)"
352 [fip_gpt]="$(gen_bin_url fip_gpt.bin)"
353 [fvp_spmc_manifest_dtb]="$(gen_bin_url fvp_spmc_manifest.dtb)"
354 [fwu_fip]="$(gen_bin_url fwu_fip.bin)"
Chris Kayc14743a2022-10-13 11:33:26 +0100355 [generic_trace]="${tfa_downloads}/FastModelsPortfolio_${model_version}/plugins/${model_flavour}/GenericTrace.so"
Harrison Mutaie5122542023-03-27 13:14:18 +0100356 [hafnium]="$(gen_bin_url hafnium.bin)"
357 [image]="$(gen_bin_url kernel.bin)"
358 [ivy]="$(gen_bin_url ivy.pkg)"
359 [manifest_dtb]="$(gen_bin_url manifest.dtb)"
360 [mcp_fw]="$(gen_bin_url mcp_fw.bin)"
361 [mcp_ram]="$(gen_bin_url mcp_ram.bin)"
362 [mcp_rom]="$(gen_bin_url mcp_rom.bin)"
363 [mcp_rom_hyphen]="$(gen_bin_url mcp-rom.bin)"
364 [ns_bl1u]="$(gen_bin_url ns_bl1u.bin)"
365 [ns_bl2u]="$(gen_bin_url ns_bl2u.bin)"
366 [ramdisk]="$(gen_bin_url initrd.bin)"
367 [romlib]="$(gen_bin_url romlib.bin)"
368 [rootfs]="$(gen_bin_url rootfs.bin.gz)"
369 [host_flash_fip]="$(gen_bin_url host_flash_fip.bin)"
David Vinczed8ed5622024-02-23 17:00:12 +0100370 [rse_rom]="$(gen_bin_url rse_rom.bin)"
371 [rse_encrypted_cm_provisioning_bundle_0]="$(gen_bin_url rse_encrypted_cm_provisioning_bundle_0.bin)"
372 [rse_encrypted_dm_provisioning_bundle]="$(gen_bin_url rse_encrypted_dm_provisioning_bundle.bin)"
Harrison Mutaie5122542023-03-27 13:14:18 +0100373 [secure_hafnium]="$(gen_bin_url secure_hafnium.bin)"
374 [scp_fw]="$(gen_bin_url scp_fw.bin)"
375 [scp_ram]="$(gen_bin_url scp_ram.bin)"
376 [scp_ram_hyphen]="$(gen_bin_url scp-ram.bin)"
377 [scp_rom]="$(gen_bin_url scp_rom.bin)"
378 [scp_rom_hyphen]="$(gen_bin_url scp-rom.bin)"
379 [spm]="$(gen_bin_url spm.bin)"
Manish V Badarkhe9589d402024-01-29 16:46:41 +0000380 [tc_fitimage]="$(gen_bin_url tc_fitimage.bin)"
Harrison Mutaie5122542023-03-27 13:14:18 +0100381 [tftf]="$(gen_bin_url tftf.bin)"
382 [tmp]="$(gen_bin_url tmp.bin)"
383 [uboot]="$(gen_bin_url uboot.bin)"
Chris Kayc14743a2022-10-13 11:33:26 +0100384 )
385
Chris Kay5d550d82022-10-12 17:20:31 +0100386 # In LAVA we don't provide the paths to the artefacts directly, but instead
387 # use macros of the form `{XYZ}`. This is a list of regular expression
388 # replacements to run on the model parameters file before we add them to the
389 # LAVA job definition.
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100390 declare -A fvp_artefact_macros=(
Chris Kay5d550d82022-10-12 17:20:31 +0100391 ["[= ]backup_fip.bin"]="={BACKUP_FIP}"
392 ["[= ]bl1.bin"]="={BL1}"
393 ["[= ]bl2.bin"]="={BL2}"
394 ["[= ]bl31.bin"]="={BL31}"
395 ["[= ]bl32.bin"]="={BL32}"
396 ["[= ]cactus-primary.pkg"]="={CACTUS_PRIMARY}"
397 ["[= ]cactus-secondary.pkg"]="={CACTUS_SECONDARY}"
398 ["[= ]cactus-tertiary.pkg"]="={CACTUS_TERTIARY}"
399 ["[= ].*coverage_trace.so"]="={COVERAGE_TRACE_PLUGIN}"
400 ["[= ]fvp_spmc_manifest.dtb"]="={FVP_SPMC_MANIFEST_DTB}"
401 ["[= ]busybox.bin"]="={BUSYBOX}"
402 ["[= ]dtb.bin"]="={DTB}"
403 ["[= ]el3_payload.bin"]="={EL3_PAYLOAD}"
Manish V Badarkhedbb9cb12022-11-16 12:30:41 +0000404 ["[= ].*libete-plugin.so"]="={ETE_TRACE}"
405 ["[= ].*ETMv4ExamplePlugin.so"]="={ETM_TRACE}"
Chris Kay5d550d82022-10-12 17:20:31 +0100406 ["[= ]fip_gpt.bin"]="={FIP_GPT}"
407 ["[= ]fwu_fip.bin"]="={FWU_FIP}"
408 ["[= ]fip.bin"]="={FIP}"
409 ["[= ].*GenericTrace.so"]="={GENERIC_TRACE}"
410 ["[= ].*/hafnium.bin"]="={HAFNIUM}"
411 ["[= ]kernel.bin"]="={IMAGE}"
412 ["[= ]ivy.pkg"]="={IVY}"
413 ["[= ]manifest.dtb"]="={MANIFEST_DTB}"
Chris Kayfbdd0142022-11-08 12:24:30 +0000414 ["[= ]mcp_fw.bin"]="={MCP_FW}"
Manish V Badarkhe18c59782022-11-09 10:14:48 +0000415 ["[= ]mcp_ram.bin"]="={MCP_RAM}"
Chris Kayef9cc802022-11-08 12:11:58 +0000416 ["[= ]mcp_rom.bin"]="={MCP_ROM}"
417 ["[= ]mcp-rom.bin"]="={MCP_ROM_HYPHEN}"
Chris Kay5d550d82022-10-12 17:20:31 +0100418 ["[= ]ns_bl1u.bin"]="={NS_BL1U}"
419 ["[= ]ns_bl2u.bin"]="={NS_BL2U}"
420 ["[= ]initrd.bin"]="={RAMDISK}"
421 ["[= ]initrd.img"]="={RAMDISK}"
422 ["[= ]romlib.bin"]="={ROMLIB}"
423 ["[= ]rootfs.bin"]="={ROOTFS}"
laurenw-arm60de2742023-03-08 10:50:15 -0600424 ["[= ]host_flash_fip.bin"]="={HOST_FLASH_FIP}"
David Vinczed8ed5622024-02-23 17:00:12 +0100425 ["[= ]rse_rom.bin"]="={RSE_ROM}"
426 ["[= ]rse_encrypted_cm_provisioning_bundle_0.bin"]="={RSE_ENCRYPTED_CM_PROVISIONING_BUNDLE_0}"
427 ["[= ]rse_encrypted_dm_provisioning_bundle.bin"]="={RSE_ENCRYPTED_DM_PROVISIONING_BUNDLE}"
Chris Kay5d550d82022-10-12 17:20:31 +0100428 ["[= ].*/secure_hafnium.bin"]="={SECURE_HAFNIUM}"
Chris Kayfbdd0142022-11-08 12:24:30 +0000429 ["[= ]scp_fw.bin"]="={SCP_FW}"
Chris Kay5d550d82022-10-12 17:20:31 +0100430 ["[= ]scp_ram.bin"]="={SCP_RAM}"
431 ["[= ]scp-ram.bin"]="={SCP_RAM_HYPHEN}"
432 ["[= ]scp_rom.bin"]="={SCP_ROM}"
433 ["[= ]scp-rom.bin"]="={SCP_ROM_HYPHEN}"
434 ["[= ]spm.bin"]="={SPM}"
Manish V Badarkhe9589d402024-01-29 16:46:41 +0000435 ["[= ]tc_fitimage.bin"]="={TC_FITIMAGE}"
Chris Kay5d550d82022-10-12 17:20:31 +0100436 ["[= ]tftf.bin"]="={TFTF}"
437 ["[= ].*/tmp.bin"]="={TMP}"
438 ["[= ]uboot.bin"]="={UBOOT}"
439 )
440
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100441 declare -a fvp_artefacts
442 filter_artefacts fvp_artefacts fvp_artefact_filters
Chris Kay4eb9ded2022-10-10 15:51:40 +0100443
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100444 lava_model_params="${lava_model_params}" \
445 gen_lava_model_params fvp_artefact_macros
Leonardo Sandovalbe690bd2020-10-12 17:59:39 -0500446
Harrison Mutaia6d6e682023-03-27 13:20:33 +0100447 yaml_template_file="$yaml_template_file" \
448 yaml_file="$yaml_file" \
449 yaml_job_file="$yaml_job_file" \
450 gen_lava_job_def fvp_artefacts fvp_artefact_urls
Leonardo Sandovald76d1e22020-10-06 16:02:52 -0500451}
452
453docker_registry_append() {
454 # if docker_registry is empty, just use local docker registry
455 [ -z "$docker_registry" ] && return
456
457 local last=-1
458 local last_char="${docker_registry:last}"
459
460 if [ "$last_char" != '/' ]; then
461 docker_registry="${docker_registry}/";
462 fi
463 echo "$docker_registry"
464}
465
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000466# generate GPT image and archive it
467gen_gpt_bin() {
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000468 fip_bin="$1"
469 gpt_image="fip_gpt.bin"
470 # the FIP partition type is not standardized, so generate one
471 fip_type_uuid=`uuidgen --sha1 --namespace @dns --name "fip_type_uuid"`
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000472 # metadata partition type UUID, specified by the document:
473 # Platform Security Firmware Update for the A-profile Arm Architecture
474 # version: 1.0BET0
475 metadata_type_uuid="8a7a84a0-8387-40f6-ab41-a8b9a5a60d23"
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000476 location_uuid=`uuidgen`
477 FIP_A_uuid=`uuidgen`
478 FIP_B_uuid=`uuidgen`
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000479
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000480 fip_max_size=$2
Manish V Badarkhee79bc952024-01-25 14:34:37 +0000481 partition_alignment=${3:-1}
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000482 fip_bin_size=$(stat -c %s $fip_bin)
483 if [ $fip_max_size -lt $fip_bin_size ]; then
484 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 +0000485 fi
486
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000487 # maximum metadata size 512B.
488 # This is the current size of the metadata rounded up to an integer number of sectors.
489 metadata_max_size=512
490 metadata_file="metadata.bin"
491
492 # generate_fwu_metadata.py --metadata_file <file> \
493 # --image_data "[(image_type_uuid, location_uuid, [image_uuid1, image_uuid2,...])]"
494 python3 $ci_root/generate_fwu_metadata.py --metadata_file $metadata_file \
495 --image_data "[('$fip_type_uuid', '$location_uuid', ['$FIP_A_uuid', '$FIP_B_uuid'])]"
496
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000497 # create GPT image. The GPT contains 1 FIP partition: FIP_A.
498 # the GPT layout is the following:
499 #
500 # +----------------------+
501 # LBA0 | Protective MBR |
502 # ------------------------
503 # LBA1 | Primary GPT Header |
504 # ------------------------
505 # LBA34| FIP_A |
506 # ------------------------
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000507 # | FIP_B |
508 # ------------------------
509 # | FWU-Metadata |
510 # ------------------------
511 # | Bkup-FWU-Metadata |
512 # ------------------------
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000513 # LBA-1| Secondary GPT Header |
514 # +----------------------+
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000515
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000516 sector_size=512 # in bytes
517 gpt_header_size=33 # in sectors
518 num_sectors_fip=`expr $fip_max_size / $sector_size`
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000519 num_sectors_metadata=`expr $metadata_max_size / $sector_size`
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000520 start_sector_1=`expr 1 + $gpt_header_size` # size of MBR is 1 sector
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000521 start_sector_2=`expr $start_sector_1 + $num_sectors_fip`
522 start_sector_3=`expr $start_sector_2 + $num_sectors_fip`
523 start_sector_4=`expr $start_sector_3 + $num_sectors_metadata`
524 num_sectors_gpt=`expr $start_sector_4 + $num_sectors_metadata + $gpt_header_size`
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000525 gpt_size=`expr $num_sectors_gpt \* $sector_size`
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000526
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000527 # create raw image
528 dd if=/dev/zero of=$gpt_image bs=$gpt_size count=1
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000529
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000530 # create the GPT layout
531 sgdisk $gpt_image \
Manish V Badarkhee79bc952024-01-25 14:34:37 +0000532 --set-alignment $partition_alignment \
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000533 --disk-guid $location_uuid \
534 \
535 --new 1:$start_sector_1:+$num_sectors_fip \
536 --change-name 1:FIP_A \
537 --typecode 1:$fip_type_uuid \
Manish V Badarkhe02bcfb12024-01-25 14:14:31 +0000538 --partition-guid 1:$FIP_A_uuid \
539 \
540 --new 2:$start_sector_2:+$num_sectors_fip \
541 --change-name 2:FIP_B \
542 --typecode 2:$fip_type_uuid \
543 --partition-guid 2:$FIP_B_uuid \
544 \
545 --new 3:$start_sector_3:+$num_sectors_metadata \
546 --change-name 3:FWU-Metadata \
547 --typecode 3:$metadata_type_uuid \
548 \
549 --new 4:$start_sector_4:+$num_sectors_metadata \
550 --change-name 4:Bkup-FWU-Metadata \
551 --typecode 4:$metadata_type_uuid
Manish V Badarkhe048c9682024-01-22 10:11:49 +0000552
553 # populate the GPT partitions
554 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 +0000555 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
556 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
557 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 +0000558
559 echo "Built $gpt_image"
560
561 archive_file "$gpt_image"
Manish V Badarkheea3e0942021-03-05 11:51:48 +0000562}
563
Govindraj Raja67501732023-09-22 16:27:06 -0500564#corrupt GPT image header and archive it
565corrupt_gpt_bin() {
566 bin="${1:?}"
laurenw-arm2c6665f2024-02-09 16:08:34 -0600567 corrupt_data=$2
Govindraj Raja67501732023-09-22 16:27:06 -0500568
laurenw-arm2c6665f2024-02-09 16:08:34 -0600569 # Check if parameters are provided
570 if [ -z "$bin" ] || [ -z "$corrupt_data" ]; then
571 echo "Usage: corrupt_gpt_bin <bin> <corrupt_data>"
572 return 1
573 fi
574
575 case "$corrupt_data" in
576 "header")
577 # Primary GPT header is present in LBA-1 second block after MBR
578 # empty the primary GPT header forcing to use backup GPT header
579 # and backup GPT entries.
580 seek=1
581 count=1
582 ;;
583 "partition-entries")
584 # GPT partition entry array is present in LBA-2 through LBA-34
585 # blocks empty the GPT partition entry array forcing to use backup
586 # GPT header and backup GPT entries.
587 seek=2
588 count=32
589 ;;
Manish V Badarkheb473c402024-02-14 16:50:08 +0000590 "fwu-metadata")
591 # Get the LBA number for the FWU metadata. Size of which is always
592 # 1 sector (512 bytes).
593 seek=$(gdisk -l $bin | grep " FWU-Metadata$" | awk '{print $2}')
594 count=1
595 ;;
laurenw-arm2c6665f2024-02-09 16:08:34 -0600596 *)
597 echo "Invalid $corrupt_data. Use 'header', 'partition-entries'"
598 return 1
599 ;;
600 esac
601
602 # Use parameters in the dd command
603 dd if=/dev/zero of=$bin bs=512 seek=$seek count=$count conv=notrunc
Govindraj Raja67501732023-09-22 16:27:06 -0500604}
605
Fathi Boudra422bf772019-12-02 11:10:16 +0200606set +u