mtd-utils: ubiformat: writing images on flash with badblocks.

Message ID
State New, archived
Headers show

Commit Message

Anton Olofsson Aug. 25, 2011, 8:26 a.m.

We encountered some problems with ubiformat
and writing ubi-images onto flash with badblocks.

If a badblock was encountered during write ubiformat would
skip writing that “file-block” altogether, and this would eventually
result in EOF while trying to read the image file.

The quick fix was to rewind the filedescriptor for the next pass.

Im not sure if others have encountered this problem
or even if this is the correct way to handle this situation.

Here is the change made though:

                if (++written_ebs >= img_ebs)


--- a/ubi-utils/ubiformat.c
+++ b/ubi-utils/ubiformat.c
@@ -546,6 +546,11 @@  static int flash_image(libmtd_t libmtd, const
struct mtd_dev_info *mtd,
                                if (mark_bad(mtd, si, eb))
                                        goto out_close;
+                       /*rewind fd so next read_all(...) reads correct block*/
+                       if (lseek(fd, -mtd->eb_size, SEEK_CUR) == -1) {
+                               sys_errmsg("unable to rewind file");
+                               goto out_close;
+                       }