04_handle_checksumming 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Netgear WNCE2001 has does a checksum check on boot and goes into recovery
  2. # tftp mode when the check fails. Initializing the JFFS2 partition triggers
  3. # this, so we make sure to zero checksum and size to be checksummed before
  4. # that happens, so this needs to run very early during boot.
  5. do_checksumming_disable() {
  6. . /lib/functions.sh
  7. local board=$(board_name)
  8. case "$board" in
  9. netgear,wnce2001)
  10. echo "Board is WNCE2001, updating checksum partition..."
  11. local zeroes=/dev/zero
  12. local tmpfile=/tmp/wnce2001_checksum
  13. local partname=checksum
  14. local mtd=$(find_mtd_part $partname)
  15. dd if=$mtd of=$tmpfile bs=80 count=1 2>/dev/null
  16. signature=$(dd if=$tmpfile bs=1 skip=24 count=20 2>/dev/null)
  17. checksum=$(dd if=$tmpfile bs=1 count=4 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"')
  18. if [ "$signature" != "RT3052-AP-WNCE2001-3" ]; then
  19. echo "Signature of checksum partition is wrong, bailing."
  20. return 0
  21. fi
  22. if [ "$checksum" != "00000000" ]; then
  23. echo "Checksum is set, zeroing."
  24. # zero out checksum
  25. dd if=$zeroes of=$tmpfile conv=notrunc bs=1 seek=0 count=4 2>/dev/null
  26. # zero out bytecount to be checksummed
  27. dd if=$zeroes of=$tmpfile conv=notrunc bs=1 seek=60 count=4 2>/dev/null
  28. mtd write $tmpfile $partname
  29. else
  30. echo "Checksum is already zero, nothing to do."
  31. fi
  32. ;;
  33. esac
  34. return 0
  35. }
  36. boot_hook_add preinit_main do_checksumming_disable