]> www.infradead.org Git - mtd-utils.git/commitdiff
ubiformat: fix segfault and messages
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Sat, 18 Apr 2009 13:35:22 +0000 (16:35 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Sat, 18 Apr 2009 13:45:39 +0000 (16:45 +0300)
ubiformat segfaults like this:

ubiformat: mtd0 (NAND), size 134217728 bytes (128.0 MiB), 16384 eraseblocks of 16384 bytes (16.0 KiB), min. I/O size 512 bytes
libscan: scanning eraseblock 8191 -- 100 % complete
ubiformat: 8190 eraseblocks have valid erase counter, mean value is 9
ubiformat: 2 eraseblocks are supposedly empty
ubiformat: warning!: VID header and data offsets on flash are 512 and 1024, which is different to calculated offsets 256 and 512
ubiformat: use new offsets 512 and 1024? (yes/no)  no
Segmentation fault

The reason is that volume table size is calculated for 256/512
layout, and when user chooses 512/1024 - it is not re-calculated
which leads to segfault in 'ubigen_write_layout_vol()'.

This patch also fixes the message - in the above output new
offsets are 256/512, not 512/1024.

Also, this patch adds explicit printing of the selected
positions.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
ubi-utils/src/ubiformat.c

index 2226a759cccc0165248ea6e1f35b5c811c35c3ff..920df9ad791a07a6bdbf4ce3511a330eddc2283b 100644 (file)
@@ -852,19 +852,19 @@ int main(int argc, char * const argv[])
                 */
                if (!args.yes || !args.quiet) {
                        warnmsg("VID header and data offsets on flash are %d and %d, "
-                               "which is different to calculated offsets %d and %d",
+                               "which is different to requested offsets %d and %d",
                                si->vid_hdr_offs, si->data_offs, ui.vid_hdr_offs,
                                ui.data_offs);
                        normsg_cont("use new offsets %d and %d? (yes/no)  ",
-                                   si->vid_hdr_offs, si->data_offs);
+                                   ui.vid_hdr_offs, ui.data_offs);
                }
                if (args.yes || answer_is_yes()) {
                        if (args.yes && !args.quiet)
                                printf("yes\n");
-               } else {
-                       ui.vid_hdr_offs = si->vid_hdr_offs;
-                       ui.data_offs = si->data_offs;
-               }
+               } else
+                       ubigen_info_init(&ui, mtd.eb_size, mtd.min_io_size, 0,
+                                        si->vid_hdr_offs, args.ubi_ver);
+               normsg("use offsets %d and %d",  ui.vid_hdr_offs, ui.data_offs);
        }
 
        if (args.image) {