Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Add support for building MCUboot bootloader #4

Merged
merged 5 commits into from
Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Build bootloader and partition table
- name: Build IDF bootloader and partition table
uses: docker://docker.io/espressif/idf:release-v4.3
with:
args: ./build.sh
args: ./build_idfboot.sh
- name: Build MCUboot bootloader
uses: docker://docker.io/espressif/idf:release-v4.3
with:
args: ./build_mcuboot.sh
- name: Update release
if: "github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')"
uses: eine/tip@master
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "mcuboot"]
path = mcuboot
url = https://github.com/mcu-tools/mcuboot.git
60 changes: 50 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,83 @@
[![Build Status](https://github.com/espressif/esp-nuttx-bootloader/workflows/build/badge.svg)](https://github.com/espressif/esp-nuttx-bootloader/actions?query=branch%3Amain)

# Bootloader and partition table for NuttX
# Bootloader for NuttX

This repository contains a minimal ESP-IDF project and build scripts used to produce 2nd stage bootloader and partition table binaries. Users of NuttX RTOS can download the binaries from release artifacts in this repository.
This repository contains build scripts for producing the binaries for the 2nd stage bootloader. There are two bootloader options:
- [IDF bootloader](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-guides/startup.html#second-stage-bootloader) (**default** option for NuttX images)
- [MCUboot bootloader](https://github.com/mcu-tools/mcuboot/blob/main/docs/readme-espressif.md) (for loading NuttX images built with `CONFIG_ESP32_APP_FORMAT_MCUBOOT` option)

# Obtaining the binaries
Users of NuttX RTOS can download the binaries from release artifacts in this repository.

## Downloading the latest version from Github
# Downloading the latest version from Github

Binaries built from the tip of the default branch or this repository can be obtained here:
Binaries built from the tip of the default branch of this repository can be obtained here:

## IDF bootloader

Chip | Bootloader | Partition table
-----|------------|-----------------
ESP32 | [bootloader-esp32.bin](https://github.com/espressif/esp-nuttx-bootloader/releases/download/latest/bootloader-esp32.bin) | [partition-table-esp32.bin](https://github.com/espressif/esp-nuttx-bootloader/releases/download/latest/partition-table-esp32.bin)
ESP32-S2 | [bootloader-esp32s2.bin](https://github.com/espressif/esp-nuttx-bootloader/releases/download/latest/bootloader-esp32s2.bin) | [partition-table-esp32s2.bin](https://github.com/espressif/esp-nuttx-bootloader/releases/download/latest/partition-table-esp32s2.bin)
ESP32-C3 | [bootloader-esp32c3.bin](https://github.com/espressif/esp-nuttx-bootloader/releases/download/latest/bootloader-esp32c3.bin) | [partition-table-esp32c3.bin](https://github.com/espressif/esp-nuttx-bootloader/releases/download/latest/partition-table-esp32c3.bin)

## Building locally
## MCUboot bootloader

Chip | Bootloader
-----|------------
ESP32 | [mcuboot-esp32.bin](https://github.com/espressif/esp-nuttx-bootloader/releases/download/latest/mcuboot-esp32.bin)

The prebuilt bootloader image considers the following default partitioning of the chip's SPI Flash for the application slots:

Attribute | Value
----------|-------
Application Primary slot offset | 0x10000
Application Secondary slot offset | 0x110000
Application slot size | 0x100000 (1 MiB)
Scratch slot offset | 0x210000
Scratch slot size | 0x40000 (256 KiB)

# Building locally

To build the binaries locally, it is recommended to run [build.sh](build.sh) script inside `espressif/idf` Docker image:
## IDF bootloader

It is recommended to build the binaries inside the `espressif/idf` Docker image.

```bash
git clone https://github.com/espressif/esp-nuttx-bootloader.git
cd esp-nuttx-bootloader
docker run --rm -v $PWD:/work -w /work espressif/idf:release-v4.3 ./build.sh
docker run --rm -v $PWD:/work -w /work espressif/idf:release-v4.3 ./build_idfboot.sh
```

The binaries will be inside `out` directory.

## Modifying sdkconfig or the partition table
### Modifying sdkconfig or the partition table

When building locally, you can customize bootloader configuration and the partition table by editing [sdkconfig.defaults](sdkconfig.defaults) and [partitions.csv](partitions.csv) files.

For more information about these files, refer to the following chapters of IDF Programming Guide:

* [Partition Tables](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/partition-tables.html)
* [Partition Tables](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/partition-tables.html)
* [Bootloader](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/bootloader.html)
* [Configuration Options Reference](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/kconfig.html#configuration-options-reference)


## MCUboot bootloader

It is recommended to build the binaries inside the `espressif/idf` Docker image.

```bash
git clone https://github.com/espressif/esp-nuttx-bootloader.git
cd esp-nuttx-bootloader
docker run --rm -v $PWD:/work -w /work espressif/idf:release-v4.3 ./build_mcuboot.sh
```

The binaries will be inside `out` directory.

### Modifying the application slots attributes

When building locally, you may customize the bootloader default attributes by editing [mcuboot.conf](mcuboot.conf) file.
Remember to mirror the customized configuration on the application firmware image.

# License

This repository and the binaries on the Releases page are distributed under Apache 2.0, the same as the license of ESP-IDF.
File renamed without changes.
29 changes: 29 additions & 0 deletions build_mcuboot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
#
# Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
#
# SPDX-License-Identifier: Apache-2.0
#

set -euo pipefail

targets="esp32"
mcuboot_config="${PWD}/mcuboot.conf"
output_dir="${PWD}/out"

mkdir -p "${output_dir}"

git submodule update --init mcuboot
pushd mcuboot &>/dev/null

git submodule update --init --recursive ext/mbedtls
cd boot/espressif

for target in ${targets}; do
cmake -DCMAKE_TOOLCHAIN_FILE=tools/toolchain-"${target}".cmake -DMCUBOOT_TARGET="${target}" -DMCUBOOT_CONFIG_FILE="${mcuboot_config}" -DIDF_PATH="${IDF_PATH}" -B build -GNinja
cmake --build build/
"${IDF_PATH}"/components/esptool_py/esptool/esptool.py --chip "${target}" elf2image --flash_mode dio --flash_freq 40m -o build/mcuboot-"${target}".bin build/mcuboot_"${target}".elf
cp build/mcuboot-"${target}".bin "${output_dir}"/mcuboot-"${target}".bin
done

popd &>/dev/null
1 change: 1 addition & 0 deletions mcuboot
Submodule mcuboot added at d36324
7 changes: 7 additions & 0 deletions mcuboot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CONFIG_ESP_BOOTLOADER_SIZE=0xF000
CONFIG_ESP_APPLICATION_PRIMARY_START_ADDRESS=0x10000
CONFIG_ESP_APPLICATION_SIZE=0x100000
CONFIG_ESP_APPLICATION_SECONDARY_START_ADDRESS=0x110000
CONFIG_ESP_MCUBOOT_WDT_ENABLE=y
CONFIG_ESP_SCRATCH_OFFSET=0x210000
CONFIG_ESP_SCRATCH_SIZE=0x40000