Roman Okhrimenko | 977b375 | 2022-03-31 14:40:48 +0300 | [diff] [blame^] | 1 | ## PSoC™ 6 platform description |
| 2 | |
| 3 | ### MCUBootApp specifics |
| 4 | |
| 5 | ### Default memory map |
| 6 | |
| 7 | This repository provides a set of predefined memory maps in JSON files. They are located in `cy_flash_pal/flash_psoc6/flashmap`. One can use the predefined flash map or define its own using the predefined file as a template. |
| 8 | |
| 9 | ### JSON flash map |
| 10 | As absolute addresses are used in JSON flash maps, the placement of flash area in internal or external memory is derived from its address. For instance: |
| 11 | ``` |
| 12 | "application_1": { |
| 13 | "address": { |
| 14 | "description": "Address of the application primary slot", |
| 15 | "value": "0x10018000" |
| 16 | }, |
| 17 | "size": { |
| 18 | "description": "Size of the application primary slot", |
| 19 | "value": "0x10000" |
| 20 | }, |
| 21 | "upgrade_address": { |
| 22 | "description": "Address of the application secondary slot", |
| 23 | "value": "0x18030200" |
| 24 | }, |
| 25 | "upgrade_size": { |
| 26 | "description": "Size of the application secondary slot", |
| 27 | "value": "0x10000" |
| 28 | } |
| 29 | } |
| 30 | ``` |
| 31 | declares primary slot in the internal Flash, and secondary slot in the external Flash. |
| 32 | |
| 33 | ##### Shared secondary slot |
| 34 | Some Flash ICs have large erase block. For SEMPER™ Secure NOR Flash it is 256 kilobytes, so placing each image trailer in a separate erase block seems a waste. |
| 35 | |
| 36 | Specific technique is needed to place all trailers of the shared secondary slot in the single erase block. Since the whole erase block with trailer is occasionally cleared by MCUBoot, image padding is required to place trailers at different addresses and to avoid unintended erasing of image bytes. |
| 37 | ``` |
| 38 | /| |-----------| | |
| 39 | / | | | | |
| 40 | / |-----------| | | |
| 41 | / | | | | |
| 42 | / | | Image 2 |-----------| |
| 43 | / | Image 1 | | | |
| 44 | / : : : Image 3 : |
| 45 | / | | | | |
| 46 | / |-----------|-----------|-----------| |
| 47 | Shared | Trailer | Padding | |\ |
| 48 | Secondary |0x200 bytes|0x200 bytes| Padding | \ |
| 49 | Slot |-----------|-----------| | \ |
| 50 | \ | | Trailer |0x400 bytes| \ |
| 51 | \ | |0x200 bytes| | Erase |
| 52 | \ | |-----------|-----------| block |
| 53 | \ | | | Trailer | 256 K |
| 54 | \ | | |0x200 bytes| / |
| 55 | \ | | |-----------| / |
| 56 | \ : : : : / |
| 57 | \ | | | |/ |
| 58 | \|-----------|-----------|-----------| |
| 59 | ``` |
| 60 | The pre-build script issues messages, such as |
| 61 | ``` |
| 62 | Note: application_2 (secondary slot) requires 512 padding bytes before trailer |
| 63 | ``` |
| 64 | to remind about the necessary padding. |
| 65 | |
| 66 | ### Encrypted Image Support |
| 67 | |
| 68 | To protect the user's image from unwanted read, Upgrade Image Encryption can be applied. The ECDH/HKDF with the EC256 scheme is used in a given solution as well as mbedTLS as a crypto provider. |
| 69 | |
| 70 | To enable the image encryption support, use the `ENC_IMG=1` build flag (BlinkyApp should also be built with this flash set 1). |
| 71 | |
| 72 | The user is also responsible for providing corresponding binary key data in `enc_priv_key[]` (file `\MCUBootApp\keys.c`). The public part will be used by `imgtool` when signing and encrypting upgrade image. Signing image with encryption is described in [BlinkyApp.md](../../BlinkyApp/BlinkyApp.md). |
| 73 | |
| 74 | After MCUBootApp is built with these settings, unencrypted and encrypted images will be accepted in the secondary (upgrade) slot. |
| 75 | |
| 76 | An example of the command: |
| 77 | |
| 78 | make app APP_NAME=MCUBootApp PLATFORM=PSOC_062_2M BUILDCFG=Debug FLASH_MAP=cy_flash_pal/flash_psoc6/flashmap/psoc62_swap_single.json ENC_IMG=1 |
| 79 | |
| 80 | NOTE: Debug configuration of MCUBootApp with Multi-image encrypted upgrades in external flash (built with flags `BUILDCFG=Debug` `MCUBOOT_IMG_NUMBER=2 USE_EXTERNAL_FLASH=1 ENC_IMG=1`) is set to use optimization level `-O2 -g3` to fit into `0x18000` allocated for `MCUBootApp`. |
| 81 | |
| 82 | ### Programming applications |
| 83 | |
| 84 | #### Using OpenOCD from command line |
| 85 | |
| 86 | The following instructions assume the usage of one of Cypress development kits `CY8CPROTO_062_4343W`. |
| 87 | |
| 88 | Connect the board to your computer. Switch Kitprog3 to DAP-BULK mode by clicking the `SW3 MODE` button until `LED2 STATUS` constantly shines. |
| 89 | |
| 90 | Open the terminal application and execute the following command after substitution of the `PATH_TO_APPLICATION.hex` and `OPENOCD` paths: |
| 91 | |
| 92 | export OPENOCD=/Applications/ModusToolbox/tools_2.4/openocd |
| 93 | |
| 94 | ${OPENOCD}/bin/openocd -s ${OPENOCD}/scripts \ |
| 95 | -f ${OPENOCD}/scripts/interface/kitprog3.cfg \ |
| 96 | -f ${OPENOCD}/scripts/target/psoc6_2m.cfg \ |
| 97 | -c "init; reset init; program PATH_TO_APPLICATION.hex" \ |
| 98 | -c "resume; reset; exit" |