Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 1 | /* |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 2 | * nandwrite and nanddump ported to busybox from mtd-utils |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 3 | * |
| 4 | * Author: Baruch Siach <baruch@tkos.co.il>, Orex Computed Radiography |
| 5 | * |
| 6 | * Licensed under GPLv2, see file LICENSE in this source tree. |
| 7 | * |
| 8 | * TODO: add support for large (>4GB) MTD devices |
| 9 | */ |
| 10 | |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 11 | //config:config NANDWRITE |
Denys Vlasenko | ae178ce | 2017-07-19 14:32:54 +0200 | [diff] [blame] | 12 | //config: bool "nandwrite (5.9 kb)" |
Denys Vlasenko | c97578d | 2011-08-13 09:00:29 +0200 | [diff] [blame] | 13 | //config: default y |
Denys Vlasenko | e3b1a1f | 2011-02-26 22:24:08 +0100 | [diff] [blame] | 14 | //config: select PLATFORM_LINUX |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 15 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame^] | 16 | //config: Write to the specified MTD device, with bad blocks awareness |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 17 | //config: |
| 18 | //config:config NANDDUMP |
Denys Vlasenko | ae178ce | 2017-07-19 14:32:54 +0200 | [diff] [blame] | 19 | //config: bool "nanddump (6.3 kb)" |
Denys Vlasenko | c97578d | 2011-08-13 09:00:29 +0200 | [diff] [blame] | 20 | //config: default y |
Denys Vlasenko | e3b1a1f | 2011-02-26 22:24:08 +0100 | [diff] [blame] | 21 | //config: select PLATFORM_LINUX |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 22 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame^] | 23 | //config: Dump the content of raw NAND chip |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 24 | |
Denys Vlasenko | c97578d | 2011-08-13 09:00:29 +0200 | [diff] [blame] | 25 | //applet:IF_NANDWRITE(APPLET(nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP)) |
Alexander Shiyan | 0d61dcd | 2013-03-15 00:27:41 +0100 | [diff] [blame] | 26 | //applet:IF_NANDDUMP(APPLET_ODDNAME(nanddump, nandwrite, BB_DIR_USR_SBIN, BB_SUID_DROP, nanddump)) |
Denys Vlasenko | c97578d | 2011-08-13 09:00:29 +0200 | [diff] [blame] | 27 | |
| 28 | //kbuild:lib-$(CONFIG_NANDWRITE) += nandwrite.o |
| 29 | //kbuild:lib-$(CONFIG_NANDDUMP) += nandwrite.o |
| 30 | |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 31 | //usage:#define nandwrite_trivial_usage |
Aaro Koskinen | 76915bf | 2015-12-19 22:34:44 +0200 | [diff] [blame] | 32 | //usage: "[-np] [-s ADDR] MTD_DEVICE [FILE]" |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 33 | //usage:#define nandwrite_full_usage "\n\n" |
Alexander Shiyan | 0d61dcd | 2013-03-15 00:27:41 +0100 | [diff] [blame] | 34 | //usage: "Write to MTD_DEVICE\n" |
Aaro Koskinen | 76915bf | 2015-12-19 22:34:44 +0200 | [diff] [blame] | 35 | //usage: "\n -n Write without ecc" |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 36 | //usage: "\n -p Pad to page size" |
| 37 | //usage: "\n -s ADDR Start address" |
| 38 | |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 39 | //usage:#define nanddump_trivial_usage |
Denys Vlasenko | bbc7bee | 2017-01-21 02:49:58 +0100 | [diff] [blame] | 40 | //usage: "[-no]" IF_LONG_OPTS(" [--bb padbad|skipbad]") " [-s ADDR] [-l LEN] [-f FILE] MTD_DEVICE" |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 41 | //usage:#define nanddump_full_usage "\n\n" |
Alexander Shiyan | 0d61dcd | 2013-03-15 00:27:41 +0100 | [diff] [blame] | 42 | //usage: "Dump MTD_DEVICE\n" |
Aaro Koskinen | 76915bf | 2015-12-19 22:34:44 +0200 | [diff] [blame] | 43 | //usage: "\n -n Read without ecc" |
Baruch Siach | 3aeb870 | 2012-10-15 14:32:23 +0200 | [diff] [blame] | 44 | //usage: "\n -o Dump oob data" |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 45 | //usage: "\n -s ADDR Start address" |
| 46 | //usage: "\n -l LEN Length" |
| 47 | //usage: "\n -f FILE Dump to file ('-' for stdout)" |
Baruch Siach | ad0d009 | 2014-12-18 00:27:26 +0200 | [diff] [blame] | 48 | //usage: IF_LONG_OPTS( |
Denys Vlasenko | bbc7bee | 2017-01-21 02:49:58 +0100 | [diff] [blame] | 49 | //usage: "\n --bb METHOD" |
Richard Genoud | f17fbe1 | 2014-06-24 12:12:59 +0200 | [diff] [blame] | 50 | //usage: "\n skipbad: skip bad blocks" |
| 51 | //usage: "\n padbad: substitute bad blocks by 0xff (default)" |
Baruch Siach | ad0d009 | 2014-12-18 00:27:26 +0200 | [diff] [blame] | 52 | //usage: ) |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 53 | |
| 54 | #include "libbb.h" |
| 55 | #include <mtd/mtd-user.h> |
| 56 | |
| 57 | #define IS_NANDDUMP (ENABLE_NANDDUMP && (!ENABLE_NANDWRITE || (applet_name[4] == 'd'))) |
| 58 | #define IS_NANDWRITE (ENABLE_NANDWRITE && (!ENABLE_NANDDUMP || (applet_name[4] != 'd'))) |
| 59 | |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 60 | #define OPT_p (1 << 0) /* nandwrite only */ |
| 61 | #define OPT_o (1 << 0) /* nanddump only */ |
Aaro Koskinen | 76915bf | 2015-12-19 22:34:44 +0200 | [diff] [blame] | 62 | #define OPT_n (1 << 1) |
| 63 | #define OPT_s (1 << 2) |
| 64 | #define OPT_f (1 << 3) |
| 65 | #define OPT_l (1 << 4) |
| 66 | #define OPT_bb (1 << 5) /* must be the last one in the list */ |
Richard Genoud | f17fbe1 | 2014-06-24 12:12:59 +0200 | [diff] [blame] | 67 | |
| 68 | #define BB_PADBAD (1 << 0) |
| 69 | #define BB_SKIPBAD (1 << 1) |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 70 | |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 71 | /* helper for writing out 0xff for bad blocks pad */ |
| 72 | static void dump_bad(struct mtd_info_user *meminfo, unsigned len, int oob) |
| 73 | { |
| 74 | unsigned char buf[meminfo->writesize]; |
| 75 | unsigned count; |
| 76 | |
Richard Genoud | cbf3bfa | 2014-06-24 12:12:58 +0200 | [diff] [blame] | 77 | /* round len to the next page only if len is not already on a page */ |
| 78 | len = ((len - 1) | (meminfo->writesize - 1)) + 1; |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 79 | |
| 80 | memset(buf, 0xff, sizeof(buf)); |
| 81 | for (count = 0; count < len; count += meminfo->writesize) { |
| 82 | xwrite(STDOUT_FILENO, buf, meminfo->writesize); |
| 83 | if (oob) |
| 84 | xwrite(STDOUT_FILENO, buf, meminfo->oobsize); |
| 85 | } |
| 86 | } |
| 87 | |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 88 | static unsigned next_good_eraseblock(int fd, struct mtd_info_user *meminfo, |
| 89 | unsigned block_offset) |
| 90 | { |
| 91 | while (1) { |
| 92 | loff_t offs; |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 93 | |
| 94 | if (block_offset >= meminfo->size) { |
| 95 | if (IS_NANDWRITE) |
| 96 | bb_error_msg_and_die("not enough space in MTD device"); |
| 97 | return block_offset; /* let the caller exit */ |
| 98 | } |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 99 | offs = block_offset; |
| 100 | if (xioctl(fd, MEMGETBADBLOCK, &offs) == 0) |
| 101 | return block_offset; |
| 102 | /* ioctl returned 1 => "bad block" */ |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 103 | if (IS_NANDWRITE) |
| 104 | printf("Skipping bad block at 0x%08x\n", block_offset); |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 105 | block_offset += meminfo->erasesize; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | int nandwrite_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 110 | int nandwrite_main(int argc UNUSED_PARAM, char **argv) |
| 111 | { |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 112 | /* Buffer for OOB data */ |
Baruch Siach | d982da7 | 2010-10-18 11:35:30 +0200 | [diff] [blame] | 113 | unsigned char *oobbuf; |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 114 | unsigned opts; |
Richard Genoud | 2a870d0 | 2014-06-25 17:38:30 +0200 | [diff] [blame] | 115 | unsigned bb_method = BB_SKIPBAD; |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 116 | int fd; |
| 117 | ssize_t cnt; |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 118 | unsigned mtdoffset, meminfo_writesize, blockstart, limit; |
| 119 | unsigned end_addr = ~0; |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 120 | struct mtd_info_user meminfo; |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 121 | struct mtd_oob_buf oob; |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 122 | unsigned char *filebuf; |
Richard Genoud | f17fbe1 | 2014-06-24 12:12:59 +0200 | [diff] [blame] | 123 | const char *opt_s = "0", *opt_f = "-", *opt_l, *opt_bb; |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 124 | |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 125 | if (IS_NANDDUMP) { |
| 126 | opt_complementary = "=1"; |
Baruch Siach | e835afa | 2014-12-17 17:02:37 +0100 | [diff] [blame] | 127 | #if ENABLE_LONG_OPTS |
| 128 | applet_long_options = |
| 129 | "bb\0" Required_argument "\xff"; /* no short equivalent */ |
| 130 | #endif |
Aaro Koskinen | 76915bf | 2015-12-19 22:34:44 +0200 | [diff] [blame] | 131 | opts = getopt32(argv, "ons:f:l:", &opt_s, &opt_f, &opt_l, &opt_bb); |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 132 | } else { /* nandwrite */ |
| 133 | opt_complementary = "-1:?2"; |
Aaro Koskinen | 76915bf | 2015-12-19 22:34:44 +0200 | [diff] [blame] | 134 | opts = getopt32(argv, "pns:", &opt_s); |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 135 | } |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 136 | argv += optind; |
| 137 | |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 138 | if (IS_NANDWRITE && argv[1]) |
| 139 | opt_f = argv[1]; |
| 140 | if (!LONE_DASH(opt_f)) { |
| 141 | int tmp_fd = xopen(opt_f, |
| 142 | IS_NANDDUMP ? O_WRONLY | O_TRUNC | O_CREAT : O_RDONLY |
| 143 | ); |
| 144 | xmove_fd(tmp_fd, IS_NANDDUMP ? STDOUT_FILENO : STDIN_FILENO); |
| 145 | } |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 146 | |
Matt Reimer | 6979325 | 2012-05-30 10:31:13 -0400 | [diff] [blame] | 147 | fd = xopen(argv[0], IS_NANDWRITE ? O_RDWR : O_RDONLY); |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 148 | xioctl(fd, MEMGETINFO, &meminfo); |
| 149 | |
Aaro Koskinen | 76915bf | 2015-12-19 22:34:44 +0200 | [diff] [blame] | 150 | if (opts & OPT_n) |
| 151 | xioctl(fd, MTDFILEMODE, (void *)MTD_FILE_MODE_RAW); |
| 152 | |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 153 | mtdoffset = xstrtou(opt_s, 0); |
| 154 | if (IS_NANDDUMP && (opts & OPT_l)) { |
| 155 | unsigned length = xstrtou(opt_l, 0); |
| 156 | if (length < meminfo.size - mtdoffset) |
| 157 | end_addr = mtdoffset + length; |
| 158 | } |
Richard Genoud | 8feb259 | 2014-06-25 17:33:34 +0200 | [diff] [blame] | 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(); |
Richard Genoud | f17fbe1 | 2014-06-24 12:12:59 +0200 | [diff] [blame] | 166 | } |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 167 | |
| 168 | /* Pull it into a CPU register (hopefully) - smaller code that way */ |
| 169 | meminfo_writesize = meminfo.writesize; |
| 170 | |
| 171 | if (mtdoffset & (meminfo_writesize - 1)) |
| 172 | bb_error_msg_and_die("start address is not page aligned"); |
| 173 | |
| 174 | filebuf = xmalloc(meminfo_writesize); |
Baruch Siach | d982da7 | 2010-10-18 11:35:30 +0200 | [diff] [blame] | 175 | oobbuf = xmalloc(meminfo.oobsize); |
| 176 | |
| 177 | oob.start = 0; |
| 178 | oob.length = meminfo.oobsize; |
| 179 | oob.ptr = oobbuf; |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 180 | |
Baruch Siach | 7715b48 | 2010-08-29 10:36:50 +0300 | [diff] [blame] | 181 | blockstart = mtdoffset & ~(meminfo.erasesize - 1); |
| 182 | if (blockstart != mtdoffset) { |
| 183 | unsigned tmp; |
| 184 | /* mtdoffset is in the middle of an erase block, verify that |
| 185 | * this block is OK. Advance mtdoffset only if this block is |
| 186 | * bad. |
| 187 | */ |
| 188 | tmp = next_good_eraseblock(fd, &meminfo, blockstart); |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 189 | if (tmp != blockstart) { |
| 190 | /* bad block(s), advance mtdoffset */ |
Richard Genoud | f17fbe1 | 2014-06-24 12:12:59 +0200 | [diff] [blame] | 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 | } |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 200 | } |
Baruch Siach | 7715b48 | 2010-08-29 10:36:50 +0300 | [diff] [blame] | 201 | mtdoffset = tmp; |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 202 | } |
Baruch Siach | 7715b48 | 2010-08-29 10:36:50 +0300 | [diff] [blame] | 203 | } |
| 204 | |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 205 | cnt = -1; |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 206 | limit = MIN(meminfo.size, end_addr); |
| 207 | while (mtdoffset < limit) { |
| 208 | int input_fd = IS_NANDWRITE ? STDIN_FILENO : fd; |
| 209 | int output_fd = IS_NANDWRITE ? fd : STDOUT_FILENO; |
| 210 | |
Baruch Siach | 7715b48 | 2010-08-29 10:36:50 +0300 | [diff] [blame] | 211 | blockstart = mtdoffset & ~(meminfo.erasesize - 1); |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 212 | if (blockstart == mtdoffset) { |
| 213 | /* starting a new eraseblock */ |
| 214 | mtdoffset = next_good_eraseblock(fd, &meminfo, blockstart); |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 215 | if (IS_NANDWRITE) |
| 216 | printf("Writing at 0x%08x\n", mtdoffset); |
Richard Genoud | f17fbe1 | 2014-06-24 12:12:59 +0200 | [diff] [blame] | 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 | } |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 230 | } |
| 231 | if (mtdoffset >= limit) |
| 232 | break; |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 233 | } |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 234 | xlseek(fd, mtdoffset, SEEK_SET); |
| 235 | |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 236 | /* get some more data from input */ |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 237 | cnt = full_read(input_fd, filebuf, meminfo_writesize); |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 238 | if (cnt == 0) { |
| 239 | /* even with -p, we do not pad past the end of input |
| 240 | * (-p only zero-pads last incomplete page) |
| 241 | */ |
| 242 | break; |
| 243 | } |
| 244 | if (cnt < meminfo_writesize) { |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 245 | if (IS_NANDDUMP) |
| 246 | bb_error_msg_and_die("short read"); |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 247 | if (!(opts & OPT_p)) |
| 248 | bb_error_msg_and_die("input size is not rounded up to page size, " |
| 249 | "use -p to zero pad"); |
| 250 | /* zero pad to end of write block */ |
| 251 | memset(filebuf + cnt, 0, meminfo_writesize - cnt); |
| 252 | } |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 253 | xwrite(output_fd, filebuf, meminfo_writesize); |
| 254 | |
Baruch Siach | 3aeb870 | 2012-10-15 14:32:23 +0200 | [diff] [blame] | 255 | if (IS_NANDDUMP && (opts & OPT_o)) { |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 256 | /* Dump OOB data */ |
| 257 | oob.start = mtdoffset; |
| 258 | xioctl(fd, MEMREADOOB, &oob); |
| 259 | xwrite(output_fd, oobbuf, meminfo.oobsize); |
| 260 | } |
| 261 | |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 262 | mtdoffset += meminfo_writesize; |
| 263 | if (cnt < meminfo_writesize) |
| 264 | break; |
| 265 | } |
| 266 | |
Baruch Siach | 36af2f7 | 2010-10-18 02:36:34 +0200 | [diff] [blame] | 267 | if (IS_NANDWRITE && cnt != 0) { |
Baruch Siach | 6f32ea4 | 2010-08-25 16:36:17 +0200 | [diff] [blame] | 268 | /* We filled entire MTD, but did we reach EOF on input? */ |
| 269 | if (full_read(STDIN_FILENO, filebuf, meminfo_writesize) != 0) { |
| 270 | /* no */ |
| 271 | bb_error_msg_and_die("not enough space in MTD device"); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 276 | free(filebuf); |
| 277 | close(fd); |
| 278 | } |
| 279 | |
| 280 | return EXIT_SUCCESS; |
| 281 | } |