diff --git a/arch/risc-v/src/common/espressif/Bootloader.mk b/arch/risc-v/src/common/espressif/Bootloader.mk index bc81defebe..b622a9da1d 100644 --- a/arch/risc-v/src/common/espressif/Bootloader.mk +++ b/arch/risc-v/src/common/espressif/Bootloader.mk @@ -34,6 +34,7 @@ BOOTLOADER_CONFIG = $(BOOTLOADER_SRCDIR)/bootloader.conf MCUBOOT_SRCDIR = $(BOOTLOADER_SRCDIR)/mcuboot MCUBOOT_ESPDIR = $(MCUBOOT_SRCDIR)/boot/espressif MCUBOOT_URL = https://github.com/mcu-tools/mcuboot +MCUBOOT_TOOLCHAIN = $(TOOLSDIR)/mcuboot_toolchain_espressif.cmake # Helpers for creating the configuration file @@ -95,7 +96,8 @@ $(BOOTLOADER_BIN): chip/$(ESP_HAL_3RDPARTY_REPO) $(MCUBOOT_SRCDIR) $(BOOTLOADER_ -c $(CHIP_SERIES) \ -f $(BOOTLOADER_CONFIG) \ -p $(BOOTLOADER_SRCDIR) \ - -e $(HALDIR) + -e $(HALDIR) \ + -d $(MCUBOOT_TOOLCHAIN) $(call COPYFILE, $(BOOTLOADER_OUTDIR)/mcuboot-$(CHIP_SERIES).bin, $(TOPDIR)) bootloader: $(BOOTLOADER_CONFIG) $(BOOTLOADER_BIN) diff --git a/tools/espressif/build_mcuboot.sh b/tools/espressif/build_mcuboot.sh index 6362ea50d4..e46fcb8f39 100755 --- a/tools/espressif/build_mcuboot.sh +++ b/tools/espressif/build_mcuboot.sh @@ -11,6 +11,7 @@ usage() { echo " -f Path to file containing configuration options" echo " -p Path to execute the script" echo " -e Path to HAL directory" + echo " -d Path to toolchain file" echo " -h Show usage and terminate" echo "" } @@ -22,7 +23,7 @@ build_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 toolchain_file="tools/nuttx-toolchain-${target}.cmake" local mcuboot_config local mcuboot_flashsize local mcuboot_flashmode @@ -49,6 +50,12 @@ build_mcuboot() { mcuboot_flashfreq="40m" fi + if ! [ -z "${nuttx_toolchain}" ]; then + cp "${nuttx_toolchain}" "${mcuboot_dir}/${source_dir}/${toolchain_file}" + else + toolchain_file="tools/toolchain-${target}.cmake" + fi + pushd "${exec_path}" &>/dev/null mkdir -p "${output_dir}" &>/dev/null @@ -84,7 +91,7 @@ build_mcuboot() { popd &>/dev/null } -while getopts ":hc:f:p:e:" arg; do +while getopts ":hc:f:p:e:d:" arg; do case "${arg}" in c) chip=${OPTARG} @@ -98,6 +105,9 @@ while getopts ":hc:f:p:e:" arg; do e) esp_hal=${OPTARG} ;; + d) + nuttx_toolchain=${OPTARG} + ;; h) usage exit 0 diff --git a/tools/espressif/mcuboot_toolchain_espressif.cmake b/tools/espressif/mcuboot_toolchain_espressif.cmake new file mode 100644 index 0000000000..bfefd437c8 --- /dev/null +++ b/tools/espressif/mcuboot_toolchain_espressif.cmake @@ -0,0 +1,35 @@ +# ############################################################################## +# tools/espressif/mcuboot_toolchain_espressif.cmake +# +# 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. +# +# ############################################################################## + +set(CMAKE_SYSTEM_NAME Generic) + +set(CMAKE_C_COMPILER riscv-none-elf-gcc) +set(CMAKE_CXX_COMPILER riscv-none-elf-g++) +set(CMAKE_ASM_COMPILER riscv-none-elf-gcc) + +set(CMAKE_C_FLAGS + "-march=rv32imc_zicsr_zifencei" + CACHE STRING "C Compiler Base Flags") +set(CMAKE_CXX_FLAGS + "-march=rv32imc_zicsr_zifencei" + CACHE STRING "C++ Compiler Base Flags") +set(CMAKE_EXE_LINKER_FLAGS + "-nostartfiles -march=rv32imc_zicsr_zifencei --specs=nosys.specs" + CACHE STRING "Linker Base Flags")