aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/brcm47xx
diff options
context:
space:
mode:
authorMarkus Wigge <markus@cultcom.de>2010-07-01 16:26:24 +0000
committerMarkus Wigge <markus@cultcom.de>2010-07-01 16:26:24 +0000
commit36b02072c50715634f663e10f0f0d79f0df0631a (patch)
tree78f99348d7c79a4a90db42eaf7e490248a08fd31 /target/linux/brcm47xx
parentd312e88e23b57ee0c75264a9c270c51cdfb232c5 (diff)
downloadupstream-36b02072c50715634f663e10f0f0d79f0df0631a.tar.gz
upstream-36b02072c50715634f663e10f0f0d79f0df0631a.tar.bz2
upstream-36b02072c50715634f663e10f0f0d79f0df0631a.zip
brcm47xx: added dual image support to flashmap driver
some CFE versions (i.e. WRT54G3Gv2-VF) expect two separate firmware images which each consume half of the available flash space. these changes check for the TRX header version and set the partition size correctly. Tested on G3Gv2-VF and Asus WL-500GP git-svn-id: svn://svn.openwrt.org/openwrt/trunk@22019 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/brcm47xx')
-rw-r--r--target/linux/brcm47xx/files/drivers/mtd/maps/bcm47xx-flash.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/target/linux/brcm47xx/files/drivers/mtd/maps/bcm47xx-flash.c b/target/linux/brcm47xx/files/drivers/mtd/maps/bcm47xx-flash.c
index 3ceec403cf..61605d3f4a 100644
--- a/target/linux/brcm47xx/files/drivers/mtd/maps/bcm47xx-flash.c
+++ b/target/linux/brcm47xx/files/drivers/mtd/maps/bcm47xx-flash.c
@@ -222,6 +222,37 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos,
}
+static int __init
+find_dual_image_off (struct mtd_info *mtd, size_t size)
+{
+ struct trx_header trx;
+ int off, blocksize;
+ size_t len;
+
+ blocksize = mtd->erasesize;
+ if (blocksize < 0x10000)
+ blocksize = 0x10000;
+
+ for (off = (128*1024); off < size; off += blocksize) {
+ memset(&trx, 0xe5, sizeof(trx));
+ /*
+ * Read into buffer
+ */
+ if (mtd->read(mtd, off, sizeof(trx), &len, (char *) &trx) ||
+ len != sizeof(trx))
+ continue;
+ /* found last TRX header */
+ if (le32_to_cpu(trx.magic) == TRX_MAGIC){
+ if (le32_to_cpu(trx.flag_version >> 16)==2){
+ printk("dual image TRX header found\n");
+ return size/2;
+ } else {
+ return 0;
+ }
+ }
+ }
+ return 0;
+}
static int __init
@@ -232,7 +263,6 @@ find_root(struct mtd_info *mtd, size_t size, struct mtd_partition *part)
int off, blocksize;
u32 i, crc = ~0;
size_t len;
- struct squashfs_super_block *sb = (struct squashfs_super_block *) buf;
blocksize = mtd->erasesize;
if (blocksize < 0x10000)
@@ -318,6 +348,7 @@ struct mtd_partition * __init
init_mtd_partitions(struct mtd_info *mtd, size_t size)
{
int cfe_size;
+ int dual_image_offset = 0;
if ((cfe_size = find_cfe_size(mtd,size)) < 0)
return NULL;
@@ -336,10 +367,13 @@ init_mtd_partitions(struct mtd_info *mtd, size_t size)
bcm47xx_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
}
+ /* dual image offset*/
+ printk("Looking for dual image\n");
+ dual_image_offset=find_dual_image_off(mtd,size);
/* linux (kernel and rootfs) */
if (cfe_size != 384 * 1024) {
bcm47xx_parts[1].offset = bcm47xx_parts[0].size;
- bcm47xx_parts[1].size = bcm47xx_parts[3].offset -
+ bcm47xx_parts[1].size = bcm47xx_parts[3].offset - dual_image_offset -
bcm47xx_parts[1].offset;
} else {
/* do not count the elf loader, which is on one block */
@@ -353,7 +387,7 @@ init_mtd_partitions(struct mtd_info *mtd, size_t size)
/* find and size rootfs */
find_root(mtd,size,&bcm47xx_parts[2]);
- bcm47xx_parts[2].size = size - bcm47xx_parts[2].offset - bcm47xx_parts[3].size;
+ bcm47xx_parts[2].size = size - dual_image_offset - bcm47xx_parts[2].offset - bcm47xx_parts[3].size;
return bcm47xx_parts;
}