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 2024/07/16 02:31:08 UTC
(nuttx) 05/05: esp32[c3]: Add mcuboot build script for esp32c3-legacy
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 0df037855a34e3bf10e96017be0bd399a10846c1
Author: Eren Terzioglu <er...@espressif.com>
AuthorDate: Thu Jul 11 17:26:50 2024 +0200
esp32[c3]: Add mcuboot build script for esp32c3-legacy
---
arch/risc-v/src/esp32c3-legacy/Bootloader.mk | 2 +-
tools/espressif/build_mcuboot_esp32c3_legacy.sh | 136 ++++++++++++++++++++++++
2 files changed, 137 insertions(+), 1 deletion(-)
diff --git a/arch/risc-v/src/esp32c3-legacy/Bootloader.mk b/arch/risc-v/src/esp32c3-legacy/Bootloader.mk
index ac636e610d..bedd5e4604 100644
--- a/arch/risc-v/src/esp32c3-legacy/Bootloader.mk
+++ b/arch/risc-v/src/esp32c3-legacy/Bootloader.mk
@@ -125,7 +125,7 @@ $(MCUBOOT_SRCDIR):
$(BOOTLOADER_BIN): chip/$(ESP_HAL_3RDPARTY_REPO) $(MCUBOOT_SRCDIR) $(BOOTLOADER_CONFIG)
$(Q) echo "Building Bootloader"
- $(Q) $(TOOLSDIR)/build_mcuboot.sh \
+ $(Q) $(TOOLSDIR)/build_mcuboot_esp32c3_legacy.sh \
-c esp32c3 \
-f $(BOOTLOADER_CONFIG) \
-p $(BOOTLOADER_DIR) \
diff --git a/tools/espressif/build_mcuboot_esp32c3_legacy.sh b/tools/espressif/build_mcuboot_esp32c3_legacy.sh
new file mode 100755
index 0000000000..6362ea50d4
--- /dev/null
+++ b/tools/espressif/build_mcuboot_esp32c3_legacy.sh
@@ -0,0 +1,136 @@
+#!/usr/bin/env bash
+
+SCRIPT_NAME=$(basename "${BASH_SOURCE[0]}")
+
+usage() {
+ echo ""
+ echo "USAGE: ${SCRIPT_NAME} [-h] -c <chip> -f <config> -p <path> -e <hal>"
+ echo ""
+ echo "Where:"
+ echo " -c <chip> Target chip"
+ echo " -f <config> Path to file containing configuration options"
+ echo " -p <path> Path to execute the script"
+ echo " -e <hal> Path to HAL directory"
+ echo " -h Show usage and terminate"
+ echo ""
+}
+
+build_mcuboot() {
+ local target=${1}
+ local config=${2}
+ local mcuboot_dir="${exec_path}/mcuboot"
+ local build_dir=".build-${target}"
+ local source_dir="boot/espressif"
+ local output_dir="${exec_path}/out"
+ local toolchain_file="tools/toolchain-${target}.cmake"
+ local mcuboot_config
+ local mcuboot_flashsize
+ local mcuboot_flashmode
+ local mcuboot_flashfreq
+ local make_generator
+
+ mcuboot_config=$(realpath "${config:-${exec_path}/mcuboot.conf}")
+
+ # Try parsing Flash parameters from the mcuboot config file.
+ # If not found, let's assume some commonplace values.
+
+ mcuboot_flashsize=$(sed -n 's/^CONFIG_ESPTOOLPY_FLASHSIZE_\(.*\)MB=1/\1MB/p' "${mcuboot_config}")
+ if [ -z "${mcuboot_flashsize}" ]; then
+ mcuboot_flashsize="4MB"
+ fi
+
+ mcuboot_flashmode=$(sed -n 's/^CONFIG_ESPTOOLPY_FLASHMODE_\(.*\)=1/\L\1/p' "${mcuboot_config}")
+ if [ -z "${mcuboot_flashmode}" ]; then
+ mcuboot_flashmode="dio"
+ fi
+
+ mcuboot_flashfreq=$(sed -n 's/^CONFIG_ESPTOOLPY_FLASHFREQ_\(.*\)M=1/\1m/p' "${mcuboot_config}")
+ if [ -z "${mcuboot_flashfreq}" ]; then
+ mcuboot_flashfreq="40m"
+ fi
+
+ pushd "${exec_path}" &>/dev/null
+ mkdir -p "${output_dir}" &>/dev/null
+
+ # Build with Ninja if installed
+
+ if command -v ninja &>/dev/null; then
+ make_generator="-GNinja"
+ fi
+
+ # Build bootloader for selected target
+
+ cd "${mcuboot_dir}" &>/dev/null
+ cmake -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \
+ -DMCUBOOT_TARGET="${target}" \
+ -DMCUBOOT_CONFIG_FILE="${mcuboot_config}" \
+ -DESP_HAL_PATH="${esp_hal}" \
+ -DCONFIG_ESP_FLASH_SIZE="${mcuboot_flashsize}" \
+ -DESP_FLASH_MODE="${mcuboot_flashmode}" \
+ -DESP_FLASH_FREQ="${mcuboot_flashfreq}" \
+ -B "${build_dir}" \
+ "${make_generator}" \
+ "${source_dir}"
+ cmake --build "${build_dir}"/
+
+ # Copy bootloader binary file to output directory
+
+ cp "${build_dir}"/mcuboot_"${target}".bin "${output_dir}"/mcuboot-"${target}".bin &>/dev/null
+
+ # Remove build directory
+
+ rm -rf "${build_dir}" &>/dev/null
+
+ popd &>/dev/null
+}
+
+while getopts ":hc:f:p:e:" arg; do
+ case "${arg}" in
+ c)
+ chip=${OPTARG}
+ ;;
+ f)
+ config=${OPTARG}
+ ;;
+ p)
+ exec_path=${OPTARG}
+ ;;
+ e)
+ esp_hal=${OPTARG}
+ ;;
+ h)
+ usage
+ exit 0
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
+ esac
+done
+
+if [ -z "${chip}" ]; then
+ printf "ERROR: Missing target chip.\n"
+ usage
+ exit 1
+fi
+
+if ! [ -d "${esp_hal}" ]; then
+ printf "ERROR: Invalid HAL path.\n"
+ usage
+ exit 1
+fi
+
+if [ ! -d "${exec_path}" ]; then
+ printf "ERROR: Invalid exec path.\n"
+ usage
+ exit 1
+fi
+
+if [ -n "${config}" ] && [ ! -f "${config}" ]; then
+ printf "ERROR: Configuration file %s not found.\n" "${config}"
+ usage
+ exit 1
+fi
+
+build_mcuboot "${chip}" "${config}"