--- a/drivers/mtd/bcm63xxpart.c
+++ b/drivers/mtd/bcm63xxpart.c
-@@ -32,6 +32,7 @@
+@@ -33,6 +33,7 @@
#include <linux/vmalloc.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
+#include <linux/of.h>
#include <asm/mach-bcm63xx/bcm63xx_nvram.h>
- #include <asm/mach-bcm63xx/bcm963xx_tag.h>
-@@ -43,46 +44,35 @@
+ #include <asm/mach-bcm63xx/bcm63xx_board.h>
+@@ -41,46 +42,35 @@
#define BCM63XX_CFE_MAGIC_OFFSET 0x4e0
}
computed_crc = crc32_le(IMAGETAG_CRC_START, (u8 *)buf,
-@@ -101,7 +91,6 @@ static int bcm63xx_parse_cfe_partitions(
+@@ -99,7 +89,6 @@ static int bcm63xx_parse_cfe_partitions(
- kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
- rootfsaddr = rootfsaddr - BCM63XX_EXTENDED_SIZE;
+ kerneladdr = kerneladdr - BCM963XX_EXTENDED_SIZE;
+ rootfsaddr = rootfsaddr - BCM963XX_EXTENDED_SIZE;
- spareaddr = roundup(totallen, master->erasesize) + cfelen;
if (rootfsaddr < kerneladdr) {
/* default Broadcom layout */
-@@ -110,8 +99,8 @@ static int bcm63xx_parse_cfe_partitions(
+@@ -108,8 +97,8 @@ static int bcm63xx_parse_cfe_partitions(
} else {
/* OpenWrt layout */
rootfsaddr = kerneladdr + kernellen;
}
} else {
pr_warn("CFE boot tag CRC invalid (expected %08x, actual %08x)\n",
-@@ -119,23 +108,139 @@ static int bcm63xx_parse_cfe_partitions(
+@@ -117,23 +106,139 @@ static int bcm63xx_parse_cfe_partitions(
kernellen = 0;
rootfslen = 0;
rootfsaddr = 0;
/* Start building partition list */
parts[curpart].name = "CFE";
-@@ -143,29 +248,7 @@ static int bcm63xx_parse_cfe_partitions(
+@@ -141,29 +246,7 @@ static int bcm63xx_parse_cfe_partitions(
parts[curpart].size = cfelen;
curpart++;
parts[curpart].name = "nvram";
parts[curpart].offset = master->size - nvramlen;
-@@ -174,25 +257,33 @@ static int bcm63xx_parse_cfe_partitions(
+@@ -172,25 +255,33 @@ static int bcm63xx_parse_cfe_partitions(
/* Global partition "linux" to make easy firmware upgrade */
parts[curpart].name = "linux";
--- /dev/null
+From 8fce60b8d0c62363c29d64efb0cceb98519f0350 Mon Sep 17 00:00:00 2001
+From: Simon Arlott <simon@fire.lp0.eu>
+Date: Sun, 13 Dec 2015 22:46:59 +0000
+Subject: [PATCH] MIPS: bcm963xx: Move Broadcom BCM963xx image tag data
+ structure
+
+Move Broadcom BCM963xx image tag data structure to include/linux/
+so that drivers outside of mach-bcm63xx can use it.
+
+Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
+Cc: David Woodhouse <dwmw2@infradead.org>
+Cc: Brian Norris <computersforpeace@gmail.com>
+Cc: Kevin Cernekee <cernekee@gmail.com>
+Cc: Florian Fainelli <f.fainelli@gmail.com>
+Cc: Jonas Gorski <jogo@openwrt.org>
+Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
+Cc: MIPS Mailing List <linux-mips@linux-mips.org>
+Cc: MTD Maling List <linux-mtd@lists.infradead.org>
+Patchwork: https://patchwork.linux-mips.org/patch/11832/
+Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
+---
+ arch/mips/include/asm/mach-bcm63xx/bcm963xx_tag.h | 96 ----------------------
+ drivers/mtd/bcm63xxpart.c | 2 +-
+ include/linux/bcm963xx_tag.h | 98 +++++++++++++++++++++++
+ 4 files changed, 100 insertions(+), 97 deletions(-)
+ delete mode 100644 arch/mips/include/asm/mach-bcm63xx/bcm963xx_tag.h
+ create mode 100644 include/linux/bcm963xx_tag.h
+
+--- a/arch/mips/include/asm/mach-bcm63xx/bcm963xx_tag.h
++++ /dev/null
+@@ -1,96 +0,0 @@
+-#ifndef __BCM963XX_TAG_H
+-#define __BCM963XX_TAG_H
+-
+-#define TAGVER_LEN 4 /* Length of Tag Version */
+-#define TAGLAYOUT_LEN 4 /* Length of FlashLayoutVer */
+-#define SIG1_LEN 20 /* Company Signature 1 Length */
+-#define SIG2_LEN 14 /* Company Signature 2 Length */
+-#define BOARDID_LEN 16 /* Length of BoardId */
+-#define ENDIANFLAG_LEN 2 /* Endian Flag Length */
+-#define CHIPID_LEN 6 /* Chip Id Length */
+-#define IMAGE_LEN 10 /* Length of Length Field */
+-#define ADDRESS_LEN 12 /* Length of Address field */
+-#define DUALFLAG_LEN 2 /* Dual Image flag Length */
+-#define INACTIVEFLAG_LEN 2 /* Inactie Flag Length */
+-#define RSASIG_LEN 20 /* Length of RSA Signature in tag */
+-#define TAGINFO1_LEN 30 /* Length of vendor information field1 in tag */
+-#define FLASHLAYOUTVER_LEN 4 /* Length of Flash Layout Version String tag */
+-#define TAGINFO2_LEN 16 /* Length of vendor information field2 in tag */
+-#define ALTTAGINFO_LEN 54 /* Alternate length for vendor information; Pirelli */
+-
+-#define NUM_PIRELLI 2
+-#define IMAGETAG_CRC_START 0xFFFFFFFF
+-
+-#define PIRELLI_BOARDS { \
+- "AGPF-S0", \
+- "DWV-S0", \
+-}
+-
+-/*
+- * The broadcom firmware assumes the rootfs starts the image,
+- * therefore uses the rootfs start (flash_image_address)
+- * to determine where to flash the image. Since we have the kernel first
+- * we have to give it the kernel address, but the crc uses the length
+- * associated with this address (root_length), which is added to the kernel
+- * length (kernel_length) to determine the length of image to flash and thus
+- * needs to be rootfs + deadcode (jffs2 EOF marker)
+-*/
+-
+-struct bcm_tag {
+- /* 0-3: Version of the image tag */
+- char tag_version[TAGVER_LEN];
+- /* 4-23: Company Line 1 */
+- char sig_1[SIG1_LEN];
+- /* 24-37: Company Line 2 */
+- char sig_2[SIG2_LEN];
+- /* 38-43: Chip this image is for */
+- char chip_id[CHIPID_LEN];
+- /* 44-59: Board name */
+- char board_id[BOARDID_LEN];
+- /* 60-61: Map endianness -- 1 BE 0 LE */
+- char big_endian[ENDIANFLAG_LEN];
+- /* 62-71: Total length of image */
+- char total_length[IMAGE_LEN];
+- /* 72-83: Address in memory of CFE */
+- char cfe__address[ADDRESS_LEN];
+- /* 84-93: Size of CFE */
+- char cfe_length[IMAGE_LEN];
+- /* 94-105: Address in memory of image start
+- * (kernel for OpenWRT, rootfs for stock firmware)
+- */
+- char flash_image_start[ADDRESS_LEN];
+- /* 106-115: Size of rootfs */
+- char root_length[IMAGE_LEN];
+- /* 116-127: Address in memory of kernel */
+- char kernel_address[ADDRESS_LEN];
+- /* 128-137: Size of kernel */
+- char kernel_length[IMAGE_LEN];
+- /* 138-139: Unused at the moment */
+- char dual_image[DUALFLAG_LEN];
+- /* 140-141: Unused at the moment */
+- char inactive_flag[INACTIVEFLAG_LEN];
+- /* 142-161: RSA Signature (not used; some vendors may use this) */
+- char rsa_signature[RSASIG_LEN];
+- /* 162-191: Compilation and related information (not used in OpenWrt) */
+- char information1[TAGINFO1_LEN];
+- /* 192-195: Version flash layout */
+- char flash_layout_ver[FLASHLAYOUTVER_LEN];
+- /* 196-199: kernel+rootfs CRC32 */
+- __u32 fskernel_crc;
+- /* 200-215: Unused except on Alice Gate where is is information */
+- char information2[TAGINFO2_LEN];
+- /* 216-219: CRC32 of image less imagetag (kernel for Alice Gate) */
+- __u32 image_crc;
+- /* 220-223: CRC32 of rootfs partition */
+- __u32 rootfs_crc;
+- /* 224-227: CRC32 of kernel partition */
+- __u32 kernel_crc;
+- /* 228-235: Unused at present */
+- char reserved1[8];
+- /* 236-239: CRC32 of header excluding last 20 bytes */
+- __u32 header_crc;
+- /* 240-255: Unused at present */
+- char reserved2[16];
+-};
+-
+-#endif /* __BCM63XX_TAG_H */
+--- a/drivers/mtd/bcm63xxpart.c
++++ b/drivers/mtd/bcm63xxpart.c
+@@ -24,6 +24,7 @@
+
+ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
++#include <linux/bcm963xx_tag.h>
+ #include <linux/crc32.h>
+ #include <linux/module.h>
+ #include <linux/kernel.h>
+@@ -34,7 +35,6 @@
+ #include <linux/mtd/partitions.h>
+
+ #include <asm/mach-bcm63xx/bcm63xx_nvram.h>
+-#include <asm/mach-bcm63xx/bcm963xx_tag.h>
+ #include <asm/mach-bcm63xx/board_bcm963xx.h>
+
+ #define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */
+--- /dev/null
++++ b/include/linux/bcm963xx_tag.h
+@@ -0,0 +1,98 @@
++#ifndef __LINUX_BCM963XX_TAG_H__
++#define __LINUX_BCM963XX_TAG_H__
++
++#include <linux/types.h>
++
++#define TAGVER_LEN 4 /* Length of Tag Version */
++#define TAGLAYOUT_LEN 4 /* Length of FlashLayoutVer */
++#define SIG1_LEN 20 /* Company Signature 1 Length */
++#define SIG2_LEN 14 /* Company Signature 2 Length */
++#define BOARDID_LEN 16 /* Length of BoardId */
++#define ENDIANFLAG_LEN 2 /* Endian Flag Length */
++#define CHIPID_LEN 6 /* Chip Id Length */
++#define IMAGE_LEN 10 /* Length of Length Field */
++#define ADDRESS_LEN 12 /* Length of Address field */
++#define DUALFLAG_LEN 2 /* Dual Image flag Length */
++#define INACTIVEFLAG_LEN 2 /* Inactie Flag Length */
++#define RSASIG_LEN 20 /* Length of RSA Signature in tag */
++#define TAGINFO1_LEN 30 /* Length of vendor information field1 in tag */
++#define FLASHLAYOUTVER_LEN 4 /* Length of Flash Layout Version String tag */
++#define TAGINFO2_LEN 16 /* Length of vendor information field2 in tag */
++#define ALTTAGINFO_LEN 54 /* Alternate length for vendor information; Pirelli */
++
++#define NUM_PIRELLI 2
++#define IMAGETAG_CRC_START 0xFFFFFFFF
++
++#define PIRELLI_BOARDS { \
++ "AGPF-S0", \
++ "DWV-S0", \
++}
++
++/*
++ * The broadcom firmware assumes the rootfs starts the image,
++ * therefore uses the rootfs start (flash_image_address)
++ * to determine where to flash the image. Since we have the kernel first
++ * we have to give it the kernel address, but the crc uses the length
++ * associated with this address (root_length), which is added to the kernel
++ * length (kernel_length) to determine the length of image to flash and thus
++ * needs to be rootfs + deadcode (jffs2 EOF marker)
++*/
++
++struct bcm_tag {
++ /* 0-3: Version of the image tag */
++ char tag_version[TAGVER_LEN];
++ /* 4-23: Company Line 1 */
++ char sig_1[SIG1_LEN];
++ /* 24-37: Company Line 2 */
++ char sig_2[SIG2_LEN];
++ /* 38-43: Chip this image is for */
++ char chip_id[CHIPID_LEN];
++ /* 44-59: Board name */
++ char board_id[BOARDID_LEN];
++ /* 60-61: Map endianness -- 1 BE 0 LE */
++ char big_endian[ENDIANFLAG_LEN];
++ /* 62-71: Total length of image */
++ char total_length[IMAGE_LEN];
++ /* 72-83: Address in memory of CFE */
++ char cfe__address[ADDRESS_LEN];
++ /* 84-93: Size of CFE */
++ char cfe_length[IMAGE_LEN];
++ /* 94-105: Address in memory of image start
++ * (kernel for OpenWRT, rootfs for stock firmware)
++ */
++ char flash_image_start[ADDRESS_LEN];
++ /* 106-115: Size of rootfs */
++ char root_length[IMAGE_LEN];
++ /* 116-127: Address in memory of kernel */
++ char kernel_address[ADDRESS_LEN];
++ /* 128-137: Size of kernel */
++ char kernel_length[IMAGE_LEN];
++ /* 138-139: Unused at the moment */
++ char dual_image[DUALFLAG_LEN];
++ /* 140-141: Unused at the moment */
++ char inactive_flag[INACTIVEFLAG_LEN];
++ /* 142-161: RSA Signature (not used; some vendors may use this) */
++ char rsa_signature[RSASIG_LEN];
++ /* 162-191: Compilation and related information (not used in OpenWrt) */
++ char information1[TAGINFO1_LEN];
++ /* 192-195: Version flash layout */
++ char flash_layout_ver[FLASHLAYOUTVER_LEN];
++ /* 196-199: kernel+rootfs CRC32 */
++ __u32 fskernel_crc;
++ /* 200-215: Unused except on Alice Gate where is is information */
++ char information2[TAGINFO2_LEN];
++ /* 216-219: CRC32 of image less imagetag (kernel for Alice Gate) */
++ __u32 image_crc;
++ /* 220-223: CRC32 of rootfs partition */
++ __u32 rootfs_crc;
++ /* 224-227: CRC32 of kernel partition */
++ __u32 kernel_crc;
++ /* 228-235: Unused at present */
++ char reserved1[8];
++ /* 236-239: CRC32 of header excluding last 20 bytes */
++ __u32 header_crc;
++ /* 240-255: Unused at present */
++ char reserved2[16];
++};
++
++#endif /* __LINUX_BCM63XX_TAG_H__ */
--- /dev/null
+From 1f29cb19cb7c3bea870d7da02ec23823af9d636e Mon Sep 17 00:00:00 2001
+From: Simon Arlott <simon@fire.lp0.eu>
+Date: Sun, 13 Dec 2015 22:47:55 +0000
+Subject: [PATCH] MIPS: bcm963xx: Move extended flash address to bcm_tag header
+ file
+
+The extended flash address needs to be subtracted from bcm_tag flash
+image offsets. Move this value to the bcm_tag header file.
+
+Renamed define name to consistently use bcm963xx for flash layout
+which should be considered a property of the board and not the SoC
+(i.e. bcm63xx could theoretically be used on a board without CFE
+or any flash).
+
+Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
+Cc: David Woodhouse <dwmw2@infradead.org>
+Cc: Brian Norris <computersforpeace@gmail.com>
+Cc: Kevin Cernekee <cernekee@gmail.com>
+Cc: Florian Fainelli <f.fainelli@gmail.com>
+Cc: Jonas Gorski <jogo@openwrt.org>
+Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
+Cc: MIPS Mailing List <linux-mips@linux-mips.org>
+Cc: MTD Maling List <linux-mtd@lists.infradead.org>
+Patchwork: https://patchwork.linux-mips.org/patch/11833/
+Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
+---
+ drivers/mtd/bcm63xxpart.c | 6 ++----
+ include/linux/bcm963xx_tag.h | 5 +++++
+ 2 files changed, 7 insertions(+), 4 deletions(-)
+
+--- a/drivers/mtd/bcm63xxpart.c
++++ b/drivers/mtd/bcm63xxpart.c
+@@ -37,8 +37,6 @@
+ #include <asm/mach-bcm63xx/bcm63xx_nvram.h>
+ #include <asm/mach-bcm63xx/board_bcm963xx.h>
+
+-#define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */
+-
+ #define BCM63XX_CFE_BLOCK_SIZE SZ_64K /* always at least 64KiB */
+
+ #define BCM63XX_CFE_MAGIC_OFFSET 0x4e0
+@@ -123,8 +121,8 @@ static int bcm63xx_parse_cfe_partitions(
+ pr_info("CFE boot tag found with version %s and board type %s\n",
+ tagversion, boardid);
+
+- kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
+- rootfsaddr = rootfsaddr - BCM63XX_EXTENDED_SIZE;
++ kerneladdr = kerneladdr - BCM963XX_EXTENDED_SIZE;
++ rootfsaddr = rootfsaddr - BCM963XX_EXTENDED_SIZE;
+ spareaddr = roundup(totallen, master->erasesize) + cfelen;
+
+ if (rootfsaddr < kerneladdr) {
+--- a/include/linux/bcm963xx_tag.h
++++ b/include/linux/bcm963xx_tag.h
+@@ -28,6 +28,11 @@
+ "DWV-S0", \
+ }
+
++/* Extended flash address, needs to be subtracted
++ * from bcm_tag flash image offsets.
++ */
++#define BCM963XX_EXTENDED_SIZE 0xBFC00000
++
+ /*
+ * The broadcom firmware assumes the rootfs starts the image,
+ * therefore uses the rootfs start (flash_image_address)
--- /dev/null
+From 696569f759cdebc7da67666fc4f962eaee13562b Mon Sep 17 00:00:00 2001
+From: Simon Arlott <simon@fire.lp0.eu>
+Date: Sun, 13 Dec 2015 22:48:44 +0000
+Subject: [PATCH] MIPS: bcm963xx: Update bcm_tag field image_sequence
+
+The "dual_image" and "inactive_flag" fields should be merged into a single
+"image_sequence" field.
+
+Signed-off-by: Simon Arlott <simon@fire.lp0.eu>
+Cc: David Woodhouse <dwmw2@infradead.org>
+Cc: Brian Norris <computersforpeace@gmail.com>
+Cc: Kevin Cernekee <cernekee@gmail.com>
+Cc: Florian Fainelli <f.fainelli@gmail.com>
+Cc: Jonas Gorski <jogo@openwrt.org>
+Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
+Cc: MIPS Mailing List <linux-mips@linux-mips.org>
+Cc: MTD Maling List <linux-mtd@lists.infradead.org>
+Patchwork: https://patchwork.linux-mips.org/patch/11834/
+Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
+---
+ include/linux/bcm963xx_tag.h | 11 +++++------
+ 1 file changed, 5 insertions(+), 6 deletions(-)
+
+--- a/include/linux/bcm963xx_tag.h
++++ b/include/linux/bcm963xx_tag.h
+@@ -12,8 +12,7 @@
+ #define CHIPID_LEN 6 /* Chip Id Length */
+ #define IMAGE_LEN 10 /* Length of Length Field */
+ #define ADDRESS_LEN 12 /* Length of Address field */
+-#define DUALFLAG_LEN 2 /* Dual Image flag Length */
+-#define INACTIVEFLAG_LEN 2 /* Inactie Flag Length */
++#define IMAGE_SEQUENCE_LEN 4 /* Image sequence Length */
+ #define RSASIG_LEN 20 /* Length of RSA Signature in tag */
+ #define TAGINFO1_LEN 30 /* Length of vendor information field1 in tag */
+ #define FLASHLAYOUTVER_LEN 4 /* Length of Flash Layout Version String tag */
+@@ -72,10 +71,10 @@ struct bcm_tag {
+ char kernel_address[ADDRESS_LEN];
+ /* 128-137: Size of kernel */
+ char kernel_length[IMAGE_LEN];
+- /* 138-139: Unused at the moment */
+- char dual_image[DUALFLAG_LEN];
+- /* 140-141: Unused at the moment */
+- char inactive_flag[INACTIVEFLAG_LEN];
++ /* 138-141: Image sequence number
++ * (to be incremented when flashed with a new image)
++ */
++ char image_sequence[IMAGE_SEQUENCE_LEN];
+ /* 142-161: RSA Signature (not used; some vendors may use this) */
+ char rsa_signature[RSASIG_LEN];
+ /* 162-191: Compilation and related information (not used in OpenWrt) */