fix(zyxel/nwa50ax): ubi cannot run on phram

Discovered the hard way.

Signed-off-by: Raito Bezarius <masterancpp@gmail.com>
This commit is contained in:
Raito Bezarius 2024-08-26 18:55:58 +02:00 committed by Ryan Lahfa
parent 85bfe94429
commit c1e61d6af5
5 changed files with 42 additions and 24 deletions

View file

@ -5,7 +5,8 @@
, ... , ...
}: }:
let let
inherit (lib) mkIf mkOption types; inherit (pkgs) liminix;
inherit (lib) mkIf;
o = config.system.outputs; o = config.system.outputs;
in in
{ {
@ -24,17 +25,10 @@ in
}; };
boot.initramfs.enable = true; boot.initramfs.enable = true;
system.outputs = { system.outputs = {
rootfs = rootfs = liminix.builders.jffs2 {
let bootableRootDirectory = o.bootablerootdir;
inherit (pkgs.pkgsBuildBuild) runCommand mtdutils; inherit (config.hardware.flash) eraseBlockSize;
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 )
'';
}; };
}; };
} }

View file

@ -5,10 +5,18 @@
, ... , ...
}: }:
let let
inherit (lib) mkOption types concatStringsSep; inherit (lib) mkOption mkIf types concatStringsSep;
inherit (pkgs) liminix;
cfg = config.boot.tftp; cfg = config.boot.tftp;
hw = config.hardware; hw = config.hardware;
arch = pkgs.stdenv.hostPlatform.linuxArch; 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 { in {
imports = [ ../ramdisk.nix ]; imports = [ ../ramdisk.nix ];
options.boot.tftp = { options.boot.tftp = {
@ -74,6 +82,11 @@ in {
config = { config = {
boot.ramdisk.enable = true; boot.ramdisk.enable = true;
kernel.config = mkIf needsSquashfs {
SQUASHFS = "y";
SQUASHFS_XZ = "y";
};
system.outputs = rec { system.outputs = rec {
tftpboot-fit = tftpboot-fit =
let let
@ -128,7 +141,7 @@ in {
hex() { printf "0x%x" $1; } hex() { printf "0x%x" $1; }
rootfsStart=${toString cfg.loadAddress} rootfsStart=${toString cfg.loadAddress}
rootfsSize=$(binsize64k ${o.rootfs} ) rootfsSize=$(binsize64k ${rootfs} )
rootfsSize=$(($rootfsSize + ${toString cfg.freeSpaceBytes} )) rootfsSize=$(($rootfsSize + ${toString cfg.freeSpaceBytes} ))
ln -s ${o.manifest} manifest ln -s ${o.manifest} manifest
@ -142,13 +155,13 @@ in {
dtbStart=$(($rootfsStart + $rootfsSize)) dtbStart=$(($rootfsStart + $rootfsSize))
${if cfg.compressRoot ${if cfg.compressRoot
then '' then ''
lzma -z9cv ${o.rootfs} > rootfs.lz lzma -z9cv ${rootfs} > rootfs.lz
rootfsLzStart=$dtbStart rootfsLzStart=$dtbStart
rootfsLzSize=$(binsize rootfs.lz) rootfsLzSize=$(binsize rootfs.lz)
dtbStart=$(($dtbStart + $rootfsLzSize)) dtbStart=$(($dtbStart + $rootfsLzSize))
'' ''
else '' 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 s dtb /reserved-memory/$node compatible phram
fdtput -p -t lx dtb /reserved-memory/$node reg $ac_prefix $(hex $rootfsStart) $sz_prefix $(hex $rootfsSize) 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" fdtput -t s dtb /chosen ${config.boot.commandLineDtbNode} "$cmd"
dtbSize=$(binsize ./dtb ) dtbSize=$(binsize ./dtb )

View file

@ -29,13 +29,6 @@ in
}; };
boot.initramfs.enable = true; 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 = system.outputs.rootfs =
let let
inherit (pkgs.pkgsBuildBuild) runCommand; inherit (pkgs.pkgsBuildBuild) runCommand;

View file

@ -13,6 +13,7 @@ in {
liminix = { liminix = {
builders = { builders = {
squashfs = callPackage ./liminix-tools/builders/squashfs.nix {}; squashfs = callPackage ./liminix-tools/builders/squashfs.nix {};
jffs2 = callPackage ./liminix-tools/builders/jffs2.nix {};
dtb = callPackage ./kernel/dtb.nix {}; dtb = callPackage ./kernel/dtb.nix {};
uimage = callPackage ./kernel/uimage.nix {}; uimage = callPackage ./kernel/uimage.nix {};
kernel = callPackage ./kernel {}; kernel = callPackage ./kernel {};

View file

@ -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)
''