History log of /linux-master/drivers/mtd/ubi/debug.h
Revision Date Author Comments
# 7cd8d1f8 25-Dec-2023 ZhaoLong Wang <wangzhaolong1@huawei.com>

ubi: Add six fault injection type for testing

This commit adds six fault injection type for testing to cover the
abnormal path of the UBI driver.

Inject the following faults when the UBI reads the LEB:
+----------------------------+-----------------------------------+
| Interface name | emulate behavior |
+----------------------------+-----------------------------------+
| emulate_eccerr | ECC error |
+----------------------------+-----------------------------------+
| emulate_read_failure | read failure |
|----------------------------+-----------------------------------+
| emulate_io_ff | read content as all FF |
|----------------------------+-----------------------------------+
| emulate_io_ff_bitflips | content FF with MTD err reported |
+----------------------------+-----------------------------------+
| emulate_bad_hdr | bad leb header |
|----------------------------+-----------------------------------+
| emulate_bad_hdr_ebadmsg | bad header with ECC err |
+----------------------------+-----------------------------------+

Signed-off-by: ZhaoLong Wang <wangzhaolong1@huawei.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>


# e30948f7 25-Dec-2023 ZhaoLong Wang <wangzhaolong1@huawei.com>

ubi: Split io_failures into write_failure and erase_failure

The emulate_io_failures debugfs entry controls both write
failure and erase failure. This patch split io_failures
to write_failure and erase_failure.

Signed-off-by: ZhaoLong Wang <wangzhaolong1@huawei.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>


# 6931fb44 25-Dec-2023 ZhaoLong Wang <wangzhaolong1@huawei.com>

ubi: Use the fault injection framework to enhance the fault injection capability

To make debug parameters configurable at run time, use the
fault injection framework to reconstruct the debugfs interface,
and retain the legacy fault injection interface.

Now, the file emulate_failures and fault_attr files control whether
to enable fault emmulation.

The file emulate_failures receives a mask that controls type and
process of fault injection. Generally, for ease of use, you can
directly enter a mask with all 1s.

echo 0xffff > /sys/kernel/debug/ubi/ubi0/emulate_failures

And you need to configure other fault-injection capabilities for
testing purpose:

echo 100 > /sys/kernel/debug/ubi/fault_inject/emulate_power_cut/probability
echo 15 > /sys/kernel/debug/ubi/fault_inject/emulate_power_cut/space
echo 2 > /sys/kernel/debug/ubi/fault_inject/emulate_power_cut/verbose
echo -1 > /sys/kernel/debug/ubi/fault_inject/emulate_power_cut/times

The CONFIG_MTD_UBI_FAULT_INJECTION to enable the Fault Injection is
added to kconfig.

Signed-off-by: ZhaoLong Wang <wangzhaolong1@huawei.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: Richard Weinberger <richard@nod.at>


# 8032bf12 09-Oct-2022 Jason A. Donenfeld <Jason@zx2c4.com>

treewide: use get_random_u32_below() instead of deprecated function

This is a simple mechanical transformation done by:

@@
expression E;
@@
- prandom_u32_max
+ get_random_u32_below
(E)

Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
Reviewed-by: SeongJae Park <sj@kernel.org> # for damon
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> # for infiniband
Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> # for arm
Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # for mmc
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>


# 81895a65 05-Oct-2022 Jason A. Donenfeld <Jason@zx2c4.com>

treewide: use prandom_u32_max() when possible, part 1

Rather than incurring a division or requesting too many random bytes for
the given range, use the prandom_u32_max() function, which only takes
the minimum required bytes from the RNG and avoids divisions. This was
done mechanically with this coccinelle script:

@basic@
expression E;
type T;
identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
typedef u64;
@@
(
- ((T)get_random_u32() % (E))
+ prandom_u32_max(E)
|
- ((T)get_random_u32() & ((E) - 1))
+ prandom_u32_max(E * XXX_MAKE_SURE_E_IS_POW2)
|
- ((u64)(E) * get_random_u32() >> 32)
+ prandom_u32_max(E)
|
- ((T)get_random_u32() & ~PAGE_MASK)
+ prandom_u32_max(PAGE_SIZE)
)

@multi_line@
identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
identifier RAND;
expression E;
@@

- RAND = get_random_u32();
... when != RAND
- RAND %= (E);
+ RAND = prandom_u32_max(E);

// Find a potential literal
@literal_mask@
expression LITERAL;
type T;
identifier get_random_u32 =~ "get_random_int|prandom_u32|get_random_u32";
position p;
@@

((T)get_random_u32()@p & (LITERAL))

// Add one to the literal.
@script:python add_one@
literal << literal_mask.LITERAL;
RESULT;
@@

value = None
if literal.startswith('0x'):
value = int(literal, 16)
elif literal[0] in '123456789':
value = int(literal, 10)
if value is None:
print("I don't know how to handle %s" % (literal))
cocci.include_match(False)
elif value == 2**32 - 1 or value == 2**31 - 1 or value == 2**24 - 1 or value == 2**16 - 1 or value == 2**8 - 1:
print("Skipping 0x%x for cleanup elsewhere" % (value))
cocci.include_match(False)
elif value & (value + 1) != 0:
print("Skipping 0x%x because it's not a power of two minus one" % (value))
cocci.include_match(False)
elif literal.startswith('0x'):
coccinelle.RESULT = cocci.make_expr("0x%x" % (value + 1))
else:
coccinelle.RESULT = cocci.make_expr("%d" % (value + 1))

// Replace the literal mask with the calculated result.
@plus_one@
expression literal_mask.LITERAL;
position literal_mask.p;
expression add_one.RESULT;
identifier FUNC;
@@

- (FUNC()@p & (LITERAL))
+ prandom_u32_max(RESULT)

@collapse_ret@
type T;
identifier VAR;
expression E;
@@

{
- T VAR;
- VAR = (E);
- return VAR;
+ return E;
}

@drop_var@
type T;
identifier VAR;
@@

{
- T VAR;
... when != VAR
}

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Yury Norov <yury.norov@gmail.com>
Reviewed-by: KP Singh <kpsingh@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz> # for ext4 and sbitmap
Reviewed-by: Christoph Böhmwalder <christoph.boehmwalder@linbit.com> # for drbd
Acked-by: Jakub Kicinski <kuba@kernel.org>
Acked-by: Heiko Carstens <hca@linux.ibm.com> # for s390
Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # for mmc
Acked-by: Darrick J. Wong <djwong@kernel.org> # for xfs
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>


# 1a59d1b8 27-May-2019 Thomas Gleixner <tglx@linutronix.de>

treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156

Based on 1 normalized pattern(s):

this program is free software you can redistribute it and or modify
it under the terms of the gnu general public license as published by
the free software foundation either version 2 of the license or at
your option any later version this program is distributed in the
hope that it will be useful but without any warranty without even
the implied warranty of merchantability or fitness for a particular
purpose see the gnu general public license for more details you
should have received a copy of the gnu general public license along
with this program if not write to the free software foundation inc
59 temple place suite 330 boston ma 02111 1307 usa

extracted by the scancode license scanner the SPDX license identifier

GPL-2.0-or-later

has been chosen to replace the boilerplate/reference in 1334 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Richard Fontana <rfontana@redhat.com>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190527070033.113240726@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 50269067 26-Mar-2015 david.oberhollenzer@sigma-star.at <david.oberhollenzer@sigma-star.at>

UBI: power cut emulation for testing

Emulate random power cuts by switching device to ro after a number of
writes to allow simple power cut testing with nand-sim.

Maximum and minimum number of successful writes before power cut and
what kind of writes (EC header, VID header or none) to interrupt
configurable via debugfs.

Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Signed-off-by: Richard Weinberger <richard@nod.at>


# 479c2c0c 08-Oct-2014 Richard Weinberger <richard@nod.at>

UBI: Fastmap: Add new module parameter fm_debug

If fm_debug is set fastmap debugging is enabled by default.
This is useful if one wants to debug fastmap on an UBI device
with serves the rootfs.
The the UBI attach mechanism runs long before debugfs can be mounted
and chk_fastmap set.

Signed-off-by: Richard Weinberger <richard@nod.at>


# 5fa7fa5d 22-Sep-2014 Richard Weinberger <richard@nod.at>

UBI: Add initial support for fastmap self checks

Using this debugfs knob fastmap self checks can be controlled.

Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Tanya Brokhman <tlinder@codeaurora.org>


# aca662a3 03-Jan-2013 Akinobu Mita <akinobu.mita@gmail.com>

mtd: rename random32() to prandom_u32()

Use more preferable function name which implies using a pseudo-random
number generator.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# eab73772 28-Nov-2012 Ezequiel Garcia <elezegarcia@gmail.com>

UBI: embed ubi_debug_info field in ubi_device struct

ubi_debug_info struct was dynamically allocated which
is always suboptimal, for it tends to fragment memory
and make the code error-prone.
Fix this by embedding it in ubi_device struct.

Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 64575574 28-Nov-2012 Ezequiel Garcia <elezegarcia@gmail.com>

UBI: introduce helpers dbg_chk_{io, gen}

With this patch code is a bit more readable and there's no
generated code or functionality impact.
Furthermore, this abstracts implementation details and
will allow to change ubi_debug_info in a less invasive way.

Signed-off-by: Ezequiel Garcia <elezegarcia@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 719bb840 27-Aug-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: print less

UBI currently prints a lot of information when it mounts a volume, which
bothers some people. Make it less chatty - print only important information
by default.

Get rid of 'dbg_msg()' macro completely.

Reported-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# e28453bb 27-Aug-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: use pr_ helper instead of printk

Use 'pr_err()' instead of 'printk(KERN_ERR', etc.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 183ae6cf 22-Aug-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: print PID in debug messages

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 517af48c 17-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: rename sv to av

After re-naming the 'struct ubi_scan_volume' we should adjust all variables
named 'sv' to something else, because 'sv' stands for "scanning volume".
Let's rename it to 'av' which stands for "attaching volume" which is
a bit more consistent and has the same length, which makes re-naming easy.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>


# 2c5ec5ce 16-May-2012 Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>

UBI: rename seb to aeb

After re-naming the 'struct ubi_scan_leb' we should adjust all variables
named 'seb' to something else, because 'seb' stands for "scanning eraseblock".
Let's rename it to 'aeb' which stands for "attaching eraseblock" which is
a bit more consistend and has the same length.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>


# cb28a932 16-May-2012 Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>

UBI: rename struct ubi_scan_volume

Rename 'struct ubi_scan_volume' to 'struct ubi_ainf_volume'. This is part
of the code re-structuring I am trying to do in order to add fastmap
in a more logical way. Fastmap can share a lot with scanning, including
the attach-time data structures, which all now have "scan" word in the
name. Let's get rid of this word and use "ainf" instead which stands
for "attach information". It has the same length as "scan" so re-naming
is trivial.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>


# 227423d2 16-May-2012 Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>

UBI: rename struct ubi_scan_leb

Rename 'struct ubi_scan_leb' to 'struct ubi_ainf_leb'. This is part
of the code re-structuring I am trying to do in order to add fastmap
in a more logical way. Fastmap can share a lot with scanning, including
the attach-time data structures, which all now have "scan" word in the
name. Let's get rid of this word and use "ainf" instead which stands
for "attach information". It has the same length as "scan" so re-naming
is trivial.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>


# 97d6104b 16-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: rename few functions for consistency

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# e2986827 16-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: get rid of dbg_err

This patch removes the 'dbg_err()' macro and we now use 'ubi_err' instead.
The idea of 'dbg_err()' was to compile out some error message to make the
binary a bit smaller - but I think it was a bad idea.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# aa44d1d3 16-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: remove Kconfig debugging option

This patch kills the UBI debugging Kconfig option completely and makes all the
debugging stuff to be always compiled-in. It was pain in the neck to maintain
this useless option because all users I am aware of have debugging enabled
anyway - how else will you diagnose errors otherwise?

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 718c00bb 16-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: rename ubi_dbg_dump_mkvol_req

I am going to remove the "UBI debugging" compilation option and make the
debugging stuff to be always compiled it. This patch is a preparation
which renames 'ubi_dbg_dump_mkvol_req()' to 'ubi_dump_mkvol_req()'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# b989bd4c 16-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: rename ubi_dbg_dump_seb

I am going to remove the "UBI debugging" compilation option and make the
debugging stuff to be always compiled it. This patch is a preparation
which renames 'ubi_dbg_dump_seb()' to 'ubi_dump_seb()'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 614c74a75 16-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: rename ubi_dbg_dump_sv

I am going to remove the "UBI debugging" compilation option and make the
debugging stuff to be always compiled it. This patch is a preparation
which renames 'ubi_dbg_dump_sv()' to 'ubi_dump_sv()'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 1f021e1d 16-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: rename ubi_dbg_dump_vtbl_record

I am going to remove the "UBI debugging" compilation option and make the
debugging stuff to be always compiled it. This patch is a preparation
which renames 'ubi_dbg_dump_vtbl_record()' to 'ubi_dump_vtbl_record()'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 766381f0 16-May-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: rename ubi_dbg_dump_vol_info

I am going to remove the "UBI debugging" compilation option and make the
debugging stuff to be always compiled it. This patch is a preparation
which renames 'ubi_dbg_dump_vol_info()' to 'ubi_dump_vol_info()'.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# a904e3f1 25-Apr-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: always dump VID and EC headers in case of errors

UBI (and UBIFS) are a bit over-engineered WRT debugging. The idea was to
link as few as possible when debugging is disabled, but the downside is
that most people produce bug reports which are difficult to understand.

Always dump the VID and EC headers' contents in case of errors when it
is helpful.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# ef7088e7 23-Apr-2012 Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>

UBI: always dump flash contents in case of errors

UBI (and UBIFS) are a bit over-engineered WRT debugging. The idea was to
link as few as possible when debugging is disabled, but the downside is
that most people produce bug reports which are difficult to understand.

Always dump the flash contents in case of errors, not only when debugging is
enabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>


# 25886a36 23-Apr-2012 Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>

UBI: always dump the stack on error

UBI (and UBIFS) are a bit over-engineered WRT debugging. The idea was to
link as few as possible when debugging is disabled, but the downside is
that most people produce bug reports which are difficult to understand.

This patch weeds out the 'ubi_dbg_dump_stack()' function and turns it
into 'dump_stack()' - it is always useful to have stack dump in case of
an error.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>


# 72f0d453 10-Jan-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

UBI: fix debugging messages

Patch ab50ff684707031ed4bad2fdd313208ae392e5bb broke UBI debugging messages:
before that commit when UBI debugging was enabled, users saw few useful
debugging messages after attaching an MTD device. However, that patch turned
'dbg_msg()' into 'pr_debug()', so to enable the debugging messages users have
to enable them first via /sys/kernel/debug/dynamic_debug/control, which is
very impractical.

This commit makes 'dbg_msg()' to use 'printk()' instead of 'pr_debug()', just
as it was before the breakage.

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Cc: stable@kernel.org [3.0+]


# 9efabc84 19-Aug-2011 Artem Bityutskiy <artem.bityutskiy@intel.com>

UBI: do not link debug messages when debugging is disabled

Michal Marek spotted the same issue in UBIFS and this patch fixes UBI,
see "UBIFS: not build debug messages with CONFIG_UBIFS_FS_DEBUG disabled"

When UBI debugging is disabled, we have debugging messages defined as:

if (0)
pr_debug()

But pr_debug macro defines data structures with debugging data and makes
the linux binary larger, even though we have "if (0)".

Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>


# cd6d8567 18-May-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: switch debugging tests knobs to debugfs

Kill the UBI 'debug_tsts' module parameter and switch to debugfs. Create
per-test mode files there. E.g., to enable bit-flips emulation you may just do:

echo 1 > /sys/kernel/debug/ubi/ubi0/tst_emulate_bitflips

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 18073733 18-May-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: make it possible to use struct ubi_device in debug.h

Current layout does not allow us to add inline functions to debug.h which use
the 'struct ubi_device' object, because it is undefined there. Move
'#include "debug.h"' in "ubi.h" down so to make 'struct ubi_device" be defined.
Additionally, this makes it possible to remove a bunch of forward declarations
in "debug.h". This is a preparation to the next patch.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 27a0f2a3 18-May-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: prepare debugging stuff to further debugfs conversion

We'll need the 'struct ubi_device *ubi' pointer in every debugging function (to
access the ->dbg field), so add this pointer to all the functions implementing
UBI debugging test modes like 'ubi_dbg_is_bitflip()' etc.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 2a734bb8 18-May-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: use debugfs for the extra checks knobs

This patch introduces debugfs support to UBI. All the UBI stuff is kept in the
"ubi" debugfs directory, which contains per-UBI device "ubi/ubiX"
sub-directories, containing debugging files. This file also creates
"ubi/ubiX/chk_gen" and "ubi/ubiX/chk_io" knobs for switching general and I/O
extra checks on and off. And it removes the 'debug_chks' UBI module parameters.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# ab50ff68 17-May-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: switch to dynamic printks

Remove custom dynamic prints and the module parameter to toggle them and use
the generic kernel dynamic printk infrastructure.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# ebfce01a 17-May-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: turn some macros into static inline

Similarly as we have done for UBIFS in
1dcffad74183bb00e8129ba1c5bb2c9931d31bd7, turn the debugging macros into static
inline functions, for the same reasons: to avoid gcc 4.5 warnings.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 3802243a 16-May-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: improve checking in debugging prints

When debugging is disabled, define debugging prints as if (0) printk() to make
sure that the compiler still the format string in debugging messages even if
debugging is disabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 28237e45 15-Mar-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: make tests modes dynamic

Similarly to the debugging checks and message, make the test modes
be dynamically selected via the "debug_tsts" module parameter or
via the "/sys/module/ubi/parameters/debug_tsts" sysfs file. This
is consistent with UBIFS as well.

And now, since all the Kconfig knobs became dynamic, we can remove
the Kconfig.debug file completely.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 92d124f5 14-Mar-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: make self-checks dynamic

This patch adds a possibility to dynamically switch UBI self-checks
on and off, instead of toggling them compile-time from the configuration
menu. This is much more flexible, and consistent with UBIFS, and this
also simplifies UBI Kconfig menu and the code.

This patch introduces two levels of self-checks - general, which
includes all self-checks which are relatively fast, and I/O, which
includes write-verify checks and erase-verify checks, which are
relatively slow and involve flash I/O.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# b342efd4 11-Mar-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: make debugging messages dynamic

This patch adds a possibility to dynamically select UBI debugging
messages, instead of selecting them compile-time from the configuration
menu. This is much more flexible, and consistent with UBIFS, and this
also simplifies UBI Kconfig menu and the code.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 6f9fdf62 11-Mar-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: remove UBI_IO_DEBUG macro

This additional little macro is used to print a bit more messages
while scanning the media. However, we have the 'dbg_bld()' macro
for this, so we better us 'dbg_bld()' and kill UBI_IO_DEBUG. This
simplifies the code a tiny bit.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 31532494 03-Sep-2010 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: introduce debugging helper function

Introduce a helper function to print hexdump: 'ubi_dbg_print_hex_dump()'.
It is compiled out if debugging is enabled. Will be used in the next patch.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 6e9065d7 25-Jan-2010 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: add write checking

Add an extra debugging check function which validates writes.
After every write it reads the data back, compares it with the
original data, and complains if they mismatch.

Useful for debugging. No-op if extra debugging checks are disabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 867996b1 24-Jul-2009 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: introduce flash dump helper

Useful for debugging problems, compiled in only if UBI debugging
is enabled. This patch also makes the UBI writing function dump
the flash if it fails to write.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 1398788f 29-Jun-2009 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: remove bogus debugging checks

The 'paranoid_check_empty()' is bogus because, which is easilly
seen on NOR flash, which has long erase cycles, and which may
easilly end-up with half-erased eraseblocks. In this case the
paranoid check fails. I is just wrong to assume that PEBs which
do not have EC headers always contain all 0xFF. Such assumption
should not be made on the I/O level, which is quite low.

Thus, just kill the check.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 40a71a87 28-Jun-2009 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: add empty eraseblocks verification

This patch adds code which makes sure eraseblocks contain all 0xFF
bytes before starting using them. The verification is done only when
debugging checks are enabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# f2863c54 27-Dec-2008 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: fix checkpatch.pl warnings

Just minor indentation and "over 80 characters" fixes.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# c8566350 16-Jul-2008 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: fix and re-work debugging stuff

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 85c6e6e2 16-Jul-2008 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: amend commentaries

Hch asked not to use "unit" for sub-systems, let it be so.
Also some other commentaries modifications.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# cb53b3b9 18-Apr-2008 Harvey Harrison <harvey.harrison@gmail.com>

[MTD] replace remaining __FUNCTION__ occurrences

__FUNCTION__ is gcc-specific, use __func__

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# a4f0fcdf 12-Feb-2008 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: be verbose when debuggin is enabled

Make I/O function to be always verbose when about CRC errors
and magic number errors when I/O debugging is enabled.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# d19bafd9 17-Dec-2007 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: add PID to debugging prints

Also, use single dbg_msg() macro for all prints.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# ef6075fb 07-Aug-2007 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: use linux print_hex_dump(), not home-grown one

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 94784d91 17-Jun-2007 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

UBI: bugfix in error path

When volume creation fails, we have to set ubi->volumes[vol_id]
back to NULL.

This patch also tweaks some debugging stuff.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 801c135c 26-Jun-2006 Artem B. Bityutskiy <dedekind@linutronix.de>

UBI: Unsorted Block Images

UBI (Latin: "where?") manages multiple logical volumes on a single
flash device, specifically supporting NAND flash devices. UBI provides
a flexible partitioning concept which still allows for wear-levelling
across the whole flash device.

In a sense, UBI may be compared to the Logical Volume Manager
(LVM). Whereas LVM maps logical sector numbers to physical HDD sector
numbers, UBI maps logical eraseblocks to physical eraseblocks.

More information may be found at
http://www.linux-mtd.infradead.org/doc/ubi.html

Partitioning/Re-partitioning

An UBI volume occupies a certain number of erase blocks. This is
limited by a configured maximum volume size, which could also be
viewed as the partition size. Each individual UBI volume's size can
be changed independently of the other UBI volumes, provided that the
sum of all volume sizes doesn't exceed a certain limit.

UBI supports dynamic volumes and static volumes. Static volumes are
read-only and their contents are protected by CRC check sums.

Bad eraseblocks handling

UBI transparently handles bad eraseblocks. When a physical
eraseblock becomes bad, it is substituted by a good physical
eraseblock, and the user does not even notice this.

Scrubbing

On a NAND flash bit flips can occur on any write operation,
sometimes also on read. If bit flips persist on the device, at first
they can still be corrected by ECC, but once they accumulate,
correction will become impossible. Thus it is best to actively scrub
the affected eraseblock, by first copying it to a free eraseblock
and then erasing the original. The UBI layer performs this type of
scrubbing under the covers, transparently to the UBI volume users.

Erase Counts

UBI maintains an erase count header per eraseblock. This frees
higher-level layers (like file systems) from doing this and allows
for centralized erase count management instead. The erase counts are
used by the wear-levelling algorithm in the UBI layer. The algorithm
itself is exchangeable.

Booting from NAND

For booting directly from NAND flash the hardware must at least be
capable of fetching and executing a small portion of the NAND
flash. Some NAND flash controllers have this kind of support. They
usually limit the window to a few kilobytes in erase block 0. This
"initial program loader" (IPL) must then contain sufficient logic to
load and execute the next boot phase.

Due to bad eraseblocks, which may be randomly scattered over the
flash device, it is problematic to store the "secondary program
loader" (SPL) statically. Also, due to bit-flips it may become
corrupted over time. UBI allows to solve this problem gracefully by
storing the SPL in a small static UBI volume.

UBI volumes vs. static partitions

UBI volumes are still very similar to static MTD partitions:

* both consist of eraseblocks (logical eraseblocks in case of UBI
volumes, and physical eraseblocks in case of static partitions;
* both support three basic operations - read, write, erase.

But UBI volumes have the following advantages over traditional
static MTD partitions:

* there are no eraseblock wear-leveling constraints in case of UBI
volumes, so the user should not care about this;
* there are no bit-flips and bad eraseblocks in case of UBI volumes.

So, UBI volumes may be considered as flash devices with relaxed
restrictions.

Where can it be found?

Documentation, kernel code and applications can be found in the MTD
gits.

What are the applications for?

The applications help to create binary flash images for two purposes: pfi
files (partial flash images) for in-system update of UBI volumes, and plain
binary images, with or without OOB data in case of NAND, for a manufacturing
step. Furthermore some tools are/and will be created that allow flash content
analysis after a system has crashed..

Who did UBI?

The original ideas, where UBI is based on, were developed by Andreas
Arnez, Frank Haverkamp and Thomas Gleixner. Josh W. Boyer and some others
were involved too. The implementation of the kernel layer was done by Artem
B. Bityutskiy. The user-space applications and tools were written by Oliver
Lohmann with contributions from Frank Haverkamp, Andreas Arnez, and Artem.
Joern Engel contributed a patch which modifies JFFS2 so that it can be run on
a UBI volume. Thomas Gleixner did modifications to the NAND layer. Alexander
Schmidt made some testing work as well as core functionality improvements.

Signed-off-by: Artem B. Bityutskiy <dedekind@linutronix.de>
Signed-off-by: Frank Haverkamp <haver@vnet.ibm.com>