diff --git a/autoflash.sh b/autoflash.sh new file mode 100755 index 0000000..766f255 --- /dev/null +++ b/autoflash.sh @@ -0,0 +1,83 @@ +#!/bin/bash + +# ๐Ÿง  Show help message +function show_help() { + echo "Usage: $0 [-d device] [-i index] TopModuleName" + echo + echo "Arguments:" + echo " -d Name of the USB device (e.g., DOnbUsb), optional (default: DOnbUsb)" + echo " -i Interface index, optional (default: 0)" + echo " TopModule Name of the top module (e.g., VGATimingGenerator)" + exit 1 +} + +# ๐Ÿ”ง Default values +DEVICE="DOnbUsb" +INDEX=0 + +# ๐Ÿงฉ Parse arguments +while [[ "$1" =~ ^- ]]; do + case "$1" in + -d) + shift + DEVICE="$1" + ;; + -i) + shift + INDEX="$1" + ;; + -h|--help) + show_help + ;; + *) + echo "โŒ Unknown option: $1" + show_help + ;; + esac + shift +done + +# ๐Ÿ“› Get top module name +TOPMODULE="$1" + +if [ -z "$TOPMODULE" ]; then + echo "โŒ Error: No top module specified." + show_help +fi + +# ๐Ÿ“‚ Path to bitstream file +BITFILE="working/${TOPMODULE}.bit" + +# ๐Ÿ“ก Flashing function +function flash_bitstream() { + echo "โšก Flashing bitstream to device $DEVICE, index $INDEX..." + yes Y | djtgcfg prog -d "$DEVICE" -i "$INDEX" -f "$BITFILE" +} + +# ๐Ÿงน Cleanup on Ctrl+C +function cleanup() { + echo + echo "๐Ÿ‘‹ Terminated. Auto-flashing is no longer active." + exit 0 +} +trap cleanup SIGINT + +# ๐Ÿ” Initial check +if [ -f "$BITFILE" ]; then + echo "๐Ÿ“ฆ Bitstream file $BITFILE found. Starting initial flash..." + flash_bitstream + echo "โœ… Initial flash completed. Waiting for changes..." +else + echo "โš ๏ธ Bitstream file $BITFILE does not exist yet. Waiting for initial creation..." +fi + +echo "๐Ÿ‘‚ Monitoring $BITFILE for changes... (Press Ctrl+C to exit)" + +# โ™ป๏ธ Infinite watch loop +while true; do + inotifywait -e close_write "$BITFILE" >/dev/null 2>&1 + echo "๐ŸŒ€ Change detected. Waiting 1 second..." + sleep 1 + flash_bitstream + echo "โœ… Done. Waiting for next change..." +done