Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synch up to the mcu-tool/mcuboot cd22b693 19.01.2025 #122

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions boot/boot_serial/src/boot_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ bs_set(char *buf, int len)
uint8_t image_index = 0;
size_t decoded = 0;
uint8_t hash[IMAGE_HASH_SIZE];
bool confirm;
struct zcbor_string img_hash;
bool confirm = false;
struct zcbor_string img_hash = { 0 };
bool ok;
int rc;

Expand Down Expand Up @@ -798,7 +798,7 @@ bs_upload(char *buf, int len)
size_t img_size_tmp = SIZE_MAX; /* Temp variable for image size */
const struct flash_area *fap = NULL;
int rc;
struct zcbor_string img_chunk_data;
struct zcbor_string img_chunk_data = { 0 };
size_t decoded = 0;
bool ok;
#ifdef MCUBOOT_ERASE_PROGRESSIVELY
Expand Down Expand Up @@ -1021,7 +1021,7 @@ bs_upload(char *buf, int len)
}
}
} else {
out_invalid_data:
out_invalid_data:
rc = MGMT_ERR_EINVAL;
}

Expand Down
23 changes: 13 additions & 10 deletions boot/bootutil/include/bootutil/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
extern "C" {
#endif

#ifndef __packed
#define __packed __attribute__((__packed__))
#if defined(__IAR_SYSTEMS_ICC__)
#define STRUCT_PACKED __packed struct
#else
#define STRUCT_PACKED struct __attribute__((__packed__))
#endif

struct flash_area;
Expand Down Expand Up @@ -124,6 +126,7 @@ struct flash_area;
* the format and size of the raw slot (compressed)
* signature
*/
#define IMAGE_TLV_COMP_DEC_SIZE 0x73 /* Compressed decrypted image size */
/*
* vendor reserved TLVs at xxA0-xxFF,
* where xx denotes the upper byte
Expand All @@ -136,12 +139,12 @@ struct flash_area;
*/
#define IMAGE_TLV_ANY 0xffff /* Used to iterate over all TLV */

struct image_version {
STRUCT_PACKED image_version {
uint8_t iv_major;
uint8_t iv_minor;
uint16_t iv_revision;
uint32_t iv_build_num;
} __packed;
};

struct image_dependency {
uint8_t image_id; /* Image index (from 0) */
Expand All @@ -154,7 +157,7 @@ struct image_dependency {
};

/** Image header. All fields are in little endian byte order. */
struct image_header {
STRUCT_PACKED image_header {
uint32_t ih_magic;
uint32_t ih_load_addr;
uint16_t ih_hdr_size; /* Size of image header (bytes). */
Expand All @@ -163,19 +166,19 @@ struct image_header {
uint32_t ih_flags; /* IMAGE_F_[...]. */
struct image_version ih_ver;
uint32_t _pad1;
} __packed;
};

/** Image TLV header. All fields in little endian. */
struct image_tlv_info {
STRUCT_PACKED image_tlv_info {
uint16_t it_magic;
uint16_t it_tlv_tot; /* size of TLV area (including tlv_info header) */
} __packed;
};

/** Image trailer TLV format. All fields in little endian. */
struct image_tlv {
STRUCT_PACKED image_tlv {
uint16_t it_type; /* IMAGE_TLV_[...]. */
uint16_t it_len; /* Data length (not including TLV header). */
} __packed;
};

#define ENCRYPTIONFLAGS (IMAGE_F_ENCRYPTED_AES128 | IMAGE_F_ENCRYPTED_AES256)
#define IS_ENCRYPTED(hdr) (((hdr)->ih_flags & IMAGE_F_ENCRYPTED_AES128) \
Expand Down
21 changes: 21 additions & 0 deletions boot/espressif/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ endif()
add_definitions(-DMCUBOOT_TARGET=${MCUBOOT_TARGET})
add_definitions(-D__ESPRESSIF__=1)

set(EXPECTED_IDF_HAL_VERSION "5.1.4")

if ("${MCUBOOT_TARGET}" STREQUAL "esp32" OR
"${MCUBOOT_TARGET}" STREQUAL "esp32s2" OR
"${MCUBOOT_TARGET}" STREQUAL "esp32s3")
Expand Down Expand Up @@ -92,6 +94,25 @@ if (NOT DEFINED ESP_HAL_PATH)
endif()
endif()
endif()
message(STATUS "Defined ESP_HAL_PATH: ${ESP_HAL_PATH}")

# Verify from which IDF version the HAL is based on
set(IDF_VER_HEADER_FILE "${ESP_HAL_PATH}/components/esp_common/include/esp_idf_version.h")

get_version_from_header("ESP_IDF_VERSION_MAJOR" ${IDF_VER_HEADER_FILE} IDF_VERSION_MAJOR)
get_version_from_header("ESP_IDF_VERSION_MINOR" ${IDF_VER_HEADER_FILE} IDF_VERSION_MINOR)
get_version_from_header("ESP_IDF_VERSION_PATCH" ${IDF_VER_HEADER_FILE} IDF_VERSION_PATCH)

set(IDF_VERSION "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}.${IDF_VERSION_PATCH}")

if (NOT IDF_VERSION VERSION_EQUAL ${EXPECTED_IDF_HAL_VERSION})
message(FATAL_ERROR
"Unsupported HAL version ${IDF_VERSION}, expected ${EXPECTED_IDF_HAL_VERSION}. \
Verify if the RTOS repository, where you are trying to build from, is up to date, \
or check the installation pointed on ESP_HAL_PATH.")
else ()
message(STATUS "HAL based on ESP-IDF version: ${IDF_VERSION}")
endif()

execute_process(
COMMAND git describe --tags
Expand Down
1 change: 1 addition & 0 deletions boot/espressif/hal/include/esp32s3/sdkconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
#define CONFIG_EFUSE_VIRTUAL_OFFSET 0x250000
#define CONFIG_EFUSE_VIRTUAL_SIZE 0x2000
#define CONFIG_EFUSE_MAX_BLK_LEN 256
#define CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT 1
29 changes: 21 additions & 8 deletions boot/espressif/hal/include/esp_mcuboot_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@
* for MCUboot-Espressif port booting.
*/
typedef struct esp_image_load_header {
uint32_t header_magic; /* Magic for load header */
uint32_t entry_addr; /* Application entry address */
uint32_t iram_dest_addr; /* Destination address(VMA) for IRAM region */
uint32_t iram_flash_offset; /* Flash offset(LMA) for start of IRAM region */
uint32_t iram_size; /* Size of IRAM region */
uint32_t dram_dest_addr; /* Destination address(VMA) for DRAM region */
uint32_t dram_flash_offset; /* Flash offset(LMA) for start of DRAM region */
uint32_t dram_size; /* Size of DRAM region */
uint32_t header_magic; /* Magic for load header */
uint32_t entry_addr; /* Application entry address */
uint32_t iram_dest_addr; /* Destination address(VMA) for IRAM region */
uint32_t iram_flash_offset; /* Flash offset(LMA) for start of IRAM region */
uint32_t iram_size; /* Size of IRAM region */
uint32_t dram_dest_addr; /* Destination address(VMA) for DRAM region */
uint32_t dram_flash_offset; /* Flash offset(LMA) for start of DRAM region */
uint32_t dram_size; /* Size of DRAM region */
uint32_t lp_rtc_iram_dest_addr; /* Destination address (VMA) for LP_IRAM region */
uint32_t lp_rtc_iram_flash_offset; /* Flash offset (LMA) for LP_IRAM region */
uint32_t lp_rtc_iram_size; /* Size of LP_IRAM region */
uint32_t lp_rtc_dram_dest_addr; /* Destination address (VMA) for LP_DRAM region */
uint32_t lp_rtc_dram_flash_offset; /* Flash offset (LMA) for LP_DRAM region */
uint32_t lp_rtc_dram_size; /* Size of LP_DRAM region */
uint32_t irom_map_addr; /* Mapped address (VMA) for IROM region */
uint32_t irom_flash_offset; /* Flash offset (LMA) for IROM region */
uint32_t irom_size; /* Size of IROM region */
uint32_t drom_map_addr; /* Mapped address (VMA) for DROM region */
uint32_t drom_flash_offset; /* Flash offset (LMA) for DROM region */
uint32_t drom_size; /* Size of DROM region */
uint32_t _reserved[4]; /* Up to 24 words reserved for the header */
} esp_image_load_header_t;
34 changes: 27 additions & 7 deletions boot/espressif/hal/include/mcuboot_config/mcuboot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
3 changes: 3 additions & 0 deletions boot/espressif/hal/src/flash_encrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32/bootloader-multi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32/bootloader.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32c2/bootloader.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32c3/bootloader.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32c6/bootloader.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32h2/bootloader.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32s2/bootloader.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion boot/espressif/port/esp32s2/ld/bootloader.ld
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MEMORY
{
iram_seg (RWX) : org = 0x40047000, len = 0x9000
iram_loader_seg (RWX) : org = 0x40050000, len = 0x6000
dram_seg (RW) : org = 0x3FFE6000, len = 0x9000
dram_seg (RW) : org = 0x3FFE6000, len = 0x9A00
}

/* Default entry point: */
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32s3/bootloader-multi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions boot/espressif/port/esp32s3/bootloader.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading