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

login
register
mail settings
Submitter Anton Olofsson
Date Aug. 25, 2011, 8:26 a.m.
Message ID <CAMjE+nUOxOm4bBWKp1xAcVDjP-Pepd_GuJ=DcQ4jUcsohn-K=g@mail.gmail.com>
Download mbox | patch
Permalink /patch/111501/
State New
Headers show

Comments

Anton Olofsson - Aug. 25, 2011, 8:26 a.m.
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:

                if (++written_ebs >= img_ebs)

Patch

--- 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;
                }