Build: Support TF-M split build feature

TF-M build commands are changed by new feature "split build".
Update CI scripts to support this feature.

Signed-off-by: Xinyu Zhang <xinyu.zhang@arm.com>
Change-Id: If5a81ca7a1bd99ac8fb9f4850be89b48b76fcbe2
diff --git a/build_helper/build_helper_configs.py b/build_helper/build_helper_configs.py
index 01c6904..2a00f0b 100755
--- a/build_helper/build_helper_configs.py
+++ b/build_helper/build_helper_configs.py
@@ -45,7 +45,9 @@
     # Keys for the templace will come from the combinations of parameters
     # provided in the seed dictionary.
 
-    "config_template": "cmake -G Ninja " + \
+    "spe_config_template": "cmake -G Ninja " + \
+        "-S %(tfm_tests_root_dir)s/%(test_root_dir)s/spe " + \
+        "-B %(ci_build_root_dir)s/spe " + \
         "-DTFM_PLATFORM=%(tfm_platform)s " + \
         "-DTFM_TOOLCHAIN_FILE=%(codebase_root_dir)s/%(compiler)s " + \
         "-DTFM_ISOLATION_LEVEL=%(isolation_level)s " + \
@@ -55,13 +57,23 @@
         "-DBL2=%(with_bl2)s " + \
         "-DTFM_PROFILE=%(profile)s " + \
         "%(extra_params)s " + \
-        "-DTFM_TEST_REPO_PATH=%(codebase_root_dir)s/../tf-m-tests " + \
+        "-DCONFIG_TFM_SOURCE_PATH=%(codebase_root_dir)s " + \
         "-DMBEDCRYPTO_PATH=%(codebase_root_dir)s/../mbedtls " + \
         "-DPSA_ARCH_TESTS_PATH=%(codebase_root_dir)s/../psa-arch-tests " + \
         "-DMCUBOOT_PATH=%(codebase_root_dir)s/../mcuboot " + \
         "-DQCBOR_PATH=%(codebase_root_dir)s/../qcbor " + \
-        "-DTFM_EXTRAS_REPO_PATH=%(codebase_root_dir)s/../tf-m-extras " + \
-        "%(codebase_root_dir)s",
+        "-DTFM_EXTRAS_REPO_PATH=%(codebase_root_dir)s/../tf-m-extras ",
+
+    "nspe_config_template": "cmake -G Ninja " + \
+        "-S %(tfm_tests_root_dir)s/%(test_root_dir)s " + \
+        "-B %(ci_build_root_dir)s/nspe " + \
+        "-DCONFIG_SPE_PATH=%(ci_build_root_dir)s/spe/api_ns " + \
+        "%(extra_params)s " + \
+        "-DQCBOR_PATH=%(codebase_root_dir)s/../qcbor ",
+
+    # CMake build commands will be executed for every build.
+    "spe_cmake_build":  "cmake --build %(ci_build_root_dir)s/spe -- install",
+    "nspe_cmake_build": "cmake --build %(ci_build_root_dir)s/nspe -- tfm_app_binaries",
 
     "set_compiler_path": "export PATH=$PATH:$%(compiler)s_PATH",
 
@@ -69,97 +81,96 @@
     # tfm_build_manager will replace %(_tbm_build_dir_)s,  %(_tbm_code_dir_)s,
     # _tbm_target_platform_ with the  paths set when building
 
-    "artifact_capture_rex": (r'%(_tbm_build_dir_)s/bin'
+    "artifact_capture_rex": (r'%(ci_build_root_dir)s/nspe'
                              r'/(\w+\.(?:axf|bin|hex))$'),
 
-    # CMake build commands will be executed for every build.
-    "cmake_build": "cmake --build ./ -- install",
     # Keys will append extra commands when matching target_platform
-    "post_build": {"arm/corstone1000": ("dd conv=notrunc bs=1 if=%(_tbm_build_dir_)s/bin/bl1_1.bin of=%(_tbm_build_dir_)s/bin/bl1.bin seek=0;"
-                                        "dd conv=notrunc bs=1 if=%(_tbm_build_dir_)s/bin/bl1_provisioning_bundle.bin of=%(_tbm_build_dir_)s/bin/bl1.bin seek=40960;"
-                                        "../platform/ext/target/arm/corstone1000/create-flash-image.sh %(_tbm_build_dir_)s/bin/ cs1000.bin;"),
+    "post_build": {"arm/corstone1000": ("dd conv=notrunc bs=1 if=%(ci_build_root_dir)s/spe/bin/bl1_1.bin of=%(ci_build_root_dir)s/spe/bin/bl1.bin seek=0;"
+                                        "dd conv=notrunc bs=1 if=%(ci_build_root_dir)s/spe/bin/bl1_provisioning_bundle.bin of=%(ci_build_root_dir)s/spe/bin/bl1.bin seek=40960;"
+                                        "../platform/ext/target/arm/corstone1000/create-flash-image.sh %(ci_build_root_dir)s/spe/bin/ cs1000.bin;"),
                     "arm/musca_b1": ("srec_cat "
-                                 "%(_tbm_build_dir_)s/bin/"
+                                 "%(ci_build_root_dir)s/spe/bin/"
                                  "bl2.bin "
                                  "-Binary -offset 0xA000000 "
                                  "-fill 0xFF 0xA000000 0xA020000 "
-                                 "%(_tbm_build_dir_)s/bin/"
+                                 "%(ci_build_root_dir)s/nspe/"
                                  "tfm_s_ns_signed.bin "
                                  "-Binary -offset 0xA020000 "
                                  "-fill 0xFF 0xA020000 0xA200000 "
-                                 "-o %(_tbm_build_dir_)s/bin/"
+                                 "-o %(ci_build_root_dir)s/"
                                  "tfm.hex -Intel"),
                    "arm/musca_s1": ("srec_cat "
-                                 "%(_tbm_build_dir_)s/bin/"
+                                 "%(ci_build_root_dir)s/spe/bin/"
                                  "bl2.bin "
                                  "-Binary -offset 0xA000000 "
                                  "-fill 0xFF 0xA000000 0xA020000 "
-                                 "%(_tbm_build_dir_)s/bin/"
+                                 "%(ci_build_root_dir)s/nspe/"
                                  "tfm_s_ns_signed.bin "
                                  "-Binary -offset 0xA020000 "
                                  "-fill 0xFF 0xA020000 0xA200000 "
-                                 "-o %(_tbm_build_dir_)s/bin/"
+                                 "-o %(ci_build_root_dir)s/"
                                  "tfm.hex -Intel"),
                    "stm/stm32l562e_dk": ("echo 'STM32L562E-DK board post process';"
-                                          "%(_tbm_build_dir_)s/postbuild.sh;"
-                                          "pushd %(_tbm_build_dir_)s;"
+                                          # TODO: Confirm the path of postbuild.sh
+                                          "%(ci_build_root_dir)s/spe/postbuild.sh;"
+                                          "pushd %(ci_build_root_dir)s/spe;"
                                           "BIN_FILES=$(grep -o '\/.*\.bin' TFM_UPDATE.sh | sed 's/^/bin/');"
                                           "tar jcf ./bin/stm32l562e-dk-tfm.tar.bz2 regression.sh TFM_UPDATE.sh ${BIN_FILES};"
                                           "popd"),
                    "stm/b_u585i_iot02a": ("echo 'STM32U5 board post process';"
-                                          "%(_tbm_build_dir_)s/postbuild.sh;"
-                                          "pushd %(_tbm_build_dir_)s;"
+                                          # TODO: Confirm the path of postbuild.sh
+                                          "%(ci_build_root_dir)s/spe/postbuild.sh;"
+                                          "pushd %(ci_build_root_dir)s/spe;"
                                           "BIN_FILES=$(grep -o '\/.*\.bin' TFM_UPDATE.sh | sed 's/^/bin/');"
                                           "tar jcf ./bin/b_u585i_iot02a-tfm.tar.bz2 regression.sh TFM_UPDATE.sh ${BIN_FILES};"
                                           "popd"),
                   "nxp/lpcxpresso55s69": ("echo 'LPCXpresso55S69 board post process\n';"
-                                            "if [ -f \"%(_tbm_build_dir_)s/bin/bl2.hex\" ]; then FLASH_FILE='flash_bl2_JLink.py'; else FLASH_FILE='flash_JLink.py'; fi;"
-                                            "pushd %(_tbm_build_dir_)s/../platform/ext/target/nxp/lpcxpresso55s69/scripts;"
+                                            "if [ -f \"%(ci_build_root_dir)s/spe/bin/bl2.hex\" ]; then FLASH_FILE='flash_bl2_JLink.py'; else FLASH_FILE='flash_JLink.py'; fi;"
+                                            "pushd%(codebase_root_dir)s/platform/ext/target/nxp/lpcxpresso55s69/scripts;"
                                             "LN=$(grep -n 'JLinkExe' ${FLASH_FILE}|awk -F: '{print $1}');"
                                             "sed -i \"${LN}s/.*/    print('flash.jlink generated')/\" ${FLASH_FILE};"
                                             "python3 ./${FLASH_FILE};"
-                                            "cd %(_tbm_build_dir_)s/bin;"
+                                            # TODO: Confirm which bin is needed? SPE or NSPE?
+                                            "cd %(ci_build_root_dir)s/spe/bin;"
                                             "BIN_FILES=$(grep loadfile flash.jlink | awk '{print $2}');"
                                             "tar jcf lpcxpresso55s69-tfm.tar.bz2 flash.jlink ${BIN_FILES};"
                                             "popd"),
                    "cypress/psoc64": ("echo 'Sign binaries for Cypress PSoC64 platform';"
-                                       "pushd %(_tbm_build_dir_)s/..;"
+                                       "pushd %(codebase_root_dir)s/;"
                                        "sudo /usr/local/bin/cysecuretools "
                                        "--policy platform/ext/target/cypress/psoc64/security/policy/policy_multi_CM0_CM4_tfm.json "
                                        "--target cy8ckit-064s0s2-4343w "
                                        "sign-image "
-                                       "--hex %(_tbm_build_dir_)s/bin/tfm_s.hex "
+                                       "--hex %(ci_build_root_dir)s/spe/bin/tfm_s.hex "
                                        "--image-type BOOT --image-id 1;"
                                        "sudo /usr/local/bin/cysecuretools "
                                        "--policy platform/ext/target/cypress/psoc64/security/policy/policy_multi_CM0_CM4_tfm.json "
                                        "--target cy8ckit-064s0s2-4343w "
                                        "sign-image "
-                                       "--hex %(_tbm_build_dir_)s/bin/tfm_ns.hex "
+                                       "--hex %(ci_build_root_dir)s/nspe/bin/tfm_ns.hex "
                                        "--image-type BOOT --image-id 16;"
-                                       "mv %(_tbm_build_dir_)s/bin/tfm_s.hex %(_tbm_build_dir_)s/bin/tfm_s_signed.hex;"
-                                       "mv %(_tbm_build_dir_)s/bin/tfm_ns.hex %(_tbm_build_dir_)s/bin/tfm_ns_signed.hex;"
+                                       "mv %(ci_build_root_dir)s/spe/bin/tfm_s.hex %(ci_build_root_dir)s/spe/bin/tfm_s_signed.hex;"
+                                       "mv %(ci_build_root_dir)s/nspe/bin/tfm_ns.hex %(ci_build_root_dir)s/nspe/bin/tfm_ns_signed.hex;"
                                        "popd")
                    },
 
     # (Optional) If set will fail if those artefacts are missing post build
     "required_artefacts": {"all": [
-                           "%(_tbm_build_dir_)s/bin/"
+                           "%(ci_build_root_dir)s/spe/bin/"
                            "tfm_s.bin",
-                           "%(_tbm_build_dir_)s/bin/"
+                           "%(ci_build_root_dir)s/nspe/"
                            "tfm_ns.bin"],
                            "arm/musca_b1": [
-                           "%(_tbm_build_dir_)s/bin/"
-                           "tfm.hex",
-                           "%(_tbm_build_dir_)s/bin/"
+                           "%(ci_build_root_dir)s/tfm.hex",
+                           "%(ci_build_root_dir)s/spe/bin/"
                            "bl2.bin",
-                           "%(_tbm_build_dir_)s/bin/"
+                           "%(ci_build_root_dir)s/spe/bin/"
                            "tfm_sign.bin"],
                            "arm/musca_s1": [
-                           "%(_tbm_build_dir_)s/bin/"
-                           "tfm.hex",
-                           "%(_tbm_build_dir_)s/bin/"
+                           "%(ci_build_root_dir)s/tfm.hex",
+                           "%(ci_build_root_dir)s/spe/bin/"
                            "bl2.bin",
-                           "%(_tbm_build_dir_)s/bin/"
+                           "%(ci_build_root_dir)s/spe/bin/"
                            "tfm_sign.bin"]
                            }
 }
@@ -185,10 +196,12 @@
 
 # Configure build manager to build several combinations
 # Config group for per-patch job
+
+# TODO: Revert the config change in pp test when merging back to master
 config_pp_test = {"seed_params": {
-                # AN519_ARMCLANG_IPC_1_RegBL2_RegS_RegNS_Debug_BL2
-                "tfm_platform":     ["arm/mps2/an519"],
-                "compiler":         ["ARMCLANG_6_13"],
+                # AN521_ARMCLANG_IPC_1_RegBL2_RegS_RegNS_Debug_BL2
+                "tfm_platform":     ["arm/mps2/an521"],
+                "compiler":         ["GCC_10_3"],
                 "isolation_level":  ["1"],
                 "test_regression":  ["RegBL2, RegS, RegNS"],
                 "test_psa_api":     ["OFF"],
@@ -199,36 +212,6 @@
                 },
                 "common_params": _common_tfm_builder_cfg,
                 "valid": [
-                    # AN519_ARMCLANG_2_RegBL2_RegS_RegNS_Release_BL2
-                    ("arm/mps2/an519", "ARMCLANG_6_13", "2",
-                     "RegBL2, RegS, RegNS", "OFF", "Release", True, "",  ""),
-                    # AN519_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
-                    ("arm/mps2/an519", "GCC_10_3", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "",  ""),
-                    # AN519_GCC_2_RegBL2_RegS_RegNS_Release_BL2
-                    ("arm/mps2/an519", "GCC_10_3", "2",
-                     "RegBL2, RegS, RegNS", "OFF", "Release", True, "", ""),
-                    # AN519_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
-                    ("arm/mps2/an519", "GCC_10_3", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
-                    # AN521_ARMCLANG_1_RegBL2_RegS_RegNS_Debug_BL2_SMALL_PSOFF
-                    ("arm/mps2/an521", "ARMCLANG_6_13", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "profile_small", "PSOFF"),
-                    # AN521_ARMCLANG_1_RegBL2_RegS_RegNS_Debug_BL2
-                    ("arm/mps2/an521", "ARMCLANG_6_13", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
-                    # AN521_ARMCLANG_1_RegBL2_RegS_RegNS_Debug_BL2_IPC
-                    ("arm/mps2/an521", "ARMCLANG_6_13", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", "IPC"),
-                    # AN521_ARMCLANG_2_RegBL2_RegS_RegNS_Release_BL2
-                    ("arm/mps2/an521", "ARMCLANG_6_13", "2",
-                     "RegBL2, RegS, RegNS", "OFF", "Release", True, "", ""),
-                    # AN521_ARMCLANG_3_RegBL2_RegS_RegNS_Minsizerel_BL2
-                    ("arm/mps2/an521", "ARMCLANG_6_13", "3",
-                     "RegBL2, RegS, RegNS", "OFF", "Minsizerel", True, "", ""),
-                    # AN521_ARMCLANG_1_RegBL2_RegS_RegNS_Debug_BL2_SMALL_PSOFF
-                    ("arm/mps2/an521", "ARMCLANG_6_13", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "profile_small", "PSOFF"),
                     # AN521_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
                     ("arm/mps2/an521", "GCC_10_3", "1",
                      "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
@@ -244,51 +227,36 @@
                     # AN521_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
                     ("arm/mps2/an521", "GCC_10_3", "1",
                      "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
-                    # CS300_FVP_GNUARM_2_RegBL2_RegS_RegNS_Debug_BL2
-                    ("arm/mps3/corstone300/fvp", "GCC_10_3", "2",
-                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
-                    # CS300_FVP_GNUARM_2_RegBL2_RegS_RegNS_Release_BL2
-                    ("arm/mps3/corstone300/fvp", "GCC_10_3", "2",
-                     "RegBL2, RegS, RegNS", "OFF", "Release", True, "", ""),
-                    # MUSCA_B1_GCC_1_RegBL2_RegS_RegNS_Minsizerel_BL2
+                    # MUSCA-B1_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
                     ("arm/musca_b1", "GCC_10_3", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Minsizerel", True, "", ""),
-                    # MUSCA_S1_ARMCLANG_2_RegBL2_RegS_RegNS_Release_BL2
-                    ("arm/musca_s1", "ARMCLANG_6_13", "2",
+                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
+                    # MUSCA-B1_GCC_2_Debug_BL2_LARGET
+                    ("arm/musca_b1", "GCC_10_3", "2",
+                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "profile_large", ""),
+                    # MUSCA-B1_GCC_2_RegBL2_RegS_RegNS_Release_BL2
+                    ("arm/musca_b1", "GCC_10_3", "2",
                      "RegBL2, RegS, RegNS", "OFF", "Release", True, "", ""),
-                    # MUSCA_S1_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
+                    # MUSCA-B1_GCC_3_RegBL2_RegS_RegNS_Minsizerel_BL2
+                    ("arm/musca_b1", "GCC_10_3", "3",
+                     "RegBL2, RegS, RegNS", "OFF", "Minsizerel", True, "", ""),
+                    # MUSCA-B1_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
+                    ("arm/musca_b1", "GCC_10_3", "1",
+                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
+                    # MUSCA-S1_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
                     ("arm/musca_s1", "GCC_10_3", "1",
                      "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
-                    # MUSCA_S1_GCC_2_RegBL2_RegS_RegNS_Release_BL2
+                    # MUSCA-S1_GCC_1_Debug_BL2_SMALL
+                    ("arm/musca_s1", "GCC_10_3", "1",
+                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "profile_small", ""),
+                    # MUSCA-S1_GCC_2_RegBL2_RegS_RegNS_Release_BL2
                     ("arm/musca_s1", "GCC_10_3", "2",
                      "RegBL2, RegS, RegNS", "OFF", "Release", True, "", ""),
-                    # MUSCA_S1_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
+                    # MUSCA-S1_GCC_3_RegBL2_RegS_RegNS_Minsizerel_BL2
                     ("arm/musca_s1", "GCC_10_3", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", ""),
-                    # MUSCA_S1_GCC_1_RegBL2_RegS_RegNS_Release_BL2_CC_DRIVER_PSA
+                     "RegBL2, RegS, RegNS", "OFF", "Minsizerel", True, "", ""),
+                    # MUSCA-S1_GCC_1_RegBL2_RegS_RegNS_Debug_BL2
                     ("arm/musca_s1", "GCC_10_3", "1",
-                     "RegBL2, RegS, RegNS", "OFF", "Release", True, "", "CC_DRIVER_PSA"),
-                    # RSS_TC_GCC_2_Release_BL2_PSOFF
-                    ("arm/rss/tc", "GCC_10_3", "2",
-                     "RegS, RegNS", "OFF", "Release", True, "", "PSOFF"),
-                    # stm32l562e_dk_ARMCLANG_1_RegS_RegNS_Release_BL2_CRYPTO_OFF
-                    ("stm/stm32l562e_dk", "ARMCLANG_6_13", "1",
-                     "RegS, RegNS", "OFF", "Release", True, "", "CRYPTO_OFF"),
-                    # stm32l562e_dk_GCC_2_Release_BL2_CRYPTO_ON
-                    ("stm/stm32l562e_dk", "GCC_10_3", "2",
-                     "OFF", "OFF", "Release", True, "", "CRYPTO_ON"),
-                    # stm32l562e_dk_GCC_3_RegS_RegNS_Release_BL2_CRYPTO_OFF
-                    ("stm/stm32l562e_dk", "GCC_10_3", "3",
-                     "RegBL2, RegS, RegNS", "OFF", "Release", True, "", "CRYPTO_OFF"),
-                    # b_u585i_iot02a_GCC_1_RegS_RegNS_Release_BL2
-                    ("stm/b_u585i_iot02a", "GCC_10_3", "1",
-                     "RegS, RegNS", "OFF", "Release", True, "", ""),
-                    # b_u585i_iot02a_ARMCLANG_2_RegS_RegNS_Release_BL2
-                    ("stm/b_u585i_iot02a", "ARMCLANG_6_13", "2",
-                     "RegS, RegNS", "OFF", "Release", True, "", ""),
-                    # psoc64_GCC_2_RegS_RegNS_Release
-                    ("cypress/psoc64", "GCC_10_3", "2",
-                     "RegS, RegNS", "OFF", "Release", False, "", ""),
+                     "RegBL2, RegS, RegNS", "OFF", "Debug", True, "", "")
                 ],
                 "invalid": _common_tfm_invalid_configs + []
                 }