[PATCH v3 1/4] mtdparts: regroup calls to get_mtd_device_nm [PATCH v3 2/4] mtdparts: show net size in mtdparts list [PATCH v3 3/4] mtdparts: add new sub-command "spread" [PATCH v3 4/4] mtdparts: new add.e: add part skipping bad blocks
cmd_mtdparts.c | 256 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 237 insertions(+), 19 deletions(-) This patch series is based on the idea of Harald Welte <lafo...@gnumonks.org> and the comments of Wolfgang Denk <w...@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.e' 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 <bengardi...@nanometrics.ca> CC: Wolfgang Denk <w...@denx.de> --- 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 NOTE: I'm not sure what to call the new subcommands, I chose 'spread' because of the way it changes the existing mtdparts variable; however, I am open to suggestions for a different name. I chose add.e/add.i because of the behaviour of the write.e/write.i commands; however, I am again open to suggestions. Testing was performed in the u-boot-omap-l1 tree [3]. 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.e 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.i 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. The checkpatch.pl output follows: total: 0 errors, 0 warnings, 71 lines checked 0001-PATCH-v3-1-4-mtdparts-regroup-calls-to-get_mtd_devic.patch has no obvious style problems and is ready for submission. total: 0 errors, 0 warnings, 85 lines checked 0002-PATCH-v3-2-4-mtdparts-show-net-size-in-mtdparts-list.patch has no obvious style problems and is ready for submission. total: 0 errors, 0 warnings, 148 lines checked 0003-PATCH-v3-3-4-mtdparts-add-new-sub-command-spread.patch has no obvious style problems and is ready for submission. total: 0 errors, 0 warnings, 69 lines checked 0004-PATCH-v3-4-4-mtdparts-new-add.e-add-part-skipping-ba.patch has no obvious style problems and is ready for submission. I tested the binary size and compiler warnings on ARM9 and 8xx with the following commands: #checkout u-boot/master, apply changes to da850evm_config for testing, #commit ./MAKEALL ARM9 2>&1 > ../makeall-master.log ./MAKEALL 8xx 2>&1 > ../makeall-master.log #apply patches, commit ./MAKEALL ARM9 2>&1 > ../makeall-spread.log ./MAKEALL 8xx 2>&1 > ../makeall-8xx-spread.log diff -burp ../makeall-8xx-master.log ../makeall-8xx-spread.log diff -burp ../makeall-master.log ../makeall-spread.log The diff output of the 8xx build shows all binaries text sections decreased in size -- except for kmsupx4 and mgsuvd which appear larger but are the same size when built manually: @@ -45,7 +45,7 @@ Configuring for FLAGADM board... 121164 9096 14388 144648 23508 ./u-boot Configuring for FPS850L board... text data bss dec hex filename - 233060 12636 25472 271168 42340 ./u-boot + 233036 12632 25472 271140 42324 ./u-boot Configuring for GEN860T board... text data bss dec hex filename 207072 32432 18752 258256 3f0d0 ./u-boot @@ -102,7 +102,7 @@ Configuring for lwmon board... 214504 34208 218388 467100 7209c ./u-boot Configuring for kmsupx4 board... text data bss dec hex filename - 274920 19924 28748 323592 4f008 ./u-boot + 274936 19920 28748 323604 4f014 ./u-boot Configuring for MBX board... text data bss dec hex filename 104736 7388 13016 125140 1e8d4 ./u-boot @@ -111,7 +111,7 @@ Configuring for MBX860T board... 92380 6424 13172 111976 1b568 ./u-boot Configuring for mgsuvd board... text data bss dec hex filename - 277012 20048 28752 325812 4f8b4 ./u-boot + 277028 20044 28752 325824 4f8c0 ./u-boot Configuring for MHPC board... text data bss dec hex filename 150944 21984 16776 189704 2e508 ./u-boot @@ -201,19 +201,19 @@ Configuring for TOP860 board... 160456 27360 17336 205152 32160 ./u-boot Configuring for TQM823L board... text data bss dec hex filename - 256664 13888 25700 296252 4853c ./u-boot + 256640 13884 25700 296224 48520 ./u-boot Configuring for TQM823L_LCD board... text data bss dec hex filename - 265408 29636 25732 320776 4e508 ./u-boot + 265384 29632 25732 320748 4e4ec ./u-boot Configuring for TQM850L board... text data bss dec hex filename - 256544 13868 25700 296112 484b0 ./u-boot + 256520 13864 25700 296084 48494 ./u-boot Configuring for TQM855L board... text data bss dec hex filename - 258544 13964 27236 299744 492e0 ./u-boot + 258520 13960 27236 299716 492c4 ./u-boot Configuring for TQM860L board... text data bss dec hex filename - 258592 13972 27236 299800 49318 ./u-boot + 258568 13968 27236 299772 492fc ./u-boot Configuring for TQM885D board... text data bss dec hex filename 209964 14680 26052 250696 3d348 ./u-boot The diff output of the ARM9 build shows a decrease in text size for all but the da850evm config in which the feature introduced by this patch series were enabled: @@ -48,7 +48,7 @@ Configuring for da830evm board... 147617 4888 295320 447825 6d551 ./u-boot Configuring for da850evm board... text data bss dec hex filename - 198497 10332 296608 505437 7b65d ./u-boot + 199590 10332 296608 506530 7baa2 ./u-boot Configuring for edb9301 board... text data bss dec hex filename 133899 3772 213400 351071 55b5f ./u-boot @@ -83,13 +83,13 @@ kirkwood_egiga.c:620: warning: dereferen 166164 8214 260736 435114 6a3aa ./u-boot Configuring for imx27lite board... text data bss dec hex filename - 195862 9876 236052 441790 6bdbe ./u-boot + 195784 9876 236052 441712 6bd70 ./u-boot Configuring for lpd7a400 board... text data bss dec hex filename 96349 3368 14496 114213 1be25 ./u-boot Configuring for magnesium board... text data bss dec hex filename - 195897 9892 236052 441841 6bdf1 ./u-boot + 195819 9892 236052 441763 6bda3 ./u-boot Configuring for mv88f6281gtw_ge board... kirkwood_egiga.c: In function 'kwgbe_recv': kirkwood_egiga.c:620: warning: dereferencing type-punned pointer will break strict-aliasing rules @@ -100,10 +100,10 @@ Configuring for mx1ads board... 105339 3740 14580 123659 1e30b ./u-boot Configuring for mx1fs2 board... text data bss dec hex filename - 97987 3240 4124 105351 19b87 ./u-boot + 97921 3240 4124 105285 19b45 ./u-boot Configuring for netstar board... text data bss dec hex filename - 173323 8060 14688 196071 2fde7 ./u-boot + 173269 8060 14688 196017 2fdb1 ./u-boot Configuring for nhk8815 board... text data bss dec hex filename 175012 10436 37144 222592 36580 ./u-boot @@ -129,7 +129,7 @@ Configuring for openrd_base board... kirkwood_egiga.c: In function 'kwgbe_recv': kirkwood_egiga.c:620: warning: dereferencing type-punned pointer will break strict-aliasing rules text data bss dec hex filename - 302083 9002 286656 597741 91eed ./u-boot + 302055 9002 286656 597713 91ed1 ./u-boot Configuring for rd6281a board... kirkwood_egiga.c: In function 'kwgbe_recv': kirkwood_egiga.c:620: warning: dereferencing type-punned pointer will break strict-aliasing rules @@ -145,7 +145,7 @@ Configuring for sheevaplug board... kirkwood_egiga.c: In function 'kwgbe_recv': kirkwood_egiga.c:620: warning: dereferencing type-punned pointer will break strict-aliasing rules text data bss dec hex filename - 319712 8990 286784 615486 9643e ./u-boot + 319684 8990 286784 615458 96422 ./u-boot Configuring for smdk2400 board... text data bss dec hex filename 97632 3440 14500 115572 1c374 ./u-boot @@ -168,10 +168,10 @@ Configuring for suen3 board... kirkwood_egiga.c: In function 'kwgbe_recv': kirkwood_egiga.c:620: warning: dereferencing type-punned pointer will break strict-aliasing rules text data bss dec hex filename - 244086 12716 25128 281930 44d4a ./u-boot + 244054 12716 25128 281898 44d2a ./u-boot Configuring for trab board... text data bss dec hex filename - 217847 14027 424192 656066 a02c2 ./u-boot + 217781 14027 424192 656000 a0280 ./u-boot Configuring for VCMA9 board... text data bss dec hex filename 177726 7504 261900 447130 6d29a ./u-boot @@ -189,7 +189,7 @@ Variant:: PB926EJ-S 85977 2920 12132 101029 18aa5 ./u-boot Configuring for voiceblue board... text data bss dec hex filename - 143684 4708 18916 167308 28d8c ./u-boot + 143614 4708 18916 167238 28d46 ./u-boot Configuring for davinci_dvevm board... text data bss dec hex filename 178646 5500 297984 482130 75b52 ./u-boot @@ -204,13 +204,13 @@ Configuring for davinci_sonata board... 145390 5296 55068 205754 323ba ./u-boot Configuring for davinci_dm355evm board... text data bss dec hex filename - 207288 8516 40864 256668 3ea9c ./u-boot + 207252 8516 40864 256632 3ea78 ./u-boot Configuring for davinci_dm355leopard board... text data bss dec hex filename - 206398 7904 40864 255166 3e4be ./u-boot + 206362 7904 40864 255130 3e49a ./u-boot Configuring for davinci_dm365evm board... text data bss dec hex filename - 243459 8704 297752 549915 8641b ./u-boot + 243423 8704 297752 549879 863f7 ./u-boot Configuring for davinci_dm6467evm board... text data bss dec hex filename 91806 4776 26100 122682 1df3a ./u-boot The binary size impact was checked in a couple specific cases also: using the da830evm config + NAND enabled for arm and the virtlab2 config for ppc. In these cases the entire patch series saves 64 bytes on arm and 4 bytes on ppc -- due to the regrouping of calls in 1/4. With all the config options introduced in this series enabled the patch series adds 1096 bytes on arm and 260 bytes on ppc. [1] http://article.gmane.org/gmane.comp.boot-loaders.u-boot/43549 [2] http://wiki.openmoko.org/wiki/NAND_bad_blocks [3] git://arago-project.org/git/people/sekhar/u-boot-omapl1.git _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot