Commit 813d29ca authored by Andrzej Puzdrowski's avatar Andrzej Puzdrowski
Browse files
parents 9920005e 1cb076c2
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -578,6 +578,23 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
    hdr = boot_img_hdr(state, slot);
    if (boot_check_header_erased(state, slot) == 0 ||
        (hdr->ih_flags & IMAGE_F_NON_BOOTABLE)) {

#if defined(MCUBOOT_SWAP_USING_SCRATCH) || defined(MCUBOOT_SWAP_USING_MOVE)
        /*
         * This fixes an issue where an image might be erased, but a trailer
         * be left behind. It can happen if the image is in the secondary slot
         * and did not pass validation, in which case the whole slot is erased.
         * If during the erase operation, a reset occurs, parts of the slot
         * might have been erased while some did not. The concerning part is
         * the trailer because it might disable a new image from being loaded
         * through mcumgr; so we just get rid of the trailer here, if the header
         * is erased.
         */
        if (slot != BOOT_PRIMARY_SLOT) {
            swap_erase_trailer_sectors(state, fap);
        }
#endif

        /* No bootable image in slot; continue booting from the primary slot. */
        rc = 1;
        goto out;
+21 −8
Original line number Diff line number Diff line
@@ -212,23 +212,36 @@ boot_status_internal_off(const struct boot_status *bs, int elem_sz)
int
boot_slots_compatible(struct boot_loader_state *state)
{
    size_t num_sectors;
    size_t num_sectors_pri;
    size_t num_sectors_sec;
    size_t sector_sz_pri = 0;
    size_t sector_sz_sec = 0;
    size_t i;

    num_sectors = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT);
    if (num_sectors != boot_img_num_sectors(state, BOOT_SECONDARY_SLOT)) {
        BOOT_LOG_WRN("Cannot upgrade: slots don't have same amount of sectors");
    num_sectors_pri = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT);
    num_sectors_sec = boot_img_num_sectors(state, BOOT_SECONDARY_SLOT);
    if ((num_sectors_pri != num_sectors_sec) &&
            (num_sectors_pri != (num_sectors_sec + 1))) {
        BOOT_LOG_WRN("Cannot upgrade: not a compatible amount of sectors");
        return 0;
    }

    if (num_sectors > BOOT_MAX_IMG_SECTORS) {
    if (num_sectors_pri > BOOT_MAX_IMG_SECTORS) {
        BOOT_LOG_WRN("Cannot upgrade: more sectors than allowed");
        return 0;
    }

    for (i = 0; i < num_sectors; i++) {
        if (boot_img_sector_size(state, BOOT_PRIMARY_SLOT, i) !=
                boot_img_sector_size(state, BOOT_SECONDARY_SLOT, i)) {
    for (i = 0; i < num_sectors_sec; i++) {
        sector_sz_pri = boot_img_sector_size(state, BOOT_PRIMARY_SLOT, i);
        sector_sz_sec = boot_img_sector_size(state, BOOT_SECONDARY_SLOT, i);
        if (sector_sz_pri != sector_sz_sec) {
            BOOT_LOG_WRN("Cannot upgrade: not same sector layout");
            return 0;
        }
    }

    if (num_sectors_pri > num_sectors_sec) {
        if (sector_sz_pri != boot_img_sector_size(state, BOOT_PRIMARY_SLOT, i)) {
            BOOT_LOG_WRN("Cannot upgrade: not same sector layout");
            return 0;
        }
+4 −1
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
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
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\""
Loading