This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 60fdc9cb725c7a410a65289c953e89cc083e2199
Author: Lucas Saavedra Vaz <lucas....@espressif.com>
AuthorDate: Wed Aug 16 11:18:55 2023 -0300

    arch/xtensa/esp32: Update MCUboot build process
    
    Change the MCUboot build process to, in the future, deprecate the 
esp-nuttx-bootloaders repository.
---
 .../xtensa/esp32/boards/esp32-devkitc/index.rst    |  7 ++++
 arch/xtensa/src/esp32/.gitignore                   |  1 +
 arch/xtensa/src/esp32/Bootloader.mk                | 38 ++++++++++++-----
 arch/xtensa/src/esp32/Kconfig                      |  5 +++
 arch/xtensa/src/esp32/Make.defs                    | 31 +++++++++++++-
 arch/xtensa/src/esp32/bootloader/.gitignore        |  1 +
 .../esp32-devkitc/configs/mcuboot_nsh/defconfig    | 47 ++++++++++++++++++++++
 7 files changed, 119 insertions(+), 11 deletions(-)

diff --git 
a/Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst 
b/Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst
index ec376cb19e..1d23297856 100644
--- a/Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst
+++ b/Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst
@@ -461,6 +461,13 @@ Pin   Signal
 The MCP2515 interrupt (INT) pin is connected to the pin 22 of the
 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
 --------------------
 
diff --git a/arch/xtensa/src/esp32/.gitignore b/arch/xtensa/src/esp32/.gitignore
index cdf3df5616..ab19fe9ea8 100644
--- a/arch/xtensa/src/esp32/.gitignore
+++ b/arch/xtensa/src/esp32/.gitignore
@@ -1,2 +1,3 @@
+/esp-hal-3rdparty
 /esp-wireless-drivers-3rdparty
 /*.zip
diff --git a/arch/xtensa/src/esp32/Bootloader.mk 
b/arch/xtensa/src/esp32/Bootloader.mk
index 106ea9a7bd..0c2be5fde0 100644
--- a/arch/xtensa/src/esp32/Bootloader.mk
+++ b/arch/xtensa/src/esp32/Bootloader.mk
@@ -22,7 +22,9 @@
 
 ifeq ($(CONFIG_ESP32_BOOTLOADER_BUILD_FROM_SOURCE),y)
 
+TOOLSDIR           = $(TOPDIR)/tools/espressif
 CHIPDIR            = $(TOPDIR)/arch/xtensa/src/chip
+HALDIR             = $(CHIPDIR)/esp-hal-3rdparty
 
 BOOTLOADER_DIR     = $(CHIPDIR)/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_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
 
 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_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)) \
+               $(call cfg_val,CONFIG_ESP_BOOTLOADER_OFFSET,0x1000) \
                $(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_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_val,CONFIG_ESP_SCRATCH_OFFSET,$(CONFIG_ESP32_OTA_SCRATCH_OFFSET)) \
                $(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)
 else ifeq ($(CONFIG_ESP32_APP_FORMAT_LEGACY),y)
        $(Q) { \
@@ -108,15 +118,22 @@ ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y)
 BOOTLOADER_BIN        = $(TOPDIR)/mcuboot-esp32.bin
 BOOTLOADER_SIGNED_BIN = $(TOPDIR)/mcuboot-esp32.signed.bin
 
-$(BOOTLOADER_SRCDIR):
-       $(Q) git clone $(BOOTLOADER_URL) $(BOOTLOADER_SRCDIR) -b 
$(BOOTLOADER_VERSION)
+$(MCUBOOT_SRCDIR):
+       $(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) $(BOOTLOADER_SRCDIR)/build_mcuboot.sh -c esp32 -s -f 
$(BOOTLOADER_CONFIG)
-       $(call COPYFILE, 
$(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32.bin, $(TOPDIR))
-
-bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_SRCDIR) $(BOOTLOADER_BIN)
+       $(Q) $(TOOLSDIR)/build_mcuboot.sh \
+               -c esp32 \
+               -f $(BOOTLOADER_CONFIG) \
+               -p $(BOOTLOADER_DIR) \
+               -e $(HALDIR)
+       $(call COPYFILE, 
$(BOOTLOADER_DIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32.bin, $(TOPDIR))
+
+bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_BIN)
 ifeq ($(CONFIG_ESP32_SECURE_BOOT),y)
        $(eval KEYDIR := $(TOPDIR)/$(ESPSEC_KEYDIR))
        $(eval BOOTLOADER_SIGN_KEY := $(abspath $(KEYDIR)/$(subst 
",,$(CONFIG_ESP32_SECURE_BOOT_BOOTLOADER_SIGNING_KEY))))
@@ -141,7 +158,8 @@ endif
 endif
 
 clean_bootloader:
-       $(call DELDIR,$(BOOTLOADER_SRCDIR))
+       $(call DELDIR,$(MCUBOOT_SRCDIR))
+       $(call DELDIR,$(BOOTLOADER_DIR)/$(BOOTLOADER_OUTDIR))
        $(call DELFILE,$(BOOTLOADER_CONFIG))
        $(call DELFILE,$(BOOTLOADER_BIN))
        $(if $(CONFIG_ESP32_SECURE_BOOT_BUILD_SIGNED_BINARIES),$(call 
DELFILE,$(BOOTLOADER_SIGNED_BIN)))
diff --git a/arch/xtensa/src/esp32/Kconfig b/arch/xtensa/src/esp32/Kconfig
index fa2e873295..4a86dc4b4c 100644
--- a/arch/xtensa/src/esp32/Kconfig
+++ b/arch/xtensa/src/esp32/Kconfig
@@ -2478,6 +2478,11 @@ config ESP32_ESPTOOL_TARGET_SECONDARY
 
 endchoice
 
+config ESP32_MCUBOOT_VERSION
+       string "MCUboot version"
+       depends on ESP32_APP_FORMAT_MCUBOOT
+       default "b206b99b1555ca15f790a3287e57dc98ef3df2ac"
+
 config ESP32_APP_MCUBOOT_HEADER_SIZE
        int "Application image header size (in bytes)"
        default 32
diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs
index f42dfb3bcc..9978e65031 100644
--- a/arch/xtensa/src/esp32/Make.defs
+++ b/arch/xtensa/src/esp32/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.
@@ -251,3 +250,33 @@ EXTRA_LIBS += -lbtdm_app
     EXTRA_LIBS += -lcoexist
   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))
diff --git a/arch/xtensa/src/esp32/bootloader/.gitignore 
b/arch/xtensa/src/esp32/bootloader/.gitignore
index 1921db116c..5e47dafb03 100644
--- a/arch/xtensa/src/esp32/bootloader/.gitignore
+++ b/arch/xtensa/src/esp32/bootloader/.gitignore
@@ -1,2 +1,3 @@
 /esp-nuttx-bootloader
 /bootloader.conf
+/mcuboot
diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/mcuboot_nsh/defconfig 
b/boards/xtensa/esp32/esp32-devkitc/configs/mcuboot_nsh/defconfig
new file mode 100644
index 0000000000..6443f1ade7
--- /dev/null
+++ b/boards/xtensa/esp32/esp32-devkitc/configs/mcuboot_nsh/defconfig
@@ -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

Reply via email to