diff --git a/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-devkit/index.rst b/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-devkit/index.rst index e1fe2a10df..880d4af44a 100644 --- a/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-devkit/index.rst +++ b/Documentation/platforms/xtensa/esp32s3/boards/esp32s3-devkit/index.rst @@ -139,9 +139,9 @@ Flash and PSRAM). mcuboot_nsh ----------- -Similar configuration as nsh, except that it enables booting from -MCUboot and the experimental features configuration. -You can find more information on the `example's documentation `_. +This configuration is the same as the ``nsh`` configuration, but it generates the application +image in a format that can be used by MCUboot. It also makes the ``make bootloader`` command to +build the MCUboot bootloader image using the Espressif HAL. nsh --- diff --git a/arch/xtensa/src/esp32s3/.gitignore b/arch/xtensa/src/esp32s3/.gitignore index 24754aa308..172cd927bd 100644 --- a/arch/xtensa/src/esp32s3/.gitignore +++ b/arch/xtensa/src/esp32s3/.gitignore @@ -1,2 +1,3 @@ -/esp-nuttx-bootloader +/bootloader /esp-hal-3rdparty +/esp-nuttx-bootloader diff --git a/arch/xtensa/src/esp32s3/Bootloader.mk b/arch/xtensa/src/esp32s3/Bootloader.mk index 3d1a30e2f8..0b3d1a6678 100644 --- a/arch/xtensa/src/esp32s3/Bootloader.mk +++ b/arch/xtensa/src/esp32s3/Bootloader.mk @@ -18,25 +18,34 @@ # ############################################################################ +.PHONY: bootloader clean_bootloader + ifeq ($(CONFIG_ESP32S3_BOOTLOADER_BUILD_FROM_SOURCE),y) +TOOLSDIR = $(TOPDIR)/tools/espressif 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_URL = https://github.com/espressif/esp-nuttx-bootloader BOOTLOADER_OUTDIR = out -BOOTLOADER_CONFIG = $(CHIPDIR)/bootloader.conf +BOOTLOADER_CONFIG = $(BOOTLOADER_DIR)/bootloader.conf -$(BOOTLOADER_SRCDIR): - $(Q) git clone $(BOOTLOADER_URL) $(BOOTLOADER_SRCDIR) -b $(BOOTLOADER_VERSION) +MCUBOOT_SRCDIR = $(BOOTLOADER_DIR)/mcuboot +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 cfg_en = echo "$(1)=$(if $(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),1,y)"; cfg_val = echo "$(1)=$(2)"; -$(BOOTLOADER_CONFIG): $(TOPDIR)/.config +$(BOOTLOADER_CONFIG): $(TOPDIR)/.config $(BOOTLOADER_DIR) $(Q) echo "Creating Bootloader configuration" $(Q) { \ $(if $(CONFIG_ESP32S3_FLASH_4M),$(call cfg_en,CONFIG_ESPTOOLPY_FLASHSIZE_4MB)) \ @@ -55,12 +64,16 @@ ifeq ($(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),y) $(Q) { \ $(call cfg_val,CONFIG_ESP_BOOTLOADER_OFFSET,0x0000) \ $(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_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_val,CONFIG_ESP_SCRATCH_OFFSET,$(CONFIG_ESP32S3_OTA_SCRATCH_OFFSET)) \ $(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) else ifeq ($(CONFIG_ESP32S3_APP_FORMAT_LEGACY),y) $(Q) { \ @@ -74,20 +87,32 @@ ifeq ($(CONFIG_ESP32S3_APP_FORMAT_MCUBOOT),y) BOOTLOADER_BIN = $(TOPDIR)/mcuboot-esp32s3.bin -$(BOOTLOADER_BIN): $(BOOTLOADER_CONFIG) - $(Q) echo "Building Bootloader" - $(Q) $(BOOTLOADER_SRCDIR)/build_mcuboot.sh -c esp32s3 -s -f $(BOOTLOADER_CONFIG) - $(call COPYFILE, $(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32s3.bin, $(TOPDIR)) +$(MCUBOOT_SRCDIR): $(BOOTLOADER_DIR) + $(Q) echo "Cloning MCUboot" + $(Q) git clone --quiet $(MCUBOOT_URL) $(MCUBOOT_SRCDIR) + $(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: - $(call DELDIR,$(BOOTLOADER_SRCDIR)) - $(call DELFILE,$(BOOTLOADER_CONFIG)) + $(call DELDIR,$(BOOTLOADER_DIR)) $(call DELFILE,$(BOOTLOADER_BIN)) 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) $(Q) echo "Building Bootloader binaries" $(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)) clean_bootloader: - $(call DELDIR,$(BOOTLOADER_SRCDIR)) - $(call DELFILE,$(BOOTLOADER_CONFIG)) + $(call DELDIR,$(BOOTLOADER_DIR)) $(call DELFILE,$(TOPDIR)/bootloader-esp32s3.bin) $(call DELFILE,$(TOPDIR)/partition-table-esp32s3.bin) diff --git a/arch/xtensa/src/esp32s3/Kconfig b/arch/xtensa/src/esp32s3/Kconfig index 2e69cf1c0a..42760604ff 100644 --- a/arch/xtensa/src/esp32s3/Kconfig +++ b/arch/xtensa/src/esp32s3/Kconfig @@ -1415,6 +1415,11 @@ config ESP32S3_ESPTOOL_TARGET_SECONDARY endchoice +config ESP32S3_MCUBOOT_VERSION + string "MCUboot version" + default "b206b99b1555ca15f790a3287e57dc98ef3df2ac" + depends on ESP32S3_APP_FORMAT_MCUBOOT + config ESP32S3_APP_MCUBOOT_HEADER_SIZE int "Application image header size (in bytes)" default 32 diff --git a/arch/xtensa/src/esp32s3/Make.defs b/arch/xtensa/src/esp32s3/Make.defs index c7e4c47cf6..4cd5063c68 100644 --- a/arch/xtensa/src/esp32s3/Make.defs +++ b/arch/xtensa/src/esp32s3/Make.defs @@ -18,7 +18,6 @@ # ############################################################################ -include chip/Bootloader.mk include common/Make.defs # 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 endif -ifeq ($(CONFIG_ESP32S3_WIRELESS),y) -include chip/Wireless.mk -endif - CHIP_CSRCS += esp32s3_rtc.c ifeq ($(CONFIG_RTC_DRIVER),y) CHIP_CSRCS += esp32s3_rtc_lowerhalf.c 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)) diff --git a/arch/xtensa/src/esp32s3/Wireless.mk b/arch/xtensa/src/esp32s3/Wireless.mk index cd8cd93155..98a4fb657e 100644 --- a/arch/xtensa/src/esp32s3/Wireless.mk +++ b/arch/xtensa/src/esp32s3/Wireless.mk @@ -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) $(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 @@ -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)nuttx$(DELIM)include$(DELIM)mbedtls - ### Define Espressif's configs for mbedTLS CFLAGS += ${DEFINE_PREFIX}MBEDTLS_CONFIG_FILE="" diff --git a/boards/xtensa/esp32s3/common/scripts/flat_memory.ld b/boards/xtensa/esp32s3/common/scripts/flat_memory.ld index 3131e5a654..9a2acc1acb 100644 --- a/boards/xtensa/esp32s3/common/scripts/flat_memory.ld +++ b/boards/xtensa/esp32s3/common/scripts/flat_memory.ld @@ -43,10 +43,15 @@ * Application Image properly. * * 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 +#endif + #define I_D_SRAM_OFFSET (SRAM_DIRAM_I_START - SRAM_DRAM_START) #define SRAM_DRAM_START 0x3fc88000 diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/mcuboot_nsh/defconfig b/boards/xtensa/esp32s3/esp32s3-devkit/configs/mcuboot_nsh/defconfig index da2a469223..5dff764aa8 100644 --- a/boards/xtensa/esp32s3/esp32s3-devkit/configs/mcuboot_nsh/defconfig +++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/mcuboot_nsh/defconfig @@ -22,6 +22,7 @@ CONFIG_BOARDCTL_RESET=y CONFIG_BOARD_LOOPSPERMSEC=16717 CONFIG_BUILTIN=y CONFIG_ESP32S3_APP_FORMAT_MCUBOOT=y +CONFIG_ESP32S3_BOOTLOADER_BUILD_FROM_SOURCE=y CONFIG_ESP32S3_SPIFLASH=y CONFIG_ESP32S3_UART0=y CONFIG_FS_PROCFS=y