From 63007859c26c6c1d7210cab5b04f88b5e2d62243 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Sat, 17 Feb 2024 02:21:50 +0100 Subject: [PATCH] modules/outputs/zyxel-nwa-fit: init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Zyxel "firmware" format is just… a FIT with some metadata on the models. This FIT is like this: -------------------------- uImage FIT header -------------------------- Linux kernel -------------------------- FDT DTB -------------------------- Padding so that this makes 8192kb [1] -------------------------- UBI volume as a root filesystem -------------------------- We just reproduce this in a very brutal and naive way. In the future, this seems worth to generalize and modularize this idea so that zyxel-nwa-fit is just an instance of a more general output. [1]: https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob;f=target/linux/ramips/image/mt7621.mk;h=ab1b829ba0086cb9fc9ca8cbbf3cbc14735034d6;hb=refs/heads/main#l3097 Signed-off-by: Raito Bezarius --- modules/outputs/zyxel-nwa-fit.nix | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 modules/outputs/zyxel-nwa-fit.nix diff --git a/modules/outputs/zyxel-nwa-fit.nix b/modules/outputs/zyxel-nwa-fit.nix new file mode 100644 index 0000000..d6f894e --- /dev/null +++ b/modules/outputs/zyxel-nwa-fit.nix @@ -0,0 +1,71 @@ +{ + config +, pkgs +, lib +, ... +}: +let + inherit (lib) mkIf mkEnableOption mkOption types concatStringsSep; + models = "6b e1 6f e1 ff ff ff ff ff ff"; +in { + options.system.outputs = { + zyxel-nwa-fit = mkOption { + type = types.package; + description = '' +zyxel-nwa-fit +************* + +This output provides a FIT image for Zyxel NWA series +containing a kernel image and an UBIFS rootfs. + +It can usually be used as a factory image to install Liminix +on a system with pre-existing firmware and OS. + ''; + }; + }; + + imports = [ + ./ubivolume.nix + ]; + + config = mkIf (config.rootfsType == "ubifs") { + + system.outputs.zyxel-nwa-fit = + let + o = config.system.outputs; + # 8129kb padding. + paddedKernel = pkgs.runCommand "padded-kernel" {} '' + cp --no-preserve=mode ${o.uimage} $out + dd if=/dev/zero of=$out bs=1 count=1 seek=8388607 + ''; + firmwareImage = pkgs.runCommand "firmware-image" {} '' + cat ${paddedKernel} ${o.rootfs} > $out + ''; + dts = pkgs.writeText "image.its" '' + /dts-v1/; + + / { + description = "Zyxel FIT (Flattened Image Tree)"; + compat-models = [${models}]; + #address-cells = <1>; + + images { + firmware { + data = /incbin/("${firmwareImage}"); + type = "firmware"; + compression = "none"; + hash@1 { + algo = "sha1"; + }; + }; + }; + }; + ''; + in + pkgs.runCommand "zyxel-nwa-fit" { + nativeBuildInputs = [ pkgs.pkgsBuildBuild.ubootTools pkgs.pkgsBuildBuild.dtc ]; + } '' + mkimage -f ${dts} $out + ''; + }; +}