Bläddra i källkod

firmware-utils: mkfwimage: fix firmware_max_length for XM layout

This should fix problems with flashing from AirOS 5.6.x.
Matthias Schiffer 8 år sedan
förälder
incheckning
59ab532be7

+ 64 - 0
patches/openwrt/0052-firmware-utils-mkfwimage-add-Wall-fix-obvious-bugs-causing-compile-warnings.patch

@@ -0,0 +1,64 @@
+From: Matthias Schiffer <mschiffer@universe-factory.net>
+Date: Thu, 25 Feb 2016 21:39:03 +0100
+Subject: firmware-utils: mkfwimage: add -Wall, fix obvious bugs causing compile warnings
+
+Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
+
+diff --git a/tools/firmware-utils/Makefile b/tools/firmware-utils/Makefile
+index bd69cb4..6d88845 100644
+--- a/tools/firmware-utils/Makefile
++++ b/tools/firmware-utils/Makefile
+@@ -32,7 +32,7 @@ define Host/Compile
+ 	$(call cc,mkzynfw)
+ 	$(call cc,lzma2eva,-lz)
+ 	$(call cc,mkcasfw)
+-	$(call cc,mkfwimage,-lz)
++	$(call cc,mkfwimage,-lz -Wall)
+ 	$(call cc,mkfwimage2,-lz)
+ 	$(call cc,imagetag imagetag_cmdline cyg_crc32)
+ 	$(call cc,add_header)
+diff --git a/tools/firmware-utils/src/mkfwimage.c b/tools/firmware-utils/src/mkfwimage.c
+index e3a03c1..00bf439 100644
+--- a/tools/firmware-utils/src/mkfwimage.c
++++ b/tools/firmware-utils/src/mkfwimage.c
+@@ -104,8 +104,6 @@ typedef struct part_data {
+ 
+ #define OPTIONS "B:hv:m:o:r:k:"
+ 
+-static int debug = 0;
+-
+ typedef struct image_info {
+ 	char magic[16];
+ 	char version[256];
+@@ -236,9 +234,9 @@ static int create_image_layout(const char* kernelfile, const char* rootfsfile, c
+ 	fw_layout_t* p;
+ 
+ 	p = &fw_layout_data[0];
+-	while ((strlen(p->name) != 0) && (strncmp(p->name, board_name, sizeof(board_name)) != 0))
++	while (*p->name && (strcmp(p->name, board_name) != 0))
+ 		p++;
+-	if (p->name == NULL) {
++	if (!*p->name) {
+ 		printf("BUG! Unable to find default fw layout!\n");
+ 		exit(-1);
+ 	}
+@@ -247,7 +245,7 @@ static int create_image_layout(const char* kernelfile, const char* rootfsfile, c
+ 	strcpy(kernel->partition_name, "kernel");
+ 	kernel->partition_index = 1;
+ 	kernel->partition_baseaddr = p->kern_start;
+-	if ( (kernel->partition_length = filelength(kernelfile)) < 0) return (-1);
++	if ( (kernel->partition_length = filelength(kernelfile)) == (u_int32_t)-1) return (-1);
+ 	kernel->partition_memaddr = p->kern_entry;
+ 	kernel->partition_entryaddr = p->kern_entry;
+ 	strncpy(kernel->filename, kernelfile, sizeof(kernel->filename));
+@@ -263,8 +261,8 @@ static int create_image_layout(const char* kernelfile, const char* rootfsfile, c
+ 	rootfs->partition_entryaddr = 0x00000000;
+ 	strncpy(rootfs->filename, rootfsfile, sizeof(rootfs->filename));
+ 
+-printf("kernel: %d 0x%08x\n", kernel->partition_length, kernel->partition_baseaddr);
+-printf("root: %d 0x%08x\n", rootfs->partition_length, rootfs->partition_baseaddr);
++	printf("kernel: %d 0x%08x\n", kernel->partition_length, kernel->partition_baseaddr);
++	printf("root: %d 0x%08x\n", rootfs->partition_length, rootfs->partition_baseaddr);
+ 	im->part_count = 2;
+ 
+ 	return 0;

+ 39 - 0
patches/openwrt/0053-ar71xx-firmware-utils-split-ubdev01-flash-layout-from-XM.patch

@@ -0,0 +1,39 @@
+From: Matthias Schiffer <mschiffer@universe-factory.net>
+Date: Thu, 25 Feb 2016 21:40:19 +0100
+Subject: ar71xx, firmware-utils: split ubdev01 flash layout from XM
+
+The ubdev01 profile defines its own MTDPARTS with smaller firmware
+partition, so give it its own UBNT_BOARD in mkfwimage.
+
+Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
+
+diff --git a/target/linux/ar71xx/image/Makefile b/target/linux/ar71xx/image/Makefile
+index 4b29d9c..0806f15 100644
+--- a/target/linux/ar71xx/image/Makefile
++++ b/target/linux/ar71xx/image/Makefile
+@@ -2031,7 +2031,7 @@ $(eval $(call SingleProfile,TPLINK-SAFELOADER,64kraw,CPE510,cpe210-220-510-520,C
+ $(eval $(call SingleProfile,UAPPRO,64k,UAPPRO,ubnt-uap-pro,UAP-PRO,ttyS0,115200,BZ,BZ,ar934x))
+ $(eval $(call SingleProfile,UAPPRO,64k,UBNTUNIFIOUTDOORPLUS,ubnt-unifi-outdoor-plus,UBNT-UOP,ttyS0,115200,BZ,BZ,ar7240))
+ 
+-$(eval $(call SingleProfile,UBDEV,64kraw,UBDEV01,ubdev01,UBNT-UF,ttyS0,115200,XM,XM,ar7240))
++$(eval $(call SingleProfile,UBDEV,64kraw,UBDEV01,ubdev01,UBNT-UF,ttyS0,115200,UBDEV01,XM,ar7240))
+ 
+ $(eval $(call SingleProfile,UBNT,64k,UBNTRS,ubnt-rs,UBNT-RS,ttyS0,115200,RS,RSx,ar7100))
+ $(eval $(call SingleProfile,UBNT,64k,UBNTRSPRO,ubnt-rspro,UBNT-RSPRO,ttyS0,115200,RSPRO,RSPRO,ar7100pro))
+diff --git a/tools/firmware-utils/src/mkfwimage.c b/tools/firmware-utils/src/mkfwimage.c
+index 00bf439..5dae284 100644
+--- a/tools/firmware-utils/src/mkfwimage.c
++++ b/tools/firmware-utils/src/mkfwimage.c
+@@ -81,6 +81,12 @@ fw_layout_t fw_layout_data[] = {
+ 		.kern_entry	=	0x80002000,
+ 		.firmware_max_length=	0x006A0000,
+ 	},
++	{
++		.name		=	"UBDEV01",
++		.kern_start	=	0x9f050000,
++		.kern_entry	=	0x80002000,
++		.firmware_max_length=	0x006A0000,
++	},
+ 	{	.name		=	"",
+ 	},
+ };

+ 45 - 0
patches/openwrt/0054-firmware-utils-mkfwimage-fix-firmware_max_length-for-XM-layout.patch

@@ -0,0 +1,45 @@
+From: Matthias Schiffer <mschiffer@universe-factory.net>
+Date: Thu, 25 Feb 2016 21:42:14 +0100
+Subject: firmware-utils: mkfwimage: fix firmware_max_length for XM layout
+
+The new u-boot version bundled with the 5.6.x firmwares from Ubiquiti gets
+confused by the smaller rootfs partition size; this can lead to various
+issues:
+
+1. We've gotten reports that flashing from the 5.6.x stock firmware to
+   OpenWrt will brick devices; I wasn't able to reproduce this myself
+2. Flashing from 5.5.x stock firmware to OpenWrt and back to stock (via
+   TFTP recovery), following by an update to 5.6.x via web interface can
+   yield a bricked device with the following properties:
+   - It can't be booted without entering commands over a serial console, as
+     u-boot supplies the wrong MTD layout
+   - The web interface won't accept any image with the original flash
+     layout, so stock firmware upgrades are impossible
+   - As the TFTP recovery doesn't update u-boot, returning to the old
+     u-boot from firmware 5.5.x is impossible
+
+To recover from 2., creating an OpenWrt image which doesn't set u-boot as
+read-only and flashing a backup of the old u-boot from there is the only
+way known to me. (Fixing the mtdparts variable in u-boot-env from OpenWrt
+might also work; settings this from u-boot over serial didn't have
+any permanent effect.)
+
+Fix all of this by setting the correct flash layout also used by the stock
+firmware. Flashing has been tested from both firmware 5.5.x and 5.6.x. The
+fixed layout also matches the mtdparts defined by OpenWrt.
+
+Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
+
+diff --git a/tools/firmware-utils/src/mkfwimage.c b/tools/firmware-utils/src/mkfwimage.c
+index 5dae284..d8d5239 100644
+--- a/tools/firmware-utils/src/mkfwimage.c
++++ b/tools/firmware-utils/src/mkfwimage.c
+@@ -79,7 +79,7 @@ fw_layout_t fw_layout_data[] = {
+ 		.name		=	"XM",
+ 		.kern_start	=	0x9f050000,
+ 		.kern_entry	=	0x80002000,
+-		.firmware_max_length=	0x006A0000,
++		.firmware_max_length=	0x00760000,
+ 	},
+ 	{
+ 		.name		=	"UBDEV01",