liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

default.nix (5982B)


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