hust testsuite: fix a false positive
[oweals/busybox.git] / miscutils / nandwrite.c
index a64b95bc5433f2dafc163f0ff0624f97b3f3495d..c95cbb21e63a1834e2cef270019fd9717e5af5b9 100644 (file)
 //kbuild:lib-$(CONFIG_NANDDUMP) += nandwrite.o
 
 //usage:#define nandwrite_trivial_usage
-//usage:       "[-p] [-s ADDR] MTD_DEVICE [FILE]"
+//usage:       "[-np] [-s ADDR] MTD_DEVICE [FILE]"
 //usage:#define nandwrite_full_usage "\n\n"
 //usage:       "Write to MTD_DEVICE\n"
+//usage:     "\n       -n      Write without ecc"
 //usage:     "\n       -p      Pad to page size"
 //usage:     "\n       -s ADDR Start address"
 
 //usage:#define nanddump_trivial_usage
-//usage:       "[-o] [-b|--bb=padbad|skipbad] [-s ADDR] [-l LEN] [-f FILE] MTD_DEVICE"
+//usage:       "[-no]" IF_LONG_OPTS(" [--bb=padbad|skipbad]") " [-s ADDR] [-l LEN] [-f FILE] MTD_DEVICE"
 //usage:#define nanddump_full_usage "\n\n"
 //usage:       "Dump MTD_DEVICE\n"
+//usage:     "\n       -n      Read without ecc"
 //usage:     "\n       -o      Dump oob data"
-//usage:     "\n       -b      Omit bad block from the dump"
 //usage:     "\n       -s ADDR Start address"
 //usage:     "\n       -l LEN  Length"
 //usage:     "\n       -f FILE Dump to file ('-' for stdout)"
+//usage:     IF_LONG_OPTS(
 //usage:     "\n       --bb=METHOD:"
 //usage:     "\n               skipbad: skip bad blocks"
 //usage:     "\n               padbad: substitute bad blocks by 0xff (default)"
-//usage:     "\n       The difference between omit and skip bad block is that in the omit"
-//usage:     "\n       case, the length of the bad block is counted as part of the total"
-//usage:     "\n       dump length, and in the skip case, it's not."
+//usage:     )
 
 #include "libbb.h"
 #include <mtd/mtd-user.h>
 
 #define OPT_p  (1 << 0) /* nandwrite only */
 #define OPT_o  (1 << 0) /* nanddump only */
-#define OPT_s  (1 << 1)
-#define OPT_b  (1 << 2)
+#define OPT_n  (1 << 1)
+#define OPT_s  (1 << 2)
 #define OPT_f  (1 << 3)
 #define OPT_l  (1 << 4)
 #define OPT_bb (1 << 5) /* must be the last one in the list */
 
 #define BB_PADBAD (1 << 0)
 #define BB_SKIPBAD (1 << 1)
-#define BB_OMITBAD (1 << 2)
 
 /* helper for writing out 0xff for bad blocks pad */
 static void dump_bad(struct mtd_info_user *meminfo, unsigned len, int oob)
@@ -113,7 +112,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
        /* Buffer for OOB data */
        unsigned char *oobbuf;
        unsigned opts;
-       unsigned bb_method = BB_PADBAD;
+       unsigned bb_method = BB_SKIPBAD;
        int fd;
        ssize_t cnt;
        unsigned mtdoffset, meminfo_writesize, blockstart, limit;
@@ -122,16 +121,17 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
        struct mtd_oob_buf oob;
        unsigned char *filebuf;
        const char *opt_s = "0", *opt_f = "-", *opt_l, *opt_bb;
-       static const char nanddump_longopts[] ALIGN1 =
-               "bb\0" Required_argument "\xff"; /* no short equivalent */
 
        if (IS_NANDDUMP) {
                opt_complementary = "=1";
-               applet_long_options = nanddump_longopts;
-               opts = getopt32(argv, "os:bf:l:", &opt_s, &opt_f, &opt_l, &opt_bb);
+#if ENABLE_LONG_OPTS
+               applet_long_options =
+                       "bb\0" Required_argument "\xff"; /* no short equivalent */
+#endif
+               opts = getopt32(argv, "ons:f:l:", &opt_s, &opt_f, &opt_l, &opt_bb);
        } else { /* nandwrite */
                opt_complementary = "-1:?2";
-               opts = getopt32(argv, "ps:", &opt_s);
+               opts = getopt32(argv, "pns:", &opt_s);
        }
        argv += optind;
 
@@ -147,25 +147,22 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
        fd = xopen(argv[0], IS_NANDWRITE ? O_RDWR : O_RDONLY);
        xioctl(fd, MEMGETINFO, &meminfo);
 
+       if (opts & OPT_n)
+               xioctl(fd, MTDFILEMODE, (void *)MTD_FILE_MODE_RAW);
+
        mtdoffset = xstrtou(opt_s, 0);
        if (IS_NANDDUMP && (opts & OPT_l)) {
                unsigned length = xstrtou(opt_l, 0);
                if (length < meminfo.size - mtdoffset)
                        end_addr = mtdoffset + length;
        }
-       if (IS_NANDDUMP) {
-              if ((opts & OPT_b) && (opts & OPT_bb))
-                      bb_show_usage();
-              if (opts & OPT_b)
-                      bb_method = BB_OMITBAD;
-              if (opts & OPT_bb) {
-                      if (!strcmp("skipbad", opt_bb))
-                              bb_method = BB_SKIPBAD;
-                      else if (!strcmp("padbad", opt_bb))
-                              bb_method = BB_PADBAD;
-                      else
-                              bb_show_usage();
-              }
+       if (IS_NANDDUMP && (opts & OPT_bb)) {
+               if (strcmp("skipbad", opt_bb) == 0)
+                       bb_method = BB_SKIPBAD;
+               else if (strcmp("padbad", opt_bb) == 0)
+                       bb_method = BB_PADBAD;
+               else
+                       bb_show_usage();
        }
 
        /* Pull it into a CPU register (hopefully) - smaller code that way */
@@ -200,7 +197,6 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
                                if (bb_method == BB_SKIPBAD) {
                                        end_addr += (tmp - blockstart);
                                }
-                               /* omitbad: do nothing */
                        }
                        mtdoffset = tmp;
                }
@@ -231,7 +227,6 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
                                                end_addr = ~0;
                                        limit = MIN(meminfo.size, end_addr);
                                }
-                               /* omitbad: do nothing */
                        }
                        if (mtdoffset >= limit)
                                break;