linux-mips
[Top] [All Lists]

[PATCH 2/5] MTD: bcm63xxpart: make sure CFE and NVRAM partitions are at

To: linux-mtd@lists.infradead.org
Subject: [PATCH 2/5] MTD: bcm63xxpart: make sure CFE and NVRAM partitions are at least 64K
From: Jonas Gorski <jonas.gorski@gmail.com>
Date: Sat, 17 Dec 2011 13:58:15 +0100
Cc: linux-mips@linux-mips.org, Florian Fainelli <florian@openwrt.org>, David Woodhouse <dwmw2@infradead.org>, Artem Bityutskiy <Artem.Bityutskiy@intel.com>
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=8FXy+nAo1h6TbHmJkmlG43yl7WZc92DBtFq4EYctBik=; b=cJo+2C9UF/XPnqS/M5SA0bZQmw+JL8tjdxlwdOyIotI1+UoXytjsEDbYZSj6Pjtos2 v/eswG+VmM8EUl3r5/v1mkAJ6cMnz5uAg2F8kOQly4aOiPnlgvzlF80HmnUvF7t3lHWb evBYHmmLGM8DH/JwNwHOUqVUeNqjIbRQxstGU=
In-reply-to: <1324126698-9919-1-git-send-email-jonas.gorski@gmail.com>
References: <1324126698-9919-1-git-send-email-jonas.gorski@gmail.com>
Sender: linux-mips-bounce@linux-mips.org
The CFE and NVRAM are always at least 64K big, so make sure their
partitions are never smaller than this in case the flash has smaller
erase sectors.

Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
---
 drivers/mtd/bcm63xxpart.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c
index 9933b34..23f6201 100644
--- a/drivers/mtd/bcm63xxpart.c
+++ b/drivers/mtd/bcm63xxpart.c
@@ -36,6 +36,9 @@
 
 #define BCM63XX_EXTENDED_SIZE  0xBFC00000      /* Extended flash address */
 
+#define BCM63XX_MIN_CFE_SIZE   0x10000         /* always at least 64K */
+#define BCM63XX_MIN_NVRAM_SIZE 0x10000         /* always at least 64K */
+
 #define BCM63XX_CFE_MAGIC_OFFSET 0x4e0
 
 static int bcm63xx_detect_cfe(struct mtd_info *master)
@@ -74,6 +77,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info 
*master,
        size_t retlen;
        unsigned int rootfsaddr, kerneladdr, spareaddr;
        unsigned int rootfslen, kernellen, sparelen, totallen;
+       unsigned int cfelen, nvramlen;
        int namelen = 0;
        int i;
        char *boardid;
@@ -82,14 +86,18 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info 
*master,
        if (bcm63xx_detect_cfe(master))
                return -EINVAL;
 
+       cfelen = max_t(uint32_t, master->erasesize, BCM63XX_MIN_CFE_SIZE);
+       nvramlen = max_t(uint32_t, master->erasesize, BCM63XX_MIN_NVRAM_SIZE);
+
        /* Allocate memory for buffer */
        buf = vmalloc(sizeof(struct bcm_tag));
        if (!buf)
                return -ENOMEM;
 
        /* Get the tag */
-       ret = master->read(master, master->erasesize, sizeof(struct bcm_tag),
-                                                       &retlen, (void *)buf);
+       ret = master->read(master, cfelen, sizeof(struct bcm_tag), &retlen,
+                          (void *)buf);
+
        if (retlen != sizeof(struct bcm_tag)) {
                vfree(buf);
                return -EIO;
@@ -106,8 +114,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info 
*master,
 
        kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
        rootfsaddr = kerneladdr + kernellen;
-       spareaddr = roundup(totallen, master->erasesize) + master->erasesize;
-       sparelen = master->size - spareaddr - master->erasesize;
+       spareaddr = roundup(totallen, master->erasesize) + cfelen;
+       sparelen = master->size - spareaddr - nvramlen;
        rootfslen = spareaddr - rootfsaddr;
 
        /* Determine number of partitions */
@@ -131,7 +139,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info 
*master,
        /* Start building partition list */
        parts[curpart].name = "CFE";
        parts[curpart].offset = 0;
-       parts[curpart].size = master->erasesize;
+       parts[curpart].size = cfelen;
        curpart++;
 
        if (kernellen > 0) {
@@ -151,8 +159,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info 
*master,
        }
 
        parts[curpart].name = "nvram";
-       parts[curpart].offset = master->size - master->erasesize;
-       parts[curpart].size = master->erasesize;
+       parts[curpart].offset = master->size - nvramlen;
+       parts[curpart].size = nvramlen;
 
        /* Global partition "linux" to make easy firmware upgrade */
        curpart++;
-- 
1.7.2.5


<Prev in Thread] Current Thread [Next in Thread>