Compile swconfig for r64

Hi,

i’m trying to compile swconfig for r64, but i’m stuck

i take source from openwrt (seems the only source for it): https://github.com/openwrt-mirror/openwrt/tree/master/package/network/config/swconfig

and rewrote makefile

there are many type-mismatches and still some missing files…

is it compatible with kernel 4.19 or is it kernel-independed and needs only additional sources e.g. from https://github.com/openwrt-mirror/openwrt/tree/master/package/libs/libnl-tiny/src

tried also to clone openwrt directly and build only swconfig/src

frank@frank-N56VZ:/media/data_ext/openwrt/package/network/config/swconfig
[16:26:47]$ make
Makefile:8: /rules.mk: No such file or directory
Makefile:16: /package.mk: No such file or directory
Makefile:17: /kernel.mk: No such file or directory
make: *** No rule to make target '/kernel.mk'.  Stop.
frank@frank-N56VZ:/media/data_ext/openwrt/package/network/config/swconfig
[16:26:50]$ cd src
frank@frank-N56VZ:/media/data_ext/openwrt/package/network/config/swconfig/src
[16:27:06]$ make
cc -O2 -g -I ../src -fPIC -c -o swlib.o swlib.c
swlib.c:26:10: fatal error: linux/switch.h: No such file or directory
 #include <linux/switch.h>
          ^~~~~~~~~~~~~~~~
compilation terminated.
Makefile:9: recipe for target 'swlib.o' failed
make: *** [swlib.o] Error 1

anyone has an idea?

Copy https://github.com/openwrt-mirror/openwrt/blob/master/target/linux/generic/files/include/uapi/linux/switch.h to /usr/include/linux/ on the build machine

same as after i copied id to local source:

cc -O2 -g -I ../src -fPIC -c -o swlib.o swlib.c
In file included from swlib.c:26:0:
/usr/include/linux/switch.h:25:10: fatal error: netlink/netlink.h: No such file or directory
 #include <netlink/netlink.h>
          ^~~~~~~~~~~~~~~~~~~

seems it requires libnl

./package/libs/libnl-tiny/src/include/netlink/netlink.h

i created include-dir in src and copied libnl-tiny/src/include/netlink to it…

frank@frank-N56VZ:/media/data_ext/openwrt/package/network/config/swconfig/src
[16:53:14]$ CFLAGS=-Iinclude make
cc -Iinclude -fPIC -c -o swlib.o swlib.c
In file included from include/netlink/genl/genl.h:16:0,
                 from /usr/include/linux/switch.h:26,
                 from swlib.c:26:
include/netlink/msg.h:52:16: error: field 'nm_creds' has incomplete type
  struct ucred  nm_creds;
                ^~~~~~~~
include/netlink/msg.h: In function 'nlmsg_set_creds':
include/netlink/msg.h:207:39: error: dereferencing pointer to incomplete type 'struct ucred'
  memcpy(&msg->nm_creds, creds, sizeof(*creds));
                                       ^~~~~~

it seems that “struct ucred;” is only forward-declared in msg.h but nowhere declared with fields

tried to build it like this (only with crosscompiler, currently arm-linux-gnueabihf-gcc):

but make in swconfig failes on

make: libsw.a: Command not found

libsw.a exists in swconfig/src

currently hang here:

cli.c:26:10: fatal error: uci.h: No such file or directory
 #include <uci.h>
          ^~~~~~~

i don’t find an uci.h in openwrt-source

I’ll suggest …

  1. download openwrt 18.06 stable branch, and build image (it can boot to shell without network support) https://github.com/openwrt/openwrt/tree/openwrt-18.06 https://downloads.openwrt.org/releases/18.06.0/targets/mediatek/mt7622/
  2. refer to below github to add missing network parts and enable swconfig in menuconfig https://github.com/objelf/linux/commits/linux-4.14.y-mediatek

Isn’t there a way to compile sw-config outside openwrt? I want to use it in debian…

swconfig / uci are openwrt proprietary way to configure device, it needs patch kernel and prepare related library/app as well. I will suggest you use normal way to configure network in debian.

https://github.com/openwrt-mirror/openwrt/blob/master/target/linux/generic/patches-4.4/700-swconfig.patch

I only know dsa to configure separate ports and switchconfig…as there is no dsa-driver for r64 i tried to get swconfig working

there is no need to enable DSA or swconfig tool, just use below code base with ifconfig command to enable ethernet, thanks.

notes: swconfig is advanced feature to help hou set vlan member, pvid…etc easily.

https://github.com/objelf/linux/commits/linux-4.14.y-mediatek

I have ethernet working, but lan-ports are 1 nic so i cannot configure them separately…currently it works like r2 with kernel 4.4

I will suggest you can verify other parts first, and wait until new switch ic with DSA driver to meet your requirement. :wink:

wifi-driver is actually not compilable with gcc >6 so i’m stuck here (tried to compile full r64-bsp-repo on ubuntu 18.4 with all available gcc cross-compilers, on ubuntu 14.4 it works)

@moore, I built openwrt 18.06 stable branch but “swconfig list” does not see switch. Kernel has driver as I can see switch logs (List 1). Could you say what is a problem?

root@OpenWrt:/# swconfig 
swconfig list
swconfig dev <dev> [port <port>|vlan <vlan>] (help|set <key> <value>|get <key>|load <config>|show)
root@OpenWrt:/# 
root@OpenWrt:/# swconfig list
root@OpenWrt:/# 

root@OpenWrt:/# uname -a
Linux OpenWrt 4.19.76 #0 SMP Sun Oct 6 20:42:30 2019 aarch64 GNU/Linux

root@OpenWrt:/# cat /etc/openwrt_release 
DISTRIB_ID='OpenWrt'
DISTRIB_RELEASE='SNAPSHOT'
DISTRIB_REVISION='r11167-273a6cb'
DISTRIB_TARGET='mediatek/mt7622'
DISTRIB_ARCH='aarch64_cortex-a53'
DISTRIB_DESCRIPTION='OpenWrt SNAPSHOT r11167-273a6cb'
DISTRIB_TAINTS='no-all'

root@OpenWrt:/# cat /etc/openwrt_version 
r11167-273a6cb

List 1

[    1.749439] mt753x gsw@0: LAN/WAN VLAN setting=wllll
[    1.755031] mt753x gsw@0: Switch is MediaTek MT7531BE rev 0
[    4.444568] mt753x gsw@0: >>>>>>>>>>>>>>>>>>>>>>>>>>>>> START CALIBRATION:
[    4.453661] mt753x gsw@0: -------- gephy-calbration (port:0) --------
[    4.476896] CALDLY = 40
[    4.822980]  GE Rext AnaCal Saturation!  
[    4.827197] GE Rxet cal something wrong2
[    5.117938]  GE R50 AnaCal Saturation!  
[    5.122076]  GE R50 AnaCal Done! (32) (0x0)(0x80) 
[    5.404892]  GE R50 AnaCal Saturation!  
[    5.409020]  GE R50 AnaCal Done! (32) (0x0)(0x80) 
[    5.691807]  GE R50 AnaCal Saturation!  
[    5.695936]  GE R50 AnaCal Done! (32) (0x0)(0x80) 
[    5.978759]  GE R50 AnaCal Saturation!  
[    5.982897]  GE R50 AnaCal Done! (32) (0x0)(0x80) 
[    5.993140]  GE 1e_174(0x8080), 1e_175(0x8080)  
[    6.064762]  GE Tx offset AnaCal Done! (pair-0)(3)(0x22) 0x1e_172=0x2220
[    6.120677]  GE Tx offset AnaCal Done! (pair-1)(4)(0x23) 0x1e_172=0x2223
[    6.168419]  GE Tx offset AnaCal Done! (pair-2)(3)(0x22) 0x1e_173=0x2220
[    6.224329]  GE Tx offset AnaCal Done! (pair-3)(4)(0x23) 0x1e_173=0x2223
[    6.332597]  GE Tx amp AnaCal Done! (pair-0)(1e_12 = 0x5415)
[    6.416871]  GE Tx amp AnaCal Done! (pair-1)(1e_17 = 0x1313)
[    6.507328]  GE Tx amp AnaCal Done! (pair-2)(1e_19 = 0x1b23)
[    6.618115]  GE Tx amp AnaCal Done! (pair-3)(1e_21 = 0x1018)
.....
[  619.913583] mt753x gsw@0: Port 0 Link is Down
[  623.824121] mt753x gsw@0: Port 0 Link is Up - 100Mbps/Full

please use “make menuconfig” and enable CONFIG_PACKAGE_kmod-swconfig, thanks.

@moore, this option exists in my config too. But it doesn’t help…

please type “make kernel_menuconfig” to enable CONFIG_SWCONFIG=y, and then recompile your code, thanks.

@moore, you right. I already managed out it with @frank-w’s help. But I still don’t understand how to work with it. Look at the List 1.

  1. Ports 0-4 are an ethernet interfaces. What are mean 5 and 6? (I guess one of them is a CPU, but what is it other one?)
  2. Why vlans 1 and 2 set like this by default? How these vlans correlate with linux interfaces eth0 and eth1?

List 1:

root@client1:~# swconfig dev switch0 show
<-- cut -->
VLAN 1:
	vid: 1
	ports: 1 2 3 4 6 
VLAN 2:
	vid: 2
	ports: 0 5

Port 5 and 6 are both cpu-ports (port 6 - for lan-ports eth0,port 5 for wan-port eth1). Here you need 2 vlans to define which cpu-port to use.

You see that vlan2 is used for port 0 (wan) and 5 (eth1 - to soc). vlan 1 used for 1-4 (lan0-lan3) and 6 (eth0 - to soc)

So wan is connected via vlan 2 to eth1 (p5 of switch) and the lan-ports via vlan 1 to eth0 (p6 of switch)

To bad that i had not get managed to compile swconfig for debian so i cannot test it :frowning:

Yes you rigth @frank-w. Thank you!

I found vlan set up via swconfig on the ethernet port as untagged works as port-based vlan. Means ports can be separated each other like at List 2. So if vlans are port-based, every portX can be used independently (for example List 2a)

List 2 (Make LAN ports separated each other)

root@client1:~# swconfig dev switch0 vlan 1 set ports ''
root@client1:~# swconfig dev switch0 vlan 11 set vid 11
root@client1:~# swconfig dev switch0 vlan 11 set ports '1 6t'
root@client1:~# swconfig dev switch0 vlan 12 set vid 12
root@client1:~# swconfig dev switch0 vlan 12 set ports '2 6t'
root@client1:~# swconfig dev switch0 vlan 13 set vid 13
root@client1:~# swconfig dev switch0 vlan 13 set ports '3 6t'
root@client1:~# swconfig dev switch0 vlan 14 set vid 14
root@client1:~# swconfig dev switch0 vlan 14 set ports '4 6t'
root@client1:~# swconfig dev switch0 set apply
root@client1:~# swconfig dev switch0 show
...
VLAN 2:
	vid: 2
	ports: 0 5 
VLAN 11:
	vid: 11
	ports: 1 6t 
VLAN 12:
	vid: 12
	ports: 2 6t 
VLAN 13:
	vid: 13
	ports: 3 6t 
VLAN 14:
	vid: 14
	ports: 4 6t 

root@client1:~# ip link add link eth0 name port1 type vlan id 11
root@client1:~# ip link add link eth0 name port2 type vlan id 12
root@client1:~# ip link add link eth0 name port3 type vlan id 13
root@client1:~# ip link add link eth0 name port4 type vlan id 14
root@client1:~# for i in 1 2 3 4; do ip link set port$i up; done

List 2a

root@client1:~# ip link add link port1 name port1-100 type vlan id 100
root@client1:~# ip link add link port2 name port2-100 type vlan id 100
root@client1:~# ip link set port1-100 up; ip link set port2-100 up
root@client1:~# ip link
...
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP,80000> mtu 1500 qdisc fq_codel master ovs-system state UP mode DEFAULT group default qlen 1000
    link/ether 62:8b:b1:46:89:4a brd ff:ff:ff:ff:ff:ff
...
22: port1@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP,80000> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 62:8b:b1:46:89:4a brd ff:ff:ff:ff:ff:ff
23: port2@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP,80000> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 62:8b:b1:46:89:4a brd ff:ff:ff:ff:ff:ff
24: port3@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP,80000> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 62:8b:b1:46:89:4a brd ff:ff:ff:ff:ff:ff
25: port4@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP,80000> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 62:8b:b1:46:89:4a brd ff:ff:ff:ff:ff:ff
26: port1-100@port1: <BROADCAST,MULTICAST,UP,LOWER_UP,80000> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 62:8b:b1:46:89:4a brd ff:ff:ff:ff:ff:ff
27: port2-100@port2: <BROADCAST,MULTICAST,UP,LOWER_UP,80000> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 62:8b:b1:46:89:4a brd ff:ff:ff:ff:ff:ff