48133c81a164ae8d60f43e01d35d6d7d8f4fc6f8
[openwrt/staging/rmilecki.git] / target / linux / rockchip / armv8 / base-files / etc / board.d / 02_network
1 #!/bin/sh
2
3 . /lib/functions/uci-defaults.sh
4 . /lib/functions/system.sh
5
6 rockchip_setup_interfaces()
7 {
8 local board="$1"
9
10 case "$board" in
11 friendlyarm,nanopi-r2s)
12 ucidef_set_interfaces_lan_wan 'eth1' 'eth0'
13 ;;
14 *)
15 ucidef_set_interface_lan 'eth0'
16 ;;
17 esac
18 }
19
20 nanopi_r2s_generate_mac()
21 {
22 local sd_hash=$(sha256sum /sys/devices/platform/ff500000.dwmmc/mmc_host/mmc0/mmc0:*/cid)
23 local mac_base=$(macaddr_canonicalize "$(echo "${sd_hash}" | dd bs=1 count=12 2>/dev/null)")
24 echo "$(macaddr_unsetbit_mc "$(macaddr_setbit_la "${mac_base}")")"
25 }
26
27 rockchip_setup_macs()
28 {
29 local board="$1"
30 local lan_mac=""
31 local wan_mac=""
32 local label_mac=""
33
34 case "$board" in
35 friendlyarm,nanopi-r2s)
36 wan_mac=$(nanopi_r2s_generate_mac)
37 lan_mac=$(macaddr_add "$wan_mac" +1)
38 ;;
39 esac
40
41 [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
42 [ -n "$wan_mac" ] && ucidef_set_interface_macaddr "wan" $wan_mac
43 [ -n "$label_mac" ] && ucidef_set_label_macaddr $label_mac
44 }
45
46 board_config_update
47 board=$(board_name)
48 rockchip_setup_interfaces $board
49 rockchip_setup_macs $board
50 board_config_flush
51
52 exit 0