1#!/bin/sh 2 3rt2x00_eeprom_die() { 4 echo "rt2x00 eeprom: " "$*" 5 exit 1 6} 7 8rt2x00_eeprom_extract() { 9 local part=$1 10 local offset=$2 11 local count=$3 12 local mtd 13 14 . /lib/functions.sh 15 16 mtd=$(find_mtd_part $part) 17 [ -n "$mtd" ] || \ 18 rt2x00_eeprom_die "no mtd device found for partition $part" 19 20 dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \ 21 rt2x00_eeprom_die "failed to extract from $mtd" 22} 23 24rt2x00_eeprom_set_macaddr() { 25 local macaddr=$1 26 27 [ -n "$macaddr" ] || \ 28 rt2x00_eeprom_die "invalid wlan mac address" 29 30 macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \ 31 conv=notrunc bs=1 seek=4 count=6 2>/dev/null || \ 32 rt2x00_eeprom_die "failed to write mac address to eeprom file" 33} 34 35FW="/lib/firmware/$FIRMWARE" 36[ -e "$FW" ] && exit 0 37 38. /lib/ramips.sh 39. /lib/functions/system.sh 40 41board=$(ramips_board_name) 42 43case "$FIRMWARE" in 44"soc_wmac.eeprom") 45 case $board in 46 *) 47 rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!" 48 ;; 49 esac 50 ;; 51 52"rt2x00pci_1_0.eeprom") 53 case $board in 54 cy-swr1100) 55 rt2x00_eeprom_extract "factory" 8192 512 56 ;; 57 br-6475nd | rt-n56u | whr-600d | whr-1166d) 58 rt2x00_eeprom_extract "factory" 32768 512 59 ;; 60 tiny-ac) 61 local wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR) 62 rt2x00_eeprom_extract "factory" 0 512 63 rt2x00_eeprom_set_macaddr $wifi_mac 64 ;; 65 esac 66 ;; 67esac 68