diff --git a/devices/zyxel-nwa50ax/default.nix b/devices/zyxel-nwa50ax/default.nix index 2b4813d..2646814 100644 --- a/devices/zyxel-nwa50ax/default.nix +++ b/devices/zyxel-nwa50ax/default.nix @@ -135,232 +135,250 @@ rec { ../../modules/zyxel-dual-image ]; - nixpkgs.hostPlatform = system.crossSystem; - - filesystem = dir { - lib = dir { - firmware = dir { - mediatek = dir { - "mt7915_wa.bin" = symlink wlan_firmware; - "mt7915_wm.bin" = symlink wlan_firmware'; - "mt7915_rom_patch.bin" = symlink wlan_firmware''; - }; + options = { + hardware.wlanMacAddresses = { + wlan0 = lib.mkOption { + type = lib.types.str; + description = "Mac address of wlan0 device"; + }; + wlan1 = lib.mkOption { + type = lib.types.str; + description = "Mac address of wlan1 device"; }; }; }; - rootfsType = "ubifs"; - hardware = { - # Taken from OpenWRT - # root@OpenWrt:/# ubinfo /dev/ubi0 - # ubi0 - # Volumes count: 2 - # Logical eraseblock size: 126976 bytes, 124.0 KiB - # Total amount of logical eraseblocks: 256 (32505856 bytes, 31.0 MiB) - # Amount of available logical eraseblocks: 0 (0 bytes) - # Maximum count of volumes 128 - # Count of bad physical eraseblocks: 0 - # Count of reserved physical eraseblocks: 19 - # Current maximum erase counter value: 2 - # Minimum input/output unit size: 2048 bytes - # Character device major/minor: 250:0 - # Present volumes: 0, 1 - ubi = { - minIOSize = "2048"; - logicalEraseBlockSize = "126976"; - physicalEraseBlockSize = "128KiB"; - maxLEBcount = "256"; - }; + config = { - flash.eraseBlockSize = 64 * 1024; + nixpkgs.hostPlatform = system.crossSystem; - # This is a FIT containing a kernel padded and - # a UBI volume rootfs. - defaultOutput = "zyxel-nwa-fit"; - - loadAddress = lim.parseInt "0x80001000"; - entryPoint = lim.parseInt "0x80001000"; - # Aligned on 2kb. - alignment = 2048; - - rootDevice = "ubi0:rootfs"; - alternativeRootDevice = "ubi1:rootfs"; - - # Auto-attach MTD devices: ubi_a then ubi_b. - ubi.mtds = [ "ubi_a" "ubi_b" ]; - - dts = { - # Strong DTB assumptions: - # ubi_a and ubi_b are two MTD devices. - # If those changes, disaster will occur. - src = ./dtb/mt7621_zyxel_nwa50ax.dtsi; - includes = [ - "${./dtb}" - "${openwrt.src}/target/linux/ramips/dts" - ]; - }; - networkInterfaces = - let - inherit (config.system.service.network) link; - in { - eth = link.build { ifname = "eth0"; }; - lan = link.build { ifname = "lan"; }; - wlan0 = link.build { - ifname = "wlan0"; - dependencies = [ mac80211 ]; - }; - wlan1 = link.build { - ifname = "wlan1"; - dependencies = [ mac80211 ]; + filesystem = dir { + lib = dir { + firmware = dir { + mediatek = dir { + "mt7915_wa.bin" = symlink wlan_firmware; + "mt7915_wm.bin" = symlink wlan_firmware'; + "mt7915_rom_patch.bin" = symlink wlan_firmware''; + }; }; }; - }; - - boot = { - # Critical because NWA50AX will extend your cmdline with the image number booted. - # and some bootloader version. - # You don't want to find yourself being overridden. - commandLineDtbNode = "bootargs-override"; - - imageFormat = "fit"; - tftp = { - # 20MB is pretty good on this device as we have plenty of RAM. - freeSpaceBytes = 20 * 1024 * 1024; - appendDTB = true; - loadAddress = lim.parseInt "0x2000000"; }; - }; - # Dual image management service in userspace. - services.zyxel-dual-image = config.boot.zyxel-dual-image.build { - ensureActiveImage = "primary"; - # TODO: use mtd names rather… - # primary and secondary are always /dev/mtd3 by virtue of the - # dtb being not too wrong… - # TODO: remove this hack. - primaryMtdPartition = "/dev/mtd3"; - secondaryMtdPartition = "/dev/mtd3"; - bootConfigurationMtdPartition = "/dev/mtd12"; - }; + rootfsType = "ubifs"; + hardware = { + # Taken from OpenWRT + # root@OpenWrt:/# ubinfo /dev/ubi0 + # ubi0 + # Volumes count: 2 + # Logical eraseblock size: 126976 bytes, 124.0 KiB + # Total amount of logical eraseblocks: 256 (32505856 bytes, 31.0 MiB) + # Amount of available logical eraseblocks: 0 (0 bytes) + # Maximum count of volumes 128 + # Count of bad physical eraseblocks: 0 + # Count of reserved physical eraseblocks: 19 + # Current maximum erase counter value: 2 + # Minimum input/output unit size: 2048 bytes + # Character device major/minor: 250:0 + # Present volumes: 0, 1 + ubi = { + minIOSize = "2048"; + logicalEraseBlockSize = "126976"; + physicalEraseBlockSize = "128KiB"; + maxLEBcount = "256"; + }; - # DEVICE_VENDOR := ZyXEL - # KERNEL_SIZE := 8192k - # DEVICE_PACKAGES := kmod-mt7915-firmware zyxel-bootconfig - # KERNEL := kernel-bin | lzma | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb - # IMAGES += factory.bin ramboot-factory.bin - # IMAGE/factory.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi | zyxel-nwa-fit - # IMAGE/ramboot-factory.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi + flash.eraseBlockSize = 64 * 1024; - kernel = { - src = pkgs.fetchurl { - name = "linux.tar.gz"; - url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.137.tar.gz"; - hash = "sha256-PkdzUKZ0IpBiWe/RS70J76JKnBFzRblWcKlaIFNxnHQ="; + # This is a FIT containing a kernel padded and + # a UBI volume rootfs. + defaultOutput = "zyxel-nwa-fit"; + + loadAddress = lim.parseInt "0x80001000"; + entryPoint = lim.parseInt "0x80001000"; + # Aligned on 2kb. + alignment = 2048; + + rootDevice = "ubi0:rootfs"; + alternativeRootDevice = "ubi1:rootfs"; + + # Auto-attach MTD devices: ubi_a then ubi_b. + ubi.mtds = [ "ubi_a" "ubi_b" ]; + + dts = { + # Strong DTB assumptions: + # ubi_a and ubi_b are two MTD devices. + # If those changes, disaster will occur. + src = ./dtb/mt7621_zyxel_nwa50ax.dtsi; + includes = [ + "${./dtb}" + "${openwrt.src}/target/linux/ramips/dts" + ]; + }; + networkInterfaces = + let + inherit (config.system.service.network) link; + in { + eth = link.build { ifname = "eth0"; }; + lan = link.build { ifname = "lan"; }; + wlan0 = link.build { + ifname = "wlan0"; + dependencies = [ mac80211 ]; + mac = config.hardware.wlanMacAddresses.wlan0; + }; + wlan1 = link.build { + ifname = "wlan1"; + dependencies = [ mac80211 ]; + mac = config.hardware.wlanMacAddresses.wlan1; + }; + }; }; - extraPatchPhase = '' - ${openwrt.applyPatches.ramips} - ''; - config = { + boot = { + # Critical because NWA50AX will extend your cmdline with the image number booted. + # and some bootloader version. + # You don't want to find yourself being overridden. + commandLineDtbNode = "bootargs-override"; - RALINK = "y"; - PCI = "y"; - PHY_MT7621_PCI = "y"; - PCIE_MT7621 = "y"; - SOC_MT7621 = "y"; - CLK_MT7621 = "y"; - CLOCKSOURCE_WATCHDOG = "y"; + imageFormat = "fit"; + tftp = { + # 20MB is pretty good on this device as we have plenty of RAM. + freeSpaceBytes = 20 * 1024 * 1024; + appendDTB = true; + loadAddress = lim.parseInt "0x2000000"; + }; + }; - SERIAL_8250_CONSOLE = "y"; - SERIAL_8250 = "y"; - SERIAL_CORE_CONSOLE = "y"; - SERIAL_OF_PLATFORM = "y"; - SERIAL_8250_NR_UARTS = "3"; - SERIAL_8250_RUNTIME_UARTS = "3"; - SERIAL_MCTRL_GPIO = "y"; + # Dual image management service in userspace. + services.zyxel-dual-image = config.boot.zyxel-dual-image.build { + ensureActiveImage = "primary"; + # TODO: use mtd names rather… + # primary and secondary are always /dev/mtd3 by virtue of the + # dtb being not too wrong… + # TODO: remove this hack. + primaryMtdPartition = "/dev/mtd3"; + secondaryMtdPartition = "/dev/mtd3"; + bootConfigurationMtdPartition = "/dev/mtd12"; + }; - CONSOLE_LOGLEVEL_DEFAULT = "8"; - CONSOLE_LOGLEVEL_QUIET = "4"; + # DEVICE_VENDOR := ZyXEL + # KERNEL_SIZE := 8192k + # DEVICE_PACKAGES := kmod-mt7915-firmware zyxel-bootconfig + # KERNEL := kernel-bin | lzma | fit lzma $$(KDIR)/image-$$(firstword $$(DEVICE_DTS)).dtb + # IMAGES += factory.bin ramboot-factory.bin + # IMAGE/factory.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi | zyxel-nwa-fit + # IMAGE/ramboot-factory.bin := append-kernel | pad-to $$(KERNEL_SIZE) | append-ubi - # MTD_UBI_BEB_LIMIT = "20"; - # MTD_UBI_WL_THRESHOLD = "4096"; + kernel = { + src = pkgs.fetchurl { + name = "linux.tar.gz"; + url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.137.tar.gz"; + hash = "sha256-PkdzUKZ0IpBiWe/RS70J76JKnBFzRblWcKlaIFNxnHQ="; + }; + extraPatchPhase = '' + ${openwrt.applyPatches.ramips} - MTD = "y"; - MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_dev - MTD_RAW_NAND = "y"; - MTD_NAND_MT7621 = "y"; - MTD_NAND_MTK_BMT = "y"; # Bad-block Management Table - MTD_NAND_ECC_SW_HAMMING= "y"; - MTD_SPI_NAND= "y"; - MTD_OF_PARTS = "y"; - MTD_NAND_CORE= "y"; - MTD_SPLIT_FIRMWARE= "y"; - MTD_SPLIT_FIT_FW= "y"; + ''; + config = { - PINCTRL = "y"; - PINCTRL_MT7621 = "y"; + RALINK = "y"; + PCI = "y"; + PHY_MT7621_PCI = "y"; + PCIE_MT7621 = "y"; + SOC_MT7621 = "y"; + CLK_MT7621 = "y"; + CLOCKSOURCE_WATCHDOG = "y"; - I2C = "y"; - I2C_MT7621 = "y"; + SERIAL_8250_CONSOLE = "y"; + SERIAL_8250 = "y"; + SERIAL_CORE_CONSOLE = "y"; + SERIAL_OF_PLATFORM = "y"; + SERIAL_8250_NR_UARTS = "3"; + SERIAL_8250_RUNTIME_UARTS = "3"; + SERIAL_MCTRL_GPIO = "y"; - SPI = "y"; - MTD_SPI_NOR = "y"; - SPI_MT7621 = "y"; - SPI_MASTER = "y"; - SPI_MEM = "y"; + CONSOLE_LOGLEVEL_DEFAULT = "8"; + CONSOLE_LOGLEVEL_QUIET = "4"; - REGULATOR = "y"; - REGULATOR_FIXED_VOLTAGE = "y"; - RESET_CONTROLLER = "y"; - POWER_RESET = "y"; - POWER_RESET_GPIO = "y"; - POWER_SUPPLY = "y"; - LED_TRIGGER_PHY = "y"; + # MTD_UBI_BEB_LIMIT = "20"; + # MTD_UBI_WL_THRESHOLD = "4096"; - PCI_DISABLE_COMMON_QUIRKS = "y"; - PCI_DOMAINS = "y"; - PCI_DOMAINS_GENERIC = "y"; - PCI_DRIVERS_GENERIC = "y"; - PCS_MTK_LYNXI = "y"; + MTD = "y"; + MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_dev + MTD_RAW_NAND = "y"; + MTD_NAND_MT7621 = "y"; + MTD_NAND_MTK_BMT = "y"; # Bad-block Management Table + MTD_NAND_ECC_SW_HAMMING= "y"; + MTD_SPI_NAND= "y"; + MTD_OF_PARTS = "y"; + MTD_NAND_CORE= "y"; + MTD_SPLIT_FIRMWARE= "y"; + MTD_SPLIT_FIT_FW= "y"; - SOC_BUS = "y"; + PINCTRL = "y"; + PINCTRL_MT7621 = "y"; - NET = "y"; - ETHERNET = "y"; - WLAN = "y"; + I2C = "y"; + I2C_MT7621 = "y"; - PHYLIB = "y"; - AT803X_PHY = "y"; - FIXED_PHY = "y"; - GENERIC_PHY = "y"; - NET_DSA = "y"; - NET_DSA_MT7530 = "y"; - NET_DSA_MT7530_MDIO = "y"; - NET_DSA_TAG_MTK = "y"; - NET_MEDIATEK_SOC = "y"; - NET_SWITCHDEV = "y"; - NET_VENDOR_MEDIATEK = "y"; + SPI = "y"; + MTD_SPI_NOR = "y"; + SPI_MT7621 = "y"; + SPI_MASTER = "y"; + SPI_MEM = "y"; - SWPHY = "y"; + REGULATOR = "y"; + REGULATOR_FIXED_VOLTAGE = "y"; + RESET_CONTROLLER = "y"; + POWER_RESET = "y"; + POWER_RESET_GPIO = "y"; + POWER_SUPPLY = "y"; + LED_TRIGGER_PHY = "y"; - GPIOLIB = "y"; - GPIO_MT7621 = "y"; - OF_GPIO = "y"; + PCI_DISABLE_COMMON_QUIRKS = "y"; + PCI_DOMAINS = "y"; + PCI_DOMAINS_GENERIC = "y"; + PCI_DRIVERS_GENERIC = "y"; + PCS_MTK_LYNXI = "y"; - EARLY_PRINTK = "y"; + SOC_BUS = "y"; - NEW_LEDS = "y"; - LEDS_TRIGGERS = "y"; - LEDS_CLASS = "y"; # required by rt2x00lib - LEDS_CLASS_MULTICOLOR = "y"; - LEDS_BRIGHTNESS_HW_CHANGED = "y"; + NET = "y"; + ETHERNET = "y"; + WLAN = "y"; - PRINTK_TIME = "y"; - } // lib.optionalAttrs (config.system.service ? vlan) { - SWCONFIG = "y"; - } // lib.optionalAttrs (config.system.service ? watchdog) { - RALINK_WDT = "y"; # watchdog - MT7621_WDT = "y"; # or it might be this one + PHYLIB = "y"; + AT803X_PHY = "y"; + FIXED_PHY = "y"; + GENERIC_PHY = "y"; + NET_DSA = "y"; + NET_DSA_MT7530 = "y"; + NET_DSA_MT7530_MDIO = "y"; + NET_DSA_TAG_MTK = "y"; + NET_MEDIATEK_SOC = "y"; + NET_SWITCHDEV = "y"; + NET_VENDOR_MEDIATEK = "y"; + + SWPHY = "y"; + + GPIOLIB = "y"; + GPIO_MT7621 = "y"; + OF_GPIO = "y"; + + EARLY_PRINTK = "y"; + + NEW_LEDS = "y"; + LEDS_TRIGGERS = "y"; + LEDS_CLASS = "y"; # required by rt2x00lib + LEDS_CLASS_MULTICOLOR = "y"; + LEDS_BRIGHTNESS_HW_CHANGED = "y"; + + PRINTK_TIME = "y"; + } // lib.optionalAttrs (config.system.service ? vlan) { + SWCONFIG = "y"; + } // lib.optionalAttrs (config.system.service ? watchdog) { + RALINK_WDT = "y"; # watchdog + MT7621_WDT = "y"; # or it might be this one + }; }; }; }; diff --git a/modules/network/default.nix b/modules/network/default.nix index 73650e4..ec5695d 100644 --- a/modules/network/default.nix +++ b/modules/network/default.nix @@ -74,6 +74,13 @@ in { device will be renamed to the name provided. ''; }; + mac = mkOption { + type = types.nullOr types.str; + default = null; + description = '' + MAC address of the interface. + ''; + }; devpath = mkOption { type = types.nullOr types.str; default = null; diff --git a/modules/network/link.nix b/modules/network/link.nix index 819d2ec..99d3061 100644 --- a/modules/network/link.nix +++ b/modules/network/link.nix @@ -7,6 +7,7 @@ { ifname , devpath ? null +, mac ? null , mtu} : # if devpath is supplied, we rename the interface at that # path to have the specified name. @@ -24,7 +25,7 @@ in oneshot { inherit name; up = '' ${rename} - ${liminix.networking.ifup name ifname} + ${liminix.networking.ifup name ifname mac} ''; down = "ip link set down dev ${ifname}"; } diff --git a/modules/outputs/initramfs.nix b/modules/outputs/initramfs.nix index 6d5d473..d7ad491 100644 --- a/modules/outputs/initramfs.nix +++ b/modules/outputs/initramfs.nix @@ -75,7 +75,7 @@ in mv out $out ''; systemConfiguration = - pkgs.systemconfig config.filesystem.contents; + pkgs.systemconfig config.filesystem.contents config.hostname; }; }; } diff --git a/modules/vlan/service.nix b/modules/vlan/service.nix index 3fa4ea2..1b0ddf0 100644 --- a/modules/vlan/service.nix +++ b/modules/vlan/service.nix @@ -11,7 +11,7 @@ in oneshot rec { up = '' ip link add link $(output ${primary} ifname) name ${ifname} type vlan id ${vid} ${optionalString untagged.egress "bridge vlan add dev ${ifname} vid ${toString untagged.vid} pvid untagged master"} - ${liminix.networking.ifup name ifname} + ${liminix.networking.ifup name ifname null} (in_outputs ${name} echo ${ifname} > ifname ) diff --git a/pkgs/levitate/default.nix b/pkgs/levitate/default.nix index 5a2e9c5..17c02f1 100644 --- a/pkgs/levitate/default.nix +++ b/pkgs/levitate/default.nix @@ -74,7 +74,7 @@ let ../../modules/s6 ]; }; - in systemconfig eval.config.filesystem.contents; + in systemconfig eval.config.filesystem.contents eval.config.hostname; in writeScriptBin "levitate" '' #!/bin/sh destdir=${newRoot} diff --git a/pkgs/liminix-tools/networking/default.nix b/pkgs/liminix-tools/networking/default.nix index b51b367..3d6066c 100644 --- a/pkgs/liminix-tools/networking/default.nix +++ b/pkgs/liminix-tools/networking/default.nix @@ -3,9 +3,13 @@ , serviceFns }: { - ifup = name : ifname : '' + ifup = name : ifname : mac: '' . ${serviceFns} ${ifwait}/bin/ifwait -v ${ifname} present + ${if (mac == null) then "" else '' + ip link set down dev ${ifname} + ip link set dev ${ifname} address ${mac} + ''} ip link set up dev ${ifname} (in_outputs ${name} echo ${ifname} > ifname diff --git a/pkgs/systemconfig/default.nix b/pkgs/systemconfig/default.nix index f6a6f9d..4766fea 100644 --- a/pkgs/systemconfig/default.nix +++ b/pkgs/systemconfig/default.nix @@ -62,10 +62,10 @@ let ${(builtins.concatStringsSep "\n" (visit "." attrset))} } ''; -in attrset: +in attrset: hostname: let makedevs = activateScript attrset; in stdenv.mkDerivation { - name="make-stuff"; + name="${hostname}-system-configuration"; src = ./.; CFLAGS = "-Os";