utils: eth_mac_addr: Refactor ethernet mac addr script
Refactored the scripts which we use on DB845c to set
Ethernet MAC address.
Updated the .sh script to fall back to parsing bootconfig
file to lookup androidboot.serialno bootarg, if it is not
found in /proc/cmdline (boot image header v4 for example).
Fixed a typo s/db45c/db845c in .rc script which was blocking
this service to run.
Renamed the script from eth_mac_addr to set_ethaddr to
follow the nomenclature we have used everywhere else and
moved them to common shared/utils/ directory.
And updated the sepolicies accordingly.
Change-Id: Ia25e464b7c13934ffd8ab66a6aa2d892d7cd5a7b
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
diff --git a/shared/utils/ethaddr/ethaddr.rc b/shared/utils/ethaddr/ethaddr.rc
new file mode 100644
index 0000000..d82f5ee
--- /dev/null
+++ b/shared/utils/ethaddr/ethaddr.rc
@@ -0,0 +1,9 @@
+service set_ethaddr /system/bin/set_ethaddr.sh
+ class core
+ user root
+ group system
+ disabled
+ oneshot
+
+on post-fs-data && property:vendor.hw=db845c
+ start set_ethaddr
diff --git a/shared/utils/ethaddr/set_ethaddr.sh b/shared/utils/ethaddr/set_ethaddr.sh
new file mode 100644
index 0000000..2bfa8d8
--- /dev/null
+++ b/shared/utils/ethaddr/set_ethaddr.sh
@@ -0,0 +1,25 @@
+#! /system/bin/sh
+# Set eth0 mac address.
+#
+# Get the unique board serial number from /proc/cmdline or
+# /proc/bootconfig, prepend '0's to the serial number to
+# fill 5 LSBs of the MAC address and prepend "02" as MSB to
+# prepare a 6 byte locally administered unicast MAC address.
+#
+# Format the output in xx:xx:xx:xx:xx:xx format for the "ip"
+# set address command to work.
+
+ETHADDR=`cat /proc/cmdline | grep -o serialno.* | cut -f2 -d'=' |\
+ awk '{printf("02%010s\n", $1)}' | sed 's/\(..\)/\1:/g' |\
+ sed '$s/:$//'`
+if [ -z "${ETHADDR}" ]
+then
+ETHADDR=`cat /proc/bootconfig | grep -o serialno.* |\
+ cut -f2 -d'=' | cut -c 3-10 |\
+ awk '{printf("02%010s\n", $1)}' | sed 's/\(..\)/\1:/g' |\
+ sed '$s/:$//'`
+fi
+
+ip link set dev eth0 down
+ip link set dev eth0 address "${ETHADDR}"
+ip link set dev eth0 up