Skip to content

Commit

Permalink
ath79: POC for DT-based expansion-friendly fw
Browse files Browse the repository at this point in the history
On former ar71xx, official firmwares could be directly flashed into a
device with expanded flash, provided that partitions like "art" have been
relocated to the end of the expanded flash, but it does not work well on
the current ath79, because the offset of all partitions is set in the
device tree. If partitions like "art" are kept in their original offset,
flashing an official firmware to an expanded device can work, but extra
space beyond the original end will not be usable.

However, there are special "offset" and "size" values documented in
include/linux/mtd/partitions.h of Linux:

 // consume as much as possible, leaving size after the end of partition.
 #define MTDPART_OFS_RETAIN	(uint64_t)(-3)

 // the partition will start at the next erase block.
 #define MTDPART_OFS_NXTBLK	(uint64_t)(-2)

 // the partition will start where the previous one ended.
 #define MTDPART_OFS_APPEND	(uint64_t)(-1)

 // the partition will extend to the end of the master MTD device.
 #define MTDPART_SIZ_FULL	(0)

When these special values are used, the actual offset and size of a
partition will be determined at runtime.

As a result, MTDPART_OFS_RETAIN could be used to define the "offset" of the
original writable partition. Its "size" is used to retain spaces for
read-only partitions after it. (e.g. art) All partitions after it could use
MTDPART_OFS_APPEND for its "offset". However, since these special values
have uint64_t type, the #address-cells should be 2 and format
<high32 low32> should be used, e.g. <(-1) (-3)> for MTDPART_OFS_RETAIN.

If official firmwares are built in this way, they will be flashed to a
well-expanded device again, and can claim all extra space. Partitions like
art could still be relocated to the end of the expanded flash, as many
bootloaders expect.

Now applied only to tplink ath79 targets with "classic flash layout",
as tplink_classic_flash_layout.dtsi shows.

Tested on my tplink tl-wdr4310 (unexpanded), and tl-wdr4900v2 (expanded to
16MiB).

Signed-off-by: Edward Chow <equu@openmail.cc>
  • Loading branch information
InsaneKnight committed Aug 15, 2023
1 parent 497012a commit 2db5f0f
Show file tree
Hide file tree
Showing 33 changed files with 169 additions and 733 deletions.
27 changes: 2 additions & 25 deletions target/linux/ath79/dts/ar7240_tplink.dtsi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT

#include "ar7240.dtsi"
#include "tplink_classic_flash_layout.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
Expand Down Expand Up @@ -63,34 +64,10 @@
&spi {
status = "okay";

flash@0 {
flash: flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

uboot: partition@0 {
reg = <0x0 0x20000>;
label = "u-boot";
read-only;
};

partition@20000 {
compatible = "tplink,firmware";
reg = <0x20000 0x3d0000>;
label = "firmware";
};

art: partition@3f0000 {
reg = <0x3f0000 0x10000>;
label = "art";
read-only;
};
};
};
};

Expand Down
27 changes: 2 additions & 25 deletions target/linux/ath79/dts/ar7241_tplink.dtsi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT

#include "ar7241.dtsi"
#include "tplink_classic_flash_layout.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
Expand Down Expand Up @@ -50,34 +51,10 @@
&spi {
status = "okay";

flash@0 {
flash: flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

uboot: partition@0 {
reg = <0x0 0x20000>;
label = "u-boot";
read-only;
};

partition@20000 {
compatible = "tplink,firmware";
reg = <0x20000 0x3d0000>;
label = "firmware";
};

partition@3f0000 {
reg = <0x3f0000 0x10000>;
label = "art";
read-only;
};
};
};
};

Expand Down
27 changes: 2 additions & 25 deletions target/linux/ath79/dts/ar7241_tplink_tl-wr842n-v1.dts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT

#include "ar7241.dtsi"
#include "tplink_classic_flash_layout.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
Expand Down Expand Up @@ -88,34 +89,10 @@
&spi {
status = "okay";

flash@0 {
flash: flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

uboot: partition@0 {
reg = <0x0 0x20000>;
label = "u-boot";
read-only;
};

partition@20000 {
compatible = "tplink,firmware";
reg = <0x20000 0x7d0000>;
label = "firmware";
};

partition@7f0000 {
reg = <0x7f0000 0x10000>;
label = "art";
read-only;
};
};
};
};

Expand Down
27 changes: 2 additions & 25 deletions target/linux/ath79/dts/ar7242_tplink_tl-wr2543-v1.dts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later OR MIT

#include "ar7242.dtsi"
#include "tplink_classic_flash_layout.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
Expand Down Expand Up @@ -92,35 +93,11 @@
&spi {
status = "okay";

flash@0 {
flash: flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;
m25p,fast-read;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;
};

partition@20000 {
compatible = "tplink,firmware";
label = "firmware";
reg = <0x020000 0x7d0000>;
};

art: partition@7f0000 {
label = "art";
reg = <0x7f0000 0x010000>;
read-only;
};
};
};
};

Expand Down
27 changes: 2 additions & 25 deletions target/linux/ath79/dts/ar9132_tplink_tl-wa901nd-v2.dts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only

#include "ar9132.dtsi"
#include "tplink_classic_flash_layout.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
Expand Down Expand Up @@ -59,34 +60,10 @@
&spi {
status = "okay";

flash@0 {
flash: flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;
};

partition@1 {
compatible = "tplink,firmware";
label = "firmware";
reg = <0x020000 0x3D0000>;
};

art: partition@2 {
label = "art";
reg = <0x3F0000 0x010000>;
read-only;
};
};
};
};

Expand Down
27 changes: 2 additions & 25 deletions target/linux/ath79/dts/ar9132_tplink_tl-wr1043nd-v1.dts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only

#include "ar9132.dtsi"
#include "tplink_classic_flash_layout.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
Expand Down Expand Up @@ -84,35 +85,11 @@
&spi {
status = "okay";

flash@0 {
flash: flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;
m25p,fast-read;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;
};

partition@20000 {
compatible = "tplink,firmware";
label = "firmware";
reg = <0x020000 0x7D0000>;
};

art: partition@7F0000 {
label = "art";
reg = <0x7F0000 0x010000>;
read-only;
};
};
};
};

Expand Down
27 changes: 2 additions & 25 deletions target/linux/ath79/dts/ar9132_tplink_tl-wr941-v2.dts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only

#include "ar9132.dtsi"
#include "tplink_classic_flash_layout.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
Expand Down Expand Up @@ -108,34 +109,10 @@
&spi {
status = "okay";

flash@0 {
flash: flash@0 {
compatible = "jedec,spi-nor";
reg = <0>;
spi-max-frequency = <25000000>;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x20000>;
read-only;
};

partition@20000 {
compatible = "tplink,firmware";
label = "firmware";
reg = <0x020000 0x3d0000>;
};

art: partition@3f0000 {
label = "art";
reg = <0x3f0000 0x10000>;
read-only;
};
};
};
};

Expand Down
53 changes: 22 additions & 31 deletions target/linux/ath79/dts/ar9331_tplink_tl-mr3020-v1.dts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only

#include "ar9331.dtsi"
#include "tplink_classic_flash_layout.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
Expand Down Expand Up @@ -99,40 +100,10 @@
status = "okay";

/* Spansion S25FL032PIF SPI flash */
flash@0 {
flash: flash@0 {
compatible = "jedec,spi-nor";
spi-max-frequency = <50000000>;
reg = <0>;

partitions {
compatible = "fixed-partitions";
#address-cells = <1>;
#size-cells = <1>;

uboot: partition@0 {
label = "u-boot";
reg = <0x000000 0x020000>;
read-only;
};

partition@20000 {
compatible = "tplink,firmware";
label = "firmware";
reg = <0x020000 0x3c0000>;
};

partition@3e0000 {
label = "config";
reg = <0x3e0000 0x010000>;
read-only;
};

art: partition@3f0000 {
label = "art";
reg = <0x3f0000 0x010000>;
read-only;
};
};
};
};

Expand Down Expand Up @@ -172,3 +143,23 @@
reg = <0x1fc00 0x6>;
};
};

&mtdparts {
partition@2 {
compatible = "tplink,firmware";
label = "firmware";
reg = <MTDPART_OFS_RETAIN 0x020000>;
};

partition@3 {
label = "config";
reg = <MTDPART_OFS_APPEND 0x010000>;
read-only;
};

art: partition@4 {
label = "art";
reg = <MTDPART_OFS_APPEND 0x010000>;
read-only;
};
};

0 comments on commit 2db5f0f

Please sign in to comment.