Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 1 | ################################### |
| 2 | Details for the platform/ext folder |
| 3 | ################################### |
| 4 | This folder has code that has been imported from other projects. This means the |
| 5 | files in this folder and subfolders have Apache 2.0 license which is different |
| 6 | to 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 | *********** |
| 13 | Sub-folders |
| 14 | *********** |
| 15 | |
Raef Coles | a8d87df | 2020-10-30 13:53:42 +0000 | [diff] [blame] | 16 | accelerator |
| 17 | =========== |
| 18 | This folder contains cmake and code files to interact cryptographic |
| 19 | accelerators. |
| 20 | |
| 21 | In order to use a cryptographic accelerator, a platform must set |
| 22 | ``CRYPTO_HW_ACCELERATOR_TYPE`` in preload.cmake. This option maps directly to |
Michel Jaouen | 1ea82c0 | 2021-01-25 15:18:21 +0100 | [diff] [blame] | 23 | the subdirectories of the accelerator directory. Currently available |
| 24 | accelerators are : the CryptoCell ``cc312``, the STMicroelectronics accelerator |
| 25 | ``stm`` . |
Raef Coles | a8d87df | 2020-10-30 13:53:42 +0000 | [diff] [blame] | 26 | |
| 27 | A minimal API is exposed to interact with accelerators, the details of this api |
| 28 | are in ``accelerator/interface/crypto_hw.h``. Implementation of the API is |
| 29 | inside the subdirectory of the individual accelerator. |
| 30 | |
| 31 | To configure a cryptographic accelerator at build time, two cmake options can be |
| 32 | specified. |
| 33 | |
| 34 | - ``CRYPTO_HW_ACCELERATOR`` |
| 35 | - ``ON`` All possible mbedtls cryptographic operations will be offloaded to |
Raef Coles | bee4105 | 2021-06-14 09:37:31 +0100 | [diff] [blame] | 36 | the accelerator. |
Raef Coles | a8d87df | 2020-10-30 13:53:42 +0000 | [diff] [blame] | 37 | - ``OFF`` The cryptographic accelerator will be ignored and software |
| 38 | cryptography will be used. |
| 39 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 40 | cmsis |
| 41 | ===== |
| 42 | This folder contains core and compiler specific header files imported from the |
| 43 | ``CMSIS_5`` project. |
| 44 | |
| 45 | common |
| 46 | ====== |
Raef Coles | a657a9c | 2019-10-24 14:36:43 +0100 | [diff] [blame] | 47 | |
| 48 | armclang and gcc |
| 49 | ---------------- |
| 50 | These contain the linker scripts used to configure the memory regions in TF-M |
| 51 | regions. |
| 52 | |
Jamie Fox | c320228 | 2019-12-13 17:12:16 +0000 | [diff] [blame] | 53 | template |
| 54 | -------- |
| 55 | This directory contains platform-independent dummy implementations of the |
| 56 | interfaces in ``platform/include``. These implementations can be built directly |
| 57 | for initial testing of a platform port, or used as a basic template for a real |
| 58 | implementation for a particular target. They **must not** be used in production |
| 59 | systems. |
| 60 | |
Raef Coles | a8d87df | 2020-10-30 13:53:42 +0000 | [diff] [blame] | 61 | driver |
| 62 | ====== |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 63 | This folder contains the headers with CMSIS compliant driver definitions that |
| 64 | that TF-M project expects a target to provide. |
| 65 | |
| 66 | target_cfg.h |
| 67 | ------------ |
| 68 | This 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 | |
| 77 | target |
| 78 | ====== |
Raef Coles | a8d87df | 2020-10-30 13:53:42 +0000 | [diff] [blame] | 79 | This folder contains the files for individual target. For a buildable target, |
| 80 | the directory path from the ``target`` directory to its ``CMakeLists.txt`` file |
| 81 | is the argument that would be given to ``-DTFM_PLATFORM=``. |
| 82 | |
| 83 | The 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 | |
| 92 | Each buildable target must contain the cmake files mandated in the section |
| 93 | below. |
| 94 | |
| 95 | The ``common`` directory is not required, but can be used to contain code that |
| 96 | is used by multiple targets. |
| 97 | |
| 98 | There must not be any directories inside the vendor directory that is not either |
| 99 | the ``common`` directory or a buildable platform, to avoid confusion about what |
| 100 | directories are a valid ``TFM_PLATFORM``. |
| 101 | |
| 102 | Buildable target required cmake files |
| 103 | ------------------------------------- |
| 104 | |
| 105 | A buildable target must provide 3 mandatory cmake files. These files must all be |
| 106 | placed in the root of the buildable target directory. |
| 107 | |
| 108 | preload.cmake |
| 109 | ^^^^^^^^^^^^^ |
| 110 | |
| 111 | This file contains variable definitions that relate to the underlying hardware |
| 112 | of 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 | |
| 128 | Other than these particular cmake variables, it is permissible for the |
| 129 | ``preload.cmake`` file to contain ``add_definitions`` statements, in order for |
| 130 | set compile definitions that are global for the hardware. This is commonly used |
| 131 | to select a particular set of code from a vendor SDK. |
| 132 | |
| 133 | It 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 | |
| 138 | config.cmake |
| 139 | ^^^^^^^^^^^^ |
| 140 | |
| 141 | This file collects platform-specific overrides to the configuration options. |
| 142 | This should only contain cmake options that are included in |
| 143 | ``config_default.cmake``. These options should be set as ``CACHE`` variables, as |
| 144 | they are in ``config_default.cmake``. |
| 145 | |
| 146 | CMakeLists.txt |
| 147 | ^^^^^^^^^^^^^^ |
| 148 | |
| 149 | This file should contain all other required cmake code for the platform. This |
| 150 | primarily 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 | |
| 164 | preload_ns.cmake |
| 165 | ^^^^^^^^^^^^^^^^ |
| 166 | |
Chris Brand | d079033 | 2022-05-20 13:36:30 -0700 | [diff] [blame] | 167 | This optional cmake file is required only if the target runs the NSPE on a |
| 168 | core that requires different compiler options than the SPE core. This file has |
| 169 | the same format as ``preload.cmake``, but instead details the hardware of the |
| 170 | NS core that is **not** running the main TF-M secure code. |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 171 | |
| 172 | Flash layout header file |
| 173 | ------------------------ |
| 174 | Target must provide a header file, called ``flash_layout.h``, which defines the |
| 175 | information explained in the follow subsections. The defines must be named |
| 176 | as they are in the subsections. |
| 177 | |
| 178 | BL2 bootloader |
| 179 | ^^^^^^^^^^^^^^ |
| 180 | The 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 Vincze | bb20798 | 2019-08-21 15:13:04 +0200 | [diff] [blame] | 186 | - ``FLASH_AREA_SCRATCH_OFFSET`` - Defines the offset from the flash base |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 187 | address where the scratch area starts, which is used during image swapping. |
David Vincze | bb20798 | 2019-08-21 15:13:04 +0200 | [diff] [blame] | 188 | - ``FLASH_AREA_SCRATCH_SIZE`` - Defines the size of the scratch area. The |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 189 | 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 Vincze | bb20798 | 2019-08-21 15:13:04 +0200 | [diff] [blame] | 192 | The BL2 requires further definitions depending on the number of images, the |
| 193 | meaning 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 | |
| 228 | The table below shows a fraction of the flash layout in case of 2 and 1 |
| 229 | updatable 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 Coles | a495259 | 2019-10-01 11:43:18 +0100 | [diff] [blame] | 251 | - ``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 Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 253 | configured to be ``RAM_LOAD``. |
Raef Coles | a495259 | 2019-10-01 11:43:18 +0100 | [diff] [blame] | 254 | |
| 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 Ban | f4023f3 | 2020-09-16 11:02:52 +0100 | [diff] [blame] | 257 | configured to be ``RAM_LOAD``. |
Raef Coles | a495259 | 2019-10-01 11:43:18 +0100 | [diff] [blame] | 258 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 259 | Assemble tool |
| 260 | ^^^^^^^^^^^^^ |
Sverteczky, Marcell | 79ae915 | 2019-06-06 15:00:11 +0200 | [diff] [blame] | 261 | The ``assemble.py`` tool is used to concatenate secure and non-secure binary |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 262 | to 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, Marcell | 79ae915 | 2019-06-06 15:00:11 +0200 | [diff] [blame] | 272 | Image tool |
| 273 | ^^^^^^^^^^^^^ |
| 274 | The ``imgtool.py`` tool is used to handle the tasks related to signing the |
David Vincze | d8fbe0e | 2019-08-12 15:58:57 +0200 | [diff] [blame] | 275 | binary. It requires the following definition: |
Sverteczky, Marcell | 79ae915 | 2019-06-06 15:00:11 +0200 | [diff] [blame] | 276 | |
Jamie Fox | 957fb61 | 2022-01-17 17:58:41 +0000 | [diff] [blame] | 277 | - ``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, Marcell | 79ae915 | 2019-06-06 15:00:11 +0200 | [diff] [blame] | 284 | |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 285 | *************************************** |
| 286 | Expose target support for HW components |
| 287 | *************************************** |
| 288 | Services may require HW components to be supported by the target to enable some |
Kevin Peng | c6d7450 | 2020-03-04 16:55:37 +0800 | [diff] [blame] | 289 | features (e.g. PS service with rollback protection, etc). The following |
Gyorgy Szing | db9783c | 2019-04-17 21:08:48 +0200 | [diff] [blame] | 290 | definitions need to be set in the .cmake file if the target has the following |
| 291 | HW components: |
| 292 | |
| 293 | - ``TARGET_NV_COUNTERS_ENABLE`` - Specifies that the target has non-volatile |
| 294 | (NV) counters. |
| 295 | |
| 296 | -------------- |
| 297 | |
Jamie Fox | 957fb61 | 2022-01-17 17:58:41 +0000 | [diff] [blame] | 298 | *Copyright (c) 2017-2022, Arm Limited. All rights reserved.* |
Chris Brand | d079033 | 2022-05-20 13:36:30 -0700 | [diff] [blame] | 299 | *Copyright (c) 2020-2022 Cypress Semiconductor Corporation (an Infineon company) |
| 300 | or an affiliate of Cypress Semiconductor Corporation. All rights reserved.* |