Files
openocd-utils/flash.sh
2026-04-09 12:16:42 +02:00

40 lines
726 B
Bash

#!/bin/bash
set -e
INTERFACE="swd0"
HEX_FILE=""
usage() {
echo "Usage: $0 -f <hex_file> [-i swd0|swd1]"
exit 1
}
while getopts "f:i:h" opt; do
case "$opt" in
f) HEX_FILE="$OPTARG" ;;
i)
if [[ "$OPTARG" == "swd0" || "$OPTARG" == "swd1" ]]; then
INTERFACE="$OPTARG"
else
usage
fi
;;
h) usage ;;
*) usage ;;
esac
done
[[ -n "$HEX_FILE" ]] || usage
[[ -f "$HEX_FILE" ]] || { echo "HEX file not found: $HEX_FILE"; exit 1; }
sudo openocd \
-f ./raspberrypi-${INTERFACE}.cfg \
-c "init" \
-c "reset init" \
-c "flash banks" \
-c "flash write_image $HEX_FILE" \
-c "verify_image $HEX_FILE" \
-c "reset run" \
-c "shutdown"
echo "Flashing complete."