1#!/bin/sh
2# based on gabors ralink wisoc implementation
3
4rt2x00_eeprom_die() {
5	echo "rt2x00 eeprom: " "$*"
6	exit 1
7}
8
9rt2x00_eeprom_extract() {
10	local part=$1
11	local offset=$2
12	local count=$3
13	local swab=$4
14	local mtd
15
16	. /lib/functions.sh
17
18	mtd=$(find_mtd_part $part)
19	[ -n "$mtd" ] || \
20		rt2x00_eeprom_die "no mtd device found for partition $part"
21
22	if [ $swab -gt 0 ]; then
23		dd if=$mtd of=/lib/firmware/$FIRMWARE bs=2 skip=$offset count=$count conv=swab || \
24			rt2x00_eeprom_die "failed to extract from $mtd"
25	else
26		dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count || \
27			rt2x00_eeprom_die "failed to extract from $mtd"
28	fi
29}
30
31[ -e /lib/firmware/$FIRMWARE ] && exit 0
32. /lib/functions/lantiq.sh
33
34case "$FIRMWARE" in
35"RT2860.eeprom" )
36	local board=$(lantiq_board_name)
37	case $board in
38	ARV7510PW22|ARV7519PW|ARV752DPW|ARV752DPW22|VGV7519)
39		rt2x00_eeprom_extract "board_config" 520 256 1
40		;;
41	ARV7525PW)
42		rt2x00_eeprom_extract "board_config" 1040 512 0
43		;;
44	*)
45		rt2x00_eeprom_die "board $board is not supported yet"
46		;;
47	esac
48	;;
49"RT3062.eeprom" )
50	local board=$(lantiq_board_name)
51	case $board in
52	VGV7510KW22)
53		rt2x00_eeprom_extract "board_config" 520 256 1
54		;;
55	*)
56		rt2x00_eeprom_die "board $board is not supported yet"
57		;;
58	esac
59	;;
60esac
61