arch/xtensa/esp32s3: Update MCUboot build process

Change the MCUboot build process to, in the future, deprecate the esp-nuttx-bootloaders repository.
This commit is contained in:
Lucas Saavedra Vaz 2023-08-17 13:12:51 -03:00 committed by Xiang Xiao
parent 4bcc930535
commit e02b203311
8 changed files with 93 additions and 47 deletions

View File

@ -139,9 +139,9 @@ Flash and PSRAM).
mcuboot_nsh mcuboot_nsh
----------- -----------
Similar configuration as nsh, except that it enables booting from This configuration is the same as the ``nsh`` configuration, but it generates the application
MCUboot and the experimental features configuration. image in a format that can be used by MCUboot. It also makes the ``make bootloader`` command to
You can find more information on the `example's documentation <https://github.com/apache/nuttx-apps/blob/master/examples/mcuboot/swap_test/README.md>`_. build the MCUboot bootloader image using the Espressif HAL.
nsh nsh
--- ---

View File

@ -1,2 +1,3 @@
/esp-nuttx-bootloader /bootloader
/esp-hal-3rdparty /esp-hal-3rdparty
/esp-nuttx-bootloader

View File

@ -18,25 +18,34 @@
# #
############################################################################ ############################################################################
.PHONY: bootloader clean_bootloader
ifeq ($(CONFIG_ESP32S3_BOOTLOADER_BUILD_FROM_SOURCE),y) ifeq ($(CONFIG_ESP32S3_BOOTLOADER_BUILD_FROM_SOURCE),y)
TOOLSDIR = $(TOPDIR)/tools/espressif
CHIPDIR = $(TOPDIR)/arch/xtensa/src/chip CHIPDIR = $(TOPDIR)/arch/xtensa/src/chip
HALDIR = $(CHIPDIR)/esp-hal-3rdparty
BOOTLOADER_SRCDIR = $(CHIPDIR)/esp-nuttx-bootloader BOOTLOADER_DIR = $(CHIPDIR)/bootloader
BOOTLOADER_SRCDIR = $(BOOTLOADER_DIR)/esp-nuttx-bootloader
BOOTLOADER_VERSION = main BOOTLOADER_VERSION = main
BOOTLOADER_URL = https://github.com/espressif/esp-nuttx-bootloader BOOTLOADER_URL = https://github.com/espressif/esp-nuttx-bootloader
BOOTLOADER_OUTDIR = out BOOTLOADER_OUTDIR = out
BOOTLOADER_CONFIG = $(CHIPDIR)/bootloader.conf BOOTLOADER_CONFIG = $(BOOTLOADER_DIR)/bootloader.conf
$(BOOTLOADER_SRCDIR): MCUBOOT_SRCDIR = $(BOOTLOADER_DIR)/mcuboot
$(Q) git clone $(BOOTLOADER_URL) $(BOOTLOADER_SRCDIR) -b $(BOOTLOADER_VERSION) MCUBOOT_ESPDIR = $(MCUBOOT_SRCDIR)/boot/espressif
MCUBOOT_URL = https://github.com/mcu-tools/mcuboot
$(BOOTLOADER_DIR):
$(Q) mkdir -p $(BOOTLOADER_DIR) &>/dev/null
# Helpers for creating the configuration file # Helpers for creating the configuration file
cfg_en = echo "$(1)=$(if $(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),1,y)"; cfg_en = echo "$(1)=$(if $(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),1,y)";
cfg_val = echo "$(1)=$(2)"; cfg_val = echo "$(1)=$(2)";
$(BOOTLOADER_CONFIG): $(TOPDIR)/.config $(BOOTLOADER_CONFIG): $(TOPDIR)/.config $(BOOTLOADER_DIR)
$(Q) echo "Creating Bootloader configuration" $(Q) echo "Creating Bootloader configuration"
$(Q) { \ $(Q) { \
$(if $(CONFIG_ESP32S3_FLASH_4M),$(call cfg_en,CONFIG_ESPTOOLPY_FLASHSIZE_4MB)) \ $(if $(CONFIG_ESP32S3_FLASH_4M),$(call cfg_en,CONFIG_ESPTOOLPY_FLASHSIZE_4MB)) \
@ -55,12 +64,16 @@ ifeq ($(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),y)
$(Q) { \ $(Q) { \
$(call cfg_val,CONFIG_ESP_BOOTLOADER_OFFSET,0x0000) \ $(call cfg_val,CONFIG_ESP_BOOTLOADER_OFFSET,0x0000) \
$(call cfg_val,CONFIG_ESP_BOOTLOADER_SIZE,0xF000) \ $(call cfg_val,CONFIG_ESP_BOOTLOADER_SIZE,0xF000) \
$(call cfg_val,CONFIG_ESP_APPLICATION_PRIMARY_START_ADDRESS,$(CONFIG_ESP32S3_OTA_PRIMARY_SLOT_OFFSET)) \ $(call cfg_val,CONFIG_ESP_IMAGE0_PRIMARY_START_ADDRESS,$(CONFIG_ESP32S3_OTA_PRIMARY_SLOT_OFFSET)) \
$(call cfg_val,CONFIG_ESP_APPLICATION_SIZE,$(CONFIG_ESP32S3_OTA_SLOT_SIZE)) \ $(call cfg_val,CONFIG_ESP_APPLICATION_SIZE,$(CONFIG_ESP32S3_OTA_SLOT_SIZE)) \
$(call cfg_val,CONFIG_ESP_APPLICATION_SECONDARY_START_ADDRESS,$(CONFIG_ESP32S3_OTA_SECONDARY_SLOT_OFFSET)) \ $(call cfg_val,CONFIG_ESP_IMAGE0_SECONDARY_START_ADDRESS,$(CONFIG_ESP32S3_OTA_SECONDARY_SLOT_OFFSET)) \
$(call cfg_en,CONFIG_ESP_MCUBOOT_WDT_ENABLE) \ $(call cfg_en,CONFIG_ESP_MCUBOOT_WDT_ENABLE) \
$(call cfg_val,CONFIG_ESP_SCRATCH_OFFSET,$(CONFIG_ESP32S3_OTA_SCRATCH_OFFSET)) \ $(call cfg_val,CONFIG_ESP_SCRATCH_OFFSET,$(CONFIG_ESP32S3_OTA_SCRATCH_OFFSET)) \
$(call cfg_val,CONFIG_ESP_SCRATCH_SIZE,$(CONFIG_ESP32S3_OTA_SCRATCH_SIZE)) \ $(call cfg_val,CONFIG_ESP_SCRATCH_SIZE,$(CONFIG_ESP32S3_OTA_SCRATCH_SIZE)) \
$(call cfg_en,CONFIG_ESP_CONSOLE_UART) \
$(if $(CONFIG_UART0_SERIAL_CONSOLE),$(call cfg_val,CONFIG_ESP_CONSOLE_UART_NUM,0)) \
$(if $(CONFIG_UART1_SERIAL_CONSOLE),$(call cfg_val,CONFIG_ESP_CONSOLE_UART_NUM,1)) \
$(call cfg_en,CONFIG_BOOTLOADER_FLASH_XMC_SUPPORT) \
} >> $(BOOTLOADER_CONFIG) } >> $(BOOTLOADER_CONFIG)
else ifeq ($(CONFIG_ESP32S3_APP_FORMAT_LEGACY),y) else ifeq ($(CONFIG_ESP32S3_APP_FORMAT_LEGACY),y)
$(Q) { \ $(Q) { \
@ -74,20 +87,32 @@ ifeq ($(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),y)
BOOTLOADER_BIN = $(TOPDIR)/mcuboot-esp32s3.bin BOOTLOADER_BIN = $(TOPDIR)/mcuboot-esp32s3.bin
$(BOOTLOADER_BIN): $(BOOTLOADER_CONFIG) $(MCUBOOT_SRCDIR): $(BOOTLOADER_DIR)
$(Q) echo "Building Bootloader" $(Q) echo "Cloning MCUboot"
$(Q) $(BOOTLOADER_SRCDIR)/build_mcuboot.sh -c esp32s3 -s -f $(BOOTLOADER_CONFIG) $(Q) git clone --quiet $(MCUBOOT_URL) $(MCUBOOT_SRCDIR)
$(call COPYFILE, $(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32s3.bin, $(TOPDIR)) $(Q) git -C "$(MCUBOOT_SRCDIR)" checkout --quiet $(CONFIG_ESP32S2_MCUBOOT_VERSION)
$(Q) git -C "$(MCUBOOT_SRCDIR)" submodule --quiet update --init --recursive ext/mbedtls
bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_SRCDIR) $(BOOTLOADER_BIN) $(BOOTLOADER_BIN): chip/$(ESP_HAL_3RDPARTY_REPO) $(MCUBOOT_SRCDIR) $(BOOTLOADER_CONFIG)
$(Q) echo "Building Bootloader"
$(Q) $(TOOLSDIR)/build_mcuboot.sh \
-c esp32s3 \
-f $(BOOTLOADER_CONFIG) \
-p $(BOOTLOADER_DIR) \
-e $(HALDIR)
$(call COPYFILE, $(BOOTLOADER_DIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32s3.bin, $(TOPDIR))
bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_BIN)
clean_bootloader: clean_bootloader:
$(call DELDIR,$(BOOTLOADER_SRCDIR)) $(call DELDIR,$(BOOTLOADER_DIR))
$(call DELFILE,$(BOOTLOADER_CONFIG))
$(call DELFILE,$(BOOTLOADER_BIN)) $(call DELFILE,$(BOOTLOADER_BIN))
else ifeq ($(CONFIG_ESP32S3_APP_FORMAT_LEGACY),y) else ifeq ($(CONFIG_ESP32S3_APP_FORMAT_LEGACY),y)
$(BOOTLOADER_SRCDIR): $(BOOTLOADER_DIR)
$(Q) git clone $(BOOTLOADER_URL) $(BOOTLOADER_SRCDIR) -b $(BOOTLOADER_VERSION)
bootloader: $(BOOTLOADER_SRCDIR) $(BOOTLOADER_CONFIG) bootloader: $(BOOTLOADER_SRCDIR) $(BOOTLOADER_CONFIG)
$(Q) echo "Building Bootloader binaries" $(Q) echo "Building Bootloader binaries"
$(Q) $(BOOTLOADER_SRCDIR)/build_idfboot.sh -c esp32s3 -s -f $(BOOTLOADER_CONFIG) $(Q) $(BOOTLOADER_SRCDIR)/build_idfboot.sh -c esp32s3 -s -f $(BOOTLOADER_CONFIG)
@ -95,8 +120,7 @@ bootloader: $(BOOTLOADER_SRCDIR) $(BOOTLOADER_CONFIG)
$(call COPYFILE,$(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/partition-table-esp32s3.bin,$(TOPDIR)) $(call COPYFILE,$(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/partition-table-esp32s3.bin,$(TOPDIR))
clean_bootloader: clean_bootloader:
$(call DELDIR,$(BOOTLOADER_SRCDIR)) $(call DELDIR,$(BOOTLOADER_DIR))
$(call DELFILE,$(BOOTLOADER_CONFIG))
$(call DELFILE,$(TOPDIR)/bootloader-esp32s3.bin) $(call DELFILE,$(TOPDIR)/bootloader-esp32s3.bin)
$(call DELFILE,$(TOPDIR)/partition-table-esp32s3.bin) $(call DELFILE,$(TOPDIR)/partition-table-esp32s3.bin)

View File

@ -1415,6 +1415,11 @@ config ESP32S3_ESPTOOL_TARGET_SECONDARY
endchoice endchoice
config ESP32S3_MCUBOOT_VERSION
string "MCUboot version"
default "b206b99b1555ca15f790a3287e57dc98ef3df2ac"
depends on ESP32S3_APP_FORMAT_MCUBOOT
config ESP32S3_APP_MCUBOOT_HEADER_SIZE config ESP32S3_APP_MCUBOOT_HEADER_SIZE
int "Application image header size (in bytes)" int "Application image header size (in bytes)"
default 32 default 32

View File

@ -18,7 +18,6 @@
# #
############################################################################ ############################################################################
include chip/Bootloader.mk
include common/Make.defs include common/Make.defs
# The start-up, "head", file. May be either a .S or a .c file. # The start-up, "head", file. May be either a .S or a .c file.
@ -145,12 +144,44 @@ ifeq ($(CONFIG_ESP32S3_OTG_DEVICE),y)
CHIP_CSRCS += esp32s3_otg_device.c CHIP_CSRCS += esp32s3_otg_device.c
endif endif
ifeq ($(CONFIG_ESP32S3_WIRELESS),y)
include chip/Wireless.mk
endif
CHIP_CSRCS += esp32s3_rtc.c CHIP_CSRCS += esp32s3_rtc.c
ifeq ($(CONFIG_RTC_DRIVER),y) ifeq ($(CONFIG_RTC_DRIVER),y)
CHIP_CSRCS += esp32s3_rtc_lowerhalf.c CHIP_CSRCS += esp32s3_rtc_lowerhalf.c
endif endif
#############################################################################
# Espressif HAL for 3rd Party Platforms
#############################################################################
# Fetch source files and add them to build
ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty
ifndef ESP_HAL_3RDPARTY_VERSION
ESP_HAL_3RDPARTY_VERSION = 45c33111b441363e1267158186a60f42525228ca
endif
ifndef ESP_HAL_3RDPARTY_URL
ESP_HAL_3RDPARTY_URL = https://github.com/espressif/esp-hal-3rdparty.git
endif
chip/$(ESP_HAL_3RDPARTY_REPO):
$(Q) echo "Cloning Espressif HAL for 3rd Party Platforms"
$(Q) git clone --quiet $(ESP_HAL_3RDPARTY_URL) chip/$(ESP_HAL_3RDPARTY_REPO)
$(Q) echo "Espressif HAL for 3rd Party Platforms: ${ESP_HAL_3RDPARTY_VERSION}"
$(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO) checkout --quiet $(ESP_HAL_3RDPARTY_VERSION)
# Silent preprocessor warnings
CFLAGS += -Wno-undef -Wno-unused-variable
# Files that require the HAL recipe
include chip/Bootloader.mk
ifeq ($(CONFIG_ESP32S3_WIRELESS),y)
include chip/Wireless.mk
endif
distclean::
$(call DELDIR,chip/$(ESP_HAL_3RDPARTY_REPO))

View File

@ -18,26 +18,6 @@
# #
############################################################################ ############################################################################
ESP_HAL_3RDPARTY_REPO = esp-hal-3rdparty
ESP_HAL_3RDPARTY_PATH = $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)
ifndef ESP_HAL_3RDPARTY_VERSION
ESP_HAL_3RDPARTY_VERSION = 45c33111b441363e1267158186a60f42525228ca
endif
ifndef ESP_HAL_3RDPARTY_URL
ESP_HAL_3RDPARTY_URL = https://github.com/espressif/esp-hal-3rdparty.git
endif
chip/$(ESP_HAL_3RDPARTY_REPO):
$(Q) echo "Cloning Espressif HAL for 3rd Party Platforms"
$(Q) git clone --quiet $(ESP_HAL_3RDPARTY_URL) chip/$(ESP_HAL_3RDPARTY_REPO)
$(Q) echo "Espressif HAL for 3rd Party Platforms: checking out to ${ESP_HAL_3RDPARTY_VERSION}"
$(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO) checkout --quiet $(ESP_HAL_3RDPARTY_VERSION)
# Silent preprocessor warnings
CFLAGS += -Wno-undef -Wno-unused-variable
context:: chip/$(ESP_HAL_3RDPARTY_REPO) context:: chip/$(ESP_HAL_3RDPARTY_REPO)
$(Q) echo "Espressif HAL for 3rd Party Platforms: initializing submodules..." $(Q) echo "Espressif HAL for 3rd Party Platforms: initializing submodules..."
$(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO) submodule --quiet update --init --depth=1 components/mbedtls/mbedtls components/esp_phy/lib components/esp_wifi/lib components/bt/controller/lib_esp32c3_family components/esp_coex/lib $(Q) git -C chip/$(ESP_HAL_3RDPARTY_REPO) submodule --quiet update --init --depth=1 components/mbedtls/mbedtls components/esp_phy/lib components/esp_wifi/lib components/bt/controller/lib_esp32c3_family components/esp_coex/lib
@ -98,7 +78,6 @@ INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY
INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)mbedtls$(DELIM)port$(DELIM)include INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)components$(DELIM)mbedtls$(DELIM)port$(DELIM)include
INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)include$(DELIM)mbedtls INCLUDES += ${INCDIR_PREFIX}$(ARCH_SRCDIR)$(DELIM)chip$(DELIM)$(ESP_HAL_3RDPARTY_REPO)$(DELIM)nuttx$(DELIM)include$(DELIM)mbedtls
### Define Espressif's configs for mbedTLS ### Define Espressif's configs for mbedTLS
CFLAGS += ${DEFINE_PREFIX}MBEDTLS_CONFIG_FILE="<mbedtls/esp_config.h>" CFLAGS += ${DEFINE_PREFIX}MBEDTLS_CONFIG_FILE="<mbedtls/esp_config.h>"

View File

@ -43,10 +43,15 @@
* Application Image properly. * Application Image properly.
* *
* For more information, refer to the bootloader linker scripts: * For more information, refer to the bootloader linker scripts:
* https://github.com/espressif/esp-idf/blob/v4.4.2/components/bootloader/subproject/main/ld/esp32s3/bootloader.ld#L41-L47 * https://github.com/espressif/esp-idf/blob/v5.1/components/bootloader/subproject/main/ld/esp32s3/bootloader.ld#L46-L52
*/ */
#ifdef CONFIG_ESP32S3_APP_FORMAT_MCUBOOT
#define SRAM_IRAM_END 0x403ba000
#else
#define SRAM_IRAM_END 0x403cc700 #define SRAM_IRAM_END 0x403cc700
#endif
#define I_D_SRAM_OFFSET (SRAM_DIRAM_I_START - SRAM_DRAM_START) #define I_D_SRAM_OFFSET (SRAM_DIRAM_I_START - SRAM_DRAM_START)
#define SRAM_DRAM_START 0x3fc88000 #define SRAM_DRAM_START 0x3fc88000

View File

@ -22,6 +22,7 @@ CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y CONFIG_BUILTIN=y
CONFIG_ESP32S3_APP_FORMAT_MCUBOOT=y CONFIG_ESP32S3_APP_FORMAT_MCUBOOT=y
CONFIG_ESP32S3_BOOTLOADER_BUILD_FROM_SOURCE=y
CONFIG_ESP32S3_SPIFLASH=y CONFIG_ESP32S3_SPIFLASH=y
CONFIG_ESP32S3_UART0=y CONFIG_ESP32S3_UART0=y
CONFIG_FS_PROCFS=y CONFIG_FS_PROCFS=y