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

Anton Olofsson anol.martinsson at gmail.com
Thu Aug 25 04:26:49 EDT 2011


Hi!

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:

--- 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;
+                       }
                        continue;
                }
                if (++written_ebs >= img_ebs)



More information about the linux-mtd mailing list