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