Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/miscutils/nandwrite.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/miscutils/nandwrite.c
r3232 r3621 24 24 25 25 //applet:IF_NANDWRITE(APPLET(nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP)) 26 //applet:IF_NAND WRITE(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)) 27 27 28 28 //kbuild:lib-$(CONFIG_NANDWRITE) += nandwrite.o … … 30 30 31 31 //usage:#define nandwrite_trivial_usage 32 //usage: "[- p] [-s ADDR] MTD_DEVICE [FILE]"32 //usage: "[-np] [-s ADDR] MTD_DEVICE [FILE]" 33 33 //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" 35 36 //usage: "\n -p Pad to page size" 36 37 //usage: "\n -s ADDR Start address" 37 38 38 39 //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" 40 41 //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" 42 44 //usage: "\n -o Dump oob data" 43 //usage: "\n -b Omit bad block from the dump"44 45 //usage: "\n -s ADDR Start address" 45 46 //usage: "\n -l LEN Length" 46 47 //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: ) 47 53 48 54 #include "libbb.h" … … 54 60 #define OPT_p (1 << 0) /* nandwrite only */ 55 61 #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) 58 64 #define OPT_f (1 << 3) 59 65 #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) 60 70 61 71 /* helper for writing out 0xff for bad blocks pad */ … … 65 75 unsigned count; 66 76 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; 69 79 70 80 memset(buf, 0xff, sizeof(buf)); … … 103 113 unsigned char *oobbuf; 104 114 unsigned opts; 115 unsigned bb_method = BB_SKIPBAD; 105 116 int fd; 106 117 ssize_t cnt; … … 110 121 struct mtd_oob_buf oob; 111 122 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; 113 124 114 125 if (IS_NANDDUMP) { 115 126 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); 117 132 } else { /* nandwrite */ 118 133 opt_complementary = "-1:?2"; 119 opts = getopt32(argv, "p s:", &opt_s);134 opts = getopt32(argv, "pns:", &opt_s); 120 135 } 121 136 argv += optind; … … 133 148 xioctl(fd, MEMGETINFO, &meminfo); 134 149 150 if (opts & OPT_n) 151 xioctl(fd, MTDFILEMODE, (void *)MTD_FILE_MODE_RAW); 152 135 153 mtdoffset = xstrtou(opt_s, 0); 136 154 if (IS_NANDDUMP && (opts & OPT_l)) { … … 138 156 if (length < meminfo.size - mtdoffset) 139 157 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(); 140 166 } 141 167 … … 163 189 if (tmp != blockstart) { 164 190 /* 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 } 168 200 } 169 201 mtdoffset = tmp; … … 183 215 if (IS_NANDWRITE) 184 216 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 } 188 230 } 189 231 if (mtdoffset >= limit)
Note:
See TracChangeset
for help on using the changeset viewer.