[U-Boot] [PATCH v4 0/4] mtdparts: add bad-block skipping

Ben Gardiner bengardiner at nanometrics.ca
Mon Aug 9 22:43:56 CEST 2010


[PATCH v4 1/4] mtdparts: regroup calls to get_mtd_device_nm
[PATCH v4 2/4] mtdparts: show net size in mtdparts list
[PATCH v4 3/4] mtdparts: add new sub-command "spread"
[PATCH v4 4/4] mtdparts: new add.spread: add part skipping bad blocks

 common/cmd_mtdparts.c |  268 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 246 insertions(+), 22 deletions(-)

This patch series is based on the idea of Harald Welte <laforge at gnumonks.org>
and the comments of Wolfgang Denk <wd at denx.de> [1]. I started with Harald's
original patch and migrated it to a new mtdparts sub-command and added an
interface to the new functionality via a 'mtdparts add' variant.

I tried to keep it at the level of the mtd subsystem. Whereas the dynparts patch
was limited to NAND flashes, I believe this patch will work on any mtd device
that can report bad blocks.

These new commands can be useful when gang programming NAND chips where the
gang programmer is capable only of skipping bad blocks. One can use a
master image that contains images of each of the partitions padded-out
to their spec'd sizes; when u-boot first comes up 'mtdparts default;
mtdparts spread' (or a seq of 'mtdpart add.spread' commands) will produce a 
partition table that matches what was put there by the gang-programmer.

It can also be useful when doing in-situ programming with u-boot being the
flash programmer as demonstrated by the openmoko project's use of the
'dynpart' command [2] upon which this patch series was based.

Signed-off-by: Ben Gardiner <bengardiner at nanometrics.ca>
CC: Wolfgang Denk <wd at denx.de>
CC: Scott Wood <scottwood at freescale.com>

[1] http://article.gmane.org/gmane.comp.boot-loaders.u-boot/43549 
[2] http://wiki.openmoko.org/wiki/NAND_bad_blocks

---

V2:
 * formating: spaces after 'if' and for
 * printing net partition sizes feature is now conditional on the new
   CONFIG_CMD_MTDPARTS_SHOW_NET_SIZES macro; patch 2/4 was adding 264 bytes
   to the virtlab2 build -- now it adds 0 bytes -- see below for more binary
   size impact details
 * changed the net_part_size method to return the net size instead of using an
   output variable
 * checking mtd->block_isbad function pointer before dereferencing
 * there were some trailing whitespace errors when applying 3/4 and 4/4 that I
   have fixed now

V3:
 * rebased to 54841ab50c20d6fa6c9cc3eb826989da3a22d934 of
   git://git.denx.de/u-boot.git
 * more checkpatch fixes
 * adding openmoko to the copyright statements in cmd_mtdparts.c

V4:
 * rebased to b417260d871d4d8d336c160d95ed40cc8c0fb0fa of
   git://git.denx.de/u-boot.git
 * re-grouped list_partition #ifdefs into one
 * removed changelog and my (C) from file header
 * added source of port to the commit message
 * fixed multi-line comment style
 * indentation only by tabs
 * check for s == NULL when looking for '.' in command
 * do not include support for the '.i' synonym
 * rename to 'add.spread' to match 'mtdparts spread' as per Scott Wood's
   suggestion.

Testing was performed with da850evm.h plus NAND enabled. Here is an example
u-boot console session to demonstrate how the commands work:

-------------------------------------------------------------------------------
U-Boot > mtdparts default
U-Boot > nand bad

Device 0 bad blocks:
  062c0000
  0a140000
  128a0000
  12e20000
  18bc0000
  1ff80000
  1ffa0000
  1ffc0000
  1ffe0000
U-Boot > mtdparts

device nand0 <davinci_nand.1>, # parts = 11
 #: name                size            net size        offset
mask_flags
 0: zero                0x000c0000      0x000c0000      0x00000000      1
 1: conf                0x00200000      0x00200000      0x000c0000      0
 2: kernel_a            0x00400000      0x00400000      0x002c0000      0
 3: initrd_a            0x00400000      0x00400000      0x006c0000      0
 4: rootfs_a            0x07020000      0x07000000 (!)  0x00ac0000      0
 5: kernel_b            0x00400000      0x00400000      0x07ae0000      0
 6: initrd_b            0x00400000      0x00400000      0x07ee0000      0
 7: rootfs_b            0x07020000      0x07000000 (!)  0x082e0000      0

active partition: nand0,0 - (zero) 0x00020000 @ 0x00000000

defaults:
mtdids  : nand0=davinci_nand.1
mtdparts: mtdparts=mtdparts=davinci_nand.1:768k(zero)ro,2m(conf),4m(kernel_a),
4m(initrd_a),112m(rootfs_a),4m(kernel_b),4m(initrd_b),112m(rootfs_b)
U-Boot >
U-Boot > mtdparts spread
U-Boot > print mtdparts
mtdparts=mtdparts=davinci_nand.1:768k(zero)ro,2m(conf),4m(kernel_a),4m(initrd_a)
,114816k(rootfs_a),4m(kernel_b),4m(initrd_b),114816k(rootfs_b)
U-Boot > mtdparts

device nand0 <davinci_nand.1>, # parts = 11
 #: name                size            net size        offset
mask_flags
 0: zero                0x000c0000      0x000c0000      0x00000000      1
 1: conf                0x00200000      0x00200000      0x000c0000      0
 2: kernel_a            0x00400000      0x00400000      0x002c0000      0
 3: initrd_a            0x00400000      0x00400000      0x006c0000      0
 4: rootfs_a            0x07040000      0x07020000 (!)  0x00ac0000      0
 5: kernel_b            0x00400000      0x00400000      0x07b00000      0
 6: initrd_b            0x00400000      0x00400000      0x07f00000      0
 7: rootfs_b            0x07040000      0x07020000 (!)  0x08300000      0

active partition: nand0,0 - (zero) 0x00020000 @ 0x00000000

defaults:
mtdids  : nand0=davinci_nand.1
mtdparts: mtdparts=mtdparts=davinci_nand.1:768k(zero)ro,2m(conf),4m(kernel_a),
4m(initrd_a),112m(rootfs_a),4m(kernel_b),4m(initrd_b),112m(rootfs_b)
U-Boot >
U-Boot > mtdpart del rootfs_b
U-Boot > mtdpart add.spread nand0 112m rootfs_b
U-Boot > print mtdparts
mtdparts=mtdparts=davinci_nand.1:768k(zero)ro,2m(conf),4m(kernel_a),4m(initrd_a)
,114816k(rootfs_a),4m(kernel_b),4m(initrd_b),114816k(rootfs_b)

U-Boot > mtdpart del rootfs_b
U-Boot > mtdpart add.spread nand0 112m rootfs_b
U-Boot > print mtdparts
mtdparts=mtdparts=davinci_nand.1:768k(zero)ro,2m(conf),4m(kernel_a),4m(initrd_a)
,114816k(rootfs_a),4m(kernel_b),4m(initrd_b),114816k(rootfs_b)
U-Boot >
U-Boot > mtdparts del rootfs_b
U-Boot > mtdparts add nand0 112m rootfs_b
U-Boot > print mtdparts
mtdparts=mtdparts=davinci_nand.1:768k(zero)ro,2m(conf),4m(kernel_a),4m(initrd_a)
,114816k(rootfs_a),4m(kernel_b),4m(initrd_b),112m(rootfs_b)
-------------------------------------------------------------------------------

I verified the patches with checkpatch.

I tested the binary size and compiler warnings on ARM9 and 8xx. The patch series
saves 24 bytes of text on 8xx and 54 bytes of text on arm9 -- when none of the
config options are enabled. When the config options are enabled, text grows by 
1023 bytes on arm9.


More information about the U-Boot mailing list