63007859c2
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 <masterancpp@gmail.com>
71 lines
1.7 KiB
Nix
71 lines
1.7 KiB
Nix
{
|
|
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
|
|
'';
|
|
};
|
|
}
|