blob: d15f6672fd98d9343b155a055be339845d09084b [file] [log] [blame] [view]
Roman Okhrimenko977b3752022-03-31 14:40:48 +03001## MCUBootApp - demo bootloading application to use with Cypress targets
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +02002
Roman Okhrimenko977b3752022-03-31 14:40:48 +03003### Solution description
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +02004
Roman Okhrimenko977b3752022-03-31 14:40:48 +03005This solution demonstrates operation of MCUboot on Cypress PSoC 6 and CYW20829 devices.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +02006
Roman Okhrimenko977b3752022-03-31 14:40:48 +03007* Single-/Multi-image operation modes
8* Overwrite/Swap upgrade modes
9* Interrupted upgrade recovery for swap upgrades
10* Upgrade image confirmation
11* Reverting of bad upgrade images
12* Secondary slots located in external flash
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020013
Roman Okhrimenko977b3752022-03-31 14:40:48 +030014This demo supports PSoC 6 chips with the 1M-, 2M-, and 512K-flash on board, and the CYW20829 chip with no internal flash.
15The evaluation kits are:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020016* `CY8CPROTO-062-4343W`
17* `CY8CKIT-062-WIFI-BT`
Roman Okhrimenko977b3752022-03-31 14:40:48 +030018* `CY8CPROTO-062S3-4343W`
19* `CYW920829M2EVB-01`
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020020
Roman Okhrimenko977b3752022-03-31 14:40:48 +030021### Platfrom specifics
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020022
Roman Okhrimenko977b3752022-03-31 14:40:48 +030023MCUBootApp can be built for different platforms. So, the main application makefile `MCUBootApp.mk` operates with common build variables and flags. Most of them can be passed to build system as a `make` command parameter and each platform defines the default value prefixed with `PLATFORM_` in the corresponding makefile - `PSOC6.mk` or `CYW20829.mk`. The build flags and variables are described in detail in the following paragraphs.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020024
Roman Okhrimenko977b3752022-03-31 14:40:48 +030025### Memory maps
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020026
Roman Okhrimenko977b3752022-03-31 14:40:48 +030027The MCUboot terminology names a slot from which **boot** occurs as **primary** and a slot where an **upgrade** image is placed as **secondary**. Some platforms support both internal and external flash, some only external flash.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020028
Roman Okhrimenko977b3752022-03-31 14:40:48 +030029The flash map of bootloader is defined at compile time and cannot be changed dynamically. Flash map is prepared in the industry-accepted JSON (JavaScript Object Notation) format. It should follow the rules described in section **How to modify flash map**.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020030
Roman Okhrimenko977b3752022-03-31 14:40:48 +030031`MCUBootApp` contains JSON templates for flash maps with commonly used configurations. They can be found in `cy_flash_pal/flash_%platform_name%/flashmap` The slots' sizes are defined per platform to be compatible with all supported device families.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020032
Roman Okhrimenko977b3752022-03-31 14:40:48 +030033The actual addresses are provided in corresponding platform doc files:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020034
Roman Okhrimenko977b3752022-03-31 14:40:48 +030035- [PSOC6.md](../platforms/PSOC6/PSOC6.md)
36- [CYW20289.md](../platforms/CYW20829/CYW20829.md)
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020037
Roman Okhrimenko977b3752022-03-31 14:40:48 +030038#### How to modify flash map
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020039
Roman Okhrimenko977b3752022-03-31 14:40:48 +030040When modifying slots sizes, ensure aligning new values with the linker script files for appropriate applications.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020041
Roman Okhrimenko977b3752022-03-31 14:40:48 +030042##### Flash map definition
43Flash map describes what flash memory areas are allocated and defines their addresses and sizes. Also, it specifies the type of external flash memory, if applicable.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020044
Roman Okhrimenko977b3752022-03-31 14:40:48 +030045To build `MCUBootApp` with the given flash map (e.g., `flash_map.json`), supply the following parameter to `make`:
46`FLASH_MAP=flash_map.json`
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020047
Roman Okhrimenko977b3752022-03-31 14:40:48 +030048###### Flash map format
49Flash map must have the `"boot_and_upgrade"` section, define the location of `MCUBootApp` and at least one image. For instance:
50```
51{
52 "boot_and_upgrade": {
53 "bootloader": {
54 "address": {
55 "description": "Address of the bootloader",
56 "value": "0x10000000"
57 },
58 "size": {
59 "description": "Size of the bootloader",
60 "value": "0x18000"
61 }
62 },
63 "application_1": {
64 "address": {
65 "description": "Address of the application primary slot",
66 "value": "0x10018000"
67 },
68 "size": {
69 "description": "Size of the application primary slot",
70 "value": "0x10000"
71 },
72 "upgrade_address": {
73 "description": "Address of the application secondary slot",
74 "value": "0x18030200"
75 },
76 "upgrade_size": {
77 "description": "Size of the application secondary slot",
78 "value": "0x10000"
79 }
80 }
81 }
82}
83```
84Here an application identifier should follow the pattern, i.e., the 2nd image in the multi-image case is `"application_2"`, the 3rd is `"application_3"`, and so on. Up to four applications are supported at this moment.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020085
Roman Okhrimenko977b3752022-03-31 14:40:48 +030086For each image the location and size of its primary slot is given in the `"address"` and `"size"` parameters. The location and size of the secondary slot is specified in the `"upgrade_address"` and `"upgrade_size"`. All four values described above are mandatory.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020087
Roman Okhrimenko977b3752022-03-31 14:40:48 +030088There also should be a mandatory `"bootloader"` section, describing the location and size of `MCUBootApp` in the `"address"` and `"size"` parameters, respectively.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020089
Roman Okhrimenko977b3752022-03-31 14:40:48 +030090Under some circumstances (e.g., PSoC™ 62 with application slots in both internal and external flash memories), the slot address must be properly aligned, as the image trailer should start exactly at the erase block boundary. When an improper address is specified, `make` will fail with a message like:
91```
92Misaligned application_1 (secondary slot) - suggested address 0x18030200
93```
94This gives the nearest larger address that satisfy the slot location requirements. Other errors, such as overlapping flash areas, are also checked and reported.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020095
Roman Okhrimenko977b3752022-03-31 14:40:48 +030096###### Scratch area
97If there is a scratch area, what is generally true, its location and size is given in the `"scratch_address"` and `"scratch_size"` parameters of the `"bootloader"` subsection. For example:
98```
99{
100 "boot_and_upgrade": {
101 "bootloader": {
102 . . .
103 "scratch_address": {
104 "description": "Address of the scratch area",
105 "value": "0x18440000"
106 },
107 "scratch_size": {
108 "description": "Size of the scratch area",
109 "value": "0x10000"
110 },
111 },
112 . . .
113```
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200114
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300115###### Swap status partition
116If the desired upgrade mode is `swap scratch with status partition`, one should define the `"status_address"` and `"status_size"` parameters in the `"bootloader"` subsection, e.g.:
117```
118{
119 "boot_and_upgrade": {
120 "bootloader": {
121 . . .
122 "status_address": {
123 "description": "Address of the swap status partition",
124 "value": "0x10038000"
125 },
126 "status_size": {
127 "description": "Size of the swap status partition",
128 "value": "0x3800"
129 }
130 },
131 . . .
132```
133The required size of the status partition relies on many factors. If an insufficient size is given in the flash map, `make` will fail with a message such as:
134```
135Insufficient swap status area - suggested size 0x3800
136```
137To calculate the minimal correct size of the status partition, one could specify `"value": "0"` for the `"status_size"`. After the intentional `make` failure, copy the correct size from the error message.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200138
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300139###### External flash
140If an external flash memory is used, one should specify its parameters. The first way is specyfing the exact model:
141```
142{
143 "external_flash": [
144 {
145 "model": "S25HS256T"
146 }
147 ],
148 "boot_and_upgrade": {
149 . . .
150```
151However, the supported model list is incomplete. The known models are Infineon `S25HS256T`/`S25HS512T`/`S25HS01GT` SEMPER™ NOR Flash ICs, and a couple of SPI Flash ICs from other vendors. Another way is specyfing the important parameters, like:
152```
153{
154 "external_flash": [
155 {
156 "flash-size": "0x100000",
157 "erase-size": "0x1000"
158 }
159 ],
160 "boot_and_upgrade": {
161 . . .
162```
163for a typical 8-Mbit SPI flash with uniform 4-KByte erase blocks. While JSON list syntax is used for the `"external_flash"` section, only single instance is supported at this moment.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200164
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300165If the main application image is located in the external flash, `XIP` (eXecute In Place) mode should be turned on. To do so, supply the corresponding `"mode"` parameter:
166```
167{
168 "external_flash": [
169 {
170 "model": "S25HS256T",
171 "mode": "XIP"
172 }
173 ],
174 . . .
175```
176###### Service RAM Application
177The CYW20829 platform has a hardware-supported security counter. For more details on rollback protection support, refer to the [CYW20289.md](../platforms/CYW20829/CYW20829.md) file.
178The mentioned feature requires a dedicated area in the flash memory to store the Service RAM Application and other required data. The layout of these areas is defined in the `"service_app"` JSON section:
179```
180 . . .
181 "boot_and_upgrade":
182 {
183 "bootloader": {
184 . . .
185 },
186 "service_app": {
187 "address": {
188 "description": "Address of the service application",
189 "value": "0x60070000"
190 },
191 "size": {
192 "description": "Size of the service application",
193 "value": "0x8000"
194 },
195 "params_address": {
196 "description": "Address of the service application input parameters",
197 "value": "0x60078000"
198 },
199 "params_size": {
200 "description": "Size of the service application input parameters",
201 "value": "0x400"
202 },
203 "desc_address": {
204 "description": "Address of the service application descriptor",
205 "value": "0x60078400"
206 },
207 "desc_size": {
208 "description": "Size of the service application descriptor",
209 "value": "0x20"
210 }
211 },
212 "application_1": {
213 . . .
214```
215###### Shared secondary slot
216In the multi-image case, one can reduce the utilization of flash memory by placing secondary images into the same area. This area is reffered to as **Shared secondary slot**. This is especially desirable if there are more than two images.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200217
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300218Important consideration is that this option assumes updates are performed in sequential manner (consider the Swap upgrade method): place the 1st image into the shared slot, reset to MCUBoot, check the updated image and set the Image OK flag for the 1st image, reset to MCUBoot for permanent swap. Then place the 2nd image into the shared slot, reset to MCUBoot, check the updated image and set the Image OK flag for the 2nd image, reset to MCUBoot for permanent swap, etc.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200219
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300220Take into account that it is possible to revert only the last updated image, as its previous version resides in the Shared secondary slot. There is no way to revert changes for previous images, as their backups are gone! That is trade-off of the Shared secondary slot.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200221
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300222Shared secondary slot is rather a virtual concept, we still create individual flash areas for all secondary images. However, this areas are now overlapped (this is prohibited in the standard multi-image scenario). Moreover, special placing of secondary slots is required, as described below. Consider the triple-image example:
223```
224| |---------| |\
225| | | | \
226|---------| | | \
227| | | | \
228| Image 1 | Image 2 |---------| \
229| | | | Shared
230|---------| | | Secondary
231| Trailer | | Image 3 | Slot
232|---------|---------| | /
233| | Trailer | | /
234| |---------|---------| /
235| | | Trailer | /
236| | |---------|/
237```
238The purpose of such layout is to allow MCUBoot to understand what image is placed in the shared secondary slot. While secondary images now can (and should) overlap, their trailers must under no circumstances share the same address!
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200239
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300240Normally image trailer occupies the whole erase block (e.g. 512 bytes for PSoC™ 62 internal Flash, or 256 kilobytes for SEMPER™ Secure NOR Flash). There is a specific case when images are placed in both memory types, refer to the [PSOC6.md](../platforms/PSOC6/PSOC6.md) file.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200241
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300242One can declare all secondary slots as shared using the following JSON syntax:
243```
244 "boot_and_upgrade": {
245 "bootloader": {
246 . . .
247 "shared_slot": {
248 "description": "Using shared secondary slot",
249 "value": true
250 }
251 },
252```
253Alternatively, this can be done for each application:
254```
255 "boot_and_upgrade": {
256 "bootloader": {
257 . . .
258 },
259 "application_1": {
260 . . .
261 "shared_slot": {
262 "description": "Using shared secondary slot",
263 "value": true
264 }
265 },
266 "application_2": {
267 . . .
268 "shared_slot": {
269 "description": "Using shared secondary slot",
270 "value": true
271 }
272 },
273 . . .
274```
275where `true` marks the shared slot, `false` marks the normal (non-shared) secondary slot. In theory, one can use a separate secondary slot for the 1st image, and shared secondary slot for all other images.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200276
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300277When the `shared_slot` flag is set, different checks are performed at the pre-build stage. For instance, the following error is reported if image trailers appear at the same address:
278```
279Same trailer address for application_3 (secondary slot) and application_2 (secondary slot)
280```
281As mentioned above, shared secondary slot is a virtual concept, so overlapped flash areas are created for each image's secondary slot. No separate flash area is created for the shared slot itself.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200282
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300283**Upgrade process deviations**
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200284
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300285Shared slot feature has some differences and limitations in the update algorithm when there is one or more invalid images in primary slots and upgrade of these images is initiated through the shared upgrade slot (so-called **bootstrap** mode of bootloader). In this case, the bootloader allows to update the image even if other images are not valid (unlike the classic multi-image case). Bootloader however does not transfer control to these images until all primary slots become valid. ImageOK flag is set by updated images only after their successful validation and start.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200286
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300287Considering above there is a certain limitation for the shared slot mode. For **swap mode**, an update of valid slots is not possible as long as there is at least one image with an invalid prime slot.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200288
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300289Attempting to upgrade a valid primary slot of one image with an invalid primary slot of another image may run a revert procedure the next time the bootloader is started (provided that the data of shared slot has not been changed before). Therefore, for the shared slot, it is recommended to first make all invalid primary slots valid and only then update other images through the shared slot.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200290
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300291###### JSON syntax rules
292| Group | Item | Description |
293|--------------------|-------------------|----------------------------------------------------------|
294| `external_flash` | `model` | External flash model (if supported), e.g. `S25HS256T` |
295| `external_flash` | `flash-size` | External flash size in bytes (if model is not supported) |
296| `external_flash` | `erase-size` | Erase block size in bytes (if model is not supported) |
297| `external_flash` | `mode` | Set to `XIP` for eXecute In Place |
298| `boot_and_upgrade` | `bootloader` | Contains flash areas used by the `MCUBootApp` |
299| `bootloader` | `address` | Absolute address of the `MCUBootApp` |
300| `bootloader` | `size` | Size of the `MCUBootApp` in bytes |
301| `bootloader` | `scratch_address` | Absolute address of the Scratch Area |
302| `bootloader` | `scratch_size` | Size of the Scratch Area in bytes |
303| `bootloader` | `status_address` | Absolute address of the Swap Status Partition |
304| `bootloader` | `status_size` | Size of the Swap Status Partition in bytes |
305| `bootloader` | `shared_slot` | Marking the shared secondary slot for all images |
306| `boot_and_upgrade` | `service_app` | Reserves flash space for Service RAM Application |
307| `service_app` | `address` | Address of the Service RAM Application |
308| `service_app` | `size` | Size of the Service RAM Application |
309| `service_app` | `params_address` | Address of the input parameters (follows the app) |
310| `service_app` | `params_size` | Size of the service application input parameters |
311| `service_app` | `desc_address` | Address of the app descriptor (follows the parameters) |
312| `service_app` | `desc_size` | Size of the service application descriptor (always 0x20) |
313| `boot_and_upgrade` | `application_1` | Contains flash areas of the 1st application image |
314| `boot_and_upgrade` | `application_2` | 2nd image, see the description of `application_1` |
315| `boot_and_upgrade` | `application_3` | 3rd image, see the description of `application_1` |
316| `boot_and_upgrade` | `application_4` | 4th image, see the description of `application_1` |
317| `application_1` | `address` | Absolute address of the Primary Slot of the 1st image |
318| `application_1` | `size` | Size (in bytes) of the Primary Slot of the 1st image |
319| `application_1` | `upgrade_address` | Absolute address of the Secondary Slot of the 1st image |
320| `application_1` | `upgrade_size` | Size (in bytes) of the Secondary Slot of the 1st image |
321| `application_1` | `shared_slot` | Marking the shared secondary slot for the 1st image |
322| `address` | `value` | Value of the given address (hex or decimal) |
323| `scratch_address` | `value` | Value of the Scratch Area address (hex or decimal) |
324| `status_address` | `value` | Value of the Status Partition address (hex or decimal) |
325| `upgrade_address` | `value` | Value of the Secondary Slot address (hex or decimal) |
326| `size` | `value` | Value of the given size (hex or decimal) |
327| `scratch_size` | `value` | Value of the Scratch Area size (hex or decimal) |
328| `status_size` | `value` | Value of the Status Partition size (hex or decimal) |
329| `upgrade_size` | `value` | Value of the Secondary Slot size (hex or decimal) |
330| `shared_slot` | `value` | Set to `true` for the Shared secondary slot |
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200331
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300332###### Flash map internals
333When the `FLASH_MAP=` option is supplied to `make`, it involves the Python script `boot/cypress/scripts/flashmap.py`. It takes the JSON file and converts flash map into the C header file `boot/cypress/MCUBootApp/cy_flash_pal/cy_flash_map.h`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200334
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300335At the same time it creates the `boot/cypress/MCUBootApp/flashmap.mk`, which is conditionally included from the `boot/cypress/MCUBootApp/MCUBootApp.mk`. The generated file contains various definitions derived from the flash map, such as `MCUBOOT_IMAGE_NUMBER`, `MAX_IMG_SECTORS`, `USE_EXTERNAL_FLASH`, and `USE_XIP`. So, there is no need to specify these and similar parameters manually.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200336
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300337Do not edit neither `sysflash/cy_flash_map.h` nor `flashmap.mk`, as both files are overwritten on every build.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200338
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300339#### External flash
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200340
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300341Some Cypress devices, for example `CYW20829`, only have external flash, so all memory areas are located in external flash.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200342
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300343Hoewever, PSoC 6 chips has internal flash and, additionally, support the external memory connection. Thus, it is possible to place secondary (upgrade) slots in the external memory module and use most of internal flash for the primary image.
344For more details on External Memory usage, refer to the [ExternalMemory.md](ExternalMemory.md) file.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200345
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300346#### PSoC™ 6 RAM
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200347
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300348RAM areas in the MCUBootApp bootloading application and BlinkyApp are defined as an example pair. If your user application requires a different RAM area, ensure that it is not overlapped with the MCUBootApp RAM area. The memory (stack) corruption of the bootloading application can cause a failure if SystemCall-served operations were invoked from the user app.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200349
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300350The MCUBootApp linker script also contains the special section `public_ram`, which serves as a shared RAM area between the CM0p and CM4 cores. When CM4 and CM0p cores perform operations with internal flash, this area is used for the interprocessor data sharing.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200351
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300352#### CYW20829 RAM
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200353
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300354Only one CM33 core is used in the CYW20829 chips, so there are no restrictions for the RAM usage by the layer1 and layer2 applications (i.e. MCUBootApp and BlinkyApp).
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200355
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300356### Hardware cryptography acceleration
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200357
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300358Cypress PSoC 6 MCU family supports hardware acceleration of the cryptography based on the mbedTLS Library via a shim layer. The implementation of this layer is supplied as the separate submodule `cy-mbedtls-acceleration`. The hardware acceleration of the cryptography shortens the boot time by more than four times compared to the software implementation (observation results).
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200359
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300360The CYW20289 chip has hardware acceleration of the SHA256 algorithm only, and in other cases, uses pure software implementation of the cryptography based on MbedTLS.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200361
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300362To enable the hardware acceleration in `MCUBootApp`, pass flag `USE_CRYPTO_HW=1` to `make` during build.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200363
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300364The hardware cryptographic acceleration is disabled for all devices at the moment. `USE_CRYPTO_HW` flag is set to 0 by default. This package will be updated in next version.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200365
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300366__NOTE__: Hardware acceleration is not available in current version of mcuboot since `cy-mbedtls-acceleration` does not support `mbedTLS 3.0` yet.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200367
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300368### Multi-image mode
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200369
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300370Multi-image operation considers upgrading and verification of more than one image on a device.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200371
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300372Single or multi-image mode is dictated by `MCUBOOT_IMAGE_NUMBER` `make` flag. This flag's value is set in auto-generated `flashmap.mk` file per flash map used. There is no need to pass it manually.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200373
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300374In Multi-image operation up to four images are supported.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200375
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300376Consider MCUBootApp with 2 images supported. Operation is the following:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200377
Roman Okhrimenko977b3752022-03-31 14:40:48 +03003781. Verification of the Secondary_1 and Secondary_2 images.
3792. Upgrades Secondary to Primary if valid images found.
3803. Verification of the Primary_1 and Primary_2 images.
3814. Boots the image from the Primary_1 slot only.
3825. Boots Primary_1 only if both - Primary_1 and Primary_2 are present and valid.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200383
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300384This ensures that two dependent applications can be accepted by the device only if both images are valid.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200385
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300386### Upgrade modes
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200387
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300388There are two different types of the upgrade process supported by MCUBootApp. For the `overwrite only` type of upgrade - the secondary image is simply copied to the primary slot after successful validation. No way to revert upgrade if the secondary image is inoperable.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200389
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300390For `swap` upgrade mode - images in the primary and secondary slots are swapped. Upgrade can be reverted if the secondary image did not confirm its operation.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200391
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300392Upgrade mode is the same for all images in Multi-image mode.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200393
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300394#### Overwrite only
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200395
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300396To build MCUBootApp for overwrite upgrades only, `MCUBootApp/config/mcuboot_config/mcuboot_config.h` must contain the following definition:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200397
398`#define MCUBOOT_OVERWRITE_ONLY 1`
399
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300400This flag's value is set in auto-generated `flashmap.mk` file per flash map used. There is no need to pass it manually.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200401
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300402In Overwrite-only mode, MCUBootApp first checks if any upgrade image is present in the secondary slot(s), then validates the digital signature of the upgrade image in the secondary slot(s). If validation is successful, MCUBootApp starts copying the secondary slot content to the primary slot. After the copy is done, MCUBootApp starts the upgrade image execution from the primary slot.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200403
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300404If the upgraded application does not work - there is no way to revert back to the previous working version. Only the new upgrade firmware can fix the previous broken upgrade.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200405
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300406#### Swap mode
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200407
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300408For devices with a large minimum-erase size like PSoC 6 with 512 bytes and also for configurations, which use external flash with an even bigger minimum-erase size, there is an additional option in MCUBoot to use the dedicated `status partition` for robust storage of swap-related information.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200409
410##### Why use swap with status partition
411
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300412Originally, the MCUboot library has been designed with a consideration that the minimum write/erase size of flash is always 8 bytes or less. This value is critical, because the swap algorithms use it to align portions of data that contain the swap operation status of each flash sector in a slot before writing to flash. Data alignment is also performed before writes of special-purpose data to the image trailer.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200413
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300414Writing of the flash sector status or image trailer data will be the `single cycle` operation to ensure that the power loss and unpredicted resets robustness of bootloading applications. This requirement eliminates the usage of the `read-modify-write` type of operations with flash.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200415
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300416`Swap with status partition` is implemented specifically to address devices with a large write/erase size. It is based on existing MCUboot swap algorithms, but does not have restriction of the 8-byte alignment. Instead, the minimum write/erase size can be specified by the user and the algorithm will calculate sizes of the status partition considering this value. All write/erase operations are aligned to this minimum write/erase size as well.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200417
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300418##### Swap status partition description
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200419
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300420The main distinction of `swap with status partition` is that a separate flash area (partition) is used to store the swap status values and image trailer instead of using the free flash area at the end of the primary/secondary image slot.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200421
422This partition consists of separate areas:
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300423* the area to store swap status values
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200424 * swap_status_0
425 * ...
426 * swap_status_x
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300427* the area to store image trailer data:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200428 * Encryption key 0
429 * Encryption key 1
430 * Swap size
431 * Swap info
432 * Copy done value
433 * Image ok
434 * Boot image magic
435
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300436The principal diagram of the status partition:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200437
438```
439+-+-+-+-+-+-+ +-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \
440| | | D0 | --> | swap_status_0 | \
441| | +-+-+-+-+-+-+ | swap_status_1 | \
442| | | D1 | | swap_status_2 | \
443| | +-+-+-+-+-+-+ | ... | \
444| PRIMARY | --> | | | swap_status_max | min write/erase
445| | | .... | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ size of flash hw
446| | +-+-+-+-+-+-+ | AREA_MAGIC | /
447| | | Dx | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
448+-+-+-+-+-+-+ +-+-+-+-+-+-+ | CRC | /
449+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
450| | | CNT | /
451| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \
452| | | swap_status_max+1 | \
453| | | swap_status_max+2 | \
454| SECONDARY | | swap_status_max+3 | \
455| | | ... | \
456| | | swap_status_x | min write/erase
457| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ size of flash hw
458+-+-+-+-+-+-+ | AREA_MAGIC | /
459 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
460 | CRC | /
461 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
462 | CNT | /
463 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ \
464 | | \
465 | Image trailer | \
466 | | \
467 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ min write/erase
468 | AREA_MAGIC | size of flash hw
469 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
470 | CRC | /
471 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ /
472 | CNT | /
473 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
474```
475**Scheme legend:**
476
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300477`PRIMARY` and `SECONDARY` are areas in the status partition to contain data regarding a corresponding slot in MCUboot.
478`D0`, `D1`, and `Dx` are duplicates of data described on the left. At least 2 duplicates are present in the system. This duplication is used to eliminate flash wear. Each of `Dx` contains valid data for `current swap step - 1`. Each swap operation for the flash sector updates the status for this sector in the current `Dx` and the value on `CNT` increases. The next operation checks the least value of `CNT` in the available `Dx`s, copies the data from `Dx` with `CNT+1` and updates the status of the current sector. This continues until all sectors in the slot are moved and then swapped.
479`CRC` - A 4-byte value - the checksum of data contained in the area.
480`CNT` - A 4-byte value.
481`swap_status_0`, `swap_status_1` - 1-byte values that contain the status for a corresponding image sector.
482`swap_status_x` - The last sector of `BOOT_MAX_IMAGE_SECTORS`.
483`swap_status_max` - The maximum number of sectors that fits in the min write/erase size for particular flash hardware. If `swap_status_max` is less than `swap_status_x`, an additional slice of the min write/erase flash area is allocated to store swap status data.
484`Image trailer` - No less than 64 bytes. The code calculates how many min write/erase sizes to allocate for storing image trailer data.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200485
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300486**A calculation example for PSoC 6 with the minimum write/erase size of 512 bytes.**
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200487
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300488The following are considered:
489* Single-image case
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200490* Minimum write/erase size 512 bytes
491* PRIMARY/SECONDARY slots size `0x50000`
492* BOOT_MAX_IMG_SECTORS 0x50000 / 512 = 640
493* Number of duplicates `Dx = 2`
494
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300495One slice of the `min write/erase` size can store data for the maximum number of 500 sectors: 512 - 4 (CRC) - 4 (CNT) - 4 (area magic) = 500. BOOT_MAX_IMG_SECTORS is 640, so 2 slices of `min write/erase` are allocated. The total size is 1024 bytes.
496Image trailer data fits in 64 bytes, so one slice of the `min write/erase` size is allocated. The total size is 1024 + 512 = 1536 bytes.
497The number of duplicates 2. The total size is 1536 * 2 = 3072 bytes.
4982 slots are used in the particular case PRIMARY and SECONDARY, each needs 3072 bytes to store swap status data. The total is 3072 * 2 = 6144 bytes.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200499
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300500The swap status partition occupies 6144 bytes of the flash area.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200501
502**Expected lifecycle**
503
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300504The bootloading application uses the swap using the status partition, so Upgrade mode stores the system state in a separate flash area and the following product lifecycle is expected:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200505
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300506`Empty` - A fully-erased device.
507`Ready` - `Empty` -The device is programmed with the MCUboot-based bootloading application - MCUBootApp in this case.
508`Flashed` - Initial version v1.0 of the user application, BlinkyApp in this case, is flashed to the primary (BOOT) slot.
509`Upgraded` - The updated firmware image of the user application is delivered to the secondary slot (UPGRADE) and the bootloading application performs upgrade.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200510
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300511It is expected that the product stays in the `Upgraded` state until the end of its lifecycle.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200512
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300513If there is a need to wipe out product and flash new firmware directly to the primary (BOOT) slot, the device is transferred to the `Empty` or `Ready` state and then walks through all the states again.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200514
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300515### Hardware limitations
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200516
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300517This application is created to demonstrate the MCUboot library features and not as a reference examples. So, some considerations are taken.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200518
Roman Okhrimenko977b3752022-03-31 14:40:48 +03005191. `SCB5` is used to configure a serial port for debug prints. This is the most commonly used Serial Communication Block number among available Cypress PSoC 6 kits. To use custom hardware with this application, set custom `SCB*` and pins in the `cypress/MCUBootApp/custom_debug_uart_cfg.h` file and pass the `USE_CUSTOM_DEBUG_UART=1` parameter to the `make` command upon MCUBootApp build.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200520
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300521The `custom_debug_uart_cfg.h` file description:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200522
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300523`CUSTOM_UART_HW` - Sets a custom SCB name used as the debug serial port. (e.g. `SCB1`, `SCB2`, ...)
524`CUSTOM_UART_SCB_NUMBER` - Sets the number of SCB. It is `x` in the custom SCBx, which is set in `CUSTOM_UART_HW`.
525 (e.g. `1` if `CUSTOM_UART_HW` is set to SCB1, `2` if `CUSTOM_UART_HW`is set to SCB2, ...)
526`CUSTOM_UART_PORT` - Sets the GPIO port number whose pins are used as RX and TX of the debug serial port.
527`CUSTOM_UART_RX_PIN` - Sets the pin number in the GPIO port used as RX of the debug serial port.
528`CUSTOM_UART_TX_PIN` - Sets the pin number in the GPIO port used as TX of the debug serial port.
529
530The above-described applies only to the `PSoC™ 062` platform.
531
5322. `CY_SMIF_SLAVE_SELECT_0` is used to define the chip select for the SMIF driver. This configuration is used on the evaluation kit for this example CY8CPROTO-062-4343W. To use custom hardware with this application, change the value of `smif_id` in `main.c` of MCUBootApp to a value that corresponds to your design.
533
534### Downloading solution assets
535
536The required set of assets:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200537
538* MCUBooot Library (root repository)
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300539* HAL Library (submodule)
540* Peripheral Drivers Library (PDL) (submodule)
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200541* mbedTLS Cryptographic Library (submodule)
542
543To get submodules - run the following command:
544
545 git submodule update --init --recursive
546
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300547### Configuring MCUBootApp bootloading application
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200548
Roman Okhrimenko977b3752022-03-31 14:40:48 +03005491. Choose Upgrade mode and number of images.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200550
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300551`cy_flash_pal/flash_%platform_name%/flashmap` folder contains a set of predefined flash map JSON files with suffixes _overwrite_ or _swap_ for upgrade methods and _single_ or _multi_ for images number in its names. Depending on the file chosen upgrade method and images number is configured:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200552
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300553`USE_OVERWRITE` `make` flag is set to 1 or 0 for `overwrite` or `swap` mode;
554`MCUBOOT_IMAGE_NUMBER` flag is set to number of corresponding `application_#` sections in flash map file.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200555
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300556These flags values are set in auto-generated `flashmap.mk` file per flash map used. There is no need to pass them manually.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200557
Roman Okhrimenko977b3752022-03-31 14:40:48 +03005582. Enable the hardware acceleration of the cryptography on devices that support this feature.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200559
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300560Pass `USE_CRYPTO_HW=1` to the `make` command. This option is temporarily disabled by default - see paragraph **Hardware cryptography acceleration**.
561
562Additionally user can configure hardware rollback protection on the supported platforms. To do this flash map file from `cy_flash_pal/flash_%platform_name%/flashmap/hw_rollback_prot` folder should be used.
563
564`USE_HW_ROLLBACK_PROT` `make` flag is set to 1 in auto-generated `flashmap.mk`.
565
566Rollback protection feature is currently supported on CYW20829 devices in Secure mode only.
567
568### Building solution
569
570Folder `boot/cypress` contains make-files infrastructure for building MCUBootApp bootloader applications. Example build commands are provided later in this document for different build configurations.
571
572* Build MCUBootApp in the `Debug` configuration for Single-image mode with swap upgrade.
573
574 make app APP_NAME=MCUBootApp PLATFORM=PSOC_062_2M BUILDCFG=Debug FLASH_MAP=cy_flash_pal/flash_psoc6/flashmap/psoc62_swap_single.json
575
576* Build MCUBootApp in `Release` configuration for Multi-image mode with overwrite update.
577
578 make app APP_NAME=MCUBootApp PLATFORM=PSOC_062_2M BUILDCFG=Release FLASH_MAP=cy_flash_pal/flash_psoc6/flashmap/psoc62_overwrite_multi.json
579
580The root directory for build is `boot/cypress`.
581
582### Encrypted image support
583
584To protect firmware content from read, plain binary data can be encrypted. MCUBootApp supports the encrypted image in some implementations, depending on the platform.
585
586On PSoC 6, an upgrade image can be encrypted and then programmed to corresponding Secondary slot of MCUBootApp. It is then decrypted and transferred to the primary slot using the preferred upgrade method. For more details on the encrypted image implementation, refer to the [PSOC6.md](../platforms/PSOC6/PSOC6.md) file.
587
588On CYW20829, an encrypted image is supported in both slots. The firmware here is located in external memory, so, the chip's SMIF block encrypted eXecution In Place (XIP) feature is used. Encrypted firmware is placed directly in the primary slot and is decrypted on the fly. The encrypted upgrade image is first validated by MCUBootApp in the secondary slot and then transferred to the primary slot as it is. For more details on the encrypted image implementation, refer to the [CYW20289.md](../platforms/CYW20829/CYW20829.md) file.
589
590### Rollback protection
591
592MCUboot supports the security counter implementation to provide downgrade prevention. This mechanism allows the user to explicitly restrict the possibility to execute/upgrade images whose security counters are less than the current firmware counter. So, it can be guaranteed, that obsolete firmware with possible vulnerabilities can not be executed on the device.
593
594**Currently, only the CYW20829 platform supports the hardware rollback counter protection.**
595For more details on the implementation, refer to the [CYW20289.md](../platforms/CYW20829/CYW20829.md) file.
596
597### Complete build flags and parameters description
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200598
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300599Can be passed to `make` or set in makefiles.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200600
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300601`MCUBOOT_LOG_LEVEL` - Can be set at `MCUBOOT_LOG_LEVEL_DEBUG` to enable the verbose output of MCUBootApp.
602`ENC_IMG` - When set to `1`, enables the encrypted image support in MCUBootApp.
603`APP_DEFAULT_POLICY` - The path to a policy file to use for signing MCUBootApp and user application (BlinkyApp) on the CYW20829 platform.
604`USE_BOOTSTRAP` - When set to `1` and Swap mode is enabled, the application in the secondary slot will overwrite the primary slot, if the primary slot application is invalid.
605`USE_CRYPTO_HW` - When set to `1`, uses the hardware accelerated cryptography on the PSoC™ 6 platform, and SHA-256 HW acceleration for the CYW20289 platform.
606`LSC` - The lifecycle state of the chip. Possible options are `SECURE` and `NORMAL_NO_SECURE` (effective on CYW20829 chip only).
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200607
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300608Set by script in auto-generated makefile file.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200609
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300610`MCUBOOT_IMAGE_NUMBER` - The number of images to be supported by the current build of MCUBootApp.
611`USE_OVERWRITE` - `0` - Use swap with Scratch upgrade mode, `1` - use Overwrite only upgrade.
612`USE_EXTERNAL_FLASH` - When set to `1`, enables the external memory support on the PSoC™ 6 platform. This value is always set to `1` on CYW20829.
613`USE_HW_ROLLBACK_PROT` - When set to `1`, enables the hardware rollback protection on the CYW20829 platform with Secure mode enabled.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200614
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300615### Programming solution
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200616
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300617The MCUBootApp firmware can be programmed in different ways.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200618
Roman Okhrimenko977b3752022-03-31 14:40:48 +03006191. The direct usage of OpenOCD.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200620
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300621The OpenOCD package is supplied with ModusToolbox™ IDE and can be found in installation folder `ModusToolbox/tools_2.4/openocd`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200622
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300623Set environment variable `OPENOCD` to the path to the openocd folder in ModusToolbox™. Exact commands for programming images are provided in the corresponding platform readme files.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200624
Roman Okhrimenko977b3752022-03-31 14:40:48 +03006252. Using the GUI tool `Cypress Programmer`
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200626
627Follow [link](https://www.cypress.com/products/psoc-programming-solutions) to download.
628
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300629Connect the board to your computer. Switch Kitprog3 to DAP-BULK mode by clicking the `SW3 MODE` button until `LED2 STATUS` constantly shines. Open `Cypress Programmer` and click `Connect`, then choose hex file: `MCUBootApp.hex` or `BlinkyApp.hex` and click `Program`. Check the log to ensure the programming is successful. Reset the board.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200630
6313. Using `DAPLINK`.
632
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300633This mode is currently supported only on PSoC™ 6 development kits.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200634
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300635Connect the board to your computer. Switch the embedded Kitprog3 to `DAPLINK` mode by clicking the `SW3 MODE` button until `LED2 STATUS` blinks fast and the mass storage device displays on the OS. Drag and drop `hex` files you wish to program to the `DAPLINK` drive in your OS.
636
637### Build environment troubleshooting
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200638
639Regular shell/terminal combination on Linux and MacOS.
640
641On Windows:
642
643* Cygwin
644* Msys2
645
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300646Also, an IDE can be used:
647* Eclipse / ModusToolbox™ ("makefile project from existing source")
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200648
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300649*Make* - ensure that it is added to the system's `PATH` variable and the correct path is the first on the list.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200650
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300651*Python/Python3* - ensure that you have the correct path referenced in `PATH`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +0200652
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300653*Msys2* - To use the systems path, navigate to the msys2 folder, open `msys2_shell.cmd`, uncomment set `MSYS2_PATH_TYPE=inherit`, restart the MSYS2 shell. This will inherit the system's path and find `python` installed in the regular way as well as `imgtool` and its dependencies.