#!/bin/bash

# USB Flash with Segger J-Link Plus Compact
BIN="/usr/bin/JFlashExe"
PROJECT="config/segger_flash.jflash"
BOOTLOADER="cmake-build-release/bootloader/telemetry-controller-bootloader.bin"
APPLICATION="cmake-build-release/application/telemetry-controller.bin"
LOG="/tmp/jflash_$(date +%s).log"

clear && echo "Flashing target"
"${BIN}" \
  -openprj"${PROJECT}" \
  -open"${BOOTLOADER}" \
  -merge"${APPLICATION}",0x4000 \
  -jflashlog"${LOG}" \
  -auto -hide -startapp -exit -nogui

echo "Log file written to ${LOG}"
cat "${LOG}"
