liminix

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

commit c81e7c4d35c82a1189efc7209d3ad6f172c5b4d5
parent 53fed8839ac9c838f4b125e157a096df2a4bd14b
Author: Daniel Barlow <dan@telent.net>
Date:   Sun, 10 Dec 2023 15:23:12 +0000

move all output modules to subdirectory, trash standard.nix

standard.nix isn't, is the essence here. Not all devices
support flashimage as it is currently defined - some
have diskimage, some have neither

Diffstat:
Mexamples/arhcive.nix | 7++++++-
Mexamples/demo.nix | 6+++++-
Mexamples/extneder.nix | 6+++++-
Mexamples/rotuer.nix | 6+++++-
Mmodules/all-modules.nix | 1-
Dmodules/kexecboot.nix | 63---------------------------------------------------------------
Rmodules/initramfs.nix -> modules/outputs/initramfs.nix | 0
Rmodules/jffs2.nix -> modules/outputs/jffs2.nix | 0
Amodules/outputs/kexecboot.nix | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Amodules/outputs/tftpboot.nix | 98+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rmodules/ubifs.nix -> modules/outputs/ubifs.nix | 0
Dmodules/standard.nix | 12------------
Dmodules/tftpboot.nix | 98-------------------------------------------------------------------------------
Mvanilla-configuration-hw.nix | 6+++++-
14 files changed, 187 insertions(+), 179 deletions(-)

diff --git a/examples/arhcive.nix b/examples/arhcive.nix @@ -24,13 +24,18 @@ in rec { }; imports = [ - ../modules/standard.nix ../modules/wlan.nix ../modules/network ../modules/vlan ../modules/ssh ../modules/watchdog ../modules/mount + + ../modules/outputs/tftpboot.nix + ../modules/outputs/kexecboot.nix + ../modules/outputs/flashimage.nix + ../modules/outputs/jffs2.nix + ../modules/outputs/ubifs.nix ]; hostname = "arhcive"; diff --git a/examples/demo.nix b/examples/demo.nix @@ -33,7 +33,11 @@ in rec { ../modules/ntp ../modules/ppp ../modules/ssh - ../modules/standard.nix + ../modules/outputs/tftpboot.nix + ../modules/outputs/kexecboot.nix + ../modules/outputs/flashimage.nix + ../modules/outputs/jffs2.nix + ../modules/outputs/ubifs.nix ../modules/vlan ../modules/wlan.nix ]; diff --git a/examples/extneder.nix b/examples/extneder.nix @@ -30,7 +30,11 @@ in rec { ../modules/hostapd ../modules/bridge ../modules/ssh - ../modules/standard.nix + ../modules/outputs/tftpboot.nix + ../modules/outputs/kexecboot.nix + ../modules/outputs/flashimage.nix + ../modules/outputs/jffs2.nix + ../modules/outputs/ubifs.nix ]; hostname = "extneder"; diff --git a/examples/rotuer.nix b/examples/rotuer.nix @@ -34,7 +34,6 @@ in rec { imports = [ ../modules/wlan.nix - ../modules/standard.nix ../modules/network ../modules/ppp ../modules/dnsmasq @@ -44,6 +43,11 @@ in rec { ../modules/bridge ../modules/ntp ../modules/ssh + ../modules/outputs/tftpboot.nix + ../modules/outputs/kexecboot.nix + ../modules/outputs/flashimage.nix + ../modules/outputs/jffs2.nix + ../modules/outputs/ubifs.nix ]; rootfsType = "jffs2"; hostname = "rotuer"; diff --git a/modules/all-modules.nix b/modules/all-modules.nix @@ -29,7 +29,6 @@ ./ramdisk.nix ./squashfs.nix ./ssh - ./standard.nix ./tftpboot.nix ./ubifs.nix ./users.nix diff --git a/modules/kexecboot.nix b/modules/kexecboot.nix @@ -1,63 +0,0 @@ -{ - config -, pkgs -, lib -, ... -}: -let - inherit (lib) mkOption mkForce types concatStringsSep; -in { - imports = [ ./ramdisk.nix ]; - options.system.outputs = { - kexecboot = mkOption { - type = types.package; - description = '' - Directory containing files needed for kexec booting. - Can be copied onto the target device using ssh or similar - ''; - }; - boot-sh = mkOption { - type = types.package; - description = '' - Shell script to run on the target device that invokes - kexec with appropriate options - ''; - }; - }; - config = { - boot.ramdisk.enable = true; - system.outputs = { - kexecboot = - let o = config.system.outputs; in - pkgs.runCommand "kexecboot" {} '' - mkdir $out - cd $out - ln -s ${o.rootfs} rootfs - ln -s ${o.kernel} kernel - ln -s ${o.manifest} manifest - ln -s ${o.boot-sh} boot.sh - ln -s ${pkgs.kexec-tools-static}/bin/kexec ./kexec - ln -s ${o.dtb} dtb - ''; - - boot-sh = - let - inherit (pkgs.lib.trivial) toHexString; - inherit (config.system.outputs) rootfs kernel; - cmdline = concatStringsSep " " config.boot.commandLine; - in - pkgs.buildPackages.runCommand "boot.sh.sh" { - } '' - rootfsStart=${toString (100 * 1024 * 1024)} - rootfsBytes=$(stat -L -c %s ${rootfs}) - append_cmd="mtdparts=phram0:''${rootfsBytes}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes} memmap=''${rootfsBytes}\$''${rootfsStart}"; - cat > $out <<EOF - #!/bin/sh - test -d \$1 - cd \$1 - ./kexec -f -d --map-file rootfs@$rootfsStart --dtb dtb --command-line '${cmdline} $append_cmd' kernel - EOF - ''; - }; - }; -} diff --git a/modules/initramfs.nix b/modules/outputs/initramfs.nix diff --git a/modules/jffs2.nix b/modules/outputs/jffs2.nix diff --git a/modules/outputs/kexecboot.nix b/modules/outputs/kexecboot.nix @@ -0,0 +1,63 @@ +{ + config +, pkgs +, lib +, ... +}: +let + inherit (lib) mkOption mkForce types concatStringsSep; +in { + imports = [ ../ramdisk.nix ]; + options.system.outputs = { + kexecboot = mkOption { + type = types.package; + description = '' + Directory containing files needed for kexec booting. + Can be copied onto the target device using ssh or similar + ''; + }; + boot-sh = mkOption { + type = types.package; + description = '' + Shell script to run on the target device that invokes + kexec with appropriate options + ''; + }; + }; + config = { + boot.ramdisk.enable = true; + system.outputs = { + kexecboot = + let o = config.system.outputs; in + pkgs.runCommand "kexecboot" {} '' + mkdir $out + cd $out + ln -s ${o.rootfs} rootfs + ln -s ${o.kernel} kernel + ln -s ${o.manifest} manifest + ln -s ${o.boot-sh} boot.sh + ln -s ${pkgs.kexec-tools-static}/bin/kexec ./kexec + ln -s ${o.dtb} dtb + ''; + + boot-sh = + let + inherit (pkgs.lib.trivial) toHexString; + inherit (config.system.outputs) rootfs kernel; + cmdline = concatStringsSep " " config.boot.commandLine; + in + pkgs.buildPackages.runCommand "boot.sh.sh" { + } '' + rootfsStart=${toString (100 * 1024 * 1024)} + rootfsBytes=$(stat -L -c %s ${rootfs}) + append_cmd="mtdparts=phram0:''${rootfsBytes}(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes} memmap=''${rootfsBytes}\$''${rootfsStart}"; + cat > $out <<EOF + #!/bin/sh + test -d \$1 + cd \$1 + ./kexec -f -d --map-file rootfs@$rootfsStart --dtb dtb --command-line '${cmdline} $append_cmd' kernel + EOF + ''; + }; + }; +} diff --git a/modules/outputs/tftpboot.nix b/modules/outputs/tftpboot.nix @@ -0,0 +1,98 @@ +{ + config +, pkgs +, lib +, ... +}: +let + inherit (lib) mkOption types concatStringsSep; + cfg = config.boot.tftp; +in { + imports = [ ../ramdisk.nix ]; + options.boot.tftp.freeSpaceBytes = mkOption { + type = types.int; + default = 0; + }; + options.system.outputs = { + tftpboot = mkOption { + type = types.package; + description = '' + tftpboot + ******** + + This output is intended for developing on a new device. + It assumes you have a serial connection and a + network connection to the device and that your + build machine is running a TFTP server. + + The output is a directory containing kernel and + root filesystem image, and a script :file:`boot.scr` of U-Boot + commands that will load the images into memory and + run them directly, + instead of first writing them to flash. This saves + time and erase cycles. + + It uses the Linux `phram <https://github.com/torvalds/linux/blob/master/drivers/mtd/devices/phram.c>`_ driver to emulate a flash device using a segment of physical RAM. + ''; + }; + boot-scr = mkOption { + type = types.package; + internal = true; + description = '' + U-Boot commands to load and boot a kernel and rootfs over TFTP. + Copy-paste into the device boot monitor + ''; + }; + }; + config = { + boot.ramdisk.enable = true; + + system.outputs = rec { + tftpboot = + let o = config.system.outputs; in + pkgs.runCommand "tftpboot" {} '' + mkdir $out + cd $out + ln -s ${o.rootfs} rootfs + ln -s ${o.kernel} vmlinux + ln -s ${o.manifest} manifest + ln -s ${o.kernel.headers} build + ln -s ${o.uimage} uimage + ln -s ${o.boot-scr}/dtb dtb + ln -s ${o.boot-scr}/script boot.scr + ''; + + boot-scr = + let + inherit (pkgs.lib.trivial) toHexString; + o = config.system.outputs; + cmdline = concatStringsSep " " config.boot.commandLine; + in + pkgs.buildPackages.runCommand "boot-scr" { nativeBuildInputs = [ pkgs.pkgsBuildBuild.dtc ]; } '' + uimageSize=$(($(stat -L -c %s ${o.uimage}) + 0x1000 &(~0xfff))) + rootfsStart=0x$(printf %x $((${toString cfg.loadAddress} + 0x100000 + $uimageSize &(~0xfffff) ))) + rootfsBytes=$(($(stat -L -c %s ${o.rootfs}) + 0x100000 &(~0xfffff))) + rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} )) + rootfsMb=$(($rootfsBytes >> 20)) + cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes},${toString config.hardware.flash.eraseBlockSize} root=/dev/mtdblock0"; + + dtbStart=$(printf %x $((${toString cfg.loadAddress} + $rootfsBytes + 0x100000 + $uimageSize ))) + + mkdir $out + cat ${o.dtb} > $out/dtb + fdtput -p -t s $out/dtb /reserved-memory/phram-rootfs compatible phram + fdtput -p -t lx $out/dtb /reserved-memory/phram-rootfs reg 0 $rootfsStart 0 $(printf %x $rootfsBytes) + + dtbBytes=$(($(stat -L -c %s $out/dtb) + 0x1000 &(~0xfff))) + + cat > $out/script << EOF + setenv serverip ${cfg.serverip} + setenv ipaddr ${cfg.ipaddr} + setenv bootargs 'liminix ${cmdline} $cmd' + tftpboot 0x${lib.toHexString cfg.loadAddress} result/uimage ; tftpboot 0x$(printf %x $rootfsStart) result/rootfs ; tftpboot 0x$dtbStart result/dtb + bootm 0x${lib.toHexString cfg.loadAddress} - 0x$dtbStart + EOF + ''; + }; + }; +} diff --git a/modules/ubifs.nix b/modules/outputs/ubifs.nix diff --git a/modules/standard.nix b/modules/standard.nix @@ -1,12 +0,0 @@ -{ - # "standard" modules that aren't fundamentally required, - # but are probably useful in most common workflows and - # you should have to opt out of instead of into - imports = [ - ./tftpboot.nix - ./kexecboot.nix - ./outputs/flashimage.nix - ./jffs2.nix - ./ubifs.nix - ]; -} diff --git a/modules/tftpboot.nix b/modules/tftpboot.nix @@ -1,98 +0,0 @@ -{ - config -, pkgs -, lib -, ... -}: -let - inherit (lib) mkOption types concatStringsSep; - cfg = config.boot.tftp; -in { - imports = [ ./ramdisk.nix ]; - options.boot.tftp.freeSpaceBytes = mkOption { - type = types.int; - default = 0; - }; - options.system.outputs = { - tftpboot = mkOption { - type = types.package; - description = '' - tftpboot - ******** - - This output is intended for developing on a new device. - It assumes you have a serial connection and a - network connection to the device and that your - build machine is running a TFTP server. - - The output is a directory containing kernel and - root filesystem image, and a script :file:`boot.scr` of U-Boot - commands that will load the images into memory and - run them directly, - instead of first writing them to flash. This saves - time and erase cycles. - - It uses the Linux `phram <https://github.com/torvalds/linux/blob/master/drivers/mtd/devices/phram.c>`_ driver to emulate a flash device using a segment of physical RAM. - ''; - }; - boot-scr = mkOption { - type = types.package; - internal = true; - description = '' - U-Boot commands to load and boot a kernel and rootfs over TFTP. - Copy-paste into the device boot monitor - ''; - }; - }; - config = { - boot.ramdisk.enable = true; - - system.outputs = rec { - tftpboot = - let o = config.system.outputs; in - pkgs.runCommand "tftpboot" {} '' - mkdir $out - cd $out - ln -s ${o.rootfs} rootfs - ln -s ${o.kernel} vmlinux - ln -s ${o.manifest} manifest - ln -s ${o.kernel.headers} build - ln -s ${o.uimage} uimage - ln -s ${o.boot-scr}/dtb dtb - ln -s ${o.boot-scr}/script boot.scr - ''; - - boot-scr = - let - inherit (pkgs.lib.trivial) toHexString; - o = config.system.outputs; - cmdline = concatStringsSep " " config.boot.commandLine; - in - pkgs.buildPackages.runCommand "boot-scr" { nativeBuildInputs = [ pkgs.pkgsBuildBuild.dtc ]; } '' - uimageSize=$(($(stat -L -c %s ${o.uimage}) + 0x1000 &(~0xfff))) - rootfsStart=0x$(printf %x $((${toString cfg.loadAddress} + 0x100000 + $uimageSize &(~0xfffff) ))) - rootfsBytes=$(($(stat -L -c %s ${o.rootfs}) + 0x100000 &(~0xfffff))) - rootfsBytes=$(($rootfsBytes + ${toString cfg.freeSpaceBytes} )) - rootfsMb=$(($rootfsBytes >> 20)) - cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsBytes},${toString config.hardware.flash.eraseBlockSize} root=/dev/mtdblock0"; - - dtbStart=$(printf %x $((${toString cfg.loadAddress} + $rootfsBytes + 0x100000 + $uimageSize ))) - - mkdir $out - cat ${o.dtb} > $out/dtb - fdtput -p -t s $out/dtb /reserved-memory/phram-rootfs compatible phram - fdtput -p -t lx $out/dtb /reserved-memory/phram-rootfs reg 0 $rootfsStart 0 $(printf %x $rootfsBytes) - - dtbBytes=$(($(stat -L -c %s $out/dtb) + 0x1000 &(~0xfff))) - - cat > $out/script << EOF - setenv serverip ${cfg.serverip} - setenv ipaddr ${cfg.ipaddr} - setenv bootargs 'liminix ${cmdline} $cmd' - tftpboot 0x${lib.toHexString cfg.loadAddress} result/uimage ; tftpboot 0x$(printf %x $rootfsStart) result/rootfs ; tftpboot 0x$dtbStart result/dtb - bootm 0x${lib.toHexString cfg.loadAddress} - 0x$dtbStart - EOF - ''; - }; - }; -} diff --git a/vanilla-configuration-hw.nix b/vanilla-configuration-hw.nix @@ -2,6 +2,10 @@ { imports = [ ./vanilla-configuration.nix - ./modules/standard.nix + ./modules/outputs/tftpboot.nix + ./modules/outputs/kexecboot.nix + ./modules/outputs/flashimage.nix + ./modules/outputs/jffs2.nix + ./modules/outputs/ubifs.nix ]; }