Config: Add stm targets in single entry point

This patch allows to group all stm targets in single cmake entry point.
The stm TARGET_PLATFORM should prefix by "STM".
stm platforms supports CoreIPC, CoreIPCTfmLevel2 and RegressionIPCTfmLevel2
Build with GNUARM toolchain.

Change-Id: I6535420b2304c18f2ab260620c38fef632eb7488
Signed-off-by: Ludovic Barre <ludovic.barre@st.com>
Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
diff --git a/bl2/ext/mcuboot/scripts/imgtool.py b/bl2/ext/mcuboot/scripts/imgtool.py
index 2d1d97b..b524245 100644
--- a/bl2/ext/mcuboot/scripts/imgtool.py
+++ b/bl2/ext/mcuboot/scripts/imgtool.py
@@ -24,6 +24,7 @@
 from imgtool_lib import version
 import sys
 import macro_parser
+import fileinput
 
 sign_bin_size_re = re.compile(r"^\s*RE_SIGN_BIN_SIZE\s*=\s*(.*)")
 image_load_address_re = re.compile(r"^\s*RE_IMAGE_LOAD_ADDRESS\s*=\s*(.*)")
@@ -126,10 +127,30 @@
 
     img.save(args.outfile)
 
+def do_flash(args):
+    image_value_re = re.compile(r"^\s*"+args.macro+"\s*=\s*(.*)")
+    value = macro_parser.evaluate_macro(args.layout, image_value_re, 0, 1,
+                                        True)
+    if args.setting == 1:
+        begin_line="set "+args.begin
+    else:
+        begin_line=args.begin
+
+    for line in fileinput.input(args.infile, inplace=True):
+        if line.startswith(begin_line):
+            if args.division:
+                value = int(value/int(args.division))
+            if args.phexa == 0:
+                line = begin_line+"="+str(value)+"\n"
+            else:
+                line = begin_line+"="+hex(value)+"\n"
+        sys.stdout.write(line)
+
 subcmds = {
         'keygen': do_keygen,
         'getpub': do_getpub,
-        'sign': do_sign, }
+        'sign': do_sign,
+        'flash': do_flash, }
 
 
 def get_dependencies(text):
@@ -205,6 +226,23 @@
     sign.add_argument("infile")
     sign.add_argument("outfile")
 
+    flash = subs.add_parser('flash', help='modify flash script')
+    flash.add_argument("infile")
+    flash.add_argument('-l', '--layout', required=True,
+                      help='Location of the file that contains preprocessed macros')
+    flash.add_argument('-m', '--macro', required =True,
+                      help='macro symbol string to grep in preprocessed file')
+    flash.add_argument('-b', '--begin', required=True,
+                      help='begin of line to replace ')
+    flash.add_argument('-s', '--setting',type=intparse,required=False,default=0,
+                      help='search for window batch set variable')
+    flash.add_argument('-d', '--division',
+                       required=False,type=intparse,default=0,
+                      help='search for window batch set variable')
+    flash.add_argument('-p', '--phexa',
+                       required=False,type=intparse,default=1,
+                      help='print value in hexa')
+
     args = parser.parse_args()
     if args.subcmd is None:
         print('Must specify a subcommand', file=sys.stderr)
diff --git a/bl2/ext/mcuboot/scripts/macro_parser.py b/bl2/ext/mcuboot/scripts/macro_parser.py
index 3f7feb6..188c650 100644
--- a/bl2/ext/mcuboot/scripts/macro_parser.py
+++ b/bl2/ext/mcuboot/scripts/macro_parser.py
@@ -47,7 +47,7 @@
 # Opens a file that contains the macro of interest, then finds the macro with

 # a regular expression, parses the expression that is defined for the given

 # macro. Lastly it evaluates the expression with the parse_and_sum function

-def evaluate_macro(file, regexp, matchGroupKey, matchGroupData):

+def evaluate_macro(file, regexp, matchGroupKey, matchGroupData, bracketless=False):

     regexp_compiled = re.compile(regexp)

 

     if os.path.isabs(file):

@@ -59,6 +59,9 @@
     macroValue = {}

     with open(configFile, 'r') as macros_preprocessed_file:

         for line in macros_preprocessed_file:

+            if bracketless:

+                line=line.replace("(","")

+                line=line.replace(")","")

             m = regexp_compiled.match(line)

             if m is not None:

                 macroValue[m.group(matchGroupKey)] = \

diff --git a/configs/ConfigCoreIPC.cmake b/configs/ConfigCoreIPC.cmake
index 3b85b45..1ab012f 100644
--- a/configs/ConfigCoreIPC.cmake
+++ b/configs/ConfigCoreIPC.cmake
@@ -37,6 +37,8 @@
 	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/psoc64.cmake")
 elseif(${TARGET_PLATFORM} STREQUAL "SSE-200_AWS")
 	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/SSE-200_AWS.cmake")
+elseif(${TARGET_PLATFORM} MATCHES "^STM")
+	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/stm.cmake")
 else()
 	message(FATAL_ERROR "ERROR: Target \"${TARGET_PLATFORM}\" is not supported.")
 endif()
diff --git a/configs/ConfigCoreIPCTfmLevel2.cmake b/configs/ConfigCoreIPCTfmLevel2.cmake
index f19626c..594c34b 100644
--- a/configs/ConfigCoreIPCTfmLevel2.cmake
+++ b/configs/ConfigCoreIPCTfmLevel2.cmake
@@ -37,6 +37,8 @@
 	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/psoc64.cmake")
 elseif(${TARGET_PLATFORM} STREQUAL "SSE-200_AWS")
 	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/SSE-200_AWS.cmake")
+elseif(${TARGET_PLATFORM} MATCHES "^STM")
+	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/stm.cmake")
 else()
 	message(FATAL_ERROR "ERROR: Target \"${TARGET_PLATFORM}\" is not supported.")
 endif()
diff --git a/configs/ConfigRegressionIPCTfmLevel2.cmake b/configs/ConfigRegressionIPCTfmLevel2.cmake
index 162d224..a4c1a6d 100644
--- a/configs/ConfigRegressionIPCTfmLevel2.cmake
+++ b/configs/ConfigRegressionIPCTfmLevel2.cmake
@@ -37,6 +37,8 @@
 	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/psoc64.cmake")
 elseif(${TARGET_PLATFORM} STREQUAL "SSE-200_AWS")
 	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/SSE-200_AWS.cmake")
+elseif(${TARGET_PLATFORM} MATCHES "^STM")
+	set(PLATFORM_CMAKE_FILE "${TFM_ROOT_DIR}/platform/ext/stm.cmake")
 else()
 	message(FATAL_ERROR "ERROR: Target \"${TARGET_PLATFORM}\" is not supported.")
 endif()
diff --git a/docs/readme.rst b/docs/readme.rst
index c0d6d0a..35e628a 100644
--- a/docs/readme.rst
+++ b/docs/readme.rst
@@ -111,6 +111,10 @@
           <https://developer.arm.com/docs/101965/0102/arm-designstart-fpga-on-cloud-arm-ds-getting-started>`_
         - `NXP LPC55S69.
           <https://www.nxp.com/products/processors-and-microcontrollers/arm-microcontrollers/general-purpose-mcus/lpc5500-cortex-m33/lpcxpresso55s69-development-board:LPC55S69-EVK>`_
+        - `NUCLEO L552ZE Q.
+          <https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-mpu-eval-tools/stm32-mcu-mpu-eval-tools/stm32-nucleo-boards/nucleo-l552ze-q.html>`_
+        - `DISCO L562QE.
+          <https://www.st.com/content/st_com/en/products/evaluation-tools/product-evaluation-tools/mcu-mpu-eval-tools/stm32-mcu-mpu-eval-tools/stm32-discovery-kits/stm32l562e-dk.html>`_
 
     - Cortex-M23 system:
 
diff --git a/docs/user_guides/tfm_build_instruction.rst b/docs/user_guides/tfm_build_instruction.rst
index de910ad..3f5d0f9 100644
--- a/docs/user_guides/tfm_build_instruction.rst
+++ b/docs/user_guides/tfm_build_instruction.rst
@@ -265,6 +265,12 @@
             See :doc:`Cypress PSoC 64 platform specifics </platform/ext/target/cypress/psoc64/cypress_psoc64_spec>`
           - DesignStart FPGA on Cloud: Cortex-M33 based platform (SSE-200_AWS platform)
             ``-DTARGET_PLATFORM=SSE-200_AWS``
+          - DISCO_L562QE board (Cortex-M33 STM32L562)
+            ``-DTARGET_PLATFORM=STM_DISCO_L562QE``
+            See :doc:`STM32L5xx platform specifics </platform/ext/target/stm/stm32l5xx/readme>`
+          - NUCLEO_L552ZE_Q (Cortex-M33 STM32L552)
+            ``-DTARGET_PLATFORM=SSTM_NUCLEO_L552ZE_Q``
+            See :doc:`STM32L5xx platform specifics </platform/ext/target/stm/stm32l5xx/readme>`
 
    * - -DCOMPILER=<compiler name>
      - Specifies the compiler toolchain
diff --git a/docs/user_guides/tfm_integration_guide.rst b/docs/user_guides/tfm_integration_guide.rst
index 09e43a0..e4b56d1 100644
--- a/docs/user_guides/tfm_integration_guide.rst
+++ b/docs/user_guides/tfm_integration_guide.rst
@@ -28,6 +28,7 @@
 - Musca-S1 test chip board (Cortex-M33 SSE-200 subsystem)
 - CoreLink SSE-200 Subsystem for MPS3 (AN524)
 - DesignStart FPGA on Cloud: Cortex-M33 based platform (SSE-200_AWS)
+- STM32L5xx: Cortex-M33 based platform (STM32L562 and STM32L552 socs)
 
 The files related to the supported platforms are contained under the
 ``platform`` subfolder. The platform specific files are under
@@ -53,6 +54,9 @@
 More information about the SSE-200_AWS platform can be found in:
 `SSE-200_AWS product page <https://aws.amazon.com/marketplace/pp/ARM-DesignStart-FPGA-on-Cloud-Cortex-M33-based-pla/B082DMMTLW>`__
 
+More information about the STM32L5xx platform can be found in:
+`STM32L5 series product page <https://www.st.com/content/st_com/en/products/microcontrollers-microprocessors/stm32-32-bit-arm-cortex-mcus/stm32-ultra-low-power-mcus/stm32l5-series.html>`__
+
 Generic drivers and startup/scatter files
 =========================================
 The addition of a new platform means the creation of a new subfolder inside
diff --git a/docs/user_guides/tfm_secure_boot.rst b/docs/user_guides/tfm_secure_boot.rst
index 917d018..39e3146 100644
--- a/docs/user_guides/tfm_secure_boot.rst
+++ b/docs/user_guides/tfm_secure_boot.rst
@@ -218,35 +218,39 @@
 there) are supported by the platforms. The table below shows which of these
 modes are supported by which platforms:
 
-+------------------+-----------------+----------------------------------------------------------+
-|                  | Without BL2 [1]_| With BL2 [2]_                                            |
-+==================+=================+===============+==========+=============+=================+
-|                  | XIP             | XIP           | XIP      | XIP         | Not XIP         |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-|                  |                 | Overwrite [3]_| Swap [4]_| No-swap [5]_| RAM loading [6]_|
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| AN521            | Yes             | Yes           | Yes      | Yes         | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| AN519            | Yes             | Yes           | Yes      | Yes         | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| AN539            | Yes             | Yes           | Yes      | Yes         | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| FVP_SSE300_MPS2  | NO              | Yes           | Yes      | Yes         | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| LPC55S69         | No              | No            | No       | No          | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| Musca-A          | No              | No            | No       | No          | Yes             |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| Musca-B1         | Yes             | Yes           | Yes      | Yes         | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| Musca-S1         | Yes             | Yes           | Yes      | Yes         | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| AN524            | Yes             | No            | No       | Yes         | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| PSoC64           | Yes             | No            | No       | No          | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
-| SSE-200_AWS      | Yes             | Yes           | Yes      | Yes         | No              |
-+------------------+-----------------+---------------+----------+-------------+-----------------+
++---------------------+-----------------+----------------------------------------------------------+
+|                     | Without BL2 [1]_| With BL2 [2]_                                            |
++=====================+=================+===============+==========+=============+=================+
+|                     | XIP             | XIP           | XIP      | XIP         | Not XIP         |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+|                     |                 | Overwrite [3]_| Swap [4]_| No-swap [5]_| RAM loading [6]_|
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| AN521               | Yes             | Yes           | Yes      | Yes         | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| AN519               | Yes             | Yes           | Yes      | Yes         | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| AN539               | Yes             | Yes           | Yes      | Yes         | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| FVP_SSE300_MPS2     | NO              | Yes           | Yes      | Yes         | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| LPC55S69            | No              | No            | No       | No          | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| Musca-A             | No              | No            | No       | No          | Yes             |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| Musca-B1            | Yes             | Yes           | Yes      | Yes         | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| Musca-S1            | Yes             | Yes           | Yes      | Yes         | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| AN524               | Yes             | No            | No       | Yes         | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| PSoC64              | Yes             | No            | No       | No          | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| SSE-200_AWS         | Yes             | Yes           | Yes      | Yes         | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| STM_DISCO_L562QE    | No              | Yes           | No       | No          | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
+| STM_NUCLEO_L552ZE_Q | No              | Yes           | No       | No          | No              |
++---------------------+-----------------+---------------+----------+-------------+-----------------+
 
 .. [1] To disable BL2, please turn off the ``BL2`` compiler switch in the
     build configuration file (``bl2/ext/mcuboot/MCUBootConfig.cmake``) or
diff --git a/docs/user_guides/tfm_sw_requirement.rst b/docs/user_guides/tfm_sw_requirement.rst
index d9f0ac8..ca8688e 100644
--- a/docs/user_guides/tfm_sw_requirement.rst
+++ b/docs/user_guides/tfm_sw_requirement.rst
@@ -137,6 +137,14 @@
    `CMSIS release notes <https://github.com/ARM-software/CMSIS_5/releases>`__.
    for guidance.
 
+********************************************
+Tools for configuring and programming boards
+********************************************
+
+For stm32l5xx boards, `STM32_Programmer_CLI  <https://www.st.com/en/development-tools/stm32cubeprog.html>`__ 
+is used to configure security protections and to write the code in internal flash.
+A version is available for Linux and Windows host machine.
+
 **************
 Example setups
 **************
diff --git a/platform/ext/stm.cmake b/platform/ext/stm.cmake
new file mode 100644
index 0000000..42aa597
--- /dev/null
+++ b/platform/ext/stm.cmake
@@ -0,0 +1,17 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2020, STMicroelectronics - All Rights Reserved
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+#This file gathers all target of stm.
+
+set(PLATFORM_DIR ${CMAKE_CURRENT_LIST_DIR})
+
+if(${TARGET_PLATFORM} STREQUAL "STM_DISCO_L562QE")
+	include("${PLATFORM_DIR}/target/stm/stm32l5xx/stm32l562e_dk.cmake")
+elseif(${TARGET_PLATFORM} STREQUAL "STM_NUCLEO_L552ZE_Q")
+	include("${PLATFORM_DIR}/target/stm/stm32l5xx/nucleo_l552ze_q.cmake")
+else()
+	message(FATAL_ERROR "ERROR: Target \"${TARGET_PLATFORM}\" is not supported.")
+endif()
\ No newline at end of file