#!/usr/bin/env bash # Flash the firmware over USB, then open the serial monitor. # Usage: scripts/flash.sh [--debug] [port] USB (default: the first Espressif device found) # scripts/flash.sh [--debug] --ota [host] Wi-Fi: build, sign and push a Firmware Update # (host: the device's IP from Settings > About, or $RORO_OTA_HOST) # --debug builds the Debug Build (cardputer-adv-debug): the Debug Console on TCP 2323, see ADR 0004. set -euo pipefail ENV=cardputer-adv if [ "${1:-}" = "--debug" ]; then ENV=cardputer-adv-debug shift fi if [ "${1:-}" = "--ota" ]; then ROOT="$(cd "$(dirname "$0")/.." && pwd)" HOST="${2:-${RORO_OTA_HOST:-}}" [ -n "$HOST" ] || { echo "Usage: scripts/flash.sh --ota (or set RORO_OTA_HOST)" >&2; exit 1; } source "$(dirname "$0")/_docker.sh" DOCKER_EXTRA=() run_in_container bash -c "git config --global --add safe.directory /work && pio run -e $ENV" | tail -3 VERSION="$(git -C "$ROOT" describe --tags --always --dirty)" [ "$ENV" = cardputer-adv-debug ] && VERSION="$VERSION+debug" # as scripts/version.py names it OUT="$ROOT/.pio/build/$ENV/roro9stack-$VERSION.ota" "$ROOT/scripts/make_ota.py" "$ROOT/.pio/build/$ENV/firmware.bin" "$VERSION" "$OUT" exec "$ROOT/scripts/ota_push.py" "$OUT" "$HOST" fi PORT="${1:-$(readlink -f /dev/serial/by-id/*Espressif* 2>/dev/null | head -1)}" [ -n "$PORT" ] || { echo "No Cardputer found on USB (is it plugged in / attached to the VM?)" >&2; exit 1; } source "$(dirname "$0")/_docker.sh" docker rm -f roro9stack-serial >/dev/null 2>&1 || true # a serial log would hold the port DOCKER_EXTRA=(--device "$PORT" --group-add "$(stat -c %g "$PORT")" -it) run_in_container bash -c "git config --global --add safe.directory /work && pio run -e $ENV -t upload --upload-port $PORT && pio device monitor -p $PORT -b 115200"