diff options
author | David Woodhouse <David.Woodhouse@intel.com> | 2010-10-30 07:35:11 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2010-10-30 07:35:11 -0400 |
commit | 67577927e8d7a1f4b09b4992df640eadc6aacb36 (patch) | |
tree | 2e9efe6b5745965faf0dcc084d4613d9356263f9 /drivers/mtd | |
parent | 6fe4c590313133ebd5dadb769031489ff178ece1 (diff) | |
parent | 51f00a471ce8f359627dd99aeac322947a0e491b (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
Conflicts:
drivers/mtd/mtd_blkdevs.c
Merge Grant's device-tree bits so that we can apply the subsequent fixes.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r-- | drivers/mtd/chips/cfi_cmdset_0002.c | 4 | ||||
-rw-r--r-- | drivers/mtd/devices/lart.c | 2 | ||||
-rw-r--r-- | drivers/mtd/devices/m25p80.c | 7 | ||||
-rw-r--r-- | drivers/mtd/ftl.c | 2 | ||||
-rw-r--r-- | drivers/mtd/maps/Kconfig | 4 | ||||
-rw-r--r-- | drivers/mtd/maps/pcmciamtd.c | 102 | ||||
-rw-r--r-- | drivers/mtd/mtd_blkdevs.c | 8 | ||||
-rw-r--r-- | drivers/mtd/mtdchar.c | 15 | ||||
-rw-r--r-- | drivers/mtd/nand/cafe_nand.c | 2 | ||||
-rw-r--r-- | drivers/mtd/nand/mxc_nand.c | 92 | ||||
-rw-r--r-- | drivers/mtd/nand/omap2.c | 2 | ||||
-rw-r--r-- | drivers/mtd/ubi/Kconfig | 17 | ||||
-rw-r--r-- | drivers/mtd/ubi/Kconfig.debug | 29 | ||||
-rw-r--r-- | drivers/mtd/ubi/build.c | 6 | ||||
-rw-r--r-- | drivers/mtd/ubi/cdev.c | 1 | ||||
-rw-r--r-- | drivers/mtd/ubi/debug.h | 4 | ||||
-rw-r--r-- | drivers/mtd/ubi/eba.c | 10 | ||||
-rw-r--r-- | drivers/mtd/ubi/io.c | 138 | ||||
-rw-r--r-- | drivers/mtd/ubi/misc.c | 19 | ||||
-rw-r--r-- | drivers/mtd/ubi/scan.c | 387 | ||||
-rw-r--r-- | drivers/mtd/ubi/scan.h | 19 | ||||
-rw-r--r-- | drivers/mtd/ubi/ubi.h | 29 | ||||
-rw-r--r-- | drivers/mtd/ubi/vmt.c | 6 | ||||
-rw-r--r-- | drivers/mtd/ubi/vtbl.c | 10 | ||||
-rw-r--r-- | drivers/mtd/ubi/wl.c | 31 |
25 files changed, 568 insertions, 378 deletions
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 288fc2ea8494..3b8e32d87977 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c | |||
@@ -446,8 +446,8 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary) | |||
446 | 446 | ||
447 | /* | 447 | /* |
448 | * Valid primary extension versions are: 1.0, 1.1, 1.2, 1.3, 1.4 | 448 | * Valid primary extension versions are: 1.0, 1.1, 1.2, 1.3, 1.4 |
449 | * see: http://www.amd.com/us-en/assets/content_type/DownloadableAssets/cfi_r20.pdf, page 19 | 449 | * see: http://cs.ozerki.net/zap/pub/axim-x5/docs/cfi_r20.pdf, page 19 |
450 | * http://www.amd.com/us-en/assets/content_type/DownloadableAssets/cfi_100_20011201.pdf | 450 | * http://www.spansion.com/Support/AppNotes/cfi_100_20011201.pdf |
451 | * http://www.spansion.com/Support/Datasheets/s29ws-p_00_a12_e.pdf | 451 | * http://www.spansion.com/Support/Datasheets/s29ws-p_00_a12_e.pdf |
452 | */ | 452 | */ |
453 | if (extp->MajorVersion != '1' || | 453 | if (extp->MajorVersion != '1' || |
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c index f4359fe7150f..caf604167f03 100644 --- a/drivers/mtd/devices/lart.c +++ b/drivers/mtd/devices/lart.c | |||
@@ -17,7 +17,7 @@ | |||
17 | * - January 2000 | 17 | * - January 2000 |
18 | * | 18 | * |
19 | * [2] MTD internal API documentation | 19 | * [2] MTD internal API documentation |
20 | * - http://www.linux-mtd.infradead.org/tech/ | 20 | * - http://www.linux-mtd.infradead.org/ |
21 | * | 21 | * |
22 | * Limitations: | 22 | * Limitations: |
23 | * | 23 | * |
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 7e0edd40ad41..669d2b7e36bb 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c | |||
@@ -928,6 +928,13 @@ static int __devinit m25p_probe(struct spi_device *spi) | |||
928 | nr_parts = data->nr_parts; | 928 | nr_parts = data->nr_parts; |
929 | } | 929 | } |
930 | 930 | ||
931 | #ifdef CONFIG_OF | ||
932 | if (nr_parts <= 0 && spi->dev.of_node) { | ||
933 | nr_parts = of_mtd_parse_partitions(&spi->dev, | ||
934 | spi->dev.of_node, &parts); | ||
935 | } | ||
936 | #endif | ||
937 | |||
931 | if (nr_parts > 0) { | 938 | if (nr_parts > 0) { |
932 | for (i = 0; i < nr_parts; i++) { | 939 | for (i = 0; i < nr_parts; i++) { |
933 | DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = " | 940 | DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = " |
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index 4d6a64c387ec..037b399df3f1 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c | |||
@@ -51,7 +51,7 @@ | |||
51 | 51 | ||
52 | Use of the FTL format for non-PCMCIA applications may be an | 52 | Use of the FTL format for non-PCMCIA applications may be an |
53 | infringement of these patents. For additional information, | 53 | infringement of these patents. For additional information, |
54 | contact M-Systems (http://www.m-sys.com) directly. | 54 | contact M-Systems directly. M-Systems since acquired by Sandisk. |
55 | 55 | ||
56 | ======================================================================*/ | 56 | ======================================================================*/ |
57 | #include <linux/mtd/blktrans.h> | 57 | #include <linux/mtd/blktrans.h> |
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index e5eb65cfb3eb..a0dd7bba9481 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig | |||
@@ -172,7 +172,7 @@ config MTD_OCTAGON | |||
172 | This provides a 'mapping' driver which supports the way in which | 172 | This provides a 'mapping' driver which supports the way in which |
173 | the flash chips are connected in the Octagon-5066 Single Board | 173 | the flash chips are connected in the Octagon-5066 Single Board |
174 | Computer. More information on the board is available at | 174 | Computer. More information on the board is available at |
175 | <http://www.octagonsystems.com/CPUpages/5066.html>. | 175 | <http://www.octagonsystems.com/products/5066.aspx>. |
176 | 176 | ||
177 | config MTD_VMAX | 177 | config MTD_VMAX |
178 | tristate "JEDEC Flash device mapped on Tempustech VMAX SBC301" | 178 | tristate "JEDEC Flash device mapped on Tempustech VMAX SBC301" |
@@ -293,7 +293,7 @@ config MTD_TQM8XXL | |||
293 | chips, currently uses AMD one. This 'mapping' driver supports | 293 | chips, currently uses AMD one. This 'mapping' driver supports |
294 | that arrangement, allowing the CFI probe and command set driver | 294 | that arrangement, allowing the CFI probe and command set driver |
295 | code to communicate with the chips on the TQM8xxL board. More at | 295 | code to communicate with the chips on the TQM8xxL board. More at |
296 | <http://www.denx.de/embedded-ppc-en.html>. | 296 | <http://www.denx.de/wiki/PPCEmbedded/>. |
297 | 297 | ||
298 | config MTD_RPXLITE | 298 | config MTD_RPXLITE |
299 | tristate "CFI Flash device mapped on RPX Lite or CLLF" | 299 | tristate "CFI Flash device mapped on RPX Lite or CLLF" |
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c index 86c74685eb7b..917022948399 100644 --- a/drivers/mtd/maps/pcmciamtd.c +++ b/drivers/mtd/maps/pcmciamtd.c | |||
@@ -16,7 +16,6 @@ | |||
16 | #include <asm/io.h> | 16 | #include <asm/io.h> |
17 | #include <asm/system.h> | 17 | #include <asm/system.h> |
18 | 18 | ||
19 | #include <pcmcia/cs.h> | ||
20 | #include <pcmcia/cistpl.h> | 19 | #include <pcmcia/cistpl.h> |
21 | #include <pcmcia/ds.h> | 20 | #include <pcmcia/ds.h> |
22 | 21 | ||
@@ -101,7 +100,7 @@ MODULE_PARM_DESC(mem_type, "Set Memory type (0=Flash, 1=RAM, 2=ROM, default=0)") | |||
101 | static caddr_t remap_window(struct map_info *map, unsigned long to) | 100 | static caddr_t remap_window(struct map_info *map, unsigned long to) |
102 | { | 101 | { |
103 | struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; | 102 | struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; |
104 | window_handle_t win = (window_handle_t)map->map_priv_2; | 103 | struct resource *win = (struct resource *) map->map_priv_2; |
105 | unsigned int offset; | 104 | unsigned int offset; |
106 | int ret; | 105 | int ret; |
107 | 106 | ||
@@ -316,30 +315,19 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on) | |||
316 | { | 315 | { |
317 | struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; | 316 | struct pcmciamtd_dev *dev = (struct pcmciamtd_dev *)map->map_priv_1; |
318 | struct pcmcia_device *link = dev->p_dev; | 317 | struct pcmcia_device *link = dev->p_dev; |
319 | modconf_t mod; | ||
320 | int ret; | ||
321 | |||
322 | mod.Attributes = CONF_VPP1_CHANGE_VALID | CONF_VPP2_CHANGE_VALID; | ||
323 | mod.Vcc = 0; | ||
324 | mod.Vpp1 = mod.Vpp2 = on ? dev->vpp : 0; | ||
325 | 318 | ||
326 | DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); | 319 | DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); |
327 | ret = pcmcia_modify_configuration(link, &mod); | 320 | pcmcia_fixup_vpp(link, on ? dev->vpp : 0); |
328 | } | 321 | } |
329 | 322 | ||
330 | 323 | ||
331 | /* After a card is removed, pcmciamtd_release() will unregister the | ||
332 | * device, and release the PCMCIA configuration. If the device is | ||
333 | * still open, this will be postponed until it is closed. | ||
334 | */ | ||
335 | |||
336 | static void pcmciamtd_release(struct pcmcia_device *link) | 324 | static void pcmciamtd_release(struct pcmcia_device *link) |
337 | { | 325 | { |
338 | struct pcmciamtd_dev *dev = link->priv; | 326 | struct pcmciamtd_dev *dev = link->priv; |
339 | 327 | ||
340 | DEBUG(3, "link = 0x%p", link); | 328 | DEBUG(3, "link = 0x%p", link); |
341 | 329 | ||
342 | if (link->win) { | 330 | if (link->resource[2]->end) { |
343 | if(dev->win_base) { | 331 | if(dev->win_base) { |
344 | iounmap(dev->win_base); | 332 | iounmap(dev->win_base); |
345 | dev->win_base = NULL; | 333 | dev->win_base = NULL; |
@@ -482,18 +470,12 @@ static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *p_dev | |||
482 | } | 470 | } |
483 | 471 | ||
484 | 472 | ||
485 | /* pcmciamtd_config() is scheduled to run after a CARD_INSERTION event | ||
486 | * is received, to configure the PCMCIA socket, and to make the | ||
487 | * MTD device available to the system. | ||
488 | */ | ||
489 | |||
490 | static int pcmciamtd_config(struct pcmcia_device *link) | 473 | static int pcmciamtd_config(struct pcmcia_device *link) |
491 | { | 474 | { |
492 | struct pcmciamtd_dev *dev = link->priv; | 475 | struct pcmciamtd_dev *dev = link->priv; |
493 | struct mtd_info *mtd = NULL; | 476 | struct mtd_info *mtd = NULL; |
494 | win_req_t req; | ||
495 | int ret; | 477 | int ret; |
496 | int i; | 478 | int i, j = 0; |
497 | static char *probes[] = { "jedec_probe", "cfi_probe" }; | 479 | static char *probes[] = { "jedec_probe", "cfi_probe" }; |
498 | int new_name = 0; | 480 | int new_name = 0; |
499 | 481 | ||
@@ -520,28 +502,34 @@ static int pcmciamtd_config(struct pcmcia_device *link) | |||
520 | * smaller windows until we succeed | 502 | * smaller windows until we succeed |
521 | */ | 503 | */ |
522 | 504 | ||
523 | req.Attributes = WIN_MEMORY_TYPE_CM | WIN_ENABLE; | 505 | link->resource[2]->flags |= WIN_MEMORY_TYPE_CM | WIN_ENABLE; |
524 | req.Attributes |= (dev->pcmcia_map.bankwidth == 1) ? WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16; | 506 | link->resource[2]->flags |= (dev->pcmcia_map.bankwidth == 1) ? |
525 | req.Base = 0; | 507 | WIN_DATA_WIDTH_8 : WIN_DATA_WIDTH_16; |
526 | req.AccessSpeed = mem_speed; | 508 | link->resource[2]->start = 0; |
527 | link->win = (window_handle_t)link; | 509 | link->resource[2]->end = (force_size) ? force_size << 20 : |
528 | req.Size = (force_size) ? force_size << 20 : MAX_PCMCIA_ADDR; | 510 | MAX_PCMCIA_ADDR; |
529 | dev->win_size = 0; | 511 | dev->win_size = 0; |
530 | 512 | ||
531 | do { | 513 | do { |
532 | int ret; | 514 | int ret; |
533 | DEBUG(2, "requesting window with size = %dKiB memspeed = %d", | 515 | DEBUG(2, "requesting window with size = %luKiB memspeed = %d", |
534 | req.Size >> 10, req.AccessSpeed); | 516 | (unsigned long) resource_size(link->resource[2]) >> 10, |
535 | ret = pcmcia_request_window(link, &req, &link->win); | 517 | mem_speed); |
518 | ret = pcmcia_request_window(link, link->resource[2], mem_speed); | ||
536 | DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); | 519 | DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); |
537 | if(ret) { | 520 | if(ret) { |
538 | req.Size >>= 1; | 521 | j++; |
522 | link->resource[2]->start = 0; | ||
523 | link->resource[2]->end = (force_size) ? | ||
524 | force_size << 20 : MAX_PCMCIA_ADDR; | ||
525 | link->resource[2]->end >>= j; | ||
539 | } else { | 526 | } else { |
540 | DEBUG(2, "Got window of size %dKiB", req.Size >> 10); | 527 | DEBUG(2, "Got window of size %luKiB", (unsigned long) |
541 | dev->win_size = req.Size; | 528 | resource_size(link->resource[2]) >> 10); |
529 | dev->win_size = resource_size(link->resource[2]); | ||
542 | break; | 530 | break; |
543 | } | 531 | } |
544 | } while(req.Size >= 0x1000); | 532 | } while (link->resource[2]->end >= 0x1000); |
545 | 533 | ||
546 | DEBUG(2, "dev->win_size = %d", dev->win_size); | 534 | DEBUG(2, "dev->win_size = %d", dev->win_size); |
547 | 535 | ||
@@ -553,33 +541,31 @@ static int pcmciamtd_config(struct pcmcia_device *link) | |||
553 | DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10); | 541 | DEBUG(1, "Allocated a window of %dKiB", dev->win_size >> 10); |
554 | 542 | ||
555 | /* Get write protect status */ | 543 | /* Get write protect status */ |
556 | DEBUG(2, "window handle = 0x%8.8lx", (unsigned long)link->win); | 544 | dev->win_base = ioremap(link->resource[2]->start, |
557 | dev->win_base = ioremap(req.Base, req.Size); | 545 | resource_size(link->resource[2])); |
558 | if(!dev->win_base) { | 546 | if(!dev->win_base) { |
559 | dev_err(&dev->p_dev->dev, "ioremap(%lu, %u) failed\n", | 547 | dev_err(&dev->p_dev->dev, "ioremap(%pR) failed\n", |
560 | req.Base, req.Size); | 548 | link->resource[2]); |
561 | pcmciamtd_release(link); | 549 | pcmciamtd_release(link); |
562 | return -ENODEV; | 550 | return -ENODEV; |
563 | } | 551 | } |
564 | DEBUG(1, "mapped window dev = %p req.base = 0x%lx base = %p size = 0x%x", | 552 | DEBUG(1, "mapped window dev = %p @ %pR, base = %p", |
565 | dev, req.Base, dev->win_base, req.Size); | 553 | dev, link->resource[2], dev->win_base); |
566 | 554 | ||
567 | dev->offset = 0; | 555 | dev->offset = 0; |
568 | dev->pcmcia_map.map_priv_1 = (unsigned long)dev; | 556 | dev->pcmcia_map.map_priv_1 = (unsigned long)dev; |
569 | dev->pcmcia_map.map_priv_2 = (unsigned long)link->win; | 557 | dev->pcmcia_map.map_priv_2 = (unsigned long)link->resource[2]; |
570 | 558 | ||
571 | dev->vpp = (vpp) ? vpp : link->socket->socket.Vpp; | 559 | dev->vpp = (vpp) ? vpp : link->socket->socket.Vpp; |
572 | link->conf.Attributes = 0; | ||
573 | if(setvpp == 2) { | 560 | if(setvpp == 2) { |
574 | link->conf.Vpp = dev->vpp; | 561 | link->vpp = dev->vpp; |
575 | } else { | 562 | } else { |
576 | link->conf.Vpp = 0; | 563 | link->vpp = 0; |
577 | } | 564 | } |
578 | 565 | ||
579 | link->conf.IntType = INT_MEMORY; | 566 | link->config_index = 0; |
580 | link->conf.ConfigIndex = 0; | ||
581 | DEBUG(2, "Setting Configuration"); | 567 | DEBUG(2, "Setting Configuration"); |
582 | ret = pcmcia_request_configuration(link, &link->conf); | 568 | ret = pcmcia_enable_device(link); |
583 | if (ret != 0) { | 569 | if (ret != 0) { |
584 | if (dev->win_base) { | 570 | if (dev->win_base) { |
585 | iounmap(dev->win_base); | 571 | iounmap(dev->win_base); |
@@ -676,12 +662,6 @@ static int pcmciamtd_resume(struct pcmcia_device *dev) | |||
676 | } | 662 | } |
677 | 663 | ||
678 | 664 | ||
679 | /* This deletes a driver "instance". The device is de-registered | ||
680 | * with Card Services. If it has been released, all local data | ||
681 | * structures are freed. Otherwise, the structures will be freed | ||
682 | * when the device is released. | ||
683 | */ | ||
684 | |||
685 | static void pcmciamtd_detach(struct pcmcia_device *link) | 665 | static void pcmciamtd_detach(struct pcmcia_device *link) |
686 | { | 666 | { |
687 | struct pcmciamtd_dev *dev = link->priv; | 667 | struct pcmciamtd_dev *dev = link->priv; |
@@ -699,11 +679,6 @@ static void pcmciamtd_detach(struct pcmcia_device *link) | |||
699 | } | 679 | } |
700 | 680 | ||
701 | 681 | ||
702 | /* pcmciamtd_attach() creates an "instance" of the driver, allocating | ||
703 | * local data structures for one device. The device is registered | ||
704 | * with Card Services. | ||
705 | */ | ||
706 | |||
707 | static int pcmciamtd_probe(struct pcmcia_device *link) | 682 | static int pcmciamtd_probe(struct pcmcia_device *link) |
708 | { | 683 | { |
709 | struct pcmciamtd_dev *dev; | 684 | struct pcmciamtd_dev *dev; |
@@ -716,9 +691,6 @@ static int pcmciamtd_probe(struct pcmcia_device *link) | |||
716 | dev->p_dev = link; | 691 | dev->p_dev = link; |
717 | link->priv = dev; | 692 | link->priv = dev; |
718 | 693 | ||
719 | link->conf.Attributes = 0; | ||
720 | link->conf.IntType = INT_MEMORY; | ||
721 | |||
722 | return pcmciamtd_config(link); | 694 | return pcmciamtd_config(link); |
723 | } | 695 | } |
724 | 696 | ||
@@ -753,9 +725,7 @@ static struct pcmcia_device_id pcmciamtd_ids[] = { | |||
753 | MODULE_DEVICE_TABLE(pcmcia, pcmciamtd_ids); | 725 | MODULE_DEVICE_TABLE(pcmcia, pcmciamtd_ids); |
754 | 726 | ||
755 | static struct pcmcia_driver pcmciamtd_driver = { | 727 | static struct pcmcia_driver pcmciamtd_driver = { |
756 | .drv = { | 728 | .name = "pcmciamtd", |
757 | .name = "pcmciamtd" | ||
758 | }, | ||
759 | .probe = pcmciamtd_probe, | 729 | .probe = pcmciamtd_probe, |
760 | .remove = pcmciamtd_detach, | 730 | .remove = pcmciamtd_detach, |
761 | .owner = THIS_MODULE, | 731 | .owner = THIS_MODULE, |
@@ -767,8 +737,6 @@ static struct pcmcia_driver pcmciamtd_driver = { | |||
767 | 737 | ||
768 | static int __init init_pcmciamtd(void) | 738 | static int __init init_pcmciamtd(void) |
769 | { | 739 | { |
770 | info(DRIVER_DESC); | ||
771 | |||
772 | if(bankwidth && bankwidth != 1 && bankwidth != 2) { | 740 | if(bankwidth && bankwidth != 1 && bankwidth != 2) { |
773 | info("bad bankwidth (%d), using default", bankwidth); | 741 | info("bad bankwidth (%d), using default", bankwidth); |
774 | bankwidth = 2; | 742 | bankwidth = 2; |
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 63790e975d20..f9329794f3b5 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c | |||
@@ -29,7 +29,6 @@ | |||
29 | #include <linux/blkdev.h> | 29 | #include <linux/blkdev.h> |
30 | #include <linux/blkpg.h> | 30 | #include <linux/blkpg.h> |
31 | #include <linux/spinlock.h> | 31 | #include <linux/spinlock.h> |
32 | #include <linux/smp_lock.h> | ||
33 | #include <linux/hdreg.h> | 32 | #include <linux/hdreg.h> |
34 | #include <linux/init.h> | 33 | #include <linux/init.h> |
35 | #include <linux/mutex.h> | 34 | #include <linux/mutex.h> |
@@ -38,6 +37,7 @@ | |||
38 | 37 | ||
39 | #include "mtdcore.h" | 38 | #include "mtdcore.h" |
40 | 39 | ||
40 | static DEFINE_MUTEX(mtd_blkdevs_mutex); | ||
41 | static LIST_HEAD(blktrans_majors); | 41 | static LIST_HEAD(blktrans_majors); |
42 | static DEFINE_MUTEX(blktrans_ref_mutex); | 42 | static DEFINE_MUTEX(blktrans_ref_mutex); |
43 | 43 | ||
@@ -185,6 +185,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) | |||
185 | if (!dev) | 185 | if (!dev) |
186 | return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ | 186 | return -ERESTARTSYS; /* FIXME: busy loop! -arnd*/ |
187 | 187 | ||
188 | mutex_lock(&mtd_blkdevs_mutex); | ||
188 | mutex_lock(&dev->lock); | 189 | mutex_lock(&dev->lock); |
189 | 190 | ||
190 | if (dev->open++) | 191 | if (dev->open++) |
@@ -201,6 +202,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) | |||
201 | unlock: | 202 | unlock: |
202 | mutex_unlock(&dev->lock); | 203 | mutex_unlock(&dev->lock); |
203 | blktrans_dev_put(dev); | 204 | blktrans_dev_put(dev); |
205 | mutex_unlock(&mtd_blkdevs_mutex); | ||
204 | return ret; | 206 | return ret; |
205 | } | 207 | } |
206 | 208 | ||
@@ -212,6 +214,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode) | |||
212 | if (!dev) | 214 | if (!dev) |
213 | return ret; | 215 | return ret; |
214 | 216 | ||
217 | mutex_lock(&mtd_blkdevs_mutex); | ||
215 | mutex_lock(&dev->lock); | 218 | mutex_lock(&dev->lock); |
216 | 219 | ||
217 | if (--dev->open) | 220 | if (--dev->open) |
@@ -227,6 +230,7 @@ static int blktrans_release(struct gendisk *disk, fmode_t mode) | |||
227 | unlock: | 230 | unlock: |
228 | mutex_unlock(&dev->lock); | 231 | mutex_unlock(&dev->lock); |
229 | blktrans_dev_put(dev); | 232 | blktrans_dev_put(dev); |
233 | mutex_unlock(&mtd_blkdevs_mutex); | ||
230 | return ret; | 234 | return ret; |
231 | } | 235 | } |
232 | 236 | ||
@@ -259,6 +263,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode, | |||
259 | if (!dev) | 263 | if (!dev) |
260 | return ret; | 264 | return ret; |
261 | 265 | ||
266 | mutex_lock(&mtd_blkdevs_mutex); | ||
262 | mutex_lock(&dev->lock); | 267 | mutex_lock(&dev->lock); |
263 | 268 | ||
264 | if (!dev->mtd) | 269 | if (!dev->mtd) |
@@ -273,6 +278,7 @@ static int blktrans_ioctl(struct block_device *bdev, fmode_t mode, | |||
273 | } | 278 | } |
274 | unlock: | 279 | unlock: |
275 | mutex_unlock(&dev->lock); | 280 | mutex_unlock(&dev->lock); |
281 | mutex_unlock(&mtd_blkdevs_mutex); | ||
276 | blktrans_dev_put(dev); | 282 | blktrans_dev_put(dev); |
277 | return ret; | 283 | return ret; |
278 | } | 284 | } |
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index b7ed09c57903..3eff1e562ad3 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c | |||
@@ -26,7 +26,7 @@ | |||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
29 | #include <linux/smp_lock.h> | 29 | #include <linux/mutex.h> |
30 | #include <linux/backing-dev.h> | 30 | #include <linux/backing-dev.h> |
31 | #include <linux/compat.h> | 31 | #include <linux/compat.h> |
32 | #include <linux/mount.h> | 32 | #include <linux/mount.h> |
@@ -38,6 +38,7 @@ | |||
38 | #include <asm/uaccess.h> | 38 | #include <asm/uaccess.h> |
39 | 39 | ||
40 | #define MTD_INODE_FS_MAGIC 0x11307854 | 40 | #define MTD_INODE_FS_MAGIC 0x11307854 |
41 | static DEFINE_MUTEX(mtd_mutex); | ||
41 | static struct vfsmount *mtd_inode_mnt __read_mostly; | 42 | static struct vfsmount *mtd_inode_mnt __read_mostly; |
42 | 43 | ||
43 | /* | 44 | /* |
@@ -91,7 +92,7 @@ static int mtd_open(struct inode *inode, struct file *file) | |||
91 | if ((file->f_mode & FMODE_WRITE) && (minor & 1)) | 92 | if ((file->f_mode & FMODE_WRITE) && (minor & 1)) |
92 | return -EACCES; | 93 | return -EACCES; |
93 | 94 | ||
94 | lock_kernel(); | 95 | mutex_lock(&mtd_mutex); |
95 | mtd = get_mtd_device(NULL, devnum); | 96 | mtd = get_mtd_device(NULL, devnum); |
96 | 97 | ||
97 | if (IS_ERR(mtd)) { | 98 | if (IS_ERR(mtd)) { |
@@ -139,7 +140,7 @@ static int mtd_open(struct inode *inode, struct file *file) | |||
139 | file->private_data = mfi; | 140 | file->private_data = mfi; |
140 | 141 | ||
141 | out: | 142 | out: |
142 | unlock_kernel(); | 143 | mutex_unlock(&mtd_mutex); |
143 | return ret; | 144 | return ret; |
144 | } /* mtd_open */ | 145 | } /* mtd_open */ |
145 | 146 | ||
@@ -967,9 +968,9 @@ static long mtd_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) | |||
967 | { | 968 | { |
968 | int ret; | 969 | int ret; |
969 | 970 | ||
970 | lock_kernel(); | 971 | mutex_lock(&mtd_mutex); |
971 | ret = mtd_ioctl(file, cmd, arg); | 972 | ret = mtd_ioctl(file, cmd, arg); |
972 | unlock_kernel(); | 973 | mutex_unlock(&mtd_mutex); |
973 | 974 | ||
974 | return ret; | 975 | return ret; |
975 | } | 976 | } |
@@ -993,7 +994,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd, | |||
993 | void __user *argp = compat_ptr(arg); | 994 | void __user *argp = compat_ptr(arg); |
994 | int ret = 0; | 995 | int ret = 0; |
995 | 996 | ||
996 | lock_kernel(); | 997 | mutex_lock(&mtd_mutex); |
997 | 998 | ||
998 | switch (cmd) { | 999 | switch (cmd) { |
999 | case MEMWRITEOOB32: | 1000 | case MEMWRITEOOB32: |
@@ -1028,7 +1029,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd, | |||
1028 | ret = mtd_ioctl(file, cmd, (unsigned long)argp); | 1029 | ret = mtd_ioctl(file, cmd, (unsigned long)argp); |
1029 | } | 1030 | } |
1030 | 1031 | ||
1031 | unlock_kernel(); | 1032 | mutex_unlock(&mtd_mutex); |
1032 | 1033 | ||
1033 | return ret; | 1034 | return ret; |
1034 | } | 1035 | } |
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c index db1dfc5a1b11..e06c8983978e 100644 --- a/drivers/mtd/nand/cafe_nand.c +++ b/drivers/mtd/nand/cafe_nand.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * Driver for One Laptop Per Child ‘CAFÉ’ controller, aka Marvell 88ALP01 | 2 | * Driver for One Laptop Per Child ‘CAFÉ’ controller, aka Marvell 88ALP01 |
3 | * | 3 | * |
4 | * The data sheet for this device can be found at: | 4 | * The data sheet for this device can be found at: |
5 | * http://www.marvell.com/products/pcconn/88ALP01.jsp | 5 | * http://wiki.laptop.org/go/Datasheets |
6 | * | 6 | * |
7 | * Copyright © 2006 Red Hat, Inc. | 7 | * Copyright © 2006 Red Hat, Inc. |
8 | * Copyright © 2006 David Woodhouse <dwmw2@infradead.org> | 8 | * Copyright © 2006 David Woodhouse <dwmw2@infradead.org> |
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index b2828e84d243..214b03afdd48 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #include <linux/clk.h> | 30 | #include <linux/clk.h> |
31 | #include <linux/err.h> | 31 | #include <linux/err.h> |
32 | #include <linux/io.h> | 32 | #include <linux/io.h> |
33 | #include <linux/irq.h> | ||
34 | #include <linux/completion.h> | ||
33 | 35 | ||
34 | #include <asm/mach/flash.h> | 36 | #include <asm/mach/flash.h> |
35 | #include <mach/mxc_nand.h> | 37 | #include <mach/mxc_nand.h> |
@@ -151,7 +153,7 @@ struct mxc_nand_host { | |||
151 | int irq; | 153 | int irq; |
152 | int eccsize; | 154 | int eccsize; |
153 | 155 | ||
154 | wait_queue_head_t irq_waitq; | 156 | struct completion op_completion; |
155 | 157 | ||
156 | uint8_t *data_buf; | 158 | uint8_t *data_buf; |
157 | unsigned int buf_start; | 159 | unsigned int buf_start; |
@@ -164,6 +166,7 @@ struct mxc_nand_host { | |||
164 | void (*send_read_id)(struct mxc_nand_host *); | 166 | void (*send_read_id)(struct mxc_nand_host *); |
165 | uint16_t (*get_dev_status)(struct mxc_nand_host *); | 167 | uint16_t (*get_dev_status)(struct mxc_nand_host *); |
166 | int (*check_int)(struct mxc_nand_host *); | 168 | int (*check_int)(struct mxc_nand_host *); |
169 | void (*irq_control)(struct mxc_nand_host *, int); | ||
167 | }; | 170 | }; |
168 | 171 | ||
169 | /* OOB placement block for use with hardware ecc generation */ | 172 | /* OOB placement block for use with hardware ecc generation */ |
@@ -216,9 +219,12 @@ static irqreturn_t mxc_nfc_irq(int irq, void *dev_id) | |||
216 | { | 219 | { |
217 | struct mxc_nand_host *host = dev_id; | 220 | struct mxc_nand_host *host = dev_id; |
218 | 221 | ||
219 | disable_irq_nosync(irq); | 222 | if (!host->check_int(host)) |
223 | return IRQ_NONE; | ||
220 | 224 | ||
221 | wake_up(&host->irq_waitq); | 225 | host->irq_control(host, 0); |
226 | |||
227 | complete(&host->op_completion); | ||
222 | 228 | ||
223 | return IRQ_HANDLED; | 229 | return IRQ_HANDLED; |
224 | } | 230 | } |
@@ -245,11 +251,54 @@ static int check_int_v1_v2(struct mxc_nand_host *host) | |||
245 | if (!(tmp & NFC_V1_V2_CONFIG2_INT)) | 251 | if (!(tmp & NFC_V1_V2_CONFIG2_INT)) |
246 | return 0; | 252 | return 0; |
247 | 253 | ||
248 | writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2); | 254 | if (!cpu_is_mx21()) |
255 | writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2); | ||
249 | 256 | ||
250 | return 1; | 257 | return 1; |
251 | } | 258 | } |
252 | 259 | ||
260 | /* | ||
261 | * It has been observed that the i.MX21 cannot read the CONFIG2:INT bit | ||
262 | * if interrupts are masked (CONFIG1:INT_MSK is set). To handle this, the | ||
263 | * driver can enable/disable the irq line rather than simply masking the | ||
264 | * interrupts. | ||
265 | */ | ||
266 | static void irq_control_mx21(struct mxc_nand_host *host, int activate) | ||
267 | { | ||
268 | if (activate) | ||
269 | enable_irq(host->irq); | ||
270 | else | ||
271 | disable_irq_nosync(host->irq); | ||
272 | } | ||
273 | |||
274 | static void irq_control_v1_v2(struct mxc_nand_host *host, int activate) | ||
275 | { | ||
276 | uint16_t tmp; | ||
277 | |||
278 | tmp = readw(NFC_V1_V2_CONFIG1); | ||
279 | |||
280 | if (activate) | ||
281 | tmp &= ~NFC_V1_V2_CONFIG1_INT_MSK; | ||
282 | else | ||
283 | tmp |= NFC_V1_V2_CONFIG1_INT_MSK; | ||
284 | |||
285 | writew(tmp, NFC_V1_V2_CONFIG1); | ||
286 | } | ||
287 | |||
288 | static void irq_control_v3(struct mxc_nand_host *host, int activate) | ||
289 | { | ||
290 | uint32_t tmp; | ||
291 | |||
292 | tmp = readl(NFC_V3_CONFIG2); | ||
293 | |||
294 | if (activate) | ||
295 | tmp &= ~NFC_V3_CONFIG2_INT_MSK; | ||
296 | else | ||
297 | tmp |= NFC_V3_CONFIG2_INT_MSK; | ||
298 | |||
299 | writel(tmp, NFC_V3_CONFIG2); | ||
300 | } | ||
301 | |||
253 | /* This function polls the NANDFC to wait for the basic operation to | 302 | /* This function polls the NANDFC to wait for the basic operation to |
254 | * complete by checking the INT bit of config2 register. | 303 | * complete by checking the INT bit of config2 register. |
255 | */ | 304 | */ |
@@ -259,10 +308,9 @@ static void wait_op_done(struct mxc_nand_host *host, int useirq) | |||
259 | 308 | ||
260 | if (useirq) { | 309 | if (useirq) { |
261 | if (!host->check_int(host)) { | 310 | if (!host->check_int(host)) { |
262 | 311 | INIT_COMPLETION(host->op_completion); | |
263 | enable_irq(host->irq); | 312 | host->irq_control(host, 1); |
264 | 313 | wait_for_completion(&host->op_completion); | |
265 | wait_event(host->irq_waitq, host->check_int(host)); | ||
266 | } | 314 | } |
267 | } else { | 315 | } else { |
268 | while (max_retries-- > 0) { | 316 | while (max_retries-- > 0) { |
@@ -799,6 +847,7 @@ static void preset_v3(struct mtd_info *mtd) | |||
799 | NFC_V3_CONFIG2_2CMD_PHASES | | 847 | NFC_V3_CONFIG2_2CMD_PHASES | |
800 | NFC_V3_CONFIG2_SPAS(mtd->oobsize >> 1) | | 848 | NFC_V3_CONFIG2_SPAS(mtd->oobsize >> 1) | |
801 | NFC_V3_CONFIG2_ST_CMD(0x70) | | 849 | NFC_V3_CONFIG2_ST_CMD(0x70) | |
850 | NFC_V3_CONFIG2_INT_MSK | | ||
802 | NFC_V3_CONFIG2_NUM_ADDR_PHASE0; | 851 | NFC_V3_CONFIG2_NUM_ADDR_PHASE0; |
803 | 852 | ||
804 | if (chip->ecc.mode == NAND_ECC_HW) | 853 | if (chip->ecc.mode == NAND_ECC_HW) |
@@ -1024,6 +1073,10 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
1024 | host->send_read_id = send_read_id_v1_v2; | 1073 | host->send_read_id = send_read_id_v1_v2; |
1025 | host->get_dev_status = get_dev_status_v1_v2; | 1074 | host->get_dev_status = get_dev_status_v1_v2; |
1026 | host->check_int = check_int_v1_v2; | 1075 | host->check_int = check_int_v1_v2; |
1076 | if (cpu_is_mx21()) | ||
1077 | host->irq_control = irq_control_mx21; | ||
1078 | else | ||
1079 | host->irq_control = irq_control_v1_v2; | ||
1027 | } | 1080 | } |
1028 | 1081 | ||
1029 | if (nfc_is_v21()) { | 1082 | if (nfc_is_v21()) { |
@@ -1062,6 +1115,7 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
1062 | host->send_read_id = send_read_id_v3; | 1115 | host->send_read_id = send_read_id_v3; |
1063 | host->check_int = check_int_v3; | 1116 | host->check_int = check_int_v3; |
1064 | host->get_dev_status = get_dev_status_v3; | 1117 | host->get_dev_status = get_dev_status_v3; |
1118 | host->irq_control = irq_control_v3; | ||
1065 | oob_smallpage = &nandv2_hw_eccoob_smallpage; | 1119 | oob_smallpage = &nandv2_hw_eccoob_smallpage; |
1066 | oob_largepage = &nandv2_hw_eccoob_largepage; | 1120 | oob_largepage = &nandv2_hw_eccoob_largepage; |
1067 | } else | 1121 | } else |
@@ -1093,14 +1147,34 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
1093 | this->options |= NAND_USE_FLASH_BBT; | 1147 | this->options |= NAND_USE_FLASH_BBT; |
1094 | } | 1148 | } |
1095 | 1149 | ||
1096 | init_waitqueue_head(&host->irq_waitq); | 1150 | init_completion(&host->op_completion); |
1097 | 1151 | ||
1098 | host->irq = platform_get_irq(pdev, 0); | 1152 | host->irq = platform_get_irq(pdev, 0); |
1099 | 1153 | ||
1154 | /* | ||
1155 | * mask the interrupt. For i.MX21 explicitely call | ||
1156 | * irq_control_v1_v2 to use the mask bit. We can't call | ||
1157 | * disable_irq_nosync() for an interrupt we do not own yet. | ||
1158 | */ | ||
1159 | if (cpu_is_mx21()) | ||
1160 | irq_control_v1_v2(host, 0); | ||
1161 | else | ||
1162 | host->irq_control(host, 0); | ||
1163 | |||
1100 | err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host); | 1164 | err = request_irq(host->irq, mxc_nfc_irq, IRQF_DISABLED, DRIVER_NAME, host); |
1101 | if (err) | 1165 | if (err) |
1102 | goto eirq; | 1166 | goto eirq; |
1103 | 1167 | ||
1168 | host->irq_control(host, 0); | ||
1169 | |||
1170 | /* | ||
1171 | * Now that the interrupt is disabled make sure the interrupt | ||
1172 | * mask bit is cleared on i.MX21. Otherwise we can't read | ||
1173 | * the interrupt status bit on this machine. | ||
1174 | */ | ||
1175 | if (cpu_is_mx21()) | ||
1176 | irq_control_v1_v2(host, 1); | ||
1177 | |||
1104 | /* first scan to find the device and get the page size */ | 1178 | /* first scan to find the device and get the page size */ |
1105 | if (nand_scan_ident(mtd, 1, NULL)) { | 1179 | if (nand_scan_ident(mtd, 1, NULL)) { |
1106 | err = -ENXIO; | 1180 | err = -ENXIO; |
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c index 439e80d78edd..cd41c58b5bbd 100644 --- a/drivers/mtd/nand/omap2.c +++ b/drivers/mtd/nand/omap2.c | |||
@@ -413,7 +413,7 @@ static inline int omap_nand_dma_transfer(struct mtd_info *mtd, void *addr, | |||
413 | prefetch_status = gpmc_read_status(GPMC_PREFETCH_COUNT); | 413 | prefetch_status = gpmc_read_status(GPMC_PREFETCH_COUNT); |
414 | } while (prefetch_status); | 414 | } while (prefetch_status); |
415 | /* disable and stop the PFPW engine */ | 415 | /* disable and stop the PFPW engine */ |
416 | gpmc_prefetch_reset(); | 416 | gpmc_prefetch_reset(info->gpmc_cs); |
417 | 417 | ||
418 | dma_unmap_single(&info->pdev->dev, dma_addr, len, dir); | 418 | dma_unmap_single(&info->pdev->dev, dma_addr, len, dir); |
419 | return 0; | 419 | return 0; |
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index f702a163d8df..3cf193fb5e00 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig | |||
@@ -1,9 +1,5 @@ | |||
1 | menu "UBI - Unsorted block images" | 1 | menuconfig MTD_UBI |
2 | depends on MTD | 2 | tristate "Enable UBI - Unsorted block images" |
3 | |||
4 | config MTD_UBI | ||
5 | tristate "Enable UBI" | ||
6 | depends on MTD | ||
7 | select CRC32 | 3 | select CRC32 |
8 | help | 4 | help |
9 | UBI is a software layer above MTD layer which admits of LVM-like | 5 | UBI is a software layer above MTD layer which admits of LVM-like |
@@ -12,11 +8,12 @@ config MTD_UBI | |||
12 | capabilities. Please, consult the MTD web site for more details | 8 | capabilities. Please, consult the MTD web site for more details |
13 | (www.linux-mtd.infradead.org). | 9 | (www.linux-mtd.infradead.org). |
14 | 10 | ||
11 | if MTD_UBI | ||
12 | |||
15 | config MTD_UBI_WL_THRESHOLD | 13 | config MTD_UBI_WL_THRESHOLD |
16 | int "UBI wear-leveling threshold" | 14 | int "UBI wear-leveling threshold" |
17 | default 4096 | 15 | default 4096 |
18 | range 2 65536 | 16 | range 2 65536 |
19 | depends on MTD_UBI | ||
20 | help | 17 | help |
21 | This parameter defines the maximum difference between the highest | 18 | This parameter defines the maximum difference between the highest |
22 | erase counter value and the lowest erase counter value of eraseblocks | 19 | erase counter value and the lowest erase counter value of eraseblocks |
@@ -34,7 +31,6 @@ config MTD_UBI_BEB_RESERVE | |||
34 | int "Percentage of reserved eraseblocks for bad eraseblocks handling" | 31 | int "Percentage of reserved eraseblocks for bad eraseblocks handling" |
35 | default 1 | 32 | default 1 |
36 | range 0 25 | 33 | range 0 25 |
37 | depends on MTD_UBI | ||
38 | help | 34 | help |
39 | If the MTD device admits of bad eraseblocks (e.g. NAND flash), UBI | 35 | If the MTD device admits of bad eraseblocks (e.g. NAND flash), UBI |
40 | reserves some amount of physical eraseblocks to handle new bad | 36 | reserves some amount of physical eraseblocks to handle new bad |
@@ -48,8 +44,6 @@ config MTD_UBI_BEB_RESERVE | |||
48 | 44 | ||
49 | config MTD_UBI_GLUEBI | 45 | config MTD_UBI_GLUEBI |
50 | tristate "MTD devices emulation driver (gluebi)" | 46 | tristate "MTD devices emulation driver (gluebi)" |
51 | default n | ||
52 | depends on MTD_UBI | ||
53 | help | 47 | help |
54 | This option enables gluebi - an additional driver which emulates MTD | 48 | This option enables gluebi - an additional driver which emulates MTD |
55 | devices on top of UBI volumes: for each UBI volumes an MTD device is | 49 | devices on top of UBI volumes: for each UBI volumes an MTD device is |
@@ -59,4 +53,5 @@ config MTD_UBI_GLUEBI | |||
59 | software. | 53 | software. |
60 | 54 | ||
61 | source "drivers/mtd/ubi/Kconfig.debug" | 55 | source "drivers/mtd/ubi/Kconfig.debug" |
62 | endmenu | 56 | |
57 | endif # MTD_UBI | ||
diff --git a/drivers/mtd/ubi/Kconfig.debug b/drivers/mtd/ubi/Kconfig.debug index 61f6e5e40458..fad4adc0fe2c 100644 --- a/drivers/mtd/ubi/Kconfig.debug +++ b/drivers/mtd/ubi/Kconfig.debug | |||
@@ -1,94 +1,73 @@ | |||
1 | comment "UBI debugging options" | 1 | comment "UBI debugging options" |
2 | depends on MTD_UBI | ||
3 | 2 | ||
4 | config MTD_UBI_DEBUG | 3 | config MTD_UBI_DEBUG |
5 | bool "UBI debugging" | 4 | bool "UBI debugging" |
6 | depends on SYSFS | 5 | depends on SYSFS |
7 | depends on MTD_UBI | ||
8 | select DEBUG_FS | 6 | select DEBUG_FS |
9 | select KALLSYMS_ALL if KALLSYMS && DEBUG_KERNEL | 7 | select KALLSYMS_ALL if KALLSYMS && DEBUG_KERNEL |
10 | help | 8 | help |
11 | This option enables UBI debugging. | 9 | This option enables UBI debugging. |
12 | 10 | ||
11 | if MTD_UBI_DEBUG | ||
12 | |||
13 | config MTD_UBI_DEBUG_MSG | 13 | config MTD_UBI_DEBUG_MSG |
14 | bool "UBI debugging messages" | 14 | bool "UBI debugging messages" |
15 | depends on MTD_UBI_DEBUG | ||
16 | default n | ||
17 | help | 15 | help |
18 | This option enables UBI debugging messages. | 16 | This option enables UBI debugging messages. |
19 | 17 | ||
20 | config MTD_UBI_DEBUG_PARANOID | 18 | config MTD_UBI_DEBUG_PARANOID |
21 | bool "Extra self-checks" | 19 | bool "Extra self-checks" |
22 | default n | ||
23 | depends on MTD_UBI_DEBUG | ||
24 | help | 20 | help |
25 | This option enables extra checks in UBI code. Note this slows UBI down | 21 | This option enables extra checks in UBI code. Note this slows UBI down |
26 | significantly. | 22 | significantly. |
27 | 23 | ||
28 | config MTD_UBI_DEBUG_DISABLE_BGT | 24 | config MTD_UBI_DEBUG_DISABLE_BGT |
29 | bool "Do not enable the UBI background thread" | 25 | bool "Do not enable the UBI background thread" |
30 | depends on MTD_UBI_DEBUG | ||
31 | default n | ||
32 | help | 26 | help |
33 | This option switches the background thread off by default. The thread | 27 | This option switches the background thread off by default. The thread |
34 | may be also be enabled/disabled via UBI sysfs. | 28 | may be also be enabled/disabled via UBI sysfs. |
35 | 29 | ||
36 | config MTD_UBI_DEBUG_EMULATE_BITFLIPS | 30 | config MTD_UBI_DEBUG_EMULATE_BITFLIPS |
37 | bool "Emulate flash bit-flips" | 31 | bool "Emulate flash bit-flips" |
38 | depends on MTD_UBI_DEBUG | ||
39 | default n | ||
40 | help | 32 | help |
41 | This option emulates bit-flips with probability 1/50, which in turn | 33 | This option emulates bit-flips with probability 1/50, which in turn |
42 | causes scrubbing. Useful for debugging and stressing UBI. | 34 | causes scrubbing. Useful for debugging and stressing UBI. |
43 | 35 | ||
44 | config MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES | 36 | config MTD_UBI_DEBUG_EMULATE_WRITE_FAILURES |
45 | bool "Emulate flash write failures" | 37 | bool "Emulate flash write failures" |
46 | depends on MTD_UBI_DEBUG | ||
47 | default n | ||
48 | help | 38 | help |
49 | This option emulates write failures with probability 1/100. Useful for | 39 | This option emulates write failures with probability 1/100. Useful for |
50 | debugging and testing how UBI handlines errors. | 40 | debugging and testing how UBI handlines errors. |
51 | 41 | ||
52 | config MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES | 42 | config MTD_UBI_DEBUG_EMULATE_ERASE_FAILURES |
53 | bool "Emulate flash erase failures" | 43 | bool "Emulate flash erase failures" |
54 | depends on MTD_UBI_DEBUG | ||
55 | default n | ||
56 | help | 44 | help |
57 | This option emulates erase failures with probability 1/100. Useful for | 45 | This option emulates erase failures with probability 1/100. Useful for |
58 | debugging and testing how UBI handlines errors. | 46 | debugging and testing how UBI handlines errors. |
59 | 47 | ||
60 | menu "Additional UBI debugging messages" | 48 | comment "Additional UBI debugging messages" |
61 | depends on MTD_UBI_DEBUG | ||
62 | 49 | ||
63 | config MTD_UBI_DEBUG_MSG_BLD | 50 | config MTD_UBI_DEBUG_MSG_BLD |
64 | bool "Additional UBI initialization and build messages" | 51 | bool "Additional UBI initialization and build messages" |
65 | default n | ||
66 | depends on MTD_UBI_DEBUG | ||
67 | help | 52 | help |
68 | This option enables detailed UBI initialization and device build | 53 | This option enables detailed UBI initialization and device build |
69 | debugging messages. | 54 | debugging messages. |
70 | 55 | ||
71 | config MTD_UBI_DEBUG_MSG_EBA | 56 | config MTD_UBI_DEBUG_MSG_EBA |
72 | bool "Eraseblock association unit messages" | 57 | bool "Eraseblock association unit messages" |
73 | default n | ||
74 | depends on MTD_UBI_DEBUG | ||
75 | help | 58 | help |
76 | This option enables debugging messages from the UBI eraseblock | 59 | This option enables debugging messages from the UBI eraseblock |
77 | association unit. | 60 | association unit. |
78 | 61 | ||
79 | config MTD_UBI_DEBUG_MSG_WL | 62 | config MTD_UBI_DEBUG_MSG_WL |
80 | bool "Wear-leveling unit messages" | 63 | bool "Wear-leveling unit messages" |
81 | default n | ||
82 | depends on MTD_UBI_DEBUG | ||
83 | help | 64 | help |
84 | This option enables debugging messages from the UBI wear-leveling | 65 | This option enables debugging messages from the UBI wear-leveling |
85 | unit. | 66 | unit. |
86 | 67 | ||
87 | config MTD_UBI_DEBUG_MSG_IO | 68 | config MTD_UBI_DEBUG_MSG_IO |
88 | bool "Input/output unit messages" | 69 | bool "Input/output unit messages" |
89 | default n | ||
90 | depends on MTD_UBI_DEBUG | ||
91 | help | 70 | help |
92 | This option enables debugging messages from the UBI input/output unit. | 71 | This option enables debugging messages from the UBI input/output unit. |
93 | 72 | ||
94 | endmenu # UBI debugging messages | 73 | endif # MTD_UBI_DEBUG |
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 78ae89488a4f..5ebe280225d6 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -95,8 +95,8 @@ DEFINE_MUTEX(ubi_devices_mutex); | |||
95 | static DEFINE_SPINLOCK(ubi_devices_lock); | 95 | static DEFINE_SPINLOCK(ubi_devices_lock); |
96 | 96 | ||
97 | /* "Show" method for files in '/<sysfs>/class/ubi/' */ | 97 | /* "Show" method for files in '/<sysfs>/class/ubi/' */ |
98 | static ssize_t ubi_version_show(struct class *class, struct class_attribute *attr, | 98 | static ssize_t ubi_version_show(struct class *class, |
99 | char *buf) | 99 | struct class_attribute *attr, char *buf) |
100 | { | 100 | { |
101 | return sprintf(buf, "%d\n", UBI_VERSION); | 101 | return sprintf(buf, "%d\n", UBI_VERSION); |
102 | } | 102 | } |
@@ -591,6 +591,7 @@ static int attach_by_scanning(struct ubi_device *ubi) | |||
591 | 591 | ||
592 | ubi->bad_peb_count = si->bad_peb_count; | 592 | ubi->bad_peb_count = si->bad_peb_count; |
593 | ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count; | 593 | ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count; |
594 | ubi->corr_peb_count = si->corr_peb_count; | ||
594 | ubi->max_ec = si->max_ec; | 595 | ubi->max_ec = si->max_ec; |
595 | ubi->mean_ec = si->mean_ec; | 596 | ubi->mean_ec = si->mean_ec; |
596 | ubi_msg("max. sequence number: %llu", si->max_sqnum); | 597 | ubi_msg("max. sequence number: %llu", si->max_sqnum); |
@@ -972,6 +973,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
972 | ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); | 973 | ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); |
973 | ubi_msg("number of good PEBs: %d", ubi->good_peb_count); | 974 | ubi_msg("number of good PEBs: %d", ubi->good_peb_count); |
974 | ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count); | 975 | ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count); |
976 | ubi_msg("number of corrupted PEBs: %d", ubi->corr_peb_count); | ||
975 | ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots); | 977 | ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots); |
976 | ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD); | 978 | ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD); |
977 | ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT); | 979 | ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT); |
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index 3d2d1a69e9a0..af9fb0ff8210 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c | |||
@@ -1100,4 +1100,5 @@ const struct file_operations ubi_ctrl_cdev_operations = { | |||
1100 | .owner = THIS_MODULE, | 1100 | .owner = THIS_MODULE, |
1101 | .unlocked_ioctl = ctrl_cdev_ioctl, | 1101 | .unlocked_ioctl = ctrl_cdev_ioctl, |
1102 | .compat_ioctl = ctrl_cdev_compat_ioctl, | 1102 | .compat_ioctl = ctrl_cdev_compat_ioctl, |
1103 | .llseek = noop_llseek, | ||
1103 | }; | 1104 | }; |
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h index 17a107129726..9eca95074bc2 100644 --- a/drivers/mtd/ubi/debug.h +++ b/drivers/mtd/ubi/debug.h | |||
@@ -57,6 +57,9 @@ void ubi_dbg_dump_seb(const struct ubi_scan_leb *seb, int type); | |||
57 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); | 57 | void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req); |
58 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); | 58 | void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); |
59 | 59 | ||
60 | #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) \ | ||
61 | print_hex_dump(l, ps, pt, r, g, b, len, a) | ||
62 | |||
60 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG | 63 | #ifdef CONFIG_MTD_UBI_DEBUG_MSG |
61 | /* General debugging messages */ | 64 | /* General debugging messages */ |
62 | #define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) | 65 | #define dbg_gen(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) |
@@ -172,6 +175,7 @@ static inline int ubi_dbg_is_erase_failure(void) | |||
172 | #define ubi_dbg_dump_seb(seb, type) ({}) | 175 | #define ubi_dbg_dump_seb(seb, type) ({}) |
173 | #define ubi_dbg_dump_mkvol_req(req) ({}) | 176 | #define ubi_dbg_dump_mkvol_req(req) ({}) |
174 | #define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({}) | 177 | #define ubi_dbg_dump_flash(ubi, pnum, offset, len) ({}) |
178 | #define ubi_dbg_print_hex_dump(l, ps, pt, r, g, b, len, a) ({}) | ||
175 | 179 | ||
176 | #define UBI_IO_DEBUG 0 | 180 | #define UBI_IO_DEBUG 0 |
177 | #define DBG_DISABLE_BGT 0 | 181 | #define DBG_DISABLE_BGT 0 |
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c index fe74749e0dae..4be671815014 100644 --- a/drivers/mtd/ubi/eba.c +++ b/drivers/mtd/ubi/eba.c | |||
@@ -418,7 +418,7 @@ retry: | |||
418 | * may try to recover data. FIXME: but this is | 418 | * may try to recover data. FIXME: but this is |
419 | * not implemented. | 419 | * not implemented. |
420 | */ | 420 | */ |
421 | if (err == UBI_IO_BAD_HDR_READ || | 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 " |
424 | "%d, LEB %d:%d", pnum, vol_id, | 424 | "%d, LEB %d:%d", pnum, vol_id, |
@@ -963,7 +963,7 @@ write_error: | |||
963 | static int is_error_sane(int err) | 963 | static int is_error_sane(int err) |
964 | { | 964 | { |
965 | if (err == -EIO || err == -ENOMEM || err == UBI_IO_BAD_HDR || | 965 | if (err == -EIO || err == -ENOMEM || err == UBI_IO_BAD_HDR || |
966 | err == UBI_IO_BAD_HDR_READ || err == -ETIMEDOUT) | 966 | err == UBI_IO_BAD_HDR_EBADMSG || err == -ETIMEDOUT) |
967 | return 0; | 967 | return 0; |
968 | return 1; | 968 | return 1; |
969 | } | 969 | } |
@@ -1201,6 +1201,9 @@ static void print_rsvd_warning(struct ubi_device *ubi, | |||
1201 | 1201 | ||
1202 | ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d," | 1202 | ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d," |
1203 | " need %d", ubi->beb_rsvd_pebs, ubi->beb_rsvd_level); | 1203 | " need %d", ubi->beb_rsvd_pebs, ubi->beb_rsvd_level); |
1204 | if (ubi->corr_peb_count) | ||
1205 | ubi_warn("%d PEBs are corrupted and not used", | ||
1206 | ubi->corr_peb_count); | ||
1204 | } | 1207 | } |
1205 | 1208 | ||
1206 | /** | 1209 | /** |
@@ -1263,6 +1266,9 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1263 | if (ubi->avail_pebs < EBA_RESERVED_PEBS) { | 1266 | if (ubi->avail_pebs < EBA_RESERVED_PEBS) { |
1264 | ubi_err("no enough physical eraseblocks (%d, need %d)", | 1267 | ubi_err("no enough physical eraseblocks (%d, need %d)", |
1265 | ubi->avail_pebs, EBA_RESERVED_PEBS); | 1268 | ubi->avail_pebs, EBA_RESERVED_PEBS); |
1269 | if (ubi->corr_peb_count) | ||
1270 | ubi_err("%d PEBs are corrupted and not used", | ||
1271 | ubi->corr_peb_count); | ||
1266 | err = -ENOSPC; | 1272 | err = -ENOSPC; |
1267 | goto out_free; | 1273 | goto out_free; |
1268 | } | 1274 | } |
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 332f992f13d9..c2960ac9f39c 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -376,25 +376,6 @@ retry: | |||
376 | return 0; | 376 | return 0; |
377 | } | 377 | } |
378 | 378 | ||
379 | /** | ||
380 | * check_pattern - check if buffer contains only a certain byte pattern. | ||
381 | * @buf: buffer to check | ||
382 | * @patt: the pattern to check | ||
383 | * @size: buffer size in bytes | ||
384 | * | ||
385 | * This function returns %1 in there are only @patt bytes in @buf, and %0 if | ||
386 | * something else was also found. | ||
387 | */ | ||
388 | static int check_pattern(const void *buf, uint8_t patt, int size) | ||
389 | { | ||
390 | int i; | ||
391 | |||
392 | for (i = 0; i < size; i++) | ||
393 | if (((const uint8_t *)buf)[i] != patt) | ||
394 | return 0; | ||
395 | return 1; | ||
396 | } | ||
397 | |||
398 | /* Patterns to write to a physical eraseblock when torturing it */ | 379 | /* Patterns to write to a physical eraseblock when torturing it */ |
399 | static uint8_t patterns[] = {0xa5, 0x5a, 0x0}; | 380 | static uint8_t patterns[] = {0xa5, 0x5a, 0x0}; |
400 | 381 | ||
@@ -426,7 +407,7 @@ static int torture_peb(struct ubi_device *ubi, int pnum) | |||
426 | if (err) | 407 | if (err) |
427 | goto out; | 408 | goto out; |
428 | 409 | ||
429 | err = check_pattern(ubi->peb_buf1, 0xFF, ubi->peb_size); | 410 | err = ubi_check_pattern(ubi->peb_buf1, 0xFF, ubi->peb_size); |
430 | if (err == 0) { | 411 | if (err == 0) { |
431 | ubi_err("erased PEB %d, but a non-0xFF byte found", | 412 | ubi_err("erased PEB %d, but a non-0xFF byte found", |
432 | pnum); | 413 | pnum); |
@@ -445,7 +426,8 @@ static int torture_peb(struct ubi_device *ubi, int pnum) | |||
445 | if (err) | 426 | if (err) |
446 | goto out; | 427 | goto out; |
447 | 428 | ||
448 | err = check_pattern(ubi->peb_buf1, patterns[i], ubi->peb_size); | 429 | err = ubi_check_pattern(ubi->peb_buf1, patterns[i], |
430 | ubi->peb_size); | ||
449 | if (err == 0) { | 431 | if (err == 0) { |
450 | ubi_err("pattern %x checking failed for PEB %d", | 432 | ubi_err("pattern %x checking failed for PEB %d", |
451 | patterns[i], pnum); | 433 | patterns[i], pnum); |
@@ -517,7 +499,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum) | |||
517 | * In this case we probably anyway have garbage in this PEB. | 499 | * In this case we probably anyway have garbage in this PEB. |
518 | */ | 500 | */ |
519 | err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0); | 501 | err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0); |
520 | if (err1 == UBI_IO_BAD_HDR_READ || err1 == UBI_IO_BAD_HDR) | 502 | if (err1 == UBI_IO_BAD_HDR_EBADMSG || err1 == UBI_IO_BAD_HDR) |
521 | /* | 503 | /* |
522 | * The VID header is corrupted, so we can safely erase this | 504 | * The VID header is corrupted, so we can safely erase this |
523 | * PEB and not afraid that it will be treated as a valid PEB in | 505 | * PEB and not afraid that it will be treated as a valid PEB in |
@@ -712,47 +694,47 @@ bad: | |||
712 | * and corrected by the flash driver; this is harmless but may indicate that | 694 | * and corrected by the flash driver; this is harmless but may indicate that |
713 | * this eraseblock may become bad soon (but may be not); | 695 | * this eraseblock may become bad soon (but may be not); |
714 | * o %UBI_IO_BAD_HDR if the erase counter header is corrupted (a CRC error); | 696 | * o %UBI_IO_BAD_HDR if the erase counter header is corrupted (a CRC error); |
715 | * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty; | 697 | * o %UBI_IO_BAD_HDR_EBADMSG is the same as %UBI_IO_BAD_HDR, but there also was |
698 | * a data integrity error (uncorrectable ECC error in case of NAND); | ||
699 | * o %UBI_IO_FF if only 0xFF bytes were read (the PEB is supposedly empty) | ||
716 | * o a negative error code in case of failure. | 700 | * o a negative error code in case of failure. |
717 | */ | 701 | */ |
718 | int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | 702 | int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, |
719 | struct ubi_ec_hdr *ec_hdr, int verbose) | 703 | struct ubi_ec_hdr *ec_hdr, int verbose) |
720 | { | 704 | { |
721 | int err, read_err = 0; | 705 | int err, read_err; |
722 | uint32_t crc, magic, hdr_crc; | 706 | uint32_t crc, magic, hdr_crc; |
723 | 707 | ||
724 | dbg_io("read EC header from PEB %d", pnum); | 708 | dbg_io("read EC header from PEB %d", pnum); |
725 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); | 709 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); |
726 | 710 | ||
727 | err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); | 711 | read_err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); |
728 | if (err) { | 712 | if (read_err) { |
729 | if (err != UBI_IO_BITFLIPS && err != -EBADMSG) | 713 | if (read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG) |
730 | return err; | 714 | return read_err; |
731 | 715 | ||
732 | /* | 716 | /* |
733 | * We read all the data, but either a correctable bit-flip | 717 | * We read all the data, but either a correctable bit-flip |
734 | * occurred, or MTD reported about some data integrity error, | 718 | * occurred, or MTD reported a data integrity error |
735 | * like an ECC error in case of NAND. The former is harmless, | 719 | * (uncorrectable ECC error in case of NAND). The former is |
736 | * the later may mean that the read data is corrupted. But we | 720 | * harmless, the later may mean that the read data is |
737 | * have a CRC check-sum and we will detect this. If the EC | 721 | * corrupted. But we have a CRC check-sum and we will detect |
738 | * header is still OK, we just report this as there was a | 722 | * this. If the EC header is still OK, we just report this as |
739 | * bit-flip. | 723 | * there was a bit-flip, to force scrubbing. |
740 | */ | 724 | */ |
741 | if (err == -EBADMSG) | ||
742 | read_err = UBI_IO_BAD_HDR_READ; | ||
743 | } | 725 | } |
744 | 726 | ||
745 | magic = be32_to_cpu(ec_hdr->magic); | 727 | magic = be32_to_cpu(ec_hdr->magic); |
746 | if (magic != UBI_EC_HDR_MAGIC) { | 728 | if (magic != UBI_EC_HDR_MAGIC) { |
747 | if (read_err) | 729 | if (read_err == -EBADMSG) |
748 | return read_err; | 730 | return UBI_IO_BAD_HDR_EBADMSG; |
749 | 731 | ||
750 | /* | 732 | /* |
751 | * The magic field is wrong. Let's check if we have read all | 733 | * The magic field is wrong. Let's check if we have read all |
752 | * 0xFF. If yes, this physical eraseblock is assumed to be | 734 | * 0xFF. If yes, this physical eraseblock is assumed to be |
753 | * empty. | 735 | * empty. |
754 | */ | 736 | */ |
755 | if (check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { | 737 | if (ubi_check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) { |
756 | /* The physical eraseblock is supposedly empty */ | 738 | /* The physical eraseblock is supposedly empty */ |
757 | if (verbose) | 739 | if (verbose) |
758 | ubi_warn("no EC header found at PEB %d, " | 740 | ubi_warn("no EC header found at PEB %d, " |
@@ -760,7 +742,10 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
760 | else if (UBI_IO_DEBUG) | 742 | else if (UBI_IO_DEBUG) |
761 | dbg_msg("no EC header found at PEB %d, " | 743 | dbg_msg("no EC header found at PEB %d, " |
762 | "only 0xFF bytes", pnum); | 744 | "only 0xFF bytes", pnum); |
763 | return UBI_IO_PEB_EMPTY; | 745 | if (!read_err) |
746 | return UBI_IO_FF; | ||
747 | else | ||
748 | return UBI_IO_FF_BITFLIPS; | ||
764 | } | 749 | } |
765 | 750 | ||
766 | /* | 751 | /* |
@@ -788,7 +773,11 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum, | |||
788 | } else if (UBI_IO_DEBUG) | 773 | } else if (UBI_IO_DEBUG) |
789 | dbg_msg("bad EC header CRC at PEB %d, calculated " | 774 | dbg_msg("bad EC header CRC at PEB %d, calculated " |
790 | "%#08x, read %#08x", pnum, crc, hdr_crc); | 775 | "%#08x, read %#08x", pnum, crc, hdr_crc); |
791 | return read_err ?: UBI_IO_BAD_HDR; | 776 | |
777 | if (!read_err) | ||
778 | return UBI_IO_BAD_HDR; | ||
779 | else | ||
780 | return UBI_IO_BAD_HDR_EBADMSG; | ||
792 | } | 781 | } |
793 | 782 | ||
794 | /* And of course validate what has just been read from the media */ | 783 | /* And of course validate what has just been read from the media */ |
@@ -975,22 +964,16 @@ bad: | |||
975 | * | 964 | * |
976 | * This function reads the volume identifier header from physical eraseblock | 965 | * This function reads the volume identifier header from physical eraseblock |
977 | * @pnum and stores it in @vid_hdr. It also checks CRC checksum of the read | 966 | * @pnum and stores it in @vid_hdr. It also checks CRC checksum of the read |
978 | * volume identifier header. The following codes may be returned: | 967 | * volume identifier header. The error codes are the same as in |
968 | * 'ubi_io_read_ec_hdr()'. | ||
979 | * | 969 | * |
980 | * o %0 if the CRC checksum is correct and the header was successfully read; | 970 | * Note, the implementation of this function is also very similar to |
981 | * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected | 971 | * 'ubi_io_read_ec_hdr()', so refer commentaries in 'ubi_io_read_ec_hdr()'. |
982 | * and corrected by the flash driver; this is harmless but may indicate that | ||
983 | * this eraseblock may become bad soon; | ||
984 | * o %UBI_IO_BAD_HDR if the volume identifier header is corrupted (a CRC | ||
985 | * error detected); | ||
986 | * o %UBI_IO_PEB_FREE if the physical eraseblock is free (i.e., there is no VID | ||
987 | * header there); | ||
988 | * o a negative error code in case of failure. | ||
989 | */ | 972 | */ |
990 | int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | 973 | int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, |
991 | struct ubi_vid_hdr *vid_hdr, int verbose) | 974 | struct ubi_vid_hdr *vid_hdr, int verbose) |
992 | { | 975 | { |
993 | int err, read_err = 0; | 976 | int err, read_err; |
994 | uint32_t crc, magic, hdr_crc; | 977 | uint32_t crc, magic, hdr_crc; |
995 | void *p; | 978 | void *p; |
996 | 979 | ||
@@ -998,48 +981,29 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | |||
998 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); | 981 | ubi_assert(pnum >= 0 && pnum < ubi->peb_count); |
999 | 982 | ||
1000 | p = (char *)vid_hdr - ubi->vid_hdr_shift; | 983 | p = (char *)vid_hdr - ubi->vid_hdr_shift; |
1001 | err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, | 984 | read_err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, |
1002 | ubi->vid_hdr_alsize); | 985 | ubi->vid_hdr_alsize); |
1003 | if (err) { | 986 | if (read_err && read_err != UBI_IO_BITFLIPS && read_err != -EBADMSG) |
1004 | if (err != UBI_IO_BITFLIPS && err != -EBADMSG) | 987 | return read_err; |
1005 | return err; | ||
1006 | |||
1007 | /* | ||
1008 | * We read all the data, but either a correctable bit-flip | ||
1009 | * occurred, or MTD reported about some data integrity error, | ||
1010 | * like an ECC error in case of NAND. The former is harmless, | ||
1011 | * the later may mean the read data is corrupted. But we have a | ||
1012 | * CRC check-sum and we will identify this. If the VID header is | ||
1013 | * still OK, we just report this as there was a bit-flip. | ||
1014 | */ | ||
1015 | if (err == -EBADMSG) | ||
1016 | read_err = UBI_IO_BAD_HDR_READ; | ||
1017 | } | ||
1018 | 988 | ||
1019 | magic = be32_to_cpu(vid_hdr->magic); | 989 | magic = be32_to_cpu(vid_hdr->magic); |
1020 | if (magic != UBI_VID_HDR_MAGIC) { | 990 | if (magic != UBI_VID_HDR_MAGIC) { |
1021 | if (read_err) | 991 | if (read_err == -EBADMSG) |
1022 | return read_err; | 992 | return UBI_IO_BAD_HDR_EBADMSG; |
1023 | 993 | ||
1024 | /* | 994 | if (ubi_check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { |
1025 | * If we have read all 0xFF bytes, the VID header probably does | ||
1026 | * not exist and the physical eraseblock is assumed to be free. | ||
1027 | */ | ||
1028 | if (check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) { | ||
1029 | /* The physical eraseblock is supposedly free */ | ||
1030 | if (verbose) | 995 | if (verbose) |
1031 | ubi_warn("no VID header found at PEB %d, " | 996 | ubi_warn("no VID header found at PEB %d, " |
1032 | "only 0xFF bytes", pnum); | 997 | "only 0xFF bytes", pnum); |
1033 | else if (UBI_IO_DEBUG) | 998 | else if (UBI_IO_DEBUG) |
1034 | dbg_msg("no VID header found at PEB %d, " | 999 | dbg_msg("no VID header found at PEB %d, " |
1035 | "only 0xFF bytes", pnum); | 1000 | "only 0xFF bytes", pnum); |
1036 | return UBI_IO_PEB_FREE; | 1001 | if (!read_err) |
1002 | return UBI_IO_FF; | ||
1003 | else | ||
1004 | return UBI_IO_FF_BITFLIPS; | ||
1037 | } | 1005 | } |
1038 | 1006 | ||
1039 | /* | ||
1040 | * This is not a valid VID header, and these are not 0xFF | ||
1041 | * bytes. Report that the header is corrupted. | ||
1042 | */ | ||
1043 | if (verbose) { | 1007 | if (verbose) { |
1044 | ubi_warn("bad magic number at PEB %d: %08x instead of " | 1008 | ubi_warn("bad magic number at PEB %d: %08x instead of " |
1045 | "%08x", pnum, magic, UBI_VID_HDR_MAGIC); | 1009 | "%08x", pnum, magic, UBI_VID_HDR_MAGIC); |
@@ -1061,20 +1025,18 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1061 | } else if (UBI_IO_DEBUG) | 1025 | } else if (UBI_IO_DEBUG) |
1062 | dbg_msg("bad CRC at PEB %d, calculated %#08x, " | 1026 | dbg_msg("bad CRC at PEB %d, calculated %#08x, " |
1063 | "read %#08x", pnum, crc, hdr_crc); | 1027 | "read %#08x", pnum, crc, hdr_crc); |
1064 | return read_err ?: UBI_IO_BAD_HDR; | 1028 | if (!read_err) |
1029 | return UBI_IO_BAD_HDR; | ||
1030 | else | ||
1031 | return UBI_IO_BAD_HDR_EBADMSG; | ||
1065 | } | 1032 | } |
1066 | 1033 | ||
1067 | /* Validate the VID header that we have just read */ | ||
1068 | err = validate_vid_hdr(ubi, vid_hdr); | 1034 | err = validate_vid_hdr(ubi, vid_hdr); |
1069 | if (err) { | 1035 | if (err) { |
1070 | ubi_err("validation failed for PEB %d", pnum); | 1036 | ubi_err("validation failed for PEB %d", pnum); |
1071 | return -EINVAL; | 1037 | return -EINVAL; |
1072 | } | 1038 | } |
1073 | 1039 | ||
1074 | /* | ||
1075 | * If there was a read error (%-EBADMSG), but the header CRC is still | ||
1076 | * OK, report about a bit-flip to force scrubbing on this PEB. | ||
1077 | */ | ||
1078 | return read_err ? UBI_IO_BITFLIPS : 0; | 1040 | return read_err ? UBI_IO_BITFLIPS : 0; |
1079 | } | 1041 | } |
1080 | 1042 | ||
@@ -1383,7 +1345,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | |||
1383 | goto error; | 1345 | goto error; |
1384 | } | 1346 | } |
1385 | 1347 | ||
1386 | err = check_pattern(ubi->dbg_peb_buf, 0xFF, len); | 1348 | err = ubi_check_pattern(ubi->dbg_peb_buf, 0xFF, len); |
1387 | if (err == 0) { | 1349 | if (err == 0) { |
1388 | ubi_err("flash region at PEB %d:%d, length %d does not " | 1350 | ubi_err("flash region at PEB %d:%d, length %d does not " |
1389 | "contain all 0xFF bytes", pnum, offset, len); | 1351 | "contain all 0xFF bytes", pnum, offset, len); |
diff --git a/drivers/mtd/ubi/misc.c b/drivers/mtd/ubi/misc.c index 22ad31402945..ff2a65c37f69 100644 --- a/drivers/mtd/ubi/misc.c +++ b/drivers/mtd/ubi/misc.c | |||
@@ -103,3 +103,22 @@ void ubi_calculate_reserved(struct ubi_device *ubi) | |||
103 | if (ubi->beb_rsvd_level < MIN_RESEVED_PEBS) | 103 | if (ubi->beb_rsvd_level < MIN_RESEVED_PEBS) |
104 | ubi->beb_rsvd_level = MIN_RESEVED_PEBS; | 104 | ubi->beb_rsvd_level = MIN_RESEVED_PEBS; |
105 | } | 105 | } |
106 | |||
107 | /** | ||
108 | * ubi_check_pattern - check if buffer contains only a certain byte pattern. | ||
109 | * @buf: buffer to check | ||
110 | * @patt: the pattern to check | ||
111 | * @size: buffer size in bytes | ||
112 | * | ||
113 | * This function returns %1 in there are only @patt bytes in @buf, and %0 if | ||
114 | * something else was also found. | ||
115 | */ | ||
116 | int ubi_check_pattern(const void *buf, uint8_t patt, int size) | ||
117 | { | ||
118 | int i; | ||
119 | |||
120 | for (i = 0; i < size; i++) | ||
121 | if (((const uint8_t *)buf)[i] != patt) | ||
122 | return 0; | ||
123 | return 1; | ||
124 | } | ||
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 69b52e9c9489..3c631863bf40 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -29,7 +29,7 @@ | |||
29 | * objects which are kept in volume RB-tree with root at the @volumes field. | 29 | * objects which are kept in volume RB-tree with root at the @volumes field. |
30 | * The RB-tree is indexed by the volume ID. | 30 | * The RB-tree is indexed by the volume ID. |
31 | * | 31 | * |
32 | * Found logical eraseblocks are represented by &struct ubi_scan_leb objects. | 32 | * Scanned logical eraseblocks are represented by &struct ubi_scan_leb objects. |
33 | * These objects are kept in per-volume RB-trees with the root at the | 33 | * These objects are kept in per-volume RB-trees with the root at the |
34 | * corresponding &struct ubi_scan_volume object. To put it differently, we keep | 34 | * corresponding &struct ubi_scan_volume object. To put it differently, we keep |
35 | * an RB-tree of per-volume objects and each of these objects is the root of | 35 | * an RB-tree of per-volume objects and each of these objects is the root of |
@@ -38,6 +38,33 @@ | |||
38 | * Corrupted physical eraseblocks are put to the @corr list, free physical | 38 | * Corrupted physical eraseblocks are put to the @corr list, free physical |
39 | * eraseblocks are put to the @free list and the physical eraseblock to be | 39 | * eraseblocks are put to the @free list and the physical eraseblock to be |
40 | * erased are put to the @erase list. | 40 | * erased are put to the @erase list. |
41 | * | ||
42 | * UBI tries to distinguish between 2 types of corruptions. | ||
43 | * 1. Corruptions caused by power cuts. These are harmless and expected | ||
44 | * corruptions and UBI tries to handle them gracefully, without printing too | ||
45 | * many warnings and error messages. The idea is that we do not lose | ||
46 | * important data in these case - we may lose only the data which was being | ||
47 | * written to the media just before the power cut happened, and the upper | ||
48 | * layers (e.g., UBIFS) are supposed to handle these situations. UBI puts | ||
49 | * these PEBs to the head of the @erase list and they are scheduled for | ||
50 | * erasure. | ||
51 | * | ||
52 | * 2. Unexpected corruptions which are not caused by power cuts. During | ||
53 | * scanning, such PEBs are put to the @corr list and UBI preserves them. | ||
54 | * Obviously, this lessens the amount of available PEBs, and if at some | ||
55 | * point UBI runs out of free PEBs, it switches to R/O mode. UBI also loudly | ||
56 | * informs about such PEBs every time the MTD device is attached. | ||
57 | * | ||
58 | * However, it is difficult to reliably distinguish between these types of | ||
59 | * corruptions and UBI's strategy is as follows. UBI assumes (2.) if the VID | ||
60 | * header is corrupted and the data area does not contain all 0xFFs, and there | ||
61 | * were not bit-flips or integrity errors while reading the data area. Otherwise | ||
62 | * UBI assumes (1.). The assumptions are: | ||
63 | * o if the data area contains only 0xFFs, there is no data, and it is safe | ||
64 | * to just erase this PEB. | ||
65 | * o if the data area has bit-flips and data integrity errors (ECC errors on | ||
66 | * NAND), it is probably a PEB which was being erased when power cut | ||
67 | * happened. | ||
41 | */ | 68 | */ |
42 | 69 | ||
43 | #include <linux/err.h> | 70 | #include <linux/err.h> |
@@ -62,26 +89,26 @@ static struct ubi_vid_hdr *vidh; | |||
62 | * @si: scanning information | 89 | * @si: scanning information |
63 | * @pnum: physical eraseblock number to add | 90 | * @pnum: physical eraseblock number to add |
64 | * @ec: erase counter of the physical eraseblock | 91 | * @ec: erase counter of the physical eraseblock |
92 | * @to_head: if not zero, add to the head of the list | ||
65 | * @list: the list to add to | 93 | * @list: the list to add to |
66 | * | 94 | * |
67 | * This function adds physical eraseblock @pnum to free, erase, corrupted or | 95 | * This function adds physical eraseblock @pnum to free, erase, or alien lists. |
68 | * alien lists. Returns zero in case of success and a negative error code in | 96 | * If @to_head is not zero, PEB will be added to the head of the list, which |
69 | * case of failure. | 97 | * basically means it will be processed first later. E.g., we add corrupted |
98 | * PEBs (corrupted due to power cuts) to the head of the erase list to make | ||
99 | * sure we erase them first and get rid of corruptions ASAP. This function | ||
100 | * returns zero in case of success and a negative error code in case of | ||
101 | * failure. | ||
70 | */ | 102 | */ |
71 | static int add_to_list(struct ubi_scan_info *si, int pnum, int ec, | 103 | static int add_to_list(struct ubi_scan_info *si, int pnum, int ec, int to_head, |
72 | struct list_head *list) | 104 | struct list_head *list) |
73 | { | 105 | { |
74 | struct ubi_scan_leb *seb; | 106 | struct ubi_scan_leb *seb; |
75 | 107 | ||
76 | if (list == &si->free) { | 108 | if (list == &si->free) { |
77 | dbg_bld("add to free: PEB %d, EC %d", pnum, ec); | 109 | dbg_bld("add to free: PEB %d, EC %d", pnum, ec); |
78 | si->free_peb_count += 1; | ||
79 | } else if (list == &si->erase) { | 110 | } else if (list == &si->erase) { |
80 | dbg_bld("add to erase: PEB %d, EC %d", pnum, ec); | 111 | dbg_bld("add to erase: PEB %d, EC %d", pnum, ec); |
81 | si->erase_peb_count += 1; | ||
82 | } else if (list == &si->corr) { | ||
83 | dbg_bld("add to corrupted: PEB %d, EC %d", pnum, ec); | ||
84 | si->corr_peb_count += 1; | ||
85 | } else if (list == &si->alien) { | 112 | } else if (list == &si->alien) { |
86 | dbg_bld("add to alien: PEB %d, EC %d", pnum, ec); | 113 | dbg_bld("add to alien: PEB %d, EC %d", pnum, ec); |
87 | si->alien_peb_count += 1; | 114 | si->alien_peb_count += 1; |
@@ -94,7 +121,37 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec, | |||
94 | 121 | ||
95 | seb->pnum = pnum; | 122 | seb->pnum = pnum; |
96 | seb->ec = ec; | 123 | seb->ec = ec; |
97 | list_add_tail(&seb->u.list, list); | 124 | if (to_head) |
125 | list_add(&seb->u.list, list); | ||
126 | else | ||
127 | list_add_tail(&seb->u.list, list); | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | /** | ||
132 | * add_corrupted - add a corrupted physical eraseblock. | ||
133 | * @si: scanning information | ||
134 | * @pnum: physical eraseblock number to add | ||
135 | * @ec: erase counter of the physical eraseblock | ||
136 | * | ||
137 | * This function adds corrupted physical eraseblock @pnum to the 'corr' list. | ||
138 | * The corruption was presumably not caused by a power cut. Returns zero in | ||
139 | * case of success and a negative error code in case of failure. | ||
140 | */ | ||
141 | static int add_corrupted(struct ubi_scan_info *si, int pnum, int ec) | ||
142 | { | ||
143 | struct ubi_scan_leb *seb; | ||
144 | |||
145 | dbg_bld("add to corrupted: PEB %d, EC %d", pnum, ec); | ||
146 | |||
147 | seb = kmalloc(sizeof(struct ubi_scan_leb), GFP_KERNEL); | ||
148 | if (!seb) | ||
149 | return -ENOMEM; | ||
150 | |||
151 | si->corr_peb_count += 1; | ||
152 | seb->pnum = pnum; | ||
153 | seb->ec = ec; | ||
154 | list_add(&seb->u.list, &si->corr); | ||
98 | return 0; | 155 | return 0; |
99 | } | 156 | } |
100 | 157 | ||
@@ -258,8 +315,8 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, | |||
258 | * created before sequence numbers support has been added. At | 315 | * created before sequence numbers support has been added. At |
259 | * that times we used 32-bit LEB versions stored in logical | 316 | * that times we used 32-bit LEB versions stored in logical |
260 | * eraseblocks. That was before UBI got into mainline. We do not | 317 | * eraseblocks. That was before UBI got into mainline. We do not |
261 | * support these images anymore. Well, those images will work | 318 | * support these images anymore. Well, those images still work, |
262 | * still work, but only if no unclean reboots happened. | 319 | * but only if no unclean reboots happened. |
263 | */ | 320 | */ |
264 | ubi_err("unsupported on-flash UBI format\n"); | 321 | ubi_err("unsupported on-flash UBI format\n"); |
265 | return -EINVAL; | 322 | return -EINVAL; |
@@ -285,19 +342,25 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, | |||
285 | return 1; | 342 | return 1; |
286 | } | 343 | } |
287 | } else { | 344 | } else { |
288 | pnum = seb->pnum; | 345 | if (!seb->copy_flag) { |
346 | /* It is not a copy, so it is newer */ | ||
347 | dbg_bld("first PEB %d is newer, copy_flag is unset", | ||
348 | pnum); | ||
349 | return bitflips << 1; | ||
350 | } | ||
289 | 351 | ||
290 | vh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); | 352 | vh = ubi_zalloc_vid_hdr(ubi, GFP_KERNEL); |
291 | if (!vh) | 353 | if (!vh) |
292 | return -ENOMEM; | 354 | return -ENOMEM; |
293 | 355 | ||
356 | pnum = seb->pnum; | ||
294 | err = ubi_io_read_vid_hdr(ubi, pnum, vh, 0); | 357 | err = ubi_io_read_vid_hdr(ubi, pnum, vh, 0); |
295 | if (err) { | 358 | if (err) { |
296 | if (err == UBI_IO_BITFLIPS) | 359 | if (err == UBI_IO_BITFLIPS) |
297 | bitflips = 1; | 360 | bitflips = 1; |
298 | else { | 361 | else { |
299 | dbg_err("VID of PEB %d header is bad, but it " | 362 | dbg_err("VID of PEB %d header is bad, but it " |
300 | "was OK earlier", pnum); | 363 | "was OK earlier, err %d", pnum, err); |
301 | if (err > 0) | 364 | if (err > 0) |
302 | err = -EIO; | 365 | err = -EIO; |
303 | 366 | ||
@@ -305,14 +368,6 @@ static int compare_lebs(struct ubi_device *ubi, const struct ubi_scan_leb *seb, | |||
305 | } | 368 | } |
306 | } | 369 | } |
307 | 370 | ||
308 | if (!vh->copy_flag) { | ||
309 | /* It is not a copy, so it is newer */ | ||
310 | dbg_bld("first PEB %d is newer, copy_flag is unset", | ||
311 | pnum); | ||
312 | err = bitflips << 1; | ||
313 | goto out_free_vidh; | ||
314 | } | ||
315 | |||
316 | vid_hdr = vh; | 371 | vid_hdr = vh; |
317 | } | 372 | } |
318 | 373 | ||
@@ -463,18 +518,15 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
463 | if (err) | 518 | if (err) |
464 | return err; | 519 | return err; |
465 | 520 | ||
466 | if (cmp_res & 4) | 521 | err = add_to_list(si, seb->pnum, seb->ec, cmp_res & 4, |
467 | err = add_to_list(si, seb->pnum, seb->ec, | 522 | &si->erase); |
468 | &si->corr); | ||
469 | else | ||
470 | err = add_to_list(si, seb->pnum, seb->ec, | ||
471 | &si->erase); | ||
472 | if (err) | 523 | if (err) |
473 | return err; | 524 | return err; |
474 | 525 | ||
475 | seb->ec = ec; | 526 | seb->ec = ec; |
476 | seb->pnum = pnum; | 527 | seb->pnum = pnum; |
477 | seb->scrub = ((cmp_res & 2) || bitflips); | 528 | seb->scrub = ((cmp_res & 2) || bitflips); |
529 | seb->copy_flag = vid_hdr->copy_flag; | ||
478 | seb->sqnum = sqnum; | 530 | seb->sqnum = sqnum; |
479 | 531 | ||
480 | if (sv->highest_lnum == lnum) | 532 | if (sv->highest_lnum == lnum) |
@@ -487,10 +539,8 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
487 | * This logical eraseblock is older than the one found | 539 | * This logical eraseblock is older than the one found |
488 | * previously. | 540 | * previously. |
489 | */ | 541 | */ |
490 | if (cmp_res & 4) | 542 | return add_to_list(si, pnum, ec, cmp_res & 4, |
491 | return add_to_list(si, pnum, ec, &si->corr); | 543 | &si->erase); |
492 | else | ||
493 | return add_to_list(si, pnum, ec, &si->erase); | ||
494 | } | 544 | } |
495 | } | 545 | } |
496 | 546 | ||
@@ -510,8 +560,9 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
510 | seb->ec = ec; | 560 | seb->ec = ec; |
511 | seb->pnum = pnum; | 561 | seb->pnum = pnum; |
512 | seb->lnum = lnum; | 562 | seb->lnum = lnum; |
513 | seb->sqnum = sqnum; | ||
514 | seb->scrub = bitflips; | 563 | seb->scrub = bitflips; |
564 | seb->copy_flag = vid_hdr->copy_flag; | ||
565 | seb->sqnum = sqnum; | ||
515 | 566 | ||
516 | if (sv->highest_lnum <= lnum) { | 567 | if (sv->highest_lnum <= lnum) { |
517 | sv->highest_lnum = lnum; | 568 | sv->highest_lnum = lnum; |
@@ -521,7 +572,6 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
521 | sv->leb_count += 1; | 572 | sv->leb_count += 1; |
522 | rb_link_node(&seb->u.rb, parent, p); | 573 | rb_link_node(&seb->u.rb, parent, p); |
523 | rb_insert_color(&seb->u.rb, &sv->root); | 574 | rb_insert_color(&seb->u.rb, &sv->root); |
524 | si->used_peb_count += 1; | ||
525 | return 0; | 575 | return 0; |
526 | } | 576 | } |
527 | 577 | ||
@@ -668,8 +718,8 @@ out_free: | |||
668 | struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi, | 718 | struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi, |
669 | struct ubi_scan_info *si) | 719 | struct ubi_scan_info *si) |
670 | { | 720 | { |
671 | int err = 0, i; | 721 | int err = 0; |
672 | struct ubi_scan_leb *seb; | 722 | struct ubi_scan_leb *seb, *tmp_seb; |
673 | 723 | ||
674 | if (!list_empty(&si->free)) { | 724 | if (!list_empty(&si->free)) { |
675 | seb = list_entry(si->free.next, struct ubi_scan_leb, u.list); | 725 | seb = list_entry(si->free.next, struct ubi_scan_leb, u.list); |
@@ -678,38 +728,86 @@ struct ubi_scan_leb *ubi_scan_get_free_peb(struct ubi_device *ubi, | |||
678 | return seb; | 728 | return seb; |
679 | } | 729 | } |
680 | 730 | ||
681 | for (i = 0; i < 2; i++) { | 731 | /* |
682 | struct list_head *head; | 732 | * We try to erase the first physical eraseblock from the erase list |
683 | struct ubi_scan_leb *tmp_seb; | 733 | * and pick it if we succeed, or try to erase the next one if not. And |
734 | * so forth. We don't want to take care about bad eraseblocks here - | ||
735 | * they'll be handled later. | ||
736 | */ | ||
737 | list_for_each_entry_safe(seb, tmp_seb, &si->erase, u.list) { | ||
738 | if (seb->ec == UBI_SCAN_UNKNOWN_EC) | ||
739 | seb->ec = si->mean_ec; | ||
684 | 740 | ||
685 | if (i == 0) | 741 | err = ubi_scan_erase_peb(ubi, si, seb->pnum, seb->ec+1); |
686 | head = &si->erase; | 742 | if (err) |
687 | else | 743 | continue; |
688 | head = &si->corr; | ||
689 | 744 | ||
745 | seb->ec += 1; | ||
746 | list_del(&seb->u.list); | ||
747 | dbg_bld("return PEB %d, EC %d", seb->pnum, seb->ec); | ||
748 | return seb; | ||
749 | } | ||
750 | |||
751 | ubi_err("no free eraseblocks"); | ||
752 | return ERR_PTR(-ENOSPC); | ||
753 | } | ||
754 | |||
755 | /** | ||
756 | * check_corruption - check the data area of PEB. | ||
757 | * @ubi: UBI device description object | ||
758 | * @vid_hrd: the (corrupted) VID header of this PEB | ||
759 | * @pnum: the physical eraseblock number to check | ||
760 | * | ||
761 | * This is a helper function which is used to distinguish between VID header | ||
762 | * corruptions caused by power cuts and other reasons. If the PEB contains only | ||
763 | * 0xFF bytes in the data area, the VID header is most probably corrupted | ||
764 | * because of a power cut (%0 is returned in this case). Otherwise, it was | ||
765 | * probably corrupted for some other reasons (%1 is returned in this case). A | ||
766 | * negative error code is returned if a read error occurred. | ||
767 | * | ||
768 | * If the corruption reason was a power cut, UBI can safely erase this PEB. | ||
769 | * Otherwise, it should preserve it to avoid possibly destroying important | ||
770 | * information. | ||
771 | */ | ||
772 | static int check_corruption(struct ubi_device *ubi, struct ubi_vid_hdr *vid_hdr, | ||
773 | int pnum) | ||
774 | { | ||
775 | int err; | ||
776 | |||
777 | mutex_lock(&ubi->buf_mutex); | ||
778 | memset(ubi->peb_buf1, 0x00, ubi->leb_size); | ||
779 | |||
780 | err = ubi_io_read(ubi, ubi->peb_buf1, pnum, ubi->leb_start, | ||
781 | ubi->leb_size); | ||
782 | if (err == UBI_IO_BITFLIPS || err == -EBADMSG) { | ||
690 | /* | 783 | /* |
691 | * We try to erase the first physical eraseblock from the @head | 784 | * Bit-flips or integrity errors while reading the data area. |
692 | * list and pick it if we succeed, or try to erase the | 785 | * It is difficult to say for sure what type of corruption is |
693 | * next one if not. And so forth. We don't want to take care | 786 | * this, but presumably a power cut happened while this PEB was |
694 | * about bad eraseblocks here - they'll be handled later. | 787 | * erased, so it became unstable and corrupted, and should be |
788 | * erased. | ||
695 | */ | 789 | */ |
696 | list_for_each_entry_safe(seb, tmp_seb, head, u.list) { | 790 | return 0; |
697 | if (seb->ec == UBI_SCAN_UNKNOWN_EC) | 791 | } |
698 | seb->ec = si->mean_ec; | ||
699 | 792 | ||
700 | err = ubi_scan_erase_peb(ubi, si, seb->pnum, seb->ec+1); | 793 | if (err) |
701 | if (err) | 794 | return err; |
702 | continue; | ||
703 | 795 | ||
704 | seb->ec += 1; | 796 | if (ubi_check_pattern(ubi->peb_buf1, 0xFF, ubi->leb_size)) { |
705 | list_del(&seb->u.list); | 797 | mutex_unlock(&ubi->buf_mutex); |
706 | dbg_bld("return PEB %d, EC %d", seb->pnum, seb->ec); | 798 | return 0; |
707 | return seb; | ||
708 | } | ||
709 | } | 799 | } |
710 | 800 | ||
711 | ubi_err("no eraseblocks found"); | 801 | ubi_err("PEB %d contains corrupted VID header, and the data does not " |
712 | return ERR_PTR(-ENOSPC); | 802 | "contain all 0xFF, this may be a non-UBI PEB or a severe VID " |
803 | "header corruption which requires manual inspection", pnum); | ||
804 | ubi_dbg_dump_vid_hdr(vid_hdr); | ||
805 | dbg_msg("hexdump of PEB %d offset %d, length %d", | ||
806 | pnum, ubi->leb_start, ubi->leb_size); | ||
807 | ubi_dbg_print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | ||
808 | ubi->peb_buf1, ubi->leb_size, 1); | ||
809 | mutex_unlock(&ubi->buf_mutex); | ||
810 | return 1; | ||
713 | } | 811 | } |
714 | 812 | ||
715 | /** | 813 | /** |
@@ -725,7 +823,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
725 | int pnum) | 823 | int pnum) |
726 | { | 824 | { |
727 | long long uninitialized_var(ec); | 825 | long long uninitialized_var(ec); |
728 | int err, bitflips = 0, vol_id, ec_corr = 0; | 826 | int err, bitflips = 0, vol_id, ec_err = 0; |
729 | 827 | ||
730 | dbg_bld("scan PEB %d", pnum); | 828 | dbg_bld("scan PEB %d", pnum); |
731 | 829 | ||
@@ -746,22 +844,37 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
746 | err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); | 844 | err = ubi_io_read_ec_hdr(ubi, pnum, ech, 0); |
747 | if (err < 0) | 845 | if (err < 0) |
748 | return err; | 846 | return err; |
749 | else if (err == UBI_IO_BITFLIPS) | 847 | switch (err) { |
848 | case 0: | ||
849 | break; | ||
850 | case UBI_IO_BITFLIPS: | ||
750 | bitflips = 1; | 851 | bitflips = 1; |
751 | else if (err == UBI_IO_PEB_EMPTY) | 852 | break; |
752 | return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, &si->erase); | 853 | case UBI_IO_FF: |
753 | else if (err == UBI_IO_BAD_HDR_READ || err == UBI_IO_BAD_HDR) { | 854 | si->empty_peb_count += 1; |
855 | return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, 0, | ||
856 | &si->erase); | ||
857 | case UBI_IO_FF_BITFLIPS: | ||
858 | si->empty_peb_count += 1; | ||
859 | return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, 1, | ||
860 | &si->erase); | ||
861 | case UBI_IO_BAD_HDR_EBADMSG: | ||
862 | case UBI_IO_BAD_HDR: | ||
754 | /* | 863 | /* |
755 | * We have to also look at the VID header, possibly it is not | 864 | * We have to also look at the VID header, possibly it is not |
756 | * corrupted. Set %bitflips flag in order to make this PEB be | 865 | * corrupted. Set %bitflips flag in order to make this PEB be |
757 | * moved and EC be re-created. | 866 | * moved and EC be re-created. |
758 | */ | 867 | */ |
759 | ec_corr = err; | 868 | ec_err = err; |
760 | ec = UBI_SCAN_UNKNOWN_EC; | 869 | ec = UBI_SCAN_UNKNOWN_EC; |
761 | bitflips = 1; | 870 | bitflips = 1; |
871 | break; | ||
872 | default: | ||
873 | ubi_err("'ubi_io_read_ec_hdr()' returned unknown code %d", err); | ||
874 | return -EINVAL; | ||
762 | } | 875 | } |
763 | 876 | ||
764 | if (!ec_corr) { | 877 | if (!ec_err) { |
765 | int image_seq; | 878 | int image_seq; |
766 | 879 | ||
767 | /* Make sure UBI version is OK */ | 880 | /* Make sure UBI version is OK */ |
@@ -814,24 +927,67 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
814 | err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0); | 927 | err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0); |
815 | if (err < 0) | 928 | if (err < 0) |
816 | return err; | 929 | return err; |
817 | else if (err == UBI_IO_BITFLIPS) | 930 | switch (err) { |
931 | case 0: | ||
932 | break; | ||
933 | case UBI_IO_BITFLIPS: | ||
818 | bitflips = 1; | 934 | bitflips = 1; |
819 | else if (err == UBI_IO_BAD_HDR_READ || err == UBI_IO_BAD_HDR || | 935 | break; |
820 | (err == UBI_IO_PEB_FREE && ec_corr)) { | 936 | case UBI_IO_BAD_HDR_EBADMSG: |
821 | /* VID header is corrupted */ | 937 | if (ec_err == UBI_IO_BAD_HDR_EBADMSG) |
822 | if (err == UBI_IO_BAD_HDR_READ || | 938 | /* |
823 | ec_corr == UBI_IO_BAD_HDR_READ) | 939 | * Both EC and VID headers are corrupted and were read |
824 | si->read_err_count += 1; | 940 | * with data integrity error, probably this is a bad |
825 | err = add_to_list(si, pnum, ec, &si->corr); | 941 | * PEB, bit it is not marked as bad yet. This may also |
942 | * be a result of power cut during erasure. | ||
943 | */ | ||
944 | si->maybe_bad_peb_count += 1; | ||
945 | case UBI_IO_BAD_HDR: | ||
946 | if (ec_err) | ||
947 | /* | ||
948 | * Both headers are corrupted. There is a possibility | ||
949 | * that this a valid UBI PEB which has corresponding | ||
950 | * LEB, but the headers are corrupted. However, it is | ||
951 | * impossible to distinguish it from a PEB which just | ||
952 | * contains garbage because of a power cut during erase | ||
953 | * operation. So we just schedule this PEB for erasure. | ||
954 | */ | ||
955 | err = 0; | ||
956 | else | ||
957 | /* | ||
958 | * The EC was OK, but the VID header is corrupted. We | ||
959 | * have to check what is in the data area. | ||
960 | */ | ||
961 | err = check_corruption(ubi, vidh, pnum); | ||
962 | |||
963 | if (err < 0) | ||
964 | return err; | ||
965 | else if (!err) | ||
966 | /* This corruption is caused by a power cut */ | ||
967 | err = add_to_list(si, pnum, ec, 1, &si->erase); | ||
968 | else | ||
969 | /* This is an unexpected corruption */ | ||
970 | err = add_corrupted(si, pnum, ec); | ||
826 | if (err) | 971 | if (err) |
827 | return err; | 972 | return err; |
828 | goto adjust_mean_ec; | 973 | goto adjust_mean_ec; |
829 | } else if (err == UBI_IO_PEB_FREE) { | 974 | case UBI_IO_FF_BITFLIPS: |
830 | /* No VID header - the physical eraseblock is free */ | 975 | err = add_to_list(si, pnum, ec, 1, &si->erase); |
831 | err = add_to_list(si, pnum, ec, &si->free); | ||
832 | if (err) | 976 | if (err) |
833 | return err; | 977 | return err; |
834 | goto adjust_mean_ec; | 978 | goto adjust_mean_ec; |
979 | case UBI_IO_FF: | ||
980 | if (ec_err) | ||
981 | err = add_to_list(si, pnum, ec, 1, &si->erase); | ||
982 | else | ||
983 | err = add_to_list(si, pnum, ec, 0, &si->free); | ||
984 | if (err) | ||
985 | return err; | ||
986 | goto adjust_mean_ec; | ||
987 | default: | ||
988 | ubi_err("'ubi_io_read_vid_hdr()' returned unknown code %d", | ||
989 | err); | ||
990 | return -EINVAL; | ||
835 | } | 991 | } |
836 | 992 | ||
837 | vol_id = be32_to_cpu(vidh->vol_id); | 993 | vol_id = be32_to_cpu(vidh->vol_id); |
@@ -843,7 +999,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
843 | case UBI_COMPAT_DELETE: | 999 | case UBI_COMPAT_DELETE: |
844 | ubi_msg("\"delete\" compatible internal volume %d:%d" | 1000 | ubi_msg("\"delete\" compatible internal volume %d:%d" |
845 | " found, will remove it", vol_id, lnum); | 1001 | " found, will remove it", vol_id, lnum); |
846 | err = add_to_list(si, pnum, ec, &si->erase); | 1002 | err = add_to_list(si, pnum, ec, 1, &si->erase); |
847 | if (err) | 1003 | if (err) |
848 | return err; | 1004 | return err; |
849 | return 0; | 1005 | return 0; |
@@ -858,7 +1014,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
858 | case UBI_COMPAT_PRESERVE: | 1014 | case UBI_COMPAT_PRESERVE: |
859 | ubi_msg("\"preserve\" compatible internal volume %d:%d" | 1015 | ubi_msg("\"preserve\" compatible internal volume %d:%d" |
860 | " found", vol_id, lnum); | 1016 | " found", vol_id, lnum); |
861 | err = add_to_list(si, pnum, ec, &si->alien); | 1017 | err = add_to_list(si, pnum, ec, 0, &si->alien); |
862 | if (err) | 1018 | if (err) |
863 | return err; | 1019 | return err; |
864 | return 0; | 1020 | return 0; |
@@ -870,7 +1026,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
870 | } | 1026 | } |
871 | } | 1027 | } |
872 | 1028 | ||
873 | if (ec_corr) | 1029 | if (ec_err) |
874 | ubi_warn("valid VID header but corrupted EC header at PEB %d", | 1030 | ubi_warn("valid VID header but corrupted EC header at PEB %d", |
875 | pnum); | 1031 | pnum); |
876 | err = ubi_scan_add_used(ubi, si, pnum, ec, vidh, bitflips); | 1032 | err = ubi_scan_add_used(ubi, si, pnum, ec, vidh, bitflips); |
@@ -878,7 +1034,7 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, | |||
878 | return err; | 1034 | return err; |
879 | 1035 | ||
880 | adjust_mean_ec: | 1036 | adjust_mean_ec: |
881 | if (!ec_corr) { | 1037 | if (!ec_err) { |
882 | si->ec_sum += ec; | 1038 | si->ec_sum += ec; |
883 | si->ec_count += 1; | 1039 | si->ec_count += 1; |
884 | if (ec > si->max_ec) | 1040 | if (ec > si->max_ec) |
@@ -904,19 +1060,20 @@ adjust_mean_ec: | |||
904 | static int check_what_we_have(struct ubi_device *ubi, struct ubi_scan_info *si) | 1060 | static int check_what_we_have(struct ubi_device *ubi, struct ubi_scan_info *si) |
905 | { | 1061 | { |
906 | struct ubi_scan_leb *seb; | 1062 | struct ubi_scan_leb *seb; |
907 | int max_corr; | 1063 | int max_corr, peb_count; |
908 | 1064 | ||
909 | max_corr = ubi->peb_count - si->bad_peb_count - si->alien_peb_count; | 1065 | peb_count = ubi->peb_count - si->bad_peb_count - si->alien_peb_count; |
910 | max_corr = max_corr / 20 ?: 8; | 1066 | max_corr = peb_count / 20 ?: 8; |
911 | 1067 | ||
912 | /* | 1068 | /* |
913 | * Few corrupted PEBs are not a problem and may be just a result of | 1069 | * Few corrupted PEBs is not a problem and may be just a result of |
914 | * unclean reboots. However, many of them may indicate some problems | 1070 | * unclean reboots. However, many of them may indicate some problems |
915 | * with the flash HW or driver. | 1071 | * with the flash HW or driver. |
916 | */ | 1072 | */ |
917 | if (si->corr_peb_count >= 8) { | 1073 | if (si->corr_peb_count) { |
918 | ubi_warn("%d PEBs are corrupted", si->corr_peb_count); | 1074 | ubi_err("%d PEBs are corrupted and preserved", |
919 | printk(KERN_WARNING "corrupted PEBs are:"); | 1075 | si->corr_peb_count); |
1076 | printk(KERN_ERR "Corrupted PEBs are:"); | ||
920 | list_for_each_entry(seb, &si->corr, u.list) | 1077 | list_for_each_entry(seb, &si->corr, u.list) |
921 | printk(KERN_CONT " %d", seb->pnum); | 1078 | printk(KERN_CONT " %d", seb->pnum); |
922 | printk(KERN_CONT "\n"); | 1079 | printk(KERN_CONT "\n"); |
@@ -931,41 +1088,35 @@ static int check_what_we_have(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
931 | } | 1088 | } |
932 | } | 1089 | } |
933 | 1090 | ||
934 | if (si->free_peb_count + si->used_peb_count + | 1091 | if (si->empty_peb_count + si->maybe_bad_peb_count == peb_count) { |
935 | si->alien_peb_count == 0) { | 1092 | /* |
936 | /* No UBI-formatted eraseblocks were found */ | 1093 | * All PEBs are empty, or almost all - a couple PEBs look like |
937 | if (si->corr_peb_count == si->read_err_count && | 1094 | * they may be bad PEBs which were not marked as bad yet. |
938 | si->corr_peb_count < 8) { | 1095 | * |
939 | /* No or just few corrupted PEBs, and all of them had a | 1096 | * This piece of code basically tries to distinguish between |
940 | * read error. We assume that those are bad PEBs, which | 1097 | * the following situations: |
941 | * were just not marked as bad so far. | 1098 | * |
942 | * | 1099 | * 1. Flash is empty, but there are few bad PEBs, which are not |
943 | * This piece of code basically tries to distinguish | 1100 | * marked as bad so far, and which were read with error. We |
944 | * between the following 2 situations: | 1101 | * want to go ahead and format this flash. While formatting, |
945 | * | 1102 | * the faulty PEBs will probably be marked as bad. |
946 | * 1. Flash is empty, but there are few bad PEBs, which | 1103 | * |
947 | * are not marked as bad so far, and which were read | 1104 | * 2. Flash contains non-UBI data and we do not want to format |
948 | * with error. We want to go ahead and format this | 1105 | * it and destroy possibly important information. |
949 | * flash. While formating, the faulty PEBs will | 1106 | */ |
950 | * probably be marked as bad. | 1107 | if (si->maybe_bad_peb_count <= 2) { |
951 | * | ||
952 | * 2. Flash probably contains non-UBI data and we do | ||
953 | * not want to format it and destroy possibly needed | ||
954 | * data (e.g., consider the case when the bootloader | ||
955 | * MTD partition was accidentally fed to UBI). | ||
956 | */ | ||
957 | si->is_empty = 1; | 1108 | si->is_empty = 1; |
958 | ubi_msg("empty MTD device detected"); | 1109 | ubi_msg("empty MTD device detected"); |
959 | get_random_bytes(&ubi->image_seq, sizeof(ubi->image_seq)); | 1110 | get_random_bytes(&ubi->image_seq, |
1111 | sizeof(ubi->image_seq)); | ||
960 | } else { | 1112 | } else { |
961 | ubi_err("MTD device possibly contains non-UBI data, " | 1113 | ubi_err("MTD device is not UBI-formatted and possibly " |
962 | "refusing it"); | 1114 | "contains non-UBI data - refusing it"); |
963 | return -EINVAL; | 1115 | return -EINVAL; |
964 | } | 1116 | } |
1117 | |||
965 | } | 1118 | } |
966 | 1119 | ||
967 | if (si->corr_peb_count > 0) | ||
968 | ubi_msg("corrupted PEBs will be formatted"); | ||
969 | return 0; | 1120 | return 0; |
970 | } | 1121 | } |
971 | 1122 | ||
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h index 2576a8d1532b..a3264f0bef2b 100644 --- a/drivers/mtd/ubi/scan.h +++ b/drivers/mtd/ubi/scan.h | |||
@@ -30,6 +30,7 @@ | |||
30 | * @pnum: physical eraseblock number | 30 | * @pnum: physical eraseblock number |
31 | * @lnum: logical eraseblock number | 31 | * @lnum: logical eraseblock number |
32 | * @scrub: if this physical eraseblock needs scrubbing | 32 | * @scrub: if this physical eraseblock needs scrubbing |
33 | * @copy_flag: this LEB is a copy (@copy_flag is set in VID header of this LEB) | ||
33 | * @sqnum: sequence number | 34 | * @sqnum: sequence number |
34 | * @u: unions RB-tree or @list links | 35 | * @u: unions RB-tree or @list links |
35 | * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects | 36 | * @u.rb: link in the per-volume RB-tree of &struct ubi_scan_leb objects |
@@ -42,7 +43,8 @@ struct ubi_scan_leb { | |||
42 | int ec; | 43 | int ec; |
43 | int pnum; | 44 | int pnum; |
44 | int lnum; | 45 | int lnum; |
45 | int scrub; | 46 | unsigned int scrub:1; |
47 | unsigned int copy_flag:1; | ||
46 | unsigned long long sqnum; | 48 | unsigned long long sqnum; |
47 | union { | 49 | union { |
48 | struct rb_node rb; | 50 | struct rb_node rb; |
@@ -91,14 +93,13 @@ struct ubi_scan_volume { | |||
91 | * @erase: list of physical eraseblocks which have to be erased | 93 | * @erase: list of physical eraseblocks which have to be erased |
92 | * @alien: list of physical eraseblocks which should not be used by UBI (e.g., | 94 | * @alien: list of physical eraseblocks which should not be used by UBI (e.g., |
93 | * those belonging to "preserve"-compatible internal volumes) | 95 | * those belonging to "preserve"-compatible internal volumes) |
94 | * @used_peb_count: count of used PEBs | ||
95 | * @corr_peb_count: count of PEBs in the @corr list | 96 | * @corr_peb_count: count of PEBs in the @corr list |
96 | * @read_err_count: count of PEBs read with error (%UBI_IO_BAD_HDR_READ was | 97 | * @empty_peb_count: count of PEBs which are presumably empty (contain only |
97 | * returned) | 98 | * 0xFF bytes) |
98 | * @free_peb_count: count of PEBs in the @free list | ||
99 | * @erase_peb_count: count of PEBs in the @erase list | ||
100 | * @alien_peb_count: count of PEBs in the @alien list | 99 | * @alien_peb_count: count of PEBs in the @alien list |
101 | * @bad_peb_count: count of bad physical eraseblocks | 100 | * @bad_peb_count: count of bad physical eraseblocks |
101 | * @maybe_bad_peb_count: count of bad physical eraseblocks which are not marked | ||
102 | * as bad yet, but which look like bad | ||
102 | * @vols_found: number of volumes found during scanning | 103 | * @vols_found: number of volumes found during scanning |
103 | * @highest_vol_id: highest volume ID | 104 | * @highest_vol_id: highest volume ID |
104 | * @is_empty: flag indicating whether the MTD device is empty or not | 105 | * @is_empty: flag indicating whether the MTD device is empty or not |
@@ -119,13 +120,11 @@ struct ubi_scan_info { | |||
119 | struct list_head free; | 120 | struct list_head free; |
120 | struct list_head erase; | 121 | struct list_head erase; |
121 | struct list_head alien; | 122 | struct list_head alien; |
122 | int used_peb_count; | ||
123 | int corr_peb_count; | 123 | int corr_peb_count; |
124 | int read_err_count; | 124 | int empty_peb_count; |
125 | int free_peb_count; | ||
126 | int erase_peb_count; | ||
127 | int alien_peb_count; | 125 | int alien_peb_count; |
128 | int bad_peb_count; | 126 | int bad_peb_count; |
127 | int maybe_bad_peb_count; | ||
129 | int vols_found; | 128 | int vols_found; |
130 | int highest_vol_id; | 129 | int highest_vol_id; |
131 | int is_empty; | 130 | int is_empty; |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 0359e0cce482..0b0149c41fe3 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -85,21 +85,26 @@ | |||
85 | /* | 85 | /* |
86 | * Error codes returned by the I/O sub-system. | 86 | * Error codes returned by the I/O sub-system. |
87 | * | 87 | * |
88 | * UBI_IO_PEB_EMPTY: the physical eraseblock is empty, i.e. it contains only | 88 | * UBI_IO_FF: the read region of flash contains only 0xFFs |
89 | * %0xFF bytes | 89 | * UBI_IO_FF_BITFLIPS: the same as %UBI_IO_FF, but also also there was a data |
90 | * UBI_IO_PEB_FREE: the physical eraseblock is free, i.e. it contains only a | 90 | * integrity error reported by the MTD driver |
91 | * valid erase counter header, and the rest are %0xFF bytes | 91 | * (uncorrectable ECC error in case of NAND) |
92 | * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC) | 92 | * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC) |
93 | * UBI_IO_BAD_HDR_READ: the same as %UBI_IO_BAD_HDR, but also there was a read | 93 | * UBI_IO_BAD_HDR_EBADMSG: the same as %UBI_IO_BAD_HDR, but also there was a |
94 | * error reported by the flash driver | 94 | * data integrity error reported by the MTD driver |
95 | * (uncorrectable ECC error in case of NAND) | ||
95 | * UBI_IO_BITFLIPS: bit-flips were detected and corrected | 96 | * UBI_IO_BITFLIPS: bit-flips were detected and corrected |
97 | * | ||
98 | * Note, it is probably better to have bit-flip and ebadmsg as flags which can | ||
99 | * be or'ed with other error code. But this is a big change because there are | ||
100 | * may callers, so it does not worth the risk of introducing a bug | ||
96 | */ | 101 | */ |
97 | enum { | 102 | enum { |
98 | UBI_IO_PEB_EMPTY = 1, | 103 | UBI_IO_FF = 1, |
99 | UBI_IO_PEB_FREE, | 104 | UBI_IO_FF_BITFLIPS, |
100 | UBI_IO_BAD_HDR, | 105 | UBI_IO_BAD_HDR, |
101 | UBI_IO_BAD_HDR_READ, | 106 | UBI_IO_BAD_HDR_EBADMSG, |
102 | UBI_IO_BITFLIPS | 107 | UBI_IO_BITFLIPS, |
103 | }; | 108 | }; |
104 | 109 | ||
105 | /* | 110 | /* |
@@ -356,6 +361,8 @@ struct ubi_wl_entry; | |||
356 | * @peb_size: physical eraseblock size | 361 | * @peb_size: physical eraseblock size |
357 | * @bad_peb_count: count of bad physical eraseblocks | 362 | * @bad_peb_count: count of bad physical eraseblocks |
358 | * @good_peb_count: count of good physical eraseblocks | 363 | * @good_peb_count: count of good physical eraseblocks |
364 | * @corr_peb_count: count of corrupted physical eraseblocks (preserved and not | ||
365 | * used by UBI) | ||
359 | * @erroneous_peb_count: count of erroneous physical eraseblocks in @erroneous | 366 | * @erroneous_peb_count: count of erroneous physical eraseblocks in @erroneous |
360 | * @max_erroneous: maximum allowed amount of erroneous physical eraseblocks | 367 | * @max_erroneous: maximum allowed amount of erroneous physical eraseblocks |
361 | * @min_io_size: minimal input/output unit size of the underlying MTD device | 368 | * @min_io_size: minimal input/output unit size of the underlying MTD device |
@@ -442,6 +449,7 @@ struct ubi_device { | |||
442 | int peb_size; | 449 | int peb_size; |
443 | int bad_peb_count; | 450 | int bad_peb_count; |
444 | int good_peb_count; | 451 | int good_peb_count; |
452 | int corr_peb_count; | ||
445 | int erroneous_peb_count; | 453 | int erroneous_peb_count; |
446 | int max_erroneous; | 454 | int max_erroneous; |
447 | int min_io_size; | 455 | int min_io_size; |
@@ -506,6 +514,7 @@ int ubi_calc_data_len(const struct ubi_device *ubi, const void *buf, | |||
506 | int length); | 514 | int length); |
507 | int ubi_check_volume(struct ubi_device *ubi, int vol_id); | 515 | int ubi_check_volume(struct ubi_device *ubi, int vol_id); |
508 | void ubi_calculate_reserved(struct ubi_device *ubi); | 516 | void ubi_calculate_reserved(struct ubi_device *ubi); |
517 | int ubi_check_pattern(const void *buf, uint8_t patt, int size); | ||
509 | 518 | ||
510 | /* eba.c */ | 519 | /* eba.c */ |
511 | int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol, | 520 | int ubi_eba_unmap_leb(struct ubi_device *ubi, struct ubi_volume *vol, |
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index e42afab9a9fe..c47620dfc722 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c | |||
@@ -261,6 +261,9 @@ int ubi_create_volume(struct ubi_device *ubi, struct ubi_mkvol_req *req) | |||
261 | /* Reserve physical eraseblocks */ | 261 | /* Reserve physical eraseblocks */ |
262 | if (vol->reserved_pebs > ubi->avail_pebs) { | 262 | if (vol->reserved_pebs > ubi->avail_pebs) { |
263 | dbg_err("not enough PEBs, only %d available", ubi->avail_pebs); | 263 | dbg_err("not enough PEBs, only %d available", ubi->avail_pebs); |
264 | if (ubi->corr_peb_count) | ||
265 | dbg_err("%d PEBs are corrupted and not used", | ||
266 | ubi->corr_peb_count); | ||
264 | err = -ENOSPC; | 267 | err = -ENOSPC; |
265 | goto out_unlock; | 268 | goto out_unlock; |
266 | } | 269 | } |
@@ -527,6 +530,9 @@ int ubi_resize_volume(struct ubi_volume_desc *desc, int reserved_pebs) | |||
527 | if (pebs > ubi->avail_pebs) { | 530 | if (pebs > ubi->avail_pebs) { |
528 | dbg_err("not enough PEBs: requested %d, available %d", | 531 | dbg_err("not enough PEBs: requested %d, available %d", |
529 | pebs, ubi->avail_pebs); | 532 | pebs, ubi->avail_pebs); |
533 | if (ubi->corr_peb_count) | ||
534 | dbg_err("%d PEBs are corrupted and not used", | ||
535 | ubi->corr_peb_count); | ||
530 | spin_unlock(&ubi->volumes_lock); | 536 | spin_unlock(&ubi->volumes_lock); |
531 | err = -ENOSPC; | 537 | err = -ENOSPC; |
532 | goto out_free; | 538 | goto out_free; |
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index 14c10bed94ee..fcdb7f65fe0b 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c | |||
@@ -366,7 +366,7 @@ write_error: | |||
366 | * Probably this physical eraseblock went bad, try to pick | 366 | * Probably this physical eraseblock went bad, try to pick |
367 | * another one. | 367 | * another one. |
368 | */ | 368 | */ |
369 | list_add_tail(&new_seb->u.list, &si->corr); | 369 | list_add(&new_seb->u.list, &si->erase); |
370 | goto retry; | 370 | goto retry; |
371 | } | 371 | } |
372 | kfree(new_seb); | 372 | kfree(new_seb); |
@@ -662,9 +662,13 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si, | |||
662 | ubi->vol_count += 1; | 662 | ubi->vol_count += 1; |
663 | vol->ubi = ubi; | 663 | vol->ubi = ubi; |
664 | 664 | ||
665 | if (reserved_pebs > ubi->avail_pebs) | 665 | if (reserved_pebs > ubi->avail_pebs) { |
666 | ubi_err("not enough PEBs, required %d, available %d", | 666 | ubi_err("not enough PEBs, required %d, available %d", |
667 | reserved_pebs, ubi->avail_pebs); | 667 | reserved_pebs, ubi->avail_pebs); |
668 | if (ubi->corr_peb_count) | ||
669 | ubi_err("%d PEBs are corrupted and not used", | ||
670 | ubi->corr_peb_count); | ||
671 | } | ||
668 | ubi->rsvd_pebs += reserved_pebs; | 672 | ubi->rsvd_pebs += reserved_pebs; |
669 | ubi->avail_pebs -= reserved_pebs; | 673 | ubi->avail_pebs -= reserved_pebs; |
670 | 674 | ||
@@ -837,7 +841,7 @@ int ubi_read_volume_table(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
837 | return PTR_ERR(ubi->vtbl); | 841 | return PTR_ERR(ubi->vtbl); |
838 | } | 842 | } |
839 | 843 | ||
840 | ubi->avail_pebs = ubi->good_peb_count; | 844 | ubi->avail_pebs = ubi->good_peb_count - ubi->corr_peb_count; |
841 | 845 | ||
842 | /* | 846 | /* |
843 | * The layout volume is OK, initialize the corresponding in-RAM data | 847 | * The layout volume is OK, initialize the corresponding in-RAM data |
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 97a435672eaf..655bbbe415d9 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -745,7 +745,7 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, | |||
745 | 745 | ||
746 | err = ubi_io_read_vid_hdr(ubi, e1->pnum, vid_hdr, 0); | 746 | err = ubi_io_read_vid_hdr(ubi, e1->pnum, vid_hdr, 0); |
747 | if (err && err != UBI_IO_BITFLIPS) { | 747 | if (err && err != UBI_IO_BITFLIPS) { |
748 | if (err == UBI_IO_PEB_FREE) { | 748 | if (err == UBI_IO_FF) { |
749 | /* | 749 | /* |
750 | * We are trying to move PEB without a VID header. UBI | 750 | * We are trying to move PEB without a VID header. UBI |
751 | * always write VID headers shortly after the PEB was | 751 | * always write VID headers shortly after the PEB was |
@@ -759,6 +759,16 @@ static int wear_leveling_worker(struct ubi_device *ubi, struct ubi_work *wrk, | |||
759 | dbg_wl("PEB %d has no VID header", e1->pnum); | 759 | dbg_wl("PEB %d has no VID header", e1->pnum); |
760 | protect = 1; | 760 | protect = 1; |
761 | goto out_not_moved; | 761 | goto out_not_moved; |
762 | } else if (err == UBI_IO_FF_BITFLIPS) { | ||
763 | /* | ||
764 | * The same situation as %UBI_IO_FF, but bit-flips were | ||
765 | * detected. It is better to schedule this PEB for | ||
766 | * scrubbing. | ||
767 | */ | ||
768 | dbg_wl("PEB %d has no VID header but has bit-flips", | ||
769 | e1->pnum); | ||
770 | scrubbing = 1; | ||
771 | goto out_not_moved; | ||
762 | } | 772 | } |
763 | 773 | ||
764 | ubi_err("error %d while reading VID header from PEB %d", | 774 | ubi_err("error %d while reading VID header from PEB %d", |
@@ -1468,22 +1478,6 @@ int ubi_wl_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1468 | ubi->lookuptbl[e->pnum] = e; | 1478 | ubi->lookuptbl[e->pnum] = e; |
1469 | } | 1479 | } |
1470 | 1480 | ||
1471 | list_for_each_entry(seb, &si->corr, u.list) { | ||
1472 | cond_resched(); | ||
1473 | |||
1474 | e = kmem_cache_alloc(ubi_wl_entry_slab, GFP_KERNEL); | ||
1475 | if (!e) | ||
1476 | goto out_free; | ||
1477 | |||
1478 | e->pnum = seb->pnum; | ||
1479 | e->ec = seb->ec; | ||
1480 | ubi->lookuptbl[e->pnum] = e; | ||
1481 | if (schedule_erase(ubi, e, 0)) { | ||
1482 | kmem_cache_free(ubi_wl_entry_slab, e); | ||
1483 | goto out_free; | ||
1484 | } | ||
1485 | } | ||
1486 | |||
1487 | ubi_rb_for_each_entry(rb1, sv, &si->volumes, rb) { | 1481 | ubi_rb_for_each_entry(rb1, sv, &si->volumes, rb) { |
1488 | ubi_rb_for_each_entry(rb2, seb, &sv->root, u.rb) { | 1482 | ubi_rb_for_each_entry(rb2, seb, &sv->root, u.rb) { |
1489 | cond_resched(); | 1483 | cond_resched(); |
@@ -1510,6 +1504,9 @@ int ubi_wl_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si) | |||
1510 | if (ubi->avail_pebs < WL_RESERVED_PEBS) { | 1504 | if (ubi->avail_pebs < WL_RESERVED_PEBS) { |
1511 | ubi_err("no enough physical eraseblocks (%d, need %d)", | 1505 | ubi_err("no enough physical eraseblocks (%d, need %d)", |
1512 | ubi->avail_pebs, WL_RESERVED_PEBS); | 1506 | ubi->avail_pebs, WL_RESERVED_PEBS); |
1507 | if (ubi->corr_peb_count) | ||
1508 | ubi_err("%d PEBs are corrupted and not used", | ||
1509 | ubi->corr_peb_count); | ||
1513 | goto out_free; | 1510 | goto out_free; |
1514 | } | 1511 | } |
1515 | ubi->avail_pebs -= WL_RESERVED_PEBS; | 1512 | ubi->avail_pebs -= WL_RESERVED_PEBS; |