liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

zyxel-nwa-fit.nix (1856B)


      1 {
      2   config,
      3   pkgs,
      4   lib,
      5   ...
      6 }:
      7 let
      8   inherit (lib) mkIf mkOption types;
      9   models = "6b e1 6f e1 ff ff ff ff ff ff";
     10 in
     11 {
     12   options.system.outputs = {
     13     zyxel-nwa-fit = mkOption {
     14       type = types.package;
     15       description = ''
     16         zyxel-nwa-fit
     17         *************
     18 
     19         This output provides a FIT image for Zyxel NWA series
     20         containing a kernel image and an UBIFS rootfs.
     21 
     22         It can usually be used as a factory image to install Liminix
     23         on a system with pre-existing firmware and OS.
     24       '';
     25     };
     26   };
     27 
     28   imports = [
     29     ./ubivolume.nix
     30   ];
     31 
     32   config = mkIf (config.rootfsType == "ubifs") {
     33 
     34     system.outputs.zyxel-nwa-fit =
     35       let
     36         o = config.system.outputs;
     37         # 8129kb padding.
     38         paddedKernel = pkgs.runCommand "padded-kernel" { } ''
     39           cp --no-preserve=mode ${o.uimage} $out
     40           dd if=/dev/zero of=$out bs=1 count=1 seek=8388607
     41         '';
     42         firmwareImage = pkgs.runCommand "firmware-image" { } ''
     43           cat ${paddedKernel} ${o.ubivolume} > $out
     44         '';
     45         dts = pkgs.writeText "image.its" ''
     46           /dts-v1/;
     47 
     48           / {
     49             description = "Zyxel FIT (Flattened Image Tree)";
     50             compat-models = [${models}];
     51             #address-cells = <1>;
     52 
     53             images {
     54               firmware {
     55                 data = /incbin/("${firmwareImage}");
     56                 type = "firmware";
     57                 compression = "none";
     58                 hash@1 {
     59                   algo = "sha1";
     60                 };
     61               };
     62             };
     63           };
     64         '';
     65       in
     66       pkgs.runCommand "zyxel-nwa-fit-${config.boot.imageType}"
     67         {
     68           nativeBuildInputs = [
     69             pkgs.pkgsBuildBuild.ubootTools
     70             pkgs.pkgsBuildBuild.dtc
     71           ];
     72         }
     73         ''
     74           mkimage -f ${dts} $out
     75         '';
     76   };
     77 }