Commit 1c32c9b1 authored by Martin Jäger's avatar Martin Jäger Committed by almir-okato
Browse files

boot: espressif: add support for upgrade modes w/o scratch

Upgrade using move decreases flash wear and is now the default mode
used by Zephyr.

The implementation is done by MCUboot itself, so it is just a matter of
setting the correct define to enable it.

Swap using move was successfully tested with ESP32C6.

Signed-off-by: default avatarMartin Jäger <martin@libre.solar>
parent 1c04eac6
Loading
Loading
Loading
Loading
+27 −7
Changes for boot/espressif/hal/include/mcuboot_config/mcuboot_config.h: 27 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -45,23 +45,43 @@
 * the default upgrade mode.
 */

/* Uncomment to enable the overwrite-only code path. */
/* #define MCUBOOT_OVERWRITE_ONLY */
/* Define to enable the swap-using-move code path. */
#if defined(CONFIG_ESP_BOOT_SWAP_USING_MOVE)
#define MCUBOOT_SWAP_USING_MOVE 1
#endif

#ifdef MCUBOOT_OVERWRITE_ONLY
/* Define to enable the overwrite-only code path. */
#if defined(CONFIG_ESP_BOOT_UPGRADE_ONLY)
#define MCUBOOT_OVERWRITE_ONLY
/* Uncomment to only erase and overwrite those primary slot sectors needed
 * to install the new image, rather than the entire image slot. */
/* #define MCUBOOT_OVERWRITE_ONLY_FAST */
#endif

/* Uncomment to enable the direct-xip code path. */
/* #define MCUBOOT_DIRECT_XIP */
/* Define to enable the direct-xip code path (CURRENTLY UNSUPPORTED!). */
#if defined(CONFIG_ESP_BOOT_DIRECT_XIP)
#define MCUBOOT_DIRECT_XIP
#endif

/* Define to enable the ram-load code path. */
#if defined(CONFIG_BOOT_RAM_LOAD)
/* Define to enable the ram-load code path (CURRENTLY UNSUPPORTED!). */
#if defined(CONFIG_ESP_BOOT_RAM_LOAD)
#define MCUBOOT_RAM_LOAD
#endif

/* If none of the above paths is defined, define CONFIG_ESP_BOOT_SWAP_USING_SCRATCH.
 *
 * Note: MCUBOOT_SWAP_USING_SCRATCH does not have to be defined, as it will be defined
 *       by MCUboot in bootutil_priv.h.
 */
#if !defined(CONFIG_ESP_BOOT_SWAP_USING_SCRATCH) && \
    !defined(CONFIG_ESP_BOOT_SWAP_USING_MOVE) && \
    !defined(CONFIG_ESP_BOOT_UPGRADE_ONLY) && \
    !defined(CONFIG_ESP_BOOT_DIRECT_XIP) && \
    !defined(CONFIG_ESP_BOOT_RAM_LOAD)
#define CONFIG_ESP_BOOT_SWAP_USING_SCRATCH
#endif


/*
 * Cryptographic settings
 *
+3 −0
Changes for boot/espressif/hal/src/flash_encrypt.c: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -307,12 +307,15 @@ esp_err_t esp_flash_encrypt_contents(void)
    if (err != ESP_OK) {
        return err;
    }

#ifdef CONFIG_ESP_BOOT_SWAP_USING_SCRATCH
    region_addr = CONFIG_ESP_SCRATCH_OFFSET;
    region_size = CONFIG_ESP_SCRATCH_SIZE;
    err = esp_flash_encrypt_region(region_addr, region_size);
    if (err != ESP_OK) {
        return err;
    }
#endif

#if defined(CONFIG_ESP_IMAGE_NUMBER) && (CONFIG_ESP_IMAGE_NUMBER == 2)
    region_addr = CONFIG_ESP_IMAGE1_PRIMARY_START_ADDRESS;
+4 −0
Changes for boot/espressif/port/esp32/bootloader-multi.conf: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@
#
# SPDX-License-Identifier: Apache-2.0

# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y

CONFIG_ESP_FLASH_SIZE=4MB
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
CONFIG_ESP_BOOTLOADER_OFFSET=0x1000
+4 −0
Changes for boot/espressif/port/esp32/bootloader.conf: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@
#
# SPDX-License-Identifier: Apache-2.0

# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y

CONFIG_ESP_FLASH_SIZE=4MB
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
CONFIG_ESP_BOOTLOADER_OFFSET=0x1000
+4 −0
Changes for boot/espressif/port/esp32c2/bootloader.conf: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,10 @@
#
# SPDX-License-Identifier: Apache-2.0

# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y

CONFIG_ESP_FLASH_SIZE=4MB
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
CONFIG_ESP_BOOTLOADER_OFFSET=0x0000
Loading