Compare commits

..

No commits in common. "mdebray/mac-personalisation" and "main" have entirely different histories.

8 changed files with 201 additions and 231 deletions

View file

@ -135,250 +135,232 @@ rec {
../../modules/zyxel-dual-image ../../modules/zyxel-dual-image
]; ];
options = { nixpkgs.hostPlatform = system.crossSystem;
hardware.wlanMacAddresses = {
wlan0 = lib.mkOption { filesystem = dir {
type = lib.types.str; lib = dir {
description = "Mac address of wlan0 device"; firmware = dir {
}; mediatek = dir {
wlan1 = lib.mkOption { "mt7915_wa.bin" = symlink wlan_firmware;
type = lib.types.str; "mt7915_wm.bin" = symlink wlan_firmware';
description = "Mac address of wlan1 device"; "mt7915_rom_patch.bin" = symlink wlan_firmware'';
};
}; };
}; };
}; };
config = { 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";
};
nixpkgs.hostPlatform = system.crossSystem; flash.eraseBlockSize = 64 * 1024;
filesystem = dir { # This is a FIT containing a kernel padded and
lib = dir { # a UBI volume rootfs.
firmware = dir { defaultOutput = "zyxel-nwa-fit";
mediatek = dir {
"mt7915_wa.bin" = symlink wlan_firmware; loadAddress = lim.parseInt "0x80001000";
"mt7915_wm.bin" = symlink wlan_firmware'; entryPoint = lim.parseInt "0x80001000";
"mt7915_rom_patch.bin" = symlink wlan_firmware''; # 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 ];
}; };
}; };
};
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";
}; };
};
rootfsType = "ubifs"; # Dual image management service in userspace.
hardware = { services.zyxel-dual-image = config.boot.zyxel-dual-image.build {
# Taken from OpenWRT ensureActiveImage = "primary";
# root@OpenWrt:/# ubinfo /dev/ubi0 # TODO: use mtd names rather…
# ubi0 # primary and secondary are always /dev/mtd3 by virtue of the
# Volumes count: 2 # dtb being not too wrong…
# Logical eraseblock size: 126976 bytes, 124.0 KiB # TODO: remove this hack.
# Total amount of logical eraseblocks: 256 (32505856 bytes, 31.0 MiB) primaryMtdPartition = "/dev/mtd3";
# Amount of available logical eraseblocks: 0 (0 bytes) secondaryMtdPartition = "/dev/mtd3";
# Maximum count of volumes 128 bootConfigurationMtdPartition = "/dev/mtd12";
# 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";
};
flash.eraseBlockSize = 64 * 1024; # 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
# This is a FIT containing a kernel padded and kernel = {
# a UBI volume rootfs. src = pkgs.fetchurl {
defaultOutput = "zyxel-nwa-fit"; name = "linux.tar.gz";
url = "https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.15.137.tar.gz";
loadAddress = lim.parseInt "0x80001000"; hash = "sha256-PkdzUKZ0IpBiWe/RS70J76JKnBFzRblWcKlaIFNxnHQ=";
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}
boot = { '';
# Critical because NWA50AX will extend your cmdline with the image number booted. config = {
# and some bootloader version.
# You don't want to find yourself being overridden.
commandLineDtbNode = "bootargs-override";
imageFormat = "fit"; RALINK = "y";
tftp = { PCI = "y";
# 20MB is pretty good on this device as we have plenty of RAM. PHY_MT7621_PCI = "y";
freeSpaceBytes = 20 * 1024 * 1024; PCIE_MT7621 = "y";
appendDTB = true; SOC_MT7621 = "y";
loadAddress = lim.parseInt "0x2000000"; CLK_MT7621 = "y";
}; CLOCKSOURCE_WATCHDOG = "y";
};
# Dual image management service in userspace. SERIAL_8250_CONSOLE = "y";
services.zyxel-dual-image = config.boot.zyxel-dual-image.build { SERIAL_8250 = "y";
ensureActiveImage = "primary"; SERIAL_CORE_CONSOLE = "y";
# TODO: use mtd names rather… SERIAL_OF_PLATFORM = "y";
# primary and secondary are always /dev/mtd3 by virtue of the SERIAL_8250_NR_UARTS = "3";
# dtb being not too wrong… SERIAL_8250_RUNTIME_UARTS = "3";
# TODO: remove this hack. SERIAL_MCTRL_GPIO = "y";
primaryMtdPartition = "/dev/mtd3";
secondaryMtdPartition = "/dev/mtd3";
bootConfigurationMtdPartition = "/dev/mtd12";
};
# DEVICE_VENDOR := ZyXEL CONSOLE_LOGLEVEL_DEFAULT = "8";
# KERNEL_SIZE := 8192k CONSOLE_LOGLEVEL_QUIET = "4";
# 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
kernel = { # MTD_UBI_BEB_LIMIT = "20";
src = pkgs.fetchurl { # MTD_UBI_WL_THRESHOLD = "4096";
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";
config = { 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";
RALINK = "y"; PINCTRL = "y";
PCI = "y"; PINCTRL_MT7621 = "y";
PHY_MT7621_PCI = "y";
PCIE_MT7621 = "y";
SOC_MT7621 = "y";
CLK_MT7621 = "y";
CLOCKSOURCE_WATCHDOG = "y";
SERIAL_8250_CONSOLE = "y"; I2C = "y";
SERIAL_8250 = "y"; I2C_MT7621 = "y";
SERIAL_CORE_CONSOLE = "y";
SERIAL_OF_PLATFORM = "y";
SERIAL_8250_NR_UARTS = "3";
SERIAL_8250_RUNTIME_UARTS = "3";
SERIAL_MCTRL_GPIO = "y";
CONSOLE_LOGLEVEL_DEFAULT = "8"; SPI = "y";
CONSOLE_LOGLEVEL_QUIET = "4"; MTD_SPI_NOR = "y";
SPI_MT7621 = "y";
SPI_MASTER = "y";
SPI_MEM = "y";
# MTD_UBI_BEB_LIMIT = "20"; REGULATOR = "y";
# MTD_UBI_WL_THRESHOLD = "4096"; REGULATOR_FIXED_VOLTAGE = "y";
RESET_CONTROLLER = "y";
POWER_RESET = "y";
POWER_RESET_GPIO = "y";
POWER_SUPPLY = "y";
LED_TRIGGER_PHY = "y";
MTD = "y"; PCI_DISABLE_COMMON_QUIRKS = "y";
MTD_BLOCK = "y"; # fix undefined ref to register_mtd_blktrans_dev PCI_DOMAINS = "y";
MTD_RAW_NAND = "y"; PCI_DOMAINS_GENERIC = "y";
MTD_NAND_MT7621 = "y"; PCI_DRIVERS_GENERIC = "y";
MTD_NAND_MTK_BMT = "y"; # Bad-block Management Table PCS_MTK_LYNXI = "y";
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";
PINCTRL = "y"; SOC_BUS = "y";
PINCTRL_MT7621 = "y";
I2C = "y"; NET = "y";
I2C_MT7621 = "y"; ETHERNET = "y";
WLAN = "y";
SPI = "y"; PHYLIB = "y";
MTD_SPI_NOR = "y"; AT803X_PHY = "y";
SPI_MT7621 = "y"; FIXED_PHY = "y";
SPI_MASTER = "y"; GENERIC_PHY = "y";
SPI_MEM = "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";
REGULATOR = "y"; SWPHY = "y";
REGULATOR_FIXED_VOLTAGE = "y";
RESET_CONTROLLER = "y";
POWER_RESET = "y";
POWER_RESET_GPIO = "y";
POWER_SUPPLY = "y";
LED_TRIGGER_PHY = "y";
PCI_DISABLE_COMMON_QUIRKS = "y"; GPIOLIB = "y";
PCI_DOMAINS = "y"; GPIO_MT7621 = "y";
PCI_DOMAINS_GENERIC = "y"; OF_GPIO = "y";
PCI_DRIVERS_GENERIC = "y";
PCS_MTK_LYNXI = "y";
SOC_BUS = "y"; EARLY_PRINTK = "y";
NET = "y"; NEW_LEDS = "y";
ETHERNET = "y"; LEDS_TRIGGERS = "y";
WLAN = "y"; LEDS_CLASS = "y"; # required by rt2x00lib
LEDS_CLASS_MULTICOLOR = "y";
LEDS_BRIGHTNESS_HW_CHANGED = "y";
PHYLIB = "y"; PRINTK_TIME = "y";
AT803X_PHY = "y"; } // lib.optionalAttrs (config.system.service ? vlan) {
FIXED_PHY = "y"; SWCONFIG = "y";
GENERIC_PHY = "y"; } // lib.optionalAttrs (config.system.service ? watchdog) {
NET_DSA = "y"; RALINK_WDT = "y"; # watchdog
NET_DSA_MT7530 = "y"; MT7621_WDT = "y"; # or it might be this one
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
};
}; };
}; };
}; };

View file

@ -74,13 +74,6 @@ in {
device will be renamed to the name provided. 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 { devpath = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;

View file

@ -7,7 +7,6 @@
{ {
ifname ifname
, devpath ? null , devpath ? null
, mac ? null
, mtu} : , mtu} :
# if devpath is supplied, we rename the interface at that # if devpath is supplied, we rename the interface at that
# path to have the specified name. # path to have the specified name.
@ -25,7 +24,7 @@ in oneshot {
inherit name; inherit name;
up = '' up = ''
${rename} ${rename}
${liminix.networking.ifup name ifname mac} ${liminix.networking.ifup name ifname}
''; '';
down = "ip link set down dev ${ifname}"; down = "ip link set down dev ${ifname}";
} }

View file

@ -75,7 +75,7 @@ in
mv out $out mv out $out
''; '';
systemConfiguration = systemConfiguration =
pkgs.systemconfig config.filesystem.contents config.hostname; pkgs.systemconfig config.filesystem.contents;
}; };
}; };
} }

View file

@ -11,7 +11,7 @@ in oneshot rec {
up = '' up = ''
ip link add link $(output ${primary} ifname) name ${ifname} type vlan id ${vid} 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"} ${optionalString untagged.egress "bridge vlan add dev ${ifname} vid ${toString untagged.vid} pvid untagged master"}
${liminix.networking.ifup name ifname null} ${liminix.networking.ifup name ifname}
(in_outputs ${name} (in_outputs ${name}
echo ${ifname} > ifname echo ${ifname} > ifname
) )

View file

@ -74,7 +74,7 @@ let
../../modules/s6 ../../modules/s6
]; ];
}; };
in systemconfig eval.config.filesystem.contents eval.config.hostname; in systemconfig eval.config.filesystem.contents;
in writeScriptBin "levitate" '' in writeScriptBin "levitate" ''
#!/bin/sh #!/bin/sh
destdir=${newRoot} destdir=${newRoot}

View file

@ -3,13 +3,9 @@
, serviceFns , serviceFns
}: }:
{ {
ifup = name : ifname : mac: '' ifup = name : ifname : ''
. ${serviceFns} . ${serviceFns}
${ifwait}/bin/ifwait -v ${ifname} present ${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} ip link set up dev ${ifname}
(in_outputs ${name} (in_outputs ${name}
echo ${ifname} > ifname echo ${ifname} > ifname

View file

@ -62,10 +62,10 @@ let
${(builtins.concatStringsSep "\n" (visit "." attrset))} ${(builtins.concatStringsSep "\n" (visit "." attrset))}
} }
''; '';
in attrset: hostname: in attrset:
let makedevs = activateScript attrset; let makedevs = activateScript attrset;
in stdenv.mkDerivation { in stdenv.mkDerivation {
name="${hostname}-system-configuration"; name="make-stuff";
src = ./.; src = ./.;
CFLAGS = "-Os"; CFLAGS = "-Os";