summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Pundir <amit.pundir@linaro.org>2020-04-23 21:39:03 +0530
committerAmit Pundir <amit.pundir@linaro.org>2020-04-25 12:58:40 +0530
commit7cc6a2d9d7041917780d2311e66747e8ec789b60 (patch)
tree1f8c2e44bd6732ab275c050cf1f73caa5d3782f3
parentbed1321ddcf66ccd8b9d4065ad9aeea38b04436a (diff)
db845c: Set Ethernet MAC address on boot
db845c development boards do not have unique Ethernet MAC address. All boards share same MAC address and it cause problems while running CTS tests on db845c in a lab with multiple db845c boards connected. Set the Ethernet MAC address based on board's unique serial number as a workaround for now. Signed-off-by: Amit Pundir <amit.pundir@linaro.org> Change-Id: I1c5b63b7d6cbf5e55ac40980b5823cc6bb4f44d3
-rw-r--r--db845c/device.mk5
-rw-r--r--db845c/eth_mac_addr.rc9
-rw-r--r--db845c/eth_mac_addr.sh15
-rw-r--r--sepolicy/eth_mac_addr.te12
-rw-r--r--sepolicy/file_contexts2
5 files changed, 43 insertions, 0 deletions
diff --git a/db845c/device.mk b/db845c/device.mk
index cc5b973..b37e06f 100644
--- a/db845c/device.mk
+++ b/db845c/device.mk
@@ -43,5 +43,10 @@ PRODUCT_PACKAGES += \
PRODUCT_COPY_FILES += \
device/linaro/dragonboard/qcom/init.qcom.rc:$(TARGET_COPY_OUT_VENDOR)/etc/init/init.qcom.rc
+# Install scripts to set Ethernet MAC address
+PRODUCT_COPY_FILES += \
+ $(LOCAL_PATH)/eth_mac_addr.rc:/system/etc/init/eth_mac_addr.rc \
+ $(LOCAL_PATH)/eth_mac_addr.sh:/system/bin/eth_mac_addr.sh
+
# Copy firmware files
$(call inherit-product-if-exists, $(LOCAL_PATH)/firmware/device.mk)
diff --git a/db845c/eth_mac_addr.rc b/db845c/eth_mac_addr.rc
new file mode 100644
index 0000000..e710c19
--- /dev/null
+++ b/db845c/eth_mac_addr.rc
@@ -0,0 +1,9 @@
+service eth_mac_addr /system/bin/eth_mac_addr.sh
+ class core
+ user root
+ group system
+ disabled
+ oneshot
+
+on post-fs-data
+ start eth_mac_addr
diff --git a/db845c/eth_mac_addr.sh b/db845c/eth_mac_addr.sh
new file mode 100644
index 0000000..bdc1ba7
--- /dev/null
+++ b/db845c/eth_mac_addr.sh
@@ -0,0 +1,15 @@
+#! /system/bin/sh
+# Set eth0 mac address.
+#
+# Get the unique board serial number from /proc/cmdline,
+# 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.
+
+SERIALNO=`cat /proc/cmdline | grep -o serialno.* | cut -f2 -d'=' | awk '{printf("02%010s\n", $1)}' | sed 's/\(..\)/\1:/g' | sed '$s/:$//'`
+
+/system/bin/ip link set dev eth0 down
+/system/bin/ip link set dev eth0 address "${SERIALNO}"
+/system/bin/ip link set dev eth0 up
diff --git a/sepolicy/eth_mac_addr.te b/sepolicy/eth_mac_addr.te
new file mode 100644
index 0000000..d2e4e1a
--- /dev/null
+++ b/sepolicy/eth_mac_addr.te
@@ -0,0 +1,12 @@
+type eth_mac_addr, domain, coredomain;
+type eth_mac_addr_exec, exec_type, system_file_type, file_type;
+init_daemon_domain(eth_mac_addr);
+
+allow eth_mac_addr proc_cmdline:file { open read };
+allow eth_mac_addr rootfs:dir { open read };
+allow eth_mac_addr self:capability net_admin;
+allow eth_mac_addr self:netlink_route_socket { bind create getattr nlmsg_readpriv nlmsg_write read setopt write };
+allow eth_mac_addr self:udp_socket { create ioctl };
+allow eth_mac_addr shell_exec:file { execute getattr map read };
+allow eth_mac_addr system_file:file execute_no_trans;
+allow eth_mac_addr toolbox_exec:file { execute execute_no_trans getattr map open read };
diff --git a/sepolicy/file_contexts b/sepolicy/file_contexts
index 165f3b3..247e1ab 100644
--- a/sepolicy/file_contexts
+++ b/sepolicy/file_contexts
@@ -29,6 +29,8 @@
/data/vendor/readwrite(/.*)? u:object_r:tqftpserv_vendor_data_file:s0
/data/vendor/readonly(/.*)? u:object_r:tqftpserv_vendor_data_file:s0
+/system/bin/eth_mac_addr\.sh u:object_r:eth_mac_addr_exec:s0
+
/vendor/bin/hw/android\.hardware\.gatekeeper@1\.0-service\.software u:object_r:hal_gatekeeper_default_exec:s0
/vendor/bin/pd-mapper u:object_r:pd_mapper_exec:s0
/vendor/bin/qrtr-cfg u:object_r:qrtr_exec:s0