blob: 30e10820fb787e99b2a422441da1a8da438be94f [file] [log] [blame]
Gustavo Henrique Nihei38453f62021-11-03 15:00:19 -03001#!/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="${ESPRESSIF_ROOT}/hal/esp-idf"
9
10set -eo pipefail
11
Gustavo Henrique Nihei67b73d32021-12-09 17:05:10 -030012prepare_environment() {
Gustavo Henrique Nihei38453f62021-11-03 15:00:19 -030013 # Prepare the environment for ESP-IDF
14
15 . "${IDF_PATH}"/export.sh
Gustavo Henrique Nihei67b73d32021-12-09 17:05:10 -030016}
17
18build_mcuboot() {
Gustavo Henrique Niheid6e98102021-12-28 14:05:52 -030019 local target=${1}
20 local feature=${2}
Gustavo Henrique Nihei67b73d32021-12-09 17:05:10 -030021 local toolchain_file="${ESPRESSIF_ROOT}/tools/toolchain-${target}.cmake"
Almir Okatofa173df2022-04-19 01:10:30 -030022 local mcuboot_config="${ESPRESSIF_ROOT}/port/${target}/bootloader.conf"
Gustavo Henrique Nihei67b73d32021-12-09 17:05:10 -030023 local build_dir=".build-${target}"
24
25 if [ -n "${feature}" ]; then
Almir Okatofa173df2022-04-19 01:10:30 -030026 mcuboot_config="${mcuboot_config};${ESPRESSIF_ROOT}/secureboot-${feature}.conf"
Gustavo Henrique Nihei67b73d32021-12-09 17:05:10 -030027 build_dir=".build-${target}-${feature}"
28 fi
Gustavo Henrique Nihei38453f62021-11-03 15:00:19 -030029
30 # Build MCUboot for selected target
31
32 cd "${MCUBOOT_ROOTDIR}" &>/dev/null
33 cmake -DCMAKE_TOOLCHAIN_FILE="${toolchain_file}" \
34 -DMCUBOOT_TARGET="${target}" \
35 -DMCUBOOT_CONFIG_FILE="${mcuboot_config}" \
36 -DIDF_PATH="${IDF_PATH}" \
37 -B "${build_dir}" \
38 "${ESPRESSIF_ROOT}"
39 cmake --build "${build_dir}"/
40}
41
Gustavo Henrique Nihei67b73d32021-12-09 17:05:10 -030042prepare_environment
43
44if [ -n "${MCUBOOT_FEATURES}" ]; then
45 IFS=','
Gustavo Henrique Niheid6e98102021-12-28 14:05:52 -030046 read -ra target_list <<< "${MCUBOOT_TARGETS}"
47 for target in "${target_list[@]}"; do
48 read -ra feature_list <<< "${MCUBOOT_FEATURES}"
49 for feature in "${feature_list[@]}"; do
50 echo "Building MCUboot for \"${target}\" with support for \"${feature}\""
51 build_mcuboot "${target}" "${feature}"
52 done
Gustavo Henrique Nihei67b73d32021-12-09 17:05:10 -030053 done
54fi