summaryrefslogtreecommitdiff
path: root/recipes-core/udev/eudev/mtcdt/mtcdt_eth_rename.sh
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/udev/eudev/mtcdt/mtcdt_eth_rename.sh')
-rwxr-xr-xrecipes-core/udev/eudev/mtcdt/mtcdt_eth_rename.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/recipes-core/udev/eudev/mtcdt/mtcdt_eth_rename.sh b/recipes-core/udev/eudev/mtcdt/mtcdt_eth_rename.sh
new file mode 100755
index 0000000..4273d30
--- /dev/null
+++ b/recipes-core/udev/eudev/mtcdt/mtcdt_eth_rename.sh
@@ -0,0 +1,46 @@
+#!/bin/bash
+
+I2C_DIR="/sys/bus/i2c/devices"
+
+AP1_EEPROM="$I2C_DIR/1-0050/eeprom"
+AP2_EEPROM="$I2C_DIR/1-0052/eeprom"
+hw_version1=''
+hw_version2=''
+
+if [[ -f $AP1_EEPROM ]] ; then
+ hw_version1=$(mts-id-eeprom --accessory-card --in-file "$AP1_EEPROM" 2>/dev/null | grep '^hw-version:')
+fi
+if [[ -f $AP2_EEPROM ]] ; then
+ hw_version2=$(mts-id-eeprom --accessory-card --in-file "$AP2_EEPROM" 2>/dev/null | grep '^hw-version:')
+fi
+
+AP1=0
+AP2=0
+
+if [[ $hw_version1 =~ ^hw-version:[[:space:]]*\"MTAC-ETH ]] ; then
+ AP1=1
+fi
+
+if [[ $hw_version2 =~ ^hw-version:[[:space:]]*\"MTAC-ETH ]] ; then
+ AP2=1
+fi
+
+if ((AP1 == 0)) && ((AP2 == 1)) ; then
+ if ip addr show eth1 >/dev/null 2>&1 && ! ip addr show eth2 >/dev/null 2>&1 ; then
+ ip link set eth1 name eth2
+ fi
+fi
+
+# Handle the case where we are coming out of reset.
+# udev will assign eth# where # is the first open slot starting from zero.
+# We assing by AP slot here.
+if ((AP1 == 1)) && ((AP2 == 1)) ; then
+ if (($(mts-io-sysfs show ap2/reset) == 0)) ; then
+ :
+ # Nothing to do if ap2 is in reset.
+ elif (($(mts-io-sysfs show ap1/reset) == 0)) ; then
+ if ip addr show eth1 >/dev/null 2>&1 && ! ip addr show eth2 >/dev/null 2>&1 ; then
+ ip link set eth1 name eth2
+ fi
+ fi
+fi