liminix

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

default.nix (5103B)


      1 # GL.INet GL-MT300N v2
      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   module = { pkgs, config, ...}:
     15     let
     16       inherit (pkgs.liminix.networking) interface;
     17       inherit (pkgs.liminix.services) oneshot;
     18       inherit (pkgs.pseudofile) dir symlink;
     19       inherit (pkgs) openwrt;
     20 
     21       mac80211 = pkgs.mac80211.override {
     22         drivers = ["mt7603e"];
     23         klibBuild = config.system.outputs.kernel.modulesupport;
     24       };
     25       wlan_firmware = pkgs.fetchurl {
     26         url = "https://github.com/openwrt/mt76/raw/f24b56f935392ca1d35fae5fd6e56ef9deda4aad/firmware/mt7628_e2.bin";
     27         hash = "sha256:1dkhfznmdz6s50kwc841x3wj0h6zg6icg5g2bim9pvg66as2vmh9";
     28       };
     29     in {
     30       filesystem = dir {
     31         lib = dir {
     32           firmware = dir {
     33             "mt7628_e2.bin" = symlink wlan_firmware;
     34           };
     35         };
     36       };
     37       hardware = {
     38         defaultOutput = "tftpboot";
     39         loadAddress = "0x80000000";
     40         entryPoint  = "0x80000000";
     41 
     42         flash = {
     43           address = "0xbc050000";
     44           size = "0xfb0000";
     45           eraseBlockSize = "65536";
     46         };
     47         rootDevice = "/dev/mtdblock5";
     48 
     49         dts = {
     50           src = "${openwrt.src}/target/linux/ramips/dts/mt7628an_glinet_gl-mt300n-v2.dts";
     51           includes = [
     52             "${openwrt.src}/target/linux/ramips/dts"
     53           ];
     54         };
     55         networkInterfaces = rec {
     56           # lan and wan ports are both behind a switch on eth0
     57           eth =
     58             let swconfig = oneshot {
     59                   name = "swconfig";
     60                   up = ''
     61                     PATH=${pkgs.swconfig}/bin:$PATH
     62                     swconfig dev switch0 set reset
     63                     swconfig dev switch0 set enable_vlan 1
     64                     swconfig dev switch0 vlan 1 set ports '1 2 3 4 6t'
     65                     swconfig dev switch0 vlan 2 set ports '0 6t'
     66                     swconfig dev switch0 set apply
     67                   '';
     68                   down = "swconfig dev switch0 set reset";
     69                 };
     70             in interface {
     71               device = "eth0";
     72               dependencies =  [swconfig];
     73             };
     74           lan = interface {
     75             type = "vlan";
     76             device = "eth0.1";
     77             link = "eth0";
     78             id = "1";
     79             dependencies = [eth];
     80           };
     81           wan = interface {
     82             type = "vlan";
     83             device = "eth0.2";
     84             id = "2";
     85             link = "eth0";
     86             dependencies = [eth];
     87           };
     88           wlan = interface {
     89             device = "wlan0";
     90             dependencies = [ mac80211 ];
     91           };
     92         };
     93       };
     94       boot.tftp = {
     95         # 20MB seems to give enough room to uncompress the kernel
     96         # without anything getting trodden on. 10MB was too small
     97         loadAddress = "0x1400000";
     98       };
     99 
    100       kernel = {
    101         src = pkgs.fetchurl {
    102           name = "linux.tar.gz";
    103           url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz";
    104           hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8=";
    105         };
    106         extraPatchPhase = ''
    107           ${openwrt.applyPatches.ramips}
    108         '';
    109         config = {
    110           MIPS_ELF_APPENDED_DTB = "y";
    111           OF = "y";
    112           USE_OF = "y";
    113 
    114           RALINK = "y";
    115           PCI = "y";
    116           SOC_MT7620 = "y";
    117           CPU_LITTLE_ENDIAN= "y";
    118 
    119           SERIAL_8250_CONSOLE = "y";
    120           SERIAL_8250 = "y";
    121           SERIAL_CORE_CONSOLE = "y";
    122           SERIAL_OF_PLATFORM = "y";
    123 
    124           CONSOLE_LOGLEVEL_DEFAULT = "8";
    125           CONSOLE_LOGLEVEL_QUIET = "4";
    126 
    127           MTD = "y";
    128           MTD_CMDLINE_PARTS = "y";
    129           MTD_BLOCK = "y";          # fix undefined ref to register_mtd_blktrans_dev
    130 
    131           SPI = "y";
    132           MTD_SPI_NOR = "y";
    133           SPI_MT7621 = "y";
    134           SPI_MASTER= "y";
    135           SPI_MEM= "y";
    136 
    137           REGULATOR = "y";
    138           REGULATOR_FIXED_VOLTAGE = "y";
    139 
    140           NET = "y";
    141           NETDEVICES = "y";
    142           ETHERNET = "y";
    143 
    144           PHYLIB = "y";
    145           AT803X_PHY="y";
    146           FIXED_PHY="y";
    147           GENERIC_PHY="y";
    148           NET_VENDOR_RALINK = "y";
    149           NET_RALINK_RT3050 = "y";
    150           NET_RALINK_SOC="y";
    151 
    152           # both the ethernet ports on this device (lan and wan)
    153           # are behind a switch, so we need VLANs to do anything
    154           # useful with them
    155 
    156           VLAN_8021Q = "y";
    157           SWCONFIG = "y";
    158           SWPHY = "y";
    159 
    160           BRIDGE = "y";
    161           BRIDGE_VLAN_FILTERING = "y";
    162           BRIDGE_IGMP_SNOOPING = "y";
    163 
    164           WATCHDOG = "y";
    165           RALINK_WDT = "y";  # watchdog
    166           MT7621_WDT = "y";  # or it might be this one
    167 
    168           GPIOLIB="y";
    169           GPIO_MT7621 = "y";
    170 
    171           PHY_RALINK_USB = "y";
    172 
    173           CMDLINE_PARTITION = "y";
    174           EARLY_PRINTK = "y";
    175 
    176           PARTITION_ADVANCED = "y";
    177           PRINTK_TIME = "y";
    178           SQUASHFS = "y";
    179           SQUASHFS_XZ = "y";
    180         };
    181       };
    182     };
    183 }