Ignore:
Timestamp:
Dec 20, 2016, 4:07:32 PM (7 years ago)
Author:
Bruno Cornec
Message:

New 3?3 banch for incorporation of latest busybox 1.25. Changing minor version to handle potential incompatibilities.

Location:
branches/3.3
Files:
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi-busybox/miscutils/nandwrite.c

    r3232 r3621  
    2424
    2525//applet:IF_NANDWRITE(APPLET(nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP))
    26 //applet:IF_NANDWRITE(APPLET_ODDNAME(nanddump, nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP, nanddump))
     26//applet:IF_NANDDUMP(APPLET_ODDNAME(nanddump, nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP, nanddump))
    2727
    2828//kbuild:lib-$(CONFIG_NANDWRITE) += nandwrite.o
     
    3030
    3131//usage:#define nandwrite_trivial_usage
    32 //usage:    "[-p] [-s ADDR] MTD_DEVICE [FILE]"
     32//usage:    "[-np] [-s ADDR] MTD_DEVICE [FILE]"
    3333//usage:#define nandwrite_full_usage "\n\n"
    34 //usage:    "Write to the specified MTD device\n"
     34//usage:    "Write to MTD_DEVICE\n"
     35//usage:     "\n    -n  Write without ecc"
    3536//usage:     "\n    -p  Pad to page size"
    3637//usage:     "\n    -s ADDR Start address"
    3738
    3839//usage:#define nanddump_trivial_usage
    39 //usage:    "[-o] [-b] [-s ADDR] [-f FILE] MTD_DEVICE"
     40//usage:    "[-no]" IF_LONG_OPTS(" [--bb=padbad|skipbad]") " [-s ADDR] [-l LEN] [-f FILE] MTD_DEVICE"
    4041//usage:#define nanddump_full_usage "\n\n"
    41 //usage:    "Dump the specified MTD device\n"
     42//usage:    "Dump MTD_DEVICE\n"
     43//usage:     "\n    -n  Read without ecc"
    4244//usage:     "\n    -o  Dump oob data"
    43 //usage:     "\n    -b  Omit bad block from the dump"
    4445//usage:     "\n    -s ADDR Start address"
    4546//usage:     "\n    -l LEN  Length"
    4647//usage:     "\n    -f FILE Dump to file ('-' for stdout)"
     48//usage:     IF_LONG_OPTS(
     49//usage:     "\n    --bb=METHOD:"
     50//usage:     "\n        skipbad: skip bad blocks"
     51//usage:     "\n        padbad: substitute bad blocks by 0xff (default)"
     52//usage:     )
    4753
    4854#include "libbb.h"
     
    5460#define OPT_p  (1 << 0) /* nandwrite only */
    5561#define OPT_o  (1 << 0) /* nanddump only */
    56 #define OPT_s  (1 << 1)
    57 #define OPT_b  (1 << 2)
     62#define OPT_n  (1 << 1)
     63#define OPT_s  (1 << 2)
    5864#define OPT_f  (1 << 3)
    5965#define OPT_l  (1 << 4)
     66#define OPT_bb (1 << 5) /* must be the last one in the list */
     67
     68#define BB_PADBAD (1 << 0)
     69#define BB_SKIPBAD (1 << 1)
    6070
    6171/* helper for writing out 0xff for bad blocks pad */
     
    6575    unsigned count;
    6676
    67     /* round len to the next page */
    68     len = (len | ~(meminfo->writesize - 1)) + 1;
     77    /* round len to the next page only if len is not already on a page */
     78    len = ((len - 1) | (meminfo->writesize - 1)) + 1;
    6979
    7080    memset(buf, 0xff, sizeof(buf));
     
    103113    unsigned char *oobbuf;
    104114    unsigned opts;
     115    unsigned bb_method = BB_SKIPBAD;
    105116    int fd;
    106117    ssize_t cnt;
     
    110121    struct mtd_oob_buf oob;
    111122    unsigned char *filebuf;
    112     const char *opt_s = "0", *opt_f = "-", *opt_l;
     123    const char *opt_s = "0", *opt_f = "-", *opt_l, *opt_bb;
    113124
    114125    if (IS_NANDDUMP) {
    115126        opt_complementary = "=1";
    116         opts = getopt32(argv, "os:bf:l:", &opt_s, &opt_f, &opt_l);
     127#if ENABLE_LONG_OPTS
     128        applet_long_options =
     129            "bb\0" Required_argument "\xff"; /* no short equivalent */
     130#endif
     131        opts = getopt32(argv, "ons:f:l:", &opt_s, &opt_f, &opt_l, &opt_bb);
    117132    } else { /* nandwrite */
    118133        opt_complementary = "-1:?2";
    119         opts = getopt32(argv, "ps:", &opt_s);
     134        opts = getopt32(argv, "pns:", &opt_s);
    120135    }
    121136    argv += optind;
     
    133148    xioctl(fd, MEMGETINFO, &meminfo);
    134149
     150    if (opts & OPT_n)
     151        xioctl(fd, MTDFILEMODE, (void *)MTD_FILE_MODE_RAW);
     152
    135153    mtdoffset = xstrtou(opt_s, 0);
    136154    if (IS_NANDDUMP && (opts & OPT_l)) {
     
    138156        if (length < meminfo.size - mtdoffset)
    139157            end_addr = mtdoffset + length;
     158    }
     159    if (IS_NANDDUMP && (opts & OPT_bb)) {
     160        if (strcmp("skipbad", opt_bb) == 0)
     161            bb_method = BB_SKIPBAD;
     162        else if (strcmp("padbad", opt_bb) == 0)
     163            bb_method = BB_PADBAD;
     164        else
     165            bb_show_usage();
    140166    }
    141167
     
    163189        if (tmp != blockstart) {
    164190            /* bad block(s), advance mtdoffset */
    165             if (IS_NANDDUMP && !(opts & OPT_b)) {
    166                 int bad_len = MIN(tmp, end_addr) - mtdoffset;
    167                 dump_bad(&meminfo, bad_len, opts & OPT_o);
     191            if (IS_NANDDUMP) {
     192                if (bb_method == BB_PADBAD) {
     193                    int bad_len = MIN(tmp, end_addr) - mtdoffset;
     194                    dump_bad(&meminfo, bad_len, opts & OPT_o);
     195                }
     196                /* with option skipbad, increase the total length */
     197                if (bb_method == BB_SKIPBAD) {
     198                    end_addr += (tmp - blockstart);
     199                }
    168200            }
    169201            mtdoffset = tmp;
     
    183215            if (IS_NANDWRITE)
    184216                printf("Writing at 0x%08x\n", mtdoffset);
    185             else if (mtdoffset > blockstart && !(opts & OPT_b)) {
    186                 int bad_len = MIN(mtdoffset, limit) - blockstart;
    187                 dump_bad(&meminfo, bad_len, opts & OPT_o);
     217            else if (mtdoffset > blockstart) {
     218                if (bb_method == BB_PADBAD) {
     219                    /* dump FF padded bad block */
     220                    int bad_len = MIN(mtdoffset, limit) - blockstart;
     221                    dump_bad(&meminfo, bad_len, opts & OPT_o);
     222                } else if (bb_method == BB_SKIPBAD) {
     223                    /* for skipbad, increase the length */
     224                    if ((end_addr + mtdoffset - blockstart) > end_addr)
     225                        end_addr += (mtdoffset - blockstart);
     226                    else
     227                        end_addr = ~0;
     228                    limit = MIN(meminfo.size, end_addr);
     229                }
    188230            }
    189231            if (mtdoffset >= limit)
Note: See TracChangeset for help on using the changeset viewer.