History log of /linux-master/drivers/mtd/mtdpart.c
Revision Date Author Comments
# 5c2f7727 27-Sep-2023 Rafał Miłecki <rafal@milecki.pl>

mtd: mtdpart: check for subpartitions parsing result

parse_mtd_partitions() may return an error so it should be checked and
optionally passed up

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20230927202657.27169-1-zajec5@gmail.com


# 19bfa9eb 20-Jun-2023 Tomas Winkler <tomas.winkler@intel.com>

mtd: use refcount to prevent corruption

When underlying device is removed mtd core will crash
in case user space is holding open handle.
Need to use proper refcounting so device is release
only when has no users.

Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20230620131905.648089-2-alexander.usyskin@intel.com


# 6db02fdf 03-Jun-2023 Christophe JAILLET <christophe.jaillet@wanadoo.fr>

mtd: mtdpart: Drop useless LIST_HEAD

'tmp_list' is unused, so drop it.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/547248195d87d1240d6126d13eb1364b1a0b634d.1685853690.git.christophe.jaillet@wanadoo.fr


# fb42378d 06-Feb-2023 Saravana Kannan <saravanak@google.com>

mtd: mtdpart: Don't create platform device that'll never probe

These "nvmem-cells" platform devices never get probed because there's no
platform driver for it and it's never used anywhere else. So it's a
waste of memory. These devices also cause fw_devlink to block nvmem
consumers of "nvmem-cells" partition from probing because the supplier
device never probes.

So stop creating platform devices for nvmem-cells partitions to avoid
wasting memory and to avoid blocking probing of consumers.

Reported-by: Maxim Kiselev <bigunclemax@gmail.com>
Fixes: bcdf0315a61a ("mtd: call of_platform_populate() for MTD partitions")
Signed-off-by: Saravana Kannan <saravanak@google.com>
Tested-by: Maksim Kiselev <bigunclemax@gmail.com>
Tested-by: Douglas Anderson <dianders@chromium.org>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Tested-by: Luca Weiss <luca.weiss@fairphone.com> # qcom/sm7225-fairphone-fp4
Link: https://lore.kernel.org/r/20230207014207.1678715-13-saravanak@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# bcdf0315 10-May-2022 Rafał Miłecki <rafal@milecki.pl>

mtd: call of_platform_populate() for MTD partitions

Until this change MTD subsystem supported handling partitions only with
MTD partitions parsers. That's a specific / limited API designed around
partitions.

Some MTD partitions may however require different handling. They may
contain specific data that needs to be parsed and somehow extracted. For
that purpose MTD subsystem should allow binding of standard platform
drivers.

An example can be U-Boot (sub)partition with environment variables.
There exist a "u-boot,env" DT binding for MTD (sub)partition that
requires an NVMEM driver.

Ref: 5db1c2dbc04c ("dt-bindings: nvmem: add U-Boot environment variables binding")
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220510131259.555-1-zajec5@gmail.com


# 2966daf7 02-Nov-2021 Andreas Oetken <ennoerlangen@gmail.com>

mtd: Fixed breaking list in __mtd_del_partition.

Not the child partition should be removed from the partition list
but the partition itself. Otherwise the partition list gets broken
and any subsequent remove operations leads to a kernel panic.

Fixes: 46b5889cc2c5 ("mtd: implement proper partition handling")
Signed-off-by: Andreas Oetken <andreas.oetken@siemens-energy.com>
Cc: stable@vger.kernel.org
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20211102172604.2921065-1-andreas.oetken@siemens-energy.com


# 97f41002 03-Jun-2021 Zhen Lei <thunder.leizhen@huawei.com>

mtd: mtdpart: use DEVICE_ATTR_RO() helper macro

Use DEVICE_ATTR_RO() helper macro instead of plain DEVICE_ATTR(), which
makes the code a bit shorter and easier to read.

Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210603123041.12036-1-thunder.leizhen@huawei.com


# ce675043 12-Apr-2021 Tian Tao <tiantao6@hisilicon.com>

mtd: mtdpart: Convert sysfs sprintf/snprintf family to sysfs_emit

Use sysfs_emit instead of snprintf to avoid buf overrun,because in
sysfs_emit it strictly checks whether buf is null or buf whether
pagesize aligned, otherwise it returns an error.

Signed-off-by: Tian Tao <tiantao6@hisilicon.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/1618220144-33839-3-git-send-email-tiantao6@hisilicon.com


# cb454305 17-Feb-2021 David Bauer <mail@david-bauer.net>

mtd: don't lock when recursively deleting partitions

When recursively deleting partitions, don't acquire the masters
partition lock twice. Otherwise the process ends up in a deadlocked
state.

Fixes: 46b5889cc2c5 ("mtd: implement proper partition handling")
Signed-off-by: David Bauer <mail@david-bauer.net>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20210217195320.893253-1-mail@david-bauer.net


# 620747ee 09-Nov-2020 Lee Jones <lee.jones@linaro.org>

mtd: mtdpart: Fix misdocumented function parameter 'mtd'

Fixes the following W=1 kernel build warning(s):

drivers/mtd/mtdpart.c:300: warning: Function parameter or member 'mtd' not described in '__mtd_del_partition'
drivers/mtd/mtdpart.c:300: warning: Excess function parameter 'priv' description in '__mtd_del_partition'

Cc: Miquel Raynal <miquel.raynal@bootlin.com>
Cc: Richard Weinberger <richard@nod.at>
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Nicolas Pitre <nico@fluxnic.net>
Cc: Thomas Gleixner <gleixner@linutronix.de>
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-mtd@lists.infradead.org
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20201109182206.3037326-2-lee.jones@linaro.org


# 9e3307a1 03-May-2020 Boris Brezillon <bbrezillon@kernel.org>

mtd: Add support for emulated SLC mode on MLC NANDs

MLC NANDs can be made a bit more reliable if we only program the lower
page of each pair. At least, this solves the paired-pages corruption
issue.

Signed-off-by: Boris Brezillon <bbrezillon@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20200503155341.16712-5-miquel.raynal@bootlin.com


# 46b5889c 14-Jan-2020 Miquel Raynal <miquel.raynal@bootlin.com>

mtd: implement proper partition handling

Instead of collecting partitions in a flat list, create a hierarchy
within the mtd_info structure: use a partitions list to keep track of
the partitions of an MTD device (which might be itself a partition of
another MTD device), a pointer to the parent device (NULL when the MTD
device is the root one, not a partition).

By also saving directly in mtd_info the offset of the partition, we
can get rid of the mtd_part structure.

While at it, be consistent in the naming of the mtd_info structures to
ease the understanding of the new hierarchy: these structures are
usually called 'mtd', unless there are multiple instances of the same
structure. In this case, there is usually a parent/child bound so we
will call them 'parent' and 'child'.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20200114090952.11232-1-miquel.raynal@bootlin.com


# fd534e9b 23-May-2019 Thomas Gleixner <tglx@linutronix.de>

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

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
51 franklin st fifth floor boston ma 02110 1301 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 50 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
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/20190523091649.499889647@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 3008ba87 31-Jan-2019 Colin Ian King <colin.king@canonical.com>

mtd: part: fix incorrect format specifier for an unsigned long long

An unsigned long long is being formatted with %lld instead of the unsigned
version %llu. Fix this.

Clean up cppcheck warning:
%lld in format string (no. 1) requires 'long long' but the argument type
is 'unsigned long long'.

Fixes: a62c24d75529 ("mtd: part: Add sysfs variable for offset of partition")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Richard Weinberger <richard@nod.at>


# ad463515 29-Jan-2019 Boris Brezillon <bbrezillon@kernel.org>

mtd: Make sure mtd->erasesize is valid even if the partition is of size 0

Commit 33f45c44d68b ("mtd: Do not allow MTD devices with inconsistent
erase properties") introduced a check to make sure ->erasesize and
->_erase values are consistent with the MTD_NO_ERASE flag.
This patch did not take the 0 bytes partition case into account which
can happen when the defined partition is outside the flash device memory
range. Fix that by setting the partition erasesize to the parent
erasesize.

Fixes: 33f45c44d68b ("mtd: Do not allow MTD devices with inconsistent erase properties")
Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: <stable@vger.kernel.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Boris Brezillon <bbrezillon@kernel.org>
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>


# bda2ab56 30-Jan-2019 Boris Brezillon <bbrezillon@kernel.org>

mtd: Remove a debug trace in mtdpart.c

Commit 2b6f0090a333 ("mtd: Check add_mtd_device() ret code") contained
a leftover of the debug session that led to this bug fix. Remove this
pr_info().

Fixes: 2b6f0090a333 ("mtd: Check add_mtd_device() ret code")
Signed-off-by: Boris Brezillon <bbrezillon@kernel.org>


# 2b6f0090 02-Jan-2019 Boris Brezillon <bbrezillon@kernel.org>

mtd: Check add_mtd_device() ret code

add_mtd_device() can fail. We should always check its return value
and gracefully handle the failure case. Fix the call sites where this
not done (in mtdpart.c) and add a __must_check attribute to the
prototype to avoid this kind of mistakes.

Signed-off-by: Boris Brezillon <bbrezillon@kernel.org>


# 6750f61a 20-Nov-2018 Rafał Miłecki <rafal@milecki.pl>

mtd: improve calculating partition boundaries when checking for alignment

When checking for alignment mtd should check absolute offsets. It's
important for subpartitions as it doesn't make sense to check their
relative addresses.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>


# 1186af45 20-Nov-2018 Rafał Miłecki <rafal@milecki.pl>

mtd: keep original flags for every struct mtd_info

When allocating a new partition mtd subsystem runs internal tests in the
allocate_partition(). They may result in modifying specified flags (e.g.
dropping some /features/ like write access).

Those constraints don't have to be necessary true for subpartitions. It
may happen parent partition isn't block aligned (effectively disabling
write access) while subpartition may fit blocks nicely. In such case all
checks should be run again (starting with original flags value).

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>


# 85516a98 07-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

mtd: partitions: fix unbalanced of_node_get/put()

While at first mtd_part_of_parse() would just call
of_get_chil_by_name(), it has been patched to deal with sub-partitions
and will now directly manipulate the node returned by mtd_get_of_node()
if the MTD device is a partition.

A of_node_put() was a bit below in the code, to balance the
of_get_child_by_name(). However, despite its name, mtd_get_of_node()
does not take a reference on the OF node. It is a simple helper hiding
some pointer logic to retrieve the OF node related to an MTD
device.

The direct effect of such unbalanced reference counting is visible by
rmmod'ing any module that would have added MTD partitions:

OF: ERROR: Bad of_node_put() on <of_path_to_partition>

As it seems normal to get a reference on the OF node during the
of_property_for_each_string() that follows, add a call to
of_node_get() when relevant.

Fixes: 76a832254ab0 ("mtd: partitions: use DT info for parsing partitions with "compatible" prop")
Cc: stable@vger.kernel.org
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>


# 76a83225 13-Jul-2018 Rafał Miłecki <rafal@milecki.pl>

mtd: partitions: use DT info for parsing partitions with "compatible" prop

So far only flash devices could be described in DT regarding partitions
parsing. That could be done with "partitions" subnode and a proper
"compatible" string.

Some devices may use hierarchical (multi-level) layouts and may mix used
layouts (fixed and dynamic). Describing that in DT is done by specifying
"compatible" for DT-represented partition plus optionally more
properties and/or subnodes.

To support such layouts each DT partition has to be checked for
additional description.

Please note this implementation will work in parallel with support for
partition type specified for non-DT setups. That already works since
commit 1a0915be1926 ("mtd: partitions: add support for partition
parsers").

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>


# 5ac67ce3 27-Mar-2018 Rafał Miłecki <rafal@milecki.pl>

mtd: move code adding (registering) partitions to the parse_mtd_partitions()

This commit slightly simplifies the code. Every parse_mtd_partitions()
caller (out of two existing ones) had to add partitions & cleanup parser
on its own. This moves that responsibility into the function.

That change also allows dropping struct mtd_partitions argument.

There is one minor behavior change caused by this cleanup. If
parse_mtd_partitions() fails to add partitions (add_mtd_partitions()
return an error) then mtd_device_parse_register() will still try to
add (register) fallback partitions. It's a real corner case affecting
one of uncommon error paths and shouldn't cause any harm.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>


# c0faf434 14-Mar-2018 Rafał Miłecki <rafal@milecki.pl>

mtd: rename "ofpart" parser to "fixed-partitions" as it fits it better

Type "ofpart" means that OF should be used to get partitioning info and
this driver supports "fixed-partitions" binding only. Renaming it should
lead to less confusion especially when parsers for new compatibility
strings start to appear.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Reviewed-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>


# 5b644aa0 14-Mar-2018 Rafał Miłecki <rafal@milecki.pl>

mtd: partitions: add of_match_table parser matching for the "ofpart" type

In order to properly support compatibility strings as described in the
bindings/mtd/partition.txt "ofpart" type should be treated as an
indication for looking into OF. MTD should check "compatible" property
and search for a matching parser rather than blindly trying the one
supporting "fixed-partitions".

It also means that existing "fixed-partitions" parser should get renamed
to use a more meaningful name.

This commit achievies that aim by introducing a new mtd_part_of_parse().
It works by looking for a matching parser for every string in the
"compatibility" property (starting with the most specific one).

Please note that driver-specified parsers still take a precedence. It's
assumed that driver providing a parser type has a good reason for that
(e.g. having platform data with device-specific info). Also doing
otherwise could break existing setups. The same applies to using default
parsers (including "cmdlinepart") as some overwrite DT data with cmdline
argument.

Partition parsers can now provide an of_match_table to enable
flash<-->parser matching via device tree as documented in the
mtd/partition.txt.

This support is currently limited to built-in parsers as it uses
request_module() and friends. This should be sufficient for most cases
though as compiling parsers as modules isn't a common choice.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Tested-by: Peter Rosin <peda@axentia.se>
Reviewed-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>


# e7bfb3fd 12-Feb-2018 Boris Brezillon <bbrezillon@kernel.org>

mtd: Stop updating erase_info->state and calling mtd_erase_callback()

MTD users are no longer checking erase_info->state to determine if the
erase operation failed or succeeded. Moreover, mtd_erase_callback() is
now a NOP.

We can safely get rid of all mtd_erase_callback() calls and all
erase_info->state assignments. While at it, get rid of the
erase_info->state field, all MTD_ERASE_XXX definitions and the
mtd_erase_callback() function.

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Reviewed-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
Acked-by: Bert Kenward <bkenward@solarflare.com>
---
Changes in v2:
- Address a few coding style issues (reported by Miquel)
- Remove comments that are no longer valid (reported by Miquel)


# 8f347c42 12-Feb-2018 Boris Brezillon <bbrezillon@kernel.org>

mtd: Unconditionally update ->fail_addr and ->addr in part_erase()

->fail_addr and ->addr can be updated no matter the result of
parent->_erase(), we just need to remove the code doing the same thing
in mtd_erase_callback() to avoid adjusting those fields twice.

Note that this can be done because all MTD users have been converted to
not pass an erase_info->callback() and are thus only taking the
->addr_fail and ->addr fields into account after part_erase() has
returned.

While we're at it, get rid of the erase_info->mtd field which was only
needed to let mtd_erase_callback() get the partition device back.

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Reviewed-by: Richard Weinberger <richard@nod.at>


# 884cfd90 12-Feb-2018 Boris Brezillon <bbrezillon@kernel.org>

mtd: Stop assuming mtd_erase() is asynchronous

None of the mtd->_erase() implementations work in an asynchronous manner,
so let's simplify MTD users that call mtd_erase(). All they need to do
is check the value returned by mtd_erase() and assume that != 0 means
failure.

Signed-off-by: Boris Brezillon <boris.brezillon@bootlin.com>
Reviewed-by: Richard Weinberger <richard@nod.at>


# 0aede42e 09-Jan-2018 Boris Brezillon <bbrezillon@kernel.org>

mtd: Remove duplicate checks on mtd_oob_ops parameter

Some of the check done in custom ->_read/write_oob() implementation are
already done by the core (in mtd_check_oob_ops()).

Suggested-by: Peter Pan <peterpansjtu@gmail.com>
[Remove redundant checks done in mtdpart.c]
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Ladislav Michl <ladis@linux-mips.org>


# 24ff1292 09-Jan-2018 Boris Brezillon <bbrezillon@kernel.org>

mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing

Some MTD sublayers/drivers are implementing ->_read/write_oob() and
provide dummy wrappers for their ->_read/write() implementations.
Let the core handle this case instead of duplicating the logic.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Miquel Raynal <miquel.raynal@free-electrons.com>
Tested-by: Ladislav Michl <ladis@linux-mips.org>


# d020fc8e 09-Jan-2018 Boris Brezillon <bbrezillon@kernel.org>

mtd: mtdpart: Make ECC stat handling consistent

part_read() and part_read_oob() were counting ECC failures and
bitflips differently. Adjust part_read_oob() to mimic what is done in
part_read(). This is needed to use ->_read_oob() as a fallback when
when ->_read() is not implemented.

Note that bitflips and ECC failure accounting on MTD partitions is
broken by design, because nothing prevents concurrent accesses to the
underlying master MTD device between the moment we save the stats in a
local variable and the moment master->_read[_oob]() returns. It's not
something that can easily be fixed, so leave it like that for now.

Suggested-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Ladislav Michl <ladis@linux-mips.org>


# 9a594108 07-Nov-2017 Nicolas Pitre <nico@fluxnic.net>

mtd: remove the get_unmapped_area method

It is now unused.

Signed-off-by: Nicolas Pitre <nico@linaro.org>
Reviewed-by: Richard Weinberger <richard@nod.at>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Chris Brandt <chris.brandt@renesas.com>
Signed-off-by: Richard Weinberger <richard@nod.at>


# 7e439681 25-Sep-2017 Boris Brezillon <bbrezillon@kernel.org>

mtd: Fix partition alignment check on multi-erasesize devices

Commit 1eeef2d7483a ("mtd: handle partitioning on devices with 0
erasesize") introduced a regression on heterogeneous erase region
devices. Alignment of the partition was tested against the master
eraseblock size which can be bigger than the slave one, thus leading
to some partitions being marked as read-only.

Update wr_alignment to match this slave erasesize after this erasesize
has been determined by picking the biggest erasesize of all the regions
embedded in the MTD partition.

Reported-by: Mathias Thore <Mathias.Thore@infinera.com>
Fixes: 1eeef2d7483a ("mtd: handle partitioning on devices with 0 erasesize")
Cc: <stable@vger.kernel.org>
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Tested-by: Mathias Thore <Mathias.Thore@infinera.com>
Reviewed-by: Mathias Thore <Mathias.Thore@infinera.com>


# c169e3d3 22-Jun-2017 Brian Norris <computersforpeace@gmail.com>

mtd: partitions: fixup some allocate_partition() whitespace

Some recent patches caused churn around this area, and checkpatch
noticed the existing issues.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 1a0915be 21-Jun-2017 Rafał Miłecki <rafal@milecki.pl>

mtd: partitions: add support for partition parsers

Some devices have partitions that are kind of containers with extra
subpartitions / volumes instead of e.g. a simple filesystem data. To
support such cases we need to first create normal flash device
partitions and then take care of these special ones.

It's very common case for home routers. Depending on the vendor there
are formats like TRX, Seama, TP-Link, WRGG & more. All of them are used
to embed few partitions into a single one / single firmware file.

Ideally all vendors would use some well documented / standardized format
like UBI (and some probably start doing so), but there are still
countless devices on the market using these poor vendor specific
formats.

This patch extends MTD subsystem by allowing to specify list of parsers
that should be tried for a given partition. Supporting such poor formats
is highly unlikely to be the top priority so these changes try to
minimize maintenance cost to the minimum. It reuses existing code for
these new parsers and just adds a one property and one new function.

This implementation requires setting partition parsers in a flash
parser. A proper change of bcm47xxpart will follow and in the future we
will hopefully also find a solution for doing it with ofpart
("fixed-partitions").

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 97519dc5 21-Jun-2017 Rafał Miłecki <rafal@milecki.pl>

mtd: partitions: add support for subpartitions

Some flash device partitions can be containers with extra subpartitions
(volumes). All callbacks are already capable of this additional level of
indirection.

This patch makes sure we always display subpartitions using a tree
structure and takes care of deleting subpartitions when parent gets
removed.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 0a9d72b6 21-Jun-2017 Rafał Miłecki <rafal@milecki.pl>

mtd: partitions: rename "master" to the "parent" where appropriate

This prepares mtd subsystem for the new feature: subpartitions. In some
cases flash device partition can be a container with extra subpartitions
(volumes).

So far there was a flat structure implemented. One master (flash device)
could be partitioned into few partitions. Every partition got its master
and it was enough to get things running.

To support subpartitions we need to store pointer to the parent for each
partition. This is required to implement more natural tree structure and
handle all recursion and offsets calculation.

To make code consistent this patch renamed "master" to the "parent" in
places where we can be dealing with subpartitions.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# c5ceaba7 21-Jun-2017 Rafał Miłecki <rafal@milecki.pl>

mtd: partitions: remove sysfs files when deleting all master's partitions

When support for sysfs "offset" file was added it missed to update the
del_mtd_partitions function. It deletes partitions just like
mtd_del_partition does so both should also take care of removing sysfs
files.

This change moves sysfs_remove_files call to the shared function to fix
this issue.

Fixes: a62c24d755291 ("mtd: part: Add sysfs variable for offset of partition")
Cc: Dan Ehrenberg <dehrenberg@chromium.org>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 08263a9a 21-Jun-2017 Rafał Miłecki <rafal@milecki.pl>

mtd: partitions: add helper for deleting partition

There are two similar functions handling deletion. One handles single
partition and another the whole MTD flash device. They share (duplicate)
some code so it makes sense to add a small helper for that part.

Function del_mtd_partitions has been moved a bit to keep all deleting
stuff together.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 01f9c724 22-May-2017 Brian Norris <computersforpeace@gmail.com>

mtd: partitions: factor out code calling parser

This code is going to be reused for parsers matched using OF so let's
factor it out to make this easier.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: Brian Norris <computersforpeace@gmail.com>


# 1eeef2d7 08-Jun-2017 Chris Packham <chris.packham@alliedtelesis.co.nz>

mtd: handle partitioning on devices with 0 erasesize

erasesize is meaningful for flash devices but for SRAM there is no
concept of an erase block so erasesize is set to 0. When partitioning
these devices instead of ensuring partitions fall on erasesize
boundaries we ensure they fall on writesize boundaries.

Helped-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 42e9401b 09-Feb-2017 Sascha Hauer <s.hauer@pengutronix.de>

mtd: Add partition device node to mtd partition devices

The user visible change here is that mtd partitions get an of_node link
in sysfs.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 6080ef6e 10-Jan-2017 Jeff Westfahl <jeff.westfahl@ni.com>

mtd: introduce function max_bad_blocks

If implemented, 'max_bad_blocks' returns the maximum number of bad
blocks to reserve for a MTD. An implementation for NAND is coming soon.

Signed-off-by: Jeff Westfahl <jeff.westfahl@ni.com>
Signed-off-by: Zach Brown <zach.brown@ni.com>
Acked-by: Boris Brezillon <boris.brezillon@free-electron.com>
Acked-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 97139d4a 11-Oct-2016 Masahiro Yamada <yamada.masahiro@socionext.com>

treewide: remove redundant #include <linux/kconfig.h>

Kernel source files need not include <linux/kconfig.h> explicitly
because the top Makefile forces to include it with:

-include $(srctree)/include/linux/kconfig.h

This commit removes explicit includes except the following:

* arch/s390/include/asm/facilities_src.h
* tools/testing/radix-tree/linux/kernel.h

These two are used for host programs.

Link: http://lkml.kernel.org/r/1473656164-11929-1-git-send-email-yamada.masahiro@socionext.com
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>


# 5e149073 21-Sep-2016 Richard Weinberger <richard@nod.at>

mtdpart: Propagate _get/put_device()

If the master device has callbacks for _get/put_device()
and this MTD has slaves a get_mtd_device() call on paritions
will never issue the registered callbacks.
Fix this by propagating _get/put_device() down.

Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 477b0229 16-Nov-2015 Boris Brezillon <bbrezillon@kernel.org>

mtd: introduce the mtd_pairing_scheme concept

MLC and TLC NAND devices are using NAND cells exposing more than one bit,
but instead of attaching all the bits in a given cell to a single NAND
page, each bit is usually attached to a different page. This concept is
called 'page pairing', and has significant impacts on the flash storage
usage.
The main problem showed by these devices is that interrupting a page
program operation may not only corrupt the page we are programming
but also the page it is paired with, hence the need to expose to MTD
users the pairing scheme information.

The pairing APIs allows one to query pairing information attached to a
given page (here called wunit), or the other way around (the wunit
pointed by pairing information).
It also provides several helpers to help the conversion between absolute
offsets and wunits, and query the number of pairing groups.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Reviewed-by: Brian Norris <computersforpeace@gmail.com>


# adbbc3bc 03-Feb-2016 Boris Brezillon <bbrezillon@kernel.org>

mtd: create an mtd_ooblayout_ops struct to ease ECC layout definition

ECC layout definitions are currently exposed using the nand_ecclayout
struct which embeds oobfree and eccpos arrays with predefined size.
This approach was acceptable when NAND chips were providing relatively
small OOB regions, but MLC and TLC now provide OOB regions of several
hundreds of bytes, which implies a non negligible overhead for everybody
even those who only need to support legacy NANDs.

Create an mtd_ooblayout_ops interface providing the same functionality
(expose the ECC and oobfree layout) without the need for this huge
structure.

The mtd->ecclayout is now deprecated and should be replaced by the
equivalent mtd_ooblayout_ops. In the meantime we provide a wrapper around
the ->ecclayout field to ease migration to this new model.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>


# f6a6da17 03-Feb-2016 Boris Brezillon <bbrezillon@kernel.org>

mtd: use mtd_set_ecclayout() where appropriate

Use the mtd_set_ecclayout() helper instead of directly assigning the
mtd->ecclayout field.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>


# 29f1058a 07-Mar-2016 Boris Brezillon <bbrezillon@kernel.org>

mtd: create an mtd_oobavail() helper and make use of it

Currently, all MTD drivers/sublayers exposing an OOB area are
doing the same kind of test to extract the available OOB size
based on the mtd_info and mtd_oob_ops structures.
Move this common logic into an inline function and make use of it.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Suggested-by: Priit Laes <plaes@plaes.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# adc83bf8 09-Dec-2015 Brian Norris <computersforpeace@gmail.com>

mtd: partitions: support a cleanup callback for parsers

If partition parsers need to clean up their resources, we shouldn't
assume that all memory will fit in a single kmalloc() that the caller
can kfree(). We should allow the parser to provide a proper cleanup
routine.

Note that this means we need to keep a hold on the parser's module for a
bit longer, and release it later with mtd_part_parser_put().

Alongside this, define a default callback that we'll automatically use
if the parser doesn't provide one, so we can still retain the old
behavior.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>


# 07fd2f87 04-Dec-2015 Brian Norris <computersforpeace@gmail.com>

mtd: partitions: pass around 'mtd_partitions' wrapper struct

For some of the core partitioning code, it helps to keep info about the
parsed partition (and who parsed them) together in one place.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# c42c2710 04-Dec-2015 Brian Norris <computersforpeace@gmail.com>

mtd: partitions: remove kmemdup()

The use of kmemdup() complicates the error handling a bit. We don't
actually need to allocate new memory, since this reference is treated as
const, and it is copied into new memory by the partition registration
code anyway. So remove it.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>


# 5531ae48 04-Dec-2015 Brian Norris <computersforpeace@gmail.com>

mtd: partitions: rename MTD parser get/put

We're going to reuse put_partition_parser(), so let's fix up the prefix
naming a bit, to hopefully be more consistent. Also make convert to a
true C function instead of a macro.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>


# 2524534d 19-Nov-2015 Brian Norris <computersforpeace@gmail.com>

mtd: partitions: turn PART() macro into inline function

We can guard against reorganization of struct mtd_part by using
container_of(). We can also make sure we're using the right pointer
types by making this a static inline function instead of a macro.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# b9eab011 11-Nov-2015 Brian Norris <computersforpeace@gmail.com>

mtd: partitions: add module_mtd_part_parser() helper

This can help eliminate some boilerplate by generating the module_init()
and module_exit() functions, and by automatically assigning the module
owner.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 93867233 11-Nov-2015 Brian Norris <computersforpeace@gmail.com>

mtd: zero out mtd_partition struct before using it

It's easier to guarantee we've cleared out all unused fields with
memset() than by manually initializing each field.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Reviewed-by: Boris Brezillon <boris.brezillon@free-electrons.com>


# 5a2415b0 11-Oct-2015 Brian Norris <computersforpeace@gmail.com>

mtd: mtdpart: Do not fail mtd probe when parsing partitions fails

Due to wrong assumption in ofpart ofpart fails on Exynos on SPI chips
with no partitions because the subnode containing controller data
confuses the ofpart parser.

Thus compiling in ofpart support automatically fails probing any SPI NOR
flash without partitions on Exynos.

Compiling in a partitioning scheme should not cause probe of otherwise
valid device to fail.

Instead, let's do the following:
* try parsers until one succeeds
* if no parser succeeds, report the first error we saw
* even in the failure case, allow MTD to probe, with fallback
partitions or no partitions at all -- the master device will still be
registered

Issue report and comments initially by Michal Suchanek.

Reported-by: Michal Suchanek <hramrach@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 8e2c992b 18-Aug-2015 Michal Suchanek <hramrach@gmail.com>

mtd: mtdpart: add debug prints to partition parser.

The probe of a mtd device can fail when a partition parser returns
error. The failure due to partition parsing can be quite mysterious when
multiple partitioning schemes are compiled in and any of them can fail
the probe.

Add debug prints which show what parsers were tried and what they
returned.

Signed-off-by: Michal Suchanek <hramrach@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# e5bae867 29-Jul-2015 Boris Brezillon <bbrezillon@kernel.org>

mtd: mtdpart: fix add_mtd_partitions error path

If we fail to allocate a partition structure in the middle of the partition
creation process, the already allocated partitions are never removed, which
means they are still present in the partition list and their resources are
never freed.

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Cc: stable@vger.kernel.org
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 3a434f66 02-Apr-2015 Dan Ehrenberg <dehrenberg@chromium.org>

mtd: part: Remove partition overlap checks

This patch makes MTD dynamic partitioning more flexible by removing
overlap checks for dynamic partitions. I don't see any particular
reason why overlapping dynamic partitions should be prohibited while
static partitions are allowed to overlap freely.

The checks previously had an off-by-one error, where 'end' should be
one less than what it is currently set at, and adding partitions out of
increasing order will fail. Disabling the checks resolves this issue.

Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# a62c24d7 02-Apr-2015 Dan Ehrenberg <dehrenberg@chromium.org>

mtd: part: Add sysfs variable for offset of partition

This patch makes a sysfs variable called 'offset' on each partition
which contains the offset in bytes from the beginning of the master
device that the partition starts.

Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 727dc612 02-Apr-2015 Dan Ehrenberg <dehrenberg@chromium.org>

mtd: part: Create the master device node when partitioned

For many use cases, it helps to have a device node for the entire
MTD device as well as device nodes for the individual partitions.
For example, this allows querying the entire device's properties.
A common idiom is to create an additional partition which spans
over the whole device.

This patch makes a config option, CONFIG_MTD_PARTITIONED_MASTER,
which makes the master partition present even when the device is
partitioned. This isn't turned on by default since it presents
a backwards-incompatible device numbering.

The patch also makes the parent of a partition device be the master,
if the config flag is set, now that the master is a full device.

Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# b4caecd4 14-Jan-2015 Christoph Hellwig <hch@lst.de>

fs: introduce f_op->mmap_capabilities for nommu mmap support

Since "BDI: Provide backing device capability information [try #3]" the
backing_dev_info structure also provides flags for the kind of mmap
operation available in a nommu environment, which is entirely unrelated
to it's original purpose.

Introduce a new nommu-only file operation to provide this information to
the nommu mmap code instead. Splitting this from the backing_dev_info
structure allows to remove lots of backing_dev_info instance that aren't
otherwise needed, and entirely gets rid of the concept of providing a
backing_dev_info for a character device. It also removes the need for
the mtd_inodefs filesystem.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Tejun Heo <tj@kernel.org>
Acked-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>


# fdf43a42 21-Mar-2014 Ezequiel Garcia <ezequiel.garcia@free-electrons.com>

mtd: Account for BBT blocks when a partition is being allocated

With the introduction of mtd_block_isreserved(), it's now possible
to fix the bad and reserved block distribution exposed by ecc_stats,
instead of accounting all the bad or reserved blocks as 'bad'.

Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Tested-by: Pekon Gupta <pekon@ti.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 8471bb73 21-May-2014 Ezequiel Garcia <ezequiel.garcia@free-electrons.com>

mtd: Introduce mtd_block_isreserved()

In addition to mtd_block_isbad(), which checks if a block is bad or
reserved, it's needed to check if a block is reserved only (but not
bad). This commit adds an MTD interface for it, in a similar fashion to
mtd_block_isbad().

While here, fix mtd_block_isbad() so the out-of-bounds checking is done
before the callback check.

Signed-off-by: Ezequiel Garcia <ezequiel.garcia@free-electrons.com>
Tested-by: Pekon Gupta <pekon@ti.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 4b78fc42 28-Jan-2014 Christian Riesch <christian.riesch@omicron.at>

mtd: Add a retlen parameter to _get_{fact,user}_prot_info

Signed-off-by: Christian Riesch <christian.riesch@omicron.at>
Cc: Artem Bityutskiy <Artem.Bityutskiy@linux.intel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 6e14a61d 01-Dec-2013 Axel Lin <axel.lin@ingics.com>

mtd: make register_mtd_parser return void

register_mtd_parser never fails; hence make it return void.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# cf3b2b1e 01-Dec-2013 Axel Lin <axel.lin@ingics.com>

mtd: make deregister_mtd_parser return void

deregister_mtd_parser never fails; hence make it return void.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# 26a6d240 12-Nov-2013 Geert Uytterhoeven <geert@linux-m68k.org>

mtd: make mtd_partition.name const

This allows to drop a few casts.

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>


# bdf69c47 15-Aug-2013 Huang Shijie <b32955@freescale.com>

mtd: set the ecc step size for master/slave mtd_info

Set the ecc step size for master/slave mtd_info{}.

Signed-off-by: Huang Shijie <b32955@freescale.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# ccef4dcc 12-Mar-2013 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: mtdcore: use const qualifier

Be a bit stricter and add few more 'const' qualifiers.

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


# 26a47346 11-Mar-2013 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: add 'const' qualifier to a couple of register functions

'mtd_device_parse_register()' and 'parse_mtd_partitions()' functions accept a
an array of character pointers. These functions modify neither the pointers nor
the characters they point to. The characters are actually names of the MTD
parsers.

At the moment, the argument type is 'const char **', which means that only the
names of the parsers are constant. Let's turn the argument type into 'const
char * const *', which means that both names and the pointers which point to
them are constant.

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


# c51803dd 18-Aug-2012 Huang Shijie <shijie8@gmail.com>

mtd: mtdpart: break it as soon as we parse out the partitions

We may cause a memory leak when the @types has more then one parser.

Take the `default_mtd_part_types` for example. The default_mtd_part_types has
two parsers now: `cmdlinepart` and `ofpart`.

Assume the following case:
The kernel command line sets the partitions like:
#gpmi-nand:20m(boot),20m(kernel),1g(rootfs),-(user)
But the devicetree file(such as arch/arm/boot/dts/imx28-evk.dts) also sets
the same partitions as the kernel command line does.

In the current code, the partitions parsed out by the `ofpart` will
overwrite the @pparts which has already set by the `cmdlinepart` parser,
and the the partitions parsed out by the `cmdlinepart` is missed.
A memory leak occurs.

So we should break the code as soon as we parse out the partitions,
In actually, this patch makes a priority order between the parsers.
If one parser has already parsed out the partitions successfully,
it's no need to use another parser anymore.

Signed-off-by: Huang Shijie <shijie8@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 62082e56 10-Jul-2012 Richard Genoud <richard.genoud@gmail.com>

mtd: mtdparts: introduce mtd_get_device_size

'mtd_get_device_size()' returns the size of the whole MTD device, that is the
mtd_info master size. This will be used by UBI to calculate the maximum number
of bad blocks (MBB) on a MTD device.

Artem: amended the patch a bit.

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# 5dee4674 10-Jul-2012 Richard Genoud <richard.genoud@gmail.com>

mtd: mark mtd_is_partition argument as constant

'struct mtd_info' is not modified by 'mtd_is_partition()' so it can be marked
as "const".

Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>


# edbc4540 25-Apr-2012 Mike Dunn <mikedunn@newsguy.com>

mtd: driver _read() returns max_bitflips; mtd_read() returns -EUCLEAN

The drivers' _read() method, absent an error, returns a non-negative integer
indicating the maximum number of bit errors that were corrected in any one
region comprising an ecc step. MTD returns -EUCLEAN if this is >=
bitflip_threshold, 0 otherwise. If bitflip_threshold is zero, the comparison is
not made since these devices lack ECC and always return zero in the non-error
case (thanks Brian)¹. Note that this is a subtle change to the driver
interface.

This and the preceding patches in this set were tested with ubi on top of the
nandsim and docg4 devices, running the ubi test io_basic from mtd-utils.

¹ http://lists.infradead.org/pipermail/linux-mtd/2012-March/040468.html

Signed-off-by: Mike Dunn <mikedunn@newsguy.com>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Acked-by: Brian Norris <computersforpeace@gmail.com>
Ivan Djelic <ivan.djelic@parrot.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# d062d4ed 25-Apr-2012 Mike Dunn <mikedunn@newsguy.com>

mtd: bitflip_threshold added to mtd_info and sysfs

An element 'bitflip_threshold' is added to struct mtd_info, and also exposed as
a read/write variable in sysfs. This will be used to determine whether or not
mtd_read() returns -EUCLEAN or 0 (absent a hard error). If the driver leaves it
as zero, mtd will set it to a default value of ecc_strength.

This v2 adds the line that propagates bitflip_threshold from the master to the
partitions - thanks Ivan¹.

¹ http://lists.infradead.org/pipermail/linux-mtd/2012-April/040900.html

Signed-off-by: Mike Dunn <mikedunn@newsguy.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 6a918bad 11-Mar-2012 Mike Dunn <mikedunn@newsguy.com>

mtd: flash drivers set ecc strength

Flash device drivers initialize 'ecc_strength' in struct mtd_info, which is the
maximum number of bit errors that can be corrected in one writesize region.

Drivers using the nand interface intitialize 'strength' in struct nand_ecc_ctrl,
which is the maximum number of bit errors that can be corrected in one ecc step.
Nand infrastructure code translates this to 'ecc_strength'.

Also for nand drivers, the nand infrastructure code sets ecc.strength for ecc
modes NAND_ECC_SOFT, NAND_ECC_SOFT_BCH, and NAND_ECC_NONE. It is set in the
driver for all other modes.

Signed-off-by: Mike Dunn <mikedunn@newsguy.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 994c8409 03-Mar-2012 Mike Dunn <mikedunn@newsguy.com>

mtd: fix partition wrapper functions

This patch reverts a change that may have been mistakenly included with the set
of patches that introduced the new mtd api entry functions. Or perhaps I am
mistaken :)

The problem is in the partition wrapper functions, where the calls to the driver
methods were replaced with calls to the new mtd api functions. This causes the
api function to be called a second time, further down the call stack. This is
not only unnecessary and redundant - because the sanity checking code and (more
restrictive) bounds checks for the partition were done in the first call - but
is potentially problematic and confusing.

For example, the call stack for a call to mtd_read() on a partitioned device
currently looks like this:

mtd_read() gets struct mtd_info for the partition
|
+-> part_read() via the pointer assigned when the partition was created
|
+->mtd_read() this time gets struct mtd_info for the master
|
+->xyz_driver_read() via the pointer asigned by the driver

It seems that this can cause a variety of problems. For example, if you want to
add code to the api function that tests a value in mtd_info that is relevant
only to the partition. Or (in my case) you want the driver to return a value
that may be different from that returned by the mtd api function.

This patch eliminates the second call to the mtd api function. It was tested on
the docg4 nand driver with a subset of the api functions, but I inspected the
rest and don't see any problems.

Signed-off-by: Mike Dunn <mikedunn@newsguy.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 664addc2 03-Feb-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: remove R/O checking duplication

Many drivers check whether the partition is R/O and return -EROFS if yes.
Let's stop having duplicated checks and move them to the API functions
instead.

And again a bit of noise - deleted few too sparse newlines, sorry.

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


# 5def4898 03-Feb-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: do not duplicate length and offset checks in drivers

We already verify that offset and length are within the MTD device size
in the MTD API functions. Let's remove the duplicated checks in drivers.
This patch only affects the following API's:

'mtd_erase()'
'mtd_point()'
'mtd_unpoint()'
'mtd_get_unmapped_area()'
'mtd_read()'
'mtd_write()'
'mtd_panic_write()'
'mtd_lock()'
'mtd_unlock()'
'mtd_is_locked()'
'mtd_block_isbad()'
'mtd_block_markbad()'

This patch adds a bit of noise by removing too sparse empty lines, but this is
not too bad.

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


# 5e4e6e3f 03-Feb-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: return error code from mtd_unpoint

The 'mtd_unpoint()' API function should be able to return an error code because
it may fail if you specify incorrect offset. This patch changes this MTD API
function and amends all the drivers correspondingly.

Also return '-EOPNOTSUPP' from 'mtd_unpoint()' when the '->unpoint()' method is
undefined. We do not really need this currently, but this just makes
sense to be consistent with 'mtd_point()'.

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


# 3c3c10bb 30-Jan-2012 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: add leading underscore to all mtd functions

This patch renames all MTD functions by adding a "_" prefix:

mtd->erase -> mtd->_erase
mtd->read_oob -> mtd->_read_oob
...

The reason is that we are re-working the MTD API and from now on it is
an error to use MTD function pointers directly - we have a corresponding
API call for every pointer. By adding a leading "_" we achieve the following:

1. Make sure we convert every direct pointer users
2. A leading "_" suggests that this interface is internal and it becomes
less likely that people will use them directly
3. Make sure all the out-of-tree modules stop compiling and the owners
spot the big API change and amend them.

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


# 58edc904 25-Jan-2012 Stefan Roese <sr@denx.de>

mtd: minor coding style cleanup in mtdpart.c

Signed-off-by: Stefan Roese <sr@denx.de>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 5942ddbc 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_block_markbad interface

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


# 7086c19d 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_block_isbad interface

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


# ead995f8 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_resume interface

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


# 3fe4bae8 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_suspend interface

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


# e95e9786 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_is_locked interface

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


# b66005cd 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_unlock interface

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


# 7799f9ac 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_lock interface

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


# 85f2f2a8 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_sync interface

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


# b0a31f7b 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_writev interface

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


# 4403dbfb 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_lock_user_prot_reg interface

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


# 482b43ad 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_write_user_prot_reg interface

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


# 4ea1cabb 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_read_user_prot_reg interface

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


# 855e5d8c 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_get_user_prot_info interface

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


# d264f72a 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_read_fact_prot_reg interface

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


# a750b5ce 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_get_fact_prot_info interface

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


# a2cc5ba0 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_write_oob interface

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


# fd2819bb 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_read_oob interface

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


# 7ae79d7f 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_panic_write interface

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


# eda95cbf 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_write interface

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


# 329ad399 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_read interface

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


# 04c601bf 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_get_unmapped_area interface

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


# 7219778a 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_unpoint interface

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


# d35ea200 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_point interface

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


# 7e1f0dc0 23-Dec-2011 Artem Bityutskiy <artem.bityutskiy@linux.intel.com>

mtd: introduce mtd_erase interface

This patch is part of a patch-set which changes the MTD interface
from 'mtd->func()' form to 'mtd_func()' form. We need this because
we want to add common code to to all drivers in the mtd core level,
which is impossible with the current interface when MTD clients
call driver functions like 'read()' or 'write()' directly.

At this point we just introduce a new inline wrapper function, but
later some of them are expected to gain more code. E.g., the input
parameters check should be moved to the wrappers rather than be
duplicated at many drivers.

This particular patch introduced the 'mtd_erase()' interface. The
following patches add all the other interfaces one by one.

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


# d57f4054 20-Sep-2011 Brian Norris <computersforpeace@gmail.com>

mtd: utilize `mtd_is_*()' functions

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>


# 0612b9dd 30-Aug-2011 Brian Norris <computersforpeace@gmail.com>

mtd: rename MTD_OOB_* to MTD_OPS_*

These modes are not necessarily for OOB only. Particularly, MTD_OOB_RAW
affected operations on in-band page data as well. To clarify these
options and to emphasize that their effect is applied per-operation, we
change the primary prefix to MTD_OPS_.

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>


# 953b3bd1 23-Jun-2011 Dmitry Baryshkov <dbaryshkov@gmail.com>

mtd: remove put_partition_parser() from public header

There is no need to pollute public header with a definition private
to mtdpart.c. Move it from mtd/partitions.h to mtdpart.c

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 3165f44b 23-Jun-2011 Dmitry Baryshkov <dbaryshkov@gmail.com>

mtd: hide parse_mtd_partitions

There is no need to export parse_mtd_partitions() now , as it's fully handled
by registration functions. So move the definition to private header and
remove respective EXPORT_SYMBOL_GPL.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# d26c87d6 29-May-2011 Dmitry Baryshkov <dbaryshkov@gmail.com>

mtd: prepare to convert of_mtd_parse_partitions to partition parser

Prepare to convert of_mtd_parse_partitions() to usual partitions parser:
1) Register ofpart parser
2) Internally don't use passed device for error printing
3) Add device_node to mtd_part_parser_data struct
4) Move of_mtd_parse_partitions from __devinit to common text section
5) add ofpart to the default list of partition parsers

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>


# c7975330 10-Jun-2011 Dmitry Baryshkov <dbaryshkov@gmail.com>

mtd: abstract last MTD partition parser argument

Encapsulate last MTD partition parser argument into a separate
structure. Currently it holds only 'origin' field for RedBoot parser,
but will be extended in future to contain at least device_node for OF
devices.

Amended commentary to make kerneldoc happy

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Artem Bityutskiy <dedekind1@gmail.com>


# ad274cec 08-Jun-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

mtd: document parse_mtd_partitions

Add a kerneldoc comment for the 'parse_mtd_partitions()' function - its
behavior has changed recently so it is good idea to have it documented.

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


# 1a31368b 06-Jun-2011 Dmitry Baryshkov <dbaryshkov@gmail.com>

mtd: add a flags for partitions which should just leave smth. after them

Add support for MTDPART_OFS_RETAIN: such partitions start at the current
offset, take as much space as possible, but rain part->size bytes after
the end of the partitions for other parts. Primarily this is intended
for ts72xx arm platforms cleanup.

Artem: tweaked the patch a bit

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# 5c4eefbd 02-Jun-2011 Dmitry Baryshkov <dbaryshkov@gmail.com>

mtd: mtdpart: default to cmdlinepart, NULL partitions probing

Lots of MTD devices default to cmdlinepart, NULL as partition parsing
order. Make it a default.

Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>


# eea72d5f 23-May-2011 Jamie Iles <jamie@jamieiles.com>

mtd: remove add_mtd_partitions, add_mtd_device and friends

These symbols are replaced with mtd_device_register() (and removal with
mtd_device_unregister()) for public registration.

Signed-off-by: Jamie Iles <jamie@jamieiles.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


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

mtd: be silent when mtd partition parser cannot be found

Currently when we register partitions in 'parse_mtd_partitions()' we accept the
list of parsers we should try. And if one of the parsers was not found we print
a message. Well, first of all this whole idea is bad - look at how many
'part_probes' and 'part_probe_types' variables we have - nearly every driver
defines one. Instead, we should just go through all registered parsers all the
time. But this needs to be worked on separately.

This patch makes life of MTD partitions' users a bit simpler and allows them to
safely request parsers which have not been registered -
'parse_mtd_partitions()' will not print a "not available" message in this
case.

The point is that drivers do not have to do things like this any longer:

static const char *part_probe_types[] = { "cmdlinepart", "RedBoot",
"afs",
NULL };

but can simply do like this:

static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", "afs", NULL };

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


# 154bf89f 16-Jan-2011 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

mtd: mtdpart: disallow reading OOB past the end of the partition

This patch fixes the mtdpart bug which allows users reading OOB past the
end of the partition. This happens because 'part_read_oob()' allows reading
multiple OOB areas in one go, and mtdparts does not validate the OOB
length in the request.

Although there is such check in 'nand_do_read_oob()' in nand_base.c, but
it checks that we do not read past the flash chip, not the partition,
because in nand_base.c we work with the whole chip (e.g., mtd->size
in nand_base.c is the size of the whole chip). So this check cannot
be done correctly in nand_base.c and should be instead done in mtdparts.c.

This problem was reported by Jason Liu <r64343@freescale.com> and reproduced
with nandsim:

$ modprobe nandsim first_id_byte=0x20 second_id_byte=0xaa third_id_byte=0x00 \
fourth_id_byte=0x15 parts=0x400,0x400
$ modprobe nandsim mtd_oobtest.ko dev=0
$ dmesg
= snip =
mtd_oobtest: attempting to read past end of device
mtd_oobtest: an error is expected...
mtd_oobtest: error: read past end of device
= snip =
mtd_oobtest: finished with 2 errors

Reported-by: Jason Liu <liu.h.jason@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 7fa33ac0 16-Dec-2010 Anatolij Gustschin <agust@denx.de>

mtd: initialize writebufsize in the MTD object of a partition

Propagate the writebufsize to the partition's MTD object so
that UBI can set correct value for it's minimal I/O size
using the writebufsize field of MTD object of the partition.

By previous patches we added proper writebufsize field
initialization. Next patch can now change UBI to use
this field for setting the minimal I/O size.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# a7e93dcd 23-Nov-2010 Roman Tereshonkov <roman.tereshonkov@nokia.com>

mtd: fix master device identification for mtd repartition

Function mtd_has_master renamed as mtd_is_partition to follow the function logic.
The patch fixes the problem of checking the right mtd device for partition creation.
To delete partition checking is not needed here so as it is done in mtd_del_partition.
By master we consider the mtd device which does not belong to any partition.

Signed-off-by: Roman Tereshonkov <roman.tereshonkov@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 5daa7b21 17-Sep-2010 Roman Tereshonkov <roman.tereshonkov@nokia.com>

mtd: prepare partition add and del functions for ioctl requests

mtd_is_master, mtd_add_partition and mtd_del_partition functions
are added to give the possibility of partition manipulation
by ioctl request.

The old partition add function is modified to fit the dynamic
allocation.

Signed-off-by: Roman Tereshonkov <roman.tereshonkov@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 6ae0185f 08-Aug-2010 David Woodhouse <David.Woodhouse@intel.com>

mtd: Remove obsolete <mtd/compatmac.h> include

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# a1452a37 08-Aug-2010 David Woodhouse <David.Woodhouse@intel.com>

mtd: Update copyright notices

Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 9938424f 14-Jun-2010 Richard Cochran <richardcochran@gmail.com>

mtd: add an ioctl to query the lock status of a flash sector

This patchs adds a way for user space programs to find out whether a
flash sector is locked. An optional driver method in the mtd_info struct
provides the information.

Signed-off-by: Richard Cochran <richard.cochran@omicron.at>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# a57ca046 18-Sep-2009 Roel Kluin <roel.kluin@gmail.com>

mtd: mtdpart: prevent a read from regions[-1]

If the erase region was found in the first iteration we read from
regions[-1]

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 2f82af08 14-Sep-2009 Nicolas Pitre <nico@fluxnic.net>

Nicolas Pitre has a new email address

Due to problems at cam.org, my nico@cam.org email address is no longer
valid. FRom now on, nico@fluxnic.net should be used instead.

Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>


# b90cf668 05-Apr-2009 David Woodhouse <David.Woodhouse@intel.com>

[MTD] Remove option for add_mtd_partitions() to not register partitions.

This breaks the dilnetpc map driver, but it could be fixed not to use
that option. We want to simplify the partition handling, and this is a
step towards that.

Remove superfluous 'index' field from private struct mtd_part too, while
we're at it.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 4704a784 05-Apr-2009 David Woodhouse <David.Woodhouse@intel.com>

[MTD] Only set partition suspend/resume method if parent not registered

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# d8877f19 26-Mar-2009 Yauhen Kharuzhy <jekhor@gmail.com>

[MTD] mtdpart: Make ecc_stats more realistic.

In the existing implementation, ecc_stats fields are incremented only by
one, regardless of master mtd errors number. For example, if there are N
errors were corrected by ECC, partition ecc_stats.corrected will be
incremented by one.

This commit changes simple increment to sum of old value and parent mtd
error count.

Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 1f24b5a8 26-Mar-2009 David Brownell <dbrownell@users.sourceforge.net>

[MTD] driver model updates

Update driver model support in the MTD framework, so it fits
better into the current udev-based hotplug framework:

- Each mtd_info now has a device node. MTD drivers should set
the dev.parent field to point to the physical device, before
setting up partitions or otherwise declaring MTDs.

- Those device nodes always map to /sys/class/mtdX device nodes,
which no longer depend on MTD_CHARDEV.

- Those mtdX sysfs nodes have a "starter set" of attributes;
it's not yet sufficient to replace /proc/mtd.

- Enabling MTD_CHARDEV provides /sys/class/mtdXro/ nodes and the
/sys/class/mtd*/dev attributes (for udev, mdev, etc).

- Include a MODULE_ALIAS_CHARDEV_MAJOR macro. It'll work with
udev creating the /dev/mtd* nodes, not just a static rootfs.

So the sysfs structure is pretty much what you'd expect, except
that readonly chardev nodes are a bit quirky.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 402d3265 12-Feb-2009 David Howells <dhowells@redhat.com>

NOMMU: Present backing device capabilities for MTD chardevs

Present backing device capabilities for MTD character device files to allow
NOMMU mmap to do direct mapping where possible.

Signed-off-by: David Howells <dhowells@redhat.com>
Tested-by: Bernd Schmidt <bernd.schmidt@analog.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 69423d99 10-Dec-2008 Adrian Hunter <ext-adrian.hunter@nokia.com>

[MTD] update internal API to support 64-bit device size

MTD internal API presently uses 32-bit values to represent
device size. This patch updates them to 64-bits but leaves
the external API unchanged. Extending the external API
is a separate issue for several reasons. First, no one
needs it at the moment. Secondly, whether the implementation
is done with IOCTLs, sysfs or both is still debated. Thirdly
external API changes require the internal API to be accepted
first.

Note that although the MTD API will be able to support 64-bit
device sizes, existing drivers do not and are not required
to do so, although NAND base has been updated.

In general, changing from 32-bit to 64-bit values cause little
or no changes to the majority of the code with the following
exceptions:
- printk message formats
- division and modulus of 64-bit values
- NAND base support
- 32-bit local variables used by mtdpart and mtdconcat
- naughtily assuming one structure maps to another
in MEMERASE ioctl

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# a65e5d78 09-Jul-2008 Johannes Berg <johannes@sipsolutions.net>

remove CONFIG_KMOD from drivers

Straight forward conversions to CONFIG_MODULE; many drivers
include <linux/kmod.h> conditionally and then don't have any
other conditional code so remove it from those.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Cc: video4linux-list@redhat.com
Cc: David Woodhouse <dwmw2@infradead.org>
Cc: linux-ppp@vger.kernel.org
Cc: dm-devel@redhat.com
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>


# bb0eb217 11-Aug-2008 Adrian Hunter <ext-adrian.hunter@nokia.com>

[MTD] Define and use MTD_FAIL_ADDR_UNKNOWN instead of 0xffffffff

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# f636ffb4 18-Jul-2008 Atsushi Nemoto <anemo@mba.ocn.ne.jp>

[MTD][MTDPART] Fix a division by zero bug

When detecting a partition beyond the end of the device, skip most of
the initialisation, in particular those bits causing a division by zero.

Signed-off-by: Jörn Engel <joern@logfs.org>
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 6910c136 18-Jul-2008 Atsushi Nemoto <anemo@mba.ocn.ne.jp>

[MTD][MTDPART] Cleanup and document the erase region handling

Mostly simplifying the loops. Now everything fits into 80 columns,
is easier to read and the finer details have extra comments.

Signed-off-by: Jörn Engel <joern@logfs.org>
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# b33a2887 18-Jul-2008 Atsushi Nemoto <anemo@mba.ocn.ne.jp>

[MTD][MTDPART] Handle most checkpatch findings

Remaining are 12 warnings about long lines and 1 about braces that
could be argued about.

Signed-off-by: Jörn Engel <joern@logfs.org>
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 7788ba71 18-Jul-2008 Atsushi Nemoto <anemo@mba.ocn.ne.jp>

[MTD][MTDPART] Seperate main loop from per-partition code in add_mtd_partition

add_mtd_partition was a 150+ line monster consisting mostly of a single
loop. Seperate the loop from most of the body. Now it should be
obvious which variables are carried around from iteration to iteration.

Signed-off-by: Jörn Engel <joern@logfs.org>
Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>


# 71a928c0 19-May-2008 Chris Malley <mail@chrismalley.co.uk>

[MTD] Use list_for_each_entry[_safe] where appropriate.

Janitorial work to remove temporary pointers and make some functions a bit
more readable.

Signed-off-by: Chris Malley <mail@chrismalley.co.uk>
Reviewed-By: Jörn Engel <joern@logfs.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 59018b6d 19-May-2008 Adrian Bunk <bunk@kernel.org>

MTD/JFFS2: remove CVS keywords

Once upon a time, the MTD repository was using CVS.

This patch therefore removes all usages of the no longer updated CVS
keywords from the MTD code.

This also includes code that printed them to the user.

Signed-off-by: Adrian Bunk <bunk@kernel.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# a98889f3 30-Apr-2008 Jared Hulbert <jaredeh@gmail.com>

[MTD][NOR] Add physical address to point() method

Adding the ability to get a physical address from point() in addition
to virtual address. This physical address is required for XIP of
userspace code from flash.

Signed-off-by: Jared Hulbert <jaredeh@gmail.com>
Reviewed-by: Jörn Engel <joern@logfs.org>
Acked-by: Nicolas Pitre <nico@cam.org>
Acked-by: Greg Ungerer <gerg@uclinux.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 388bbb09 06-Feb-2008 Richard Purdie <rpurdie@rpsys.net>

[MTD] Add mtd panic_write function pointer

MTDs are well suited for logging critical data and the mtdoops driver
allows kernel panics/oops to be written to flash in a blackbox flight
recorder fashion allowing better debugging and analysis of crashes.

Any kernel oops in user context can be easily handled since the kernel
continues as normal and any queued mtd writes are scheduled. Any kernel
oops in interrupt context results in a panic and the delayed writes will
not be scheduled however. The existing mtd->write function cannot be
called in interrupt context so these messages can never be written to
flash.

This patch adds a panic_write function pointer that drivers can
optionally implement which can be called in interrupt context. It is
only intended to be called when its known the kernel is about to panic
and we need to write to succeed. Since the kernel is not going to be
running for much longer, this function can break locks and delay to
ensure the write succeeds (but not sleep).

Signed-off-by: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# bec49477 02-Aug-2007 Satyam Sharma <satyam@infradead.org>

[MTD] Makefile fix for mtdsuper

We want drivers/mtd/{mtdcore, mtdsuper, mtdpart}.c to be built and linked
into the same mtd.ko module. Fix the Makefile to ensure this, and remove
duplicate MODULE_ declarations in mtdpart.c, as mtdcore.c already has them.

Signed-off-by: Satyam Sharma <satyam@infradead.org>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 42f209d3 04-May-2007 Robert P. J. Day <rpjday@mindspring.com>

[MTD] Delete allegedly obsolete "bank_size" field of mtd_info.

Delete the allegedly obsolete "bank_size" member of struct mtd_info.

Signed-off-by: Robert P. J. Day <rpjday@mindspring.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 74641d75 07-Mar-2007 Adrian Hunter <ext-adrian.hunter@nokia.com>

[MTD] Correct partition failed erase address

If an erase operation fails, the address at which the
failure occurred is returned by the driver. The MTD
partition must adjust this address (by subtracting the
partition offset) before returning to the caller.
This was not happening, which caused JFFS2 to mark
the wrong block bad!

Signed-off-by: Adrian Hunter <ext-adrian.hunter@nokia.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 1f92267c 06-Mar-2007 Vitaly Wool <vwool@ru.mvista.com>

[MTD] [NAND] make oobavail public

During the MTD rework the oobavail parameter of mtd_info structure has become
private. This is not quite correct in terms of integrity and logic. If we have
means to write to OOB area, then we'd like to know upfront how many bytes out
of OOB are spare per page to be able to adapt to specific cases.
The patch inlined adds the public oobavail parameter.

Signed-off-by: Vitaly Wool <vwool@ru.mvista.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 64f60710 30-Jan-2007 Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

[MTD] remove unused ecctype,eccsize fields from struct mtd_info

Remove unused and broken mtd->ecctype and mtd->eccsize fields
from struct mtd_info. Do not remove them from userspace API
data structures (don't want to breake userspace) but mark them
as obsolete by a comment. Any userspace program which uses them
should be half-broken anyway, so this is more about saving
data structure size.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 29072b96 28-Sep-2006 Thomas Gleixner <tglx@linutronix.de>

[MTD] NAND: add subpage write support

Many SLC NANDs support up to 4 writes at one NAND page. Add support
of this feature.

Signed-off-by: Artem Bityutskiy <dedekind@infradead.org>


# 95b93a0c 15-Nov-2006 Burman Yan <yan_952@hotmail.com>

[MTD] replace kmalloc+memset with kzalloc

Signed-off-by: Yan Burman <yan_952@hotmail.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 7014568b 03-Nov-2006 Vitaly Wool <vwool@ru.mvista.com>

[MTD] [NAND] remove len/ooblen confusion.

As was discussed between Ricard Wanderlöf, David Woodhouse, Artem
Bityutskiy and me, the current API for reading/writing OOB is confusing.

The thing that introduces confusion is the need to specify ops.len
together with ops.ooblen for reads/writes that concern only OOB not data
area. So, ops.len is overloaded: when ops.datbuf != NULL it serves to
specify the length of the data read, and when ops.datbuf == NULL, it
serves to specify the full OOB read length.

The patch inlined below is the slightly updated version of the previous
patch serving the same purpose, but with the new Artem's comments taken
into account.

Artem, BTW, thanks a lot for your valuable input!

Signed-off-by: Vitaly Wool <vwool@ru.mvista.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 6ab3d562 30-Jun-2006 Jörn Engel <joern@wohnheim.fh-wedel.de>

Remove obsolete #include <linux/config.h>

Signed-off-by: Jörn Engel <joern@wohnheim.fh-wedel.de>
Signed-off-by: Adrian Bunk <bunk@stusta.de>


# f1a28c02 29-May-2006 Thomas Gleixner <tglx@cruncher.tec.linutronix.de>

[MTD] NAND Expose the new raw mode function and status info to userspace

The raw read/write access to NAND (without ECC) has been changed in the
NAND rework. Expose the new way - setting the file mode via ioctl - to
userspace. Also allow to read out the ecc statistics information so userspace
tools can see that bitflips happened and whether errors where correctable
or not. Also expose the number of bad blocks for the partition, so nandwrite
can check if the data fits into the parition before writing to it.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# 8593fbc6 28-May-2006 Thomas Gleixner <tglx@cruncher.tec.linutronix.de>

[MTD] Rework the out of band handling completely

Hopefully the last iteration on this!

The handling of out of band data on NAND was accompanied by tons of fruitless
discussions and halfarsed patches to make it work for a particular
problem. Sufficiently annoyed by I all those "I know it better" mails and the
resonable amount of discarded "it solves my problem" patches, I finally decided
to go for the big rework. After removing the _ecc variants of mtd read/write
functions the solution to satisfy the various requirements was to refactor the
read/write _oob functions in mtd.

The major change is that read/write_oob now takes a pointer to an operation
descriptor structure "struct mtd_oob_ops".instead of having a function with at
least seven arguments.

read/write_oob which should probably renamed to a more descriptive name, can do
the following tasks:

- read/write out of band data
- read/write data content and out of band data
- read/write raw data content and out of band data (ecc disabled)

struct mtd_oob_ops has a mode field, which determines the oob handling mode.

Aside of the MTD_OOB_RAW mode, which is intended to be especially for
diagnostic purposes and some internal functions e.g. bad block table creation,
the other two modes are for mtd clients:

MTD_OOB_PLACE puts/gets the given oob data exactly to/from the place which is
described by the ooboffs and ooblen fields of the mtd_oob_ops strcuture. It's
up to the caller to make sure that the byte positions are not used by the ECC
placement algorithms.

MTD_OOB_AUTO puts/gets the given oob data automaticaly to/from the places in
the out of band area which are described by the oobfree tuples in the ecclayout
data structre which is associated to the devicee.

The decision whether data plus oob or oob only handling is done depends on the
setting of the datbuf member of the data structure. When datbuf == NULL then
the internal read/write_oob functions are selected, otherwise the read/write
data routines are invoked.

Tested on a few platforms with all variants. Please be aware of possible
regressions for your particular device / application scenario

Disclaimer: Any whining will be ignored from those who just contributed "hot
air blurb" and never sat down to tackle the underlying problem of the mess in
the NAND driver grown over time and the big chunk of work to fix up the
existing users. The problem was not the holiness of the existing MTD
interfaces. The problems was the lack of time to go for the big overhaul. It's
easy to add more mess to the existing one, but it takes alot of effort to go
for a real solution.

Improvements and bugfixes are welcome!

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# 5bd34c09 27-May-2006 Thomas Gleixner <tglx@cruncher.tec.linutronix.de>

[MTD] NAND Replace oobinfo by ecclayout

The nand_oobinfo structure is not fitting the newer error correction
demands anymore. Replace it by struct nand_ecclayout and fixup the users
all over the place. Keep the nand_oobinfo based ioctl for user space
compability reasons.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# ff268fb8 27-May-2006 Thomas Gleixner <tglx@cruncher.tec.linutronix.de>

[MTD] NAND Consolidate oobinfo handling

The info structure for out of band data was copied into
the mtd structure. Make it a pointer and remove the ability
to set it from userspace. The position of ecc bytes is
defined by the hardware and should not be changed by software.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# 9223a456 23-May-2006 Thomas Gleixner <tglx@cruncher.tec.linutronix.de>

[MTD] Remove read/write _ecc variants

MTD clients are agnostic of FLASH which needs ECC suppport.
Remove the functions and fixup the callers.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# 2528e8cd 23-May-2006 Thomas Gleixner <tglx@cruncher.tec.linutronix.de>

[MTD] Remove readv/readv_ecc

These functions were never implemented and added only bloat to
partition and concat code.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# 9d8522df 23-May-2006 Thomas Gleixner <tglx@cruncher.tec.linutronix.de>

[MTD] Remove nand writev support

NAND writev(_ecc) support is not longer necessary. Remove it.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# 28318776 22-May-2006 Joern Engel <joern@wh.fh-wedel.de>

[MTD] Introduce writesize

At least two flashes exists that have the concept of a minimum write unit,
similar to NAND pages, but no other NAND characteristics. Therefore, rename
the minimum write unit to "writesize" for all flashes, including NAND.

Signed-off-by: Joern Engel <joern@wh.fh-wedel.de>


# ae282d49 16-May-2006 Vitaly Wool <vwool@ru.mvista.com>

[MTD] generic: propagate oobavail to MTD partitions

'oobavail' parameter of mtd_info structure is now propagated to the MTD
partitions

Signed-off-by: Vitaly Wool <vwool@ru.mvista.com>
Signed-off-by: David Woodhouse <dwmw2@infradead.org>


# 97894cda 07-Nov-2005 Thomas Gleixner <tglx@linutronix.de>

[MTD] core: Clean up trailing white spaces

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# 5cea5dad 30-Sep-2005 Artem B. Bityutskiy <dedekind@infradead.org>

[MTD] mtdpart.c: Allow eraseblock size != power of 2

Don't assume eraseblock size is power of 2.
Dataflash can have aligned eraseblock size.

From: Peter Menzebach <pm-mtd@mw-itcon.de>
Acked-by: Artem B. Bityutskiy <dedekind@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# f77814dd 08-Feb-2005 Nicolas Pitre <nico@cam.org>

[MTD] Support for protection register support on Intel FLASH chips

This enables support for reading, writing and locking so called
"Protection Registers" present on some flash chips.
A subset of them are pre-programmed at the factory with a
unique set of values. The rest is user-programmable.

Signed-off-by: Nicolas Pitre <nico@cam.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>


# 1da177e4 16-Apr-2005 Linus Torvalds <torvalds@ppc970.osdl.org>

Linux-2.6.12-rc2

Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.

Let it rip!