add chaos_calmer branch
[15.05/openwrt.git] / target / linux / mpc85xx / base-files / etc / hotplug.d / firmware / 10-ath9k-eeprom
1 #!/bin/sh
2
3 FW_FILE="/lib/firmware/$FIRMWARE"
4
5 ath9k_eeprom_die() {
6         echo "ath9k eeprom: " "$*" >&2
7         exit 1
8 }
9
10 ath9k_eeprom_extract() {
11         local part=$1
12         local offset=$2
13         local count=$3
14         local mtd
15
16         . /lib/functions.sh
17         . /lib/functions/system.sh
18
19         mtd=$(find_mtd_chardev $part)
20         [ -n "$mtd" ] || \
21                 ath9k_eeprom_die "no mtd device found for partition $part"
22
23         dd if=$mtd bs=$offset skip=1 count=1 2>/dev/null | dd of=$FW_FILE bs=$count count=1 2>/dev/null || \
24                 ath9k_eeprom_die "failed to extract from $mtd"
25 }
26
27 tpl_set_wireless_mac()
28 {
29         local offset=$1
30         local mac
31
32         . /lib/functions.sh
33         . /lib/functions/system.sh
34
35         mac=$(mtd_get_mac_binary u-boot 326656)
36         mac=$(macaddr_add $mac $offset)
37
38         macaddr_2bin $mac | dd bs=1 count=6 seek=2 conv=notrunc of=$FW_FILE 2>/dev/null
39 }
40
41 [ -e $FW_FILE ] && exit 0
42
43 . /lib/mpc85xx.sh
44
45 board=$(mpc85xx_board_name)
46
47 case "$FIRMWARE" in
48 "pci_wmac0.eeprom")
49         case $board in
50         tl-wdr4900-v1)
51                 ath9k_eeprom_extract "caldata" 4096 2048
52                 tpl_set_wireless_mac 0
53                 ;;
54         *)
55                 ath9k_eeprom_die "board $board is not supported yet"
56                 ;;
57         esac
58         ;;
59
60 "pci_wmac1.eeprom")
61         case $board in
62         tl-wdr4900-v1)
63                 ath9k_eeprom_extract "caldata" 20480 2048
64                 tpl_set_wireless_mac -1
65                 ;;
66         *)
67                 ath9k_eeprom_die "board $board is not supported yet"
68                 ;;
69         esac
70         ;;
71 esac