udhcpc: add comment about server IP
[oweals/busybox.git] / miscutils / nandwrite.c
index 6c85ea346247c221b40b528daa2916ad0b941e6c..2ba6e3fe55c280883a45e7b13f84bb4c25a80dbd 100644 (file)
@@ -8,39 +8,37 @@
  * TODO: add support for large (>4GB) MTD devices
  */
 
-//applet:IF_NANDWRITE(APPLET(nandwrite, _BB_DIR_USR_SBIN, _BB_SUID_DROP))
-//applet:IF_NANDWRITE(APPLET_ODDNAME(nanddump, nandwrite, _BB_DIR_USR_SBIN, _BB_SUID_DROP, nanddump))
-
-//kbuild:lib-$(CONFIG_NANDWRITE) += nandwrite.o
-//kbuild:lib-$(CONFIG_NANDDUMP) += nandwrite.o
-
 //config:config NANDWRITE
 //config:      bool "nandwrite"
-//config:      default n
-//config:      depends on PLATFORM_LINUX
+//config:      default y
+//config:      select PLATFORM_LINUX
 //config:      help
 //config:        Write to the specified MTD device, with bad blocks awareness
 //config:
 //config:config NANDDUMP
 //config:      bool "nanddump"
-//config:      default n
-//config:      depends on PLATFORM_LINUX
+//config:      default y
+//config:      select PLATFORM_LINUX
 //config:      help
 //config:        Dump the content of raw NAND chip
 
+//applet:IF_NANDWRITE(APPLET(nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP))
+//applet:IF_NANDWRITE(APPLET_ODDNAME(nanddump, nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP, nanddump))
+
+//kbuild:lib-$(CONFIG_NANDWRITE) += nandwrite.o
+//kbuild:lib-$(CONFIG_NANDDUMP) += nandwrite.o
+
 //usage:#define nandwrite_trivial_usage
 //usage:       "[-p] [-s ADDR] MTD_DEVICE [FILE]"
 //usage:#define nandwrite_full_usage "\n\n"
 //usage:       "Write to the specified MTD device\n"
-//usage:     "\nOptions:"
 //usage:     "\n       -p      Pad to page size"
 //usage:     "\n       -s ADDR Start address"
 
 //usage:#define nanddump_trivial_usage
 //usage:       "[-o] [-b] [-s ADDR] [-f FILE] MTD_DEVICE"
 //usage:#define nanddump_full_usage "\n\n"
-//usage:       "Dump the sepcified MTD device\n"
-//usage:     "\nOptions:"
+//usage:       "Dump the specified MTD device\n"
 //usage:     "\n       -o      Omit oob data"
 //usage:     "\n       -b      Omit bad block from the dump"
 //usage:     "\n       -s ADDR Start address"
 #define IS_NANDDUMP  (ENABLE_NANDDUMP && (!ENABLE_NANDWRITE || (applet_name[4] == 'd')))
 #define IS_NANDWRITE (ENABLE_NANDWRITE && (!ENABLE_NANDDUMP || (applet_name[4] != 'd')))
 
-#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_f  (1 << 3)
-#define OPT_l  (1 << 4)
+#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_f  (1 << 3)
+#define OPT_l  (1 << 4)
 
-#define NAND_MAX_OOBSIZE 256
 /* helper for writing out 0xff for bad blocks pad */
 static void dump_bad(struct mtd_info_user *meminfo, unsigned len, int oob)
 {
@@ -103,7 +100,7 @@ int nandwrite_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int nandwrite_main(int argc UNUSED_PARAM, char **argv)
 {
        /* Buffer for OOB data */
-       unsigned char oobbuf[NAND_MAX_OOBSIZE];
+       unsigned char *oobbuf;
        unsigned opts;
        int fd;
        ssize_t cnt;
@@ -135,10 +132,6 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
        fd = xopen(argv[0], O_RDWR);
        xioctl(fd, MEMGETINFO, &meminfo);
 
-       oob.start  = 0;
-       oob.length = meminfo.oobsize;
-       oob.ptr    = oobbuf;
-
        mtdoffset = xstrtou(opt_s, 0);
        if (IS_NANDDUMP && (opts & OPT_l)) {
                unsigned length = xstrtou(opt_l, 0);
@@ -153,6 +146,11 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
                bb_error_msg_and_die("start address is not page aligned");
 
        filebuf = xmalloc(meminfo_writesize);
+       oobbuf = xmalloc(meminfo.oobsize);
+
+       oob.start  = 0;
+       oob.length = meminfo.oobsize;
+       oob.ptr    = oobbuf;
 
        blockstart = mtdoffset & ~(meminfo.erasesize - 1);
        if (blockstart != mtdoffset) {