Commit 678eb9bb authored by Jonas Gorski's avatar Jonas Gorski Committed by David Woodhouse

mtd: bcm63xxpart: make sure CFE and NVRAM partitions are at least 64KiB

The CFE boot loader on BCM63XX platforms assumes itself and the NVRAM
partition to be 64 KiB (or erase block sized, if larger).
Ensure this assumption is also met when creating the partitions to
prevent accidential erasure of CFE or NVRAM.
Signed-off-by: default avatarJonas Gorski <jonas.gorski@gmail.com>
Signed-off-by: default avatarArtem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent f2d9739b
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
#define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */ #define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */
#define BCM63XX_MIN_CFE_SIZE 0x10000 /* always at least 64KiB */
#define BCM63XX_MIN_NVRAM_SIZE 0x10000 /* always at least 64KiB */
#define BCM63XX_CFE_MAGIC_OFFSET 0x4e0 #define BCM63XX_CFE_MAGIC_OFFSET 0x4e0
static int bcm63xx_detect_cfe(struct mtd_info *master) static int bcm63xx_detect_cfe(struct mtd_info *master)
...@@ -74,6 +77,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -74,6 +77,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
size_t retlen; size_t retlen;
unsigned int rootfsaddr, kerneladdr, spareaddr; unsigned int rootfsaddr, kerneladdr, spareaddr;
unsigned int rootfslen, kernellen, sparelen, totallen; unsigned int rootfslen, kernellen, sparelen, totallen;
unsigned int cfelen, nvramlen;
int namelen = 0; int namelen = 0;
int i; int i;
char *boardid; char *boardid;
...@@ -82,14 +86,18 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -82,14 +86,18 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
if (bcm63xx_detect_cfe(master)) if (bcm63xx_detect_cfe(master))
return -EINVAL; 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 */ /* Allocate memory for buffer */
buf = vmalloc(sizeof(struct bcm_tag)); buf = vmalloc(sizeof(struct bcm_tag));
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
/* Get the tag */ /* Get the tag */
ret = master->read(master, master->erasesize, sizeof(struct bcm_tag), ret = master->read(master, cfelen, sizeof(struct bcm_tag), &retlen,
&retlen, (void *)buf); (void *)buf);
if (retlen != sizeof(struct bcm_tag)) { if (retlen != sizeof(struct bcm_tag)) {
vfree(buf); vfree(buf);
return -EIO; return -EIO;
...@@ -106,8 +114,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -106,8 +114,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
rootfsaddr = kerneladdr + kernellen; rootfsaddr = kerneladdr + kernellen;
spareaddr = roundup(totallen, master->erasesize) + master->erasesize; spareaddr = roundup(totallen, master->erasesize) + cfelen;
sparelen = master->size - spareaddr - master->erasesize; sparelen = master->size - spareaddr - nvramlen;
rootfslen = spareaddr - rootfsaddr; rootfslen = spareaddr - rootfsaddr;
/* Determine number of partitions */ /* Determine number of partitions */
...@@ -131,7 +139,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -131,7 +139,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
/* Start building partition list */ /* Start building partition list */
parts[curpart].name = "CFE"; parts[curpart].name = "CFE";
parts[curpart].offset = 0; parts[curpart].offset = 0;
parts[curpart].size = master->erasesize; parts[curpart].size = cfelen;
curpart++; curpart++;
if (kernellen > 0) { if (kernellen > 0) {
...@@ -151,8 +159,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -151,8 +159,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
} }
parts[curpart].name = "nvram"; parts[curpart].name = "nvram";
parts[curpart].offset = master->size - master->erasesize; parts[curpart].offset = master->size - nvramlen;
parts[curpart].size = master->erasesize; parts[curpart].size = nvramlen;
/* Global partition "linux" to make easy firmware upgrade */ /* Global partition "linux" to make easy firmware upgrade */
curpart++; curpart++;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment