gl-mt300n-v2: initialize switch & define networkInterfaces

It booted and mounted rootfs the first time I tried, which
was nice. Wireless doesn't work yet, it needs firmware
module-based-network
Daniel Barlow 2023-03-09 19:30:57 +00:00
parent 91c0147919
commit f50b0627a2
1 changed files with 54 additions and 3 deletions

View File

@ -11,8 +11,10 @@
}; };
}; };
module = { pkgs, ...}: module = { pkgs, config, ...}:
let let
inherit (pkgs.liminix.networking) interface;
inherit (pkgs.liminix.services) oneshot;
openwrt = pkgs.fetchFromGitHub { openwrt = pkgs.fetchFromGitHub {
name = "openwrt-source"; name = "openwrt-source";
repo = "openwrt"; repo = "openwrt";
@ -20,24 +22,64 @@
rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab"; rev = "a5265497a4f6da158e95d6a450cb2cb6dc085cab";
hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8="; hash = "sha256-YYi4gkpLjbOK7bM2MGQjAyEBuXJ9JNXoz/JEmYf8xE8=";
}; };
mac80211 = pkgs.mac80211.override {
drivers = ["mt7603e"];
klibBuild = config.outputs.kernel.modulesupport;
};
in { in {
hardware = { hardware = {
defaultOutput = "tftproot"; defaultOutput = "tftproot";
loadAddress = "0x80000000"; loadAddress = "0x80000000";
entryPoint = "0x80000000"; entryPoint = "0x80000000";
radios = ["mt7603e"];
dts = { dts = {
src = "${openwrt}/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts"; src = "${openwrt}/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts";
includes = [ includes = [
"${openwrt}/target/linux/ramips/dts" "${openwrt}/target/linux/ramips/dts"
]; ];
}; };
networkInterfaces = rec {
# lan and wan ports are both behind a switch on eth0
eth =
let swconfig = oneshot {
name = "swconfig";
up = ''
PATH=${pkgs.swconfig}/bin:$PATH
swconfig dev switch0 set reset
swconfig dev switch0 set enable_vlan 1
swconfig dev switch0 vlan 1 set ports '1 2 3 4 6t'
swconfig dev switch0 vlan 2 set ports '0 6t'
swconfig dev switch0 set apply
'';
down = "swconfig dev switch0 set reset";
};
in interface {
device = "eth0";
dependencies = [swconfig];
};
lan = interface {
type = "vlan";
device = "eth0.1";
link = "eth0";
id = "1";
dependencies = [eth];
};
wan = interface {
type = "vlan";
device = "eth0.2";
id = "2";
link = "eth0";
dependencies = [eth];
};
wlan = interface {
device = "wlan0";
dependencies = [ mac80211 ];
};
};
}; };
boot.tftp = { boot.tftp = {
loadAddress = "0x00A00000"; loadAddress = "0x00A00000";
}; };
kernel = { kernel = {
src = pkgs.fetchurl { src = pkgs.fetchurl {
name = "linux.tar.gz"; name = "linux.tar.gz";
@ -101,9 +143,18 @@
NET_RALINK_RT3050 = "y"; NET_RALINK_RT3050 = "y";
NET_RALINK_SOC="y"; NET_RALINK_SOC="y";
# both the ethernet ports on this device (lan and wan)
# are behind a switch, so we need VLANs to do anything
# useful with them
VLAN_8021Q = "y";
SWCONFIG = "y"; SWCONFIG = "y";
SWPHY = "y"; SWPHY = "y";
BRIDGE = "y";
BRIDGE_VLAN_FILTERING = "y";
BRIDGE_IGMP_SNOOPING = "y";
GPIOLIB="y"; GPIOLIB="y";
GPIO_MT7621 = "y"; GPIO_MT7621 = "y";