e2e08937a32f4de2f80e51ec1241d356c2800f53
[openwrt/openwrt.git] / target / linux / ramips / rt305x / base-files / lib / preinit / 04_handle_checksumming
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
6 do_checksumming_disable() {
7 . /lib/functions.sh
8
9 local board=$(board_name)
10
11 case "$board" in
12 netgear,wnce2001)
13 echo "Board is WNCE2001, updating checksum partition..."
14 local zeroes=/dev/zero
15 local tmpfile=/tmp/wnce2001_checksum
16 local partname=checksum
17 local mtd=$(find_mtd_part $partname)
18 dd if=$mtd of=$tmpfile bs=80 count=1 2>/dev/null
19 signature=$(dd if=$tmpfile bs=1 skip=24 count=20 2>/dev/null)
20 checksum=$(dd if=$tmpfile bs=1 count=4 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"')
21 if [ "$signature" != "RT3052-AP-WNCE2001-3" ]; then
22 echo "Signature of checksum partition is wrong, bailing."
23 return 0
24 fi
25 if [ "$checksum" != "00000000" ]; then
26 echo "Checksum is set, zeroing."
27 # zero out checksum
28 dd if=$zeroes of=$tmpfile conv=notrunc bs=1 seek=0 count=4 2>/dev/null
29 # zero out bytecount to be checksummed
30 dd if=$zeroes of=$tmpfile conv=notrunc bs=1 seek=60 count=4 2>/dev/null
31 mtd write $tmpfile $partname
32 else
33 echo "Checksum is already zero, nothing to do."
34 fi
35 ;;
36 esac
37
38 return 0
39 }
40
41 boot_hook_add preinit_main do_checksumming_disable