From 7c78be1b747eb0c8d64da67deb3a8aec75bd7b9c Mon Sep 17 00:00:00 2001
From: Koen Vandeputte <koen.vandeputte@ncentric.com>
Date: Wed, 24 Oct 2018 14:49:07 +0200
Subject: [PATCH] ar71xx: switch more targets to dynamic partitioning

Targets:
- TP-LINK ER355
- TP-LINK C25 V1
- TP-LINK C59 V1
- TP-LINK C7 V4
- TP-LINK C7 V5

Fixes build issues seen due to the kernel being too big

Signed-off-by: Koen Vandeputte <koen.vandeputte@ncentric.com>
---
 target/linux/ar71xx/image/generic-tp-link.mk | 12 +++---
 tools/firmware-utils/src/tplink-safeloader.c | 43 ++++++--------------
 2 files changed, 20 insertions(+), 35 deletions(-)

diff --git a/target/linux/ar71xx/image/generic-tp-link.mk b/target/linux/ar71xx/image/generic-tp-link.mk
index 5036e85a01..08cc444a49 100644
--- a/target/linux/ar71xx/image/generic-tp-link.mk
+++ b/target/linux/ar71xx/image/generic-tp-link.mk
@@ -14,7 +14,7 @@ define Device/archer-c25-v1
   TPLINK_BOARD_ID := ARCHER-C25-V1
   DEVICE_PROFILE := ARCHERC25V1
   IMAGE_SIZE := 7808k
-  MTDPARTS := spi0.0:128k(factory-uboot)ro,64k(u-boot)ro,1536k(kernel),6272k(rootfs),128k(config)ro,64k(art)ro,7808k@0x30000(firmware)
+  MTDPARTS := spi0.0:128k(factory-uboot)ro,64k(u-boot)ro,7808k(firmware),128k(config)ro,64k(art)ro
   SUPPORTED_DEVICES := archer-c25-v1
 endef
 TARGET_DEVICES += archer-c25-v1
@@ -40,7 +40,7 @@ define Device/archer-c59-v1
   TPLINK_BOARD_ID := ARCHER-C59-V1
   DEVICE_PROFILE := ARCHERC59V1
   IMAGE_SIZE := 14528k
-  MTDPARTS := spi0.0:64k(u-boot)ro,64k(mac)ro,1536k(kernel),12992k(rootfs),1664k(tplink)ro,64k(art)ro,14528k@0x20000(firmware)
+  MTDPARTS := spi0.0:64k(u-boot)ro,64k(mac)ro,14528k(firmware),1664k(tplink)ro,64k(art)ro
   SUPPORTED_DEVICES := archer-c59-v1
 endef
 TARGET_DEVICES += archer-c59-v1
@@ -143,7 +143,7 @@ define Device/archer-c7-v4
   BOARDNAME := ARCHER-C7-V4
   TPLINK_BOARD_ID := ARCHER-C7-V4
   IMAGE_SIZE := 15104k
-  MTDPARTS := spi0.0:128k(factory-uboot)ro,128k(u-boot)ro,1536k(kernel),13568k(rootfs),960k(config)ro,64k(art)ro,15104k@0x40000(firmware)
+  MTDPARTS := spi0.0:128k(factory-uboot)ro,128k(u-boot)ro,15104k(firmware),960k(config)ro,64k(art)ro
   SUPPORTED_DEVICES := archer-c7-v4
 endef
 TARGET_DEVICES += archer-c7-v4
@@ -153,8 +153,8 @@ define Device/archer-c7-v5
   DEVICE_TITLE := TP-LINK Archer C7 v5
   BOARDNAME := ARCHER-C7-V5
   TPLINK_BOARD_ID := ARCHER-C7-V5
-  IMAGE_SIZE := 15104k
-  MTDPARTS := spi0.0:128k(factory-uboot)ro,128k(u-boot)ro,64k@0x50000(art)ro,1536k@0xc0000(kernel),13824k(rootfs),15360k@0xc0000(firmware)
+  IMAGE_SIZE := 15360k
+  MTDPARTS := spi0.0:128k(factory-uboot)ro,128k(u-boot)ro,64k@0x50000(art)ro,15360k@0xc0000(firmware)
   SUPPORTED_DEVICES := archer-c7-v5
 endef
 TARGET_DEVICES += archer-c7-v5
@@ -240,6 +240,8 @@ define Device/re355-v1
   DEVICE_PROFILE := RE355
   TPLINK_HWID := 0x0
   TPLINK_HWREV := 0
+  KERNEL := kernel-bin | patch-cmdline | lzma | tplink-v1-header -O
+  KERNEL_INITRAMFS := kernel-bin | patch-cmdline | lzma | tplink-v1-header
 endef
 TARGET_DEVICES += re355-v1
 
diff --git a/tools/firmware-utils/src/tplink-safeloader.c b/tools/firmware-utils/src/tplink-safeloader.c
index 7f8a5d22ad..0ff00e463c 100644
--- a/tools/firmware-utils/src/tplink-safeloader.c
+++ b/tools/firmware-utils/src/tplink-safeloader.c
@@ -368,16 +368,12 @@ static struct device_info boards[] = {
 		.support_trail = '\x00',
 		.soft_ver = "soft_ver:1.0.0\n",
 
-		/**
-		    We use a bigger os-image partition than the stock images (and thus
-		    smaller file-system), as our kernel doesn't fit in the stock firmware's
-		    1MB os-image.
-		*/
+		/* We're using a dynamic kernel/rootfs split here */
 		.partitions = {
 			{"factory-boot", 0x00000, 0x20000},
 			{"fs-uboot", 0x20000, 0x10000},
-			{"os-image", 0x30000, 0x180000},	/* Stock: base 0x30000 size 0x100000 */
-			{"file-system", 0x1b0000, 0x620000},	/* Stock: base 0x130000 size 0x6a0000 */
+			{"firmware", 0x30000, 0x7a0000},	/* Stock: name os-image base 0x30000 size 0x100000 */
+								/* Stock: name file-system base 0x130000 size 0x6a0000 */
 			{"user-config", 0x7d0000, 0x04000},
 			{"default-mac", 0x7e0000, 0x00100},
 			{"device-id", 0x7e0100, 0x00100},
@@ -447,14 +443,14 @@ static struct device_info boards[] = {
 		.support_trail = '\x00',
 		.soft_ver = "soft_ver:1.0.0\n",
 
+		/* We're using a dynamic kernel/rootfs split here */
 		.partitions = {
 			{"fs-uboot", 0x00000, 0x10000},
 			{"default-mac", 0x10000, 0x00200},
 			{"pin", 0x10200, 0x00200},
 			{"device-id", 0x10400, 0x00100},
 			{"product-info", 0x10500, 0x0fb00},
-			{"os-image", 0x20000, 0x180000},
-			{"file-system", 0x1a0000, 0xcb0000},
+			{"firmware", 0x20000, 0xe30000},
 			{"partition-table", 0xe50000, 0x10000},
 			{"soft-version", 0xe60000, 0x10000},
 			{"support-list", 0xe70000, 0x10000},
@@ -638,16 +634,12 @@ static struct device_info boards[] = {
 		.support_trail = '\x00',
 		.soft_ver = "soft_ver:1.0.0\n",
 
-		/**
-		    We use a bigger os-image partition than the stock images (and thus
-		    smaller file-system), as our kernel doesn't fit in the stock firmware's
-		    1MB os-image.
-		*/
+		/* We're using a dynamic kernel/rootfs split here */
 		.partitions = {
 			{"factory-boot", 0x00000, 0x20000},
 			{"fs-uboot", 0x20000, 0x20000},
-			{"os-image", 0x40000, 0x180000},	/* Stock: base 0x40000 size 0x120000 */
-			{"file-system", 0x1c0000, 0xd40000},	/* Stock: base 0x160000 size 0xda0000 */
+			{"firmware", 0x40000, 0xEC0000},	/* Stock: name os-image base 0x40000 size 0x120000 */
+								/* Stock: name file-system base 0x160000 size 0xda0000 */
 			{"default-mac", 0xf00000, 0x00200},
 			{"pin", 0xf00200, 0x00200},
 			{"device-id", 0xf00400, 0x00100},
@@ -681,11 +673,7 @@ static struct device_info boards[] = {
 		.support_trail = '\x00',
 		.soft_ver = "soft_ver:1.0.0\n",
 
-		/**
-		  We use a bigger os-image partition than the stock images (and thus
-		  smaller file-system), as our kernel doesn't fit in the stock firmware's
-		  1MB os-image.
-		  */
+		/* We're using a dynamic kernel/rootfs split here */
 		.partitions = {
 			{"factory-boot",    0x00000,  0x20000},
 			{"fs-uboot",        0x20000,  0x20000},
@@ -702,8 +690,8 @@ static struct device_info boards[] = {
 			{"user-config",     0x80000,  0x40000},
 
 
-			{"os-image",        0xc0000,  0x180000}, /* Stock: base 0xc0000  size 0x120000 */
-			{"file-system",     0x240000, 0xd80000}, /* Stock: base 0x1e0000 size 0xde0000 */
+			{"firmware",        0xc0000,  0xf00000},	/* Stock: name os-image base 0xc0000  size 0x120000 */
+									/* Stock: name file-system base 0x1e0000 size 0xde0000 */
 
 			{"log",             0xfc0000, 0x20000},
 			{"certificate",     0xfe0000, 0x10000},
@@ -1060,15 +1048,10 @@ static struct device_info boards[] = {
 		.support_trail = '\x00',
 		.soft_ver = NULL,
 
-		/**
-		   The flash partition table for RE355;
-		   it is almost the same as the one used by the stock images,
-		   576KB were moved from file-system to os-image.
-		*/
+		/* We're using a dynamic kernel/rootfs split here */
 		.partitions = {
 			{"fs-uboot", 0x00000, 0x20000},
-			{"os-image", 0x20000, 0x180000},
-			{"file-system", 0x1a0000, 0x460000},
+			{"firmware", 0x20000, 0x5e0000},
 			{"partition-table", 0x600000, 0x02000},
 			{"default-mac", 0x610000, 0x00020},
 			{"pin", 0x610100, 0x00020},
-- 
2.30.2