From 629914f65e7f9e8f0251b401a0966340557da91e Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 16 Oct 2023 19:55:17 +0100 Subject: [PATCH] initial support for ubifs --- devices/belkin-rt3200/default.nix | 15 ++++---- modules/base.nix | 2 +- modules/standard.nix | 1 + modules/ubifs.nix | 59 +++++++++++++++++++++++++++++++ pkgs/systemconfig/default.nix | 2 +- 5 files changed, 71 insertions(+), 8 deletions(-) create mode 100644 modules/ubifs.nix diff --git a/devices/belkin-rt3200/default.nix b/devices/belkin-rt3200/default.nix index 7dd0f17..248464f 100644 --- a/devices/belkin-rt3200/default.nix +++ b/devices/belkin-rt3200/default.nix @@ -102,10 +102,7 @@ MTD_SPI_NOR= "y"; MTD_SPLIT_FIRMWARE= "y"; MTD_SPLIT_FIT_FW= "y"; - MTD_UBI="y"; - MTD_UBI_BEB_LIMIT="20"; - MTD_UBI_BLOCK="y"; - MTD_UBI_WL_THRESHOLD="4096"; + MMC = "y"; MMC_BLOCK = "y"; @@ -158,6 +155,12 @@ klibBuild = config.system.outputs.kernel.modulesupport; }; in { + ubi = { + minIOSize = "2048"; + eraseBlockSize = "126976"; + maxLEBcount = "1024"; # guessing + }; + defaultOutput = "flashimage"; # the kernel expects this to be on a 2MB boundary. U-Boot # (I don't know why) has a default of 0x41080000, which isn't. @@ -166,7 +169,7 @@ # RAM unless the kernel is able to reuse it later. Oh well loadAddress = "0x42000000"; entryPoint = "0x42000000"; - rootDevice = "/dev/mtdblock0"; + rootDevice = "ubi0:liminix"; dts = { src = "${openwrt.src}/target/linux/mediatek/dts/mt7622-linksys-e8450-ubi.dts"; includes = [ @@ -175,7 +178,7 @@ ]; }; - flash.eraseBlockSize = "65536"; # c.f. pkgs/mips-vm/mips-vm.sh + flash.eraseBlockSize = "65536"; # this is probably wrong networkInterfaces = let inherit (config.system.service.network) link; diff --git a/modules/base.nix b/modules/base.nix index fb059d2..67d6ed7 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -39,7 +39,7 @@ in { }; rootfsType = mkOption { default = "squashfs"; - type = types.enum ["squashfs" "jffs2"]; + type = types.enum ["squashfs" "jffs2" "ubifs"]; }; boot = { commandLine = mkOption { diff --git a/modules/standard.nix b/modules/standard.nix index cb9b8ee..c89017a 100644 --- a/modules/standard.nix +++ b/modules/standard.nix @@ -7,5 +7,6 @@ ./kexecboot.nix ./flashimage.nix ./jffs2.nix + ./ubifs.nix ]; } diff --git a/modules/ubifs.nix b/modules/ubifs.nix new file mode 100644 index 0000000..4b8e190 --- /dev/null +++ b/modules/ubifs.nix @@ -0,0 +1,59 @@ +{ + config +, pkgs +, lib +, ... +}: +let + inherit (lib) mkIf mkOption types; +in +{ + imports = [ + ./initramfs.nix + ]; + options.system.outputs = { + systemConfiguration = mkOption { + type = types.package; + description = '' + pkgs.systemconfig for the configured filesystem, + contains 'activate' and 'init' commands + ''; + internal = true; + }; + }; + 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 = rec { + systemConfiguration = + pkgs.systemconfig config.filesystem.contents; + rootfs = + let + inherit (pkgs.pkgsBuildBuild) runCommand mtdutils; + cfg = config.hardware.ubi; + in runCommand "mkfs.ubifs" { + depsBuildBuild = [ mtdutils ]; + } '' + mkdir -p $TMPDIR/empty/nix/store/ $TMPDIR/empty/secrets + cp ${systemConfiguration}/bin/activate $TMPDIR/empty/activate + ln -s ${pkgs.s6-init-bin}/bin/init $TMPDIR/empty/init + mkdir -p $TMPDIR/empty/nix/store + for path in $(cat ${systemConfiguration}/etc/nix-store-paths) ; do + (cd $TMPDIR/empty && cp -a $path .$path) + done + mkfs.ubifs -x favor_lzo -c ${cfg.maxLEBcount} -m ${cfg.minIOSize} -e ${cfg.eraseBlockSize} -y -r $TMPDIR/empty --output $out --squash-uids -o $out + ''; + }; + }; +} diff --git a/pkgs/systemconfig/default.nix b/pkgs/systemconfig/default.nix index d229fdf..a18800e 100644 --- a/pkgs/systemconfig/default.nix +++ b/pkgs/systemconfig/default.nix @@ -68,7 +68,7 @@ in attrset: src = ./.; CFLAGS = "-Os"; - LDFLAGS = "-static"; + LDFLAGS = "-static -Xlinker -static"; postConfigure = '' cp ${makedevs} makedevs.c