blob: c251446d20ebc0b3ae0b0269e2770916ef54fae1 [file] [log] [blame] [view]
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +02001### Port of MCUBoot library to be used with Cypress targets
2
3**Solution Description**
4
5Given solution demonstrates operation of MCUBoot on Cypress' PSoC6 device.
6
7There are two applications implemented:
8* MCUBootApp - PSoC6 MCUBoot-based bootloading application;
9* BlinkyApp - simple PSoC6 blinking LED application which is a target of BOOT/UPGRADE;
10
11The demonstration device is CY8CPROTO-062-4343W board which is PSoC6 device with 2M of Flash available.
12
13The default flash map implemented is the following:
14
15* [0x10000000, 0x10018000] - MCUBootApp (bootloader) area;
16* [0x10018000, 0x10028000] - primary slot for BlinkyApp;
17* [0x10028000, 0x10038000] - secondary slot for BlinkyApp;
18* [0x10038000, 0x10039000] - scratch area;
19
20Size of slots `0x10000` - 64kb
21
22**Important**: make sure primary, secondary slot and bootloader app sizes are appropriate and correspond to flash area size defined in Applications' linker files.
23
24MCUBootApp checks image integrity with SHA256, image authenticity with EC256 digital signature verification and uses completely SW implementation of cryptographic functions based on mbedTLS Library.
25
Roman Okhrimenko4c1c5b02020-01-31 16:22:39 +020026**Hardware cryptography acceleration:**
27
28Cypress PSOC6 MCU family supports hardware acceleration of cryptography based on mbedTLS Library via shim layer. Implementation of this layer is supplied as separate submodule `cy-mbedtls-acceleration`. HW acceleration of cryptography shortens boot time more then 4 times, comparing to software implementation (observation results).
29
30To enable hardware acceleration in `MCUBootApp` pass flag `USE_CRYPTO_HW=1` to `make` while build.
31
32Hardware acceleration of cryptography is enabled for PSOC6 devices by default.
33
Roman Okhrimenko89ecdac2020-02-28 17:05:55 +020034**How to modify Flash map:**
35
36__Option 1.__
37
38Navigate to `sysflash.h` and modify the flash area(s) / slots sizes to meet your needs.
39
40__Option 2.__
41
42Navigate to `sysflash.h`, uncomment `CY_FLASH_MAP_EXT_DESC` definition.
43Now define and initialize `struct flash_area *boot_area_descs[]` with flash memory addresses and sizes you need at the beginning of application, so flash APIs from `cy_flash_map.c` will use it.
44
45__Note:__ for both options make sure you have updated `MCUBOOT_MAX_IMG_SECTORS` appropriatery with sector size assumed to be 512.
46
47**How to override the flash map values during build process:**
48
49Navigate to MCUBootApp.mk, find section `DEFINES_APP +=`
50Update this line and or add similar for flash map parameters to override.
51
52The possible list could be:
53
54* MCUBOOT_MAX_IMG_SECTORS
55* CY_FLASH_MAP_EXT_DESC
56* CY_BOOT_SCRATCH_SIZE
57* CY_BOOT_BOOTLOADER_SIZE
58* CY_BOOT_PRIMARY_1_SIZE
59* CY_BOOT_SECONDARY_1_SIZE
60* CY_BOOT_PRIMARY_2_SIZE
61* CY_BOOT_SECONDARY_2_SIZE
62
63As an example in a makefile it should look like following:
64
65`DEFINES_APP +=-DCY_FLASH_MAP_EXT_DESC`
66
67`DEFINES_APP +=-DMCUBOOT_MAX_IMG_SECTORS=512`
68
69`DEFINES_APP +=-DCY_BOOT_PRIMARY_1_SIZE=0x15000`
70
71**Multi-Image Operation**
72
73Multi-image operation considers upgrading and verification of more then one image on the device.
74
75To enable multi-image operation define `MCUBOOT_IMAGE_NUMBER` in `MCUBootApp/mcuboot_config.h` file should be set to 2 (only dual-image is supported at the moment). This could also be done on build time by passing `MCUBOOT_IMAGE_NUMBER=2` as parameter to `make`.
76
77Default value of `MCUBOOT_IMAGE_NUMBER` is 1, which corresponds to single image configuratios.
78
79In multi-image operation (two images are considered for simplicity) MCUBoot Bootloader application operates as following:
80
81* Verifies Primary_1 and Primary_2 images;
82* Verifies Secondary_1 and Secondary_2 images;
83* Upgrades Secondary to Primary if valid images found;
84* Boots image from Primary_1 slot only;
85* Boots Primary_1 only if both - Primary_1 and Primary_2 are present and valid;
86
87This ensures two dependent applications can be accepted by device only in case both images are valid.
88
89**Default Flash map for Multi-Image operation:**
90
91`0x10000000 - 0x10018000` - MCUBoot Bootloader
92
93`0x10018000 - 0x10028000` - Primary_1 (BOOT) slot of Bootloader
94
95`0x10028000 - 0x10038000` - Secondary_1 (UPGRADE) slot of Bootloader
96
97`0x10038000 - 0x10048000` - Primary_2 (BOOT) slot of Bootloader
98
99`0x10048000 - 0x10058000` - Secondary_2 (UPGRADE) slot of Bootloader
100
101`0x10058000 - 0x10058100` - Scratch of Bootloader
102
103Size of slots `0x10000` - 64kb
104
105**Downloading Solution's Assets**
106
107There is a set assets required:
108
109* MCUBooot Library (root repository)
110* PSoC6 HAL Library
111* PSoC6 Peripheral Drivers Library (PDL)
112* mbedTLS Cryptographic Library
113
114To get submodules - run the following command:
115
116 git submodule update --init --recursive
117
118**Building Solution**
119
120This folder contains make files infrastructure for building MCUBoot Bootloader. Same approach used in sample BlinkyLedApp application. Example command are provided below for couple different build configurations.
121
122* Build MCUBootApp in `Debug` for signle image use case.
123
124 make app APP_NAME=MCUBootApp PLATFORM=PSOC_062_2M BUILDCFG=Debug MCUBOOT_IMAGE_NUMBER=1
125
126* Build MCUBootApp in `Release` for multi image use case.
127
128 make app APP_NAME=MCUBootApp PLATFORM=PSOC_062_2M BUILDCFG=Release MCUBOOT_IMAGE_NUMBER=2
129
130Root directory for build is **boot/cypress.**
131
132**Currently supported platforms:**
133
134* PSOC_062_2M
135
136**Build environment troubleshooting:**
137
138Regular shell/terminal combination on Linux and MacOS.
139
140On Windows:
141
142* Cygwin
143* Msys2
144
145Also IDE may be used:
146* Eclipse / ModusToolbox ("makefile project from existing source")
147
148*Make* - make sure it is added to system's `PATH` variable and correct path is first in the list;
149
150*Python/Python3* - make sure you have correct path referenced in `PATH`;
151
152*Msys2* - to use systems PATH navigate to msys2 folder, open `msys2_shell.cmd`, uncomment set `MSYS2_PATH_TYPE=inherit`, restart MSYS2 shell.
153
154This will iherit system's PATH so should find `python3.7` installed in regular way as well as imgtool and its dependencies.
155