diff options
author | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-01-10 01:39:24 +0200 |
---|---|---|
committer | Artem Bityutskiy <Artem.Bityutskiy@nokia.com> | 2010-01-10 01:44:20 +0200 |
commit | 180c09de57d8e254716c562bd0537df543d12577 (patch) | |
tree | 66b9e86425544c5b9ca94634309834a3204a7a08 /ubi-utils | |
parent | 69d3d2a45e58d6f1561d7685008e90dae459cb85 (diff) |
ubiformat: be consistent with sequence numbers
This commit fixes a stupid an nasty bug. When we flash an UBI image,
we do not change its sequence numbers. But when we format the rest
of the PEBs (beyond the flashed image), we use a random (or specified
via cmdline) sequence number. As a result, we have a broken flash
format and UBI refuses it, because half of it has one sequence number,
another half has a different one.
What we have to do instead, we have to substitute image's sequence
number with ours.
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'ubi-utils')
-rw-r--r-- | ubi-utils/src/ubiformat.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/ubi-utils/src/ubiformat.c b/ubi-utils/src/ubiformat.c index 80f3a6d..2316d67 100644 --- a/ubi-utils/src/ubiformat.c +++ b/ubi-utils/src/ubiformat.c @@ -295,7 +295,8 @@ static void print_bad_eraseblocks(const struct mtd_dev_info *mtd, printf("\n"); } -static int change_ec(struct ubi_ec_hdr *hdr, long long ec) +static int change_ech(struct ubi_ec_hdr *hdr, uint32_t image_seq, + long long ec) { uint32_t crc; @@ -309,6 +310,7 @@ static int change_ec(struct ubi_ec_hdr *hdr, long long ec) return errmsg("bad CRC %#08x, should be %#08x\n", crc, be32_to_cpu(hdr->hdr_crc)); + hdr->image_seq = cpu_to_be32(image_seq); hdr->ec = cpu_to_be64(ec); crc = crc32(UBI_CRC32_INIT, hdr, UBI_EC_HDR_SIZE_CRC); hdr->hdr_crc = cpu_to_be32(crc); @@ -438,7 +440,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, struct ubi_scan_info *si) +static int flash_image(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; @@ -518,7 +521,7 @@ static int flash_image(const struct mtd_dev_info *mtd, struct ubi_scan_info *si) fflush(stdout); } - err = change_ec((struct ubi_ec_hdr *)buf, ec); + err = change_ech((struct ubi_ec_hdr *)buf, ui->image_seq, ec); if (err) { errmsg("bad EC header at eraseblock %d of \"%s\"", written_ebs, args.image); @@ -918,7 +921,7 @@ int main(int argc, char * const argv[]) } if (args.image) { - err = flash_image(&mtd, si); + err = flash_image(&mtd, &ui, si); if (err < 0) goto out_free; |