Commit f98872fc authored by Jonas Gorski's avatar Jonas Gorski Committed by David Woodhouse

mtd: bcm63xxpart: check the image tag's crc32

Only use the values from the image tag if it is valid. Always create
the CFE, NVRAM and linux partitions, to allow flashing a new image even
if the old is invalid without overwriting 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 80516678
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/crc32.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -80,8 +81,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -80,8 +81,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
unsigned int cfelen, nvramlen; unsigned int cfelen, nvramlen;
int namelen = 0; int namelen = 0;
int i; int i;
char *boardid; u32 computed_crc;
char *tagversion;
if (bcm63xx_detect_cfe(master)) if (bcm63xx_detect_cfe(master))
return -EINVAL; return -EINVAL;
...@@ -103,20 +103,33 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, ...@@ -103,20 +103,33 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master,
return -EIO; return -EIO;
} }
sscanf(buf->kernel_address, "%u", &kerneladdr); computed_crc = crc32_le(IMAGETAG_CRC_START, (u8 *)buf,
sscanf(buf->kernel_length, "%u", &kernellen); offsetof(struct bcm_tag, header_crc));
sscanf(buf->total_length, "%u", &totallen); if (computed_crc == buf->header_crc) {
tagversion = &(buf->tag_version[0]); char *boardid = &(buf->board_id[0]);
boardid = &(buf->board_id[0]); char *tagversion = &(buf->tag_version[0]);
pr_info("CFE boot tag found with version %s and board type %s\n", sscanf(buf->kernel_address, "%u", &kerneladdr);
tagversion, boardid); sscanf(buf->kernel_length, "%u", &kernellen);
sscanf(buf->total_length, "%u", &totallen);
kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
rootfsaddr = kerneladdr + kernellen; pr_info("CFE boot tag found with version %s and board type %s\n",
spareaddr = roundup(totallen, master->erasesize) + cfelen; tagversion, boardid);
sparelen = master->size - spareaddr - nvramlen;
rootfslen = spareaddr - rootfsaddr; kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE;
rootfsaddr = kerneladdr + kernellen;
spareaddr = roundup(totallen, master->erasesize) + cfelen;
sparelen = master->size - spareaddr - nvramlen;
rootfslen = spareaddr - rootfsaddr;
} else {
pr_warn("CFE boot tag CRC invalid (expected %08x, actual %08x)\n",
buf->header_crc, computed_crc);
kernellen = 0;
rootfslen = 0;
rootfsaddr = 0;
spareaddr = cfelen;
sparelen = master->size - cfelen - nvramlen;
}
/* Determine number of partitions */ /* Determine number of partitions */
namelen = 8; namelen = 8;
......
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