ipq40xx: add support for Linksys WHW03 V1
[openwrt/staging/pepe2k.git] / target / linux / ipq40xx / base-files / etc / init.d / bootcount
1 #!/bin/sh /etc/rc.common
2
3 START=99
4
5 mmc_resetbc() {
6 local part_label="$1"
7
8 . /lib/functions.sh
9
10 local part_device="$(find_mmc_part "$part_label")"
11 if [ "$part_device" = "" ]; then
12 >&2 echo "mmc_resetbc: Unknown partition label: $part_label"
13 return 1
14 fi
15
16 local magic_number="$(hexdump -e '"0x%02x\n"' -n 4 "$part_device")"
17 if [ "$magic_number" != "0x20110811" ]; then
18 >&2 echo "mmc_resetbc: Unexpected partition magic: $magic_number"
19 return 1
20 fi
21
22 local last_count=$(hexdump -e '"0x%02x\n"' -n 4 -s 4 "$part_device")
23 if [ "$last_count" != "0x00" ]; then
24 printf "\x00" | dd of="$part_device" bs=4 seek=1 count=1 conv=notrunc 2>/dev/null
25
26 last_count=$(hexdump -e '"0x%02x\n"' -n 4 -s 4 "$part_device")
27 if [ "$last_count" != "0x00" ]; then
28 >&2 echo "mmc_resetbc: Unable to reset boot counter"
29 return 1
30 fi
31 fi
32 }
33
34 boot() {
35 case $(board_name) in
36 alfa-network,ap120c-ac)
37 [ -n "$(fw_printenv bootcount changed 2>/dev/null)" ] &&\
38 echo -e "bootcount\nchanged\n" | /usr/sbin/fw_setenv -s -
39 ;;
40 linksys,ea6350v3|\
41 linksys,ea8300|\
42 linksys,mr8300|\
43 linksys,whw01|\
44 linksys,whw03v2)
45 mtd resetbc s_env || true
46 ;;
47 linksys,whw03)
48 mmc_resetbc s_env || true
49 ;;
50 netgear,wac510)
51 fw_setenv boot_cnt=0
52 ;;
53 esac
54 }