blob: da37c460df78bc3ccbe52caf490212a30ab4424b [file] [log] [blame]
Gyorgy Szingdb9783c2019-04-17 21:08:48 +02001###################################
2Details for the platform/ext folder
3###################################
4This folder has code that has been imported from other projects. This means the
5files in this folder and subfolders have Apache 2.0 license which is different
6to BSD 3.0 license applied to the parent TF-M project.
7
8.. Note::
9 This folder is strictly Apache 2.0 with the exception of cmake files.
10 Maintainers should be consulted if this needs to be revisited.
11
12***********
13Sub-folders
14***********
15
Raef Colesa8d87df2020-10-30 13:53:42 +000016accelerator
17===========
18This folder contains cmake and code files to interact cryptographic
19accelerators.
20
21In order to use a cryptographic accelerator, a platform must set
22``CRYPTO_HW_ACCELERATOR_TYPE`` in preload.cmake. This option maps directly to
Michel Jaouen1ea82c02021-01-25 15:18:21 +010023the subdirectories of the accelerator directory. Currently available
24accelerators are : the CryptoCell ``cc312``, the STMicroelectronics accelerator
25``stm`` .
Raef Colesa8d87df2020-10-30 13:53:42 +000026
27A minimal API is exposed to interact with accelerators, the details of this api
28are in ``accelerator/interface/crypto_hw.h``. Implementation of the API is
29inside the subdirectory of the individual accelerator.
30
31To configure a cryptographic accelerator at build time, two cmake options can be
32specified.
33
34- ``CRYPTO_HW_ACCELERATOR``
35 - ``ON`` All possible mbedtls cryptographic operations will be offloaded to
Raef Colesbee41052021-06-14 09:37:31 +010036 the accelerator.
Raef Colesa8d87df2020-10-30 13:53:42 +000037 - ``OFF`` The cryptographic accelerator will be ignored and software
38 cryptography will be used.
39
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020040cmsis
41=====
42This folder contains core and compiler specific header files imported from the
43``CMSIS_5`` project.
44
45common
46======
Raef Colesa657a9c2019-10-24 14:36:43 +010047
48armclang and gcc
49----------------
50These contain the linker scripts used to configure the memory regions in TF-M
51regions.
52
Jamie Foxc3202282019-12-13 17:12:16 +000053template
54--------
55This directory contains platform-independent dummy implementations of the
56interfaces in ``platform/include``. These implementations can be built directly
57for initial testing of a platform port, or used as a basic template for a real
58implementation for a particular target. They **must not** be used in production
59systems.
60
Raef Colesa8d87df2020-10-30 13:53:42 +000061driver
62======
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020063This folder contains the headers with CMSIS compliant driver definitions that
64that TF-M project expects a target to provide.
65
66target_cfg.h
67------------
68This file is expected to define the following macros respectively.
69
70- ``TFM_DRIVER_STDIO`` - This macro should expand to a structure of type
71 ``ARM_DRIVER_USART``. TFM redirects its standard input and output to this
72 instance of USART.
73- ``NS_DRIVER_STDIO`` - This macro should expand to a structure of type
74 ``ARM_DRIVER_USART``. Non-Secure application redirects its standard input and
75 output to this instance of USART.
76
77target
78======
Raef Colesa8d87df2020-10-30 13:53:42 +000079This folder contains the files for individual target. For a buildable target,
80the directory path from the ``target`` directory to its ``CMakeLists.txt`` file
81is the argument that would be given to ``-DTFM_PLATFORM=``.
82
83The standard directory structure is as follows:
84
85- target
86 - <Vendor name>
87 - common
88 - <buildable target 1>
89 - <buildable target 2>
90 - <buildable target 3>
91
92Each buildable target must contain the cmake files mandated in the section
93below.
94
95The ``common`` directory is not required, but can be used to contain code that
96is used by multiple targets.
97
98There must not be any directories inside the vendor directory that is not either
99the ``common`` directory or a buildable platform, to avoid confusion about what
100directories are a valid ``TFM_PLATFORM``.
101
102Buildable target required cmake files
103-------------------------------------
104
105A buildable target must provide 3 mandatory cmake files. These files must all be
106placed in the root of the buildable target directory.
107
108preload.cmake
109^^^^^^^^^^^^^
110
111This file contains variable definitions that relate to the underlying hardware
112of the target.
113
114- ``TFM_SYSTEM_PROCESSOR``: The processor used by the target. The format is that
115 same as the format used in the ``-mcpu=`` argument of GNUARM or ARMCLANG. The
116 special ``+modifier`` syntax must not be used.
117
118- ``TFM_SYSTEM_ARCHITECTURE``: The architecture used by the target. The format is
119 that same as the format used in the ``-march=`` argument of GNUARM or ARMCLANG.
120 The special ``+modifier`` syntax must not be used.
121
122- ``TFM_SYSTEM_DSP``: Whether the target has the DSP feature of the given
123 ``TFM_SYSTEM_PROCESSOR``
124- ``CRYPTO_HW_ACCELERATOR_TYPE``: The type of cryptographic accelerator the
125 target has, if it has one. This maps exactly to the subdirectories of
126 ``platform/ext/accelerator``
127
128Other than these particular cmake variables, it is permissible for the
129``preload.cmake`` file to contain ``add_definitions`` statements, in order for
130set compile definitions that are global for the hardware. This is commonly used
131to select a particular set of code from a vendor SDK.
132
133It is not permissible to contains code other than the above in a
134``preload.cmake`` file, any general cmake code should be placed in
135``CMakeLists.txt`` and any configuration options should be contained in
136``config.cmake``
137
138config.cmake
139^^^^^^^^^^^^
140
141This file collects platform-specific overrides to the configuration options.
142This should only contain cmake options that are included in
143``config_default.cmake``. These options should be set as ``CACHE`` variables, as
144they are in ``config_default.cmake``.
145
146CMakeLists.txt
147^^^^^^^^^^^^^^
148
149This file should contain all other required cmake code for the platform. This
150primarily consists of the following:
151
152- Adding an include directory to the target ``platform_region_defs``, which
153 contains the headers ``flash_layout.h`` and ``region_defs.h``
154
155- Adding startup and scatter files to the ``tfm_s``, ``tfm_ns`` and ``bl2``
156 targets.
157
158- linking ``CMSIS_5_tfm_ns`` to the correct version of the CMSIS RTX libraries,
159 as defined in ``lib/ext/CMSIS_5/CMakeLists.txt``
160
161- Adding required source files, include directories and compile definitions to
162 the ``platform_s``, ``platform_ns`` and ``platform_bl2`` targets.
163
164preload_ns.cmake
165^^^^^^^^^^^^^^^^
166
Chris Brandd0790332022-05-20 13:36:30 -0700167This optional cmake file is required only if the target runs the NSPE on a
168core that requires different compiler options than the SPE core. This file has
169the same format as ``preload.cmake``, but instead details the hardware of the
170NS core that is **not** running the main TF-M secure code.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200171
172Flash layout header file
173------------------------
174Target must provide a header file, called ``flash_layout.h``, which defines the
175information explained in the follow subsections. The defines must be named
176as they are in the subsections.
177
178BL2 bootloader
179^^^^^^^^^^^^^^
180The BL2 bootloader requires the following definitions:
181
182- ``FLASH_BASE_ADDRESS`` - Defines the first valid address in the flash.
183- ``FLASH_AREA_BL2_OFFSET`` - Defines the offset from the flash base address
184 where the BL2 - MCUBOOT area starts.
185- ``FLASH_AREA_BL2_SIZE`` - Defines the size of the BL2 area.
David Vinczebb207982019-08-21 15:13:04 +0200186- ``FLASH_AREA_SCRATCH_OFFSET`` - Defines the offset from the flash base
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200187 address where the scratch area starts, which is used during image swapping.
David Vinczebb207982019-08-21 15:13:04 +0200188- ``FLASH_AREA_SCRATCH_SIZE`` - Defines the size of the scratch area. The
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200189 minimal size must be as the biggest sector size in the flash.
190- ``FLASH_DEV_NAME`` - Specifies the flash device used by BL2.
191
David Vinczebb207982019-08-21 15:13:04 +0200192The BL2 requires further definitions depending on the number of images, the
193meaning of these macros are also slightly different:
194
195- Required definitions in case of 1 image (S and NS images are concatenated
196 and handled together as one binary blob):
197
198 - ``FLASH_AREA_0_OFFSET`` - Defines the offset from the flash base address
199 where the primary image area starts, which hosts the active firmware
200 image.
201 - ``FLASH_AREA_0_SIZE`` - Defines the size of the primary image area.
202 - ``FLASH_AREA_2_OFFSET`` - Defines the offset from the flash base address
203 where the secondary image area starts, which is a placeholder for new
204 firmware images.
205 - ``FLASH_AREA_2_SIZE`` - Defines the size of the secondary image area.
206
207- Required definitions in case of 2 images (S and NS images are handled and
208 updated separately):
209
210 - ``FLASH_AREA_0_OFFSET`` - Defines the offset from the flash base address
211 where the primary image areas start, which host the active firmware
212 images. It is also the offset of the primary (active) secure image area.
213 - ``FLASH_AREA_0_SIZE`` - Defines the size of the primary secure image area.
214 - ``FLASH_AREA_1_OFFSET`` - Defines the offset from the flash base address
215 where the primary (active) non-secure image area starts.
216 - ``FLASH_AREA_1_SIZE`` - Defines the size of the primary non-secure image
217 area.
218 - ``FLASH_AREA_2_OFFSET`` - Defines the offset from the flash base address
219 where the secondary image areas start, which are placeholders for new
220 firmware images. It is also the offset of the secondary secure image area.
221 - ``FLASH_AREA_2_SIZE`` - Defines the size of the secondary secure image
222 area.
223 - ``FLASH_AREA_3_OFFSET`` - Defines the offset from the flash base address
224 where the secondary non-secure image area starts.
225 - ``FLASH_AREA_3_SIZE`` - Defines the size of the secondary non-secure image
226 area.
227
228The table below shows a fraction of the flash layout in case of 2 and 1
229updatable images with the related flash areas that hold the firmware images:
230
231+-----------------------+--------------------+-----------------------+-----------------------------+
232| Image number: 2 | Image number: 1 |
233+=======================+====================+=======================+=============================+
234| **Flash area** | **Content** | **Flash area** | **Content** |
235+-----------------------+--------------------+-----------------------+-----------------------------+
236| FLASH_AREA_0 | | Secure image | FLASH_AREA_0 | | Secure + Non-secure image |
237| | | primary slot | | | primary slot |
238+-----------------------+--------------------+-----------------------+ +
239| FLASH_AREA_1 | | Non-secure image | | |
240| | | primary slot | | |
241+-----------------------+--------------------+-----------------------+-----------------------------+
242| FLASH_AREA_2 | | Secure image | FLASH_AREA_2 | | Secure + Non-secure image |
243| | | secondary slot | | | secondary slot |
244+-----------------------+--------------------+-----------------------+ +
245| FLASH_AREA_3 | | Non-secure image | | |
246| | | secondary slot | | |
247+-----------------------+--------------------+-----------------------+-----------------------------+
248| FLASH_AREA_SCRATCH | Scratch area | FLASH_AREA_SCRATCH | Scratch area |
249+-----------------------+--------------------+-----------------------+-----------------------------+
250
Raef Colesa4952592019-10-01 11:43:18 +0100251- ``IMAGE_EXECUTABLE_RAM_START`` - Defines the start of the region to which
252 images are allowed to be loaded. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is
Tamas Banf4023f32020-09-16 11:02:52 +0100253 configured to be ``RAM_LOAD``.
Raef Colesa4952592019-10-01 11:43:18 +0100254
255- ``IMAGE_EXECUTABLE_RAM_SIZE`` - Defines the size of the region to which images
256 are allowed to be loaded. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is
Tamas Banf4023f32020-09-16 11:02:52 +0100257 configured to be ``RAM_LOAD``.
Raef Colesa4952592019-10-01 11:43:18 +0100258
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200259Assemble tool
260^^^^^^^^^^^^^
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200261The ``assemble.py`` tool is used to concatenate secure and non-secure binary
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200262to a single binary blob. It requires the following definitions:
263
264- ``SECURE_IMAGE_OFFSET`` - Defines the offset from the single binary blob base
265 address, where the secure image starts.
266- ``SECURE_IMAGE_MAX_SIZE`` - Defines the maximum size of the secure image area.
267- ``NON_SECURE_IMAGE_OFFSET`` - Defines the offset from the single binary blob
268 base address, where the non-secure image starts.
269- ``NON_SECURE_IMAGE_MAX_SIZE`` - Defines the maximum size of the non-secure
270 image area.
271
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200272Image tool
273^^^^^^^^^^^^^
274The ``imgtool.py`` tool is used to handle the tasks related to signing the
David Vinczed8fbe0e2019-08-12 15:58:57 +0200275binary. It requires the following definition:
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200276
Jamie Fox957fb612022-01-17 17:58:41 +0000277- ``S_IMAGE_LOAD_ADDRESS`` - Defines the address to where the Secure (or
278 combined Secure and Non-secure) image is loaded and is executed from. Only
279 used if ``MCUBOOT_UPGRADE_STRATEGY`` is configured to be ``RAM_LOAD``.
280
281- ``NS_IMAGE_LOAD_ADDRESS`` - Defines the address to where the Non-secure image
282 is loaded and is executed from. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is
283 configured to be ``RAM_LOAD`` and ``MCUBOOT_IMAGE_NUMBER`` is greater than 1.
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200284
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200285***************************************
286Expose target support for HW components
287***************************************
288Services may require HW components to be supported by the target to enable some
Kevin Pengc6d74502020-03-04 16:55:37 +0800289features (e.g. PS service with rollback protection, etc). The following
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200290definitions need to be set in the .cmake file if the target has the following
291HW components:
292
293- ``TARGET_NV_COUNTERS_ENABLE`` - Specifies that the target has non-volatile
294 (NV) counters.
295
296--------------
297
Jamie Fox957fb612022-01-17 17:58:41 +0000298*Copyright (c) 2017-2022, Arm Limited. All rights reserved.*
Chris Brandd0790332022-05-20 13:36:30 -0700299*Copyright (c) 2020-2022 Cypress Semiconductor Corporation (an Infineon company)
300or an affiliate of Cypress Semiconductor Corporation. All rights reserved.*