projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
dc: fix "dc does_not_exist" SEGVing
[oweals/busybox.git]
/
miscutils
/
nandwrite.c
diff --git
a/miscutils/nandwrite.c
b/miscutils/nandwrite.c
index 247fc72f4becb5a145d822ef8ac46256c2339e51..29c800612467057dd6fd603fa4336e82c2b07517 100644
(file)
--- a/
miscutils/nandwrite.c
+++ b/
miscutils/nandwrite.c
@@
-7,20
+7,19
@@
*
* TODO: add support for large (>4GB) MTD devices
*/
*
* TODO: add support for large (>4GB) MTD devices
*/
-
//config:config NANDWRITE
//config:config NANDWRITE
-//config: bool "nandwrite"
+//config: bool "nandwrite
(5.9 kb)
"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: default y
//config: select PLATFORM_LINUX
//config: help
-//config:
Write to the specified MTD device, with bad blocks awareness
+//config: Write to the specified MTD device, with bad blocks awareness
//config:
//config:config NANDDUMP
//config:
//config:config NANDDUMP
-//config: bool "nanddump"
+//config: bool "nanddump
(6.3 kb)
"
//config: default y
//config: select PLATFORM_LINUX
//config: help
//config: default y
//config: select PLATFORM_LINUX
//config: help
-//config:
Dump the content of raw NAND chip
+//config: Dump the content of raw NAND chip
//applet:IF_NANDWRITE(APPLET(nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP))
//applet:IF_NANDDUMP(APPLET_ODDNAME(nanddump, nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP, nanddump))
//applet:IF_NANDWRITE(APPLET(nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP))
//applet:IF_NANDDUMP(APPLET_ODDNAME(nanddump, nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP, nanddump))
@@
-29,22
+28,24
@@
//kbuild:lib-$(CONFIG_NANDDUMP) += nandwrite.o
//usage:#define nandwrite_trivial_usage
//kbuild:lib-$(CONFIG_NANDDUMP) += nandwrite.o
//usage:#define nandwrite_trivial_usage
-//usage: "[-p] [-s ADDR] MTD_DEVICE [FILE]"
+//usage: "[-
n
p] [-s ADDR] MTD_DEVICE [FILE]"
//usage:#define nandwrite_full_usage "\n\n"
//usage: "Write to MTD_DEVICE\n"
//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: "\n -p Pad to page size"
//usage: "\n -s ADDR Start address"
//usage:#define nanddump_trivial_usage
-//usage: "[-
o]" IF_LONG_OPTS(" [--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:#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 -s ADDR Start address"
//usage: "\n -l LEN Length"
//usage: "\n -f FILE Dump to file ('-' for stdout)"
//usage: IF_LONG_OPTS(
//usage: "\n -o Dump oob data"
//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 --bb
METHOD
"
//usage: "\n skipbad: skip bad blocks"
//usage: "\n padbad: substitute bad blocks by 0xff (default)"
//usage: )
//usage: "\n skipbad: skip bad blocks"
//usage: "\n padbad: substitute bad blocks by 0xff (default)"
//usage: )
@@
-52,15
+53,25
@@
#include "libbb.h"
#include <mtd/mtd-user.h>
#include "libbb.h"
#include <mtd/mtd-user.h>
+/* Old headers call it MTD_MODE_RAW.
+ * FIXME: In kernel headers, MTD_FILE_MODE_RAW is not a define,
+ * it's an enum. How I can test for existence of an enum?
+ */
+#if !defined(MTD_FILE_MODE_RAW)
+# define MTD_FILE_MODE_RAW 3
+#endif
+
+
#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 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_f (1 << 2)
-#define OPT_l (1 << 3)
-#define OPT_bb (1 << 4) /* must be the last one in the list */
+#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_PADBAD (1 << 0)
#define BB_SKIPBAD (1 << 1)
@@
-120,15
+131,12
@@
int nandwrite_main(int argc UNUSED_PARAM, char **argv)
const char *opt_s = "0", *opt_f = "-", *opt_l, *opt_bb;
if (IS_NANDDUMP) {
const char *opt_s = "0", *opt_f = "-", *opt_l, *opt_bb;
if (IS_NANDDUMP) {
- opt_complementary = "=1";
-#if ENABLE_LONG_OPTS
- applet_long_options =
- "bb\0" Required_argument "\xff"; /* no short equivalent */
-#endif
- opts = getopt32(argv, "os:f:l:", &opt_s, &opt_f, &opt_l, &opt_bb);
+ opts = getopt32long(argv, "^" "ons:f:l:" "\0" "=1",
+ "bb\0" Required_argument "\xff", /* no short equivalent */
+ &opt_s, &opt_f, &opt_l, &opt_bb
+ );
} else { /* nandwrite */
} else { /* nandwrite */
- opt_complementary = "-1:?2";
- opts = getopt32(argv, "ps:", &opt_s);
+ opts = getopt32(argv, "^" "pns:" "\0" "-1:?2", &opt_s);
}
argv += optind;
}
argv += optind;
@@
-144,6
+152,9
@@
int nandwrite_main(int argc UNUSED_PARAM, char **argv)
fd = xopen(argv[0], IS_NANDWRITE ? O_RDWR : O_RDONLY);
xioctl(fd, MEMGETINFO, &meminfo);
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);
mtdoffset = xstrtou(opt_s, 0);
if (IS_NANDDUMP && (opts & OPT_l)) {
unsigned length = xstrtou(opt_l, 0);