#!/bin/bash if [ $# == 0 ] then cat << EOF miniprohex by Al Williams http://www.awce.com Usage: miniprohex [--offset offset] [--unfill byte size] [--obs blksize] [--line-length length] [minipro_options] -r filename.ext miniprohex [--offset offset] [minipro_options] -w filename.ext This calls minipro after converting known file types to .bin for writing or converting bin files after reading. --offset: Offset for file conversion (see srec_cat) --unfill: Unfil blocks of at least size of byte (see srec_cat) --obs: Output block size (see srec_cat) --line-length: Output line length max (see srec_cat) Assumes minipro and srec_cat are on the path. Here's the minipro help: EOF exec minipro fi # Options for minipro OPTS= # The -r or -w RWOPT= # Real file name FN= # Extension provided EXT= # Options for srec_cat SRECOPTS= # parse arguments and sort them out while [ $# != 0 ] do # note --obs x becomes --obs=x if [ "$1" == "--obs" ] then SRECOPTS="$SRECOPTS $1=$2" shift shift continue fi # note --line-length x becomes --line-length=x if [ "$1" == "--line-length" ] then SRECOPTS="$SRECOPTS $1=$2" fi if [ "$1" == "--unfill" ] then SRECOPTS="$SRECOPTS $1 $2 $3" shift shift shift continue fi if [ "$1" == "--offset" ] then SRECOPTS="$SRECOPTS $1 $2" shift shift continue fi if [ "$1" == "-r" ] then RWOPT=-r shift FN=$1 elif [ "$1" == "-w" ] then RWOPT=-w shift FN=$1 elif [ "$1" == "-p" ] then if [ -z "$DEVICE" ] then shift DEVICE="-p '$1'" shift continue else echo "Ignoring duplicate -p flag!" shift shift continue fi else OPTS="$OPTS $1" fi shift done # Pick apart file name filename=$(basename "$FN") extension="${filename##*.}" fileprefix="${filename%.*}" # for each case decide the real file name (RFILE) # and what you have to do before or after # to get the right answer case "$extension" in .bin) # no conversion needed RFILE="$FN" PRECVT= POSTCVT= ;; hex) RFILE="$(mktemp)" PRECVT="srec_cat $FN --intel $SRECOPTS -o $RFILE --binary" POSTCVT="srec_cat $RFILE --binary $SRECOPTS -o $FN --intel" ;; srec | s19) RFILE="$(mktemp)" PRECVT="srec_cat $FN --motorola $SRECOPTS -o $RFILE --binary" POSTCVT="srec_cat $RFILE --binary $SRECOPTS -o $FN --motorola" ;; txt) # assume fuse and just go for it RFILE="$FN" PRECVT= POSTCVT= ;; *) # Who knows? RFILE="$FN" PRECVT= POSTCVT= esac DOIT="minipro $OPTS $DEVICE $RWOPT $RFILE" # If we write, do PRECMD and execute if [ $RWOPT == -w ] then $PRECVT eval $DOIT else # If reading, execute and then do post cmd eval $DOIT $POSTCVT fi # Purge the temporary file if we used one [ "$PRECVT" ] && rm "$RFILE"