From 2f3b108ef15dd6b9b93ad85443777ed75f58e35c Mon Sep 17 00:00:00 2001
From: Daniel Barlow <dan@telent.net>
Date: Sun, 23 Apr 2023 18:23:05 +0100
Subject: [PATCH] tftpboot: set phram erase block size to match hardware

this is needed for tftp boot with a jffs2 filesystem
---
 devices/gl-mt300a/default.nix    | 1 +
 devices/gl-mt300n-v2/default.nix | 1 +
 modules/tftpboot.nix             | 2 +-
 3 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/devices/gl-mt300a/default.nix b/devices/gl-mt300a/default.nix
index 2cd72b9..3682d2f 100644
--- a/devices/gl-mt300a/default.nix
+++ b/devices/gl-mt300a/default.nix
@@ -45,6 +45,7 @@
         flash = {
           address = "0xbc050000";
           size ="0xf80000";
+          eraseBlockSize = "65536";
         };
         rootDevice = "1f05";
 
diff --git a/devices/gl-mt300n-v2/default.nix b/devices/gl-mt300n-v2/default.nix
index 959dce3..168831d 100644
--- a/devices/gl-mt300n-v2/default.nix
+++ b/devices/gl-mt300n-v2/default.nix
@@ -42,6 +42,7 @@
         flash = {
           address = "0xbc050000";
           size = "0xfb0000";
+          eraseBlockSize = "65536";
         };
         rootDevice = "1f05";
 
diff --git a/modules/tftpboot.nix b/modules/tftpboot.nix
index e1ce9f6..6eb2e79 100644
--- a/modules/tftpboot.nix
+++ b/modules/tftpboot.nix
@@ -34,7 +34,7 @@ in {
           rootfsStart=0x$(printf %x $((${cfg.loadAddress} + 0x100000 + $uimageSize)))
           rootfsBytes=$(($(stat -L -c %s ${config.outputs.rootfs}) + 0x100000 &(~0xfffff)))
           rootfsMb=$(($rootfsBytes >> 20))
-          cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsMb}Mi memmap=''${rootfsMb}M\$''${rootfsStart} root=1f00";
+          cmd="mtdparts=phram0:''${rootfsMb}M(rootfs) phram.phram=phram0,''${rootfsStart},''${rootfsMb}Mi,${config.hardware.flash.eraseBlockSize} memmap=''${rootfsMb}M\$''${rootfsStart} root=/dev/mtdblock0";
 
           cat > $out << EOF
           setenv serverip ${cfg.serverip}