fvp_utils: support trace-based code coverage in FVP LAVA jobs

Different test configurations required the trace-based code
coverage pluging [1], however in OpenCI, these are disabled due to
lack of support. This commit enables the support in LAVA jobs,
fetching the coverage trace plugin from the downloads repository
[2]. This patch co-depends on [3] to properly work.

NOTE: this patch does not cover the extraction of trace logs from LAVA
into Jenkins, so the latter can convert logs into human-friendly LCOV
html reports. This is WIP and will be coverered in a separate patch.

[1] https://gitlab.arm.com/tooling/qa-tools
[2] https://downloads.trustedfirmware.org
[3] https://review.trustedfirmware.org/c/ci/tf-a-job-configs/+/9631

Signed-off-by: Leonardo Sandoval <leonardo.sandoval@linaro.org>
Change-Id: I20c1cb0570169dad1e4c3fd8b6245c820cf5d1ac
diff --git a/fvp_utils.sh b/fvp_utils.sh
index 1318385..4a1c733 100644
--- a/fvp_utils.sh
+++ b/fvp_utils.sh
@@ -349,6 +349,7 @@
     cactus_primary="$(fvp_gen_bin_url cactus-primary.pkg)"
     cactus_secondary="$(fvp_gen_bin_url cactus-secondary.pkg)"
     cactus_tertiary="$(fvp_gen_bin_url cactus-tertiary.pkg)"
+    coverage_trace_plugin="${coverage_trace_plugin}"
     dtb="$(fvp_gen_bin_url ${model_dtb})"
     el3_payload="$(fvp_gen_bin_url el3_payload.bin)"
     fip="$(fvp_gen_bin_url fip.bin)"
@@ -404,6 +405,7 @@
         [cactus_primary]="{CACTUS_PRIMARY}"
         [cactus_secondary]="{CACTUS_SECONDARY}"
         [cactus_tertiary]="{CACTUS_TERTIARY}"
+        [coverage_trace_plugin]="{COVERAGE_TRACE_PLUGIN}"
         [busybox]="{BUSYBOX}"
         [dtb]="{DTB}"
         [el3_payload]="{EL3_PAYLOAD}"
@@ -464,6 +466,12 @@
                     sed -i "/url: ${artefacts_macros[$m]}\$/d" "${yaml_template_file}"
                 fi
                 ;;
+            coverage_trace_plugin)
+                if ! grep -q "coverage_trace.so" "$archive/model_params"; then
+                    sed -i "/$m:\$/d" "${yaml_template_file}"
+                    sed -i "/url: ${artefacts_macros[$m]}\$/d" "${yaml_template_file}"
+                fi
+                ;;
             dtb)
                 # dtb can come in different names, i.e.  dtb.bin, manifest.dtb,
                 # so handle with regex
@@ -561,6 +569,10 @@
             cactus_tertiary)
                 sed -i -e "s|=cactus-tertiary.pkg|=${artefacts_macros[$m]}|" "$lava_model_params"
                 ;;
+            coverage_trace_plugin)
+                sed -i -e "s|--plugin .*coverage_trace.so|--plugin ${artefacts_macros[$m]}|" "$lava_model_params"
+                sed -i -e "s|--plugin=.*coverage_trace.so|--plugin=${artefacts_macros[$m]}|" "$lava_model_params"
+                ;;
             generic_trace)
                 sed -i -e "s|--plugin .*GenericTrace.so|--plugin ${artefacts_macros[$m]}|" "$lava_model_params"
 		sed -i -e "s|--plugin=.*GenericTrace.so|--plugin=${artefacts_macros[$m]}|" "$lava_model_params"
diff --git a/script/gen_fvp_linux_yaml.sh b/script/gen_fvp_linux_yaml.sh
index 5ff62c1..bf78d24 100755
--- a/script/gen_fvp_linux_yaml.sh
+++ b/script/gen_fvp_linux_yaml.sh
@@ -54,6 +54,8 @@
         url: {CACTUS_SECONDARY}
       cactus_tertiary:
         url: {CACTUS_TERTIARY}
+      coverage_trace_plugin:
+        url: {COVERAGE_TRACE_PLUGIN}
       dtb:
         url: {DTB}
       el3_payload:
diff --git a/script/gen_fvp_tftf_yaml.sh b/script/gen_fvp_tftf_yaml.sh
index e1c874e..a6bab56 100755
--- a/script/gen_fvp_tftf_yaml.sh
+++ b/script/gen_fvp_tftf_yaml.sh
@@ -57,6 +57,8 @@
         url: {CACTUS_SECONDARY}
       cactus_tertiary:
         url: {CACTUS_TERTIARY}
+      coverage_trace_plugin:
+        url: {COVERAGE_TRACE_PLUGIN}
       dtb:
         url: {DTB}
       el3_payload:
diff --git a/utils.sh b/utils.sh
index 51e3178..6a5ce49 100644
--- a/utils.sh
+++ b/utils.sh
@@ -326,7 +326,7 @@
 spm_src_repo_url="${spm_src_repo_url:-$SPM_SRC_REPO_URL}"
 spm_src_repo_url="${spm_src_repo_url:-https://$tforg_gerrit_url/hafnium/hafnium}"
 
-# FIXME set a sane default for tfa_downloads
+tf_downloads="${tf_downloads:-file:///downloads/}"
 tfa_downloads="${tfa_downloads:-file:///downloads/tf-a}"
 css_downloads="${css_downloads:-$tfa_downloads/css}"