summaryrefslogtreecommitdiffstats
path: root/target/linux/ar71xx/base-files/etc/uci-defaults/caldata-migration
blob: 486e4ed7b8c7ab896fd20ae5c38bd4acf1981386 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
#
# Copyright (C) 2011 OpenWrt.org
#

. /lib/functions/uci-defaults.sh
. /lib/ar71xx.sh

board=$(ar71xx_board_name)

findmtd() {
	local partname="$1"
	grep "\"$partname\"" /proc/mtd | awk -F: '{ print $1 }'
}

getcalmac() {
	local partname="$1"
	local offset="$2"

	hexdump -e '17/1 "%c"' -s $offset -n 17 /dev/$(findmtd $partname) | tr -d : | tr 'A-Z' 'a-z'
}

calcmacX() {
	local mac="$1"
	local X="$2"

	local oui="$(expr substr "$mac" 1 6)"
	local end="$(expr substr "$mac" 7 12)"

	echo -n $oui
	expr substr "$(printf "%6lx" "$(($(printf "%lu" 0x${end}) + $X))")" 1 6
}

getifmac() {
	local ifname="$1"

	local ifmac

	ifmac="$(ifconfig "$ifname" | grep HWaddr)"
	ifmac="${ifmac#*HWaddr }"
	ifmac="${ifmac%% *}"

	echo "$ifmac" | tr -d : | tr 'A-Z' 'a-z'
}

case "$board" in
dir-825-b1-towholeflash)
	mac1="$(getcalmac caldata 65440)"
	mac1="$(calcmacX "$mac1" 2)"
	mac2="$(calcmacX "$mac1" 1)"

	if grep -q '"owrt_caldata"' /proc/mtd && [ "$mac1" = "$(getifmac eth0)" ] && [ "$mac2" = "$(getifmac eth1)" ]; then
		mtd erase owrt_caldata
		dd if=/dev/$(findmtd caldata) of=/dev/$(findmtd owrt_caldata) bs=65536 count=1
	fi
	;;
dir-825-b1-tostock)
	mac1="$(getcalmac owrt_caldata 65440)"
	mac1="$(calcmacX "$mac1" 2)"
	mac2="$(calcmacX "$mac1" 1)"
	if grep -q '"owrt_caldata"' /proc/mtd && [ "$mac1" = "$(getifmac eth0)" ] && [ "$mac2" = "$(getifmac eth1)" ]; then
		mtd erase caldata
		dd if=/dev/$(findmtd owrt_caldata) of=/dev/$(findmtd caldata) bs=65536 count=1
	fi
	;;
esac

return 0