From 0a2881914b7504a614a13736474ec59c24282155 Mon Sep 17 00:00:00 2001
From: Daniel Barlow <dan@telent.net>
Date: Mon, 10 Apr 2023 20:39:26 +0100
Subject: [PATCH] set erase block size to something that works for jffs2

---
 devices/gl-ar750/default.nix | 4 ++++
 modules/hardware.nix         | 1 +
 modules/jffs2.nix            | 2 +-
 3 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/devices/gl-ar750/default.nix b/devices/gl-ar750/default.nix
index 77dbaa035..0d4b76297 100644
--- a/devices/gl-ar750/default.nix
+++ b/devices/gl-ar750/default.nix
@@ -87,6 +87,7 @@
         flash = {
           address = "0x9F060000";
           size ="0xfa0000";
+          eraseBlockSize = "65536";
         };
         rootDevice = "1f05";
         dts = {
@@ -163,12 +164,15 @@
           AR8216_PHY = "y";         # eth1 is behind a switch
 
           MTD_SPI_NOR = "y";
+          MTD_SPI_NOR_USE_4K_SECTORS = "n";  # jffs2 needs min 8k erase block
+
           SPI_ATH79 = "y";      # these are copied from OpenWrt.
           SPI_MASTER= "y";      # At least one of them is necessary
           SPI_MEM= "y";
           SPI_AR934X= "y";
           SPI_BITBANG= "y";
           SPI_GPIO= "y";
+
           GPIO_ATH79 = "y";
           GPIOLIB = "y";
           EXPERT="y";
diff --git a/modules/hardware.nix b/modules/hardware.nix
index faa70a9f2..d98526112 100644
--- a/modules/hardware.nix
+++ b/modules/hardware.nix
@@ -24,6 +24,7 @@ in {
         # for wireless devices, etc
         address = mkOption { type = types.str; };
         size = mkOption { type = types.str; };
+        eraseBlockSize = mkOption { type = types.str; };
       };
       loadAddress = mkOption { default = null; };
       entryPoint = mkOption { };
diff --git a/modules/jffs2.nix b/modules/jffs2.nix
index deca6fda3..7ceaff687 100644
--- a/modules/jffs2.nix
+++ b/modules/jffs2.nix
@@ -33,7 +33,7 @@ in
            }}
           cp $pkgClosure/registration nix-path-registration
           grafts=$(sed < $pkgClosure/store-paths 's/^\(.*\)$/--graft \1:\1/g')
-          mkfs.jffs2 ${endian} --pad --root $TMPDIR/empty --output $out  $grafts
+          mkfs.jffs2 ${endian} -e ${config.hardware.flash.eraseBlockSize} --pad --root $TMPDIR/empty --output $out  $grafts
         '';
       jffs2boot =
         let o = config.outputs; in