Flip the switch
Mon, 02 Apr 2018 22:07:34 +0000
[ meta: I wanted to call this one "sudo make me a LAN switch" but now the MRAs have ruined that phrase for everyone ]
I got networking working on the GL-MT300A. This entailed:
Patching the device tree definition.
This is slightly cargo-culted (I Read It On The Internet), but by
pinctrl-0 entry from the
ðernet stanza I managed
to change the bootup mesages from saying
[ 1.873672] rt2880-pinmux pinctrl: could not request pin 40 (io40) from group ephy on device rt2880-pinmux [ 1.883620] mtk_soc_eth 10100000.ethernet: Error applying setting, reverse things back [ 1.891724] mtk_soc_eth: probe of 10100000.ethernet failed with error -22
<6>[ 2.586201] mtk_soc_eth 10100000.ethernet eth0 (uninitialized): port 1 link up (100Mbps/Full duplex) <6>[ 2.595753] mtk_soc_eth 10100000.ethernet: loaded mt7620 driver <6>[ 2.602600] mtk_soc_eth 10100000.ethernet eth0: mediatek frame engine at 0xb0100000, irq 5
which felt a lot like progress but did not result in actual connectivity.
After trying the obvious culprits (firewall rules? weird routing?) for why my board was not seeing the network - indeed, not even able to ping its own IP address - I studied the dmesg output a bit more closely, and noticing the line
<6>[ 2.581845] gsw: setting port4 to ephy mode
I took a wild-ass guess that given I knew the the device contains some kind of network switch, maybe the switch doesn't come up in a useful state. So we needed a tool of some kind to reconfigure it and apparently the appropriate tool is swconfig
(If you followed that link and struggled to understand what it was talking about, be assured that it means nothing to me either. Ure not alone)
Building swconfig is easier when you start with a fork for
Debian instead of the original
OpenWRT package: I simply made my
kernel derivation install the header
files (first time I have written a multi-output derivation, but turned
out that in this case it was a one-line change), wrote a derivation with
libnl as a dependency, and
created an 80MB filesystem image.
PRO TIP: don't override
phases in a Nixpkgs derivation unless you
understand what is done by all the phases you didn't include. In
this case, not running the fixup phase meant that
nothing ran the "shrink rpath" magic which removes unneeded
compile-time dependencies from the runtime dependency list. Image
size go boom.
I spent some time trying to figure out what I was doing with vlans and port configuration and worrying that when it said
link: ?unknown-type? against each port that would mean I had to tell it somehow what kind of link type to use. Then eventually I hit on
swconfig dev switch0 set enable_vlan 0 swconfig dev switch0 set apply
and as if by magic (= "insufficiently advanced understanding of technology") it all started working. When I eventually want it to function as a switch, obviously I will need to revisit this. But that is Milestone 1 and this is Milestone 0 - sufficient unto the day etc etc.