Build: Add tf-m-extras examples to build configs

- The examples also need extra_params remapping to use custom
build flags.

- Multiple examples use the freertos kernel so it should be cloned.

- The extra_params could contain paths that uses "codebase_root_dir".
  These also need to be substituted in the final build command.

Change-Id: I4d4f67a6f23e3eab193e265a9414f3b941f70d67
Signed-off-by: Bence Balogh <bence.balogh@arm.com>
diff --git a/build_helper/build_helper_config_maps.py b/build_helper/build_helper_config_maps.py
index 984e2c6..8939719 100644
--- a/build_helper/build_helper_config_maps.py
+++ b/build_helper/build_helper_config_maps.py
@@ -81,4 +81,22 @@
     "FVP"          : "-DPLATFORM_IS_FVP=True ",
     "FPGA"         : "-DPLATFORM_IS_FVP=False ",
     "S_PS_OFF"     : "-DTEST_S_PS=OFF ",
+
+    # tf-m-extras example support
+    "EXAMPLE_VAD"             : ("-DNS_EVALUATION_APP_PATH=%(codebase_root_dir)s/../tf-m-extras/examples/vad_an552/ns_side "
+                                "-DTFM_EXTRA_PARTITION_PATHS=%(codebase_root_dir)s/../tf-m-extras/partitions/vad_an552_sp/ "
+                                "-DTFM_EXTRA_MANIFEST_LIST_FILES=%(codebase_root_dir)s/../tf-m-extras/partitions/vad_an552_sp/extra_manifest_list.yaml "
+                                "-DCRYPTO_ENGINE_BUF_SIZE=0x8000 -DITS_MAX_ASSET_SIZE=1300 "
+                                "-DTFM_PARTITION_FIRMWARE_UPDATE=ON -DMCUBOOT_DATA_SHARING=ON "
+                                "-DMCUBOOT_UPGRADE_STRATEGY=SWAP_USING_SCRATCH "
+                                "-DMCUBOOT_IMAGE_NUMBER=1 -DMCUBOOT_SIGNATURE_KEY_LEN=2048 "
+                                "-DCONFIG_TFM_ENABLE_MVE=ON "
+                                "-DFREERTOS_KERNEL_SRC_PATH=%(codebase_root_dir)s/../freertos-kernel"),
+    "EXAMPLE_DMA350_TRIGGER"  : ("-DNS_EVALUATION_APP_PATH=%(codebase_root_dir)s/../tf-m-extras/examples/corstone310_fvp_dma/triggering_example "
+                                "-DFREERTOS_KERNEL_SRC_PATH=%(codebase_root_dir)s/../freertos-kernel"),
+    "EXAMPLE_DMA350_NS"       : ("-DDEFAULT_NS_SCATTER=OFF -DPLATFORM_SVC_HANDLERS=ON "
+                                "-DNS_EVALUATION_APP_PATH=%(codebase_root_dir)s/../tf-m-extras/examples/corstone310_fvp_dma/dma350_ns "
+                                "-DFREERTOS_KERNEL_SRC_PATH=%(codebase_root_dir)s/../freertos-kernel"),
+    "EXAMPLE_DMA350_S"        : "-DEXTRA_S_TEST_SUITES_PATHS=%(codebase_root_dir)s/../tf-m-extras/examples/corstone310_fvp_dma/dma350_s"
+
 }
diff --git a/build_helper/build_helper_configs.py b/build_helper/build_helper_configs.py
index 1af97df..1a07825 100755
--- a/build_helper/build_helper_configs.py
+++ b/build_helper/build_helper_configs.py
@@ -501,6 +501,67 @@
                 "invalid": _common_tfm_invalid_configs + []
                 }
 
+# Config groups for TF-M examples
+config_example_vad = {"seed_params": {
+                "tfm_platform":     ["arm/mps3/an552"],
+                "compiler":         ["GCC_10_3"],
+                "isolation_level":  ["2"],
+                "test_regression":  [False],
+                "test_psa_api":     ["OFF"],
+                "cmake_build_type": ["Release"],
+                "with_bl2":         [True],
+                "profile":          [""],
+                "extra_params":     ["EXAMPLE_VAD"]
+                },
+                "common_params": _common_tfm_builder_cfg,
+                "invalid": _common_tfm_invalid_configs + []
+                }
+
+config_example_dma350_ns = {"seed_params": {
+                "tfm_platform":     ["arm/mps3/corstone310/fvp"],
+                "compiler":         ["GCC_10_3"],
+                "isolation_level":  ["2"],
+                "test_regression":  [False],
+                "test_psa_api":     ["OFF"],
+                "cmake_build_type": ["Release"],
+                "with_bl2":         [True],
+                "profile":          [""],
+                "extra_params":     ["EXAMPLE_DMA350_NS"]
+                },
+                "common_params": _common_tfm_builder_cfg,
+                "invalid": _common_tfm_invalid_configs + []
+                }
+
+config_example_dma350_s = {"seed_params": {
+                "tfm_platform":     ["arm/mps3/corstone310/fvp"],
+                "compiler":         ["GCC_10_3"],
+                "isolation_level":  ["1"],
+                "test_regression":  [False],
+                "test_psa_api":     ["OFF"],
+                "cmake_build_type": ["Release"],
+                "with_bl2":         [True],
+                "profile":          [""],
+                "extra_params":     ["EXAMPLE_DMA350_S"]
+                },
+                "common_params": _common_tfm_builder_cfg,
+                "invalid": _common_tfm_invalid_configs + []
+                }
+
+config_example_dma350_trigger = {"seed_params": {
+                "tfm_platform":     ["arm/mps3/corstone310/fvp"],
+                "compiler":         ["GCC_10_3"],
+                "isolation_level":  ["2"],
+                "test_regression":  [False],
+                "test_psa_api":     ["OFF"],
+                "cmake_build_type": ["Release"],
+                "with_bl2":         [True],
+                "profile":          [""],
+                "extra_params":     ["EXAMPLE_DMA350_TRIGGER"]
+                },
+                "common_params": _common_tfm_builder_cfg,
+                "invalid": _common_tfm_invalid_configs + []
+                }
+
 # Config groups for code coverage
 config_cov_profile_s = deepcopy(config_profile_s)
 config_cov_profile_s["seed_params"]["compiler"] = ["GCC_10_3"]
@@ -950,6 +1011,12 @@
                     "nuvoton_m2351": config_m2351,
                     "nuvoton_m2354": config_m2354,
 
+                    # config groups for tf-m-extras examples
+                    "example_vad": config_example_vad,
+                    "example_dma350_trigger": config_example_dma350_trigger,
+                    "example_dma350_ns": config_example_dma350_ns,
+                    "example_dma350_s": config_example_dma350_s,
+
                     # config groups for debug
                     "debug": config_debug,
                     "debug_regr": config_debug_regr,
diff --git a/clone.sh b/clone.sh
index c84fd4a..b107bb7 100755
--- a/clone.sh
+++ b/clone.sh
@@ -1,6 +1,6 @@
 #!/usr/bin/env bash
 #
-# Copyright (c) 2021 Arm Limited. All rights reserved.
+# Copyright (c) 2021-2022 Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -46,6 +46,14 @@
 TFM_TESTS_REFSPEC="${TFM_TESTS_REFSPEC:-}"
 TFM_TESTS_NAME="tf-m-tests"
 
+TFM_EXTRAS_PROJECT="${TFM_EXTRAS_URL:-}"
+TFM_EXTRAS_REFSPEC="${TFM_EXTRAS_REFSPEC:-}"
+TFM_EXTRAS_NAME="tf-m-extras"
+
+FREERTOS_KERNEL_PROJECT="${FREERTOS_KERNEL_URL:-}"
+FREERTOS_KERNEL_REFSPEC="${FREERTOS_KERNEL_REFSPEC:-}"
+FREERTOS_KERNEL_NAME="freertos-kernel"
+
 MBEDTLS_PROJECT="${MBEDTLS_URL:-}"
 MBEDTLS_REFSPEC="${MBEDTLS_VERSION:-}"
 MBEDTLS_NAME="mbedtls"
@@ -71,6 +79,8 @@
     "${MCUBOOT_PROJECT};${MCUBOOT_NAME};${MCUBOOT_REFSPEC}"
     "${PSA_ARCH_TESTS_PROJECT};${PSA_ARCH_TESTS_NAME};${PSA_ARCH_TESTS_REFSPEC}"
     "${PSA_QCBOR_PROJECT};${PSA_QCBOR_NAME};${PSA_QCBOR_REFSPEC}"
+    "${TFM_EXTRAS_PROJECT};${TFM_EXTRAS_NAME};${TFM_EXTRAS_REFSPEC}"
+    "${FREERTOS_KERNEL_PROJECT};${FREERTOS_KERNEL_NAME};${FREERTOS_KERNEL_REFSPEC}"
     "https://review.trustedfirmware.org/ci/qa-tools;qa-tools;openci"
 )
 
diff --git a/jenkins/ci.jpl b/jenkins/ci.jpl
index fd6d9ff..5557a08 100644
--- a/jenkins/ci.jpl
+++ b/jenkins/ci.jpl
@@ -90,10 +90,14 @@
   params += string(name: 'MCUBOOT_URL', value: env.MCUBOOT_URL)
   params += string(name: 'MBEDTLS_VERSION', value: env.MBEDTLS_VERSION)
   params += string(name: 'MBEDTLS_URL', value: env.MBEDTLS_URL)
+  params += string(name: 'TFM_EXTRAS_REFSPEC', value: env.TFM_EXTRAS_REFSPEC)
+  params += string(name: 'TFM_EXTRAS_URL', value: env.TFM_EXTRAS_URL)
   params += string(name: 'TFM_TESTS_REFSPEC', value: env.TFM_TESTS_REFSPEC)
   params += string(name: 'TFM_TESTS_URL', value: env.TFM_TESTS_URL)
   params += string(name: 'PSA_ARCH_TESTS_VERSION', value: env.PSA_ARCH_TESTS_VERSION)
   params += string(name: 'PSA_ARCH_TESTS_URL', value: env.PSA_ARCH_TESTS_URL)
+  params += string(name: 'FREERTOS_KERNEL_REFSPEC', value: env.FREERTOS_KERNEL_REFSPEC)
+  params += string(name: 'FREERTOS_KERNEL_URL', value: env.FREERTOS_KERNEL_URL)
   params += string(name: 'SHARE_FOLDER', value: env.SHARE_FOLDER)
   params += string(name: 'SQUAD_CONFIGURATIONS', value: env.SQUAD_CONFIGURATIONS)
   return { -> results
diff --git a/tfm_ci_pylib/tfm_build_manager.py b/tfm_ci_pylib/tfm_build_manager.py
index ff48960..d30c285 100644
--- a/tfm_ci_pylib/tfm_build_manager.py
+++ b/tfm_ci_pylib/tfm_build_manager.py
@@ -398,8 +398,11 @@
                             "test_psa_api": i.test_psa_api,
                             "cmake_build_type": i.cmake_build_type,
                             "with_bl2": i.with_bl2,
-                            "profile": "" if i.profile=="N.A" else i.profile,
-                            "extra_params": self.map_extra_params(i.extra_params)}
+                            "profile": "" if i.profile=="N.A" else i.profile}
+        # The extra params can also contain paths with "codebase_root_dir" and
+        # these also need to be substituted
+        overwrite_params["extra_params"] = self.map_extra_params(i.extra_params) % overwrite_params
+
         if i.test_psa_api == "IPC":
             overwrite_params["test_psa_api"] += " -DINCLUDE_PANIC_TESTS=1"
         if i.test_psa_api == "CRYPTO" and "musca" in i.tfm_platform: