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