liminix

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

default.nix (5110B)


      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     GL.iNet GL-MT300A
     16     *****************
     17 
     18     The GL-MT300A is based on a MT7620 chipset.
     19 
     20     For flashing from U-Boot, the firmware partition is from
     21     0xbc050000 to 0xbcfd0000.
     22 
     23     WiFi on this device is provided by the rt2800soc module. It
     24     expects firmware to be present in the "factory" MTD partition, so
     25     - assuming we want to use the wireless - we need to build MTD
     26     support into the kernel even if we're using TFTP root.
     27 
     28     Installation
     29     ============
     30 
     31     The stock vendor firmware is a fork of OpenWrt, meaning that the
     32     binary created by :ref:`system-outputs-mtdimage` can be flashed
     33     using the vendor web UI or the U-Boot emergency "unbrick" routine.
     34 
     35     Flashing over an existing Liminix system is not possible while
     36     that system is running, otherwise you'll be overwriting flash
     37     partitions while they're in use - and that might not end well.
     38     Configure the system with :ref:`levitate` if you need to
     39     make it upgradable.
     40 
     41     Vendor web page: https://www.gl-inet.com/products/gl-mt300a/
     42 
     43     OpenWrt web page: https://openwrt.org/toh/gl.inet/gl-mt300a
     44 
     45   '';
     46 
     47   module =
     48     {
     49       pkgs,
     50       config,
     51       lib,
     52       lim,
     53       ...
     54     }:
     55     let
     56       inherit (pkgs) openwrt;
     57       mac80211 = pkgs.kmodloader.override {
     58         targets = [ "rt2800soc" ];
     59         inherit (config.system.outputs) kernel;
     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       hardware = {
     70         defaultOutput = "mtdimage";
     71         loadAddress = lim.parseInt "0x80000000";
     72         entryPoint = lim.parseInt "0x80000000";
     73 
     74         # Creating 5 MTD partitions on "spi0.0":
     75         # 0x000000000000-0x000000030000 : "u-boot"
     76         # 0x000000030000-0x000000040000 : "u-boot-env"
     77         # 0x000000040000-0x000000050000 : "factory"
     78         # 0x000000050000-0x000000fd0000 : "firmware"
     79         # 2 uimage-fw partitions found on MTD device firmware
     80         # Creating 2 MTD partitions on "firmware":
     81         # 0x000000000000-0x000000260000 : "kernel"
     82         # 0x000000260000-0x000000f80000 : "rootfs"
     83 
     84         flash = {
     85           address = lim.parseInt "0xbc050000";
     86           size = lim.parseInt "0xf80000";
     87           eraseBlockSize = 65536;
     88         };
     89         rootDevice = "/dev/mtdblock5";
     90 
     91         dts = {
     92           src = "${openwrt.src}/target/linux/ramips/dts/mt7620a_glinet_gl-mt300a.dts";
     93           includePaths = [
     94             "${openwrt.src}/target/linux/ramips/dts"
     95           ];
     96         };
     97         networkInterfaces =
     98           let
     99             inherit (config.system.service.network) link;
    100             inherit (config.system.service) vlan;
    101           in
    102           rec {
    103             eth = link.build { ifname = "eth0"; };
    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         loadAddress = lim.parseInt "0x00A00000";
    123         appendDTB = true;
    124       };
    125 
    126       kernel = {
    127         extraPatchPhase = ''
    128           ${openwrt.applyPatches.ramips}
    129           ${openwrt.applyPatches.rt2x00}
    130         '';
    131         config =
    132           {
    133 
    134             RALINK = "y";
    135             PCI = "y";
    136             SOC_MT7620 = "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             WLAN_VENDOR_RALINK = "y";
    177             RT2800SOC = "m";
    178             RT2X00 = "m";
    179           };
    180         };
    181 
    182       };
    183     };
    184 }