miniprohex 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/bash
  2. if [ $# == 0 ]
  3. then
  4. cat << EOF
  5. miniprohex by Al Williams http://www.awce.com
  6. Usage:
  7. miniprohex [--o offset] [--unfill byte size] [--obs blksize] [--line-length length] [minipro_options] -r filename.ext
  8. miniprohex [--o offset] [minirpo_options] -w filename.ext
  9. This calls minipro after converting known file types to
  10. .bin for writing or converting bin files after reading.
  11. --o: Offset for file conversion (see srec_cat)
  12. --unfill: Unfil blocks of at least size of byte (see srec_cat)
  13. --obs: Output block size (see srec_cat)
  14. --line-length: Output line length max (see srec_cat)
  15. Assumes minipro and srec_cat are on the path.
  16. Here's the minipro help:
  17. EOF
  18. exec minipro
  19. fi
  20. # Options for minipro
  21. OPTS=
  22. # The -r or -w
  23. RWOPT=
  24. # Real file name
  25. FN=
  26. # Extension provided
  27. EXT=
  28. # Options for srec_cat
  29. SRECOPTS=
  30. # parse arguments and sort them out
  31. while [ $# != 0 ]
  32. do
  33. # note --obs x becomes --obs=x
  34. if [ "$1" == "--obs" ]
  35. then
  36. SRECOPTS="$SRECOPTS $1=$2"
  37. shift
  38. shift
  39. continue
  40. fi
  41. # note --line-length x becomes --line-length=x
  42. if [ "$1" == "--line-length" ]
  43. then
  44. SRECOPTS="$SRECOPTS $1=$2"
  45. fi
  46. if [ "$1" == "--unfill" ]
  47. then
  48. SRECOPTS="$SRECOPTS $1 $2 $3"
  49. shift
  50. shift
  51. shift
  52. continue
  53. fi
  54. if [ "$1" == "--offset" ]
  55. then
  56. SRECOPTS="$SRECOPTS $1 $2"
  57. shift
  58. shift
  59. continue
  60. fi
  61. if [ "$1" == "-r" ]
  62. then
  63. RWOPT=-r
  64. shift
  65. FN=$1
  66. elif [ "$1" == "-w" ]
  67. then
  68. RWOPT=-w
  69. shift
  70. FN=$1
  71. else
  72. OPTS="$OPTS $1"
  73. fi
  74. shift
  75. done
  76. # Pick apart file name
  77. filename=$(basename "$FN")
  78. extension="${filename##*.}"
  79. fileprefix="${filename%.*}"
  80. # for each case decide the real file name (RFILE)
  81. # and what you have to do before or after
  82. # to get the right answer
  83. case "$extension" in
  84. .bin)
  85. # no conversion needed
  86. RFILE="$FN"
  87. PRECVT=
  88. POSTCVT=
  89. ;;
  90. hex)
  91. RFILE="$(mktemp)"
  92. PRECVT="srec_cat $FN --intel -o $SRECOPT $RFILE --binary"
  93. POSTCVT="srec_cat $RFILE --binary $SRECOPTS -o $FN --intel"
  94. ;;
  95. srec)
  96. RFILE="$(mktemp)"
  97. PRECVT="srec_cat $FN --motorola -o $SRECOPT $RFILE --binary"
  98. POSTCVT="srec_cat $RFILE --binary $SRECOPTS -o $FN --motorola"
  99. ;;
  100. txt)
  101. # assume fuse and just go for it
  102. RFILE="$FN"
  103. PRECVT=
  104. POSTCVT=
  105. ;;
  106. *)
  107. # Who knows?
  108. RFILE="$FN"
  109. PRECVT=
  110. POSTCVT=
  111. esac
  112. # If we write, do PRECMD and execute
  113. if [ $RWOPT == -w ]
  114. then
  115. $PRECVT
  116. minipro $OPTS $RWOPT $RFILE
  117. else
  118. # If reading, execute and then do post cmd
  119. minipro $OPTS $RWOPT $RFILE
  120. $POSTCVT
  121. fi
  122. # Purge the temporary file if we used one
  123. [ "$PRECVT" ] && rm "$RFILE"