aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/rtl838x/base-files/etc/board.d/02_network
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux/rtl838x/base-files/etc/board.d/02_network')
-rwxr-xr-xtarget/linux/rtl838x/base-files/etc/board.d/02_network87
1 files changed, 87 insertions, 0 deletions
diff --git a/target/linux/rtl838x/base-files/etc/board.d/02_network b/target/linux/rtl838x/base-files/etc/board.d/02_network
new file mode 100755
index 0000000000..a79869d8c3
--- /dev/null
+++ b/target/linux/rtl838x/base-files/etc/board.d/02_network
@@ -0,0 +1,87 @@
+#!/bin/sh
+
+. /lib/functions.sh
+. /lib/functions/uci-defaults.sh
+. /lib/functions/system.sh
+
+rtl838x_setup_switch()
+{
+ local switchid net portid master device lan_role lan_list
+
+ json_select_object switch
+ # Find slave ports
+ for net in $(ls -d /sys/class/net/*); do
+ switchid=$(cat $net/phys_switch_id 2>/dev/null)
+ [ -z "$switchid" ] && continue
+ device=$(basename $net)
+ portid=$(cat $net/phys_port_name)
+ lan_role="$lan_role ${portid##p}"
+ lan_list="$lan_list $device"
+ json_select_object "switch$((switchid))"
+ json_add_boolean enable 1
+ json_add_boolean reset 0
+ json_add_boolean dsa 1
+ json_select_array ports
+ json_add_object
+ json_add_int num "${portid##p}"
+ json_add_string role "lan"
+ json_add_string device "$device"
+ json_close_object
+ json_select ..
+ json_select ..
+ done
+ # Add switch master device
+ for net in $(ls -d /sys/class/net/*/dsa); do
+ master=$(dirname $net)
+ device=$(basename $master)
+ portid=$(cat $master/phys_port_name)
+ lan_role="$lan_role ${portid##p}"
+ json_select_object "switch$((switchid))"
+ json_select_array ports
+ json_add_object
+ json_add_int num "${portid##p}"
+ json_add_string device "$device"
+ json_add_boolean need_tag 0
+ json_add_boolean want_untag 0
+ json_add_boolean master 1
+ json_close_object
+ json_select ..
+ json_select_array roles
+ json_add_object
+ json_add_string role "lan"
+ lan_role=$(echo $lan_role | xargs -n1 | sort -n | xargs)
+ json_add_string ports "$lan_role"
+ json_close_object
+ json_select ..
+ json_select ..
+ done
+ json_select ..
+ lan_list=$(echo $lan_list | xargs -n1 | sort -V | xargs)
+ ucidef_set_interface_lan "$lan_list"
+}
+
+rtl838x_setup_macs()
+{
+ local board="$1"
+ local lan_mac
+ local wan_mac
+ local label_mac
+
+ case $board in
+ allnet,all-sg8208m)
+ lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
+ label_mac=$lan_mac
+ esac
+
+ [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
+ [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
+ [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
+}
+
+board_config_update
+board=$(board_name)
+rtl838x_setup_switch
+rtl838x_setup_macs $board
+board_config_flush
+
+exit 0