generic: mt7530: fix null pointer dereferencing in port5 setup
[openwrt/staging/wigyori.git] / target / linux / ramips / base-files / lib / preinit / 07_set_preinit_iface_ramips
1 #!/bin/sh
2 #
3 # Copyright (C) 2013 OpenWrt.org
4 #
5
6 . /lib/functions.sh
7
8 ramips_switchdev_from_soc() {
9 # The ethernet switch driver enables VLAN by default, but
10 # failsafe uses eth0, making the device unreachable:
11 # https://dev.openwrt.org/ticket/18768
12
13 local switchdev
14 local RT3X5X=$(grep -E "(RT3.5|RT5350|MT7628|MT7688|MT7620|MT7621)" /proc/cpuinfo)
15
16 [ -n "$RT3X5X" ] || return 1
17
18 case "$RT3X5X" in
19 *MT7620*)
20 switchdev=mt7620
21 ;;
22 *MT7621*)
23 switchdev=mt7530
24 ;;
25 *)
26 switchdev=rt305x
27 ;;
28 esac
29
30 echo "$switchdev"
31 }
32
33 ramips_switchdev_from_board() {
34 # For these devices, external ethernet switch should be used
35 # instead of the SoC internal switch.
36
37 local switchdev
38 local board=$(board_name)
39
40 case "$board" in
41 esac
42
43 echo "$switchdev"
44 }
45
46 ramips_set_preinit_iface() {
47 local switchdev=$(ramips_switchdev_from_board)
48 [ -n "$switchdev" ] || switchdev=$(ramips_switchdev_from_soc)
49
50 if [ -n "$switchdev" ]; then
51 swconfig dev $switchdev set reset 1
52 swconfig dev $switchdev set enable_vlan 0
53 swconfig dev $switchdev set apply 1
54 fi
55
56 ifname=eth0
57 }
58
59 boot_hook_add preinit_main ramips_set_preinit_iface