Skip to content

Commit 1c32c9b

Browse files
martinjaegeralmir-okato
authored andcommitted
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: Martin Jäger <[email protected]>
1 parent 1c04eac commit 1c32c9b

File tree

12 files changed

+76
-9
lines changed

12 files changed

+76
-9
lines changed

boot/espressif/hal/include/mcuboot_config/mcuboot_config.h

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,43 @@
4545
* the default upgrade mode.
4646
*/
4747

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

51-
#ifdef MCUBOOT_OVERWRITE_ONLY
53+
/* Define to enable the overwrite-only code path. */
54+
#if defined(CONFIG_ESP_BOOT_UPGRADE_ONLY)
55+
#define MCUBOOT_OVERWRITE_ONLY
5256
/* Uncomment to only erase and overwrite those primary slot sectors needed
5357
* to install the new image, rather than the entire image slot. */
5458
/* #define MCUBOOT_OVERWRITE_ONLY_FAST */
5559
#endif
5660

57-
/* Uncomment to enable the direct-xip code path. */
58-
/* #define MCUBOOT_DIRECT_XIP */
61+
/* Define to enable the direct-xip code path (CURRENTLY UNSUPPORTED!). */
62+
#if defined(CONFIG_ESP_BOOT_DIRECT_XIP)
63+
#define MCUBOOT_DIRECT_XIP
64+
#endif
5965

60-
/* Define to enable the ram-load code path. */
61-
#if defined(CONFIG_BOOT_RAM_LOAD)
66+
/* Define to enable the ram-load code path (CURRENTLY UNSUPPORTED!). */
67+
#if defined(CONFIG_ESP_BOOT_RAM_LOAD)
6268
#define MCUBOOT_RAM_LOAD
6369
#endif
6470

71+
/* If none of the above paths is defined, define CONFIG_ESP_BOOT_SWAP_USING_SCRATCH.
72+
*
73+
* Note: MCUBOOT_SWAP_USING_SCRATCH does not have to be defined, as it will be defined
74+
* by MCUboot in bootutil_priv.h.
75+
*/
76+
#if !defined(CONFIG_ESP_BOOT_SWAP_USING_SCRATCH) && \
77+
!defined(CONFIG_ESP_BOOT_SWAP_USING_MOVE) && \
78+
!defined(CONFIG_ESP_BOOT_UPGRADE_ONLY) && \
79+
!defined(CONFIG_ESP_BOOT_DIRECT_XIP) && \
80+
!defined(CONFIG_ESP_BOOT_RAM_LOAD)
81+
#define CONFIG_ESP_BOOT_SWAP_USING_SCRATCH
82+
#endif
83+
84+
6585
/*
6686
* Cryptographic settings
6787
*

boot/espressif/hal/src/flash_encrypt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,15 @@ esp_err_t esp_flash_encrypt_contents(void)
307307
if (err != ESP_OK) {
308308
return err;
309309
}
310+
311+
#ifdef CONFIG_ESP_BOOT_SWAP_USING_SCRATCH
310312
region_addr = CONFIG_ESP_SCRATCH_OFFSET;
311313
region_size = CONFIG_ESP_SCRATCH_SIZE;
312314
err = esp_flash_encrypt_region(region_addr, region_size);
313315
if (err != ESP_OK) {
314316
return err;
315317
}
318+
#endif
316319

317320
#if defined(CONFIG_ESP_IMAGE_NUMBER) && (CONFIG_ESP_IMAGE_NUMBER == 2)
318321
region_addr = CONFIG_ESP_IMAGE1_PRIMARY_START_ADDRESS;

boot/espressif/port/esp32/bootloader-multi.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
6+
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
7+
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y
8+
59
CONFIG_ESP_FLASH_SIZE=4MB
610
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
711
CONFIG_ESP_BOOTLOADER_OFFSET=0x1000

boot/espressif/port/esp32/bootloader.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
6+
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
7+
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y
8+
59
CONFIG_ESP_FLASH_SIZE=4MB
610
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
711
CONFIG_ESP_BOOTLOADER_OFFSET=0x1000

boot/espressif/port/esp32c2/bootloader.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
6+
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
7+
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y
8+
59
CONFIG_ESP_FLASH_SIZE=4MB
610
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
711
CONFIG_ESP_BOOTLOADER_OFFSET=0x0000

boot/espressif/port/esp32c3/bootloader.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
6+
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
7+
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y
8+
59
CONFIG_ESP_FLASH_SIZE=4MB
610
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
711
CONFIG_ESP_BOOTLOADER_OFFSET=0x0000

boot/espressif/port/esp32c6/bootloader.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
6+
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
7+
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y
8+
59
CONFIG_ESP_FLASH_SIZE=4MB
610
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
711
CONFIG_ESP_BOOTLOADER_OFFSET=0x0000

boot/espressif/port/esp32h2/bootloader.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
6+
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
7+
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y
8+
59
CONFIG_ESP_FLASH_SIZE=4MB
610
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
711
CONFIG_ESP_BOOTLOADER_OFFSET=0x0000

boot/espressif/port/esp32s2/bootloader.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
6+
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
7+
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y
8+
59
CONFIG_ESP_FLASH_SIZE=4MB
610
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
711
CONFIG_ESP_BOOTLOADER_OFFSET=0x1000

boot/espressif/port/esp32s3/bootloader-multi.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

5+
# Define upgrade mode (default is CONFIG_ESP_BOOT_SWAP_USING_SCRATCH)
6+
# CONFIG_ESP_BOOT_SWAP_USING_MOVE=y
7+
# CONFIG_ESP_BOOT_UPGRADE_ONLY=y
8+
59
CONFIG_ESP_FLASH_SIZE=4MB
610
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
711
CONFIG_ESP_BOOTLOADER_OFFSET=0x0000

0 commit comments

Comments
 (0)