From a2673d3bcdd90766ee415463273f1ed77ac3dcd0 Mon Sep 17 00:00:00 2001 From: Tiago Medicci Serrano Date: Fri, 19 Jan 2024 15:10:03 -0300 Subject: [PATCH] esp32c3: Improve selection of the bootloader being used on Kconfig - A pre-built IDF bootloader is used by default; - `ESP32C3_PARTITION_TABLE` requires the IDF bootloader to be built from sources. - Native MCUboot also can be used to boot the device. It will be built from sources and depends on !ESP32C3_PARTITION_TABLE. --- arch/risc-v/src/esp32c3/Bootloader.mk | 14 ++---- arch/risc-v/src/esp32c3/Kconfig | 67 ++++++++++++++++----------- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/arch/risc-v/src/esp32c3/Bootloader.mk b/arch/risc-v/src/esp32c3/Bootloader.mk index bd81934dda..48e730b96f 100644 --- a/arch/risc-v/src/esp32c3/Bootloader.mk +++ b/arch/risc-v/src/esp32c3/Bootloader.mk @@ -109,12 +109,12 @@ ifeq ($(CONFIG_ESP32C3_APP_FORMAT_MCUBOOT),y) BOOTLOADER_BIN = $(TOPDIR)/mcuboot-esp32c3.bin BOOTLOADER_SIGNED_BIN = $(TOPDIR)/mcuboot-esp32c3.signed.bin -$(BOOTLOADER_BIN): $(BOOTLOADER_CONFIG) +$(BOOTLOADER_BIN): $(BOOTLOADER_SRCDIR) $(BOOTLOADER_CONFIG) $(Q) echo "Building Bootloader" $(Q) $(BOOTLOADER_SRCDIR)/build_mcuboot.sh -c esp32c3 -s -f $(BOOTLOADER_CONFIG) $(call COPYFILE, $(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32c3.bin, $(TOPDIR)) -bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_SRCDIR) $(BOOTLOADER_BIN) +bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_BIN) ifeq ($(CONFIG_ESP32C3_SECURE_BOOT),y) $(eval KEYDIR := $(TOPDIR)/$(ESPSEC_KEYDIR)) $(eval BOOTLOADER_SIGN_KEY := $(abspath $(KEYDIR)/$(subst ",,$(CONFIG_ESP32C3_SECURE_BOOT_BOOTLOADER_SIGNING_KEY)))) @@ -165,15 +165,7 @@ else ifeq ($(CONFIG_ESP32C3_BOOTLOADER_DOWNLOAD_PREBUILT),y) BOOTLOADER_VERSION = latest BOOTLOADER_URL = https://github.com/espressif/esp-nuttx-bootloader/releases/download/$(BOOTLOADER_VERSION) -ifeq ($(CONFIG_ESP32C3_APP_FORMAT_MCUBOOT),y) - -bootloader: - $(call DOWNLOAD,$(BOOTLOADER_URL),mcuboot-esp32c3.bin,$(TOPDIR)/mcuboot-esp32c3.bin) - -clean_bootloader: - $(call DELFILE,$(TOPDIR)/mcuboot-esp32c3.bin) - -else ifeq ($(CONFIG_ESP32C3_APP_FORMAT_LEGACY),y) +ifeq ($(CONFIG_ESP32C3_APP_FORMAT_LEGACY),y) bootloader: $(call DOWNLOAD,$(BOOTLOADER_URL),bootloader-esp32c3.bin,$(TOPDIR)/bootloader-esp32c3.bin) diff --git a/arch/risc-v/src/esp32c3/Kconfig b/arch/risc-v/src/esp32c3/Kconfig index a8b1caa8f3..88caa8a878 100644 --- a/arch/risc-v/src/esp32c3/Kconfig +++ b/arch/risc-v/src/esp32c3/Kconfig @@ -994,6 +994,7 @@ comment "Partition Table configuration" config ESP32C3_PARTITION_TABLE bool "Create MTD partitions from Partition Table" default n + select ESP32C3_BOOTLOADER_BUILD_FROM_SOURCE ---help--- Decode partition table and initialize partitions as MTD. @@ -1032,42 +1033,28 @@ config ESP32C3_HAVE_OTA_PARTITION bool default n -menu "Application Image Configuration" - -choice - prompt "Application Image Format" - default ESP32C3_APP_FORMAT_LEGACY - ---help--- - Depending on the chosen 2nd stage bootloader, the application may - be required to be perform a specific startup routine. Furthermore, - the image binary must be formatted according to the definition from - the 2nd stage bootloader. +menu "Bootloader and Image Configuration" config ESP32C3_APP_FORMAT_LEGACY - bool "Legacy format" + bool + default y if !ESP32C3_APP_FORMAT_MCUBOOT + depends on !ESP32C3_APP_FORMAT_MCUBOOT ---help--- This is the legacy application image format, as supported by the ESP-IDF 2nd stage bootloader. config ESP32C3_APP_FORMAT_MCUBOOT - bool "MCUboot-bootable format" + bool "Enable MCUboot-bootable format" depends on !MCUBOOT_BOOTLOADER select ESP32C3_HAVE_OTA_PARTITION + select ESP32C3_BOOTLOADER_BUILD_FROM_SOURCE ---help--- - The Espressif port of MCUboot supports the loading of unsegmented firmware - images. - -endchoice # Application Image Format - -choice - prompt "Source for bootloader binaries" - default ESP32C3_BOOTLOADER_DOWNLOAD_PREBUILT - ---help--- - Select the action to be taken by the build system for the - "make bootloader" target. + Enables the Espressif port of MCUboot to be used as 2nd stage bootloader. config ESP32C3_BOOTLOADER_DOWNLOAD_PREBUILT - bool "Download prebuilt binaries" + bool + default y if !ESP32C3_BOOTLOADER_BUILD_FROM_SOURCE + depends on !ESP32C3_BOOTLOADER_BUILD_FROM_SOURCE ---help--- The build system will download the prebuilt binaries from https://github.com/espressif/esp-nuttx-bootloader according to the chosen @@ -1081,8 +1068,6 @@ config ESP32C3_BOOTLOADER_BUILD_FROM_SOURCE custom bootloader according to the chosen Application Image Format (ESP32C3_APP_FORMAT_LEGACY or ESP32C3_APP_FORMAT_MCUBOOT) and partition information. -endchoice - choice prompt "Target slot for image flashing" default ESP32C3_ESPTOOL_TARGET_PRIMARY @@ -1113,11 +1098,37 @@ config ESP32C3_APP_MCUBOOT_HEADER_SIZE default 32 depends on ESP32C3_APP_FORMAT_MCUBOOT -config ESP32C3_PARTITION_TABLE_OFFSET - hex "Partition Table offset" +config ESP32C3_PARTITION_TABLE_OFFSET_DEFAULT + hex default 0x8000 depends on ESP32C3_APP_FORMAT_LEGACY +config ESP32C3_CUSTOM_PARTITION_TABLE_OFFSET + bool "Customize partition table offset" + default n + depends on ESP32C3_APP_FORMAT_LEGACY + select ESP32C3_BOOTLOADER_BUILD_FROM_SOURCE + ---help--- + Enable to select the offset of the partition table in the flash. + +if ESP32C3_CUSTOM_PARTITION_TABLE_OFFSET + +config ESP32C3_PARTITION_TABLE_OFFSET + hex "Partition Table offset" + default ESP32C3_PARTITION_TABLE_OFFSET_DEFAULT + depends on ESP32C3_APP_FORMAT_LEGACY + +endif # ESP32C3_CUSTOM_PARTITION_TABLE_OFFSET + +if !ESP32C3_CUSTOM_PARTITION_TABLE_OFFSET + +config ESP32C3_PARTITION_TABLE_OFFSET + hex + default ESP32C3_PARTITION_TABLE_OFFSET_DEFAULT + depends on ESP32C3_APP_FORMAT_LEGACY + +endif # !ESP32C3_CUSTOM_PARTITION_TABLE_OFFSET + if BUILD_PROTECTED config ESP32C3_USER_IMAGE_OFFSET