From e413d17f8bd6c680a4f792006932a070ce504120 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Fri, 9 Sep 2011 10:11:49 -0700 Subject: mtd-utils: update mtd-abi.h Kernel ABI header added a new ioctl, killed an old one, and exposed OOB modes to user-space. Plus, it added a lot of documentation. We have some trivial name changes for some MTD mode constants as well. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy --- nandwrite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nandwrite.c') diff --git a/nandwrite.c b/nandwrite.c index 066ef55..3eea6e2 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -274,7 +274,7 @@ int main(int argc, char * const argv[]) } if (noecc) { - ret = ioctl(fd, MTDFILEMODE, MTD_MODE_RAW); + ret = ioctl(fd, MTDFILEMODE, MTD_FILE_MODE_RAW); if (ret) { switch (errno) { case ENOTTY: -- cgit v1.2.3 From cd42aea270e84884e6bbac845414568f0febbedf Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 31 Aug 2011 13:00:33 -0700 Subject: libmtd: modify `mtd_write' to cover OOB writes To support the MEMWRITE ioctl, we will need a different sort of libmtd interface for writing to flash. We will expand mtd_write to include more functionality; for now, we just change the function definition and description as we begin to add the actual functionality. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy --- include/libmtd.h | 15 +++++++++++---- lib/libmtd.c | 10 ++++++---- nandwrite.c | 4 ++-- ubi-utils/ubiformat.c | 6 ++++-- 4 files changed, 23 insertions(+), 12 deletions(-) (limited to 'nandwrite.c') diff --git a/include/libmtd.h b/include/libmtd.h index 9efccbc..07c304a 100644 --- a/include/libmtd.h +++ b/include/libmtd.h @@ -255,19 +255,26 @@ int mtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs, /** * mtd_write - write data to an MTD device. + * @desc: MTD library descriptor * @mtd: MTD device description object * @fd: MTD device node file descriptor * @eb: eraseblock to write to * @offs: offset withing the eraseblock to write to - * @buf: buffer to write - * @len: how many bytes to write + * @data: data buffer to write + * @len: how many data bytes to write + * @oob: OOB buffer to write + * @ooblen: how many OOB bytes to write + * @mode: write mode (e.g., %MTD_OOB_PLACE, %MTD_OOB_RAW) * * This function writes @len bytes of data to eraseblock @eb and offset @offs * of the MTD device defined by @mtd. Returns %0 in case of success and %-1 in * case of failure. + * + * Can only write to a single page at a time if writing to OOB. */ -int mtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs, - void *buf, int len); +int mtd_write(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb, + int offs, void *data, int len, void *oob, int ooblen, + uint8_t mode); /** * mtd_read_oob - read out-of-band area. diff --git a/lib/libmtd.c b/lib/libmtd.c index c34874e..746ea69 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -970,7 +970,8 @@ int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb) /* Write a pattern and check it */ memset(buf, patterns[i], mtd->eb_size); - err = mtd_write(mtd, fd, eb, 0, buf, mtd->eb_size); + err = mtd_write(desc, mtd, fd, eb, 0, buf, mtd->eb_size, NULL, + 0, 0); if (err) goto out; @@ -1070,8 +1071,9 @@ int mtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs, return 0; } -int mtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs, - void *buf, int len) +int mtd_write(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb, + int offs, void *data, int len, void *oob, int ooblen, + uint8_t mode) { int ret; off_t seek; @@ -1105,7 +1107,7 @@ int mtd_write(const struct mtd_dev_info *mtd, int fd, int eb, int offs, return sys_errmsg("cannot seek mtd%d to offset %llu", mtd->mtd_num, (unsigned long long)seek); - ret = write(fd, buf, len); + ret = write(fd, data, len); if (ret != len) return sys_errmsg("cannot write %d bytes to mtd%d (eraseblock %d, offset %d)", len, mtd->mtd_num, eb, offs); diff --git a/nandwrite.c b/nandwrite.c index 3eea6e2..33a3b8f 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -543,8 +543,8 @@ int main(int argc, char * const argv[]) } /* Write out the Page data */ - if (!onlyoob && mtd_write(&mtd, fd, mtdoffset / mtd.eb_size, mtdoffset % mtd.eb_size, - writebuf, mtd.min_io_size)) { + if (!onlyoob && mtd_write(mtd_desc, &mtd, fd, mtdoffset / mtd.eb_size, mtdoffset % mtd.eb_size, + writebuf, mtd.min_io_size, NULL, 0, 0)) { int i; if (errno != EIO) { sys_errmsg("%s: MTD write failure", mtd_device); diff --git a/ubi-utils/ubiformat.c b/ubi-utils/ubiformat.c index bfa1730..ed2b8d0 100644 --- a/ubi-utils/ubiformat.c +++ b/ubi-utils/ubiformat.c @@ -534,7 +534,8 @@ static int flash_image(libmtd_t libmtd, const struct mtd_dev_info *mtd, new_len = drop_ffs(mtd, buf, mtd->eb_size); - err = mtd_write(mtd, args.node_fd, eb, 0, buf, new_len); + err = mtd_write(libmtd, mtd, args.node_fd, eb, 0, buf, new_len, + NULL, 0, 0); if (err) { sys_errmsg("cannot write eraseblock %d", eb); @@ -637,7 +638,8 @@ static int format(libmtd_t libmtd, const struct mtd_dev_info *mtd, fflush(stdout); } - err = mtd_write(mtd, args.node_fd, eb, 0, hdr, write_size); + err = mtd_write(libmtd, mtd, args.node_fd, eb, 0, hdr, + write_size, NULL, 0, 0); if (err) { if (!args.quiet && !args.verbose) printf("\n"); -- cgit v1.2.3 From 040c937ca2c5ae1f35c24a3cc0154e9a31df5933 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 31 Aug 2011 13:00:35 -0700 Subject: nandwrite: merge `mtd_write_oob' and `mtd_write' calls Now that `mtd_write' can write to both OOB and data regions, we need to perform our `mtd_write' call only once. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy --- nandwrite.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'nandwrite.c') diff --git a/nandwrite.c b/nandwrite.c index 33a3b8f..a78b0b6 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -534,17 +534,17 @@ int main(int argc, char * const argv[]) } else { memcpy(oobbuf, oobreadbuf, mtd.oob_size); } - /* Write OOB data first, as ecc will be placed in there */ - if (mtd_write_oob(mtd_desc, &mtd, fd, mtdoffset, - mtd.oob_size, oobbuf)) { - sys_errmsg("%s: MTD writeoob failure", mtd_device); - goto closeall; - } } - /* Write out the Page data */ - if (!onlyoob && mtd_write(mtd_desc, &mtd, fd, mtdoffset / mtd.eb_size, mtdoffset % mtd.eb_size, - writebuf, mtd.min_io_size, NULL, 0, 0)) { + /* Write out data */ + ret = mtd_write(mtd_desc, &mtd, fd, mtdoffset / mtd.eb_size, + mtdoffset % mtd.eb_size, + onlyoob ? NULL : writebuf, + onlyoob ? 0 : mtd.min_io_size, + writeoob ? oobbuf : NULL, + writeoob ? mtd.oob_size : 0, + noecc ? MTD_OPS_RAW : MTD_OPS_PLACE_OOB); + if (ret) { int i; if (errno != EIO) { sys_errmsg("%s: MTD write failure", mtd_device); -- cgit v1.2.3 From c4c8cdf621a5d1ea4f0f01ff004c6f1c33be9daa Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 31 Aug 2011 13:00:36 -0700 Subject: mtdutils: move OOB auto-layout into libmtd's mtd_write With the addition of the the new ioctl(MEMWRITE), we can use the kernel's internal OOB autoplacement option. It's a cleaner interface and avoids too much duplication of coding effort. This patch moves any legacy code (using MEMGETOOBSEL) into a legacy function in libmtd.c. It's not exactly a "pre-2.6.30" feature, so I'm not moving it to libmtd_legacy.c. Now, autoplacement features are only activated if we call mtd_write with mode == MTD_OPS_AUTO_OOB. This should fix some discrepancies for nandwrite, where we weren't handling OOB consistently (i.e., we had different functionality when the kernel did/didn't support MEMWRITE). But that also means that we now default to using MTD_OPS_PLACE_OOB instead of AUTO layout. To re-enable autoplacement, we can re-implement the `--autoplace' option that had previously rotted. This patch also cleans up a need for an extra OOB buffer in nandwrite. This has been tested a little in nandsim as well as on SLC NAND flash. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy --- lib/libmtd.c | 39 +++++++++++++++++++++++++++++++++++++++ nandwrite.c | 53 ++++------------------------------------------------- 2 files changed, 43 insertions(+), 49 deletions(-) (limited to 'nandwrite.c') diff --git a/lib/libmtd.c b/lib/libmtd.c index d47b307..1b16de5 100644 --- a/lib/libmtd.c +++ b/lib/libmtd.c @@ -1071,6 +1071,42 @@ int mtd_read(const struct mtd_dev_info *mtd, int fd, int eb, int offs, return 0; } +static int legacy_auto_oob_layout(const struct mtd_dev_info *mtd, int fd, + int ooblen, void *oob) { + struct nand_oobinfo old_oobinfo; + int start, len; + uint8_t *tmp_buf; + + /* Read the current oob info */ + if (ioctl(fd, MEMGETOOBSEL, &old_oobinfo)) + return sys_errmsg("MEMGETOOBSEL failed"); + + tmp_buf = malloc(ooblen); + memcpy(tmp_buf, oob, ooblen); + + /* + * We use autoplacement and have the oobinfo with the autoplacement + * information from the kernel available + */ + if (old_oobinfo.useecc == MTD_NANDECC_AUTOPLACE) { + int i, tags_pos = 0; + for (i = 0; old_oobinfo.oobfree[i][1]; i++) { + /* Set the reserved bytes to 0xff */ + start = old_oobinfo.oobfree[i][0]; + len = old_oobinfo.oobfree[i][1]; + memcpy(oob + start, tmp_buf + tags_pos, len); + tags_pos += len; + } + } else { + /* Set at least the ecc byte positions to 0xff */ + start = old_oobinfo.eccbytes; + len = mtd->oob_size - start; + memcpy(oob + start, tmp_buf + start, len); + } + + return 0; +} + int mtd_write(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb, int offs, void *data, int len, void *oob, int ooblen, uint8_t mode) @@ -1120,6 +1156,9 @@ int mtd_write(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb, /* Fall back to old methods if necessary */ if (oob) { + if (mode == MTD_OPS_AUTO_OOB) + if (legacy_auto_oob_layout(mtd, fd, ooblen, oob)) + return -1; if (mtd_write_oob(desc, mtd, fd, seek, ooblen, oob) < 0) return sys_errmsg("cannot write to OOB"); } diff --git a/nandwrite.c b/nandwrite.c index a78b0b6..920863f 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -233,7 +233,6 @@ int main(int argc, char * const argv[]) /* points to the current page inside filebuf */ unsigned char *writebuf = NULL; /* points to the OOB for the current page in filebuf */ - unsigned char *oobreadbuf = NULL; unsigned char *oobbuf = NULL; libmtd_t mtd_desc; int ebsize_aligned; @@ -345,9 +344,6 @@ int main(int argc, char * const argv[]) filebuf = xmalloc(filebuf_max); erase_buffer(filebuf, filebuf_max); - oobbuf = xmalloc(mtd.oob_size); - erase_buffer(oobbuf, mtd.oob_size); - /* * Get data from input and write to the device while there is * still input to read and we are still within the device @@ -460,16 +456,16 @@ int main(int argc, char * const argv[]) } if (writeoob) { - oobreadbuf = writebuf + mtd.min_io_size; + oobbuf = writebuf + mtd.min_io_size; /* Read more data for the OOB from the input if there isn't enough in the buffer */ - if ((oobreadbuf + mtd.oob_size) > (filebuf + filebuf_len)) { + if ((oobbuf + mtd.oob_size) > (filebuf + filebuf_len)) { int readlen = mtd.oob_size; - int alreadyread = (filebuf + filebuf_len) - oobreadbuf; + int alreadyread = (filebuf + filebuf_len) - oobbuf; int tinycnt = alreadyread; while (tinycnt < readlen) { - cnt = read(ifd, oobreadbuf + tinycnt, readlen - tinycnt); + cnt = read(ifd, oobbuf + tinycnt, readlen - tinycnt); if (cnt == 0) { /* EOF */ break; } else if (cnt < 0) { @@ -494,46 +490,6 @@ int main(int argc, char * const argv[]) imglen = 0; } } - - if (!noecc) { - int start, len; - struct nand_oobinfo old_oobinfo; - - /* Read the current oob info */ - if (ioctl(fd, MEMGETOOBSEL, &old_oobinfo) != 0) { - perror("MEMGETOOBSEL"); - close(fd); - exit(EXIT_FAILURE); - } - - /* - * We use autoplacement and have the oobinfo with the autoplacement - * information from the kernel available - * - * Modified to support out of order oobfree segments, - * such as the layout used by diskonchip.c - */ - if (old_oobinfo.useecc == MTD_NANDECC_AUTOPLACE) { - int i, tags_pos = 0, tmp_ofs; - for (i = 0; old_oobinfo.oobfree[i][1]; i++) { - /* Set the reserved bytes to 0xff */ - start = old_oobinfo.oobfree[i][0]; - len = old_oobinfo.oobfree[i][1]; - tmp_ofs = rawoob ? start : tags_pos; - memcpy(oobbuf + start, oobreadbuf + tmp_ofs, len); - tags_pos += len; - } - } else { - /* Set at least the ecc byte positions to 0xff */ - start = old_oobinfo.eccbytes; - len = mtd.oob_size - start; - memcpy(oobbuf + start, - oobreadbuf + start, - len); - } - } else { - memcpy(oobbuf, oobreadbuf, mtd.oob_size); - } } /* Write out data */ @@ -588,7 +544,6 @@ closeall: close(ifd); libmtd_close(mtd_desc); free(filebuf); - free(oobbuf); close(fd); if (failed -- cgit v1.2.3 From 647e385da091396a42617232ad3e59734bca110a Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 31 Aug 2011 13:00:37 -0700 Subject: nandwrite: kill `--raw' option The `--raw' option has lost all usefulness as it overlapped with several other OOB modes. I cannot even figure out what it was actually intended to do, but I'm sure its functionality fits somewhere in the MTD_OPS_{AUTO_OOB,PLACE_OOB,RAW} options, which are mostly implemented in libmtd's mtd_write(). I don't think users need a warning for this one, unless someone can tell me what it actually was supposed to have done in the first place. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy --- nandwrite.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'nandwrite.c') diff --git a/nandwrite.c b/nandwrite.c index 920863f..45782c7 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -54,7 +54,6 @@ static void display_help(void) " -N, --noskipbad Write without bad block skipping\n" " -o, --oob Image contains oob data\n" " -O, --onlyoob Image contains oob data and only write the oob part\n" -" -r, --raw Image contains the raw oob data dumped by nanddump\n" " -s addr, --start=addr Set start address (default is 0)\n" " -p, --pad Pad to page size\n" " -b, --blockalign=1|2|4 Set multiple of eraseblocks to align to\n" @@ -86,7 +85,6 @@ static const char *mtd_device, *img; static long long mtdoffset = 0; static bool quiet = false; static bool writeoob = false; -static bool rawoob = false; static bool onlyoob = false; static bool markbad = false; static bool noecc = false; @@ -100,7 +98,7 @@ static void process_options(int argc, char * const argv[]) for (;;) { int option_index = 0; - static const char *short_options = "b:mnNoOpqrs:"; + static const char *short_options = "b:mnNoOpqs:"; static const struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, @@ -112,7 +110,6 @@ static void process_options(int argc, char * const argv[]) {"onlyoob", no_argument, 0, 'O'}, {"pad", no_argument, 0, 'p'}, {"quiet", no_argument, 0, 'q'}, - {"raw", no_argument, 0, 'r'}, {"start", required_argument, 0, 's'}, {0, 0, 0, 0}, }; @@ -156,10 +153,6 @@ static void process_options(int argc, char * const argv[]) case 'p': pad = true; break; - case 'r': - rawoob = true; - writeoob = true; - break; case 's': mtdoffset = simple_strtoll(optarg, &error); break; -- cgit v1.2.3 From e3867cfa7cbfab9c2aa192ad6969afb438fc0136 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 31 Aug 2011 13:00:38 -0700 Subject: nandwrite: re-implement `--autoplace' option The restructuring of mtd_write() has allowed us to use `--autoplace' somewhat successfully; it is supported by the new ioctl(MEMWRITE) as well as some legacy code utilizing the deprecated ioctl(MEMGETOOBSEL). Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy --- nandwrite.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'nandwrite.c') diff --git a/nandwrite.c b/nandwrite.c index 45782c7..ca72f16 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -49,6 +49,7 @@ static void display_help(void) "Usage: nandwrite [OPTION] MTD_DEVICE [INPUTFILE|-]\n" "Writes to the specified MTD device.\n" "\n" +" -a, --autoplace Use auto OOB layout\n" " -m, --markbad Mark blocks bad if write fails\n" " -n, --noecc Write without ecc\n" " -N, --noskipbad Write without bad block skipping\n" @@ -88,6 +89,7 @@ static bool writeoob = false; static bool onlyoob = false; static bool markbad = false; static bool noecc = false; +static bool autoplace = false; static bool noskipbad = false; static bool pad = false; static int blockalign = 1; /* default to using actual block size */ @@ -98,7 +100,7 @@ static void process_options(int argc, char * const argv[]) for (;;) { int option_index = 0; - static const char *short_options = "b:mnNoOpqs:"; + static const char *short_options = "b:mnNoOpqs:a"; static const struct option long_options[] = { {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, @@ -111,6 +113,7 @@ static void process_options(int argc, char * const argv[]) {"pad", no_argument, 0, 'p'}, {"quiet", no_argument, 0, 'q'}, {"start", required_argument, 0, 's'}, + {"autoplace", no_argument, 0, 'a'}, {0, 0, 0, 0}, }; @@ -159,6 +162,9 @@ static void process_options(int argc, char * const argv[]) case 'b': blockalign = atoi(optarg); break; + case 'a': + autoplace = true; + break; case '?': error++; break; @@ -173,6 +179,9 @@ static void process_options(int argc, char * const argv[]) errmsg_die("Can't specify negative blockalign with option -b:" " %d", blockalign); + if (autoplace && noecc) + errmsg_die("Autoplacement and no-ECC are mutually exclusive"); + argc -= optind; argv += optind; @@ -229,6 +238,7 @@ int main(int argc, char * const argv[]) unsigned char *oobbuf = NULL; libmtd_t mtd_desc; int ebsize_aligned; + uint8_t write_mode; process_options(argc, argv); @@ -265,6 +275,14 @@ int main(int argc, char * const argv[]) exit(EXIT_FAILURE); } + /* Select OOB write mode */ + if (noecc) + write_mode = MTD_OPS_RAW; + else if (autoplace) + write_mode = MTD_OPS_AUTO_OOB; + else + write_mode = MTD_OPS_PLACE_OOB; + if (noecc) { ret = ioctl(fd, MTDFILEMODE, MTD_FILE_MODE_RAW); if (ret) { @@ -492,7 +510,7 @@ int main(int argc, char * const argv[]) onlyoob ? 0 : mtd.min_io_size, writeoob ? oobbuf : NULL, writeoob ? mtd.oob_size : 0, - noecc ? MTD_OPS_RAW : MTD_OPS_PLACE_OOB); + write_mode); if (ret) { int i; if (errno != EIO) { -- cgit v1.2.3 From 0970bf408707d610e88abb069b123e267aeb42f8 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 31 Aug 2011 13:00:39 -0700 Subject: nandwrite: use common.h "errmsg" functions Convert several forms of exit(), perror(), etc. to use common.h helper functions. Also, move one of our parameter checks inside the process_options() function for consistency. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy --- nandwrite.c | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) (limited to 'nandwrite.c') diff --git a/nandwrite.c b/nandwrite.c index ca72f16..a42f7c9 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -182,6 +182,9 @@ static void process_options(int argc, char * const argv[]) if (autoplace && noecc) errmsg_die("Autoplacement and no-ECC are mutually exclusive"); + if (!onlyoob && (pad && writeoob)) + errmsg_die("Can't pad when oob data is present"); + argc -= optind; argv += optind; @@ -242,23 +245,16 @@ int main(int argc, char * const argv[]) process_options(argc, argv); - if (!onlyoob && (pad && writeoob)) { - fprintf(stderr, "Can't pad when oob data is present.\n"); - exit(EXIT_FAILURE); - } - /* Open the device */ - if ((fd = open(mtd_device, O_RDWR)) == -1) { - perror(mtd_device); - exit(EXIT_FAILURE); - } + if ((fd = open(mtd_device, O_RDWR)) == -1) + sys_errmsg_die("%s", mtd_device); mtd_desc = libmtd_open(); if (!mtd_desc) - return errmsg("can't initialize libmtd"); + errmsg_die("can't initialize libmtd"); /* Fill in MTD device capability structure */ if (mtd_get_dev_info(mtd_desc, mtd_device, &mtd) < 0) - return errmsg("mtd_get_dev_info failed"); + errmsg_die("mtd_get_dev_info failed"); /* * Pretend erasesize is specified number of blocks - to match jffs2 @@ -267,13 +263,10 @@ int main(int argc, char * const argv[]) */ ebsize_aligned = mtd.eb_size * blockalign; - if (mtdoffset & (mtd.min_io_size - 1)) { - fprintf(stderr, "The start address is not page-aligned !\n" - "The pagesize of this NAND Flash is 0x%x.\n", - mtd.min_io_size); - close(fd); - exit(EXIT_FAILURE); - } + if (mtdoffset & (mtd.min_io_size - 1)) + errmsg_die("The start address is not page-aligned !\n" + "The pagesize of this NAND Flash is 0x%x.\n", + mtd.min_io_size); /* Select OOB write mode */ if (noecc) @@ -290,9 +283,7 @@ int main(int argc, char * const argv[]) case ENOTTY: errmsg_die("ioctl MTDFILEMODE is missing"); default: - perror("MTDFILEMODE"); - close(fd); - exit(EXIT_FAILURE); + sys_errmsg_die("MTDFILEMODE"); } } } @@ -341,7 +332,7 @@ int main(int argc, char * const argv[]) fprintf(stderr, "Image %d bytes, NAND page %d bytes, OOB area %d" " bytes, device size %lld bytes\n", imglen, pagelen, mtd.oob_size, mtd.size); - perror("Input file does not fit into device"); + sys_errmsg("Input file does not fit into device"); goto closeall; } @@ -557,12 +548,9 @@ closeall: free(filebuf); close(fd); - if (failed - || ((ifd != STDIN_FILENO) && (imglen > 0)) - || (writebuf < (filebuf + filebuf_len))) { - perror("Data was only partially written due to error\n"); - exit(EXIT_FAILURE); - } + if (failed || ((ifd != STDIN_FILENO) && (imglen > 0)) + || (writebuf < (filebuf + filebuf_len))) + sys_errmsg_die("Data was only partially written due to error"); /* Return happy */ return EXIT_SUCCESS; -- cgit v1.2.3