liminix

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

default.nix (8021B)


      1 {
      2   description = ''
      3     Turris Omnia
      4     ************
      5   '';
      6 
      7   system = {
      8     crossSystem = {
      9       config = "armv7l-unknown-linux-musleabihf";
     10     };
     11   };
     12 
     13   module = {pkgs, config, lib, lim, ... }:
     14     let
     15       openwrt = pkgs.openwrt;
     16       inherit (lib) mkOption types;
     17       inherit (pkgs.liminix.services) oneshot;
     18       inherit (pkgs) liminix;
     19       mtd_by_name_links = pkgs.liminix.services.oneshot rec  {
     20         name = "mtd_by_name_links";
     21         up = ''
     22           mkdir -p /dev/mtd/by-name
     23           cd /dev/mtd/by-name
     24           for i in /sys/class/mtd/mtd*[0-9]; do
     25             ln -s ../../$(basename $i) $(cat $i/name)
     26           done
     27         '';
     28       };
     29     in {
     30       imports = [
     31         ../../modules/arch/arm.nix
     32         ../../modules/outputs/tftpboot.nix
     33         ../../modules/outputs/ext4fs.nix
     34         ../../modules/outputs/mbrimage.nix
     35         ../../modules/outputs/extlinux.nix
     36       ];
     37 
     38       config = {
     39         services.mtd-name-links = mtd_by_name_links;
     40         kernel = {
     41           src = pkgs.pkgsBuildBuild.fetchurl {
     42             name = "linux.tar.gz";
     43             url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.71.tar.gz";
     44             hash = "sha256-yhO2cXIeIgUxkSZf/4aAsF11uxyh+UUZu6D1h92vCD8=";
     45           };
     46           extraPatchPhase = ''
     47           ${pkgs.openwrt.applyPatches.mvebu}
     48         '';
     49           config = {
     50             PCI = "y";
     51             OF = "y";
     52             MEMORY = "y"; # for MVEBU_DEVBUS
     53             DMADEVICES = "y"; # for MV_XOR
     54             CPU_V7 = "y";
     55             ARCH_MULTIPLATFORM = "y";
     56             ARCH_MVEBU = "y";
     57             ARCH_MULTI_V7= "y";
     58             PCI_MVEBU = "y";
     59             AHCI_MVEBU = "y";
     60             MACH_ARMADA_38X = "y";
     61             SMP = "y";
     62 	          # this is disabled for the moment because it relies on a GCC
     63             # plugin that requires gmp.h to build, and I can't see right now
     64             # how to confgure it to find gmp
     65             STACKPROTECTOR_PER_TASK = "n";
     66             NR_CPUS = "4";
     67             VFP = "y";
     68             NEON= "y";
     69 
     70             # WARNING: unmet direct dependencies detected for ARCH_WANT_LIBATA_LEDS
     71             ATA = "y";
     72 
     73             PSTORE = "y";
     74             PSTORE_RAM = "y";
     75             PSTORE_CONSOLE = "y";
     76             PSTORE_DEFLATE_COMPRESS = "n";
     77 
     78             BLOCK = "y";
     79             MMC="y";
     80             PWRSEQ_EMMC="y";        # ???
     81             PWRSEQ_SIMPLE="y";      # ???
     82             MMC_BLOCK="y";
     83 
     84             MMC_SDHCI= "y";
     85             MMC_SDHCI_PLTFM= "y";
     86             MMC_SDHCI_PXAV3= "y";
     87             MMC_MVSDIO= "y";
     88 
     89             SERIAL_8250 = "y";
     90             SERIAL_8250_CONSOLE = "y";
     91             SERIAL_OF_PLATFORM="y";
     92             SERIAL_MVEBU_UART = "y";
     93             SERIAL_MVEBU_CONSOLE = "y";
     94 
     95             SERIAL_8250_DMA= "y";
     96             SERIAL_8250_DW= "y";
     97             SERIAL_8250_EXTENDED= "y";
     98             SERIAL_8250_MANY_PORTS= "y";
     99             SERIAL_8250_SHARE_IRQ= "y";
    100             OF_ADDRESS= "y";
    101             OF_MDIO= "y";
    102 
    103             WATCHDOG = "y";        # watchdog is enabled by u-boot
    104             ORION_WATCHDOG = "y";  # so is non-optional to keep feeding
    105 
    106             MVEBU_DEVBUS = "y"; # "Device Bus controller ...  flash devices such as NOR, NAND, SRAM, and FPGA"
    107             MVMDIO = "y";
    108             MVNETA = "y";
    109             MVNETA_BM = "y";
    110             MVNETA_BM_ENABLE = "y";
    111             SRAM = "y"; # mmio-sram is "compatible" for bm_bppi reqd by BM
    112             PHY_MVEBU_A38X_COMPHY = "y"; # for eth2
    113 
    114             MVPP2 = "y";
    115             MV_XOR = "y";
    116 
    117             # there is NOR flash on this device, which is used for U-Boot
    118             # and the rescue system (which we don't interfere with) but
    119             # also for the U-Boot environment variables (which we might
    120             # need to meddle with)
    121             MTD_SPI_NOR = "y";
    122             SPI = "y";
    123             SPI_MASTER = "y";
    124             SPI_ORION = "y";
    125 
    126             NET_DSA = "y";
    127             NET_DSA_MV88E6XXX = "y"; # depends on PTP_1588_CLOCK_OPTIONAL
    128           };
    129         };
    130         rootfsType = "ext4";
    131         boot = {
    132           commandLine = [
    133             "console=ttyS0,115200"
    134             "pcie_aspm=off" # ath9k pci incompatible with PCIe ASPM
    135           ];
    136           imageFormat = "fit";
    137         };
    138         filesystem =
    139           let
    140             inherit (pkgs.pseudofile) dir symlink;
    141             firmware = pkgs.stdenv.mkDerivation {
    142               name = "wlan-firmware";
    143               phases = ["installPhase"];
    144               installPhase = ''
    145             mkdir $out
    146             cp -r ${pkgs.linux-firmware}/lib/firmware/ath10k/QCA988X $out
    147           '';
    148             };
    149           in dir {
    150             lib = dir {
    151               firmware = dir {
    152                 ath10k = symlink firmware;
    153               };
    154             };
    155             etc = dir {
    156               "fw_env.config" =
    157                 let f = pkgs.writeText "fw_env.config" ''
    158                   /dev/mtd/by-name/u-boot-env 0x0 0x10000 0x10000
    159                 '';
    160                 in symlink f;
    161             };
    162           };
    163 
    164         boot.tftp = {
    165           loadAddress = lim.parseInt "0x1000000";
    166           kernelFormat = "zimage";
    167           compressRoot = true;
    168         };
    169 
    170         hardware = let
    171           mac80211 = pkgs.mac80211.override {
    172             drivers = ["ath9k_pci" "ath10k_pci"];
    173             klibBuild = config.system.outputs.kernel.modulesupport;
    174           };
    175         in {
    176           defaultOutput = "mtdimage";
    177           loadAddress = lim.parseInt "0x00800000"; # "0x00008000";
    178           entryPoint = lim.parseInt "0x00800000"; # "0x00008000";
    179           rootDevice = "/dev/mtdblock0";
    180 
    181           dts = {
    182             src = "${config.system.outputs.kernel.modulesupport}/arch/arm/boot/dts/armada-385-turris-omnia.dts";
    183             includes =  [
    184               "${config.system.outputs.kernel.modulesupport}/arch/arm/boot/dts/"
    185             ];
    186           };
    187           flash.eraseBlockSize = 65536; # only used for tftpboot
    188           networkInterfaces =
    189             let
    190               inherit (config.system.service.network) link;
    191               inherit (config.system.service) bridge;
    192             in rec {
    193               en70000 = link.build {
    194                 # in armada-38x.dtsi this is eth0.
    195                 # It's connected to port 5 of the 88E6176 switch
    196                 devpath = "/devices/platform/soc/soc:internal-regs/f1070000.ethernet";
    197                 # name is unambiguous but not very semantic
    198                 ifname = "en70000";
    199               };
    200               en30000 = link.build {
    201                 # in armada-38x.dtsi this is eth1
    202                 # It's connected to port 6 of the 88E6176 switch
    203                 devpath = "/devices/platform/soc/soc:internal-regs/f1030000.ethernet";
    204                 # name is unambiguous but not very semantic
    205                 ifname = "en30000";
    206               };
    207               # the default (from the dts? I'm guessing) behavour for
    208               # lan ports on the switch is to attach them to
    209               # en30000. It should be possible to do something better,
    210               # per
    211               # https://www.kernel.org/doc/html/latest/networking/dsa/configuration.html#affinity-of-user-ports-to-cpu-ports
    212               # but apparently OpenWrt doesn't either so maybe it's more
    213               # complicated than it looks
    214 
    215               wan = link.build {
    216                 # in armada-38x.dtsi this is eth2. It may be connected to
    217                 # an ethernet phy or to the SFP cage, depending on a gpio
    218                 devpath = "/devices/platform/soc/soc:internal-regs/f1034000.ethernet";
    219                 ifname = "wan";
    220               };
    221 
    222               lan = link.build {
    223                 ifname = "lan1";
    224               };
    225 
    226               wlan = link.build {
    227                 ifname = "wlan0";
    228                 dependencies = [ mac80211 ];
    229               };
    230               wlan5 = link.build {
    231                 ifname = "wlan1";
    232                 dependencies = [ mac80211 ];
    233               };
    234             };
    235         };
    236       };
    237     };
    238 }