blob: c2a6ca453c324f3f4d36e5518aed14b8ccc86d98 [file] [log] [blame] [view]
Roman Okhrimenko977b3752022-03-31 14:40:48 +03001### Support of secondary slot in external memory for PSoC™ 6 devices
2
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +02003* For the CYW20829/CYW89829 external memory support, see the [CYW20829.md](../platforms/CYW20829.md) file.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -05004
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +02005#### Description
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -05006
Roman Okhrimenko977b3752022-03-31 14:40:48 +03007This document describes the use of the external memory module as a secondary (upgrade) slot with Cypress PSoC 6 devices.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -05008
Roman Okhrimenko977b3752022-03-31 14:40:48 +03009The demonstration device is the `CY8CPROTO-062-4343W` board, which is a PSoC 6 device with 2M-flash, but other kits with 1M (CY8CKIT-062-WIFI-BT) or 512K (CY8CPROTO-062S3-4343W) chips can be used as well.
10The memory module on boards is S25FL512SAGMFI010 512-Mbit external Quad SPI NOR flash.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050011
Roman Okhrimenko977b3752022-03-31 14:40:48 +030012Using external memory for secondary slots allows nearly doubling the Boot Image size.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050013
Roman Okhrimenko977b3752022-03-31 14:40:48 +030014#### Operation design and flow
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050015
Roman Okhrimenko977b3752022-03-31 14:40:48 +030016The design is based on using the SFDP command's auto-discovery functionality of memory module IC and Cypress SMIF PDL driver.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050017
Roman Okhrimenko977b3752022-03-31 14:40:48 +030018A user's design example:
19* The memory-module is SFDP-compliant.
20* Only one module is used for the secondary slot.
21* The address for the secondary slot starts from 0x18000000.
22This corresponds to PSoC 6 SMIF (Serial Memory InterFace) IP block mapping.
23* The slot size and start address for the upgrade slot meet the requirements, when using swap upgrade.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050024
Roman Okhrimenko977b3752022-03-31 14:40:48 +030025The default flash map can be found in the [MCUBootApp.md](MCUBootApp.md) file.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050026
Roman Okhrimenko977b3752022-03-31 14:40:48 +030027MCUBootApp's `main.c` contains the call to Init-SFDP API, which performs the required GPIO configurations, SMIF IP block configuration, SFDP protocol read and memory-config structure initialization.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050028
Roman Okhrimenko977b3752022-03-31 14:40:48 +030029Now, MCUBootApp is ready to accept an upgrade image from the external memory module.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050030
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020031Upgrades from external memory are supported for both `overwrite only` and `swap with status partition` modes of MCUBootApp.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050032
Roman Okhrimenko977b3752022-03-31 14:40:48 +030033##### Requirements to size and start address of upgrade slot when using Swap mode
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020034
Roman Okhrimenko977b3752022-03-31 14:40:48 +030035Due to the MCUboot image structure, some restrictions apply when using upgrades from external flash. The main requirement:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020036
Roman Okhrimenko977b3752022-03-31 14:40:48 +030037**The trailer portion of an upgrade image can be erased separately.**
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020038
Roman Okhrimenko977b3752022-03-31 14:40:48 +030039To meet this requirement, the image trailer is placed separately on a full flash page, which equals 0x40200 for S25FL512SAGMFI010.
40Considering the default slot size for the external memory case described in the [MCUBootApp.md](MCUBootApp.md) file, occupied external flash looks as follows:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020041
42 0x18000000 [xxxxxxxxxxxxxxxx][ttfffffffffffff][fffffffffffffff]
43
44Here:
Roman Okhrimenko977b3752022-03-31 14:40:48 +030045`0x18000000` - The start address of external memory.
46`[xxxxxxxxxxxxxxxx]` - The first flash page of minimum erase size 0x40000 occupied by the firmware.
47`[tt]` - The trailer portion (last 0x200 of image) of the upgrade slot placed on a separate flash page.
48`[fffff]` - The remained portion of the flash page, used to store the image trailer - this area cannot be used for anything else.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020049
Roman Okhrimenko977b3752022-03-31 14:40:48 +030050When using slots sizes other than default, consider the above-described `0x40200`.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020051
Roman Okhrimenko977b3752022-03-31 14:40:48 +030052When the slot size is not aligned to `0x40200`, the start address of the upgrade image in the external flash is calculated starting from the image trailer location. Consider the following example:
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020053
Roman Okhrimenko977b3752022-03-31 14:40:48 +030054The primary slot size required is 590336 bytes (576k + 512b).
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020055
Roman Okhrimenko977b3752022-03-31 14:40:48 +030056Four flash pages are required to fit the secondary slot (P1-P4):
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020057
58 0x1800 0000 - 0x1804 0000 - P1
59 0x1804 0000 - 0x1808 0000 - P2
60 0x1808 0000 - 0x180C 0000 - P3
61 0x1808 0000 - 0x180C 0000 - P4
62
Roman Okhrimenko977b3752022-03-31 14:40:48 +030063The primary slot consists of 512 bytes of the image trailer, it goes to P4, 2 full sectors of 256k goes in P3 and P2, the remainder of 64k is resided in P1.
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020064
Roman Okhrimenko977b3752022-03-31 14:40:48 +030065Thus, the start address of the secondary slot is: 0x1804 0000 - 0x10000 (64k) = 0x1803 0000. The size occupied is 4 * 256k = 786k
Roman Okhrimenko13f79ed2021-03-11 19:05:41 +020066
Roman Okhrimenko977b3752022-03-31 14:40:48 +030067#### Execute in place (XIP) mode
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050068
Roman Okhrimenko977b3752022-03-31 14:40:48 +030069In the XIP mode firmware image can be placed in the external memory and executed from there directly. This mode is useful for devices with small internal flash or when one wishes to reserve internal flash for other purposes.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050070
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +020071On CYW20829/CYW89829 platforms XIP mode is always used due to absence of internal memory.
Bohdan Kovalchuka333a452020-07-09 16:55:58 +030072
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030073This is optional for PSoC™ 6 devices. The JSON flash map should contain `"mode": "XIP"` in the `"external_flash" section`. `USE_XIP` flag is added to auto-generated `memorymap.mk` on pre-build action.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050074
Roman Okhrimenko977b3752022-03-31 14:40:48 +030075When XIP mode is used primary slot of an image can be placed in external memory.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050076
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030077This repository provides default flash map files with suffix _xip_ to be used for XIP mode in `platforms/memory/flash_%platform_name%/flashmap`.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050078
Roman Okhrimenko977b3752022-03-31 14:40:48 +030079#### How to enable external memory support
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050080
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030081External memory is enabled when `make` flag `USE_EXTERNAL_FLASH` is set to `1`. Value of this flag is set in auto-generated `memorymap.mk` files when field `"external_flash"` is present in JSON file.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050082
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030083Default flash maps with suffix _smif_ are provided in `platforms/memory/PSOC6/flashmap` folder for PSoC™ 6 devices, where presense of external memory in system is optional.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -050084
Roman Okhrimenko977b3752022-03-31 14:40:48 +030085Build MCUBootApp as described in the [MCUBootApp.md](MCUBootApp.md) file.
86
87**Building an upgrade image for external memory:**
88
Roman Okhrimenkodc0ca082023-06-21 20:49:51 +030089 make app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE ERASED_VALUE=0xff FLASH_MAP=platforms/memory/PSOC6/flashmap/psoc6_swap_single_smif.json IMG_ID=1
Roman Okhrimenko977b3752022-03-31 14:40:48 +030090
91`ERASED_VALUE` - Defines the memory cell contents in the erased state. It is `0x00` for PSoC™ 6 internal flash and `0xff` for S25FL512S.
92
93**Programming external memory**
94
95Programming tools require configuration of SMIF block to debug/program external memory. When `MCUBootApp` is built with `BUILDCFG=Debug` flag SMIF configuration structures are added to the `MCUBootApp.hex` image. Additional sections:
96
97At SFlash address `0x16000800` address of SMIF configuration structure is placed.
98
99At SFlash address `0x16007c00` updated content of TOC2 structure is placed.
100
101The MCUBootApp can be programmed similarly to described in the [MCUBootApp.md](MCUBootApp.md) file:
102
Roman Okhrimenko883cb5b2024-03-28 17:22:33 +0200103 export OPENOCD=/Applications/ModusToolbox/tools_3.2/openocd
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -0500104
105 ${OPENOCD}/bin/openocd -s ${OPENOCD}/scripts \
106 -f ${OPENOCD}/scripts/interface/kitprog3.cfg \
107 -f ${OPENOCD}/scripts/target/psoc6_2m.cfg \
108 -c "init; psoc6 sflash_restrictions 1" \
109 -c "init; reset init; program PATH_TO_APPLICATION.hex" \
110 -c "resume; reset; exit"
111
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300112There is a NULL-pointer placed for the SMIF configuration pointer in TOC2 (Table Of Contents, `cy_serial_flash_prog.c`).
113This is done to force the CY8PROTO-062-4343W DAP Link firmware to program external memory with hardcoded values.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -0500114
Roman Okhrimenko977b3752022-03-31 14:40:48 +03001151. Click the SW3 Mode button on the board to switch the board to DAP Link mode.
1162. Once DAP Link removable disk displays, drop (copy) the upgrade image HEX file to it.
117This will invoke the firmware to program external memory.
Bohdan Kovalchuk0324f1b2020-05-26 08:04:24 -0500118
Roman Okhrimenko977b3752022-03-31 14:40:48 +0300119**Note :** the programming of external memory is limited to S25FL512S p/n only at this moment.