blob: 206c0674cd0650688d80e707ac12ee6dbb5c9b86 [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
23the subdirectories of the accelerator directory. Currently the only available
24accelerator is the CryptoCell ``cc312``.
25
26A minimal API is exposed to interact with accelerators, the details of this api
27are in ``accelerator/interface/crypto_hw.h``. Implementation of the API is
28inside the subdirectory of the individual accelerator.
29
30To configure a cryptographic accelerator at build time, two cmake options can be
31specified.
32
33- ``CRYPTO_HW_ACCELERATOR``
34 - ``ON`` All possible mbedtls cryptographic operations will be offloaded to
35 the accelerator. This mode is required for
36 ``CRYPTO_HW_ACCELERATOR_OTP_STATE`` to have an effect.
37 - ``OFF`` The cryptographic accelerator will be ignored and software
38 cryptography will be used.
39
40- ``CRYPTO_HW_ACCELERATOR_OTP_STATE``
41 - ``DISABLED`` The HW accelerator will not use any data from its onboard OTP
42 (One Time Programmable) memory.
43 - ``PROVISIONING`` This special mode is used to program cryptographic
44 material into the OTP memory. When the flag is set TF-M will not boot, but
45 will instead program the hardware unique key, the root of trust private key
46 and the attestation private key into the OTP memory.
47 - ``ENABLED`` The HW accelerator will use the previously programmed data as
48 the hardware unique key, the root of trust private key and the attestation
49 private key.
50
51.. Warning::
52
53 Provisioning **can not** be reversed, and data in the OTP memory **can not**
54 be changed once set.
55
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020056cmsis
57=====
58This folder contains core and compiler specific header files imported from the
59``CMSIS_5`` project.
60
61common
62======
Raef Colesa657a9c2019-10-24 14:36:43 +010063
64armclang and gcc
65----------------
66These contain the linker scripts used to configure the memory regions in TF-M
67regions.
68
Jamie Foxc3202282019-12-13 17:12:16 +000069template
70--------
71This directory contains platform-independent dummy implementations of the
72interfaces in ``platform/include``. These implementations can be built directly
73for initial testing of a platform port, or used as a basic template for a real
74implementation for a particular target. They **must not** be used in production
75systems.
76
Raef Colesa8d87df2020-10-30 13:53:42 +000077driver
78======
Gyorgy Szingdb9783c2019-04-17 21:08:48 +020079This folder contains the headers with CMSIS compliant driver definitions that
80that TF-M project expects a target to provide.
81
82target_cfg.h
83------------
84This file is expected to define the following macros respectively.
85
86- ``TFM_DRIVER_STDIO`` - This macro should expand to a structure of type
87 ``ARM_DRIVER_USART``. TFM redirects its standard input and output to this
88 instance of USART.
89- ``NS_DRIVER_STDIO`` - This macro should expand to a structure of type
90 ``ARM_DRIVER_USART``. Non-Secure application redirects its standard input and
91 output to this instance of USART.
92
93target
94======
Raef Colesa8d87df2020-10-30 13:53:42 +000095This folder contains the files for individual target. For a buildable target,
96the directory path from the ``target`` directory to its ``CMakeLists.txt`` file
97is the argument that would be given to ``-DTFM_PLATFORM=``.
98
99The standard directory structure is as follows:
100
101- target
102 - <Vendor name>
103 - common
104 - <buildable target 1>
105 - <buildable target 2>
106 - <buildable target 3>
107
108Each buildable target must contain the cmake files mandated in the section
109below.
110
111The ``common`` directory is not required, but can be used to contain code that
112is used by multiple targets.
113
114There must not be any directories inside the vendor directory that is not either
115the ``common`` directory or a buildable platform, to avoid confusion about what
116directories are a valid ``TFM_PLATFORM``.
117
118Buildable target required cmake files
119-------------------------------------
120
121A buildable target must provide 3 mandatory cmake files. These files must all be
122placed in the root of the buildable target directory.
123
124preload.cmake
125^^^^^^^^^^^^^
126
127This file contains variable definitions that relate to the underlying hardware
128of the target.
129
130- ``TFM_SYSTEM_PROCESSOR``: The processor used by the target. The format is that
131 same as the format used in the ``-mcpu=`` argument of GNUARM or ARMCLANG. The
132 special ``+modifier`` syntax must not be used.
133
134- ``TFM_SYSTEM_ARCHITECTURE``: The architecture used by the target. The format is
135 that same as the format used in the ``-march=`` argument of GNUARM or ARMCLANG.
136 The special ``+modifier`` syntax must not be used.
137
138- ``TFM_SYSTEM_DSP``: Whether the target has the DSP feature of the given
139 ``TFM_SYSTEM_PROCESSOR``
140- ``CRYPTO_HW_ACCELERATOR_TYPE``: The type of cryptographic accelerator the
141 target has, if it has one. This maps exactly to the subdirectories of
142 ``platform/ext/accelerator``
143
144Other than these particular cmake variables, it is permissible for the
145``preload.cmake`` file to contain ``add_definitions`` statements, in order for
146set compile definitions that are global for the hardware. This is commonly used
147to select a particular set of code from a vendor SDK.
148
149It is not permissible to contains code other than the above in a
150``preload.cmake`` file, any general cmake code should be placed in
151``CMakeLists.txt`` and any configuration options should be contained in
152``config.cmake``
153
154config.cmake
155^^^^^^^^^^^^
156
157This file collects platform-specific overrides to the configuration options.
158This should only contain cmake options that are included in
159``config_default.cmake``. These options should be set as ``CACHE`` variables, as
160they are in ``config_default.cmake``.
161
162CMakeLists.txt
163^^^^^^^^^^^^^^
164
165This file should contain all other required cmake code for the platform. This
166primarily consists of the following:
167
168- Adding an include directory to the target ``platform_region_defs``, which
169 contains the headers ``flash_layout.h`` and ``region_defs.h``
170
171- Adding startup and scatter files to the ``tfm_s``, ``tfm_ns`` and ``bl2``
172 targets.
173
174- linking ``CMSIS_5_tfm_ns`` to the correct version of the CMSIS RTX libraries,
175 as defined in ``lib/ext/CMSIS_5/CMakeLists.txt``
176
177- Adding required source files, include directories and compile definitions to
178 the ``platform_s``, ``platform_ns`` and ``platform_bl2`` targets.
179
180preload_ns.cmake
181^^^^^^^^^^^^^^^^
182
183This optional 4th cmake file is required only if the target is utilising
184``TFM_MULTI_CORE_TOPOLOGY``. This file has the same format as ``preload.cmake``,
185but instead details the hardware of the NS core that is **not** running the main
186TF-M secure code.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200187
188Flash layout header file
189------------------------
190Target must provide a header file, called ``flash_layout.h``, which defines the
191information explained in the follow subsections. The defines must be named
192as they are in the subsections.
193
194BL2 bootloader
195^^^^^^^^^^^^^^
196The BL2 bootloader requires the following definitions:
197
198- ``FLASH_BASE_ADDRESS`` - Defines the first valid address in the flash.
199- ``FLASH_AREA_BL2_OFFSET`` - Defines the offset from the flash base address
200 where the BL2 - MCUBOOT area starts.
201- ``FLASH_AREA_BL2_SIZE`` - Defines the size of the BL2 area.
David Vinczebb207982019-08-21 15:13:04 +0200202- ``FLASH_AREA_SCRATCH_OFFSET`` - Defines the offset from the flash base
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200203 address where the scratch area starts, which is used during image swapping.
David Vinczebb207982019-08-21 15:13:04 +0200204- ``FLASH_AREA_SCRATCH_SIZE`` - Defines the size of the scratch area. The
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200205 minimal size must be as the biggest sector size in the flash.
206- ``FLASH_DEV_NAME`` - Specifies the flash device used by BL2.
207
David Vinczebb207982019-08-21 15:13:04 +0200208The BL2 requires further definitions depending on the number of images, the
209meaning of these macros are also slightly different:
210
211- Required definitions in case of 1 image (S and NS images are concatenated
212 and handled together as one binary blob):
213
214 - ``FLASH_AREA_0_OFFSET`` - Defines the offset from the flash base address
215 where the primary image area starts, which hosts the active firmware
216 image.
217 - ``FLASH_AREA_0_SIZE`` - Defines the size of the primary image area.
218 - ``FLASH_AREA_2_OFFSET`` - Defines the offset from the flash base address
219 where the secondary image area starts, which is a placeholder for new
220 firmware images.
221 - ``FLASH_AREA_2_SIZE`` - Defines the size of the secondary image area.
222
223- Required definitions in case of 2 images (S and NS images are handled and
224 updated separately):
225
226 - ``FLASH_AREA_0_OFFSET`` - Defines the offset from the flash base address
227 where the primary image areas start, which host the active firmware
228 images. It is also the offset of the primary (active) secure image area.
229 - ``FLASH_AREA_0_SIZE`` - Defines the size of the primary secure image area.
230 - ``FLASH_AREA_1_OFFSET`` - Defines the offset from the flash base address
231 where the primary (active) non-secure image area starts.
232 - ``FLASH_AREA_1_SIZE`` - Defines the size of the primary non-secure image
233 area.
234 - ``FLASH_AREA_2_OFFSET`` - Defines the offset from the flash base address
235 where the secondary image areas start, which are placeholders for new
236 firmware images. It is also the offset of the secondary secure image area.
237 - ``FLASH_AREA_2_SIZE`` - Defines the size of the secondary secure image
238 area.
239 - ``FLASH_AREA_3_OFFSET`` - Defines the offset from the flash base address
240 where the secondary non-secure image area starts.
241 - ``FLASH_AREA_3_SIZE`` - Defines the size of the secondary non-secure image
242 area.
243
244The table below shows a fraction of the flash layout in case of 2 and 1
245updatable images with the related flash areas that hold the firmware images:
246
247+-----------------------+--------------------+-----------------------+-----------------------------+
248| Image number: 2 | Image number: 1 |
249+=======================+====================+=======================+=============================+
250| **Flash area** | **Content** | **Flash area** | **Content** |
251+-----------------------+--------------------+-----------------------+-----------------------------+
252| FLASH_AREA_0 | | Secure image | FLASH_AREA_0 | | Secure + Non-secure image |
253| | | primary slot | | | primary slot |
254+-----------------------+--------------------+-----------------------+ +
255| FLASH_AREA_1 | | Non-secure image | | |
256| | | primary slot | | |
257+-----------------------+--------------------+-----------------------+-----------------------------+
258| FLASH_AREA_2 | | Secure image | FLASH_AREA_2 | | Secure + Non-secure image |
259| | | secondary slot | | | secondary slot |
260+-----------------------+--------------------+-----------------------+ +
261| FLASH_AREA_3 | | Non-secure image | | |
262| | | secondary slot | | |
263+-----------------------+--------------------+-----------------------+-----------------------------+
264| FLASH_AREA_SCRATCH | Scratch area | FLASH_AREA_SCRATCH | Scratch area |
265+-----------------------+--------------------+-----------------------+-----------------------------+
266
Raef Colesa4952592019-10-01 11:43:18 +0100267- ``IMAGE_EXECUTABLE_RAM_START`` - Defines the start of the region to which
268 images are allowed to be loaded. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is
Tamas Banf4023f32020-09-16 11:02:52 +0100269 configured to be ``RAM_LOAD``.
Raef Colesa4952592019-10-01 11:43:18 +0100270
271- ``IMAGE_EXECUTABLE_RAM_SIZE`` - Defines the size of the region to which images
272 are allowed to be loaded. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is
Tamas Banf4023f32020-09-16 11:02:52 +0100273 configured to be ``RAM_LOAD``.
Raef Colesa4952592019-10-01 11:43:18 +0100274
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200275Assemble tool
276^^^^^^^^^^^^^
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200277The ``assemble.py`` tool is used to concatenate secure and non-secure binary
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200278to a single binary blob. It requires the following definitions:
279
280- ``SECURE_IMAGE_OFFSET`` - Defines the offset from the single binary blob base
281 address, where the secure image starts.
282- ``SECURE_IMAGE_MAX_SIZE`` - Defines the maximum size of the secure image area.
283- ``NON_SECURE_IMAGE_OFFSET`` - Defines the offset from the single binary blob
284 base address, where the non-secure image starts.
285- ``NON_SECURE_IMAGE_MAX_SIZE`` - Defines the maximum size of the non-secure
286 image area.
287
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200288Image tool
289^^^^^^^^^^^^^
290The ``imgtool.py`` tool is used to handle the tasks related to signing the
David Vinczed8fbe0e2019-08-12 15:58:57 +0200291binary. It requires the following definition:
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200292
Raef Colesa4952592019-10-01 11:43:18 +0100293- ``IMAGE_LOAD_ADDRESS`` - Defines the address to where the image is loaded and
294 is executed from. Only used if ``MCUBOOT_UPGRADE_STRATEGY`` is configured to
Tamas Banf4023f32020-09-16 11:02:52 +0100295 be ``RAM_LOAD``.
Sverteczky, Marcell79ae9152019-06-06 15:00:11 +0200296
Kevin Pengc6d74502020-03-04 16:55:37 +0800297Protected Storage (PS) Service definitions
298^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
299The PS service requires the following definitions:
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200300
Kevin Pengc6d74502020-03-04 16:55:37 +0800301- ``PS_FLASH_AREA_ADDR`` - Defines the flash address where the protected storage
Jamie Foxdd3de952019-11-25 17:45:40 +0000302 area starts.
Kevin Pengc6d74502020-03-04 16:55:37 +0800303- ``PS_FLASH_AREA_SIZE`` - Defines the size of the dedicated flash area
304 for protected storage in bytes.
305- ``PS_SECTOR_SIZE`` - Defines the size of the external flash sectors (the
Jamie Foxdd3de952019-11-25 17:45:40 +0000306 smallest erasable unit) in bytes.
Kevin Pengc6d74502020-03-04 16:55:37 +0800307- ``PS_SECTORS_PER_BLOCK`` - Defines the number of contiguous PS_SECTOR_SIZE
Jamie Foxdd3de952019-11-25 17:45:40 +0000308 to form a logical block in the filesystem.
Kevin Pengc6d74502020-03-04 16:55:37 +0800309- ``PS_FLASH_DEV_NAME`` - Specifies the flash device used by PS to store the
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200310 data.
Kevin Pengc6d74502020-03-04 16:55:37 +0800311- ``PS_FLASH_PROGRAM_UNIT`` - Defines the smallest flash programmable unit in
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200312 bytes.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200313
314.. Note::
315
316 The sectors must be consecutive.
Chris Brandc47d7102020-02-20 11:12:18 -0800317 The platform may implement ``tfm_hal_ps_fs_info()`` as an alternative
318 to defining ``PS_FLASH_AREA_ADDR`` and ``PS_FLASH_AREA_SIZE``.
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200319
TudorCretuba8a3fa2019-07-22 10:05:12 +0100320Internal Trusted Storage (ITS) Service definitions
321^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
322The ITS service requires the following definitions:
323
Jamie Foxdd3de952019-11-25 17:45:40 +0000324- ``ITS_FLASH_AREA_ADDR`` - Defines the flash address where the internal trusted
325 storage area starts.
326- ``ITS_FLASH_AREA_SIZE`` - Defines the size of the dedicated flash area for
327 internal trusted storage in bytes.
328- ``ITS_SECTOR_SIZE`` - Defines the size of the internal flash sectors (the
329 smallest erasable unit) in bytes.
David Hu74977d22019-10-22 10:26:03 +0800330- ``ITS_SECTORS_PER_BLOCK`` - Defines the number of contiguous ITS_SECTOR_SIZE
Jamie Foxdd3de952019-11-25 17:45:40 +0000331 to form a logical block in the filesystem.
TudorCretuba8a3fa2019-07-22 10:05:12 +0100332- ``ITS_FLASH_DEV_NAME`` - Specifies the internal flash device used by ITS to
333 store the data.
334- ``ITS_FLASH_PROGRAM_UNIT`` - Defines the smallest flash programmable unit in
335 bytes.
TudorCretuba8a3fa2019-07-22 10:05:12 +0100336
337.. Note::
338
339 The sectors must be consecutive.
Chris Brandc47d7102020-02-20 11:12:18 -0800340 The platform may implement ``tfm_hal_its_fs_info()`` as an alternative
341 to defining ``ITS_FLASH_AREA_ADDR`` and ``ITS_FLASH_AREA_SIZE``.
TudorCretuba8a3fa2019-07-22 10:05:12 +0100342
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200343***************************************
344Expose target support for HW components
345***************************************
346Services may require HW components to be supported by the target to enable some
Kevin Pengc6d74502020-03-04 16:55:37 +0800347features (e.g. PS service with rollback protection, etc). The following
Gyorgy Szingdb9783c2019-04-17 21:08:48 +0200348definitions need to be set in the .cmake file if the target has the following
349HW components:
350
351- ``TARGET_NV_COUNTERS_ENABLE`` - Specifies that the target has non-volatile
352 (NV) counters.
353
354--------------
355
Jamie Foxdd3de952019-11-25 17:45:40 +0000356*Copyright (c) 2017-2020, Arm Limited. All rights reserved.*
Chris Brandc47d7102020-02-20 11:12:18 -0800357*Copyright (c) 2020, Cypress Semiconductor Corporation. All rights reserved.*