diff --git a/modules/outputs/jffs2.nix b/modules/outputs/jffs2.nix index 02c7c10..0a69a1f 100644 --- a/modules/outputs/jffs2.nix +++ b/modules/outputs/jffs2.nix @@ -5,7 +5,8 @@ , ... }: let - inherit (lib) mkIf mkOption types; + inherit (pkgs) liminix; + inherit (lib) mkIf; o = config.system.outputs; in { @@ -24,17 +25,10 @@ in }; boot.initramfs.enable = true; system.outputs = { - rootfs = - let - inherit (pkgs.pkgsBuildBuild) runCommand mtdutils; - endian = if pkgs.stdenv.isBigEndian - then "--big-endian" else "--little-endian"; - in runCommand "make-jffs2" { - depsBuildBuild = [ mtdutils ]; - } '' - tree=${o.bootablerootdir} - (cd $tree && mkfs.jffs2 --compression-mode=size ${endian} -e ${toString config.hardware.flash.eraseBlockSize} --enable-compressor=lzo --pad --root . --output $out --squash --faketime ) - ''; + rootfs = liminix.builders.jffs2 { + bootableRootDirectory = o.bootablerootdir; + inherit (config.hardware.flash) eraseBlockSize; + }; }; }; } diff --git a/modules/outputs/tftpboot.nix b/modules/outputs/tftpboot.nix index 6d5bad9..ca51d10 100644 --- a/modules/outputs/tftpboot.nix +++ b/modules/outputs/tftpboot.nix @@ -5,10 +5,18 @@ , ... }: let - inherit (lib) mkOption types concatStringsSep; + inherit (lib) mkOption mkIf types concatStringsSep; + inherit (pkgs) liminix; cfg = config.boot.tftp; hw = config.hardware; arch = pkgs.stdenv.hostPlatform.linuxArch; + + # UBI cannot run on the top of phram. + needsSquashfs = config.rootfsType == "ubifs"; + rootfstype = if needsSquashfs then "squashfs" else config.rootfsType; + rootfs = if needsSquashfs then + liminix.builders.squashfs config.filesystem.contents + else config.system.outputs.rootfs; in { imports = [ ../ramdisk.nix ]; options.boot.tftp = { @@ -74,6 +82,11 @@ in { config = { boot.ramdisk.enable = true; + kernel.config = mkIf needsSquashfs { + SQUASHFS = "y"; + SQUASHFS_XZ = "y"; + }; + system.outputs = rec { tftpboot-fit = let @@ -128,7 +141,7 @@ in { hex() { printf "0x%x" $1; } rootfsStart=${toString cfg.loadAddress} - rootfsSize=$(binsize64k ${o.rootfs} ) + rootfsSize=$(binsize64k ${rootfs} ) rootfsSize=$(($rootfsSize + ${toString cfg.freeSpaceBytes} )) ln -s ${o.manifest} manifest @@ -142,13 +155,13 @@ in { dtbStart=$(($rootfsStart + $rootfsSize)) ${if cfg.compressRoot then '' - lzma -z9cv ${o.rootfs} > rootfs.lz + lzma -z9cv ${rootfs} > rootfs.lz rootfsLzStart=$dtbStart rootfsLzSize=$(binsize rootfs.lz) dtbStart=$(($dtbStart + $rootfsLzSize)) '' else '' - ln -s ${o.rootfs} rootfs + ln -s ${rootfs} rootfs '' } @@ -165,7 +178,7 @@ in { fdtput -p -t s dtb /reserved-memory/$node compatible phram fdtput -p -t lx dtb /reserved-memory/$node reg $ac_prefix $(hex $rootfsStart) $sz_prefix $(hex $rootfsSize) - cmd="liminix ${cmdline} mtdparts=phram0:''${rootfsSize}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsSize},${toString config.hardware.flash.eraseBlockSize} root=/dev/mtdblock0"; + cmd="liminix ${cmdline} mtdparts=phram0:''${rootfsSize}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsSize},${toString config.hardware.flash.eraseBlockSize} rootfstype=${rootfstype} root=/dev/mtdblock0"; fdtput -t s dtb /chosen ${config.boot.commandLineDtbNode} "$cmd" dtbSize=$(binsize ./dtb ) diff --git a/modules/outputs/ubivolume.nix b/modules/outputs/ubivolume.nix index 1b9decc..45aa889 100644 --- a/modules/outputs/ubivolume.nix +++ b/modules/outputs/ubivolume.nix @@ -29,13 +29,6 @@ in }; boot.initramfs.enable = true; - # In TFTP, the device named "rootfs" is the UBI device. - # We tell the kernel to load it. - # This avoids interference from the other UBI volumes. - boot.tftp.commandLine = [ - "ubi.mtd=rootfs" - ]; - system.outputs.rootfs = let inherit (pkgs.pkgsBuildBuild) runCommand; diff --git a/pkgs/default.nix b/pkgs/default.nix index b63ab3a..7bb2470 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -13,6 +13,7 @@ in { liminix = { builders = { squashfs = callPackage ./liminix-tools/builders/squashfs.nix {}; + jffs2 = callPackage ./liminix-tools/builders/jffs2.nix {}; dtb = callPackage ./kernel/dtb.nix {}; uimage = callPackage ./kernel/uimage.nix {}; kernel = callPackage ./kernel {}; diff --git a/pkgs/liminix-tools/builders/jffs2.nix b/pkgs/liminix-tools/builders/jffs2.nix new file mode 100644 index 0000000..62378b4 --- /dev/null +++ b/pkgs/liminix-tools/builders/jffs2.nix @@ -0,0 +1,17 @@ +{ + stdenv +, busybox +, buildPackages +, callPackage +, pseudofile +, runCommand +, writeText +} : { eraseBlockSize, bootableRootDirectory }: +let + endian = if stdenv.isBigEndian then "--big-endian" else "--little-endian"; +in runCommand "frob-jffs2" { + depsBuildBuild = [ buildPackages.mtdutils ]; + } '' + tree=${bootableRootDirectory} + (cd $tree && mkfs.jffs2 --compression-mode=size ${endian} -e ${toString eraseBlockSize} --enable-compressor=lzo --pad --root . --output $out --squash --faketime) + ''