blob: 55f13cfb61ce2059bc24fd4e908c4fb4ab345278 [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
36 the accelerator. This mode is required for
37 ``CRYPTO_HW_ACCELERATOR_OTP_STATE`` to have an effect.
38 - ``OFF`` The cryptographic accelerator will be ignored and software
39 cryptography will be used.
40
41- ``CRYPTO_HW_ACCELERATOR_OTP_STATE``
42 - ``DISABLED`` The HW accelerator will not use any data from its onboard OTP
43 (One Time Programmable) memory.
44 - ``PROVISIONING`` This special mode is used to program cryptographic
45 material into the OTP memory. When the flag is set TF-M will not boot, but
46 will instead program the hardware unique key, the root of trust private key
47 and the attestation private key into the OTP memory.
48 - ``ENABLED`` The HW accelerator will use the previously programmed data as
49 the hardware unique key, the root of trust private key and the attestation
50 private key.
51
52.. Warning::
53
54 Provisioning **can not** be reversed, and data in the OTP memory **can not**
55 be changed once set.
56
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020057cmsis
58=====
59This folder contains core and compiler specific header files imported from the
60``CMSIS_5`` project.
61
62common
63======
Raef Colesa657a9c2019-10-24 14:36:43 +010064
65armclang and gcc
66----------------
67These contain the linker scripts used to configure the memory regions in TF-M
68regions.
69
Jamie Foxc3202282019-12-13 17:12:16 +000070template
71--------
72This directory contains platform-independent dummy implementations of the
73interfaces in ``platform/include``. These implementations can be built directly
74for initial testing of a platform port, or used as a basic template for a real
75implementation for a particular target. They **must not** be used in production
76systems.
77
Raef Colesa8d87df2020-10-30 13:53:42 +000078driver
79======
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020080This folder contains the headers with CMSIS compliant driver definitions that
81that TF-M project expects a target to provide.
82
83target_cfg.h
84------------
85This file is expected to define the following macros respectively.
86
87- ``TFM_DRIVER_STDIO`` - This macro should expand to a structure of type
88 ``ARM_DRIVER_USART``. TFM redirects its standard input and output to this
89 instance of USART.
90- ``NS_DRIVER_STDIO`` - This macro should expand to a structure of type
91 ``ARM_DRIVER_USART``. Non-Secure application redirects its standard input and
92 output to this instance of USART.
93
94target
95======
Raef Colesa8d87df2020-10-30 13:53:42 +000096This folder contains the files for individual target. For a buildable target,
97the directory path from the ``target`` directory to its ``CMakeLists.txt`` file
98is the argument that would be given to ``-DTFM_PLATFORM=``.
99
100The standard directory structure is as follows:
101
102- target
103 - <Vendor name>
104 - common
105 - <buildable target 1>
106 - <buildable target 2>
107 - <buildable target 3>
108
109Each buildable target must contain the cmake files mandated in the section
110below.
111
112The ``common`` directory is not required, but can be used to contain code that
113is used by multiple targets.
114
115There must not be any directories inside the vendor directory that is not either
116the ``common`` directory or a buildable platform, to avoid confusion about what
117directories are a valid ``TFM_PLATFORM``.
118
119Buildable target required cmake files
120-------------------------------------
121
122A buildable target must provide 3 mandatory cmake files. These files must all be
123placed in the root of the buildable target directory.
124
125preload.cmake
126^^^^^^^^^^^^^
127
128This file contains variable definitions that relate to the underlying hardware
129of the target.
130
131- ``TFM_SYSTEM_PROCESSOR``: The processor used by the target. The format is that
132 same as the format used in the ``-mcpu=`` argument of GNUARM or ARMCLANG. The
133 special ``+modifier`` syntax must not be used.
134
135- ``TFM_SYSTEM_ARCHITECTURE``: The architecture used by the target. The format is
136 that same as the format used in the ``-march=`` argument of GNUARM or ARMCLANG.
137 The special ``+modifier`` syntax must not be used.
138
139- ``TFM_SYSTEM_DSP``: Whether the target has the DSP feature of the given
140 ``TFM_SYSTEM_PROCESSOR``
141- ``CRYPTO_HW_ACCELERATOR_TYPE``: The type of cryptographic accelerator the
142 target has, if it has one. This maps exactly to the subdirectories of
143 ``platform/ext/accelerator``
144
145Other than these particular cmake variables, it is permissible for the
146``preload.cmake`` file to contain ``add_definitions`` statements, in order for
147set compile definitions that are global for the hardware. This is commonly used
148to select a particular set of code from a vendor SDK.
149
150It is not permissible to contains code other than the above in a
151``preload.cmake`` file, any general cmake code should be placed in
152``CMakeLists.txt`` and any configuration options should be contained in
153``config.cmake``
154
155config.cmake
156^^^^^^^^^^^^
157
158This file collects platform-specific overrides to the configuration options.
159This should only contain cmake options that are included in
160``config_default.cmake``. These options should be set as ``CACHE`` variables, as
161they are in ``config_default.cmake``.
162
163CMakeLists.txt
164^^^^^^^^^^^^^^
165
166This file should contain all other required cmake code for the platform. This
167primarily consists of the following:
168
169- Adding an include directory to the target ``platform_region_defs``, which
170 contains the headers ``flash_layout.h`` and ``region_defs.h``
171
172- Adding startup and scatter files to the ``tfm_s``, ``tfm_ns`` and ``bl2``
173 targets.
174
175- linking ``CMSIS_5_tfm_ns`` to the correct version of the CMSIS RTX libraries,
176 as defined in ``lib/ext/CMSIS_5/CMakeLists.txt``
177
178- Adding required source files, include directories and compile definitions to
179 the ``platform_s``, ``platform_ns`` and ``platform_bl2`` targets.
180
181preload_ns.cmake
182^^^^^^^^^^^^^^^^
183
184This optional 4th cmake file is required only if the target is utilising
185``TFM_MULTI_CORE_TOPOLOGY``. This file has the same format as ``preload.cmake``,
186but instead details the hardware of the NS core that is **not** running the main
187TF-M secure code.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200188
189Flash layout header file
190------------------------
191Target must provide a header file, called ``flash_layout.h``, which defines the
192information explained in the follow subsections. The defines must be named
193as they are in the subsections.
194
195BL2 bootloader
196^^^^^^^^^^^^^^
197The BL2 bootloader requires the following definitions:
198
199- ``FLASH_BASE_ADDRESS`` - Defines the first valid address in the flash.
200- ``FLASH_AREA_BL2_OFFSET`` - Defines the offset from the flash base address
201 where the BL2 - MCUBOOT area starts.
202- ``FLASH_AREA_BL2_SIZE`` - Defines the size of the BL2 area.
David Vinczebb207982019-08-21 15:13:04 +0200203- ``FLASH_AREA_SCRATCH_OFFSET`` - Defines the offset from the flash base
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200204 address where the scratch area starts, which is used during image swapping.
David Vinczebb207982019-08-21 15:13:04 +0200205- ``FLASH_AREA_SCRATCH_SIZE`` - Defines the size of the scratch area. The
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200206 minimal size must be as the biggest sector size in the flash.
207- ``FLASH_DEV_NAME`` - Specifies the flash device used by BL2.
208
David Vinczebb207982019-08-21 15:13:04 +0200209The BL2 requires further definitions depending on the number of images, the
210meaning of these macros are also slightly different:
211
212- Required definitions in case of 1 image (S and NS images are concatenated
213 and handled together as one binary blob):
214
215 - ``FLASH_AREA_0_OFFSET`` - Defines the offset from the flash base address
216 where the primary image area starts, which hosts the active firmware
217 image.
218 - ``FLASH_AREA_0_SIZE`` - Defines the size of the primary image area.
219 - ``FLASH_AREA_2_OFFSET`` - Defines the offset from the flash base address
220 where the secondary image area starts, which is a placeholder for new
221 firmware images.
222 - ``FLASH_AREA_2_SIZE`` - Defines the size of the secondary image area.
223
224- Required definitions in case of 2 images (S and NS images are handled and
225 updated separately):
226
227 - ``FLASH_AREA_0_OFFSET`` - Defines the offset from the flash base address
228 where the primary image areas start, which host the active firmware
229 images. It is also the offset of the primary (active) secure image area.
230 - ``FLASH_AREA_0_SIZE`` - Defines the size of the primary secure image area.
231 - ``FLASH_AREA_1_OFFSET`` - Defines the offset from the flash base address
232 where the primary (active) non-secure image area starts.
233 - ``FLASH_AREA_1_SIZE`` - Defines the size of the primary non-secure image
234 area.
235 - ``FLASH_AREA_2_OFFSET`` - Defines the offset from the flash base address
236 where the secondary image areas start, which are placeholders for new
237 firmware images. It is also the offset of the secondary secure image area.
238 - ``FLASH_AREA_2_SIZE`` - Defines the size of the secondary secure image
239 area.
240 - ``FLASH_AREA_3_OFFSET`` - Defines the offset from the flash base address
241 where the secondary non-secure image area starts.
242 - ``FLASH_AREA_3_SIZE`` - Defines the size of the secondary non-secure image
243 area.
244
245The table below shows a fraction of the flash layout in case of 2 and 1
246updatable images with the related flash areas that hold the firmware images:
247
248+-----------------------+--------------------+-----------------------+-----------------------------+
249| Image number: 2 | Image number: 1 |
250+=======================+====================+=======================+=============================+
251| **Flash area** | **Content** | **Flash area** | **Content** |
252+-----------------------+--------------------+-----------------------+-----------------------------+
253| FLASH_AREA_0 | | Secure image | FLASH_AREA_0 | | Secure + Non-secure image |
254| | | primary slot | | | primary slot |
255+-----------------------+--------------------+-----------------------+ +
256| FLASH_AREA_1 | | Non-secure image | | |
257| | | primary slot | | |
258+-----------------------+--------------------+-----------------------+-----------------------------+
259| FLASH_AREA_2 | | Secure image | FLASH_AREA_2 | | Secure + Non-secure image |
260| | | secondary slot | | | secondary slot |
261+-----------------------+--------------------+-----------------------+ +
262| FLASH_AREA_3 | | Non-secure image | | |
263| | | secondary slot | | |
264+-----------------------+--------------------+-----------------------+-----------------------------+
265| FLASH_AREA_SCRATCH | Scratch area | FLASH_AREA_SCRATCH | Scratch area |
266+-----------------------+--------------------+-----------------------+-----------------------------+
267
Raef Colesa4952592019-10-01 11:43:18 +0100268- ``IMAGE_EXECUTABLE_RAM_START`` - Defines the start of the region to which
269 images are allowed to be loaded. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is
Tamas Banf4023f32020-09-16 11:02:52 +0100270 configured to be ``RAM_LOAD``.
Raef Colesa4952592019-10-01 11:43:18 +0100271
272- ``IMAGE_EXECUTABLE_RAM_SIZE`` - Defines the size of the region to which images
273 are allowed to be loaded. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is
Tamas Banf4023f32020-09-16 11:02:52 +0100274 configured to be ``RAM_LOAD``.
Raef Colesa4952592019-10-01 11:43:18 +0100275
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200276Assemble tool
277^^^^^^^^^^^^^
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200278The ``assemble.py`` tool is used to concatenate secure and non-secure binary
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200279to a single binary blob. It requires the following definitions:
280
281- ``SECURE_IMAGE_OFFSET`` - Defines the offset from the single binary blob base
282 address, where the secure image starts.
283- ``SECURE_IMAGE_MAX_SIZE`` - Defines the maximum size of the secure image area.
284- ``NON_SECURE_IMAGE_OFFSET`` - Defines the offset from the single binary blob
285 base address, where the non-secure image starts.
286- ``NON_SECURE_IMAGE_MAX_SIZE`` - Defines the maximum size of the non-secure
287 image area.
288
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200289Image tool
290^^^^^^^^^^^^^
291The ``imgtool.py`` tool is used to handle the tasks related to signing the
David Vinczed8fbe0e2019-08-12 15:58:57 +0200292binary. It requires the following definition:
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200293
Raef Colesa4952592019-10-01 11:43:18 +0100294- ``IMAGE_LOAD_ADDRESS`` - Defines the address to where the image is loaded and
295 is executed from. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is configured to
Tamas Banf4023f32020-09-16 11:02:52 +0100296 be ``RAM_LOAD``.
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200297
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200298***************************************
299Expose target support for HW components
300***************************************
301Services may require HW components to be supported by the target to enable some
Kevin Pengc6d74502020-03-04 16:55:37 +0800302features (e.g. PS service with rollback protection, etc). The following
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200303definitions need to be set in the .cmake file if the target has the following
304HW components:
305
306- ``TARGET_NV_COUNTERS_ENABLE`` - Specifies that the target has non-volatile
307 (NV) counters.
308
309--------------
310
Jamie Foxa7e73b72021-01-15 13:39:31 +0000311*Copyright (c) 2017-2021, Arm Limited. All rights reserved.*
Chris Brandc47d7102020-02-20 11:12:18 -0800312*Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.*