Commit 4110fdd2 authored by Simon Arlott's avatar Simon Arlott Committed by Brian Norris

mtd: bcm63xxpart: Move NOR flash layout to a separate function

Move the NOR flash layout to a separate function to allow the NAND flash
layout to be supported.
Signed-off-by: default avatarSimon Arlott <simon@fire.lp0.eu>
Signed-off-by: default avatarBrian Norris <computersforpeace@gmail.com>
parent 2c4fd433
...@@ -124,13 +124,11 @@ static int bcm63xx_read_image_tag(struct mtd_info *master, const char *name, ...@@ -124,13 +124,11 @@ static int bcm63xx_read_image_tag(struct mtd_info *master, const char *name,
return 1; return 1;
} }
static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, static int bcm63xx_parse_cfe_nor_partitions(struct mtd_info *master,
const struct mtd_partition **pparts, const struct mtd_partition **pparts, struct bcm963xx_nvram *nvram)
struct mtd_part_parser_data *data)
{ {
/* CFE, NVRAM and global Linux are always present */ /* CFE, NVRAM and global Linux are always present */
int nrparts = 3, curpart = 0; int nrparts = 3, curpart = 0;
struct bcm963xx_nvram *nvram = NULL;
struct bcm_tag *buf = NULL; struct bcm_tag *buf = NULL;
struct mtd_partition *parts; struct mtd_partition *parts;
int ret; int ret;
...@@ -141,17 +139,6 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -141,17 +139,6 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
int i; int i;
bool rootfs_first = false; bool rootfs_first = false;
if (bcm63xx_detect_cfe(master))
return -EINVAL;
nvram = vzalloc(sizeof(*nvram));
if (!nvram)
return -ENOMEM;
ret = bcm63xx_read_nvram(master, nvram);
if (ret)
goto out;
cfe_erasesize = max_t(uint32_t, master->erasesize, cfe_erasesize = max_t(uint32_t, master->erasesize,
BCM963XX_CFE_BLOCK_SIZE); BCM963XX_CFE_BLOCK_SIZE);
...@@ -159,12 +146,9 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -159,12 +146,9 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
nvramlen = nvram->psi_size * SZ_1K; nvramlen = nvram->psi_size * SZ_1K;
nvramlen = roundup(nvramlen, cfe_erasesize); nvramlen = roundup(nvramlen, cfe_erasesize);
/* Allocate memory for buffer */
buf = vmalloc(sizeof(struct bcm_tag)); buf = vmalloc(sizeof(struct bcm_tag));
if (!buf) { if (!buf)
ret = -ENOMEM; return -ENOMEM;
goto out;
}
/* Get the tag */ /* Get the tag */
ret = bcm63xx_read_image_tag(master, "rootfs", cfelen, buf); ret = bcm63xx_read_image_tag(master, "rootfs", cfelen, buf);
...@@ -234,7 +218,6 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -234,7 +218,6 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
if (kernellen > 0) if (kernellen > 0)
nrparts++; nrparts++;
/* Ask kernel for more memory */
parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL); parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL);
if (!parts) { if (!parts) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -292,13 +275,40 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -292,13 +275,40 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
ret = 0; ret = 0;
out: out:
vfree(nvram);
vfree(buf); vfree(buf);
if (ret) if (ret)
return ret; return ret;
return nrparts; return nrparts;
}
static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
const struct mtd_partition **pparts,
struct mtd_part_parser_data *data)
{
struct bcm963xx_nvram *nvram = NULL;
int ret;
if (bcm63xx_detect_cfe(master))
return -EINVAL;
nvram = vzalloc(sizeof(*nvram));
if (!nvram)
return -ENOMEM;
ret = bcm63xx_read_nvram(master, nvram);
if (ret)
goto out;
if (!mtd_type_is_nand(master))
ret = bcm63xx_parse_cfe_nor_partitions(master, pparts, nvram);
else
ret = -EINVAL;
out:
vfree(nvram);
return ret;
}; };
static struct mtd_part_parser bcm63xx_cfe_parser = { static struct mtd_part_parser bcm63xx_cfe_parser = {
......
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