blob: dfa831285039a0e8968a5698d0bb1cccb03ab19a [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
26**How to modify Flash map:**
27
28__Option 1.__
29
30Navigate to `sysflash.h` and modify the flash area(s) / slots sizes to meet your needs.
31
32__Option 2.__
33
34Navigate to `sysflash.h`, uncomment `CY_FLASH_MAP_EXT_DESC` definition.
35Now 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.
36
37__Note:__ for both options make sure you have updated `MCUBOOT_MAX_IMG_SECTORS` appropriatery with sector size assumed to be 512.
38
39**How to override the flash map values during build process:**
40
41Navigate to MCUBootApp.mk, find section `DEFINES_APP +=`
42Update this line and or add similar for flash map parameters to override.
43
44The possible list could be:
45
46* MCUBOOT_MAX_IMG_SECTORS
47* CY_FLASH_MAP_EXT_DESC
48* CY_BOOT_SCRATCH_SIZE
49* CY_BOOT_BOOTLOADER_SIZE
50* CY_BOOT_PRIMARY_1_SIZE
51* CY_BOOT_SECONDARY_1_SIZE
52* CY_BOOT_PRIMARY_2_SIZE
53* CY_BOOT_SECONDARY_2_SIZE
54
55As an example in a makefile it should look like following:
56
57`DEFINES_APP +=-DCY_FLASH_MAP_EXT_DESC`
58
59`DEFINES_APP +=-DMCUBOOT_MAX_IMG_SECTORS=512`
60
61`DEFINES_APP +=-DCY_BOOT_PRIMARY_1_SIZE=0x15000`
62
63**Multi-Image Operation**
64
65Multi-image operation considers upgrading and verification of more then one image on the device.
66
67To 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`.
68
69Default value of `MCUBOOT_IMAGE_NUMBER` is 1, which corresponds to single image configuratios.
70
71In multi-image operation (two images are considered for simplicity) MCUBoot Bootloader application operates as following:
72
73* Verifies Primary_1 and Primary_2 images;
74* Verifies Secondary_1 and Secondary_2 images;
75* Upgrades Secondary to Primary if valid images found;
76* Boots image from Primary_1 slot only;
77* Boots Primary_1 only if both - Primary_1 and Primary_2 are present and valid;
78
79This ensures two dependent applications can be accepted by device only in case both images are valid.
80
81**Default Flash map for Multi-Image operation:**
82
83`0x10000000 - 0x10018000` - MCUBoot Bootloader
84
85`0x10018000 - 0x10028000` - Primary_1 (BOOT) slot of Bootloader
86
87`0x10028000 - 0x10038000` - Secondary_1 (UPGRADE) slot of Bootloader
88
89`0x10038000 - 0x10048000` - Primary_2 (BOOT) slot of Bootloader
90
91`0x10048000 - 0x10058000` - Secondary_2 (UPGRADE) slot of Bootloader
92
93`0x10058000 - 0x10058100` - Scratch of Bootloader
94
95Size of slots `0x10000` - 64kb
96
97**Downloading Solution's Assets**
98
99There is a set assets required:
100
101* MCUBooot Library (root repository)
102* PSoC6 HAL Library
103* PSoC6 Peripheral Drivers Library (PDL)
104* mbedTLS Cryptographic Library
105
106To get submodules - run the following command:
107
108 git submodule update --init --recursive
109
110**Building Solution**
111
112This 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.
113
114* Build MCUBootApp in `Debug` for signle image use case.
115
116 make app APP_NAME=MCUBootApp PLATFORM=PSOC_062_2M BUILDCFG=Debug MCUBOOT_IMAGE_NUMBER=1
117
118* Build MCUBootApp in `Release` for multi image use case.
119
120 make app APP_NAME=MCUBootApp PLATFORM=PSOC_062_2M BUILDCFG=Release MCUBOOT_IMAGE_NUMBER=2
121
122Root directory for build is **boot/cypress.**
123
124**Currently supported platforms:**
125
126* PSOC_062_2M
127
128**Build environment troubleshooting:**
129
130Regular shell/terminal combination on Linux and MacOS.
131
132On Windows:
133
134* Cygwin
135* Msys2
136
137Also IDE may be used:
138* Eclipse / ModusToolbox ("makefile project from existing source")
139
140*Make* - make sure it is added to system's `PATH` variable and correct path is first in the list;
141
142*Python/Python3* - make sure you have correct path referenced in `PATH`;
143
144*Msys2* - to use systems PATH navigate to msys2 folder, open `msys2_shell.cmd`, uncomment set `MSYS2_PATH_TYPE=inherit`, restart MSYS2 shell.
145
146This will iherit system's PATH so should find `python3.7` installed in regular way as well as imgtool and its dependencies.
147