You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2021/09/28 01:22:39 UTC
[incubator-nuttx] 04/04: risc-v/esp32c3: Enable support for "make
bootloader" target
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/incubator-nuttx.git
commit 20341e6f1730eb308b3ca4789b969df676a5c173
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Fri Sep 24 09:20:42 2021 -0300
risc-v/esp32c3: Enable support for "make bootloader" target
This enables the provisioning of the bootloader binaries through the
build system.
Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
arch/risc-v/Kconfig | 1 +
arch/risc-v/src/esp32c3/Bootloader.mk | 123 ++++++++++++++++++++++++++++++++++
arch/risc-v/src/esp32c3/Kconfig | 24 +++++++
arch/risc-v/src/esp32c3/Make.defs | 2 +
4 files changed, 150 insertions(+)
diff --git a/arch/risc-v/Kconfig b/arch/risc-v/Kconfig
index 00a3919..1c6123b 100644
--- a/arch/risc-v/Kconfig
+++ b/arch/risc-v/Kconfig
@@ -52,6 +52,7 @@ config ARCH_CHIP_ESP32C3
select LIBC_ARCH_MEMMOVE
select LIBC_ARCH_MEMSET
select ARCH_HAVE_TEXT_HEAP
+ select ARCH_HAVE_BOOTLOADER
---help---
Espressif ESP32-C3 (RV32IMC).
diff --git a/arch/risc-v/src/esp32c3/Bootloader.mk b/arch/risc-v/src/esp32c3/Bootloader.mk
new file mode 100644
index 0000000..d8be009
--- /dev/null
+++ b/arch/risc-v/src/esp32c3/Bootloader.mk
@@ -0,0 +1,123 @@
+############################################################################
+# arch/risc-v/src/esp32c3/Bootloader.mk
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+ifeq ($(CONFIG_ESP32C3_BOOTLOADER_BUILD_FROM_SOURCE),y)
+
+CHIPDIR = $(TOPDIR)/arch/xtensa/src/chip
+
+BOOTLOADER_SRCDIR = $(CHIPDIR)/esp-nuttx-bootloader
+BOOTLOADER_VERSION = main
+BOOTLOADER_URL = https://github.com/espressif/esp-nuttx-bootloader
+BOOTLOADER_OUTDIR = out
+
+$(BOOTLOADER_SRCDIR):
+ $(Q) git clone $(BOOTLOADER_URL) $(BOOTLOADER_SRCDIR) -b $(BOOTLOADER_VERSION)
+
+ifeq ($(CONFIG_ESP32C3_APP_FORMAT_MCUBOOT),y)
+
+BOOTLOADER_CONFIG = $(CHIPDIR)/mcuboot.conf
+
+$(BOOTLOADER_CONFIG): $(TOPDIR)/.config
+ $(Q) echo "Creating Bootloader configuration"
+ $(Q) { \
+ echo "CONFIG_ESP_BOOTLOADER_SIZE=0xF000"; \
+ echo "CONFIG_ESP_APPLICATION_PRIMARY_START_ADDRESS=$(CONFIG_ESP32C3_OTA_PRIMARY_SLOT_OFFSET)"; \
+ echo "CONFIG_ESP_APPLICATION_SIZE=$(CONFIG_ESP32C3_OTA_SLOT_SIZE)"; \
+ echo "CONFIG_ESP_APPLICATION_SECONDARY_START_ADDRESS=$(CONFIG_ESP32C3_OTA_SECONDARY_SLOT_OFFSET)";\
+ echo "CONFIG_ESP_MCUBOOT_WDT_ENABLE=y"; \
+ echo "CONFIG_ESP_SCRATCH_OFFSET=$(CONFIG_ESP32C3_OTA_SCRATCH_OFFSET)"; \
+ echo "CONFIG_ESP_SCRATCH_SIZE=$(CONFIG_ESP32C3_OTA_SCRATCH_SIZE)"; \
+ } > $(BOOTLOADER_CONFIG)
+
+bootloader: $(BOOTLOADER_SRCDIR) $(BOOTLOADER_CONFIG)
+ $(Q) echo "Building Bootloader binaries"
+ $(Q) $(BOOTLOADER_SRCDIR)/build_mcuboot.sh -c esp32c3 -s -f $(BOOTLOADER_CONFIG)
+ $(call COPYFILE, $(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/mcuboot-esp32c3.bin, $(TOPDIR))
+
+clean_bootloader:
+ $(call DELDIR, $(BOOTLOADER_SRCDIR))
+ $(call DELFILE, $(BOOTLOADER_CONFIG))
+ $(call DELFILE, $(TOPDIR)/mcuboot-esp32c3.bin)
+
+else ifeq ($(CONFIG_ESP32C3_APP_FORMAT_LEGACY),y)
+
+BOOTLOADER_CONFIG = $(CHIPDIR)/sdkconfig
+
+$(BOOTLOADER_CONFIG): $(TOPDIR)/.config
+ $(Q) echo "Creating Bootloader configuration"
+ $(Q) { \
+ [ "$(CONFIG_ESP32C3_FLASH_2M)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_4M)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_8M)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_16M)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_MODE_DIO)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHMODE_DIO=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_MODE_DOUT)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHMODE_DOUT=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_MODE_QIO)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHMODE_QIO=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_MODE_QOUT)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHMODE_QOUT=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_FREQ_80M)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHFREQ_80M=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_FREQ_40M)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHFREQ_40M=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_FREQ_26M)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHFREQ_26M=y"; \
+ [ "$(CONFIG_ESP32C3_FLASH_FREQ_20M)" = "y" ] && echo "CONFIG_ESPTOOLPY_FLASHFREQ_20M=y"; \
+ echo "CONFIG_PARTITION_TABLE_CUSTOM=y"; \
+ echo "CONFIG_PARTITION_TABLE_CUSTOM_FILENAME=\"partitions.csv\""; \
+ } > $(BOOTLOADER_CONFIG)
+
+bootloader: $(BOOTLOADER_SRCDIR) $(BOOTLOADER_CONFIG)
+ $(Q) echo "Building Bootloader binaries"
+ $(Q) $(BOOTLOADER_SRCDIR)/build_idfboot.sh -c esp32c3 -s -f $(BOOTLOADER_CONFIG)
+ $(call COPYFILE, $(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/bootloader-esp32c3.bin, $(TOPDIR))
+ $(call COPYFILE, $(BOOTLOADER_SRCDIR)/$(BOOTLOADER_OUTDIR)/partition-table-esp32c3.bin, $(TOPDIR))
+
+clean_bootloader:
+ $(call DELDIR, $(BOOTLOADER_SRCDIR))
+ $(call DELFILE, $(BOOTLOADER_CONFIG))
+ $(call DELFILE, $(TOPDIR)/bootloader-esp32c3.bin)
+ $(call DELFILE, $(TOPDIR)/partition-table-esp32c3.bin)
+
+endif
+
+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:
+ $(Q) echo "Downloading Bootloader binaries"
+ $(Q) curl -L $(BOOTLOADER_URL)/mcuboot-esp32c3.bin -o $(TOPDIR)/mcuboot-esp32c3.bin
+
+clean_bootloader:
+ $(call DELFILE, $(TOPDIR)/mcuboot-esp32c3.bin)
+
+else ifeq ($(CONFIG_ESP32C3_APP_FORMAT_LEGACY),y)
+
+bootloader:
+ $(Q) echo "Downloading Bootloader binaries"
+ $(Q) curl -L $(BOOTLOADER_URL)/bootloader-esp32c3.bin -o $(TOPDIR)/bootloader-esp32c3.bin
+ $(Q) curl -L $(BOOTLOADER_URL)/partition-table-esp32c3.bin -o $(TOPDIR)/partition-table-esp32c3.bin
+
+clean_bootloader:
+ $(call DELFILE, $(TOPDIR)/bootloader-esp32c3.bin)
+ $(call DELFILE, $(TOPDIR)/partition-table-esp32c3.bin)
+
+endif
+
+endif
diff --git a/arch/risc-v/src/esp32c3/Kconfig b/arch/risc-v/src/esp32c3/Kconfig
index f307375..e0866ab 100644
--- a/arch/risc-v/src/esp32c3/Kconfig
+++ b/arch/risc-v/src/esp32c3/Kconfig
@@ -966,6 +966,30 @@ comment "MCUboot support depends on CONFIG_EXPERIMENTAL"
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.
+
+config ESP32C3_BOOTLOADER_DOWNLOAD_PREBUILT
+ bool "Download prebuilt binaries"
+ ---help---
+ The build system will download the prebuilt binaries from
+ https://github.com/espressif/esp-nuttx-bootloader according to the chosen
+ Application Image Format (ESP32C3_APP_FORMAT_LEGACY or ESP32C3_APP_FORMAT_MCUBOOT)
+
+config ESP32C3_BOOTLOADER_BUILD_FROM_SOURCE
+ bool "Build binaries from source"
+ ---help---
+ The build system will build all the required binaries from source. It will clone
+ the https://github.com/espressif/esp-nuttx-bootloader repository and build a
+ 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
depends on ESP32C3_HAVE_OTA_PARTITION
diff --git a/arch/risc-v/src/esp32c3/Make.defs b/arch/risc-v/src/esp32c3/Make.defs
index 8e0b30c..5ac4124 100644
--- a/arch/risc-v/src/esp32c3/Make.defs
+++ b/arch/risc-v/src/esp32c3/Make.defs
@@ -18,6 +18,8 @@
#
############################################################################
+include chip/Bootloader.mk
+
# Specify our HEAD assembly file. This will be linked as
# the first object file, so it will appear at address 0