Commit a333a457 authored by Bohdan Kovalchuk's avatar Bohdan Kovalchuk Committed by Roman Okhrimenko
Browse files

Cypress: fix flash_area_write, warnings, improve make, readme

parent 6ec2ec32
Loading
Loading
Loading
Loading
+4 −1
Changes for boot/cypress/BlinkyApp/Readme.md: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ Pre-build action calls GCC preprocessor which intantiates defines for particular
Default values set for currently supported targets:
* PSOC_062_2M in `BlinkyApp.mk` to `-DUSER_APP_START=0x10018000`

**Important**: make sure RAM areas of CM4-based BlinkyApp and CM0p-based MCUBootApp bootloader do not overlap.
Memory (stack) corruption of CM0p application can cause failure if SystemCall-served operations invoked from CM4.

**Building an application:**

Root directory for build is **boot/cypress.**
@@ -71,7 +74,7 @@ To get appropriate artifact for second image PRIMARY slot run this command:

**How to build upgrade image for external memory:**

For prepare MCUBoot to work with external memory please refer to MCUBoot/ExternalMemory.md
To prepare MCUBootApp for work with external memory please refer to `MCUBootApp/ExternalMemory.md`.

For build BlinkyApp upgarde image for external memory use command:

+26 −4
Changes for boot/cypress/MCUBootApp/ExternalMemory.md: 26 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -23,10 +23,30 @@ This corresponds to PSoC6's SMIF (Serial Memory InterFace) IP block mapping.
This requirement is accepted for code simplicity.

The default flash map implemented is the following:
* [0x10000000, 0x10018000] - MCUBootApp (bootloader) area;
* [0x10018000, 0x10028000] - primary slot for BlinkyApp;
* [0x18000000, 0x18010000] - secondary slot for BlinkyApp;
* [0x10038000, 0x10039000] - scratch area (not used);

Single-image mode.

`[0x10000000, 0x10018000]` - MCUBootApp (bootloader) area;

`[0x10018000, 0x10028000]` - primary slot for BlinkyApp;

`[0x18000000, 0x18010000]` - secondary slot for BlinkyApp;

`[0x10038000, 0x10039000]` - scratch area (not used);

Multi(dual)-image mode.

`[0x10000000, 0x10018000]` - MCUBootApp (bootloader) area;

`[0x10018000, 0x10028000]` - primary1 slot for BlinkyApp;

`[0x18000000, 0x18010000]` - secondary1 slot for BlinkyApp;

`[0x10038000, 0x10048000]` - primary2 slot for user app ;

`[0x18040000, 0x18050000]` - secondary2 slot for user app;

`[0x10058000, 0x10059000]` - scratch area (not used);

Size of slots `0x10000` - 64kB

@@ -47,6 +67,8 @@ Once valid upgrade image was accepted the image in external memory will be erase
3. Define which slave select is used for external memory on a board by setting `smif_id` value in `main.c`.
4. Build MCUBootApp as described in `Readme.md`.

**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.

**How to build upgrade image for external memory:**

    make app APP_NAME=BlinkyApp PLATFORM=PSOC_062_2M IMG_TYPE=UPGRADE HEADER_OFFSET=0x7FE8000 ERASED_VALUE=0xff
+4 −0
Changes for boot/cypress/MCUBootApp/MCUBootApp.mk: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -41,6 +41,9 @@ include $(CUR_APP_PATH)/platforms.mk
include $(CUR_APP_PATH)/libs.mk
include $(CUR_APP_PATH)/toolchains.mk

# default slot size is 0x10000, 512bytes per row/sector, so 128 sectors
MAX_IMG_SECTORS ?= 128

# Application-specific DEFINES
DEFINES_APP := -DMBEDTLS_CONFIG_FILE="\"mcuboot_crypto_config.h\""
DEFINES_APP += -DECC256_KEY_FILE="\"keys/$(SIGN_KEY_FILE).pub\""
@@ -49,6 +52,7 @@ DEFINES_APP += -DMCUBOOT_IMAGE_NUMBER=$(MCUBOOT_IMAGE_NUMBER)
ifeq ($(USE_EXTERNAL_FLASH), 1)
DEFINES_APP += -DCY_BOOT_USE_EXTERNAL_FLASH
endif
DEFINES_APP += -DMCUBOOT_MAX_IMG_SECTORS=$(MAX_IMG_SECTORS)

ifeq ($(USE_CRYPTO_HW), 1)
DEFINES_APP += -DMBEDTLS_USER_CONFIG_FILE="\"mcuboot_crypto_acc_config.h\""
+18 −8
Changes for boot/cypress/MCUBootApp/README.md: 18 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -9,19 +9,26 @@ There are two applications implemented:
* BlinkyApp - simple PSoC6 blinking LED application which is a target of BOOT/UPGRADE;

The demonstration device is CY8CPROTO-062-4343W board which is PSoC6 device with 2M of Flash available.

The default flash map implemented is the following:

* [0x10000000, 0x10018000] - MCUBootApp (bootloader) area;
* [0x10018000, 0x10028000] - primary slot for BlinkyApp;
* [0x10028000, 0x10038000] - secondary slot for BlinkyApp;
* [0x10038000, 0x10039000] - scratch area;
Single-image mode.

`[0x10000000, 0x10018000]` - MCUBootApp (bootloader) area;

`[0x10018000, 0x10028000]` - primary slot for BlinkyApp;

`[0x10028000, 0x10038000]` - secondary slot for BlinkyApp;

`[0x10038000, 0x10039000]` - scratch area (not used);

Size of slots `0x10000` - 64kb

MCUBootApp checks image integrity with SHA256, image authenticity with EC256 digital signature verification and uses completely SW implementation of cryptographic functions based on mbedTLS Library.

**Important**: make sure primary, secondary slot and bootloader app sizes are appropriate and correspond to flash area size defined in Applications' linker files.

MCUBootApp checks image integrity with SHA256, image authenticity with EC256 digital signature verification and uses completely SW implementation of cryptographic functions based on mbedTLS Library.
**Important**: make sure RAM areas of CM0p-based MCUBootApp bootloader and CM4-based BlinkyApp do not overlap.
Memory (stack) corruption of CM0p application can cause failure if SystemCall-served operations invoked from CM4.

**Hardware cryptography acceleration:**

@@ -72,7 +79,7 @@ As an example in a makefile it should look like following:

Multi-image operation considers upgrading and verification of more then one image on the device.

To 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`.
To enable multi-image operation define `MCUBOOT_IMAGE_NUMBER` in `MCUBootApp/config/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`.

Default value of `MCUBOOT_IMAGE_NUMBER` is 1, which corresponds to single image configuratios.

@@ -98,10 +105,13 @@ This ensures two dependent applications can be accepted by device only in case b

`0x10048000 - 0x10058000` - Secondary_2 (UPGRADE) slot of Bootloader

`0x10058000 - 0x10058100` - Scratch of Bootloader
`0x10058000 - 0x10059000` - Scratch of Bootloader

Size of slots `0x10000` - 64kb

__Note:__ It is also possible to place secondary (upgrade) slots in external memory module so resulting image size can be doubled.
For more details about External Memory usage, please refer to separate guiding document `ExternalMemory.md`.

**Downloading Solution's Assets**

There is a set assets required:
+8 −1
Changes for boot/cypress/MCUBootApp/main.c: 8 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ static void do_boot(struct boot_rsp *rsp)
    app_addr = (rsp->br_image_off + rsp->br_hdr->ih_hdr_size);

    BOOT_LOG_INF("Starting User Application on CM4 (wait)...");
    BOOT_LOG_INF("Start Address: 0x%08x", app_addr);
    Cy_SysLib_Delay(100);

    Cy_SysEnableCM4(app_addr);
@@ -61,7 +62,6 @@ static void do_boot(struct boot_rsp *rsp)
int main(void)
{
    struct boot_rsp rsp;
    cy_rslt_t rc = !CY_RSLT_SUCCESS;

    init_cycfg_clocks();
    init_cycfg_peripherals();
@@ -75,6 +75,13 @@ int main(void)
    BOOT_LOG_INF("MCUBoot Bootloader Started");

#ifdef CY_BOOT_USE_EXTERNAL_FLASH
    cy_rslt_t rc = !CY_RSLT_SUCCESS;

    #undef MCUBOOT_MAX_IMG_SECTORS
    /* redefine number of sectors as there 2MB will be
     * available on PSoC062-2M in case of external
     * memory usage */
    #define MCUBOOT_MAX_IMG_SECTORS 4096
    int smif_id = 1; /* Assume SlaveSelect_0 is used for External Memory */
    /* Acceptable values are:
    * 0 - SMIF disabled (no external memory);
Loading