1.4 KiB · text History dee327e
#!/usr/bin/env bash
# `cargo run --release` lands here (see .cargo/config.toml's runner).
#
# A script rather than a runner line because two of the three flags OTA needs
# cannot be written as a constant: the bootloader lives under a content hash
# embuild chooses, and there can be more than one.
#
#   --partition-table  two app slots instead of espflash's single 3.9M factory
#   --bootloader       rollback is a BOOTLOADER feature, so espflash's bundled
#                      one (built without our sdkconfig) will not do
#   --erase-parts      otadata, so a USB flash always comes up on ota_0 rather
#                      than on whatever was last downloaded over the air
set -euo pipefail

elf=${1:?usage: flash.sh <elf> [espflash args...]}
shift

here=$(cd "$(dirname "$0")" && pwd)
cd "$here"

if build_dir=$("$here/tools/idf-build-dir.sh" release); then
    bootloader=("--bootloader" "$build_dir/bootloader/bootloader.bin")
else
    # Better to flash without it and say so than to refuse: the app still
    # boots on espflash's bundled bootloader, it just will not roll back.
    echo "flash.sh: no ESP-IDF build directory found — flashing without our" >&2
    echo "flash.sh: bootloader, so OTA rollback will NOT be active." >&2
    bootloader=()
fi

exec espflash flash --monitor \
    --partition-table "$here/partitions.csv" \
    --erase-parts otadata \
    "${bootloader[@]}" \
    "$@" \
    "$elf"