mtd: parsers: trx: Rewrite partition parsing

The TRX parser has never been fully implemented, the commit splitting
it out of the bcm47xx parser says "There is still some place for
improvement".

Here are some improvements:

1. First partition includes TRX header offset:

The parser can currently produce output like this:
0x00000000001c-0x000000280000 : "linux"
mtd: partition "linux" doesn't start on an erase/write block
boundary -- force read-only

This is because the TRX header is not included into the
partition, while it should be: the vendor code does this,
and when replacing the kernel in flash we certainly want
to write it along with a new TRX tag as well. Right now
we cannot replace it from within Linux due to this
limitation.

2. Scan for several TRX headers

Currently only the first flash block is scanned for a TRX
header, but several flashes have multiple TRX headers
each with up to 3 partitions.

3. Determine extents of the data (rootfs) partition.

While still a bit hacky (just scanning forward for UBI
magic) we check where the rootfs volume actually ends,
and do not assume it fills the rest of the flash memory.

4. Add free space as a separate partition.

Before this I could not mount my UBI rootfs because
the rootfs gets too big: all remaining space will put
into the second detected partition so the UBI partition
has the wrong size and will not attach. After this patch
it mounts just fine.

Vendor code partition detection (D-Link DWL-8610AP):

Creating 5 MTD partitions on "brcmnand":
0x000000000000-0x000002800000 : "linux"
0x000000280000-0x000002800000 : "rootfs"
0x000002800000-0x000005000000 : "linux2"
0x000002a80000-0x000005000000 : "rootfs2"
0x000005000000-0x000008000000 : "jffs2"

Before this patch:

Creating 2 MTD partitions on "brcmnand.0":
0x00000000001c-0x000000280000 : "linux"
mtd: partition "linux" doesn't start on an erase/write
  block boundary -- force read-only
0x000000280000-0x000008000000 : "ubi"

After this patch:

5 trx partitions found on MTD device brcmnand.0
Creating 5 MTD partitions on "brcmnand.0":
0x000000000000-0x000000280000 : "linux"
0x000000280000-0x000002800000 : "ubi"
0x000002800000-0x000002a80000 : "linux2"
0x000002a80000-0x000005000000 : "ubi2"
0x000005000000-0x000008000000 : "free"

Cc: Rafał Miłecki <zajec5@gmail.com>
Cc: Hauke Mehrtens <hauke@hauke-m.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 file changed