diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2019-08-15 10:58:11 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2019-08-15 10:58:11 +0200 |
commit | a0b3119905e16d7610f950d0fd04a8689979be2e (patch) | |
tree | 90dd07db7ee5ac0dbe66c3f94919d26e1c548409 /common | |
parent | 4c122cff4aa80dbfe9ebccca3ef196f70f75ef22 (diff) | |
parent | 3adce7def29d79b4f01216becf9a7fd0f8765e88 (diff) | |
download | barebox-a0b3119905e16d7610f950d0fd04a8689979be2e.tar.gz barebox-a0b3119905e16d7610f950d0fd04a8689979be2e.tar.xz |
Merge branch 'for-next/mtd'
Diffstat (limited to 'common')
-rw-r--r-- | common/imx-bbu-nand-fcb.c | 5 | ||||
-rw-r--r-- | common/state/backend_bucket_circular.c | 2 | ||||
-rw-r--r-- | common/ubiformat.c | 62 |
3 files changed, 47 insertions, 22 deletions
diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c index 6d773b59df..a62e2a2975 100644 --- a/common/imx-bbu-nand-fcb.c +++ b/common/imx-bbu-nand-fcb.c @@ -531,6 +531,9 @@ again: if (ret == -EBADMSG) { ret = mtd_peb_torture(mtd, block); + if (ret == -EIO) + mtd_peb_mark_bad(mtd, block); + if (!ret && retries++ < 3) goto again; } @@ -771,6 +774,8 @@ out: if (ret == -EBADMSG) { ret = mtd_peb_torture(mtd, block); + if (ret == -EIO) + mtd_peb_mark_bad(mtd, block); if (!ret && retries++ < 3) goto again; diff --git a/common/state/backend_bucket_circular.c b/common/state/backend_bucket_circular.c index 4676730d05..47970b79f3 100644 --- a/common/state/backend_bucket_circular.c +++ b/common/state/backend_bucket_circular.c @@ -95,6 +95,7 @@ static int state_mtd_peb_read(struct state_backend_storage_bucket_circular *circ if (ret == -EBADMSG) { ret = mtd_peb_torture(circ->mtd, circ->eraseblock); if (ret == -EIO) { + mtd_peb_mark_bad(circ->mtd, circ->eraseblock); dev_err(circ->dev, "Tortured eraseblock failed and is marked bad now, PEB %u\n", circ->eraseblock); return -EIO; @@ -132,6 +133,7 @@ static int state_mtd_peb_write(struct state_backend_storage_bucket_circular *cir if (ret == -EBADMSG) { ret = mtd_peb_torture(circ->mtd, circ->eraseblock); if (ret == -EIO) { + mtd_peb_mark_bad(circ->mtd, circ->eraseblock); dev_err(circ->dev, "Tortured eraseblock failed and is marked bad now, PEB %u\n", circ->eraseblock); return -EIO; diff --git a/common/ubiformat.c b/common/ubiformat.c index 1968bd98f8..72b9b6f2eb 100644 --- a/common/ubiformat.c +++ b/common/ubiformat.c @@ -31,7 +31,6 @@ #include <common.h> #include <fs.h> #include <fcntl.h> -#include <errno.h> #include <crc.h> #include <stdlib.h> #include <clock.h> @@ -188,6 +187,7 @@ static int flash_image(struct ubiformat_args *args, struct mtd_info *mtd, const struct ubigen_info *ui, struct ubi_scan_info *si) { int fd = 0, img_ebs, eb, written_ebs = 0, ret = -1, eb_cnt; + int skip_data_read = 0; off_t st_size; char *buf = NULL; uint64_t lastprint = 0; @@ -257,7 +257,7 @@ static int flash_image(struct ubiformat_args *args, struct mtd_info *mtd, printf("\n"); sys_errmsg("failed to erase eraseblock %d", eb); - if (err != EIO) + if (err != -EIO) goto out_close; if (mark_bad(args, mtd, si, eb)) @@ -266,17 +266,20 @@ static int flash_image(struct ubiformat_args *args, struct mtd_info *mtd, continue; } - if (args->image) { - err = read_full(fd, buf, mtd->erasesize); - if (err < 0) { - sys_errmsg("failed to read eraseblock %d from image", - written_ebs); - goto out_close; + if (!skip_data_read) { + if (args->image) { + err = read_full(fd, buf, mtd->erasesize); + if (err < 0) { + sys_errmsg("failed to read eraseblock %d from image", + written_ebs); + goto out_close; + } + } else { + memcpy(buf, inbuf, mtd->erasesize); + inbuf += mtd->erasesize; } - } else { - memcpy(buf, inbuf, mtd->erasesize); - inbuf += mtd->erasesize; } + skip_data_read = 0; if (args->override_ec) ec = args->ec; @@ -306,14 +309,24 @@ static int flash_image(struct ubiformat_args *args, struct mtd_info *mtd, if (err) { sys_errmsg("cannot write eraseblock %d", eb); - if (err != EIO) + if (err != -EIO) goto out_close; err = mtd_peb_torture(mtd, eb); - if (err < 0 && err != -EIO) - goto out_close; - if (err == -EIO && consecutive_bad_check(args, eb)) + if (err == -EIO) { + err = mark_bad(args, mtd, si, eb); + if (err) + goto out_close; + } else if (err) { goto out_close; + } + + /* + * We have to make sure that we do not read next block + * of data from the input image or stdin - we have to + * write buf first instead. + */ + skip_data_read = 1; continue; } @@ -387,7 +400,7 @@ static int format(struct ubiformat_args *args, struct mtd_info *mtd, printf("\n"); sys_errmsg("failed to erase eraseblock %d", eb); - if (err != EIO) + if (err != -EIO) goto out_free; if (mark_bad(args, mtd, si, eb)) @@ -419,17 +432,20 @@ static int format(struct ubiformat_args *args, struct mtd_info *mtd, sys_errmsg("cannot write EC header (%d bytes buffer) to eraseblock %d", write_size, eb); - if (errno != EIO) { + if (err != -EIO) { if (args->subpage_size != mtd->writesize) normsg("may be sub-page size is incorrect?"); goto out_free; } err = mtd_peb_torture(mtd, eb); - if (err < 0 && err != -EIO) - goto out_free; - if (err == -EIO && consecutive_bad_check(args, eb)) + if (err == -EIO) { + err = mark_bad(args, mtd, si, eb); + if (err) + goto out_free; + } else if (err) { goto out_free; + } continue; @@ -481,8 +497,10 @@ int ubiformat(struct mtd_info *mtd, struct ubiformat_args *args) if (!args->ubi_ver) args->ubi_ver = 1; - if (!args->image_seq) - args->image_seq = rand(); + if (!args->image_seq) { + srand(get_time_ns()); + args->image_seq = random32(); + } if (!is_power_of_2(mtd->writesize)) { errmsg("min. I/O size is %d, but should be power of 2", |