treewide: use the generic board_name function
[openwrt/staging/mkresin.git] / target / linux / ramips / base-files / etc / hotplug.d / firmware / 10-rt2x00-eeprom
1 #!/bin/sh
2
3 rt2x00_eeprom_die() {
4 echo "rt2x00 eeprom: " "$*"
5 exit 1
6 }
7
8 rt2x00_eeprom_extract() {
9 local part=$1
10 local offset=$2
11 local count=$3
12 local mtd
13
14 mtd=$(find_mtd_part $part)
15 [ -n "$mtd" ] || \
16 rt2x00_eeprom_die "no mtd device found for partition $part"
17
18 dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
19 rt2x00_eeprom_die "failed to extract from $mtd"
20 }
21
22 rt2x00_eeprom_set_macaddr() {
23 local macaddr=$1
24
25 [ -n "$macaddr" ] || \
26 rt2x00_eeprom_die "invalid wlan mac address"
27
28 macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \
29 conv=notrunc bs=1 seek=4 count=6 2>/dev/null || \
30 rt2x00_eeprom_die "failed to write mac address to eeprom file"
31 }
32
33 FW="/lib/firmware/$FIRMWARE"
34 [ -e "$FW" ] && exit 0
35
36 . /lib/functions.sh
37 . /lib/functions/system.sh
38
39 board=$(board_name)
40
41 case "$FIRMWARE" in
42 "soc_wmac.eeprom")
43 case $board in
44 tiny-ac)
45 wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
46 rt2x00_eeprom_extract "factory" 0 512
47 rt2x00_eeprom_set_macaddr $wifi_mac
48 ;;
49 *)
50 rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
51 ;;
52 esac
53 ;;
54 esac