Bohdan Kovalchuk | 0324f1b | 2020-05-26 08:04:24 -0500 | [diff] [blame] | 1 | ### External Memory support for Secondary Slot |
| 2 | |
| 3 | **Description** |
| 4 | |
| 5 | Given document describes the use of external memory module as a secondary (upgrade) slot with Cypress' PSoC6 devices. |
| 6 | |
| 7 | The demonstration device is CY8CPROTO-062-4343W board which is PSoC6 device with 2M of Flash available. |
| 8 | The memory module present on board is S25FL512SAGMFI010 512-Mbit external Quad SPI NOR Flash. |
| 9 | |
| 10 | Using external memory for secondary slot allows to nearly double the size of Boot Image. |
| 11 | |
| 12 | **Operation Design and Flow** |
| 13 | |
| 14 | The design is based on using SFDP command's auto-discovery functionality of memory module IC and Cypress' SMIF PDL driver. |
| 15 | |
| 16 | It is assumed that user's design meets following: |
| 17 | * The memory-module used is SFDP-compliant; |
| 18 | * There only one module is being used for secondary slot; |
| 19 | * Only "OWERWRITE" bootloading scheme is used; |
| 20 | * The address for secondary slot should start from 0x18000000. |
| 21 | This corresponds to PSoC6's SMIF (Serial Memory InterFace) IP block mapping. |
| 22 | * The slot size for upgrade slot is even (or smaller) to erase size (0x40000) of given memory module. |
| 23 | This requirement is accepted for code simplicity. |
| 24 | |
| 25 | The default flash map implemented is the following: |
Bohdan Kovalchuk | a333a45 | 2020-07-09 16:55:58 +0300 | [diff] [blame^] | 26 | |
| 27 | Single-image mode. |
| 28 | |
| 29 | `[0x10000000, 0x10018000]` - MCUBootApp (bootloader) area; |
| 30 | |
| 31 | `[0x10018000, 0x10028000]` - primary slot for BlinkyApp; |
| 32 | |
| 33 | `[0x18000000, 0x18010000]` - secondary slot for BlinkyApp; |
| 34 | |
| 35 | `[0x10038000, 0x10039000]` - scratch area (not used); |
| 36 | |
| 37 | Multi(dual)-image mode. |
| 38 | |
| 39 | `[0x10000000, 0x10018000]` - MCUBootApp (bootloader) area; |
| 40 | |
| 41 | `[0x10018000, 0x10028000]` - primary1 slot for BlinkyApp; |
| 42 | |
| 43 | `[0x18000000, 0x18010000]` - secondary1 slot for BlinkyApp; |
| 44 | |
| 45 | `[0x10038000, 0x10048000]` - primary2 slot for user app ; |
| 46 | |
| 47 | `[0x18040000, 0x18050000]` - secondary2 slot for user app; |
| 48 | |
| 49 | `[0x10058000, 0x10059000]` - scratch area (not used); |
Bohdan Kovalchuk | 0324f1b | 2020-05-26 08:04:24 -0500 | [diff] [blame] | 50 | |
| 51 | Size of slots `0x10000` - 64kB |
| 52 | |
| 53 | **Note 1**: make sure primary, secondary slot and bootloader app sizes are appropriate and correspond to flash area size defined in Applications' linker files. |
| 54 | |
| 55 | **Note 2**: make sure secondary slot start address is aligned (or smaller) to erase size (0x40000 - 256kB). |
| 56 | |
| 57 | MCUBootApp's `main.c` contains the call to Init-SFDP API which performs required GPIO configurations, SMIF IP block configurations, SFDP protocol read and memory-config structure initialization. |
| 58 | |
| 59 | After that MCUBootApp is ready to accept upgrade image from external memory module. |
| 60 | |
| 61 | Once valid upgrade image was accepted the image in external memory will be erased. |
| 62 | |
| 63 | **How to enable external memory support:** |
| 64 | |
| 65 | 1. Seek for `CY_BOOT_USE_EXTERNAL_FLASH` in sources and define it in any: MCUBootApp.mk or any suitable header file. |
| 66 | 2. Navigate to `cy_flash_map.c` and check if secondary slot start address and size meet the application's needs. |
| 67 | 3. Define which slave select is used for external memory on a board by setting `smif_id` value in `main.c`. |
| 68 | 4. Build MCUBootApp as described in `Readme.md`. |
| 69 | |
Bohdan Kovalchuk | a333a45 | 2020-07-09 16:55:58 +0300 | [diff] [blame^] | 70 | **Note 3**: External memory code is developed basing on PDL and can be run on CM0p core only. It may require modifications if used on CM4. |
| 71 | |
Bohdan Kovalchuk | 0324f1b | 2020-05-26 08:04:24 -0500 | [diff] [blame] | 72 | **How to build upgrade image for external memory:** |
| 73 | |
| 74 | make app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE HEADER_OFFSET=0x7FE8000 ERASED_VALUE=0xff |
| 75 | |
| 76 | `HEADER_OFFSET` defines the offset from original boot image address. This one in line above suggests secondary slot will start from `0x18000000`. |
| 77 | |
| 78 | `ERASED_VALUE` defines the memory cell contents in erased state. It is `0x00` for PSoC6's internal Flash and `0xff` for S25FL512S. |
| 79 | |
| 80 | **Programming to external memory** |
| 81 | |
| 82 | The MCUBootApp programming can be done similarly to described in `Readme.md`: |
| 83 | |
| 84 | export OPENOCD=/Applications/ModusToolbox/tools_2.1/openocd |
| 85 | |
| 86 | ${OPENOCD}/bin/openocd -s ${OPENOCD}/scripts \ |
| 87 | -f ${OPENOCD}/scripts/interface/kitprog3.cfg \ |
| 88 | -f ${OPENOCD}/scripts/target/psoc6_2m.cfg \ |
| 89 | -c "init; psoc6 sflash_restrictions 1" \ |
| 90 | -c "init; reset init; program PATH_TO_APPLICATION.hex" \ |
| 91 | -c "resume; reset; exit" |
| 92 | |
| 93 | There is a NULL-pointer placed for SMIF configuration pointer in TOC2 (Table Of Contents, `cy_serial_flash_prog.c`). |
| 94 | This is done to force CY8PROTO-062-4343W DAP Link firmware to program external memory with hardcoded values. |
| 95 | |
| 96 | 1. Press SW3 Mode button on a board to switch the board into DAP Link mode. |
| 97 | 2. Once DAP Link removable disk appeared drop (copy) the upgrade image HEX file to it. |
| 98 | This will invoke firmware to program external memory. |
| 99 | |
| 100 | **Note 3:** the programming of external memory is limited to S25FL512S p/n only at this moment. |