All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] MTD: bcm63xxpart: handle Broadcom partition order
@ 2012-04-19 11:15 Jonas Gorski
  2012-04-19 20:44 ` Florian Fainelli
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jonas Gorski @ 2012-04-19 11:15 UTC (permalink / raw)
  To: linux-mtd; +Cc: David Woodhouse, Florian Fainelli, Artem Bityutskiy

The original Broadcom partition order has the root fs in front of the
kernel, which resulted in miscalculated partition sizes.
Detect when such an image is on the flash and also reorder the partitions
accordingly.

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---

This patch is made on top of l2-mtd.

 drivers/mtd/bcm63xxpart.c |   41 ++++++++++++++++++++++++++++++-----------
 1 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c
index 608321e..63d2a64 100644
--- a/drivers/mtd/bcm63xxpart.c
+++ b/drivers/mtd/bcm63xxpart.c
@@ -4,7 +4,7 @@
  * Copyright © 2006-2008  Florian Fainelli <florian@openwrt.org>
  *			  Mike Albon <malbon@openwrt.org>
  * Copyright © 2009-2010  Daniel Dickinson <openwrt@cshore.neomailbox.net>
- * Copyright © 2011 Jonas Gorski <jonas.gorski@gmail.com>
+ * Copyright © 2011-2012  Jonas Gorski <jonas.gorski@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -82,6 +82,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	int namelen = 0;
 	int i;
 	u32 computed_crc;
+	bool rootfs_first = false;
 
 	if (bcm63xx_detect_cfe(master))
 		return -EINVAL;
@@ -109,6 +110,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 		char *boardid = &(buf->board_id[0]);
 		char *tagversion = &(buf->tag_version[0]);
 
+		sscanf(buf->flash_image_start, "%u", &rootfsaddr);
 		sscanf(buf->kernel_address, "%u", &kerneladdr);
 		sscanf(buf->kernel_length, "%u", &kernellen);
 		sscanf(buf->total_length, "%u", &totallen);
@@ -117,10 +119,19 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 			tagversion, boardid);
 
 		kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
-		rootfsaddr = kerneladdr + kernellen;
+		rootfsaddr = rootfsaddr - BCM63XX_EXTENDED_SIZE;
 		spareaddr = roundup(totallen, master->erasesize) + cfelen;
 		sparelen = master->size - spareaddr - nvramlen;
-		rootfslen = spareaddr - rootfsaddr;
+
+		if (rootfsaddr < kerneladdr) {
+			/* default Broadcom layout */
+			rootfslen = kerneladdr - rootfsaddr;
+			rootfs_first = true;
+		} else {
+			/* OpenWrt layout */
+			rootfsaddr = kerneladdr + kernellen;
+			rootfslen = spareaddr - rootfsaddr;
+		}
 	} else {
 		pr_warn("CFE boot tag CRC invalid (expected %08x, actual %08x)\n",
 			buf->header_crc, computed_crc);
@@ -156,18 +167,26 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
 	curpart++;
 
 	if (kernellen > 0) {
-		parts[curpart].name = "kernel";
-		parts[curpart].offset = kerneladdr;
-		parts[curpart].size = kernellen;
+		int kernelpart = curpart;
+
+		if (rootfslen > 0 && rootfs_first)
+			kernelpart++;
+		parts[kernelpart].name = "kernel";
+		parts[kernelpart].offset = kerneladdr;
+		parts[kernelpart].size = kernellen;
 		curpart++;
 	}
 
 	if (rootfslen > 0) {
-		parts[curpart].name = "rootfs";
-		parts[curpart].offset = rootfsaddr;
-		parts[curpart].size = rootfslen;
-		if (sparelen > 0)
-			parts[curpart].size += sparelen;
+		int rootfspart = curpart;
+
+		if (kernellen > 0 && rootfs_first)
+			rootfspart--;
+		parts[rootfspart].name = "rootfs";
+		parts[rootfspart].offset = rootfsaddr;
+		parts[rootfspart].size = rootfslen;
+		if (sparelen > 0  && !rootfs_first)
+			parts[rootfspart].size += sparelen;
 		curpart++;
 	}
 
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] MTD: bcm63xxpart: handle Broadcom partition order
  2012-04-19 11:15 [PATCH] MTD: bcm63xxpart: handle Broadcom partition order Jonas Gorski
@ 2012-04-19 20:44 ` Florian Fainelli
  2012-04-27 12:56 ` Artem Bityutskiy
  2012-04-27 13:37 ` Artem Bityutskiy
  2 siblings, 0 replies; 5+ messages in thread
From: Florian Fainelli @ 2012-04-19 20:44 UTC (permalink / raw)
  To: Jonas Gorski; +Cc: David Woodhouse, linux-mtd, Artem Bityutskiy

On Thursday 19 April 2012 13:15:57 Jonas Gorski wrote:
> The original Broadcom partition order has the root fs in front of the
> kernel, which resulted in miscalculated partition sizes.
> Detect when such an image is on the flash and also reorder the partitions
> accordingly.
> 
> Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>

Acked-by: Florian Fainelli <florian@openwrt.org>

> ---
> 
> This patch is made on top of l2-mtd.
> 
>  drivers/mtd/bcm63xxpart.c |   41 ++++++++++++++++++++++++++++++-----------
>  1 files changed, 30 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c
> index 608321e..63d2a64 100644
> --- a/drivers/mtd/bcm63xxpart.c
> +++ b/drivers/mtd/bcm63xxpart.c
> @@ -4,7 +4,7 @@
>   * Copyright © 2006-2008  Florian Fainelli <florian@openwrt.org>
>   *			  Mike Albon <malbon@openwrt.org>
>   * Copyright © 2009-2010  Daniel Dickinson <openwrt@cshore.neomailbox.net>
> - * Copyright © 2011 Jonas Gorski <jonas.gorski@gmail.com>
> + * Copyright © 2011-2012  Jonas Gorski <jonas.gorski@gmail.com>
>   *
>   * This program is free software; you can redistribute it and/or modify
>   * it under the terms of the GNU General Public License as published by
> @@ -82,6 +82,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info
> *master, int namelen = 0;
>  	int i;
>  	u32 computed_crc;
> +	bool rootfs_first = false;
> 
>  	if (bcm63xx_detect_cfe(master))
>  		return -EINVAL;
> @@ -109,6 +110,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info
> *master, char *boardid = &(buf->board_id[0]);
>  		char *tagversion = &(buf->tag_version[0]);
> 
> +		sscanf(buf->flash_image_start, "%u", &rootfsaddr);
>  		sscanf(buf->kernel_address, "%u", &kerneladdr);
>  		sscanf(buf->kernel_length, "%u", &kernellen);
>  		sscanf(buf->total_length, "%u", &totallen);
> @@ -117,10 +119,19 @@ static int bcm63xx_parse_cfe_partitions(struct
> mtd_info *master, tagversion, boardid);
> 
>  		kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
> -		rootfsaddr = kerneladdr + kernellen;
> +		rootfsaddr = rootfsaddr - BCM63XX_EXTENDED_SIZE;
>  		spareaddr = roundup(totallen, master->erasesize) + cfelen;
>  		sparelen = master->size - spareaddr - nvramlen;
> -		rootfslen = spareaddr - rootfsaddr;
> +
> +		if (rootfsaddr < kerneladdr) {
> +			/* default Broadcom layout */
> +			rootfslen = kerneladdr - rootfsaddr;
> +			rootfs_first = true;
> +		} else {
> +			/* OpenWrt layout */
> +			rootfsaddr = kerneladdr + kernellen;
> +			rootfslen = spareaddr - rootfsaddr;
> +		}
>  	} else {
>  		pr_warn("CFE boot tag CRC invalid (expected %08x, actual %08x)\n",
>  			buf->header_crc, computed_crc);
> @@ -156,18 +167,26 @@ static int bcm63xx_parse_cfe_partitions(struct
> mtd_info *master, curpart++;
> 
>  	if (kernellen > 0) {
> -		parts[curpart].name = "kernel";
> -		parts[curpart].offset = kerneladdr;
> -		parts[curpart].size = kernellen;
> +		int kernelpart = curpart;
> +
> +		if (rootfslen > 0 && rootfs_first)
> +			kernelpart++;
> +		parts[kernelpart].name = "kernel";
> +		parts[kernelpart].offset = kerneladdr;
> +		parts[kernelpart].size = kernellen;
>  		curpart++;
>  	}
> 
>  	if (rootfslen > 0) {
> -		parts[curpart].name = "rootfs";
> -		parts[curpart].offset = rootfsaddr;
> -		parts[curpart].size = rootfslen;
> -		if (sparelen > 0)
> -			parts[curpart].size += sparelen;
> +		int rootfspart = curpart;
> +
> +		if (kernellen > 0 && rootfs_first)
> +			rootfspart--;
> +		parts[rootfspart].name = "rootfs";
> +		parts[rootfspart].offset = rootfsaddr;
> +		parts[rootfspart].size = rootfslen;
> +		if (sparelen > 0  && !rootfs_first)
> +			parts[rootfspart].size += sparelen;
>  		curpart++;
>  	}
-- 
Florian

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MTD: bcm63xxpart: handle Broadcom partition order
  2012-04-19 11:15 [PATCH] MTD: bcm63xxpart: handle Broadcom partition order Jonas Gorski
  2012-04-19 20:44 ` Florian Fainelli
@ 2012-04-27 12:56 ` Artem Bityutskiy
  2012-04-27 13:07   ` Jonas Gorski
  2012-04-27 13:37 ` Artem Bityutskiy
  2 siblings, 1 reply; 5+ messages in thread
From: Artem Bityutskiy @ 2012-04-27 12:56 UTC (permalink / raw)
  To: Jonas Gorski; +Cc: David Woodhouse, linux-mtd, Florian Fainelli

[-- Attachment #1: Type: text/plain, Size: 1965 bytes --]

On Thu, 2012-04-19 at 13:15 +0200, Jonas Gorski wrote:
> The original Broadcom partition order has the root fs in front of the
> kernel, which resulted in miscalculated partition sizes.
> Detect when such an image is on the flash and also reorder the partitions
> accordingly.
> 
> Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>

Unrilated, but would someone from bcm community take a look at this
compilation problem:

In file included from /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/gpio.h:4:0,
                 from /home/dedekind/git/l2-mtd/arch/mips/include/asm/gpio.h:4,
                 from include/linux/gpio.h:36,
                 from drivers/mtd/maps/gpio-addr-flash.c:16:
/home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h: In function 'bcm63xx_gpio_count':
/home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:10:2: error: implicit declaration of function 'bcm63xx_get_cpu_id' [-Werror=implicit-function-declaration]
/home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:11:7: error: 'BCM6358_CPU_ID' undeclared (first use in this function)
/home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:11:7: note: each undeclared identifier is reported only once for each function it appears in
/home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:13:7: error: 'BCM6338_CPU_ID' undeclared (first use in this function)
/home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:15:7: error: 'BCM6345_CPU_ID' undeclared (first use in this function)
/home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:17:7: error: 'BCM6368_CPU_ID' undeclared (first use in this function)
/home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:19:7: error: 'BCM6348_CPU_ID' undeclared (first use in this function)

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MTD: bcm63xxpart: handle Broadcom partition order
  2012-04-27 12:56 ` Artem Bityutskiy
@ 2012-04-27 13:07   ` Jonas Gorski
  0 siblings, 0 replies; 5+ messages in thread
From: Jonas Gorski @ 2012-04-27 13:07 UTC (permalink / raw)
  To: Artem Bityutskiy; +Cc: David Woodhouse, linux-mtd, Florian Fainelli

On 27 April 2012 14:56, Artem Bityutskiy <dedekind1@gmail.com> wrote:
> On Thu, 2012-04-19 at 13:15 +0200, Jonas Gorski wrote:
>> The original Broadcom partition order has the root fs in front of the
>> kernel, which resulted in miscalculated partition sizes.
>> Detect when such an image is on the flash and also reorder the partitions
>> accordingly.
>>
>> Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
>
> Unrilated, but would someone from bcm community take a look at this
> compilation problem:
>
> In file included from /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/gpio.h:4:0,
>                 from /home/dedekind/git/l2-mtd/arch/mips/include/asm/gpio.h:4,
>                 from include/linux/gpio.h:36,
>                 from drivers/mtd/maps/gpio-addr-flash.c:16:
> /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h: In function 'bcm63xx_gpio_count':
> /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:10:2: error: implicit declaration of function 'bcm63xx_get_cpu_id' [-Werror=implicit-function-declaration]
> /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:11:7: error: 'BCM6358_CPU_ID' undeclared (first use in this function)
> /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:11:7: note: each undeclared identifier is reported only once for each function it appears in
> /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:13:7: error: 'BCM6338_CPU_ID' undeclared (first use in this function)
> /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:15:7: error: 'BCM6345_CPU_ID' undeclared (first use in this function)
> /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:17:7: error: 'BCM6368_CPU_ID' undeclared (first use in this function)
> /home/dedekind/git/l2-mtd/arch/mips/include/asm/mach-bcm63xx/bcm63xx_gpio.h:19:7: error: 'BCM6348_CPU_ID' undeclared (first use in this function)

There's already a patch for that waiting to be applied:

http://patchwork.linux-mips.org/patch/3351/

Regards
Jonas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MTD: bcm63xxpart: handle Broadcom partition order
  2012-04-19 11:15 [PATCH] MTD: bcm63xxpart: handle Broadcom partition order Jonas Gorski
  2012-04-19 20:44 ` Florian Fainelli
  2012-04-27 12:56 ` Artem Bityutskiy
@ 2012-04-27 13:37 ` Artem Bityutskiy
  2 siblings, 0 replies; 5+ messages in thread
From: Artem Bityutskiy @ 2012-04-27 13:37 UTC (permalink / raw)
  To: Jonas Gorski; +Cc: David Woodhouse, linux-mtd, Florian Fainelli

[-- Attachment #1: Type: text/plain, Size: 415 bytes --]

On Thu, 2012-04-19 at 13:15 +0200, Jonas Gorski wrote:
> The original Broadcom partition order has the root fs in front of the
> kernel, which resulted in miscalculated partition sizes.
> Detect when such an image is on the flash and also reorder the partitions
> accordingly.
> 
> Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>

Pushed to l2-mtd.git, thanks!

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-04-27 13:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-19 11:15 [PATCH] MTD: bcm63xxpart: handle Broadcom partition order Jonas Gorski
2012-04-19 20:44 ` Florian Fainelli
2012-04-27 12:56 ` Artem Bityutskiy
2012-04-27 13:07   ` Jonas Gorski
2012-04-27 13:37 ` Artem Bityutskiy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.