diff mbox

[OpenWrt-Devel] au1000: distinguish different models and set correct MAC-address

Message ID 20141210212621.GA4675@medion.lan
State Accepted
Headers show

Commit Message

Bastian Bittorf Dec. 10, 2014, 9:26 p.m. UTC
The target au1000 has at least 2 different models, the
'InternetBox' and the 'MeshCube' which look very similar
from the kernel point of view but are totally different
devices which base on the same design. Populating /tmp/sysinfo
now. The 1st one has an issue which leads to a random
mac-address after each boot which is corrected now via
reading the bootloader-env. The real fix would be
converting to DTS, this is only a workaround now.

Signed-off-by: Bastian Bittorf <bittorf@bluebottle.com>
---
 .../au1000/base-files/etc/uci-defaults/02_network  |   17 ++++++
 target/linux/au1000/base-files/lib/au1000.sh       |   59 ++++++++++++++++++++
 2 files changed, 76 insertions(+)
 create mode 100755 target/linux/au1000/base-files/etc/uci-defaults/02_network
 create mode 100644 target/linux/au1000/base-files/lib/au1000.sh

Comments

Bruno Randolf Dec. 11, 2014, 10:23 p.m. UTC | #1
Hi Bastian,

There is a syntax error in the /etc/uci-defaults/02_network script, but
even when I fix that, the MAC address is not set. What is
ucidef_set_interface_macaddr supposed to do?

Some more comments below:

On 12/10/2014 09:26 PM, Bastian Bittorf wrote:
> The target au1000 has at least 2 different models, the
> 'InternetBox' and the 'MeshCube' which look very similar
> from the kernel point of view but are totally different
> devices which base on the same design. Populating /tmp/sysinfo
> now. The 1st one has an issue which leads to a random
> mac-address after each boot which is corrected now via
> reading the bootloader-env. The real fix would be
> converting to DTS, this is only a workaround now.
> Signed-off-by: Bastian Bittorf <bittorf@bluebottle.com>
> ---
>  .../au1000/base-files/etc/uci-defaults/02_network  |   17 ++++++
>  target/linux/au1000/base-files/lib/au1000.sh       |   59 ++++++++++++++++++++
>  2 files changed, 76 insertions(+)
>  create mode 100755 target/linux/au1000/base-files/etc/uci-defaults/02_network
>  create mode 100644 target/linux/au1000/base-files/lib/au1000.sh
> 
> diff --git a/target/linux/au1000/base-files/etc/uci-defaults/02_network b/target/linux/au1000/base-files/etc/uci-defaults/02_network
> new file mode 100755
> index 0000000..80bfb73
> --- /dev/null
> +++ b/target/linux/au1000/base-files/etc/uci-defaults/02_network
> @@ -0,0 +1,17 @@
> +#!/bin/sh
> +
> +. /lib/au1000.sh
> +. /lib/functions/system.sh
> +. /lib/functions/uci-defaults.sh
> +MAC=
> +
> +case "$(au1000_board_name)" in
> +	'internetbox')
> +		MAC="$( au1000_yamonenv_getvar 'ethaddr' )"
> +		MAC="$( macaddr_canonicalize "$MAC" )"
> +
> +		[ -n "$MAC ] && ucidef_set_interface_macaddr lan "$MAC"

/etc/uci-defaults/02_network: line 13: syntax error: unterminated quoted
string - around "$MAC

> +	;;
> +esac
> +
> +[ -z "$MAC" ] || uci commit network
> diff --git a/target/linux/au1000/base-files/lib/au1000.sh b/target/linux/au1000/base-files/lib/au1000.sh
> new file mode 100644
> index 0000000..556598d
> --- /dev/null
> +++ b/target/linux/au1000/base-files/lib/au1000.sh
> @@ -0,0 +1,59 @@
> +#!/bin/sh
> +
> +au1000_yamonenv_getvar()
> +{
> +	local varname="$1"
> +	local partition
> +
> +	. /lib/functions.sh
> +
> +	partition="$( find_mtd_part 'yamon env' )"
> +	YAMONENVFILE="$partition" yamonenv "$varname"

That part also works on the Cube with JFFS2. I get the MAC address
correctly.

> +au1000_detect()
> +{
> +	local line board_name model
> +
> +	while read line; do
> +		case "$line" in
> +			'system type'*)
> +				break
> +			;;
> +		esac
> +	done <'/proc/cpuinfo'
> +
> +	case "$line" in
> +		*' MTX-1')
> +			# both models appear nearly similar: the 'InternetBox' has
> +			# the same design but shrinked to 1 PCB and only 1 x miniPCI
> +			# for WiFi/ath5k and 1 x miniPCI for CardBus/UMTS, they differ
> +			# in BogoMIPS but there are old MeshCubes with 330 Mhz instead
> +			# of 400 MHz and no Cube has 'imei' (for UMTS) set in bootloader-env
> +
> +			if [ -n "$( au1000_yamonenv_getvar 'imei' )" ]; then
> +				board_name='internetbox'
> +				model='T-Mobile InternetBox TMD SB1-S'
> +			else
> +				board_name='meshcube'
> +				model='4G Systems AccessCube/MeshCube'
> +			fi
> +		;;
> +		*)
> +			board_name='unknown'
> +			model='unknown'

That case statement looks pointless, but it makes sense to easily extend
the Models. For example there is one more au1000 based board I know of,
the "XXS1500" from mycable.de

bruno
diff mbox

Patch

diff --git a/target/linux/au1000/base-files/etc/uci-defaults/02_network b/target/linux/au1000/base-files/etc/uci-defaults/02_network
new file mode 100755
index 0000000..80bfb73
--- /dev/null
+++ b/target/linux/au1000/base-files/etc/uci-defaults/02_network
@@ -0,0 +1,17 @@ 
+#!/bin/sh
+
+. /lib/au1000.sh
+. /lib/functions/system.sh
+. /lib/functions/uci-defaults.sh
+MAC=
+
+case "$(au1000_board_name)" in
+	'internetbox')
+		MAC="$( au1000_yamonenv_getvar 'ethaddr' )"
+		MAC="$( macaddr_canonicalize "$MAC" )"
+
+		[ -n "$MAC ] && ucidef_set_interface_macaddr lan "$MAC"
+	;;
+esac
+
+[ -z "$MAC" ] || uci commit network
diff --git a/target/linux/au1000/base-files/lib/au1000.sh b/target/linux/au1000/base-files/lib/au1000.sh
new file mode 100644
index 0000000..556598d
--- /dev/null
+++ b/target/linux/au1000/base-files/lib/au1000.sh
@@ -0,0 +1,59 @@ 
+#!/bin/sh
+
+au1000_yamonenv_getvar()
+{
+	local varname="$1"
+	local partition
+
+	. /lib/functions.sh
+
+	partition="$( find_mtd_part 'yamon env' )"
+	YAMONENVFILE="$partition" yamonenv "$varname"
+}
+
+au1000_detect()
+{
+	local line board_name model
+
+	while read line; do
+		case "$line" in
+			'system type'*)
+				break
+			;;
+		esac
+	done <'/proc/cpuinfo'
+
+	case "$line" in
+		*' MTX-1')
+			# both models appear nearly similar: the 'InternetBox' has
+			# the same design but shrinked to 1 PCB and only 1 x miniPCI
+			# for WiFi/ath5k and 1 x miniPCI for CardBus/UMTS, they differ
+			# in BogoMIPS but there are old MeshCubes with 330 Mhz instead
+			# of 400 MHz and no Cube has 'imei' (for UMTS) set in bootloader-env
+
+			if [ -n "$( au1000_yamonenv_getvar 'imei' )" ]; then
+				board_name='internetbox'
+				model='T-Mobile InternetBox TMD SB1-S'
+			else
+				board_name='meshcube'
+				model='4G Systems AccessCube/MeshCube'
+			fi
+		;;
+		*)
+			board_name='unknown'
+			model='unknown'
+		;;
+	esac
+
+	mkdir -p '/tmp/sysinfo'
+	echo "$board_name" >'/tmp/sysinfo/board_name'
+	echo "$model" >'/tmp/sysinfo/model'
+}
+
+au1000_board_name()
+{
+	local file='/tmp/sysinfo/board_name'
+
+	[ -e "$file" ] || au1000_detect
+	cat "$file"
+}