Skip to content

Commit

Permalink
Merge tag 'upstream-3.7-rc1' of git://git.infradead.org/linux-ubi
Browse files Browse the repository at this point in the history
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
  ...
  • Loading branch information
Linus Torvalds committed Oct 3, 2012
2 parents 782c3fb + 55393ba commit 65b99c7
Show file tree
Hide file tree
Showing 17 changed files with 412 additions and 325 deletions.
2 changes: 1 addition & 1 deletion arch/arm/configs/sam9_l9260_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CONFIG_MTD_NAND=y
CONFIG_MTD_NAND_ATMEL=y
CONFIG_MTD_NAND_PLATFORM=y
CONFIG_MTD_UBI=y
CONFIG_MTD_UBI_BEB_RESERVE=3
CONFIG_MTD_UBI_BEB_LIMIT=25
CONFIG_MTD_UBI_GLUEBI=y
CONFIG_BLK_DEV_LOOP=y
CONFIG_BLK_DEV_RAM=y
Expand Down
12 changes: 11 additions & 1 deletion drivers/mtd/mtdpart.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types,
return ret;
}

int mtd_is_partition(struct mtd_info *mtd)
int mtd_is_partition(const struct mtd_info *mtd)
{
struct mtd_part *part;
int ispart = 0;
Expand All @@ -760,3 +760,13 @@ int mtd_is_partition(struct mtd_info *mtd)
return ispart;
}
EXPORT_SYMBOL_GPL(mtd_is_partition);

/* Returns the size of the entire flash chip */
uint64_t mtd_get_device_size(const struct mtd_info *mtd)
{
if (!mtd_is_partition(mtd))
return mtd->size;

return PART(mtd)->master->size;
}
EXPORT_SYMBOL_GPL(mtd_get_device_size);
40 changes: 27 additions & 13 deletions drivers/mtd/ubi/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,34 @@ config MTD_UBI_WL_THRESHOLD
life-cycle less than 10000, the threshold should be lessened (e.g.,
to 128 or 256, although it does not have to be power of 2).

config MTD_UBI_BEB_RESERVE
int "Percentage of reserved eraseblocks for bad eraseblocks handling"
default 2
range 0 25
config MTD_UBI_BEB_LIMIT
int "Maximum expected bad eraseblock count per 1024 eraseblocks"
default 20
range 0 768
help
If the MTD device admits of bad eraseblocks (e.g. NAND flash), UBI
reserves some amount of physical eraseblocks to handle new bad
eraseblocks. For example, if a flash physical eraseblock becomes bad,
UBI uses these reserved physical eraseblocks to relocate the bad one.
This option specifies how many physical eraseblocks will be reserved
for bad eraseblock handling (percents of total number of good flash
eraseblocks). If the underlying flash does not admit of bad
eraseblocks (e.g. NOR flash), this value is ignored and nothing is
reserved. Leave the default value if unsure.
This option specifies the maximum bad physical eraseblocks UBI
expects on the MTD device (per 1024 eraseblocks). If the underlying
flash does not admit of bad eraseblocks (e.g. NOR flash), this value
is ignored.

NAND datasheets often specify the minimum and maximum NVM (Number of
Valid Blocks) for the flashes' endurance lifetime. The maximum
expected bad eraseblocks per 1024 eraseblocks then can be calculated
as "1024 * (1 - MinNVB / MaxNVB)", which gives 20 for most NANDs
(MaxNVB is basically the total count of eraseblocks on the chip).

To put it differently, if this value is 20, UBI will try to reserve
about 1.9% of physical eraseblocks for bad blocks handling. And that
will be 1.9% of eraseblocks on the entire NAND chip, not just the MTD
partition UBI attaches. This means that if you have, say, a NAND
flash chip admits maximum 40 bad eraseblocks, and it is split on two
MTD partitions of the same size, UBI will reserve 40 eraseblocks when
attaching a partition.

This option can be overridden by the "mtd=" UBI module parameter or
by the "attach" ioctl.

Leave the default value if unsure.

config MTD_UBI_GLUEBI
tristate "MTD devices emulation driver (gluebi)"
Expand Down
46 changes: 22 additions & 24 deletions drivers/mtd/ubi/attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
* NAND), it is probably a PEB which was being erased when power cut
* happened, so this is corruption type 1. However, this is just a guess,
* which might be wrong.
* o Otherwise this it corruption type 2.
* o Otherwise this is corruption type 2.
*/

#include <linux/err.h>
Expand Down Expand Up @@ -378,8 +378,8 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb,
if (err == UBI_IO_BITFLIPS)
bitflips = 1;
else {
ubi_err("VID of PEB %d header is bad, but it "
"was OK earlier, err %d", pnum, err);
ubi_err("VID of PEB %d header is bad, but it was OK earlier, err %d",
pnum, err);
if (err > 0)
err = -EIO;

Expand Down Expand Up @@ -790,12 +790,12 @@ static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr,
if (ubi_check_pattern(ubi->peb_buf, 0xFF, ubi->leb_size))
goto out_unlock;

ubi_err("PEB %d contains corrupted VID header, and the data does not "
"contain all 0xFF, this may be a non-UBI PEB or a severe VID "
"header corruption which requires manual inspection", pnum);
ubi_err("PEB %d contains corrupted VID header, and the data does not contain all 0xFF",
pnum);
ubi_err("this may be a non-UBI PEB or a severe VID header corruption which requires manual inspection");
ubi_dump_vid_hdr(vid_hdr);
dbg_msg("hexdump of PEB %d offset %d, length %d",
pnum, ubi->leb_start, ubi->leb_size);
pr_err("hexdump of PEB %d offset %d, length %d",
pnum, ubi->leb_start, ubi->leb_size);
ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
ubi->peb_buf, ubi->leb_size, 1);
err = 1;
Expand Down Expand Up @@ -907,8 +907,8 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
ubi->image_seq = image_seq;
if (ubi->image_seq && image_seq &&
ubi->image_seq != image_seq) {
ubi_err("bad image sequence number %d in PEB %d, "
"expected %d", image_seq, pnum, ubi->image_seq);
ubi_err("bad image sequence number %d in PEB %d, expected %d",
image_seq, pnum, ubi->image_seq);
ubi_dump_ec_hdr(ech);
return -EINVAL;
}
Expand Down Expand Up @@ -975,7 +975,7 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
return err;
goto adjust_mean_ec;
case UBI_IO_FF:
if (ec_err)
if (ec_err || bitflips)
err = add_to_list(ai, pnum, UBI_UNKNOWN,
UBI_UNKNOWN, ec, 1, &ai->erase);
else
Expand All @@ -997,24 +997,23 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
/* Unsupported internal volume */
switch (vidh->compat) {
case UBI_COMPAT_DELETE:
ubi_msg("\"delete\" compatible internal volume %d:%d"
" found, will remove it", vol_id, lnum);
ubi_msg("\"delete\" compatible internal volume %d:%d found, will remove it",
vol_id, lnum);
err = add_to_list(ai, pnum, vol_id, lnum,
ec, 1, &ai->erase);
if (err)
return err;
return 0;

case UBI_COMPAT_RO:
ubi_msg("read-only compatible internal volume %d:%d"
" found, switch to read-only mode",
ubi_msg("read-only compatible internal volume %d:%d found, switch to read-only mode",
vol_id, lnum);
ubi->ro_mode = 1;
break;

case UBI_COMPAT_PRESERVE:
ubi_msg("\"preserve\" compatible internal volume %d:%d"
" found", vol_id, lnum);
ubi_msg("\"preserve\" compatible internal volume %d:%d found",
vol_id, lnum);
err = add_to_list(ai, pnum, vol_id, lnum,
ec, 0, &ai->alien);
if (err)
Expand Down Expand Up @@ -1075,10 +1074,10 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
if (ai->corr_peb_count) {
ubi_err("%d PEBs are corrupted and preserved",
ai->corr_peb_count);
printk(KERN_ERR "Corrupted PEBs are:");
pr_err("Corrupted PEBs are:");
list_for_each_entry(aeb, &ai->corr, u.list)
printk(KERN_CONT " %d", aeb->pnum);
printk(KERN_CONT "\n");
pr_cont(" %d", aeb->pnum);
pr_cont("\n");

/*
* If too many PEBs are corrupted, we refuse attaching,
Expand Down Expand Up @@ -1112,8 +1111,7 @@ static int late_analysis(struct ubi_device *ubi, struct ubi_attach_info *ai)
get_random_bytes(&ubi->image_seq,
sizeof(ubi->image_seq));
} else {
ubi_err("MTD device is not UBI-formatted and possibly "
"contains non-UBI data - refusing it");
ubi_err("MTD device is not UBI-formatted and possibly contains non-UBI data - refusing it");
return -EINVAL;
}

Expand Down Expand Up @@ -1172,7 +1170,7 @@ static struct ubi_attach_info *scan_all(struct ubi_device *ubi)
goto out_vidh;
}

dbg_msg("scanning is finished");
ubi_msg("scanning is finished");

/* Calculate mean erase counter */
if (ai->ec_count)
Expand Down Expand Up @@ -1244,7 +1242,7 @@ int ubi_attach(struct ubi_device *ubi)
ubi->corr_peb_count = ai->corr_peb_count;
ubi->max_ec = ai->max_ec;
ubi->mean_ec = ai->mean_ec;
ubi_msg("max. sequence number: %llu", ai->max_sqnum);
dbg_gen("max. sequence number: %llu", ai->max_sqnum);

err = ubi_read_volume_table(ubi, ai);
if (err)
Expand Down
Loading

0 comments on commit 65b99c7

Please sign in to comment.