]> www.infradead.org Git - mtd-utils.git/commitdiff
libmtd: modify `mtd_write' to cover OOB writes
authorBrian Norris <computersforpeace@gmail.com>
Wed, 31 Aug 2011 20:00:33 +0000 (13:00 -0700)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Sun, 11 Sep 2011 13:11:41 +0000 (16:11 +0300)
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 <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
include/libmtd.h
lib/libmtd.c
nandwrite.c
ubi-utils/ubiformat.c

index 9efccbc12827c67701514cb14ec241c086afba4a..07c304a6b922341612c40154990e29e45963b337 100644 (file)
@@ -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.
index c34874ee642c6662eb5cd6287302233d98479664..746ea693a6c3aa6e52df3df9b4ac765da423c44e 100644 (file)
@@ -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);
index 3eea6e243ce2f603ad81e69b54488aa4489d3618..33a3b8fb345129a11420742c17d359e13b8ccf7b 100644 (file)
@@ -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);
index bfa17300d3e7cbcb273f1d0b401d49ef6e04f1c1..ed2b8d001e68a594593e7798280317111e91083d 100644 (file)
@@ -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");