commit e9ab8d71837c6b16295578dbcbeb7375ea31fb69
parent 3dc58de0eb343d058c082388069bc5659a610216
Author: Raito Bezarius <masterancpp@gmail.com>
Date: Mon, 4 Dec 2023 14:08:13 +0100
modules/outputs/ubivolume: introduce ubinization
It creates an UBI image based on an UBI volume configuration.
For now, it creates only an empty rootfs.
Diffstat:
2 files changed, 93 insertions(+), 0 deletions(-)
diff --git a/modules/all-modules.nix b/modules/all-modules.nix
@@ -31,6 +31,8 @@
./ssh
./outputs/tftpboot.nix
./outputs/ubifs.nix
+ ./ubifs.nix
+ ./ubinize.nix
./users.nix
./vlan
./watchdog
diff --git a/modules/outputs/ubivolume.nix b/modules/outputs/ubivolume.nix
@@ -0,0 +1,91 @@
+{
+ config
+, pkgs
+, lib
+, ...
+}:
+let
+ inherit (pkgs) liminix;
+ inherit (lib) mkIf mkOption types concatStringsSep optionalString;
+in
+ {
+ imports = [
+ ./initramfs.nix
+ ./ubifs.nix
+ ];
+
+ options.hardware.ubi = {
+ minIOSize = mkOption { type = types.str; };
+ eraseBlockSize = mkOption { type = types.str; }; # LEB
+ maxLEBcount = mkOption { type = types.str; }; # LEB
+ };
+
+ config = mkIf (config.rootfsType == "ubifs") {
+ kernel.config = {
+ MTD_UBI="y";
+
+ UBIFS_FS = "y";
+ UBIFS_FS_SECURITY = "n";
+ };
+ boot.initramfs.enable = true;
+
+ system.outputs.rootfs =
+ let
+ inherit (pkgs.pkgsBuildBuild) runCommand;
+ ubiVolume = ({ name, volumeId, image, flags ? [] }:
+ ''
+ [${name}]
+ mode=ubi
+ vol_id=${toString volumeId}
+ vol_type=dynamic
+ vol_name=${name}
+ vol_alignment=1
+ ${optionalString (image != null) ''
+ image=${image}
+ ''}
+ ${optionalString (image == null) ''
+ vol_size=1MiB
+ ''}
+ ${optionalString (flags != []) ''
+ vol_flags=${concatStringsSep "," flags}
+ ''}
+ '');
+
+ ubiImage = (volumes:
+ let
+ ubinizeConfig = pkgs.writeText "ubinize.conf" (concatStringsSep "\n" volumes);
+ inherit (pkgs.pkgsBuildBuild) mtdutils;
+ in
+ runCommand "ubinize" {
+ depsBuildBuild = [ mtdutils ];
+ # block size := 128kb
+ # page size := 2048
+ # ubninize opts := -E 5
+ } ''
+ ubinize -Q "$SOURCE_DATE_EPOCH" -o $out \
+ -p ${config.hardware.ubi.physicalEraseBlockSize} -m ${config.hardware.ubi.minIOSize} \
+ -e ${config.hardware.ubi.logicalEraseBlockSize} \
+ ${ubinizeConfig}
+ '');
+
+ ubiDisk = ({ initramfs }:
+ let
+ initramfsUbi = ubiVolume {
+ name = "rootfs";
+ volumeId = 0;
+ image = initramfs;
+ flags = [ "autoresize" ];
+ };
+ in
+ ubiImage [
+ initramfsUbi
+ ]);
+
+ disk = ubiDisk {
+ initramfs = config.system.outputs.rootubifs; # liminix.builders.squashfs config.filesystem.contents; # # assert this is a proper FIT.
+ };
+
+ in
+ disk;
+ };
+}