summaryrefslogtreecommitdiff
path: root/ubi-utils/src/ubiformat.c
diff options
context:
space:
mode:
authorArtem Bityutskiy <dedekind1@gmail.com>2010-07-17 20:08:33 +0300
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2010-07-26 08:37:00 +0300
commitf1e870c3e9a1a80be7a1d886d61ccac0f8e97e10 (patch)
tree6860d01fa73cba0bb5de6fcf4a19b7a2ac007e55 /ubi-utils/src/ubiformat.c
parent05f56bf49ee0de8979c29c11f61a01e30e964444 (diff)
libmtd: support MEMERASE64
This patch is base on Kevin Cernekee's patch posted to the MTD mailing list. It adds MEMERASE64 support to the 'mtd_erase()' call. Now it first tries to use MEMERASE64, and if that is not supported, falls back to the old MEMERASE ioctl. This patch also introduces an 'offs64_ioctl' flag to the libmtd descriptor. However, we cannot initialize it in 'libmtd_open()', because we need an MTD device node, which we do not have in 'libmtd_open()'. Thus, we firs mark this flag as "uninitialized", and at the first invocation of 'mtd_erase()' we initialize it. This also means that we have to pass the limbtd descriptor to 'mtd_erase()', to save the flag value. This, in turn, requires tweaking 'mtd_erase()' users. This is not very nice, but good enough so far. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'ubi-utils/src/ubiformat.c')
-rw-r--r--ubi-utils/src/ubiformat.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/ubi-utils/src/ubiformat.c b/ubi-utils/src/ubiformat.c
index 6052a35..4e27e4f 100644
--- a/ubi-utils/src/ubiformat.c
+++ b/ubi-utils/src/ubiformat.c
@@ -441,8 +441,8 @@ static int mark_bad(const struct mtd_dev_info *mtd, struct ubi_scan_info *si, in
return consecutive_bad_check(eb);
}
-static int flash_image(const struct mtd_dev_info *mtd, const struct ubigen_info *ui,
- struct ubi_scan_info *si)
+static int flash_image(libmtd_t libmtd, const struct mtd_dev_info *mtd,
+ const struct ubigen_info *ui, struct ubi_scan_info *si)
{
int fd, img_ebs, eb, written_ebs = 0, divisor;
off_t st_size;
@@ -488,7 +488,7 @@ static int flash_image(const struct mtd_dev_info *mtd, const struct ubigen_info
fflush(stdout);
}
- err = mtd_erase(mtd, args.node_fd, eb);
+ err = mtd_erase(libmtd, mtd, args.node_fd, eb);
if (err) {
if (!args.quiet)
printf("\n");
@@ -543,7 +543,7 @@ static int flash_image(const struct mtd_dev_info *mtd, const struct ubigen_info
if (errno != EIO)
goto out_close;
- err = mtd_torture(mtd, args.node_fd, eb);
+ err = mtd_torture(libmtd, mtd, args.node_fd, eb);
if (err) {
if (mark_bad(mtd, si, eb))
goto out_close;
@@ -564,8 +564,9 @@ out_close:
return -1;
}
-static int format(const struct mtd_dev_info *mtd, const struct ubigen_info *ui,
- struct ubi_scan_info *si, int start_eb, int novtbl)
+static int format(libmtd_t libmtd, const struct mtd_dev_info *mtd,
+ const struct ubigen_info *ui, struct ubi_scan_info *si,
+ int start_eb, int novtbl)
{
int eb, err, write_size;
struct ubi_ec_hdr *hdr;
@@ -606,7 +607,7 @@ static int format(const struct mtd_dev_info *mtd, const struct ubigen_info *ui,
fflush(stdout);
}
- err = mtd_erase(mtd, args.node_fd, eb);
+ err = mtd_erase(libmtd, mtd, args.node_fd, eb);
if (err) {
if (!args.quiet)
printf("\n");
@@ -652,7 +653,7 @@ static int format(const struct mtd_dev_info *mtd, const struct ubigen_info *ui,
goto out_free;
}
- err = mtd_torture(mtd, args.node_fd, eb);
+ err = mtd_torture(libmtd, mtd, args.node_fd, eb);
if (err) {
if (mark_bad(mtd, si, eb))
goto out_free;
@@ -922,15 +923,15 @@ int main(int argc, char * const argv[])
}
if (args.image) {
- err = flash_image(&mtd, &ui, si);
+ err = flash_image(libmtd, &mtd, &ui, si);
if (err < 0)
goto out_free;
- err = format(&mtd, &ui, si, err, 1);
+ err = format(libmtd, &mtd, &ui, si, err, 1);
if (err)
goto out_free;
} else {
- err = format(&mtd, &ui, si, 0, args.novtbl);
+ err = format(libmtd, &mtd, &ui, si, 0, args.novtbl);
if (err)
goto out_free;
}