default.nix (5840B)
1 # GL.iNet GL-MT300A 2 3 { 4 system = { 5 crossSystem = { 6 config = "mipsel-unknown-linux-musl"; 7 gcc = { 8 abi = "32"; 9 arch = "mips32"; # maybe mips_24kc- 10 }; 11 }; 12 }; 13 14 description = '' 15 GL.iNet GL-MT300A 16 ***************** 17 18 The GL-MT300A is based on a MT7620 chipset. 19 20 For flashing from U-Boot, the firmware partition is from 21 0xbc050000 to 0xbcfd0000. 22 23 WiFi on this device is provided by the rt2800soc module. It 24 expects firmware to be present in the "factory" MTD partition, so 25 - assuming we want to use the wireless - we need to build MTD 26 support into the kernel even if we're using TFTP root. 27 28 Installation 29 ============ 30 31 The stock vendor firmware is a fork of OpenWrt, meaning that the 32 binary created by :ref:`system-outputs-mtdimage` can be flashed 33 using the vendor web UI or the U-Boot emergency "unbrick" routine. 34 35 For flashing from an existing Liminix system (we think) it 36 is necessary to first boot into a :ref:`system-outputs-kexecboot` 37 system, otherwise you'll be overwriting flash partitions while 38 they're in use - and that might not end well. 39 40 Vendor web page: https://www.gl-inet.com/products/gl-mt300a/ 41 42 OpenWrt web page: https://openwrt.org/toh/gl.inet/gl-mt300a 43 44 ''; 45 46 module = { pkgs, config, lib, lim, ...}: 47 let 48 inherit (pkgs.liminix.networking) interface; 49 inherit (pkgs) openwrt; 50 mac80211 = pkgs.kmodloader.override { 51 targets = ["rt2800soc"]; 52 inherit (config.system.outputs) kernel; 53 }; 54 in { 55 imports = [ 56 ../../modules/arch/mipsel.nix 57 ../../modules/outputs/tftpboot.nix 58 ../../modules/outputs/mtdimage.nix 59 ../../modules/outputs/jffs2.nix 60 ]; 61 hardware = { 62 defaultOutput = "mtdimage"; 63 loadAddress = lim.parseInt "0x80000000"; 64 entryPoint = lim.parseInt "0x80000000"; 65 66 # Creating 5 MTD partitions on "spi0.0": 67 # 0x000000000000-0x000000030000 : "u-boot" 68 # 0x000000030000-0x000000040000 : "u-boot-env" 69 # 0x000000040000-0x000000050000 : "factory" 70 # 0x000000050000-0x000000fd0000 : "firmware" 71 # 2 uimage-fw partitions found on MTD device firmware 72 # Creating 2 MTD partitions on "firmware": 73 # 0x000000000000-0x000000260000 : "kernel" 74 # 0x000000260000-0x000000f80000 : "rootfs" 75 76 flash = { 77 address = lim.parseInt "0xbc050000"; 78 size = lim.parseInt "0xf80000"; 79 eraseBlockSize = 65536; 80 }; 81 rootDevice = "/dev/mtdblock5"; 82 83 dts = { 84 src = "${openwrt.src}/target/linux/ramips/dts/mt7620a_glinet_gl-mt300a.dts"; 85 includes = [ 86 "${openwrt.src}/target/linux/ramips/dts" 87 ]; 88 }; 89 networkInterfaces = 90 let 91 inherit (config.system.service.network) link; 92 inherit (config.system.service) vlan; 93 inherit (pkgs.liminix.services) oneshot; 94 swconfig = oneshot { 95 name = "swconfig"; 96 up = '' 97 PATH=${pkgs.swconfig}/bin:$PATH 98 swconfig dev switch0 set reset 99 swconfig dev switch0 set enable_vlan 1 100 swconfig dev switch0 vlan 1 set ports '1 2 3 4 6t' 101 swconfig dev switch0 vlan 2 set ports '0 6t' 102 swconfig dev switch0 set apply 103 ''; 104 down = "${pkgs.swconfig}/bin/swconfig dev switch0 set reset"; 105 }; 106 in rec { 107 eth = link.build { ifname = "eth0"; }; 108 # lan and wan ports are both behind a switch on eth0 109 lan = vlan.build { 110 ifname = "eth0.1"; 111 primary = eth; 112 vid = "1"; 113 dependencies = [swconfig eth]; 114 }; 115 wan = vlan.build { 116 ifname = "eth0.2"; 117 primary = eth; 118 vid = "2"; 119 dependencies = [swconfig eth]; 120 }; 121 wlan = link.build { 122 ifname = "wlan0"; 123 dependencies = [ mac80211 ]; 124 }; 125 }; 126 }; 127 boot.tftp = { 128 loadAddress = lim.parseInt "0x00A00000"; 129 }; 130 131 kernel = { 132 src = pkgs.fetchurl { 133 name = "linux.tar.gz"; 134 url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.137.tar.gz"; 135 hash = "sha256-PkdzUKZ0IpBiWe/RS70J76JKnBFzRblWcKlaIFNxnHQ="; 136 }; 137 extraPatchPhase = '' 138 ${openwrt.applyPatches.ramips} 139 ''; 140 config = { 141 142 RALINK = "y"; 143 PCI = "y"; 144 SOC_MT7620 = "y"; 145 146 SERIAL_8250_CONSOLE = "y"; 147 SERIAL_8250 = "y"; 148 SERIAL_CORE_CONSOLE = "y"; 149 SERIAL_OF_PLATFORM = "y"; 150 151 CONSOLE_LOGLEVEL_DEFAULT = "8"; 152 CONSOLE_LOGLEVEL_QUIET = "4"; 153 154 NET = "y"; 155 ETHERNET = "y"; 156 NET_VENDOR_RALINK = "y"; 157 NET_RALINK_MDIO = "y"; 158 NET_RALINK_MDIO_MT7620 = "y"; 159 NET_RALINK_MT7620 = "y"; 160 SWPHY = "y"; 161 162 SPI = "y"; 163 MTD_SPI_NOR = "y"; 164 SPI_MT7621 = "y"; # } probably don't need both of these 165 SPI_RT2880 = "y"; # } 166 SPI_MASTER= "y"; 167 SPI_MEM= "y"; 168 169 MTD = "y"; 170 MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_devs 171 172 EARLY_PRINTK = "y"; 173 174 NEW_LEDS = "y"; 175 LEDS_CLASS = "y"; # required by rt2x00lib 176 177 PRINTK_TIME = "y"; 178 } // lib.optionalAttrs (config.system.service ? vlan) { 179 SWCONFIG = "y"; 180 }; 181 conditionalConfig = { 182 WLAN = { 183 WLAN_VENDOR_RALINK = "y"; 184 RT2800SOC = "m"; 185 RT2X00 = "m"; 186 }; 187 }; 188 189 }; 190 }; 191 }