gemini: Use library functions to assign MAC address
This simplifies the ethernet address extraction script by using standard library functions to locate the MTD partitions and extract ethernet address from a binary offset location in the flash. Furthermore, the aging ifconfig is replaced by the ip tool, which will now assign the MAC addresses. Suggested-by: Christian Lamparter <chunkeey@gmail.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Christian Lamparter <chunkeey@gmail.com> [ifconfig replacement, use -n instead of ! -z, -n requires string to be quoted within the test brackets, drop prepended "x" in check, add quotes, make local variables local, kill whitespaces]
This commit is contained in:
		 Linus Walleij
					Linus Walleij
				
			
				
					committed by
					
						 Christian Lamparter
						Christian Lamparter
					
				
			
			
				
	
			
			
			 Christian Lamparter
						Christian Lamparter
					
				
			
						parent
						
							bdbb679adb
						
					
				
				
					commit
					cd6c3535cd
				
			| @@ -1,25 +1,33 @@ | |||||||
| #!/bin/sh | #!/bin/sh | ||||||
|  |  | ||||||
| set_ether_mac() { | . /lib/functions.sh | ||||||
| 	# Most devices have a standard "VCTL" partition | . /lib/functions/system.sh | ||||||
| 	CONFIG_PARTITION="$(grep "VCTL" /proc/mtd | cut -d: -f1)" |  | ||||||
| 	if [ ! -z $CONFIG_PARTITION ] ; then |  | ||||||
| 		MAC1="$(strings /dev/$CONFIG_PARTITION |grep MAC|cut -d: -f2|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')" |  | ||||||
| 		MAC2="$(strings /dev/$CONFIG_PARTITION |grep MAC|cut -d: -f8|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')" |  | ||||||
|  |  | ||||||
| 		ifconfig eth0 hw ether $MAC1 2>/dev/null | set_ether_mac() { | ||||||
| 		ifconfig eth1 hw ether $MAC2 2>/dev/null | 	local part | ||||||
|  | 	local DEVID | ||||||
|  | 	local MAC1 | ||||||
|  | 	local MAC2 | ||||||
|  |  | ||||||
|  | 	# Most devices have a standard "VCTL" partition | ||||||
|  | 	part="$(find_mtd_part VCTL)" | ||||||
|  | 	if [ -n "$part" ]; then | ||||||
|  | 		MAC1="$(strings $part |grep MAC|cut -d: -f2|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')" | ||||||
|  | 		MAC2="$(strings $part |grep MAC|cut -d: -f8|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')" | ||||||
|  |  | ||||||
|  | 		ip link set eth0 address "$MAC1" 2>/dev/null | ||||||
|  | 		ip link set eth1 address "$MAC2" 2>/dev/null | ||||||
| 		return 0 | 		return 0 | ||||||
| 	fi | 	fi | ||||||
|  |  | ||||||
| 	# The DNS-313 has a special field in its RedBoot | 	# The DNS-313 has a special field in its RedBoot | ||||||
| 	# binary that we need to check | 	# binary that we need to check | ||||||
| 	CONFIG_PARTITION="$(grep "RedBoot" /proc/mtd | cut -d: -f1)" | 	part="$(find_mtd_part RedBoot)" | ||||||
| 	if [ ! -z $CONFIG_PARTITION ] ; then | 	if [ -n "$part" ]; then | ||||||
| 		DEVID="$(dd if=/dev/mtdblock0 bs=1 skip=119508 count=7 2>/dev/null)" | 		DEVID="$(dd if=$part bs=1 skip=119508 count=7 2>/dev/null)" | ||||||
| 		if [ "x$DEVID" = "xdns-313" ] ; then | 		if [ "$DEVID" = "dns-313" ]; then | ||||||
| 			MAC1="$(dd if=/dev/mtdblock0 bs=1 skip=119540 count=6 2>/dev/null | hexdump -n6 -e '/1 ":%02X"' | sed s/^://g)" | 			MAC1="$(mtd_get_mac_binary RedBoot 119540)" | ||||||
| 			ifconfig eth0 hw ether $MAC1 2>/dev/null | 			ip link set eth0 address "$MAC1" 2>/dev/null | ||||||
| 			return 0 | 			return 0 | ||||||
| 		fi | 		fi | ||||||
| 	fi | 	fi | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user