default.nix (5840B)
1 { 2 system = { 3 crossSystem = { 4 config = "mipsel-unknown-linux-musl"; 5 gcc = { 6 abi = "32"; 7 arch = "mips32"; # maybe mips_24kc- 8 }; 9 }; 10 }; 11 12 description = '' 13 == GL.iNet GL-MT300N-v2 14 15 The GL-MT300N-v2 "Mango" is is very similar to the `+gl-mt300a+`, but is 16 based on the MT7628 chipset instead of MT7620. It's also marginally 17 cheaper and comes in a yellow case not a blue one. Be sure your device 18 is v2 not v1, which is a different animal and has only half as much RAM. 19 20 === Installation 21 22 The stock vendor firmware is a fork of OpenWrt, meaning that the binary 23 created by `+system-outputs-mtdimage+` can be flashed using the vendor 24 web UI or the U-Boot emergency "unbrick" routine. 25 26 Flashing over an existing Liminix system is not possible while that 27 system is running, otherwise you'll be overwriting flash partitions 28 while they're in use - and that might not end well. Configure the system 29 with `+levitate+` if you need to make it upgradable. 30 31 Vendor web page: https://www.gl-inet.com/products/gl-mt300n-v2/ 32 33 OpenWrt web page: https://openwrt.org/toh/gl.inet/gl-mt300n_v2 34 35 ''; 36 37 module = 38 { 39 pkgs, 40 config, 41 lib, 42 lim, 43 ... 44 }: 45 let 46 inherit (pkgs.liminix.services) oneshot; 47 inherit (pkgs.pseudofile) dir symlink; 48 inherit (pkgs) openwrt; 49 50 mac80211 = pkgs.kmodloader.override { 51 targets = [ "mt7603e" ]; 52 inherit (config.system.outputs) kernel; 53 }; 54 wlan_firmware = pkgs.fetchurl { 55 url = "https://github.com/openwrt/mt76/raw/f24b56f935392ca1d35fae5fd6e56ef9deda4aad/firmware/mt7628_e2.bin"; 56 hash = "sha256:1dkhfznmdz6s50kwc841x3wj0h6zg6icg5g2bim9pvg66as2vmh9"; 57 }; 58 in 59 { 60 imports = [ 61 ../../modules/arch/mipsel.nix 62 ../../modules/outputs/tftpboot.nix 63 ../../modules/outputs/mtdimage.nix 64 ../../modules/outputs/jffs2.nix 65 ]; 66 filesystem = dir { 67 lib = dir { 68 firmware = dir { 69 "mt7628_e2.bin" = symlink wlan_firmware; 70 }; 71 }; 72 }; 73 hardware = { 74 defaultOutput = "mtdimage"; 75 loadAddress = lim.parseInt "0x80000000"; 76 entryPoint = lim.parseInt "0x80000000"; 77 78 flash = { 79 address = lim.parseInt "0xbc050000"; 80 size = lim.parseInt "0xfb0000"; 81 eraseBlockSize = 65536; 82 }; 83 rootDevice = "/dev/mtdblock5"; 84 85 dts = { 86 src = "${openwrt.src}/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts"; 87 includePaths = [ 88 "${openwrt.src}/target/linux/ramips/dts" 89 ]; 90 }; 91 networkInterfaces = 92 let 93 inherit (config.system.service.network) link; 94 inherit (config.system.service) vlan; 95 swconfig = oneshot { 96 name = "swconfig"; 97 up = '' 98 PATH=${pkgs.swconfig}/bin:$PATH 99 swconfig dev switch0 set reset 100 swconfig dev switch0 set enable_vlan 1 101 swconfig dev switch0 vlan 1 set ports '1 2 3 4 6t' 102 swconfig dev switch0 vlan 2 set ports '0 6t' 103 swconfig dev switch0 set apply 104 ''; 105 down = "${pkgs.swconfig}/bin/swconfig dev switch0 set reset"; 106 }; 107 in 108 rec { 109 eth = link.build { 110 ifname = "eth0"; 111 dependencies = [ swconfig ]; 112 }; 113 # lan and wan ports are both behind a switch on eth0 114 lan = vlan.build { 115 ifname = "eth0.1"; 116 primary = eth; 117 vid = "1"; 118 }; 119 wan = vlan.build { 120 ifname = "eth0.2"; 121 primary = eth; 122 vid = "2"; 123 }; 124 wlan = link.build { 125 ifname = "wlan0"; 126 dependencies = [ mac80211 ]; 127 }; 128 }; 129 }; 130 boot.tftp = { 131 # 20MB seems to give enough room to uncompress the kernel 132 # without anything getting trodden on. 10MB was too small 133 loadAddress = lim.parseInt "0x1400000"; 134 appendDTB = true; 135 }; 136 137 kernel = { 138 extraPatchPhase = '' 139 ${openwrt.applyPatches.ramips} 140 ''; 141 config = { 142 143 RALINK = "y"; 144 PCI = "y"; 145 SOC_MT7620 = "y"; 146 147 SERIAL_8250_CONSOLE = "y"; 148 SERIAL_8250 = "y"; 149 SERIAL_CORE_CONSOLE = "y"; 150 SERIAL_OF_PLATFORM = "y"; 151 152 CONSOLE_LOGLEVEL_DEFAULT = "8"; 153 CONSOLE_LOGLEVEL_QUIET = "4"; 154 155 MTD = "y"; 156 MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_dev 157 158 SPI = "y"; 159 MTD_SPI_NOR = "y"; 160 SPI_MT7621 = "y"; 161 SPI_MASTER = "y"; 162 SPI_MEM = "y"; 163 164 REGULATOR = "y"; 165 REGULATOR_FIXED_VOLTAGE = "y"; 166 167 NET = "y"; 168 ETHERNET = "y"; 169 170 PHYLIB = "y"; 171 AT803X_PHY = "y"; 172 FIXED_PHY = "y"; 173 GENERIC_PHY = "y"; 174 NET_VENDOR_RALINK = "y"; 175 NET_RALINK_RT3050 = "y"; 176 NET_RALINK_SOC = "y"; 177 SWPHY = "y"; 178 179 GPIOLIB = "y"; 180 GPIO_MT7621 = "y"; 181 182 PHY_RALINK_USB = "y"; 183 184 EARLY_PRINTK = "y"; 185 186 PRINTK_TIME = "y"; 187 } 188 // lib.optionalAttrs (config.system.service ? vlan) { 189 SWCONFIG = "y"; 190 } 191 // lib.optionalAttrs (config.system.service ? watchdog) { 192 RALINK_WDT = "y"; # watchdog 193 MT7621_WDT = "y"; # or it might be this one 194 }; 195 conditionalConfig = { 196 WLAN = { 197 WLAN_VENDOR_RALINK = "y"; 198 WLAN_VENDOR_MEDIATEK = "y"; 199 MT7603E = "m"; 200 }; 201 }; 202 203 }; 204 205 }; 206 }