liminix

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

default.nix (5132B)


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