commit 0cab6e9fba956b89cbf6b1b961b264b6b0a31101
parent adc198b3af57291c6d47f6585458dca6f0bc8de8
Author: Daniel Barlow <dan@telent.net>
Date: Thu, 2 Mar 2023 15:11:12 +0000
rename phram -> tftpboot and flash.scr to boot.scr
Diffstat:
6 files changed, 88 insertions(+), 81 deletions(-)
diff --git a/doc/developer.rst b/doc/developer.rst
@@ -113,7 +113,7 @@ image instead of flashing. In your device configuration add
.. code-block:: nix
imports = [
- ./modules/phram.nix
+ ./modules/tftpboot.nix
];
boot.tftp = {
diff --git a/modules/phram.nix b/modules/phram.nix
@@ -1,78 +0,0 @@
-{
- config
-, pkgs
-, lib
-, ...
-}:
-let
- inherit (lib) mkOption types concatStringsSep;
- cfg = config.boot.tftp;
-in {
- options = {
- boot = {
- tftp = {
- loadAddress = mkOption { type = types.str; };
- # These names match the uboot environment variables. I reserve
- # the right to change them if I think of better ones.
- ipaddr = mkOption { type = types.str; };
- serverip = mkOption { type = types.str; };
- enable = mkOption { type = types.boolean; };
- };
- };
- };
- config = {
- kernel = {
- config = {
- MTD = "y";
- MTD_PHRAM = "y";
- MTD_CMDLINE_PARTS = "y";
-
- # one or more of the following is required to get from
- # VFS: Cannot open root device "1f00" or unknown-block(31,0): error -6
- # to
- # VFS: Mounted root (squashfs filesystem) readonly on device 31:0.
- MTD_OF_PARTS = "y";
- PARTITION_ADVANCED = "y";
- MSDOS_PARTITION = "y";
- EFI_PARTITION = "y";
- MTD_BLKDEVS = "y";
- MTD_BLOCK = "y";
-
- # CONFIG_MTD_MTDRAM=m c'est quoi?
- };
-
- };
- outputs.tftproot =
- let o = config.outputs; in
- pkgs.runCommand "tftproot" {} ''
- mkdir $out
- cd $out
- ln -s ${o.squashfs} squashfs
- 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} flash.scr
- '';
-
- outputs.boot-scr =
- let
- inherit (pkgs.lib.trivial) toHexString;
- in
- pkgs.buildPackages.runCommand "" {} ''
- uimageSize=$(($(stat -L -c %s ${config.outputs.uimage}) + 0x1000 &(~0xfff)))
- squashfsStart=0x$(printf %x $((${cfg.loadAddress} + $uimageSize)))
- squashfsBytes=$(($(stat -L -c %s ${config.outputs.squashfs}) + 0x100000 &(~0xfffff)))
- squashfsMb=$(($squashfsBytes >> 20))
- cmd="mtdparts=phram0:''${squashfsMb}M(nix) phram.phram=phram0,''${squashfsStart},''${squashfsMb}Mi memmap=''${squashfsMb}M\$''${squashfsStart} root=1f00";
- cat > $out << EOF
- setenv serverip ${cfg.serverip}
- setenv ipaddr ${cfg.ipaddr}
- setenv bootargs '${concatStringsSep " " config.boot.commandLine} $cmd'
- tftp 0x$(printf %x ${cfg.loadAddress}) result/uimage ; tftp 0x$(printf %x $squashfsStart) result/squashfs
- bootm 0x$(printf %x ${cfg.loadAddress})
- EOF
- '';
-
- };
-}
diff --git a/modules/tftpboot.nix b/modules/tftpboot.nix
@@ -0,0 +1,78 @@
+{
+ config
+, pkgs
+, lib
+, ...
+}:
+let
+ inherit (lib) mkOption types concatStringsSep;
+ cfg = config.boot.tftp;
+in {
+ options = {
+ boot = {
+ tftp = {
+ loadAddress = mkOption { type = types.str; };
+ # These names match the uboot environment variables. I reserve
+ # the right to change them if I think of better ones.
+ ipaddr = mkOption { type = types.str; };
+ serverip = mkOption { type = types.str; };
+ enable = mkOption { type = types.boolean; };
+ };
+ };
+ };
+ config = {
+ kernel = {
+ config = {
+ MTD = "y";
+ MTD_PHRAM = "y";
+ MTD_CMDLINE_PARTS = "y";
+
+ # one or more of the following is required to get from
+ # VFS: Cannot open root device "1f00" or unknown-block(31,0): error -6
+ # to
+ # VFS: Mounted root (squashfs filesystem) readonly on device 31:0.
+ MTD_OF_PARTS = "y";
+ PARTITION_ADVANCED = "y";
+ MSDOS_PARTITION = "y";
+ EFI_PARTITION = "y";
+ MTD_BLKDEVS = "y";
+ MTD_BLOCK = "y";
+
+ # CONFIG_MTD_MTDRAM=m c'est quoi?
+ };
+
+ };
+ outputs.tftproot =
+ let o = config.outputs; in
+ pkgs.runCommand "tftproot" {} ''
+ mkdir $out
+ cd $out
+ ln -s ${o.squashfs} squashfs
+ 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} boot.scr
+ '';
+
+ outputs.boot-scr =
+ let
+ inherit (pkgs.lib.trivial) toHexString;
+ in
+ pkgs.buildPackages.runCommand "" {} ''
+ uimageSize=$(($(stat -L -c %s ${config.outputs.uimage}) + 0x1000 &(~0xfff)))
+ squashfsStart=0x$(printf %x $((${cfg.loadAddress} + $uimageSize)))
+ squashfsBytes=$(($(stat -L -c %s ${config.outputs.squashfs}) + 0x100000 &(~0xfffff)))
+ squashfsMb=$(($squashfsBytes >> 20))
+ cmd="mtdparts=phram0:''${squashfsMb}M(nix) phram.phram=phram0,''${squashfsStart},''${squashfsMb}Mi memmap=''${squashfsMb}M\$''${squashfsStart} root=1f00";
+ cat > $out << EOF
+ setenv serverip ${cfg.serverip}
+ setenv ipaddr ${cfg.ipaddr}
+ setenv bootargs '${concatStringsSep " " config.boot.commandLine} $cmd'
+ tftp 0x$(printf %x ${cfg.loadAddress}) result/uimage ; tftp 0x$(printf %x $squashfsStart) result/squashfs
+ bootm 0x$(printf %x ${cfg.loadAddress})
+ EOF
+ '';
+
+ };
+}
diff --git a/rotuer-secrets.nix b/rotuer-secrets.nix
@@ -0,0 +1,7 @@
+{
+ wpa_passphrase = "colourless green ideas";
+ l2tp = {
+ name = "db432@a.1";
+ password = "PHEALRQ8RY74";
+ };
+}
diff --git a/rotuer.nix b/rotuer.nix
@@ -43,7 +43,7 @@ in rec {
imports = [
./modules/wlan.nix
- ./modules/phram.nix
+ ./modules/tftpboot.nix
];
kernel = {
diff --git a/vanilla-configuration.nix b/vanilla-configuration.nix
@@ -4,7 +4,7 @@ let
inherit (pkgs.liminix.services) oneshot longrun bundle target;
in rec {
imports = [
- ./modules/phram.nix
+ ./modules/tftpboot.nix
./modules/wlan.nix
];
services.loopback =