#!/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 --ota [host] Wi-Fi: build, sign and push a Firmware Update # (host: the device's IP from Settings > Firmware, or $RORO_OTA_HOST) # --debug (USB only): once flashed, switches the Debug Console on and gives it the token in # ~/.config/roro9stack/debug-token, over the serial port (ADR 0010, Q192), so scripts/rdbg.py works # at once. The settings survive later updates: it is needed once for a device, not at each flash. set -euo pipefail ENV=cardputer-adv PROVISION= if [ "${1:-}" = "--debug" ]; then PROVISION=1 shift fi if [ "${1:-}" = "--ota" ]; then [ -z "$PROVISION" ] || echo "flash.sh: --debug does nothing over Wi-Fi: the console's setting stays as it is on the device" >&2 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)" 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) # The token is read from the environment inside the container (_docker.sh passes it), so it is on no # command line of the host; serial_log.py prints what the device says, not what it sends. SETUP="" # serial_log.py finds the port by its name, and follows it when the device re-enumerates after the upload. [ -z "$PROVISION" ] || DOCKER_EXTRA=(--group-add "$(stat -c %g "$PORT")" --privileged -v /dev:/dev -it) [ -z "$PROVISION" ] || SETUP='&& /pio/penv/bin/python scripts/serial_log.py 8 sleep:4 "debug token $RORO_DEBUG_TOKEN" "debug on"' run_in_container bash -c "git config --global --add safe.directory /work && pio run -e $ENV -t upload --upload-port $PORT $SETUP && pio device monitor -p $PORT -b 115200"