u-boot/include/linux
Paul Burton 40462e541d mtd: driver _read() returns max_bitflips; mtd_read() returns -EUCLEAN
Linux modified the MTD driver interface in commit edbc4540 (with the
same name as this commit). The effect is that calls to mtd_read will
not return -EUCLEAN if the number of ECC-corrected bit errors is below
a certain threshold, which defaults to the strength of the ECC. This
allows -EUCLEAN to stop indicating "some bits were corrected" and begin
indicating "a large number of bits were corrected, the data held in
this region of flash may be lost soon". UBI makes use of this and when
-EUCLEAN is returned from mtd_read it will move data to another block
of flash. Without adopting this interface change UBI on U-boot attempts
to move data between blocks every time a single bit is corrected using
the ECC, which is a very common occurance on some devices.

For some devices where bit errors are common enough, UBI can get stuck
constantly moving data around because each block it attempts to use has
a single bit error. This condition is hit when wear_leveling_worker
attempts to move data from one PEB to another in response to an
-EUCLEAN/UBI_IO_BITFLIPS error. When this happens ubi_eba_copy_leb is
called to perform the data copy, and after the data is written it is
read back to check its validity. If that read returns UBI_IO_BITFLIPS
(in response to an MTD -EUCLEAN) then ubi_eba_copy_leb returns 1 to
wear_leveling worker, which then proceeds to schedule the destination
PEB for erasure. This leads to erase_worker running on the PEB, and
following a successful erase wear_leveling_worker is called which
begins this whole cycle all over again. The end result is that (without
UBI debug output enabled) the boot appears to simply hang whilst in
reality U-boot busily works away at destroying a block of the NAND
flash. Debug output from this situation:

  UBI DBG: ensure_wear_leveling: schedule scrubbing
  UBI DBG: wear_leveling_worker: scrub PEB 1027 to PEB 4083
  UBI DBG: ubi_io_read_vid_hdr: read VID header from PEB 1027
  UBI DBG: ubi_io_read: read 4096 bytes from PEB 1027:4096
  UBI DBG: ubi_eba_copy_leb: copy LEB 0:0, PEB 1027 to PEB 4083
  UBI DBG: ubi_eba_copy_leb: read 1040384 bytes of data
  UBI DBG: ubi_io_read: read 1040384 bytes from PEB 1027:8192
  UBI: fixable bit-flip detected at PEB 1027
  UBI DBG: ubi_io_write_vid_hdr: write VID header to PEB 4083
  UBI DBG: ubi_io_write: write 4096 bytes to PEB 4083:4096
  UBI DBG: ubi_io_read_vid_hdr: read VID header from PEB 4083
  UBI DBG: ubi_io_read: read 4096 bytes from PEB 4083:4096
  UBI DBG: ubi_io_write: write 4096 bytes to PEB 4083:8192
  UBI DBG: ubi_io_read: read 4096 bytes from PEB 4083:8192
  UBI: fixable bit-flip detected at PEB 4083
  UBI DBG: schedule_erase: schedule erasure of PEB 4083, EC 55, torture 0
  UBI DBG: erase_worker: erase PEB 4083 EC 55
  UBI DBG: sync_erase: erase PEB 4083, old EC 55
  UBI DBG: do_sync_erase: erase PEB 4083
  UBI DBG: sync_erase: erased PEB 4083, new EC 56
  UBI DBG: ubi_io_write_ec_hdr: write EC header to PEB 4083
  UBI DBG: ubi_io_write: write 4096 bytes to PEB 4083:0
  UBI DBG: ensure_wear_leveling: schedule scrubbing
  UBI DBG: wear_leveling_worker: scrub PEB 1027 to PEB 4083
  ...

This patch adopts the interface change as in Linux commit edbc4540 in
order to avoid such situations. Given that none of the drivers under
drivers/mtd return -EUCLEAN, this should only affect those using
software ECC. I have tested that it works on a board which is
currently out of tree, but which I hope to be able to begin
upstreaming soon.

Signed-off-by: Paul Burton <paul.burton@imgtec.com>
Acked-by: Stefan Roese <sr@denx.de>
2013-10-09 12:52:04 -05:00
..
byteorder include/linux/byteorder: Always defines __fswab64, __swab64p and __swab64s 2012-11-30 07:15:04 -07:00
mtd mtd: driver _read() returns max_bitflips; mtd_read() returns -EUCLEAN 2013-10-09 12:52:04 -05:00
unaligned include/linux/unaligned/generic.h: fix warning: preprocessor token __force redefined 2012-11-04 11:00:34 -07:00
usb usb:gadget:Remove redundant #includes for USB composite gadget and its functions 2013-09-24 17:51:36 +02:00
apm_bios.h Add GPL-2.0+ SPDX-License-Identifier to source files 2013-07-24 09:44:38 -04:00
bch.h nand: Merge BCH code from Linux nand driver 2012-01-26 16:09:02 -06:00
bitops.h Correct ffs/fls regression for PowerPC etc 2009-09-17 22:45:31 +02:00
bitrev.h Add GPL-2.0+ SPDX-License-Identifier to source files 2013-07-24 09:44:38 -04:00
compat.h linux/compat.h: move dev_err, dev_info and dev_dbg from usb driver to compat.h 2013-08-22 16:50:29 +02:00
compiler-gcc.h compiler_gcc: do not redefine __gnu_attributes 2013-09-06 13:09:07 -04:00
compiler-gcc3.h Add missing header for gcc3 2011-10-01 21:56:20 +02:00
compiler-gcc4.h compiler_gcc: do not redefine __gnu_attributes 2013-09-06 13:09:07 -04:00
compiler.h x86: Fix support for booting bzImage 2010-05-06 00:17:01 +02:00
config.h Initial revision 2000-08-21 15:05:47 +00:00
crc7.h lib: add crc7 from Linux 2011-01-18 23:38:08 +01:00
crc32.h Coding style cleanup, update CHANGELOG. 2008-12-16 01:02:17 +01:00
ctype.h Add isblank 2011-10-17 22:25:34 +02:00
edd.h x86: Fix support for booting bzImage 2010-05-06 00:17:01 +02:00
err.h linux/compat.h: rename from linux/mtd/compat.h 2012-04-30 16:54:51 +02:00
ethtool.h add support for Xilinx 1000BASE-X phy (GTX) 2013-06-24 19:11:13 -05:00
fb.h include/linux/fb.h: Add a missing include for 'list.h' 2013-10-07 08:21:13 -04:00
input.h input: Add linux/input.h for key code support 2012-05-15 08:31:39 +02:00
ioctl.h x86: Fix support for booting bzImage 2010-05-06 00:17:01 +02:00
ioport.h x86: Fix support for booting bzImage 2010-05-06 00:17:01 +02:00
kbuild.h Coding Style cleanup 2010-10-27 22:48:30 +02:00
linkage.h Add GPL-2.0+ SPDX-License-Identifier to source files 2013-07-24 09:44:38 -04:00
linux_string.h Make linux kernel string funcs available to tools 2012-12-13 11:46:07 -07:00
list.h Coding style cleanup, update CHANGELOG 2008-09-13 02:23:05 +02:00
lzo.h add lzop decompression support 2009-12-05 01:30:23 +01:00
math64.h UBIFS: Implement read-only UBIFS support in U-Boot 2009-03-20 22:39:15 +01:00
mc146818rtc.h Replace BCD2BIN and BIN2BCD macros with inline functions 2009-08-25 12:57:55 +02:00
mdio.h Minor coding style cleanup. 2011-09-11 21:24:09 +02:00
mii.h add support for Xilinx 1000BASE-X phy (GTX) 2013-06-24 19:11:13 -05:00
netdevice.h Add GPL-2.0+ SPDX-License-Identifier to source files 2013-07-24 09:44:38 -04:00
poison.h update linux/list 2008-08-31 04:24:51 +02:00
posix_types.h Initial revision 2001-04-28 17:59:11 +00:00
rbtree.h Add GPL-2.0+ SPDX-License-Identifier to source files 2013-07-24 09:44:38 -04:00
screen_info.h x86: Fix support for booting bzImage 2010-05-06 00:17:01 +02:00
stat.h nios2: add struct stat support in linux/stat.h 2010-04-02 12:28:40 -04:00
stddef.h include/linux/stddef.h: avoid 'warning: preprocessor token offsetof redefined' 2012-11-04 11:00:34 -07:00
string.h mtd: resync with Linux-3.7.1 2013-05-31 17:12:03 -05:00
stringify.h COMMON: Add __stringify() function 2012-10-15 11:53:47 -07:00
time.h Initial revision 2002-03-08 21:31:05 +00:00
types.h Consolidate bool type 2013-04-01 16:33:52 -04:00