diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-02 23:49:15 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-02 23:49:15 -0400 |
commit | 65b99c74fdd325d1ffa2e5663295888704712604 (patch) | |
tree | 6ccec0803316bbefc1ea82add70245a9586c5fff /drivers/mtd/ubi | |
parent | 782c3fb22baa103abbcd30dfc99cad24bb09f1df (diff) | |
parent | 55393ba1bdedc5ded79b34b4cc08898a7776cddb (diff) |
Merge tag 'upstream-3.7-rc1' of git://git.infradead.org/linux-ubi
Pull UBI changes from Artem Bityutskiy:
"The main change is the way we reserve eraseblocks for bad blocks
handling. We used to reserve 2% of the partition, but now we are more
aggressive and we reserve 2% of the entire chip, which is what
actually manufacturers specify in data sheets. We introduced an
option to users to override the default, though.
There are a couple of fixes as well, and a number of cleanups."
* tag 'upstream-3.7-rc1' of git://git.infradead.org/linux-ubi: (24 commits)
UBI: fix trivial typo 'it' => 'is'
UBI: load after mtd device drivers
UBI: print less
UBI: use pr_ helper instead of printk
UBI: comply with coding style
UBI: erase free PEB with bitflip in EC header
UBI: fix autoresize handling in R/O mode
UBI: add max_beb_per1024 to attach ioctl
UBI: allow specifying bad PEBs limit using module parameter
UBI: check max_beb_per1024 value in ubi_attach_mtd_dev
UBI: prepare for max_beb_per1024 module parameter addition
UBI: introduce MTD_PARAM_MAX_COUNT
UBI: separate bad_peb_limit in a function
arm: sam9_l9260_defconfig: correct CONFIG_MTD_UBI_BEB_LIMIT
UBI: use the whole MTD device size to get bad_peb_limit
mtd: mtdparts: introduce mtd_get_device_size
mtd: mark mtd_is_partition argument as constant
arm: sam9_l9260_defconfig: remove non-existing config option
UBI: kill CONFIG_MTD_UBI_BEB_RESERVE
UBI: limit amount of reserved eraseblocks for bad PEB handling
...
Diffstat (limited to 'drivers/mtd/ubi')
-rw-r--r-- | drivers/mtd/ubi/Kconfig | 40 | ||||
-rw-r--r-- | drivers/mtd/ubi/attach.c | 46 | ||||
-rw-r--r-- | drivers/mtd/ubi/build.c | 204 | ||||
-rw-r--r-- | drivers/mtd/ubi/cdev.c | 18 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.c | 153 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.h | 12 | ||||
-rw-r--r-- | drivers/mtd/ubi/eba.c | 33 | ||||
-rw-r--r-- | drivers/mtd/ubi/gluebi.c | 30 | ||||
-rw-r--r-- | drivers/mtd/ubi/io.c | 80 | ||||
-rw-r--r-- | drivers/mtd/ubi/misc.c | 14 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi.h | 16 | ||||
-rw-r--r-- | drivers/mtd/ubi/vtbl.c | 10 | ||||
-rw-r--r-- | drivers/mtd/ubi/wl.c | 48 |
13 files changed, 383 insertions, 321 deletions
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index ea4b95b5451c..271a842f8c39 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig | |||
@@ -27,20 +27,34 @@ config MTD_UBI_WL_THRESHOLD | |||
27 | life-cycle less than 10000, the threshold should be lessened (e.g., | 27 | life-cycle less than 10000, the threshold should be lessened (e.g., |
28 | to 128 or 256, although it does not have to be power of 2). | 28 | to 128 or 256, although it does not have to be power of 2). |
29 | 29 | ||
30 | config MTD_UBI_BEB_RESERVE | 30 | config MTD_UBI_BEB_LIMIT |
31 | int "Percentage of reserved eraseblocks for bad eraseblocks handling" | 31 | int "Maximum expected bad eraseblock count per 1024 eraseblocks" |
32 | default 2 | 32 | default 20 |
33 | range 0 25 | 33 | range 0 768 |
34 | help | 34 | help |
35 | If the MTD device admits of bad eraseblocks (e.g. NAND flash), UBI | 35 | This option specifies the maximum bad physical eraseblocks UBI |
36 | reserves some amount of physical eraseblocks to handle new bad | 36 | expects on the MTD device (per 1024 eraseblocks). If the underlying |
37 | eraseblocks. For example, if a flash physical eraseblock becomes bad, | 37 | flash does not admit of bad eraseblocks (e.g. NOR flash), this value |
38 | UBI uses these reserved physical eraseblocks to relocate the bad one. | 38 | is ignored. |
39 | This option specifies how many physical eraseblocks will be reserved | 39 | |
40 | for bad eraseblock handling (percents of total number of good flash | 40 | NAND datasheets often specify the minimum and maximum NVM (Number of |
41 | eraseblocks). If the underlying flash does not admit of bad | 41 | Valid Blocks) for the flashes' endurance lifetime. The maximum |
42 | eraseblocks (e.g. NOR flash), this value is ignored and nothing is | 42 | expected bad eraseblocks per 1024 eraseblocks then can be calculated |
43 | reserved. Leave the default value if unsure. | 43 | as "1024 * (1 - MinNVB / MaxNVB)", which gives 20 for most NANDs |
44 | (MaxNVB is basically the total count of eraseblocks on the chip). | ||
45 | |||
46 | To put it differently, if this value is 20, UBI will try to reserve | ||
47 | about 1.9% of physical eraseblocks for bad blocks handling. And that | ||
48 | will be 1.9% of eraseblocks on the entire NAND chip, not just the MTD | ||
49 | partition UBI attaches. This means that if you have, say, a NAND | ||
50 | flash chip admits maximum 40 bad eraseblocks, and it is split on two | ||
51 | MTD partitions of the same size, UBI will reserve 40 eraseblocks when | ||
52 | attaching a partition. | ||
53 | |||
54 | This option can be overridden by the "mtd=" UBI module parameter or | ||
55 | by the "attach" ioctl. | ||
56 | |||
57 | Leave the default value if unsure. | ||
44 | 58 | ||
45 | config MTD_UBI_GLUEBI | 59 | config MTD_UBI_GLUEBI |
46 | tristate "MTD devices emulation driver (gluebi)" | 60 | tristate "MTD devices emulation driver (gluebi)" |
diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c index bd27cbbb4066..f7adf53e4f45 100644 --- a/drivers/mtd/ubi/attach.c +++ b/drivers/mtd/ubi/attach.c | |||
@@ -79,7 +79,7 @@ | |||
79 | * NAND), it is probably a PEB which was being erased when power cut | 79 | * NAND), it is probably a PEB which was being erased when power cut |
80 | * happened, so this is corruption type 1. However, this is just a guess, | 80 | * happened, so this is corruption type 1. However, this is just a guess, |
81 | * which might be wrong. | 81 | * which might be wrong. |
82 | * o Otherwise this it corruption type 2. | 82 | * o Otherwise this is corruption type 2. |
83 | */ | 83 | */ |
84 | 84 | ||
85 | #include <linux/err.h> | 85 | #include <linux/err.h> |
@@ -378,8 +378,8 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb, | |||
378 | if (err == UBI_IO_BITFLIPS) | 378 | if (err == UBI_IO_BITFLIPS) |
379 | bitflips = 1; | 379 | bitflips = 1; |
380 | else { | 380 | else { |
381 | ubi_err("VID of PEB %d header is bad, but it " | 381 | ubi_err("VID of PEB %d header is bad, but it was OK earlier, err %d", |
382 | "was OK earlier, err %d", pnum, err); | 382 | pnum, err); |
383 | if (err > 0) | 383 | if (err > 0) |
384 | err = -EIO; | 384 | err = -EIO; |
385 | 385 | ||
@@ -790,12 +790,12 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr, | |||
790 | if (ubi_check_pattern(ubi->peb_buf, 0xFF, ubi->leb_size)) | 790 | if (ubi_check_pattern(ubi->peb_buf, 0xFF, ubi->leb_size)) |
791 | goto out_unlock; | 791 | goto out_unlock; |
792 | 792 | ||
793 | ubi_err("PEB %d contains corrupted VID header, and the data does not " | 793 | ubi_err("PEB %d contains corrupted VID header, and the data does not contain all 0xFF", |
794 | "contain all 0xFF, this may be a non-UBI PEB or a severe VID " | 794 | pnum); |
795 | "header corruption which requires manual inspection", pnum); | 795 | ubi_err("this may be a non-UBI PEB or a severe VID header corruption which requires manual inspection"); |
796 | ubi_dump_vid_hdr(vid_hdr); | 796 | ubi_dump_vid_hdr(vid_hdr); |
797 | dbg_msg("hexdump of PEB %d offset %d, length %d", | 797 | pr_err("hexdump of PEB %d offset %d, length %d", |
798 | pnum, ubi->leb_start, ubi->leb_size); | 798 | pnum, ubi->leb_start, ubi->leb_size); |
799 | ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 799 | ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
800 | ubi->peb_buf, ubi->leb_size, 1); | 800 | ubi->peb_buf, ubi->leb_size, 1); |
801 | err = 1; | 801 | err = 1; |
@@ -907,8 +907,8 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
907 | ubi->image_seq = image_seq; | 907 | ubi->image_seq = image_seq; |
908 | if (ubi->image_seq && image_seq && | 908 | if (ubi->image_seq && image_seq && |
909 | ubi->image_seq != image_seq) { | 909 | ubi->image_seq != image_seq) { |
910 | ubi_err("bad image sequence number %d in PEB %d, " | 910 | ubi_err("bad image sequence number %d in PEB %d, expected %d", |
911 | "expected %d", image_seq, pnum, ubi->image_seq); | 911 | image_seq, pnum, ubi->image_seq); |
912 | ubi_dump_ec_hdr(ech); | 912 | ubi_dump_ec_hdr(ech); |
913 | return -EINVAL; | 913 | return -EINVAL; |
914 | } | 914 | } |
@@ -975,7 +975,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
975 | return err; | 975 | return err; |
976 | goto adjust_mean_ec; | 976 | goto adjust_mean_ec; |
977 | case UBI_IO_FF: | 977 | case UBI_IO_FF: |
978 | if (ec_err) | 978 | if (ec_err || bitflips) |
979 | err = add_to_list(ai, pnum, UBI_UNKNOWN, | 979 | err = add_to_list(ai, pnum, UBI_UNKNOWN, |
980 | UBI_UNKNOWN, ec, 1, &ai->erase); | 980 | UBI_UNKNOWN, ec, 1, &ai->erase); |
981 | else | 981 | else |
@@ -997,8 +997,8 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
997 | /* Unsupported internal volume */ | 997 | /* Unsupported internal volume */ |
998 | switch (vidh->compat) { | 998 | switch (vidh->compat) { |
999 | case UBI_COMPAT_DELETE: | 999 | case UBI_COMPAT_DELETE: |
1000 | ubi_msg("\"delete\" compatible internal volume %d:%d" | 1000 | ubi_msg("\"delete\" compatible internal volume %d:%d found, will remove it", |
1001 | " found, will remove it", vol_id, lnum); | 1001 | vol_id, lnum); |
1002 | err = add_to_list(ai, pnum, vol_id, lnum, | 1002 | err = add_to_list(ai, pnum, vol_id, lnum, |
1003 | ec, 1, &ai->erase); | 1003 | ec, 1, &ai->erase); |
1004 | if (err) | 1004 | if (err) |
@@ -1006,15 +1006,14 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
1006 | return 0; | 1006 | return 0; |
1007 | 1007 | ||
1008 | case UBI_COMPAT_RO: | 1008 | case UBI_COMPAT_RO: |
1009 | ubi_msg("read-only compatible internal volume %d:%d" | 1009 | ubi_msg("read-only compatible internal volume %d:%d found, switch to read-only mode", |
1010 | " found, switch to read-only mode", | ||
1011 | vol_id, lnum); | 1010 | vol_id, lnum); |
1012 | ubi->ro_mode = 1; | 1011 | ubi->ro_mode = 1; |
1013 | break; | 1012 | break; |
1014 | 1013 | ||
1015 | case UBI_COMPAT_PRESERVE: | 1014 | case UBI_COMPAT_PRESERVE: |
1016 | ubi_msg("\"preserve\" compatible internal volume %d:%d" | 1015 | ubi_msg("\"preserve\" compatible internal volume %d:%d found", |
1017 | " found", vol_id, lnum); | 1016 | vol_id, lnum); |
1018 | err = add_to_list(ai, pnum, vol_id, lnum, | 1017 | err = add_to_list(ai, pnum, vol_id, lnum, |
1019 | ec, 0, &ai->alien); | 1018 | ec, 0, &ai->alien); |
1020 | if (err) | 1019 | if (err) |
@@ -1075,10 +1074,10 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai) | |||
1075 | if (ai->corr_peb_count) { | 1074 | if (ai->corr_peb_count) { |
1076 | ubi_err("%d PEBs are corrupted and preserved", | 1075 | ubi_err("%d PEBs are corrupted and preserved", |
1077 | ai->corr_peb_count); | 1076 | ai->corr_peb_count); |
1078 | printk(KERN_ERR "Corrupted PEBs are:"); | 1077 | pr_err("Corrupted PEBs are:"); |
1079 | list_for_each_entry(aeb, &ai->corr, u.list) | 1078 | list_for_each_entry(aeb, &ai->corr, u.list) |
1080 | printk(KERN_CONT " %d", aeb->pnum); | 1079 | pr_cont(" %d", aeb->pnum); |
1081 | printk(KERN_CONT "\n"); | 1080 | pr_cont("\n"); |
1082 | 1081 | ||
1083 | /* | 1082 | /* |
1084 | * If too many PEBs are corrupted, we refuse attaching, | 1083 | * If too many PEBs are corrupted, we refuse attaching, |
@@ -1112,8 +1111,7 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai) | |||
1112 | get_random_bytes(&ubi->image_seq, | 1111 | get_random_bytes(&ubi->image_seq, |
1113 | sizeof(ubi->image_seq)); | 1112 | sizeof(ubi->image_seq)); |
1114 | } else { | 1113 | } else { |
1115 | ubi_err("MTD device is not UBI-formatted and possibly " | 1114 | ubi_err("MTD device is not UBI-formatted and possibly contains non-UBI data - refusing it"); |
1116 | "contains non-UBI data - refusing it"); | ||
1117 | return -EINVAL; | 1115 | return -EINVAL; |
1118 | } | 1116 | } |
1119 | 1117 | ||
@@ -1172,7 +1170,7 @@ static struct ubi_attach_info *scan_all(struct ubi_device *ubi) | |||
1172 | goto out_vidh; | 1170 | goto out_vidh; |
1173 | } | 1171 | } |
1174 | 1172 | ||
1175 | dbg_msg("scanning is finished"); | 1173 | ubi_msg("scanning is finished"); |
1176 | 1174 | ||
1177 | /* Calculate mean erase counter */ | 1175 | /* Calculate mean erase counter */ |
1178 | if (ai->ec_count) | 1176 | if (ai->ec_count) |
@@ -1244,7 +1242,7 @@ int ubi_attach(struct ubi_device *ubi) | |||
1244 | ubi->corr_peb_count = ai->corr_peb_count; | 1242 | ubi->corr_peb_count = ai->corr_peb_count; |
1245 | ubi->max_ec = ai->max_ec; | 1243 | ubi->max_ec = ai->max_ec; |
1246 | ubi->mean_ec = ai->mean_ec; | 1244 | ubi->mean_ec = ai->mean_ec; |
1247 | ubi_msg("max. sequence number: %llu", ai->max_sqnum); | 1245 | dbg_gen("max. sequence number: %llu", ai->max_sqnum); |
1248 | 1246 | ||
1249 | err = ubi_read_volume_table(ubi, ai); | 1247 | err = ubi_read_volume_table(ubi, ai); |
1250 | if (err) | 1248 | if (err) |
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 2c5ed5ca9c33..34977039850c 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/namei.h> | 36 | #include <linux/namei.h> |
37 | #include <linux/stat.h> | 37 | #include <linux/stat.h> |
38 | #include <linux/miscdevice.h> | 38 | #include <linux/miscdevice.h> |
39 | #include <linux/mtd/partitions.h> | ||
39 | #include <linux/log2.h> | 40 | #include <linux/log2.h> |
40 | #include <linux/kthread.h> | 41 | #include <linux/kthread.h> |
41 | #include <linux/kernel.h> | 42 | #include <linux/kernel.h> |
@@ -45,6 +46,12 @@ | |||
45 | /* Maximum length of the 'mtd=' parameter */ | 46 | /* Maximum length of the 'mtd=' parameter */ |
46 | #define MTD_PARAM_LEN_MAX 64 | 47 | #define MTD_PARAM_LEN_MAX 64 |
47 | 48 | ||
49 | /* Maximum number of comma-separated items in the 'mtd=' parameter */ | ||
50 | #define MTD_PARAM_MAX_COUNT 3 | ||
51 | |||
52 | /* Maximum value for the number of bad PEBs per 1024 PEBs */ | ||
53 | #define MAX_MTD_UBI_BEB_LIMIT 768 | ||
54 | |||
48 | #ifdef CONFIG_MTD_UBI_MODULE | 55 | #ifdef CONFIG_MTD_UBI_MODULE |
49 | #define ubi_is_module() 1 | 56 | #define ubi_is_module() 1 |
50 | #else | 57 | #else |
@@ -56,10 +63,12 @@ | |||
56 | * @name: MTD character device node path, MTD device name, or MTD device number | 63 | * @name: MTD character device node path, MTD device name, or MTD device number |
57 | * string | 64 | * string |
58 | * @vid_hdr_offs: VID header offset | 65 | * @vid_hdr_offs: VID header offset |
66 | * @max_beb_per1024: maximum expected number of bad PEBs per 1024 PEBs | ||
59 | */ | 67 | */ |
60 | struct mtd_dev_param { | 68 | struct mtd_dev_param { |
61 | char name[MTD_PARAM_LEN_MAX]; | 69 | char name[MTD_PARAM_LEN_MAX]; |
62 | int vid_hdr_offs; | 70 | int vid_hdr_offs; |
71 | int max_beb_per1024; | ||
63 | }; | 72 | }; |
64 | 73 | ||
65 | /* Numbers of elements set in the @mtd_dev_param array */ | 74 | /* Numbers of elements set in the @mtd_dev_param array */ |
@@ -564,9 +573,38 @@ void ubi_free_internal_volumes(struct ubi_device *ubi) | |||
564 | } | 573 | } |
565 | } | 574 | } |
566 | 575 | ||
576 | static int get_bad_peb_limit(const struct ubi_device *ubi, int max_beb_per1024) | ||
577 | { | ||
578 | int limit, device_pebs; | ||
579 | uint64_t device_size; | ||
580 | |||
581 | if (!max_beb_per1024) | ||
582 | return 0; | ||
583 | |||
584 | /* | ||
585 | * Here we are using size of the entire flash chip and | ||
586 | * not just the MTD partition size because the maximum | ||
587 | * number of bad eraseblocks is a percentage of the | ||
588 | * whole device and bad eraseblocks are not fairly | ||
589 | * distributed over the flash chip. So the worst case | ||
590 | * is that all the bad eraseblocks of the chip are in | ||
591 | * the MTD partition we are attaching (ubi->mtd). | ||
592 | */ | ||
593 | device_size = mtd_get_device_size(ubi->mtd); | ||
594 | device_pebs = mtd_div_by_eb(device_size, ubi->mtd); | ||
595 | limit = mult_frac(device_pebs, max_beb_per1024, 1024); | ||
596 | |||
597 | /* Round it up */ | ||
598 | if (mult_frac(limit, 1024, max_beb_per1024) < device_pebs) | ||
599 | limit += 1; | ||
600 | |||
601 | return limit; | ||
602 | } | ||
603 | |||
567 | /** | 604 | /** |
568 | * io_init - initialize I/O sub-system for a given UBI device. | 605 | * io_init - initialize I/O sub-system for a given UBI device. |
569 | * @ubi: UBI device description object | 606 | * @ubi: UBI device description object |
607 | * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs | ||
570 | * | 608 | * |
571 | * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are | 609 | * If @ubi->vid_hdr_offset or @ubi->leb_start is zero, default offsets are |
572 | * assumed: | 610 | * assumed: |
@@ -579,8 +617,11 @@ void ubi_free_internal_volumes(struct ubi_device *ubi) | |||
579 | * This function returns zero in case of success and a negative error code in | 617 | * This function returns zero in case of success and a negative error code in |
580 | * case of failure. | 618 | * case of failure. |
581 | */ | 619 | */ |
582 | static int io_init(struct ubi_device *ubi) | 620 | static int io_init(struct ubi_device *ubi, int max_beb_per1024) |
583 | { | 621 | { |
622 | dbg_gen("sizeof(struct ubi_ainf_peb) %zu", sizeof(struct ubi_ainf_peb)); | ||
623 | dbg_gen("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry)); | ||
624 | |||
584 | if (ubi->mtd->numeraseregions != 0) { | 625 | if (ubi->mtd->numeraseregions != 0) { |
585 | /* | 626 | /* |
586 | * Some flashes have several erase regions. Different regions | 627 | * Some flashes have several erase regions. Different regions |
@@ -607,8 +648,10 @@ static int io_init(struct ubi_device *ubi) | |||
607 | ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd); | 648 | ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd); |
608 | ubi->flash_size = ubi->mtd->size; | 649 | ubi->flash_size = ubi->mtd->size; |
609 | 650 | ||
610 | if (mtd_can_have_bb(ubi->mtd)) | 651 | if (mtd_can_have_bb(ubi->mtd)) { |
611 | ubi->bad_allowed = 1; | 652 | ubi->bad_allowed = 1; |
653 | ubi->bad_peb_limit = get_bad_peb_limit(ubi, max_beb_per1024); | ||
654 | } | ||
612 | 655 | ||
613 | if (ubi->mtd->type == MTD_NORFLASH) { | 656 | if (ubi->mtd->type == MTD_NORFLASH) { |
614 | ubi_assert(ubi->mtd->writesize == 1); | 657 | ubi_assert(ubi->mtd->writesize == 1); |
@@ -650,11 +693,11 @@ static int io_init(struct ubi_device *ubi) | |||
650 | ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size); | 693 | ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size); |
651 | ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size); | 694 | ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size); |
652 | 695 | ||
653 | dbg_msg("min_io_size %d", ubi->min_io_size); | 696 | dbg_gen("min_io_size %d", ubi->min_io_size); |
654 | dbg_msg("max_write_size %d", ubi->max_write_size); | 697 | dbg_gen("max_write_size %d", ubi->max_write_size); |
655 | dbg_msg("hdrs_min_io_size %d", ubi->hdrs_min_io_size); | 698 | dbg_gen("hdrs_min_io_size %d", ubi->hdrs_min_io_size); |
656 | dbg_msg("ec_hdr_alsize %d", ubi->ec_hdr_alsize); | 699 | dbg_gen("ec_hdr_alsize %d", ubi->ec_hdr_alsize); |
657 | dbg_msg("vid_hdr_alsize %d", ubi->vid_hdr_alsize); | 700 | dbg_gen("vid_hdr_alsize %d", ubi->vid_hdr_alsize); |
658 | 701 | ||
659 | if (ubi->vid_hdr_offset == 0) | 702 | if (ubi->vid_hdr_offset == 0) |
660 | /* Default offset */ | 703 | /* Default offset */ |
@@ -671,10 +714,10 @@ static int io_init(struct ubi_device *ubi) | |||
671 | ubi->leb_start = ubi->vid_hdr_offset + UBI_VID_HDR_SIZE; | 714 | ubi->leb_start = ubi->vid_hdr_offset + UBI_VID_HDR_SIZE; |
672 | ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size); | 715 | ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size); |
673 | 716 | ||
674 | dbg_msg("vid_hdr_offset %d", ubi->vid_hdr_offset); | 717 | dbg_gen("vid_hdr_offset %d", ubi->vid_hdr_offset); |
675 | dbg_msg("vid_hdr_aloffset %d", ubi->vid_hdr_aloffset); | 718 | dbg_gen("vid_hdr_aloffset %d", ubi->vid_hdr_aloffset); |
676 | dbg_msg("vid_hdr_shift %d", ubi->vid_hdr_shift); | 719 | dbg_gen("vid_hdr_shift %d", ubi->vid_hdr_shift); |
677 | dbg_msg("leb_start %d", ubi->leb_start); | 720 | dbg_gen("leb_start %d", ubi->leb_start); |
678 | 721 | ||
679 | /* The shift must be aligned to 32-bit boundary */ | 722 | /* The shift must be aligned to 32-bit boundary */ |
680 | if (ubi->vid_hdr_shift % 4) { | 723 | if (ubi->vid_hdr_shift % 4) { |
@@ -700,7 +743,7 @@ static int io_init(struct ubi_device *ubi) | |||
700 | ubi->max_erroneous = ubi->peb_count / 10; | 743 | ubi->max_erroneous = ubi->peb_count / 10; |
701 | if (ubi->max_erroneous < 16) | 744 | if (ubi->max_erroneous < 16) |
702 | ubi->max_erroneous = 16; | 745 | ubi->max_erroneous = 16; |
703 | dbg_msg("max_erroneous %d", ubi->max_erroneous); | 746 | dbg_gen("max_erroneous %d", ubi->max_erroneous); |
704 | 747 | ||
705 | /* | 748 | /* |
706 | * It may happen that EC and VID headers are situated in one minimal | 749 | * It may happen that EC and VID headers are situated in one minimal |
@@ -708,30 +751,18 @@ static int io_init(struct ubi_device *ubi) | |||
708 | * read-only mode. | 751 | * read-only mode. |
709 | */ | 752 | */ |
710 | if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) { | 753 | if (ubi->vid_hdr_offset + UBI_VID_HDR_SIZE <= ubi->hdrs_min_io_size) { |
711 | ubi_warn("EC and VID headers are in the same minimal I/O unit, " | 754 | ubi_warn("EC and VID headers are in the same minimal I/O unit, switch to read-only mode"); |
712 | "switch to read-only mode"); | ||
713 | ubi->ro_mode = 1; | 755 | ubi->ro_mode = 1; |
714 | } | 756 | } |
715 | 757 | ||
716 | ubi->leb_size = ubi->peb_size - ubi->leb_start; | 758 | ubi->leb_size = ubi->peb_size - ubi->leb_start; |
717 | 759 | ||
718 | if (!(ubi->mtd->flags & MTD_WRITEABLE)) { | 760 | if (!(ubi->mtd->flags & MTD_WRITEABLE)) { |
719 | ubi_msg("MTD device %d is write-protected, attach in " | 761 | ubi_msg("MTD device %d is write-protected, attach in read-only mode", |
720 | "read-only mode", ubi->mtd->index); | 762 | ubi->mtd->index); |
721 | ubi->ro_mode = 1; | 763 | ubi->ro_mode = 1; |
722 | } | 764 | } |
723 | 765 | ||
724 | ubi_msg("physical eraseblock size: %d bytes (%d KiB)", | ||
725 | ubi->peb_size, ubi->peb_size >> 10); | ||
726 | ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size); | ||
727 | ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size); | ||
728 | if (ubi->hdrs_min_io_size != ubi->min_io_size) | ||
729 | ubi_msg("sub-page size: %d", | ||
730 | ubi->hdrs_min_io_size); | ||
731 | ubi_msg("VID header offset: %d (aligned %d)", | ||
732 | ubi->vid_hdr_offset, ubi->vid_hdr_aloffset); | ||
733 | ubi_msg("data offset: %d", ubi->leb_start); | ||
734 | |||
735 | /* | 766 | /* |
736 | * Note, ideally, we have to initialize @ubi->bad_peb_count here. But | 767 | * Note, ideally, we have to initialize @ubi->bad_peb_count here. But |
737 | * unfortunately, MTD does not provide this information. We should loop | 768 | * unfortunately, MTD does not provide this information. We should loop |
@@ -759,6 +790,11 @@ static int autoresize(struct ubi_device *ubi, int vol_id) | |||
759 | struct ubi_volume *vol = ubi->volumes[vol_id]; | 790 | struct ubi_volume *vol = ubi->volumes[vol_id]; |
760 | int err, old_reserved_pebs = vol->reserved_pebs; | 791 | int err, old_reserved_pebs = vol->reserved_pebs; |
761 | 792 | ||
793 | if (ubi->ro_mode) { | ||
794 | ubi_warn("skip auto-resize because of R/O mode"); | ||
795 | return 0; | ||
796 | } | ||
797 | |||
762 | /* | 798 | /* |
763 | * Clear the auto-resize flag in the volume in-memory copy of the | 799 | * Clear the auto-resize flag in the volume in-memory copy of the |
764 | * volume table, and 'ubi_resize_volume()' will propagate this change | 800 | * volume table, and 'ubi_resize_volume()' will propagate this change |
@@ -800,6 +836,7 @@ static int autoresize(struct ubi_device *ubi, int vol_id) | |||
800 | * @mtd: MTD device description object | 836 | * @mtd: MTD device description object |
801 | * @ubi_num: number to assign to the new UBI device | 837 | * @ubi_num: number to assign to the new UBI device |
802 | * @vid_hdr_offset: VID header offset | 838 | * @vid_hdr_offset: VID header offset |
839 | * @max_beb_per1024: maximum expected number of bad PEB per 1024 PEBs | ||
803 | * | 840 | * |
804 | * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number | 841 | * This function attaches MTD device @mtd_dev to UBI and assign @ubi_num number |
805 | * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in | 842 | * to the newly created UBI device, unless @ubi_num is %UBI_DEV_NUM_AUTO, in |
@@ -810,11 +847,18 @@ static int autoresize(struct ubi_device *ubi, int vol_id) | |||
810 | * Note, the invocations of this function has to be serialized by the | 847 | * Note, the invocations of this function has to be serialized by the |
811 | * @ubi_devices_mutex. | 848 | * @ubi_devices_mutex. |
812 | */ | 849 | */ |
813 | int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | 850 | int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, |
851 | int vid_hdr_offset, int max_beb_per1024) | ||
814 | { | 852 | { |
815 | struct ubi_device *ubi; | 853 | struct ubi_device *ubi; |
816 | int i, err, ref = 0; | 854 | int i, err, ref = 0; |
817 | 855 | ||
856 | if (max_beb_per1024 < 0 || max_beb_per1024 > MAX_MTD_UBI_BEB_LIMIT) | ||
857 | return -EINVAL; | ||
858 | |||
859 | if (!max_beb_per1024) | ||
860 | max_beb_per1024 = CONFIG_MTD_UBI_BEB_LIMIT; | ||
861 | |||
818 | /* | 862 | /* |
819 | * Check if we already have the same MTD device attached. | 863 | * Check if we already have the same MTD device attached. |
820 | * | 864 | * |
@@ -839,8 +883,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
839 | * no sense to attach emulated MTD devices, so we prohibit this. | 883 | * no sense to attach emulated MTD devices, so we prohibit this. |
840 | */ | 884 | */ |
841 | if (mtd->type == MTD_UBIVOLUME) { | 885 | if (mtd->type == MTD_UBIVOLUME) { |
842 | ubi_err("refuse attaching mtd%d - it is already emulated on " | 886 | ubi_err("refuse attaching mtd%d - it is already emulated on top of UBI", |
843 | "top of UBI", mtd->index); | 887 | mtd->index); |
844 | return -EINVAL; | 888 | return -EINVAL; |
845 | } | 889 | } |
846 | 890 | ||
@@ -880,10 +924,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
880 | spin_lock_init(&ubi->volumes_lock); | 924 | spin_lock_init(&ubi->volumes_lock); |
881 | 925 | ||
882 | ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num); | 926 | ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num); |
883 | dbg_msg("sizeof(struct ubi_ainf_peb) %zu", sizeof(struct ubi_ainf_peb)); | ||
884 | dbg_msg("sizeof(struct ubi_wl_entry) %zu", sizeof(struct ubi_wl_entry)); | ||
885 | 927 | ||
886 | err = io_init(ubi); | 928 | err = io_init(ubi, max_beb_per1024); |
887 | if (err) | 929 | if (err) |
888 | goto out_free; | 930 | goto out_free; |
889 | 931 | ||
@@ -924,23 +966,24 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
924 | goto out_debugfs; | 966 | goto out_debugfs; |
925 | } | 967 | } |
926 | 968 | ||
927 | ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num); | 969 | ubi_msg("attached mtd%d (name \"%s\", size %llu MiB) to ubi%d", |
928 | ubi_msg("MTD device name: \"%s\"", mtd->name); | 970 | mtd->index, mtd->name, ubi->flash_size >> 20, ubi_num); |
929 | ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); | 971 | ubi_msg("PEB size: %d bytes (%d KiB), LEB size: %d bytes", |
930 | ubi_msg("number of good PEBs: %d", ubi->good_peb_count); | 972 | ubi->peb_size, ubi->peb_size >> 10, ubi->leb_size); |
931 | ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count); | 973 | ubi_msg("min./max. I/O unit sizes: %d/%d, sub-page size %d", |
932 | ubi_msg("number of corrupted PEBs: %d", ubi->corr_peb_count); | 974 | ubi->min_io_size, ubi->max_write_size, ubi->hdrs_min_io_size); |
933 | ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots); | 975 | ubi_msg("VID header offset: %d (aligned %d), data offset: %d", |
934 | ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD); | 976 | ubi->vid_hdr_offset, ubi->vid_hdr_aloffset, ubi->leb_start); |
935 | ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT); | 977 | ubi_msg("good PEBs: %d, bad PEBs: %d, corrupted PEBs: %d", |
936 | ubi_msg("number of user volumes: %d", | 978 | ubi->good_peb_count, ubi->bad_peb_count, ubi->corr_peb_count); |
937 | ubi->vol_count - UBI_INT_VOL_COUNT); | 979 | ubi_msg("user volume: %d, internal volumes: %d, max. volumes count: %d", |
938 | ubi_msg("available PEBs: %d", ubi->avail_pebs); | 980 | ubi->vol_count - UBI_INT_VOL_COUNT, UBI_INT_VOL_COUNT, |
939 | ubi_msg("total number of reserved PEBs: %d", ubi->rsvd_pebs); | 981 | ubi->vtbl_slots); |
940 | ubi_msg("number of PEBs reserved for bad PEB handling: %d", | 982 | ubi_msg("max/mean erase counter: %d/%d, WL threshold: %d, image sequence number: %u", |
941 | ubi->beb_rsvd_pebs); | 983 | ubi->max_ec, ubi->mean_ec, CONFIG_MTD_UBI_WL_THRESHOLD, |
942 | ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec); | 984 | ubi->image_seq); |
943 | ubi_msg("image sequence number: %d", ubi->image_seq); | 985 | ubi_msg("available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d", |
986 | ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs); | ||
944 | 987 | ||
945 | /* | 988 | /* |
946 | * The below lock makes sure we do not race with 'ubi_thread()' which | 989 | * The below lock makes sure we do not race with 'ubi_thread()' which |
@@ -1017,7 +1060,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) | |||
1017 | 1060 | ||
1018 | ubi_assert(ubi_num == ubi->ubi_num); | 1061 | ubi_assert(ubi_num == ubi->ubi_num); |
1019 | ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL); | 1062 | ubi_notify_all(ubi, UBI_VOLUME_REMOVED, NULL); |
1020 | dbg_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num); | 1063 | ubi_msg("detaching mtd%d from ubi%d", ubi->mtd->index, ubi_num); |
1021 | 1064 | ||
1022 | /* | 1065 | /* |
1023 | * Before freeing anything, we have to stop the background thread to | 1066 | * Before freeing anything, we have to stop the background thread to |
@@ -1172,7 +1215,7 @@ static int __init ubi_init(void) | |||
1172 | 1215 | ||
1173 | mutex_lock(&ubi_devices_mutex); | 1216 | mutex_lock(&ubi_devices_mutex); |
1174 | err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, | 1217 | err = ubi_attach_mtd_dev(mtd, UBI_DEV_NUM_AUTO, |
1175 | p->vid_hdr_offs); | 1218 | p->vid_hdr_offs, p->max_beb_per1024); |
1176 | mutex_unlock(&ubi_devices_mutex); | 1219 | mutex_unlock(&ubi_devices_mutex); |
1177 | if (err < 0) { | 1220 | if (err < 0) { |
1178 | ubi_err("cannot attach mtd%d", mtd->index); | 1221 | ubi_err("cannot attach mtd%d", mtd->index); |
@@ -1218,7 +1261,7 @@ out: | |||
1218 | ubi_err("UBI error: cannot initialize UBI, error %d", err); | 1261 | ubi_err("UBI error: cannot initialize UBI, error %d", err); |
1219 | return err; | 1262 | return err; |
1220 | } | 1263 | } |
1221 | module_init(ubi_init); | 1264 | late_initcall(ubi_init); |
1222 | 1265 | ||
1223 | static void __exit ubi_exit(void) | 1266 | static void __exit ubi_exit(void) |
1224 | { | 1267 | { |
@@ -1252,8 +1295,7 @@ static int __init bytes_str_to_int(const char *str) | |||
1252 | 1295 | ||
1253 | result = simple_strtoul(str, &endp, 0); | 1296 | result = simple_strtoul(str, &endp, 0); |
1254 | if (str == endp || result >= INT_MAX) { | 1297 | if (str == endp || result >= INT_MAX) { |
1255 | printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n", | 1298 | ubi_err("UBI error: incorrect bytes count: \"%s\"\n", str); |
1256 | str); | ||
1257 | return -EINVAL; | 1299 | return -EINVAL; |
1258 | } | 1300 | } |
1259 | 1301 | ||
@@ -1269,8 +1311,7 @@ static int __init bytes_str_to_int(const char *str) | |||
1269 | case '\0': | 1311 | case '\0': |
1270 | break; | 1312 | break; |
1271 | default: | 1313 | default: |
1272 | printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n", | 1314 | ubi_err("UBI error: incorrect bytes count: \"%s\"\n", str); |
1273 | str); | ||
1274 | return -EINVAL; | 1315 | return -EINVAL; |
1275 | } | 1316 | } |
1276 | 1317 | ||
@@ -1291,27 +1332,26 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | |||
1291 | struct mtd_dev_param *p; | 1332 | struct mtd_dev_param *p; |
1292 | char buf[MTD_PARAM_LEN_MAX]; | 1333 | char buf[MTD_PARAM_LEN_MAX]; |
1293 | char *pbuf = &buf[0]; | 1334 | char *pbuf = &buf[0]; |
1294 | char *tokens[2] = {NULL, NULL}; | 1335 | char *tokens[MTD_PARAM_MAX_COUNT]; |
1295 | 1336 | ||
1296 | if (!val) | 1337 | if (!val) |
1297 | return -EINVAL; | 1338 | return -EINVAL; |
1298 | 1339 | ||
1299 | if (mtd_devs == UBI_MAX_DEVICES) { | 1340 | if (mtd_devs == UBI_MAX_DEVICES) { |
1300 | printk(KERN_ERR "UBI error: too many parameters, max. is %d\n", | 1341 | ubi_err("UBI error: too many parameters, max. is %d\n", |
1301 | UBI_MAX_DEVICES); | 1342 | UBI_MAX_DEVICES); |
1302 | return -EINVAL; | 1343 | return -EINVAL; |
1303 | } | 1344 | } |
1304 | 1345 | ||
1305 | len = strnlen(val, MTD_PARAM_LEN_MAX); | 1346 | len = strnlen(val, MTD_PARAM_LEN_MAX); |
1306 | if (len == MTD_PARAM_LEN_MAX) { | 1347 | if (len == MTD_PARAM_LEN_MAX) { |
1307 | printk(KERN_ERR "UBI error: parameter \"%s\" is too long, " | 1348 | ubi_err("UBI error: parameter \"%s\" is too long, max. is %d\n", |
1308 | "max. is %d\n", val, MTD_PARAM_LEN_MAX); | 1349 | val, MTD_PARAM_LEN_MAX); |
1309 | return -EINVAL; | 1350 | return -EINVAL; |
1310 | } | 1351 | } |
1311 | 1352 | ||
1312 | if (len == 0) { | 1353 | if (len == 0) { |
1313 | printk(KERN_WARNING "UBI warning: empty 'mtd=' parameter - " | 1354 | pr_warn("UBI warning: empty 'mtd=' parameter - ignored\n"); |
1314 | "ignored\n"); | ||
1315 | return 0; | 1355 | return 0; |
1316 | } | 1356 | } |
1317 | 1357 | ||
@@ -1321,12 +1361,11 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | |||
1321 | if (buf[len - 1] == '\n') | 1361 | if (buf[len - 1] == '\n') |
1322 | buf[len - 1] = '\0'; | 1362 | buf[len - 1] = '\0'; |
1323 | 1363 | ||
1324 | for (i = 0; i < 2; i++) | 1364 | for (i = 0; i < MTD_PARAM_MAX_COUNT; i++) |
1325 | tokens[i] = strsep(&pbuf, ","); | 1365 | tokens[i] = strsep(&pbuf, ","); |
1326 | 1366 | ||
1327 | if (pbuf) { | 1367 | if (pbuf) { |
1328 | printk(KERN_ERR "UBI error: too many arguments at \"%s\"\n", | 1368 | ubi_err("UBI error: too many arguments at \"%s\"\n", val); |
1329 | val); | ||
1330 | return -EINVAL; | 1369 | return -EINVAL; |
1331 | } | 1370 | } |
1332 | 1371 | ||
@@ -1339,23 +1378,32 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | |||
1339 | if (p->vid_hdr_offs < 0) | 1378 | if (p->vid_hdr_offs < 0) |
1340 | return p->vid_hdr_offs; | 1379 | return p->vid_hdr_offs; |
1341 | 1380 | ||
1381 | if (tokens[2]) { | ||
1382 | int err = kstrtoint(tokens[2], 10, &p->max_beb_per1024); | ||
1383 | |||
1384 | if (err) { | ||
1385 | ubi_err("UBI error: bad value for max_beb_per1024 parameter: %s", | ||
1386 | tokens[2]); | ||
1387 | return -EINVAL; | ||
1388 | } | ||
1389 | } | ||
1390 | |||
1342 | mtd_devs += 1; | 1391 | mtd_devs += 1; |
1343 | return 0; | 1392 | return 0; |
1344 | } | 1393 | } |
1345 | 1394 | ||
1346 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); | 1395 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); |
1347 | MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " | 1396 | MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: mtd=<name|num|path>[,<vid_hdr_offs>[,max_beb_per1024]].\n" |
1348 | "mtd=<name|num|path>[,<vid_hdr_offs>].\n" | ||
1349 | "Multiple \"mtd\" parameters may be specified.\n" | 1397 | "Multiple \"mtd\" parameters may be specified.\n" |
1350 | "MTD devices may be specified by their number, name, or " | 1398 | "MTD devices may be specified by their number, name, or path to the MTD character device node.\n" |
1351 | "path to the MTD character device node.\n" | 1399 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID header position to be used by UBI. (default value if 0)\n" |
1352 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID " | 1400 | "Optional \"max_beb_per1024\" parameter specifies the maximum expected bad eraseblock per 1024 eraseblocks. (default value (" |
1353 | "header position to be used by UBI.\n" | 1401 | __stringify(CONFIG_MTD_UBI_BEB_LIMIT) ") if 0)\n" |
1354 | "Example 1: mtd=/dev/mtd0 - attach MTD device " | 1402 | "\n" |
1355 | "/dev/mtd0.\n" | 1403 | "Example 1: mtd=/dev/mtd0 - attach MTD device /dev/mtd0.\n" |
1356 | "Example 2: mtd=content,1984 mtd=4 - attach MTD device " | 1404 | "Example 2: mtd=content,1984 mtd=4 - attach MTD device with name \"content\" using VID header offset 1984, and MTD device number 4 with default VID header offset.\n" |
1357 | "with name \"content\" using VID header offset 1984, and " | 1405 | "Example 3: mtd=/dev/mtd1,0,25 - attach MTD device /dev/mtd1 using default VID header offset and reserve 25*nand_size_in_blocks/1024 erase blocks for bad block handling.\n" |
1358 | "MTD device number 4 with default VID header offset."); | 1406 | "\t(e.g. if the NAND *chipset* has 4096 PEB, 100 will be reserved for this UBI device)."); |
1359 | 1407 | ||
1360 | MODULE_VERSION(__stringify(UBI_VERSION)); | 1408 | MODULE_VERSION(__stringify(UBI_VERSION)); |
1361 | MODULE_DESCRIPTION("UBI - Unsorted Block Images"); | 1409 | MODULE_DESCRIPTION("UBI - Unsorted Block Images"); |
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index fb5567878181..dfcc65b33e99 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c | |||
@@ -140,9 +140,9 @@ static int vol_cdev_release(struct inode *inode, struct file *file) | |||
140 | vol->updating = 0; | 140 | vol->updating = 0; |
141 | vfree(vol->upd_buf); | 141 | vfree(vol->upd_buf); |
142 | } else if (vol->changing_leb) { | 142 | } else if (vol->changing_leb) { |
143 | dbg_gen("only %lld of %lld bytes received for atomic LEB change" | 143 | dbg_gen("only %lld of %lld bytes received for atomic LEB change for volume %d:%d, cancel", |
144 | " for volume %d:%d, cancel", vol->upd_received, | 144 | vol->upd_received, vol->upd_bytes, vol->ubi->ubi_num, |
145 | vol->upd_bytes, vol->ubi->ubi_num, vol->vol_id); | 145 | vol->vol_id); |
146 | vol->changing_leb = 0; | 146 | vol->changing_leb = 0; |
147 | vfree(vol->upd_buf); | 147 | vfree(vol->upd_buf); |
148 | } | 148 | } |
@@ -189,7 +189,8 @@ static loff_t vol_cdev_llseek(struct file *file, loff_t offset, int origin) | |||
189 | return new_offset; | 189 | return new_offset; |
190 | } | 190 | } |
191 | 191 | ||
192 | static int vol_cdev_fsync(struct file *file, loff_t start, loff_t end, int datasync) | 192 | static int vol_cdev_fsync(struct file *file, loff_t start, loff_t end, |
193 | int datasync) | ||
193 | { | 194 | { |
194 | struct ubi_volume_desc *desc = file->private_data; | 195 | struct ubi_volume_desc *desc = file->private_data; |
195 | struct ubi_device *ubi = desc->vol->ubi; | 196 | struct ubi_device *ubi = desc->vol->ubi; |
@@ -753,7 +754,7 @@ static int rename_volumes(struct ubi_device *ubi, | |||
753 | re->new_name_len = name_len; | 754 | re->new_name_len = name_len; |
754 | memcpy(re->new_name, name, name_len); | 755 | memcpy(re->new_name, name, name_len); |
755 | list_add_tail(&re->list, &rename_list); | 756 | list_add_tail(&re->list, &rename_list); |
756 | dbg_msg("will rename volume %d from \"%s\" to \"%s\"", | 757 | dbg_gen("will rename volume %d from \"%s\" to \"%s\"", |
757 | vol_id, re->desc->vol->name, name); | 758 | vol_id, re->desc->vol->name, name); |
758 | } | 759 | } |
759 | 760 | ||
@@ -811,7 +812,7 @@ static int rename_volumes(struct ubi_device *ubi, | |||
811 | re1->remove = 1; | 812 | re1->remove = 1; |
812 | re1->desc = desc; | 813 | re1->desc = desc; |
813 | list_add(&re1->list, &rename_list); | 814 | list_add(&re1->list, &rename_list); |
814 | dbg_msg("will remove volume %d, name \"%s\"", | 815 | dbg_gen("will remove volume %d, name \"%s\"", |
815 | re1->desc->vol->vol_id, re1->desc->vol->name); | 816 | re1->desc->vol->vol_id, re1->desc->vol->name); |
816 | } | 817 | } |
817 | 818 | ||
@@ -942,7 +943,7 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd, | |||
942 | { | 943 | { |
943 | struct ubi_rnvol_req *req; | 944 | struct ubi_rnvol_req *req; |
944 | 945 | ||
945 | dbg_msg("re-name volumes"); | 946 | dbg_gen("re-name volumes"); |
946 | req = kmalloc(sizeof(struct ubi_rnvol_req), GFP_KERNEL); | 947 | req = kmalloc(sizeof(struct ubi_rnvol_req), GFP_KERNEL); |
947 | if (!req) { | 948 | if (!req) { |
948 | err = -ENOMEM; | 949 | err = -ENOMEM; |
@@ -1010,7 +1011,8 @@ static long ctrl_cdev_ioctl(struct file *file, unsigned int cmd, | |||
1010 | * 'ubi_attach_mtd_dev()'. | 1011 | * 'ubi_attach_mtd_dev()'. |
1011 | */ | 1012 | */ |
1012 | mutex_lock(&ubi_devices_mutex); | 1013 | mutex_lock(&ubi_devices_mutex); |
1013 | err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset); | 1014 | err = ubi_attach_mtd_dev(mtd, req.ubi_num, req.vid_hdr_offset, |
1015 | req.max_beb_per1024); | ||
1014 | mutex_unlock(&ubi_devices_mutex); | 1016 | mutex_unlock(&ubi_devices_mutex); |
1015 | if (err < 0) | 1017 | if (err < 0) |
1016 | put_mtd_device(mtd); | 1018 | put_mtd_device(mtd); |
diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index 7c1380305219..26908a59506b 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c | |||
@@ -43,8 +43,8 @@ void ubi_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len) | |||
43 | return; | 43 | return; |
44 | err = mtd_read(ubi->mtd, addr, len, &read, buf); | 44 | err = mtd_read(ubi->mtd, addr, len, &read, buf); |
45 | if (err && err != -EUCLEAN) { | 45 | if (err && err != -EUCLEAN) { |
46 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " | 46 | ubi_err("error %d while reading %d bytes from PEB %d:%d, read %zd bytes", |
47 | "read %zd bytes", err, len, pnum, offset, read); | 47 | err, len, pnum, offset, read); |
48 | goto out; | 48 | goto out; |
49 | } | 49 | } |
50 | 50 | ||
@@ -62,21 +62,15 @@ out: | |||
62 | */ | 62 | */ |
63 | void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) | 63 | void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) |
64 | { | 64 | { |
65 | printk(KERN_DEBUG "Erase counter header dump:\n"); | 65 | pr_err("Erase counter header dump:\n"); |
66 | printk(KERN_DEBUG "\tmagic %#08x\n", | 66 | pr_err("\tmagic %#08x\n", be32_to_cpu(ec_hdr->magic)); |
67 | be32_to_cpu(ec_hdr->magic)); | 67 | pr_err("\tversion %d\n", (int)ec_hdr->version); |
68 | printk(KERN_DEBUG "\tversion %d\n", (int)ec_hdr->version); | 68 | pr_err("\tec %llu\n", (long long)be64_to_cpu(ec_hdr->ec)); |
69 | printk(KERN_DEBUG "\tec %llu\n", | 69 | pr_err("\tvid_hdr_offset %d\n", be32_to_cpu(ec_hdr->vid_hdr_offset)); |
70 | (long long)be64_to_cpu(ec_hdr->ec)); | 70 | pr_err("\tdata_offset %d\n", be32_to_cpu(ec_hdr->data_offset)); |
71 | printk(KERN_DEBUG "\tvid_hdr_offset %d\n", | 71 | pr_err("\timage_seq %d\n", be32_to_cpu(ec_hdr->image_seq)); |
72 | be32_to_cpu(ec_hdr->vid_hdr_offset)); | 72 | pr_err("\thdr_crc %#08x\n", be32_to_cpu(ec_hdr->hdr_crc)); |
73 | printk(KERN_DEBUG "\tdata_offset %d\n", | 73 | pr_err("erase counter header hexdump:\n"); |
74 | be32_to_cpu(ec_hdr->data_offset)); | ||
75 | printk(KERN_DEBUG "\timage_seq %d\n", | ||
76 | be32_to_cpu(ec_hdr->image_seq)); | ||
77 | printk(KERN_DEBUG "\thdr_crc %#08x\n", | ||
78 | be32_to_cpu(ec_hdr->hdr_crc)); | ||
79 | printk(KERN_DEBUG "erase counter header hexdump:\n"); | ||
80 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 74 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
81 | ec_hdr, UBI_EC_HDR_SIZE, 1); | 75 | ec_hdr, UBI_EC_HDR_SIZE, 1); |
82 | } | 76 | } |
@@ -87,21 +81,21 @@ void ubi_dump_ec_hdr(const struct ubi_ec_hdr *ec_hdr) | |||
87 | */ | 81 | */ |
88 | void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) | 82 | void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) |
89 | { | 83 | { |
90 | printk(KERN_DEBUG "Volume identifier header dump:\n"); | 84 | pr_err("Volume identifier header dump:\n"); |
91 | printk(KERN_DEBUG "\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); | 85 | pr_err("\tmagic %08x\n", be32_to_cpu(vid_hdr->magic)); |
92 | printk(KERN_DEBUG "\tversion %d\n", (int)vid_hdr->version); | 86 | pr_err("\tversion %d\n", (int)vid_hdr->version); |
93 | printk(KERN_DEBUG "\tvol_type %d\n", (int)vid_hdr->vol_type); | 87 | pr_err("\tvol_type %d\n", (int)vid_hdr->vol_type); |
94 | printk(KERN_DEBUG "\tcopy_flag %d\n", (int)vid_hdr->copy_flag); | 88 | pr_err("\tcopy_flag %d\n", (int)vid_hdr->copy_flag); |
95 | printk(KERN_DEBUG "\tcompat %d\n", (int)vid_hdr->compat); | 89 | pr_err("\tcompat %d\n", (int)vid_hdr->compat); |
96 | printk(KERN_DEBUG "\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id)); | 90 | pr_err("\tvol_id %d\n", be32_to_cpu(vid_hdr->vol_id)); |
97 | printk(KERN_DEBUG "\tlnum %d\n", be32_to_cpu(vid_hdr->lnum)); | 91 | pr_err("\tlnum %d\n", be32_to_cpu(vid_hdr->lnum)); |
98 | printk(KERN_DEBUG "\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size)); | 92 | pr_err("\tdata_size %d\n", be32_to_cpu(vid_hdr->data_size)); |
99 | printk(KERN_DEBUG "\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs)); | 93 | pr_err("\tused_ebs %d\n", be32_to_cpu(vid_hdr->used_ebs)); |
100 | printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad)); | 94 | pr_err("\tdata_pad %d\n", be32_to_cpu(vid_hdr->data_pad)); |
101 | printk(KERN_DEBUG "\tsqnum %llu\n", | 95 | pr_err("\tsqnum %llu\n", |
102 | (unsigned long long)be64_to_cpu(vid_hdr->sqnum)); | 96 | (unsigned long long)be64_to_cpu(vid_hdr->sqnum)); |
103 | printk(KERN_DEBUG "\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc)); | 97 | pr_err("\thdr_crc %08x\n", be32_to_cpu(vid_hdr->hdr_crc)); |
104 | printk(KERN_DEBUG "Volume identifier header hexdump:\n"); | 98 | pr_err("Volume identifier header hexdump:\n"); |
105 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 99 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
106 | vid_hdr, UBI_VID_HDR_SIZE, 1); | 100 | vid_hdr, UBI_VID_HDR_SIZE, 1); |
107 | } | 101 | } |
@@ -112,25 +106,25 @@ void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr) | |||
112 | */ | 106 | */ |
113 | void ubi_dump_vol_info(const struct ubi_volume *vol) | 107 | void ubi_dump_vol_info(const struct ubi_volume *vol) |
114 | { | 108 | { |
115 | printk(KERN_DEBUG "Volume information dump:\n"); | 109 | pr_err("Volume information dump:\n"); |
116 | printk(KERN_DEBUG "\tvol_id %d\n", vol->vol_id); | 110 | pr_err("\tvol_id %d\n", vol->vol_id); |
117 | printk(KERN_DEBUG "\treserved_pebs %d\n", vol->reserved_pebs); | 111 | pr_err("\treserved_pebs %d\n", vol->reserved_pebs); |
118 | printk(KERN_DEBUG "\talignment %d\n", vol->alignment); | 112 | pr_err("\talignment %d\n", vol->alignment); |
119 | printk(KERN_DEBUG "\tdata_pad %d\n", vol->data_pad); | 113 | pr_err("\tdata_pad %d\n", vol->data_pad); |
120 | printk(KERN_DEBUG "\tvol_type %d\n", vol->vol_type); | 114 | pr_err("\tvol_type %d\n", vol->vol_type); |
121 | printk(KERN_DEBUG "\tname_len %d\n", vol->name_len); | 115 | pr_err("\tname_len %d\n", vol->name_len); |
122 | printk(KERN_DEBUG "\tusable_leb_size %d\n", vol->usable_leb_size); | 116 | pr_err("\tusable_leb_size %d\n", vol->usable_leb_size); |
123 | printk(KERN_DEBUG "\tused_ebs %d\n", vol->used_ebs); | 117 | pr_err("\tused_ebs %d\n", vol->used_ebs); |
124 | printk(KERN_DEBUG "\tused_bytes %lld\n", vol->used_bytes); | 118 | pr_err("\tused_bytes %lld\n", vol->used_bytes); |
125 | printk(KERN_DEBUG "\tlast_eb_bytes %d\n", vol->last_eb_bytes); | 119 | pr_err("\tlast_eb_bytes %d\n", vol->last_eb_bytes); |
126 | printk(KERN_DEBUG "\tcorrupted %d\n", vol->corrupted); | 120 | pr_err("\tcorrupted %d\n", vol->corrupted); |
127 | printk(KERN_DEBUG "\tupd_marker %d\n", vol->upd_marker); | 121 | pr_err("\tupd_marker %d\n", vol->upd_marker); |
128 | 122 | ||
129 | if (vol->name_len <= UBI_VOL_NAME_MAX && | 123 | if (vol->name_len <= UBI_VOL_NAME_MAX && |
130 | strnlen(vol->name, vol->name_len + 1) == vol->name_len) { | 124 | strnlen(vol->name, vol->name_len + 1) == vol->name_len) { |
131 | printk(KERN_DEBUG "\tname %s\n", vol->name); | 125 | pr_err("\tname %s\n", vol->name); |
132 | } else { | 126 | } else { |
133 | printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n", | 127 | pr_err("\t1st 5 characters of name: %c%c%c%c%c\n", |
134 | vol->name[0], vol->name[1], vol->name[2], | 128 | vol->name[0], vol->name[1], vol->name[2], |
135 | vol->name[3], vol->name[4]); | 129 | vol->name[3], vol->name[4]); |
136 | } | 130 | } |
@@ -145,29 +139,28 @@ void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) | |||
145 | { | 139 | { |
146 | int name_len = be16_to_cpu(r->name_len); | 140 | int name_len = be16_to_cpu(r->name_len); |
147 | 141 | ||
148 | printk(KERN_DEBUG "Volume table record %d dump:\n", idx); | 142 | pr_err("Volume table record %d dump:\n", idx); |
149 | printk(KERN_DEBUG "\treserved_pebs %d\n", | 143 | pr_err("\treserved_pebs %d\n", be32_to_cpu(r->reserved_pebs)); |
150 | be32_to_cpu(r->reserved_pebs)); | 144 | pr_err("\talignment %d\n", be32_to_cpu(r->alignment)); |
151 | printk(KERN_DEBUG "\talignment %d\n", be32_to_cpu(r->alignment)); | 145 | pr_err("\tdata_pad %d\n", be32_to_cpu(r->data_pad)); |
152 | printk(KERN_DEBUG "\tdata_pad %d\n", be32_to_cpu(r->data_pad)); | 146 | pr_err("\tvol_type %d\n", (int)r->vol_type); |
153 | printk(KERN_DEBUG "\tvol_type %d\n", (int)r->vol_type); | 147 | pr_err("\tupd_marker %d\n", (int)r->upd_marker); |
154 | printk(KERN_DEBUG "\tupd_marker %d\n", (int)r->upd_marker); | 148 | pr_err("\tname_len %d\n", name_len); |
155 | printk(KERN_DEBUG "\tname_len %d\n", name_len); | ||
156 | 149 | ||
157 | if (r->name[0] == '\0') { | 150 | if (r->name[0] == '\0') { |
158 | printk(KERN_DEBUG "\tname NULL\n"); | 151 | pr_err("\tname NULL\n"); |
159 | return; | 152 | return; |
160 | } | 153 | } |
161 | 154 | ||
162 | if (name_len <= UBI_VOL_NAME_MAX && | 155 | if (name_len <= UBI_VOL_NAME_MAX && |
163 | strnlen(&r->name[0], name_len + 1) == name_len) { | 156 | strnlen(&r->name[0], name_len + 1) == name_len) { |
164 | printk(KERN_DEBUG "\tname %s\n", &r->name[0]); | 157 | pr_err("\tname %s\n", &r->name[0]); |
165 | } else { | 158 | } else { |
166 | printk(KERN_DEBUG "\t1st 5 characters of name: %c%c%c%c%c\n", | 159 | pr_err("\t1st 5 characters of name: %c%c%c%c%c\n", |
167 | r->name[0], r->name[1], r->name[2], r->name[3], | 160 | r->name[0], r->name[1], r->name[2], r->name[3], |
168 | r->name[4]); | 161 | r->name[4]); |
169 | } | 162 | } |
170 | printk(KERN_DEBUG "\tcrc %#08x\n", be32_to_cpu(r->crc)); | 163 | pr_err("\tcrc %#08x\n", be32_to_cpu(r->crc)); |
171 | } | 164 | } |
172 | 165 | ||
173 | /** | 166 | /** |
@@ -176,15 +169,15 @@ void ubi_dump_vtbl_record(const struct ubi_vtbl_record *r, int idx) | |||
176 | */ | 169 | */ |
177 | void ubi_dump_av(const struct ubi_ainf_volume *av) | 170 | void ubi_dump_av(const struct ubi_ainf_volume *av) |
178 | { | 171 | { |
179 | printk(KERN_DEBUG "Volume attaching information dump:\n"); | 172 | pr_err("Volume attaching information dump:\n"); |
180 | printk(KERN_DEBUG "\tvol_id %d\n", av->vol_id); | 173 | pr_err("\tvol_id %d\n", av->vol_id); |
181 | printk(KERN_DEBUG "\thighest_lnum %d\n", av->highest_lnum); | 174 | pr_err("\thighest_lnum %d\n", av->highest_lnum); |
182 | printk(KERN_DEBUG "\tleb_count %d\n", av->leb_count); | 175 | pr_err("\tleb_count %d\n", av->leb_count); |
183 | printk(KERN_DEBUG "\tcompat %d\n", av->compat); | 176 | pr_err("\tcompat %d\n", av->compat); |
184 | printk(KERN_DEBUG "\tvol_type %d\n", av->vol_type); | 177 | pr_err("\tvol_type %d\n", av->vol_type); |
185 | printk(KERN_DEBUG "\tused_ebs %d\n", av->used_ebs); | 178 | pr_err("\tused_ebs %d\n", av->used_ebs); |
186 | printk(KERN_DEBUG "\tlast_data_size %d\n", av->last_data_size); | 179 | pr_err("\tlast_data_size %d\n", av->last_data_size); |
187 | printk(KERN_DEBUG "\tdata_pad %d\n", av->data_pad); | 180 | pr_err("\tdata_pad %d\n", av->data_pad); |
188 | } | 181 | } |
189 | 182 | ||
190 | /** | 183 | /** |
@@ -194,13 +187,13 @@ void ubi_dump_av(const struct ubi_ainf_volume *av) | |||
194 | */ | 187 | */ |
195 | void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type) | 188 | void ubi_dump_aeb(const struct ubi_ainf_peb *aeb, int type) |
196 | { | 189 | { |
197 | printk(KERN_DEBUG "eraseblock attaching information dump:\n"); | 190 | pr_err("eraseblock attaching information dump:\n"); |
198 | printk(KERN_DEBUG "\tec %d\n", aeb->ec); | 191 | pr_err("\tec %d\n", aeb->ec); |
199 | printk(KERN_DEBUG "\tpnum %d\n", aeb->pnum); | 192 | pr_err("\tpnum %d\n", aeb->pnum); |
200 | if (type == 0) { | 193 | if (type == 0) { |
201 | printk(KERN_DEBUG "\tlnum %d\n", aeb->lnum); | 194 | pr_err("\tlnum %d\n", aeb->lnum); |
202 | printk(KERN_DEBUG "\tscrub %d\n", aeb->scrub); | 195 | pr_err("\tscrub %d\n", aeb->scrub); |
203 | printk(KERN_DEBUG "\tsqnum %llu\n", aeb->sqnum); | 196 | pr_err("\tsqnum %llu\n", aeb->sqnum); |
204 | } | 197 | } |
205 | } | 198 | } |
206 | 199 | ||
@@ -212,16 +205,16 @@ void ubi_dump_mkvol_req(const struct ubi_mkvol_req *req) | |||
212 | { | 205 | { |
213 | char nm[17]; | 206 | char nm[17]; |
214 | 207 | ||
215 | printk(KERN_DEBUG "Volume creation request dump:\n"); | 208 | pr_err("Volume creation request dump:\n"); |
216 | printk(KERN_DEBUG "\tvol_id %d\n", req->vol_id); | 209 | pr_err("\tvol_id %d\n", req->vol_id); |
217 | printk(KERN_DEBUG "\talignment %d\n", req->alignment); | 210 | pr_err("\talignment %d\n", req->alignment); |
218 | printk(KERN_DEBUG "\tbytes %lld\n", (long long)req->bytes); | 211 | pr_err("\tbytes %lld\n", (long long)req->bytes); |
219 | printk(KERN_DEBUG "\tvol_type %d\n", req->vol_type); | 212 | pr_err("\tvol_type %d\n", req->vol_type); |
220 | printk(KERN_DEBUG "\tname_len %d\n", req->name_len); | 213 | pr_err("\tname_len %d\n", req->name_len); |
221 | 214 | ||
222 | memcpy(nm, req->name, 16); | 215 | memcpy(nm, req->name, 16); |
223 | nm[16] = 0; | 216 | nm[16] = 0; |
224 | printk(KERN_DEBUG "\t1st 16 characters of name: %s\n", nm); | 217 | pr_err("\t1st 16 characters of name: %s\n", nm); |
225 | } | 218 | } |
226 | 219 | ||
227 | /** | 220 | /** |
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h index d5d2645b51a7..3dbc877d9663 100644 --- a/drivers/mtd/ubi/debug.h +++ b/drivers/mtd/ubi/debug.h | |||
@@ -29,22 +29,18 @@ void ubi_dump_vid_hdr(const struct ubi_vid_hdr *vid_hdr); | |||
29 | 29 | ||
30 | #define ubi_assert(expr) do { \ | 30 | #define ubi_assert(expr) do { \ |
31 | if (unlikely(!(expr))) { \ | 31 | if (unlikely(!(expr))) { \ |
32 | printk(KERN_CRIT "UBI assert failed in %s at %u (pid %d)\n", \ | 32 | pr_crit("UBI assert failed in %s at %u (pid %d)\n", \ |
33 | __func__, __LINE__, current->pid); \ | 33 | __func__, __LINE__, current->pid); \ |
34 | dump_stack(); \ | 34 | dump_stack(); \ |
35 | } \ | 35 | } \ |
36 | } while (0) | 36 | } while (0) |
37 | 37 | ||
38 | #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \ | 38 | #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \ |
39 | print_hex_dump(l, ps, pt, r, g, b, len, a) | 39 | print_hex_dump(l, ps, pt, r, g, b, len, a) |
40 | 40 | ||
41 | #define ubi_dbg_msg(type, fmt, ...) \ | 41 | #define ubi_dbg_msg(type, fmt, ...) \ |
42 | pr_debug("UBI DBG " type ": " fmt "\n", ##__VA_ARGS__) | 42 | pr_debug("UBI DBG " type " (pid %d): " fmt "\n", current->pid, \ |
43 | 43 | ##__VA_ARGS__) | |
44 | /* Just a debugging messages not related to any specific UBI subsystem */ | ||
45 | #define dbg_msg(fmt, ...) \ | ||
46 | printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \ | ||
47 | current->pid, __func__, ##__VA_ARGS__) | ||
48 | 44 | ||
49 | /* General debugging messages */ | 45 | /* General debugging messages */ |
50 | #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__) | 46 | #define dbg_gen(fmt, ...) ubi_dbg_msg("gen", fmt, ##__VA_ARGS__) |
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index b703ac7729cf..a26d7d253174 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c | |||
@@ -420,9 +420,8 @@ retry: | |||
420 | */ | 420 | */ |
421 | if (err == UBI_IO_BAD_HDR_EBADMSG || | 421 | if (err == UBI_IO_BAD_HDR_EBADMSG || |
422 | err == UBI_IO_BAD_HDR) { | 422 | err == UBI_IO_BAD_HDR) { |
423 | ubi_warn("corrupted VID header at PEB " | 423 | ubi_warn("corrupted VID header at PEB %d, LEB %d:%d", |
424 | "%d, LEB %d:%d", pnum, vol_id, | 424 | pnum, vol_id, lnum); |
425 | lnum); | ||
426 | err = -EBADMSG; | 425 | err = -EBADMSG; |
427 | } else | 426 | } else |
428 | ubi_ro_mode(ubi); | 427 | ubi_ro_mode(ubi); |
@@ -660,9 +659,8 @@ retry: | |||
660 | if (len) { | 659 | if (len) { |
661 | err = ubi_io_write_data(ubi, buf, pnum, offset, len); | 660 | err = ubi_io_write_data(ubi, buf, pnum, offset, len); |
662 | if (err) { | 661 | if (err) { |
663 | ubi_warn("failed to write %d bytes at offset %d of " | 662 | ubi_warn("failed to write %d bytes at offset %d of LEB %d:%d, PEB %d", |
664 | "LEB %d:%d, PEB %d", len, offset, vol_id, | 663 | len, offset, vol_id, lnum, pnum); |
665 | lnum, pnum); | ||
666 | goto write_error; | 664 | goto write_error; |
667 | } | 665 | } |
668 | } | 666 | } |
@@ -1040,9 +1038,8 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
1040 | * cancel it. | 1038 | * cancel it. |
1041 | */ | 1039 | */ |
1042 | if (vol->eba_tbl[lnum] != from) { | 1040 | if (vol->eba_tbl[lnum] != from) { |
1043 | dbg_wl("LEB %d:%d is no longer mapped to PEB %d, mapped to " | 1041 | dbg_wl("LEB %d:%d is no longer mapped to PEB %d, mapped to PEB %d, cancel", |
1044 | "PEB %d, cancel", vol_id, lnum, from, | 1042 | vol_id, lnum, from, vol->eba_tbl[lnum]); |
1045 | vol->eba_tbl[lnum]); | ||
1046 | err = MOVE_CANCEL_RACE; | 1043 | err = MOVE_CANCEL_RACE; |
1047 | goto out_unlock_leb; | 1044 | goto out_unlock_leb; |
1048 | } | 1045 | } |
@@ -1107,8 +1104,8 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
1107 | err = ubi_io_read_vid_hdr(ubi, to, vid_hdr, 1); | 1104 | err = ubi_io_read_vid_hdr(ubi, to, vid_hdr, 1); |
1108 | if (err) { | 1105 | if (err) { |
1109 | if (err != UBI_IO_BITFLIPS) { | 1106 | if (err != UBI_IO_BITFLIPS) { |
1110 | ubi_warn("error %d while reading VID header back from " | 1107 | ubi_warn("error %d while reading VID header back from PEB %d", |
1111 | "PEB %d", err, to); | 1108 | err, to); |
1112 | if (is_error_sane(err)) | 1109 | if (is_error_sane(err)) |
1113 | err = MOVE_TARGET_RD_ERR; | 1110 | err = MOVE_TARGET_RD_ERR; |
1114 | } else | 1111 | } else |
@@ -1134,8 +1131,8 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
1134 | err = ubi_io_read_data(ubi, ubi->peb_buf, to, 0, aldata_size); | 1131 | err = ubi_io_read_data(ubi, ubi->peb_buf, to, 0, aldata_size); |
1135 | if (err) { | 1132 | if (err) { |
1136 | if (err != UBI_IO_BITFLIPS) { | 1133 | if (err != UBI_IO_BITFLIPS) { |
1137 | ubi_warn("error %d while reading data back " | 1134 | ubi_warn("error %d while reading data back from PEB %d", |
1138 | "from PEB %d", err, to); | 1135 | err, to); |
1139 | if (is_error_sane(err)) | 1136 | if (is_error_sane(err)) |
1140 | err = MOVE_TARGET_RD_ERR; | 1137 | err = MOVE_TARGET_RD_ERR; |
1141 | } else | 1138 | } else |
@@ -1146,8 +1143,8 @@ int ubi_eba_copy_leb(struct ubi_device *ubi, int from, int to, | |||
1146 | cond_resched(); | 1143 | cond_resched(); |
1147 | 1144 | ||
1148 | if (crc != crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size)) { | 1145 | if (crc != crc32(UBI_CRC32_INIT, ubi->peb_buf, data_size)) { |
1149 | ubi_warn("read data back from PEB %d and it is " | 1146 | ubi_warn("read data back from PEB %d and it is different", |
1150 | "different", to); | 1147 | to); |
1151 | err = -EINVAL; | 1148 | err = -EINVAL; |
1152 | goto out_unlock_buf; | 1149 | goto out_unlock_buf; |
1153 | } | 1150 | } |
@@ -1197,11 +1194,11 @@ static void print_rsvd_warning(struct ubi_device *ubi, | |||
1197 | return; | 1194 | return; |
1198 | } | 1195 | } |
1199 | 1196 | ||
1200 | ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d," | 1197 | ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d, need %d", |
1201 | " need %d", ubi->beb_rsvd_pebs, ubi->beb_rsvd_level); | 1198 | ubi->beb_rsvd_pebs, ubi->beb_rsvd_level); |
1202 | if (ubi->corr_peb_count) | 1199 | if (ubi->corr_peb_count) |
1203 | ubi_warn("%d PEBs are corrupted and not used", | 1200 | ubi_warn("%d PEBs are corrupted and not used", |
1204 | ubi->corr_peb_count); | 1201 | ubi->corr_peb_count); |
1205 | } | 1202 | } |
1206 | 1203 | ||
1207 | /** | 1204 | /** |
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c index 4e44bee4c564..4bd4db8c84c9 100644 --- a/drivers/mtd/ubi/gluebi.c +++ b/drivers/mtd/ubi/gluebi.c | |||
@@ -41,7 +41,7 @@ | |||
41 | #include "ubi-media.h" | 41 | #include "ubi-media.h" |
42 | 42 | ||
43 | #define err_msg(fmt, ...) \ | 43 | #define err_msg(fmt, ...) \ |
44 | printk(KERN_DEBUG "gluebi (pid %d): %s: " fmt "\n", \ | 44 | pr_err("gluebi (pid %d): %s: " fmt "\n", \ |
45 | current->pid, __func__, ##__VA_ARGS__) | 45 | current->pid, __func__, ##__VA_ARGS__) |
46 | 46 | ||
47 | /** | 47 | /** |
@@ -341,9 +341,8 @@ static int gluebi_create(struct ubi_device_info *di, | |||
341 | mutex_lock(&devices_mutex); | 341 | mutex_lock(&devices_mutex); |
342 | g = find_gluebi_nolock(vi->ubi_num, vi->vol_id); | 342 | g = find_gluebi_nolock(vi->ubi_num, vi->vol_id); |
343 | if (g) | 343 | if (g) |
344 | err_msg("gluebi MTD device %d form UBI device %d volume %d " | 344 | err_msg("gluebi MTD device %d form UBI device %d volume %d already exists", |
345 | "already exists", g->mtd.index, vi->ubi_num, | 345 | g->mtd.index, vi->ubi_num, vi->vol_id); |
346 | vi->vol_id); | ||
347 | mutex_unlock(&devices_mutex); | 346 | mutex_unlock(&devices_mutex); |
348 | 347 | ||
349 | if (mtd_device_register(mtd, NULL, 0)) { | 348 | if (mtd_device_register(mtd, NULL, 0)) { |
@@ -376,8 +375,8 @@ static int gluebi_remove(struct ubi_volume_info *vi) | |||
376 | mutex_lock(&devices_mutex); | 375 | mutex_lock(&devices_mutex); |
377 | gluebi = find_gluebi_nolock(vi->ubi_num, vi->vol_id); | 376 | gluebi = find_gluebi_nolock(vi->ubi_num, vi->vol_id); |
378 | if (!gluebi) { | 377 | if (!gluebi) { |
379 | err_msg("got remove notification for unknown UBI device %d " | 378 | err_msg("got remove notification for unknown UBI device %d volume %d", |
380 | "volume %d", vi->ubi_num, vi->vol_id); | 379 | vi->ubi_num, vi->vol_id); |
381 | err = -ENOENT; | 380 | err = -ENOENT; |
382 | } else if (gluebi->refcnt) | 381 | } else if (gluebi->refcnt) |
383 | err = -EBUSY; | 382 | err = -EBUSY; |
@@ -390,9 +389,8 @@ static int gluebi_remove(struct ubi_volume_info *vi) | |||
390 | mtd = &gluebi->mtd; | 389 | mtd = &gluebi->mtd; |
391 | err = mtd_device_unregister(mtd); | 390 | err = mtd_device_unregister(mtd); |
392 | if (err) { | 391 | if (err) { |
393 | err_msg("cannot remove fake MTD device %d, UBI device %d, " | 392 | err_msg("cannot remove fake MTD device %d, UBI device %d, volume %d, error %d", |
394 | "volume %d, error %d", mtd->index, gluebi->ubi_num, | 393 | mtd->index, gluebi->ubi_num, gluebi->vol_id, err); |
395 | gluebi->vol_id, err); | ||
396 | mutex_lock(&devices_mutex); | 394 | mutex_lock(&devices_mutex); |
397 | list_add_tail(&gluebi->list, &gluebi_devices); | 395 | list_add_tail(&gluebi->list, &gluebi_devices); |
398 | mutex_unlock(&devices_mutex); | 396 | mutex_unlock(&devices_mutex); |
@@ -422,8 +420,8 @@ static int gluebi_updated(struct ubi_volume_info *vi) | |||
422 | gluebi = find_gluebi_nolock(vi->ubi_num, vi->vol_id); | 420 | gluebi = find_gluebi_nolock(vi->ubi_num, vi->vol_id); |
423 | if (!gluebi) { | 421 | if (!gluebi) { |
424 | mutex_unlock(&devices_mutex); | 422 | mutex_unlock(&devices_mutex); |
425 | err_msg("got update notification for unknown UBI device %d " | 423 | err_msg("got update notification for unknown UBI device %d volume %d", |
426 | "volume %d", vi->ubi_num, vi->vol_id); | 424 | vi->ubi_num, vi->vol_id); |
427 | return -ENOENT; | 425 | return -ENOENT; |
428 | } | 426 | } |
429 | 427 | ||
@@ -449,8 +447,8 @@ static int gluebi_resized(struct ubi_volume_info *vi) | |||
449 | gluebi = find_gluebi_nolock(vi->ubi_num, vi->vol_id); | 447 | gluebi = find_gluebi_nolock(vi->ubi_num, vi->vol_id); |
450 | if (!gluebi) { | 448 | if (!gluebi) { |
451 | mutex_unlock(&devices_mutex); | 449 | mutex_unlock(&devices_mutex); |
452 | err_msg("got update notification for unknown UBI device %d " | 450 | err_msg("got update notification for unknown UBI device %d volume %d", |
453 | "volume %d", vi->ubi_num, vi->vol_id); | 451 | vi->ubi_num, vi->vol_id); |
454 | return -ENOENT; | 452 | return -ENOENT; |
455 | } | 453 | } |
456 | gluebi->mtd.size = vi->used_bytes; | 454 | gluebi->mtd.size = vi->used_bytes; |
@@ -507,9 +505,9 @@ static void __exit ubi_gluebi_exit(void) | |||
507 | 505 | ||
508 | err = mtd_device_unregister(mtd); | 506 | err = mtd_device_unregister(mtd); |
509 | if (err) | 507 | if (err) |
510 | err_msg("error %d while removing gluebi MTD device %d, " | 508 | err_msg("error %d while removing gluebi MTD device %d, UBI device %d, volume %d - ignoring", |
511 | "UBI device %d, volume %d - ignoring", err, | 509 | err, mtd->index, gluebi->ubi_num, |
512 | mtd->index, gluebi->ubi_num, gluebi->vol_id); | 510 | gluebi->vol_id); |
513 | kfree(mtd->name); | 511 | kfree(mtd->name); |
514 | kfree(gluebi); | 512 | kfree(gluebi); |
515 | } | 513 | } |
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index a8d523794b52..78a1dcbf2107 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -177,21 +177,20 @@ retry: | |||
177 | * enabled. A corresponding message will be printed | 177 | * enabled. A corresponding message will be printed |
178 | * later, when it is has been scrubbed. | 178 | * later, when it is has been scrubbed. |
179 | */ | 179 | */ |
180 | dbg_msg("fixable bit-flip detected at PEB %d", pnum); | 180 | ubi_msg("fixable bit-flip detected at PEB %d", pnum); |
181 | ubi_assert(len == read); | 181 | ubi_assert(len == read); |
182 | return UBI_IO_BITFLIPS; | 182 | return UBI_IO_BITFLIPS; |
183 | } | 183 | } |
184 | 184 | ||
185 | if (retries++ < UBI_IO_RETRIES) { | 185 | if (retries++ < UBI_IO_RETRIES) { |
186 | ubi_warn("error %d%s while reading %d bytes from PEB " | 186 | ubi_warn("error %d%s while reading %d bytes from PEB %d:%d, read only %zd bytes, retry", |
187 | "%d:%d, read only %zd bytes, retry", | ||
188 | err, errstr, len, pnum, offset, read); | 187 | err, errstr, len, pnum, offset, read); |
189 | yield(); | 188 | yield(); |
190 | goto retry; | 189 | goto retry; |
191 | } | 190 | } |
192 | 191 | ||
193 | ubi_err("error %d%s while reading %d bytes from PEB %d:%d, " | 192 | ubi_err("error %d%s while reading %d bytes from PEB %d:%d, read %zd bytes", |
194 | "read %zd bytes", err, errstr, len, pnum, offset, read); | 193 | err, errstr, len, pnum, offset, read); |
195 | dump_stack(); | 194 | dump_stack(); |
196 | 195 | ||
197 | /* | 196 | /* |
@@ -274,8 +273,8 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
274 | } | 273 | } |
275 | 274 | ||
276 | if (ubi_dbg_is_write_failure(ubi)) { | 275 | if (ubi_dbg_is_write_failure(ubi)) { |
277 | ubi_err("cannot write %d bytes to PEB %d:%d " | 276 | ubi_err("cannot write %d bytes to PEB %d:%d (emulated)", |
278 | "(emulated)", len, pnum, offset); | 277 | len, pnum, offset); |
279 | dump_stack(); | 278 | dump_stack(); |
280 | return -EIO; | 279 | return -EIO; |
281 | } | 280 | } |
@@ -283,8 +282,8 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
283 | addr = (loff_t)pnum * ubi->peb_size + offset; | 282 | addr = (loff_t)pnum * ubi->peb_size + offset; |
284 | err = mtd_write(ubi->mtd, addr, len, &written, buf); | 283 | err = mtd_write(ubi->mtd, addr, len, &written, buf); |
285 | if (err) { | 284 | if (err) { |
286 | ubi_err("error %d while writing %d bytes to PEB %d:%d, written " | 285 | ubi_err("error %d while writing %d bytes to PEB %d:%d, written %zd bytes", |
287 | "%zd bytes", err, len, pnum, offset, written); | 286 | err, len, pnum, offset, written); |
288 | dump_stack(); | 287 | dump_stack(); |
289 | ubi_dump_flash(ubi, pnum, offset, len); | 288 | ubi_dump_flash(ubi, pnum, offset, len); |
290 | } else | 289 | } else |
@@ -685,8 +684,7 @@ static int validate_ec_hdr(const struct ubi_device *ubi, | |||
685 | leb_start = be32_to_cpu(ec_hdr->data_offset); | 684 | leb_start = be32_to_cpu(ec_hdr->data_offset); |
686 | 685 | ||
687 | if (ec_hdr->version != UBI_VERSION) { | 686 | if (ec_hdr->version != UBI_VERSION) { |
688 | ubi_err("node with incompatible UBI version found: " | 687 | ubi_err("node with incompatible UBI version found: this UBI version is %d, image version is %d", |
689 | "this UBI version is %d, image version is %d", | ||
690 | UBI_VERSION, (int)ec_hdr->version); | 688 | UBI_VERSION, (int)ec_hdr->version); |
691 | goto bad; | 689 | goto bad; |
692 | } | 690 | } |
@@ -777,10 +775,10 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
777 | if (ubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { | 775 | if (ubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { |
778 | /* The physical eraseblock is supposedly empty */ | 776 | /* The physical eraseblock is supposedly empty */ |
779 | if (verbose) | 777 | if (verbose) |
780 | ubi_warn("no EC header found at PEB %d, " | 778 | ubi_warn("no EC header found at PEB %d, only 0xFF bytes", |
781 | "only 0xFF bytes", pnum); | 779 | pnum); |
782 | dbg_bld("no EC header found at PEB %d, " | 780 | dbg_bld("no EC header found at PEB %d, only 0xFF bytes", |
783 | "only 0xFF bytes", pnum); | 781 | pnum); |
784 | if (!read_err) | 782 | if (!read_err) |
785 | return UBI_IO_FF; | 783 | return UBI_IO_FF; |
786 | else | 784 | else |
@@ -792,12 +790,12 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
792 | * 0xFF bytes. Report that the header is corrupted. | 790 | * 0xFF bytes. Report that the header is corrupted. |
793 | */ | 791 | */ |
794 | if (verbose) { | 792 | if (verbose) { |
795 | ubi_warn("bad magic number at PEB %d: %08x instead of " | 793 | ubi_warn("bad magic number at PEB %d: %08x instead of %08x", |
796 | "%08x", pnum, magic, UBI_EC_HDR_MAGIC); | 794 | pnum, magic, UBI_EC_HDR_MAGIC); |
797 | ubi_dump_ec_hdr(ec_hdr); | 795 | ubi_dump_ec_hdr(ec_hdr); |
798 | } | 796 | } |
799 | dbg_bld("bad magic number at PEB %d: %08x instead of " | 797 | dbg_bld("bad magic number at PEB %d: %08x instead of %08x", |
800 | "%08x", pnum, magic, UBI_EC_HDR_MAGIC); | 798 | pnum, magic, UBI_EC_HDR_MAGIC); |
801 | return UBI_IO_BAD_HDR; | 799 | return UBI_IO_BAD_HDR; |
802 | } | 800 | } |
803 | 801 | ||
@@ -806,12 +804,12 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
806 | 804 | ||
807 | if (hdr_crc != crc) { | 805 | if (hdr_crc != crc) { |
808 | if (verbose) { | 806 | if (verbose) { |
809 | ubi_warn("bad EC header CRC at PEB %d, calculated " | 807 | ubi_warn("bad EC header CRC at PEB %d, calculated %#08x, read %#08x", |
810 | "%#08x, read %#08x", pnum, crc, hdr_crc); | 808 | pnum, crc, hdr_crc); |
811 | ubi_dump_ec_hdr(ec_hdr); | 809 | ubi_dump_ec_hdr(ec_hdr); |
812 | } | 810 | } |
813 | dbg_bld("bad EC header CRC at PEB %d, calculated " | 811 | dbg_bld("bad EC header CRC at PEB %d, calculated %#08x, read %#08x", |
814 | "%#08x, read %#08x", pnum, crc, hdr_crc); | 812 | pnum, crc, hdr_crc); |
815 | 813 | ||
816 | if (!read_err) | 814 | if (!read_err) |
817 | return UBI_IO_BAD_HDR; | 815 | return UBI_IO_BAD_HDR; |
@@ -1032,10 +1030,10 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1032 | 1030 | ||
1033 | if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { | 1031 | if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { |
1034 | if (verbose) | 1032 | if (verbose) |
1035 | ubi_warn("no VID header found at PEB %d, " | 1033 | ubi_warn("no VID header found at PEB %d, only 0xFF bytes", |
1036 | "only 0xFF bytes", pnum); | 1034 | pnum); |
1037 | dbg_bld("no VID header found at PEB %d, " | 1035 | dbg_bld("no VID header found at PEB %d, only 0xFF bytes", |
1038 | "only 0xFF bytes", pnum); | 1036 | pnum); |
1039 | if (!read_err) | 1037 | if (!read_err) |
1040 | return UBI_IO_FF; | 1038 | return UBI_IO_FF; |
1041 | else | 1039 | else |
@@ -1043,12 +1041,12 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1043 | } | 1041 | } |
1044 | 1042 | ||
1045 | if (verbose) { | 1043 | if (verbose) { |
1046 | ubi_warn("bad magic number at PEB %d: %08x instead of " | 1044 | ubi_warn("bad magic number at PEB %d: %08x instead of %08x", |
1047 | "%08x", pnum, magic, UBI_VID_HDR_MAGIC); | 1045 | pnum, magic, UBI_VID_HDR_MAGIC); |
1048 | ubi_dump_vid_hdr(vid_hdr); | 1046 | ubi_dump_vid_hdr(vid_hdr); |
1049 | } | 1047 | } |
1050 | dbg_bld("bad magic number at PEB %d: %08x instead of " | 1048 | dbg_bld("bad magic number at PEB %d: %08x instead of %08x", |
1051 | "%08x", pnum, magic, UBI_VID_HDR_MAGIC); | 1049 | pnum, magic, UBI_VID_HDR_MAGIC); |
1052 | return UBI_IO_BAD_HDR; | 1050 | return UBI_IO_BAD_HDR; |
1053 | } | 1051 | } |
1054 | 1052 | ||
@@ -1057,12 +1055,12 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1057 | 1055 | ||
1058 | if (hdr_crc != crc) { | 1056 | if (hdr_crc != crc) { |
1059 | if (verbose) { | 1057 | if (verbose) { |
1060 | ubi_warn("bad CRC at PEB %d, calculated %#08x, " | 1058 | ubi_warn("bad CRC at PEB %d, calculated %#08x, read %#08x", |
1061 | "read %#08x", pnum, crc, hdr_crc); | 1059 | pnum, crc, hdr_crc); |
1062 | ubi_dump_vid_hdr(vid_hdr); | 1060 | ubi_dump_vid_hdr(vid_hdr); |
1063 | } | 1061 | } |
1064 | dbg_bld("bad CRC at PEB %d, calculated %#08x, " | 1062 | dbg_bld("bad CRC at PEB %d, calculated %#08x, read %#08x", |
1065 | "read %#08x", pnum, crc, hdr_crc); | 1063 | pnum, crc, hdr_crc); |
1066 | if (!read_err) | 1064 | if (!read_err) |
1067 | return UBI_IO_BAD_HDR; | 1065 | return UBI_IO_BAD_HDR; |
1068 | else | 1066 | else |
@@ -1300,8 +1298,8 @@ static int self_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | |||
1300 | crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC); | 1298 | crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_EC_HDR_SIZE_CRC); |
1301 | hdr_crc = be32_to_cpu(vid_hdr->hdr_crc); | 1299 | hdr_crc = be32_to_cpu(vid_hdr->hdr_crc); |
1302 | if (hdr_crc != crc) { | 1300 | if (hdr_crc != crc) { |
1303 | ubi_err("bad VID header CRC at PEB %d, calculated %#08x, " | 1301 | ubi_err("bad VID header CRC at PEB %d, calculated %#08x, read %#08x", |
1304 | "read %#08x", pnum, crc, hdr_crc); | 1302 | pnum, crc, hdr_crc); |
1305 | ubi_err("self-check failed for PEB %d", pnum); | 1303 | ubi_err("self-check failed for PEB %d", pnum); |
1306 | ubi_dump_vid_hdr(vid_hdr); | 1304 | ubi_dump_vid_hdr(vid_hdr); |
1307 | dump_stack(); | 1305 | dump_stack(); |
@@ -1411,15 +1409,15 @@ int ubi_self_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | |||
1411 | 1409 | ||
1412 | err = mtd_read(ubi->mtd, addr, len, &read, buf); | 1410 | err = mtd_read(ubi->mtd, addr, len, &read, buf); |
1413 | if (err && !mtd_is_bitflip(err)) { | 1411 | if (err && !mtd_is_bitflip(err)) { |
1414 | ubi_err("error %d while reading %d bytes from PEB %d:%d, " | 1412 | ubi_err("error %d while reading %d bytes from PEB %d:%d, read %zd bytes", |
1415 | "read %zd bytes", err, len, pnum, offset, read); | 1413 | err, len, pnum, offset, read); |
1416 | goto error; | 1414 | goto error; |
1417 | } | 1415 | } |
1418 | 1416 | ||
1419 | err = ubi_check_pattern(buf, 0xFF, len); | 1417 | err = ubi_check_pattern(buf, 0xFF, len); |
1420 | if (err == 0) { | 1418 | if (err == 0) { |
1421 | ubi_err("flash region at PEB %d:%d, length %d does not " | 1419 | ubi_err("flash region at PEB %d:%d, length %d does not contain all 0xFF bytes", |
1422 | "contain all 0xFF bytes", pnum, offset, len); | 1420 | pnum, offset, len); |
1423 | goto fail; | 1421 | goto fail; |
1424 | } | 1422 | } |
1425 | 1423 | ||
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c index 8bbfb444b895..f913d701a5b3 100644 --- a/drivers/mtd/ubi/misc.c +++ b/drivers/mtd/ubi/misc.c | |||
@@ -121,10 +121,16 @@ void ubi_update_reserved(struct ubi_device *ubi) | |||
121 | */ | 121 | */ |
122 | void ubi_calculate_reserved(struct ubi_device *ubi) | 122 | void ubi_calculate_reserved(struct ubi_device *ubi) |
123 | { | 123 | { |
124 | ubi->beb_rsvd_level = ubi->good_peb_count/100; | 124 | /* |
125 | ubi->beb_rsvd_level *= CONFIG_MTD_UBI_BEB_RESERVE; | 125 | * Calculate the actual number of PEBs currently needed to be reserved |
126 | if (ubi->beb_rsvd_level < MIN_RESEVED_PEBS) | 126 | * for future bad eraseblock handling. |
127 | ubi->beb_rsvd_level = MIN_RESEVED_PEBS; | 127 | */ |
128 | ubi->beb_rsvd_level = ubi->bad_peb_limit - ubi->bad_peb_count; | ||
129 | if (ubi->beb_rsvd_level < 0) { | ||
130 | ubi->beb_rsvd_level = 0; | ||
131 | ubi_warn("number of bad PEBs (%d) is above the expected limit (%d), not reserving any PEBs for bad PEB handling, will use available PEBs (if any)", | ||
132 | ubi->bad_peb_count, ubi->bad_peb_limit); | ||
133 | } | ||
128 | } | 134 | } |
129 | 135 | ||
130 | /** | 136 | /** |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 84f66e3fa05d..383ee43d2425 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -51,17 +51,14 @@ | |||
51 | #define UBI_NAME_STR "ubi" | 51 | #define UBI_NAME_STR "ubi" |
52 | 52 | ||
53 | /* Normal UBI messages */ | 53 | /* Normal UBI messages */ |
54 | #define ubi_msg(fmt, ...) printk(KERN_NOTICE "UBI: " fmt "\n", ##__VA_ARGS__) | 54 | #define ubi_msg(fmt, ...) pr_notice("UBI: " fmt "\n", ##__VA_ARGS__) |
55 | /* UBI warning messages */ | 55 | /* UBI warning messages */ |
56 | #define ubi_warn(fmt, ...) printk(KERN_WARNING "UBI warning: %s: " fmt "\n", \ | 56 | #define ubi_warn(fmt, ...) pr_warn("UBI warning: %s: " fmt "\n", \ |
57 | __func__, ##__VA_ARGS__) | 57 | __func__, ##__VA_ARGS__) |
58 | /* UBI error messages */ | 58 | /* UBI error messages */ |
59 | #define ubi_err(fmt, ...) printk(KERN_ERR "UBI error: %s: " fmt "\n", \ | 59 | #define ubi_err(fmt, ...) pr_err("UBI error: %s: " fmt "\n", \ |
60 | __func__, ##__VA_ARGS__) | 60 | __func__, ##__VA_ARGS__) |
61 | 61 | ||
62 | /* Lowest number PEBs reserved for bad PEB handling */ | ||
63 | #define MIN_RESEVED_PEBS 2 | ||
64 | |||
65 | /* Background thread name pattern */ | 62 | /* Background thread name pattern */ |
66 | #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd" | 63 | #define UBI_BGT_NAME_PATTERN "ubi_bgt%dd" |
67 | 64 | ||
@@ -363,6 +360,7 @@ struct ubi_wl_entry; | |||
363 | * @flash_size: underlying MTD device size (in bytes) | 360 | * @flash_size: underlying MTD device size (in bytes) |
364 | * @peb_count: count of physical eraseblocks on the MTD device | 361 | * @peb_count: count of physical eraseblocks on the MTD device |
365 | * @peb_size: physical eraseblock size | 362 | * @peb_size: physical eraseblock size |
363 | * @bad_peb_limit: top limit of expected bad physical eraseblocks | ||
366 | * @bad_peb_count: count of bad physical eraseblocks | 364 | * @bad_peb_count: count of bad physical eraseblocks |
367 | * @good_peb_count: count of good physical eraseblocks | 365 | * @good_peb_count: count of good physical eraseblocks |
368 | * @corr_peb_count: count of corrupted physical eraseblocks (preserved and not | 366 | * @corr_peb_count: count of corrupted physical eraseblocks (preserved and not |
@@ -410,6 +408,7 @@ struct ubi_device { | |||
410 | int avail_pebs; | 408 | int avail_pebs; |
411 | int beb_rsvd_pebs; | 409 | int beb_rsvd_pebs; |
412 | int beb_rsvd_level; | 410 | int beb_rsvd_level; |
411 | int bad_peb_limit; | ||
413 | 412 | ||
414 | int autoresize_vol_id; | 413 | int autoresize_vol_id; |
415 | int vtbl_slots; | 414 | int vtbl_slots; |
@@ -694,7 +693,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
694 | struct ubi_vid_hdr *vid_hdr); | 693 | struct ubi_vid_hdr *vid_hdr); |
695 | 694 | ||
696 | /* build.c */ | 695 | /* build.c */ |
697 | int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset); | 696 | int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, |
697 | int vid_hdr_offset, int max_beb_per1024); | ||
698 | int ubi_detach_mtd_dev(int ubi_num, int anyway); | 698 | int ubi_detach_mtd_dev(int ubi_num, int anyway); |
699 | struct ubi_device *ubi_get_device(int ubi_num); | 699 | struct ubi_device *ubi_get_device(int ubi_num); |
700 | void ubi_put_device(struct ubi_device *ubi); | 700 | void ubi_put_device(struct ubi_device *ubi); |
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index 568307cc7caf..926e3df14fb2 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c | |||
@@ -270,8 +270,8 @@ static int vtbl_check(const struct ubi_device *ubi, | |||
270 | 270 | ||
271 | if (len1 > 0 && len1 == len2 && | 271 | if (len1 > 0 && len1 == len2 && |
272 | !strncmp(vtbl[i].name, vtbl[n].name, len1)) { | 272 | !strncmp(vtbl[i].name, vtbl[n].name, len1)) { |
273 | ubi_err("volumes %d and %d have the same name" | 273 | ubi_err("volumes %d and %d have the same name \"%s\"", |
274 | " \"%s\"", i, n, vtbl[i].name); | 274 | i, n, vtbl[i].name); |
275 | ubi_dump_vtbl_record(&vtbl[i], i); | 275 | ubi_dump_vtbl_record(&vtbl[i], i); |
276 | ubi_dump_vtbl_record(&vtbl[n], n); | 276 | ubi_dump_vtbl_record(&vtbl[n], n); |
277 | return -EINVAL; | 277 | return -EINVAL; |
@@ -304,7 +304,7 @@ static int create_vtbl(struct ubi_device *ubi, struct ubi_attach_info *ai, | |||
304 | struct ubi_vid_hdr *vid_hdr; | 304 | struct ubi_vid_hdr *vid_hdr; |
305 | struct ubi_ainf_peb *new_aeb; | 305 | struct ubi_ainf_peb *new_aeb; |
306 | 306 | ||
307 | ubi_msg("create volume table (copy #%d)", copy + 1); | 307 | dbg_gen("create volume table (copy #%d)", copy + 1); |
308 | 308 | ||
309 | vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); | 309 | vid_hdr = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); |
310 | if (!vid_hdr) | 310 | if (!vid_hdr) |
@@ -562,8 +562,8 @@ static int init_volumes(struct ubi_device *ubi, | |||
562 | if (vtbl[i].flags & UBI_VTBL_AUTORESIZE_FLG) { | 562 | if (vtbl[i].flags & UBI_VTBL_AUTORESIZE_FLG) { |
563 | /* Auto re-size flag may be set only for one volume */ | 563 | /* Auto re-size flag may be set only for one volume */ |
564 | if (ubi->autoresize_vol_id != -1) { | 564 | if (ubi->autoresize_vol_id != -1) { |
565 | ubi_err("more than one auto-resize volume (%d " | 565 | ubi_err("more than one auto-resize volume (%d and %d)", |
566 | "and %d)", ubi->autoresize_vol_id, i); | 566 | ubi->autoresize_vol_id, i); |
567 | kfree(vol); | 567 | kfree(vol); |
568 | return -EINVAL; | 568 | return -EINVAL; |
569 | } | 569 | } |
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index b6be644e7b85..032fc57f1090 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -978,9 +978,10 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, | |||
978 | int cancel) | 978 | int cancel) |
979 | { | 979 | { |
980 | struct ubi_wl_entry *e = wl_wrk->e; | 980 | struct ubi_wl_entry *e = wl_wrk->e; |
981 | int pnum = e->pnum, err, need; | 981 | int pnum = e->pnum; |
982 | int vol_id = wl_wrk->vol_id; | 982 | int vol_id = wl_wrk->vol_id; |
983 | int lnum = wl_wrk->lnum; | 983 | int lnum = wl_wrk->lnum; |
984 | int err, available_consumed = 0; | ||
984 | 985 | ||
985 | if (cancel) { | 986 | if (cancel) { |
986 | dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec); | 987 | dbg_wl("cancel erasure of PEB %d EC %d", pnum, e->ec); |
@@ -1045,20 +1046,14 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, | |||
1045 | } | 1046 | } |
1046 | 1047 | ||
1047 | spin_lock(&ubi->volumes_lock); | 1048 | spin_lock(&ubi->volumes_lock); |
1048 | need = ubi->beb_rsvd_level - ubi->beb_rsvd_pebs + 1; | ||
1049 | if (need > 0) { | ||
1050 | need = ubi->avail_pebs >= need ? need : ubi->avail_pebs; | ||
1051 | ubi->avail_pebs -= need; | ||
1052 | ubi->rsvd_pebs += need; | ||
1053 | ubi->beb_rsvd_pebs += need; | ||
1054 | if (need > 0) | ||
1055 | ubi_msg("reserve more %d PEBs", need); | ||
1056 | } | ||
1057 | |||
1058 | if (ubi->beb_rsvd_pebs == 0) { | 1049 | if (ubi->beb_rsvd_pebs == 0) { |
1059 | spin_unlock(&ubi->volumes_lock); | 1050 | if (ubi->avail_pebs == 0) { |
1060 | ubi_err("no reserved physical eraseblocks"); | 1051 | spin_unlock(&ubi->volumes_lock); |
1061 | goto out_ro; | 1052 | ubi_err("no reserved/available physical eraseblocks"); |
1053 | goto out_ro; | ||
1054 | } | ||
1055 | ubi->avail_pebs -= 1; | ||
1056 | available_consumed = 1; | ||
1062 | } | 1057 | } |
1063 | spin_unlock(&ubi->volumes_lock); | 1058 | spin_unlock(&ubi->volumes_lock); |
1064 | 1059 | ||
@@ -1068,19 +1063,36 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk, | |||
1068 | goto out_ro; | 1063 | goto out_ro; |
1069 | 1064 | ||
1070 | spin_lock(&ubi->volumes_lock); | 1065 | spin_lock(&ubi->volumes_lock); |
1071 | ubi->beb_rsvd_pebs -= 1; | 1066 | if (ubi->beb_rsvd_pebs > 0) { |
1067 | if (available_consumed) { | ||
1068 | /* | ||
1069 | * The amount of reserved PEBs increased since we last | ||
1070 | * checked. | ||
1071 | */ | ||
1072 | ubi->avail_pebs += 1; | ||
1073 | available_consumed = 0; | ||
1074 | } | ||
1075 | ubi->beb_rsvd_pebs -= 1; | ||
1076 | } | ||
1072 | ubi->bad_peb_count += 1; | 1077 | ubi->bad_peb_count += 1; |
1073 | ubi->good_peb_count -= 1; | 1078 | ubi->good_peb_count -= 1; |
1074 | ubi_calculate_reserved(ubi); | 1079 | ubi_calculate_reserved(ubi); |
1075 | if (ubi->beb_rsvd_pebs) | 1080 | if (available_consumed) |
1081 | ubi_warn("no PEBs in the reserved pool, used an available PEB"); | ||
1082 | else if (ubi->beb_rsvd_pebs) | ||
1076 | ubi_msg("%d PEBs left in the reserve", ubi->beb_rsvd_pebs); | 1083 | ubi_msg("%d PEBs left in the reserve", ubi->beb_rsvd_pebs); |
1077 | else | 1084 | else |
1078 | ubi_warn("last PEB from the reserved pool was used"); | 1085 | ubi_warn("last PEB from the reserve was used"); |
1079 | spin_unlock(&ubi->volumes_lock); | 1086 | spin_unlock(&ubi->volumes_lock); |
1080 | 1087 | ||
1081 | return err; | 1088 | return err; |
1082 | 1089 | ||
1083 | out_ro: | 1090 | out_ro: |
1091 | if (available_consumed) { | ||
1092 | spin_lock(&ubi->volumes_lock); | ||
1093 | ubi->avail_pebs += 1; | ||
1094 | spin_unlock(&ubi->volumes_lock); | ||
1095 | } | ||
1084 | ubi_ro_mode(ubi); | 1096 | ubi_ro_mode(ubi); |
1085 | return err; | 1097 | return err; |
1086 | } | 1098 | } |
@@ -1189,7 +1201,7 @@ int ubi_wl_scrub_peb(struct ubi_device *ubi, int pnum) | |||
1189 | { | 1201 | { |
1190 | struct ubi_wl_entry *e; | 1202 | struct ubi_wl_entry *e; |
1191 | 1203 | ||
1192 | dbg_msg("schedule PEB %d for scrubbing", pnum); | 1204 | ubi_msg("schedule PEB %d for scrubbing", pnum); |
1193 | 1205 | ||
1194 | retry: | 1206 | retry: |
1195 | spin_lock(&ubi->wl_lock); | 1207 | spin_lock(&ubi->wl_lock); |