04_handle_checksumming 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. # Netgear WNCE2001 has does a checksum check on boot and goes into recovery
  3. # tftp mode when the check fails. Initializing the JFFS2 partition triggers
  4. # this, so we make sure to zero checksum and size to be checksummed before
  5. # that happens, so this needs to run very early during boot.
  6. do_checksumming_disable() {
  7. . /lib/ramips.sh
  8. local board=$(ramips_board_name)
  9. case "$board" in
  10. wnce2001)
  11. echo "Board is WNCE2001, updating checksum partition..."
  12. local zeroes=/dev/zero
  13. local tmpfile=/tmp/wnce2001_checksum
  14. local partname=checksum
  15. local mtd=$(find_mtd_part $partname)
  16. dd if=$mtd of=$tmpfile bs=80 count=1 2>/dev/null
  17. signature=$(dd if=$tmpfile bs=1 skip=24 count=20 2>/dev/null)
  18. checksum=$(dd if=$tmpfile bs=1 count=4 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"')
  19. if [ "$signature" != "RT3052-AP-WNCE2001-3" ]; then
  20. echo "Signature of checksum partition is wrong, bailing."
  21. return 0
  22. fi
  23. if [ "$checksum" != "00000000" ]; then
  24. echo "Checksum is set, zeroing."
  25. # zero out checksum
  26. dd if=$zeroes of=$tmpfile conv=notrunc bs=1 seek=0 count=4 2>/dev/null
  27. # zero out bytecount to be checksummed
  28. dd if=$zeroes of=$tmpfile conv=notrunc bs=1 seek=60 count=4 2>/dev/null
  29. mtd write $tmpfile $partname
  30. else
  31. echo "Checksum is already zero, nothing to do."
  32. fi
  33. ;;
  34. rt-n56u)
  35. echo "Board is ASUS RT-N56U, replacing uImage header..."
  36. local firmware_mtd=$(find_mtd_part firmware)
  37. local rootfs_mtd=$(find_mtd_part rootfs)
  38. local rootfs_data_mtd=$(find_mtd_part rootfs_data)
  39. local rootfs_len=$(grep \"rootfs\" /proc/mtd | awk -F' ' '{print "0x"$2}')
  40. local rootfs_data_len=$(grep \"rootfs_data\" /proc/mtd | awk -F' ' '{print "0x"$2}')
  41. local offset=$(echo "$rootfs_len $rootfs_data_len 0x40" | awk -F' ' '{printf "%i",$1-$2-$3}')
  42. local signature=$(dd if=$rootfs_mtd skip=$offset bs=1 count=4 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"')
  43. if [ "$signature" = "27051956" ]; then
  44. dd conv=notrunc if=$rootfs_mtd skip=$offset of=$firmware_mtd bs=1 count=64 2>/dev/null
  45. fi
  46. ;;
  47. esac
  48. return 0
  49. }
  50. boot_hook_add preinit_main do_checksumming_disable