liminix

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

default.nix (4995B)


      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       inherit (pkgs) openwrt;
     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         extraPatchPhase = ''
    126           ${openwrt.applyPatches.ramips}
    127           ${openwrt.applyPatches.rt2x00}
    128         '';
    129         config = {
    130 
    131           RALINK = "y";
    132           PCI = "y";
    133           SOC_MT7620 = "y";
    134 
    135           SERIAL_8250_CONSOLE = "y";
    136           SERIAL_8250 = "y";
    137           SERIAL_CORE_CONSOLE = "y";
    138           SERIAL_OF_PLATFORM = "y";
    139 
    140           CONSOLE_LOGLEVEL_DEFAULT = "8";
    141           CONSOLE_LOGLEVEL_QUIET = "4";
    142 
    143           NET = "y";
    144           ETHERNET = "y";
    145           NET_VENDOR_RALINK = "y";
    146           NET_RALINK_MDIO = "y";
    147           NET_RALINK_MDIO_MT7620 = "y";
    148           NET_RALINK_MT7620 = "y";
    149           SWPHY = "y";
    150 
    151           SPI = "y";
    152           MTD_SPI_NOR = "y";
    153           SPI_MT7621 = "y"; # } probably don't need both of these
    154           SPI_RT2880 = "y"; # }
    155           SPI_MASTER = "y";
    156           SPI_MEM = "y";
    157 
    158           MTD = "y";
    159           MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_devs
    160 
    161           EARLY_PRINTK = "y";
    162 
    163           NEW_LEDS = "y";
    164           LEDS_CLASS = "y"; # required by rt2x00lib
    165 
    166           PRINTK_TIME = "y";
    167         }
    168         // lib.optionalAttrs (config.system.service ? vlan) {
    169           SWCONFIG = "y";
    170         };
    171         conditionalConfig = {
    172           WLAN = {
    173             WLAN_VENDOR_RALINK = "y";
    174             RT2800SOC = "m";
    175             RT2X00 = "m";
    176           };
    177         };
    178 
    179       };
    180     };
    181 }