[OpenWrt-Devel] ath79: enable all space on Netgear ar9344-based WNDR routers
diff mbox series

Message ID 20191112140214.59f2971f@kosmio.komorska
State New
Headers show
Series
  • [OpenWrt-Devel] ath79: enable all space on Netgear ar9344-based WNDR routers
Related show

Commit Message

Michal Cieslakiewicz Nov. 12, 2019, 1:02 p.m. UTC
Netgear WNDR routers (AR9344 models) like WNDR4300 have 128 MiB of flash
memory but only first 32 MiB are used now - both by vendor's firmware and
OpenWrt. This patch concatenates two regions of flash memory: ubi part
of firmware partition and reserved (unused) space beyond 'caldata_backup'
while preserving ART backup. No data is wiped or moved away.
This increases area for OS ubi volumes from 23 to 119 Megabytes.

Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
---
 .../linux/ath79/dts/ar9344_netgear_wndr.dtsi  | 25 +++++++++++++++----
 1 file changed, 20 insertions(+), 5 deletions(-)

Comments

Enrico Mioso Nov. 12, 2019, 1:43 p.m. UTC | #1
Wow!! This is applicable also to Netgear R6220!


On Tue, 12 Nov 2019, Michal Cieslakiewicz wrote:

> Date: Tue, 12 Nov 2019 14:02:14
> From: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
> To: "openwrt-devel@lists.openwrt.org" <openwrt-devel@lists.openwrt.org>
> Cc: Adrian Schmutzler <mail@adrianschmutzler.de>
> Subject: [OpenWrt-Devel] [PATCH] ath79: enable all space on Netgear
>     ar9344-based WNDR routers
> 
> Netgear WNDR routers (AR9344 models) like WNDR4300 have 128 MiB of flash
> memory but only first 32 MiB are used now - both by vendor's firmware and
> OpenWrt. This patch concatenates two regions of flash memory: ubi part
> of firmware partition and reserved (unused) space beyond 'caldata_backup'
> while preserving ART backup. No data is wiped or moved away.
> This increases area for OS ubi volumes from 23 to 119 Megabytes.
>
> Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
> ---
> .../linux/ath79/dts/ar9344_netgear_wndr.dtsi  | 25 +++++++++++++++----
> 1 file changed, 20 insertions(+), 5 deletions(-)
>
> diff --git a/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi b/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
> index 16a4e3f6e8..d5a699e774 100644
> --- a/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
> +++ b/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
> @@ -97,6 +97,22 @@
> 			linux,default-trigger = "usbport";
> 		};
> 	};
> +
> +	ubi-concat {
> +		compatible = "mtd-concat";
> +		devices = <&ubipart0 &ubipart1>;
> +
> +		partitions {
> +			compatible = "fixed-partitions";
> +			#address-cells = <1>;
> +			#size-cells = <1>;
> +
> +			ubi@8c0000 {
> +				label = "ubi";
> +				reg = <0x0 0x7700000>;
> +			};
> +		};
> +	};
> };
>
> &pinmux {
> @@ -155,8 +171,8 @@
> 			reg = <0x6c0000 0x200000>;
> 		};
>
> -		ubi@8c0000 {
> -			label = "ubi";
> +		ubipart0: partition@8c0000 {
> +			label = "ubipart0";
> 			reg = <0x8c0000 0x1700000>;
> 		};
>
> @@ -172,10 +188,9 @@
> 			read-only;
> 		};
>
> -		partition@2000000 {
> -			label = "reserved";
> +		ubipart1: partition@2000000 {
> +			label = "ubipart1";
> 			reg = <0x2000000 0x6000000>;
> -			read-only;
> 		};
> 	};
> };
> -- 
> 2.24.0
>
>
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
>
Piotr Dymacz Nov. 12, 2019, 1:51 p.m. UTC | #2
Hi Michal,

On 12.11.2019 14:02, Michal Cieslakiewicz wrote:
> Netgear WNDR routers (AR9344 models) like WNDR4300 have 128 MiB of flash
> memory but only first 32 MiB are used now - both by vendor's firmware and
> OpenWrt. This patch concatenates two regions of flash memory: ubi part
> of firmware partition and reserved (unused) space beyond 'caldata_backup'
> while preserving ART backup. No data is wiped or moved away.
> This increases area for OS ubi volumes from 23 to 119 Megabytes.

Is revert to vendor firmware still possible with this change, e.g. using 
Netgear TFTP recovery mode?
Michal Cieslakiewicz Nov. 12, 2019, 4 p.m. UTC | #3
>
> Is revert to vendor firmware still possible with this change, e.g.
> using Netgear TFTP recovery mode?
>   

Hello Piotr,

Yes, it is possible. I've performed such operation using fw_recovery
command from u-boot prompt.

However, looking at factory logs, reserved space is used somehow by
vendor firmware in a way that I wasn't able to investigate. My
WNDR4300 (bought used) had this whole area erased. I do not know if
that was default setup or deliberate action of previous owner. Vendor
firmware does not reflash that partition at all.

Cheers
Michal
David Bauer Nov. 12, 2019, 4:15 p.m. UTC | #4
Hello Michal,

On 11/12/19 2:02 PM, Michal Cieslakiewicz wrote:
> Netgear WNDR routers (AR9344 models) like WNDR4300 have 128 MiB of flash
> memory but only first 32 MiB are used now - both by vendor's firmware and
> OpenWrt. This patch concatenates two regions of flash memory: ubi part
> of firmware partition and reserved (unused) space beyond 'caldata_backup'
> while preserving ART backup. No data is wiped or moved away.
> This increases area for OS ubi volumes from 23 to 119 Megabytes.

Have you tried if this breaks sysupgrade from an older OpenWrt firmware?
I'm not sure if an UBI resize works without additional steps.

Best wishes
David

> 
> Signed-off-by: Michal Cieslakiewicz <michal.cieslakiewicz@wp.pl>
> ---
>  .../linux/ath79/dts/ar9344_netgear_wndr.dtsi  | 25 +++++++++++++++----
>  1 file changed, 20 insertions(+), 5 deletions(-)
> 
> diff --git a/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi b/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
> index 16a4e3f6e8..d5a699e774 100644
> --- a/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
> +++ b/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
> @@ -97,6 +97,22 @@
>  			linux,default-trigger = "usbport";
>  		};
>  	};
> +
> +	ubi-concat {
> +		compatible = "mtd-concat";
> +		devices = <&ubipart0 &ubipart1>;
> +
> +		partitions {
> +			compatible = "fixed-partitions";
> +			#address-cells = <1>;
> +			#size-cells = <1>;
> +
> +			ubi@8c0000 {
> +				label = "ubi";
> +				reg = <0x0 0x7700000>;
> +			};
> +		};
> +	};
>  };
>  
>  &pinmux {
> @@ -155,8 +171,8 @@
>  			reg = <0x6c0000 0x200000>;
>  		};
>  
> -		ubi@8c0000 {
> -			label = "ubi";
> +		ubipart0: partition@8c0000 {
> +			label = "ubipart0";
>  			reg = <0x8c0000 0x1700000>;
>  		};
>  
> @@ -172,10 +188,9 @@
>  			read-only;
>  		};
>  
> -		partition@2000000 {
> -			label = "reserved";
> +		ubipart1: partition@2000000 {
> +			label = "ubipart1";
>  			reg = <0x2000000 0x6000000>;
> -			read-only;
>  		};
>  	};
>  };
>
Michal Cieslakiewicz Nov. 12, 2019, 6:22 p.m. UTC | #5
On Tue, 12 Nov 2019 17:15:17 +0100
David Bauer <mail@david-bauer.net> wrote:

> Hello Michal,
> 
> Have you tried if this breaks sysupgrade from an older OpenWrt
> firmware? I'm not sure if an UBI resize works without additional
> steps.
> 
> Best wishes
> David
> 

Hello David,

Thanks! Good point, I was usually flashing from uboot to a clean state.
I will test this sysupgrade scenario and come back with results.

Best regards
Michal
Michal Cieslakiewicz Nov. 19, 2019, 3:17 p.m. UTC | #6
Hello David,

Two questions were raised just after publishing 'all-flash-space' patch.
Now I am ready to provide more information on these issues:

0. Downgrade to vendor firmware.

It is possible. Just don't forget to erase both ubi concat partitions:
'mtd -r erase ubi' does the job fine.

1. Sysupgrade:

> > 
> > Have you tried if this breaks sysupgrade from an older OpenWrt
> > firmware? I'm not sure if an UBI resize works without additional
> > steps.
> > 

You were right, rootfs_data volume stays small after sysupgrade. My
approach is to execute 'ubirsvol' command for /dev/ubi0_1 and allocate
all available space. There are caveats however:

* command cannot be run after rootfs_data is mounted (device busy)
* command cannot be run in sysupgrade sequence (sysupgrade works in old
  system that is not mtd-concat aware)

I came out with a solution - to plug into preinit phase after ubi is
available but before ubi rootfs_data volume is started and incorporated
into overlayfs. Here is script (only for ath79/nand target so path is
target/linux/ath79/nand/base-files/lib/preinit/78_ubi_grow_rootfs_data).
I've tested it by running sysupgrade on my WNDR4300 and volume was
resized correctly.

----
#!/bin/sh

grow_ubi_volume() {
	local free_lebs="$(ubinfo /dev/ubi0 | awk '$1=="Amount" && $3=="available" { print $6 }')"
	local used_lebs="$(ubinfo /dev/ubi0_$1 | awk '$1=="Size:" { print $2 }')"

	if [ $free_lebs -eq 0 ] ; then
		return
	fi

	echo "- grow ubi volume (id $1) -"
	ubirsvol /dev/ubi0 -n $1 -S $(($used_lebs+$free_lebs))
}

do_grow_ubi_rootfs_data() {
	local board_name="$(cat /tmp/sysinfo/board_name || echo '')"

	case "$board_name" in
		netgear,wndr3700-v4|\
		netgear,wndr4300)
			grow_ubi_volume 1
		;;
	esac
}

boot_hook_add preinit_main do_grow_ubi_rootfs_data
----

I'll gladly read your opinion on above solution. Can it be accepted into mainline ?

Best regards
Michal
Jonas Gorski Nov. 19, 2019, 3:54 p.m. UTC | #7
On Tue, 19 Nov 2019 at 16:18, Michal Cieslakiewicz
<michal.cieslakiewicz@wp.pl> wrote:
>
> Hello David,
>
> Two questions were raised just after publishing 'all-flash-space' patch.
> Now I am ready to provide more information on these issues:
>
> 0. Downgrade to vendor firmware.
>
> It is possible. Just don't forget to erase both ubi concat partitions:
> 'mtd -r erase ubi' does the job fine.
>
> 1. Sysupgrade:
>
> > >
> > > Have you tried if this breaks sysupgrade from an older OpenWrt
> > > firmware? I'm not sure if an UBI resize works without additional
> > > steps.
> > >

How about

2. Initial installation:

Have you checked that flashing a factory.bin image through tftp still works?


Regards
Jonas
Michal Cieslakiewicz Nov. 19, 2019, 4:33 p.m. UTC | #8
Hello,

> 
> Have you checked that flashing a factory.bin image through tftp still
> works?
> 

Yes, it works. On this router the easiest way to flash memory via tftp
is to enter uboot and execute 'fw_recovery' command, then factory.img
file can be uploaded via tftp client.  I hope this answers your
question.

Best regards
Michal
Jonas Gorski Nov. 19, 2019, 4:36 p.m. UTC | #9
On Tue, 19 Nov 2019 at 17:33, Michal Cieslakiewicz
<michal.cieslakiewicz@wp.pl> wrote:
>
> Hello,
>
> >
> > Have you checked that flashing a factory.bin image through tftp still
> > works?
> >
>
> Yes, it works. On this router the easiest way to flash memory via tftp
> is to enter uboot and execute 'fw_recovery' command, then factory.img
> file can be uploaded via tftp client.  I hope this answers your
> question.

That was my question, if the "new" OpenWrt sysupgrade.bin still works
in the initial flash.

Regards
Jonas
Michal Cieslakiewicz Nov. 19, 2019, 4:39 p.m. UTC | #10
Hello,

Argh, I forgot to add this to my previous email...
ubi volume is successfully resized, but ubi filesystem on top of it is
not - so /overlay does not benefit from extra space. Are there any
methods for UBIFS online resize that complement ubirsvol?

Best regards
Michal
Michal Cieslakiewicz Nov. 19, 2019, 4:59 p.m. UTC | #11
> 
> That was my question, if the "new" OpenWrt sysupgrade.bin still works
> in the initial flash.
> 

sysupgrade.bin for this model is in format tar+metadata, it is not
designed to be put into flash directly.

Regards
Michal
Jonas Gorski Nov. 19, 2019, 9:58 p.m. UTC | #12
On Tue, 19 Nov 2019 at 17:59, Michal Cieslakiewicz
<michal.cieslakiewicz@wp.pl> wrote:
>
> >
> > That was my question, if the "new" OpenWrt sysupgrade.bin still works
> > in the initial flash.
> >
>
> sysupgrade.bin for this model is in format tar+metadata, it is not
> designed to be put into flash directly.

Typo, I did mean factory.bin ... . The type you use to initially flash
OpenWrt ;-)

Regards
Jonas
Michal Cieslakiewicz Nov. 19, 2019, 10:56 p.m. UTC | #13
> 
> Typo, I did mean factory.bin ... . The type you use to initially flash
> OpenWrt ;-)
> 

Ok, that will be factory.img. There is no factory.bin image for that
model to flash. If someone needs it badly, img file is 128-byte DNI
header prepended to bin file (kernel + fake rootfs).

Regards
Michal

Patch
diff mbox series

diff --git a/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi b/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
index 16a4e3f6e8..d5a699e774 100644
--- a/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
+++ b/target/linux/ath79/dts/ar9344_netgear_wndr.dtsi
@@ -97,6 +97,22 @@ 
 			linux,default-trigger = "usbport";
 		};
 	};
+
+	ubi-concat {
+		compatible = "mtd-concat";
+		devices = <&ubipart0 &ubipart1>;
+
+		partitions {
+			compatible = "fixed-partitions";
+			#address-cells = <1>;
+			#size-cells = <1>;
+
+			ubi@8c0000 {
+				label = "ubi";
+				reg = <0x0 0x7700000>;
+			};
+		};
+	};
 };
 
 &pinmux {
@@ -155,8 +171,8 @@ 
 			reg = <0x6c0000 0x200000>;
 		};
 
-		ubi@8c0000 {
-			label = "ubi";
+		ubipart0: partition@8c0000 {
+			label = "ubipart0";
 			reg = <0x8c0000 0x1700000>;
 		};
 
@@ -172,10 +188,9 @@ 
 			read-only;
 		};
 
-		partition@2000000 {
-			label = "reserved";
+		ubipart1: partition@2000000 {
+			label = "ubipart1";
 			reg = <0x2000000 0x6000000>;
-			read-only;
 		};
 	};
 };