arch/xtensa/esp32: 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-16 11:18:55 -03:00 committed by Xiang Xiao
parent 4af8927829
commit 60fdc9cb72
7 changed files with 118 additions and 10 deletions

View File

@ -461,6 +461,13 @@ Pin Signal
The MCP2515 interrupt (INT) pin is connected to the pin 22 of the The MCP2515 interrupt (INT) pin is connected to the pin 22 of the
ESP32-Devkit. ESP32-Devkit.
mcuboot_nsh
--------------------
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.
mcuboot_slot_confirm mcuboot_slot_confirm
-------------------- --------------------

View File

@ -1,2 +1,3 @@
/esp-hal-3rdparty
/esp-wireless-drivers-3rdparty /esp-wireless-drivers-3rdparty
/*.zip /*.zip

View File

@ -22,7 +22,9 @@
ifeq ($(CONFIG_ESP32_BOOTLOADER_BUILD_FROM_SOURCE),y) ifeq ($(CONFIG_ESP32_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_DIR = $(CHIPDIR)/bootloader BOOTLOADER_DIR = $(CHIPDIR)/bootloader
BOOTLOADER_SRCDIR = $(BOOTLOADER_DIR)/esp-nuttx-bootloader BOOTLOADER_SRCDIR = $(BOOTLOADER_DIR)/esp-nuttx-bootloader
@ -31,6 +33,10 @@ BOOTLOADER_URL = https://github.com/espressif/esp-nuttx-bootloader
BOOTLOADER_OUTDIR = out BOOTLOADER_OUTDIR = out
BOOTLOADER_CONFIG = $(BOOTLOADER_DIR)/bootloader.conf BOOTLOADER_CONFIG = $(BOOTLOADER_DIR)/bootloader.conf
MCUBOOT_SRCDIR = $(BOOTLOADER_DIR)/mcuboot
MCUBOOT_ESPDIR = $(MCUBOOT_SRCDIR)/boot/espressif
MCUBOOT_URL = https://github.com/mcu-tools/mcuboot
# Helpers for creating the configuration file # Helpers for creating the configuration file
cfg_en = echo "$(1)=$(if $(CONFIG_ESP32_APP_FORMAT_MCUBOOT),1,y)"; cfg_en = echo "$(1)=$(if $(CONFIG_ESP32_APP_FORMAT_MCUBOOT),1,y)";
@ -87,13 +93,17 @@ ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
$(if $(CONFIG_ESP32_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC),$(call cfg_en,CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC)) \ $(if $(CONFIG_ESP32_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC),$(call cfg_en,CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC)) \
$(if $(CONFIG_ESP32_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE),$(call cfg_en,CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE)) \ $(if $(CONFIG_ESP32_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE),$(call cfg_en,CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE)) \
$(if $(CONFIG_ESP32_SECURE_FLASH_REQUIRE_ALREADY_ENABLED),$(call cfg_en,CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED)) \ $(if $(CONFIG_ESP32_SECURE_FLASH_REQUIRE_ALREADY_ENABLED),$(call cfg_en,CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED)) \
$(call cfg_val,CONFIG_ESP_BOOTLOADER_OFFSET,0x1000) \
$(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_ESP32_OTA_PRIMARY_SLOT_OFFSET)) \ $(call cfg_val,CONFIG_ESP_IMAGE0_PRIMARY_START_ADDRESS,$(CONFIG_ESP32_OTA_PRIMARY_SLOT_OFFSET)) \
$(call cfg_val,CONFIG_ESP_APPLICATION_SIZE,$(CONFIG_ESP32_OTA_SLOT_SIZE)) \ $(call cfg_val,CONFIG_ESP_APPLICATION_SIZE,$(CONFIG_ESP32_OTA_SLOT_SIZE)) \
$(call cfg_val,CONFIG_ESP_APPLICATION_SECONDARY_START_ADDRESS,$(CONFIG_ESP32_OTA_SECONDARY_SLOT_OFFSET)) \ $(call cfg_val,CONFIG_ESP_IMAGE0_SECONDARY_START_ADDRESS,$(CONFIG_ESP32_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_ESP32_OTA_SCRATCH_OFFSET)) \ $(call cfg_val,CONFIG_ESP_SCRATCH_OFFSET,$(CONFIG_ESP32_OTA_SCRATCH_OFFSET)) \
$(call cfg_val,CONFIG_ESP_SCRATCH_SIZE,$(CONFIG_ESP32_OTA_SCRATCH_SIZE)) \ $(call cfg_val,CONFIG_ESP_SCRATCH_SIZE,$(CONFIG_ESP32_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)) \
} >> $(BOOTLOADER_CONFIG) } >> $(BOOTLOADER_CONFIG)
else ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y) else ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
$(Q) { \ $(Q) { \
@ -108,15 +118,22 @@ ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
BOOTLOADER_BIN = $(TOPDIR)/mcuboot-esp32.bin BOOTLOADER_BIN = $(TOPDIR)/mcuboot-esp32.bin
BOOTLOADER_SIGNED_BIN = $(TOPDIR)/mcuboot-esp32.signed.bin BOOTLOADER_SIGNED_BIN = $(TOPDIR)/mcuboot-esp32.signed.bin
$(BOOTLOADER_SRCDIR): $(MCUBOOT_SRCDIR):
$(Q) git clone $(BOOTLOADER_URL) $(BOOTLOADER_SRCDIR) -b $(BOOTLOADER_VERSION) $(Q) echo "Cloning MCUboot"
$(Q) git clone --quiet $(MCUBOOT_URL) $(MCUBOOT_SRCDIR)
$(Q) git -C "$(MCUBOOT_SRCDIR)" checkout --quiet $(CONFIG_ESP32_MCUBOOT_VERSION)
$(Q) git -C "$(MCUBOOT_SRCDIR)" submodule --quiet update --init --recursive ext/mbedtls
$(BOOTLOADER_BIN): $(BOOTLOADER_CONFIG) $(BOOTLOADER_BIN): chip/$(ESP_HAL_3RDPARTY_REPO) $(MCUBOOT_SRCDIR) $(BOOTLOADER_CONFIG)
$(Q) echo "Building Bootloader" $(Q) echo "Building Bootloader"
$(Q) $(BOOTLOADER_SRCDIR)/build_mcuboot.sh -c esp32 -s -f $(BOOTLOADER_CONFIG) $(Q) $(TOOLSDIR)/build_mcuboot.sh \
$(call COPYFILE, $(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32.bin, $(TOPDIR)) -c esp32 \
-f $(BOOTLOADER_CONFIG) \
-p $(BOOTLOADER_DIR) \
-e $(HALDIR)
$(call COPYFILE, $(BOOTLOADER_DIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32.bin, $(TOPDIR))
bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_SRCDIR) $(BOOTLOADER_BIN) bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_BIN)
ifeq ($(CONFIG_ESP32_SECURE_BOOT),y) ifeq ($(CONFIG_ESP32_SECURE_BOOT),y)
$(eval KEYDIR := $(TOPDIR)/$(ESPSEC_KEYDIR)) $(eval KEYDIR := $(TOPDIR)/$(ESPSEC_KEYDIR))
$(eval BOOTLOADER_SIGN_KEY := $(abspath $(KEYDIR)/$(subst ",,$(CONFIG_ESP32_SECURE_BOOT_BOOTLOADER_SIGNING_KEY)))) $(eval BOOTLOADER_SIGN_KEY := $(abspath $(KEYDIR)/$(subst ",,$(CONFIG_ESP32_SECURE_BOOT_BOOTLOADER_SIGNING_KEY))))
@ -141,7 +158,8 @@ endif
endif endif
clean_bootloader: clean_bootloader:
$(call DELDIR,$(BOOTLOADER_SRCDIR)) $(call DELDIR,$(MCUBOOT_SRCDIR))
$(call DELDIR,$(BOOTLOADER_DIR)/$(BOOTLOADER_OUTDIR))
$(call DELFILE,$(BOOTLOADER_CONFIG)) $(call DELFILE,$(BOOTLOADER_CONFIG))
$(call DELFILE,$(BOOTLOADER_BIN)) $(call DELFILE,$(BOOTLOADER_BIN))
$(if $(CONFIG_ESP32_SECURE_BOOT_BUILD_SIGNED_BINARIES),$(call DELFILE,$(BOOTLOADER_SIGNED_BIN))) $(if $(CONFIG_ESP32_SECURE_BOOT_BUILD_SIGNED_BINARIES),$(call DELFILE,$(BOOTLOADER_SIGNED_BIN)))

View File

@ -2478,6 +2478,11 @@ config ESP32_ESPTOOL_TARGET_SECONDARY
endchoice endchoice
config ESP32_MCUBOOT_VERSION
string "MCUboot version"
depends on ESP32_APP_FORMAT_MCUBOOT
default "b206b99b1555ca15f790a3287e57dc98ef3df2ac"
config ESP32_APP_MCUBOOT_HEADER_SIZE config ESP32_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.
@ -251,3 +250,33 @@ EXTRA_LIBS += -lbtdm_app
EXTRA_LIBS += -lcoexist EXTRA_LIBS += -lcoexist
endif endif
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
include chip/Bootloader.mk
distclean::
$(call DELDIR,chip/$(ESP_HAL_3RDPARTY_REPO))

View File

@ -1,2 +1,3 @@
/esp-nuttx-bootloader /esp-nuttx-bootloader
/bootloader.conf /bootloader.conf
/mcuboot

View File

@ -0,0 +1,47 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_LEDS is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="xtensa"
CONFIG_ARCH_BOARD="esp32-devkitc"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32_DEVKITC=y
CONFIG_ARCH_CHIP="esp32"
CONFIG_ARCH_CHIP_ESP32=y
CONFIG_ARCH_CHIP_ESP32WROVER=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH_XTENSA=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_ESP32_APP_FORMAT_MCUBOOT=y
CONFIG_ESP32_BOOTLOADER_BUILD_FROM_SOURCE=y
CONFIG_ESP32_UART0=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_IDLETHREAD_STACKSIZE=3072
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_MM_REGIONS=3
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_SYSLOG_BUFFER=y
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y