update_eeprom 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. prg=$(basename "$0")
  3. # parse arguments
  4. while getopts f:h optname
  5. do
  6. case $optname in
  7. f) port="$OPTARG" ;;
  8. *) help=1 ;;
  9. esac
  10. done
  11. shift `expr $OPTIND - 1`
  12. old="$1"
  13. new="$2"
  14. if [ -z "$old" -o "$help" = "-h" -o "$#" -gt 2 ]
  15. then
  16. echo "usage: $0 [-f <port>] <old dump> [<new dump>]" >&2
  17. echo "Convert <old dump> to instructions to update instructions." >&2
  18. echo "With <new dump>, generate instructions to update EEPROM changes only." >&2
  19. echo "Optionally write such changes directly if <port> if given." >&2
  20. exit 1
  21. fi
  22. set -e
  23. instr=$(mktemp)
  24. trap "rm -f \"$instr\"" EXIT
  25. convert()
  26. {
  27. sed -ne 's/^\([0-9a-f]\{4\}\) \([0-9a-f ]*\)$/D3 Ax\1 C16 X\2/p' "$@"
  28. }
  29. if [ -z "$new" ]; then
  30. # convert the instructions to updates
  31. convert "$old" > "$instr"
  32. else
  33. tmp1=$(mktemp)
  34. tmp2=$(mktemp)
  35. trap "rm -f \"$tmp1\" \"$tmp2\"" EXIT
  36. convert "$old" > "$tmp1"
  37. convert "$new" > "$tmp2"
  38. comm -13 "$tmp1" "$tmp2" > "$instr"
  39. fi
  40. # write the instructions if requested
  41. if [ -z "$port" ]; then
  42. cat "$instr"
  43. else
  44. printcore -v "$port" "$instr"
  45. fi