treewide: move calibration data extraction function to library
[openwrt/staging/wigyori.git] / target / linux / ramips / base-files / etc / hotplug.d / firmware / 10-rt2x00-eeprom
1 #!/bin/sh
2
3 [ -e /lib/firmware/$FIRMWARE ] && exit 0
4
5 . /lib/functions/caldata.sh
6
7 jboot_eeprom_extract() {
8 local part=$1
9 local offset=$2
10 local mtd
11
12 mtd=$(find_mtd_part $part)
13 [ -n "$mtd" ] || \
14 caldata_die "no mtd device found for partition $part"
15
16 jboot_config_read -i $mtd -o $offset -e /lib/firmware/$FIRMWARE 2>/dev/null || \
17 caldata_die "failed to extract from $mtd"
18 }
19
20 rt2x00_eeprom_set_macaddr() {
21 local macaddr=$1
22
23 [ -n "$macaddr" ] || \
24 caldata_die "invalid wlan mac address"
25
26 macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \
27 conv=notrunc oflag=seek_bytes bs=6 seek=4 count=1 2>/dev/null || \
28 caldata_die "failed to write mac address to eeprom file"
29 }
30
31 board=$(board_name)
32
33 case "$FIRMWARE" in
34 "soc_wmac.eeprom")
35 case $board in
36 dlink,dir-510l|\
37 dlink,dwr-116-a1|\
38 dlink,dwr-118-a1|\
39 dlink,dwr-118-a2|\
40 dlink,dwr-921-c1|\
41 dlink,dwr-922-e2|\
42 lava,lr-25g001)
43 wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000)
44 wifi_mac=$(macaddr_add "$wan_mac" 1)
45 jboot_eeprom_extract "config" 0xE000
46 rt2x00_eeprom_set_macaddr $wifi_mac
47 ;;
48 dovado,tiny-ac)
49 wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
50 caldata_extract "factory" 0x0 0x200
51 rt2x00_eeprom_set_macaddr $wifi_mac
52 ;;
53 *)
54 caldata_die "Please define mtd-eeprom in $board DTS file!"
55 ;;
56 esac
57 ;;
58 esac