1#!/usr/bin/env bash 2# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD 3# SPDX-License-Identifier: Apache-2.0 4 5SCRIPT_ROOTDIR=$(dirname "$(realpath "${BASH_SOURCE[0]}")") 6MCUBOOT_ROOTDIR=$(realpath "${SCRIPT_ROOTDIR}/..") 7ESPRESSIF_ROOT="${MCUBOOT_ROOTDIR}/boot/espressif" 8IDF_PATH="${HOME}/esp-idf" 9 10set -eo pipefail 11 12prepare_environment() { 13 # Prepare the environment for ESP-IDF 14 15 . "${IDF_PATH}"/export.sh 16} 17 18build_mcuboot() { 19 local target=${1} 20 local feature=${2} 21 local img_num=${3} 22 local build_dir=".build-${target}" 23 local toolchain_file="${ESPRESSIF_ROOT}/tools/toolchain-${target}.cmake" 24 25 if [ -n "$img_num" ]; then 26 img_num="-${img_num}" 27 fi 28 local mcuboot_config="${ESPRESSIF_ROOT}/port/${target}/bootloader${img_num}.conf" 29 30 if [ -n "${feature}" ]; then 31 mcuboot_config="${mcuboot_config};${ESPRESSIF_ROOT}/ci_configs/${feature}.conf" 32 build_dir=".build-${target}-${feature}" 33 fi 34 35 # Build MCUboot for selected target 36 37 cd "${MCUBOOT_ROOTDIR}" &>/dev/null 38 cmake -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \ 39 -DMCUBOOT_TARGET="${target}" \ 40 -DMCUBOOT_CONFIG_FILE="${mcuboot_config}" \ 41 -DESP_HAL_PATH="${IDF_PATH}" \ 42 -B "${build_dir}" \ 43 "${ESPRESSIF_ROOT}" 44 cmake --build "${build_dir}"/ 45} 46 47prepare_environment 48 49if [ -n "${MCUBOOT_FEATURES}" ]; then 50 IFS=',' 51 read -ra target_list <<< "${MCUBOOT_TARGETS}" 52 read img_num <<< "${MCUBOOT_IMG_NUM}" 53 for target in "${target_list[@]}"; do 54 read -ra feature_list <<< "${MCUBOOT_FEATURES}" 55 for feature in "${feature_list[@]}"; do 56 echo "Building MCUboot for \"${target}\" with support for \"${feature}\"" 57 build_mcuboot "${target}" "${feature}" "${img_num}" 58 done 59 done 60fi 61