From 59d66403434c8a3ab4701d208ab802208f7352cb Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sun, 21 Apr 2024 17:26:31 +0200 Subject: [PATCH] feat(zyxel): cleanup A/B schema Signed-off-by: Raito Bezarius --- default.nix | 4 - .../b_image/mt7621_zyxel_nwa-ax-for-ab.dtsi | 155 ------------------ devices/zyxel-nwa50ax/default.nix | 25 ++- .../mt7621_zyxel_nwa-ax-for-ab.dtsi | 2 +- .../{ => dtb}/mt7621_zyxel_nwa50ax.dtsi | 0 modules/base.nix | 9 +- modules/hardware.nix | 12 ++ modules/outputs/zyxel-nwa-fit.nix | 2 +- 8 files changed, 29 insertions(+), 180 deletions(-) delete mode 100644 devices/zyxel-nwa50ax/b_image/mt7621_zyxel_nwa-ax-for-ab.dtsi rename devices/zyxel-nwa50ax/{a_image => dtb}/mt7621_zyxel_nwa-ax-for-ab.dtsi (99%) rename devices/zyxel-nwa50ax/{ => dtb}/mt7621_zyxel_nwa50ax.dtsi (100%) diff --git a/default.nix b/default.nix index 13d4148..e95fff2 100644 --- a/default.nix +++ b/default.nix @@ -4,7 +4,6 @@ , liminix-config ? , nixpkgs ? , borderVmConf ? ./bordervm.conf.nix -, imageType ? "primary" }: let @@ -35,9 +34,6 @@ let ./modules/s6 ./modules/users.nix ./modules/outputs.nix - { - boot.imageType = imageType; - } ]; }; config = eval.config; diff --git a/devices/zyxel-nwa50ax/b_image/mt7621_zyxel_nwa-ax-for-ab.dtsi b/devices/zyxel-nwa50ax/b_image/mt7621_zyxel_nwa-ax-for-ab.dtsi deleted file mode 100644 index c35d362..0000000 --- a/devices/zyxel-nwa50ax/b_image/mt7621_zyxel_nwa-ax-for-ab.dtsi +++ /dev/null @@ -1,155 +0,0 @@ -#include "mt7621.dtsi" - -#include -#include - -/ { - aliases { - label-mac-device = &gmac0; - }; -}; - -&nand { - status = "okay"; - - mediatek,nmbm; - mediatek,bmt-max-ratio = <15>; - mediatek,bmt-max-reserved-blocks = <64>; - mediatek,bmt-remap-range = - <0x0 0x980000>, - <0x2980000 0x7800000>; - - partitions { - compatible = "fixed-partitions"; - #address-cells = <1>; - #size-cells = <1>; - - partition@0 { - label = "u-boot"; - reg = <0x0 0x80000>; - read-only; - }; - - partition@80000 { - label = "u-boot-env"; - reg = <0x80000 0x80000>; - read-only; - }; - - factory: partition@100000 { - label = "factory"; - reg = <0x100000 0x80000>; - read-only; - }; - - partition@2980000 { - label = "firmware_b"; - reg = <0x2980000 0x2800000>; - - compatible = "fixed-partitions"; - #address-cells = <1>; - #size-cells = <1>; - - partition@0 { - label = "kernel_b"; - reg = <0x0 0x800000>; - }; - - partition@400000 { - label = "ubi"; - reg = <0x800000 0x2000000>; - }; - }; - - partition@180000 { - label = "firmware_a"; - reg = <0x180000 0x2800000>; - - compatible = "fixed-partitions"; - #address-cells = <1>; - #size-cells = <1>; - - partition@0 { - label = "kernel_a"; - reg = <0x0 0x800000>; - }; - - partition@400000 { - label = "ubi_a"; - reg = <0x800000 0x2000000>; - }; - }; - - partition@5180000 { - label = "rootfs_data"; - reg = <0x5180000 0x1400000>; - }; - - partition@6580000 { - label = "logs"; - reg = <0x6580000 0xd00000>; - }; - - partition@7280000 { - label = "vendor-myzyxel"; - reg = <0x7280000 0x480000>; - read-only; - }; - - partition@7700000 { - label = "bootconfig"; - reg = <0x7700000 0x80000>; - }; - - mrd: partition@7780000 { - label = "mrd"; - reg = <0x7780000 0x80000>; - read-only; - - nvmem-layout { - compatible = "fixed-layout"; - #address-cells = <1>; - #size-cells = <1>; - - macaddr_mrd_1fff8: macaddr@1fff8 { - reg = <0x1fff8 0x6>; - }; - }; - }; - }; -}; - -&pcie { - status = "okay"; -}; - -&pcie1 { - wlan_5g: wifi@0,0 { - reg = <0x0 0 0 0 0>; - compatible = "mediatek,mt76"; - - mediatek,mtd-eeprom = <&factory 0x0>; - /* MAC-Address set in userspace */ - }; -}; - -&gmac0 { - nvmem-cells = <&macaddr_mrd_1fff8>; - nvmem-cell-names = "mac-address"; -}; - -&switch0 { - ports { - port@4 { - status = "okay"; - label = "lan"; - }; - }; -}; - -&state_default { - gpio { - groups = "uart3"; - function = "gpio"; - }; -}; diff --git a/devices/zyxel-nwa50ax/default.nix b/devices/zyxel-nwa50ax/default.nix index 23a394a..e58430f 100644 --- a/devices/zyxel-nwa50ax/default.nix +++ b/devices/zyxel-nwa50ax/default.nix @@ -91,7 +91,6 @@ - Mount the logs partition, mount / as overlayfs of firmware ? rootfs and rootfs_data for extended data. - Jitter-based entropy injection? Device can be slow to initialize its CRNG and hostapd will reject few clients at the start because of that. - Defaults for hostapd based on MT7915 capabilities? See the example for one possible list. - - Remove primary/secondary hack and put it in preinit. - Offer ways to reflash the *bootloader* itself to support direct boot via UBI and kernel upgrades via filesystem rewrite. Vendor web page: https://www.zyxel.com/fr/fr/products/wireless/ax1800-wifi-6-dual-radio-nebulaflex-access-point-nwa50ax @@ -171,6 +170,8 @@ maxLEBcount = "256"; }; + flash.eraseBlockSize = 65536; + # This is a FIT containing a kernel padded and # a UBI volume rootfs. defaultOutput = "zyxel-nwa-fit"; @@ -181,22 +182,18 @@ alignment = 2048; rootDevice = "ubi:rootfs"; + alternativeRootDevice = "ubi:rootfs"; + + # Auto-attach MTD devices: ubi_a then ubi_b. + ubi.mtds = [ "ubi_a" "ubi_b" ]; dts = { - # Actually, this is not what we want. - # This DTS is insufficient. - src = ./mt7621_zyxel_nwa50ax.dtsi; + # 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 = [ - # Here's one weird trick to make `ubi` detection - # out of the box. - # We will write ubi on /dev/firmware_a:rootfs location - # and same for /dev/firmware_b:rootfs. - # How do we distinguish both? - # We can just use the DTS to point ubi at A or B. - # This, unfortunately, means that we have "two images". - # But they are really just 1 image with 2 different DTS. - # TODO: improve this hack in preinit? - (if config.boot.imageType == "primary" then "${./a_image}" else "${./b_image}") + "${./dtb}" "${openwrt.src}/target/linux/ramips/dts" ]; }; diff --git a/devices/zyxel-nwa50ax/a_image/mt7621_zyxel_nwa-ax-for-ab.dtsi b/devices/zyxel-nwa50ax/dtb/mt7621_zyxel_nwa-ax-for-ab.dtsi similarity index 99% rename from devices/zyxel-nwa50ax/a_image/mt7621_zyxel_nwa-ax-for-ab.dtsi rename to devices/zyxel-nwa50ax/dtb/mt7621_zyxel_nwa-ax-for-ab.dtsi index 6c75b0b..519452f 100644 --- a/devices/zyxel-nwa50ax/a_image/mt7621_zyxel_nwa-ax-for-ab.dtsi +++ b/devices/zyxel-nwa50ax/dtb/mt7621_zyxel_nwa-ax-for-ab.dtsi @@ -56,7 +56,7 @@ }; partition@400000 { - label = "ubi"; + label = "ubi_a"; reg = <0x800000 0x2000000>; }; }; diff --git a/devices/zyxel-nwa50ax/mt7621_zyxel_nwa50ax.dtsi b/devices/zyxel-nwa50ax/dtb/mt7621_zyxel_nwa50ax.dtsi similarity index 100% rename from devices/zyxel-nwa50ax/mt7621_zyxel_nwa50ax.dtsi rename to devices/zyxel-nwa50ax/dtb/mt7621_zyxel_nwa50ax.dtsi diff --git a/modules/base.nix b/modules/base.nix index 4d3d8e4..3a3cade 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -67,10 +67,6 @@ in { default = "bootargs"; description = "Kernel command line's devicetree node"; }; - imageType = mkOption { - type = types.enum [ "primary" "secondary" ]; - default = "primary"; - }; imageFormat = mkOption { type = types.enum ["fit" "uimage"]; default = "uimage"; @@ -113,7 +109,10 @@ in { "root=${config.hardware.rootDevice}" "rootfstype=${config.rootfsType}" "fw_devlink=off" - ] ++ lib.optional (config.rootOptions != null) "rootflags=${config.rootOptions}"; + ] + ++ (map (mtd: "ubi.mtd=${mtd}") config.hardware.ubi.mtds) + ++ lib.optional (config.rootOptions != null) "rootflags=${config.rootOptions}" + ++ lib.optional (config.hardware.alternativeRootDevice != null) "altroot=${config.hardware.alternativeRootDevice}"; system.callService = path : parameters : let diff --git a/modules/hardware.nix b/modules/hardware.nix index 819bbb0..d31a198 100644 --- a/modules/hardware.nix +++ b/modules/hardware.nix @@ -82,6 +82,18 @@ in { type = types.str; example = "/dev/mtdblock3"; }; + alternativeRootDevice = mkOption { + description = "Full path to alternative preferred root device (the B partition of your rootfs)"; + type = types.nullOr types.str; + example = "ubi_b:rootfs"; + default = null; + }; + ubi.mtds = mkOption { + description = "List of MTD device to attach"; + type = types.listOf types.str; + example = [ "ubi_a" "ubi_b" "data" ]; + default = null; + }; networkInterfaces = mkOption { type = types.attrsOf types.anything; }; diff --git a/modules/outputs/zyxel-nwa-fit.nix b/modules/outputs/zyxel-nwa-fit.nix index a68dd39..d6f894e 100644 --- a/modules/outputs/zyxel-nwa-fit.nix +++ b/modules/outputs/zyxel-nwa-fit.nix @@ -62,7 +62,7 @@ on a system with pre-existing firmware and OS. }; ''; in - pkgs.runCommand "zyxel-nwa-fit-${config.boot.imageType}" { + pkgs.runCommand "zyxel-nwa-fit" { nativeBuildInputs = [ pkgs.pkgsBuildBuild.ubootTools pkgs.pkgsBuildBuild.dtc ]; } '' mkimage -f ${dts} $out