linksys-image.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. #
  3. # Copyright (C) 2018 Oceanic Systems (UK) Ltd
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. # Maintained by: Ryan Pannell <ryan [at] o s u k l .com> <github.com/Escalion>
  9. #
  10. # Write Linksys signature for factory image
  11. # This is appended to the factory image and is tested by the Linksys Upgrader - as observed in civic.
  12. # The footer is 256 bytes. The format is:
  13. # .LINKSYS. This is detected by the Linksys upgrader before continuing with upgrade. (9 bytes)
  14. # <VERSION> The version number of upgrade. Not checked so use arbitary value (8 bytes)
  15. # <TYPE> Model of target device, padded (0x20) to (15 bytes)
  16. # <CRC> CRC checksum of the image to flash (8 byte)
  17. # <padding> Padding (0x20) (7 bytes)
  18. # <signature> Signature of signer. Not checked so use Arbitary value (16 bytes)
  19. # <padding> Padding (0x00) (192 bytes)
  20. # 0x0A (1 byte)
  21. ## version history
  22. # * version 1: initial commit
  23. set -e
  24. ME="${0##*/}"
  25. usage() {
  26. echo "Usage: $ME <type> <in filename>"
  27. [ "$IMG_OUT" ] && rm -f "$IMG_OUT"
  28. exit 1
  29. }
  30. [ "$#" -lt 3 ] && usage
  31. TYPE=$1
  32. tmpdir="$( mktemp -d 2> /dev/null )"
  33. if [ -z "$tmpdir" ]; then
  34. # try OSX signature
  35. tmpdir="$( mktemp -t 'ubitmp' -d )"
  36. fi
  37. if [ -z "$tmpdir" ]; then
  38. exit 1
  39. fi
  40. trap "rm -rf $tmpdir" EXIT
  41. IMG_TMP_OUT="${tmpdir}/out"
  42. IMG_IN=$2
  43. IMG_OUT="${IMG_IN}.new"
  44. [ ! -f "$IMG_IN" ] && echo "$ME: Not a valid image: $IMG_IN" && usage
  45. dd if="${IMG_IN}" of="${IMG_TMP_OUT}"
  46. CRC=$(printf "%08X" $(dd if="${IMG_IN}" bs=$(stat -c%s "${IMG_IN}") count=1|cksum| cut -d ' ' -f1))
  47. printf ".LINKSYS.01000409%-15s%-8s%-7s%-16s" "${TYPE}" "${CRC}" "" "K0000000F0246434" >> "${IMG_TMP_OUT}"
  48. dd if=/dev/zero bs=1 count=192 conv=notrunc >> "${IMG_TMP_OUT}"
  49. printf '\12' >> "${IMG_TMP_OUT}"
  50. cp "${IMG_TMP_OUT}" "${IMG_OUT}"