All of lore.kernel.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v13 0/7] SPI-NAND support (third batch)
Date: Mon,  1 Oct 2018 15:43:24 +0200	[thread overview]
Message-ID: <20181001134331.9756-1-miquel.raynal@bootlin.com> (raw)

During the last months, Boris Brezillon shared his work to support
serial flashes within Linux. First, he delivered (and merged) a new
layer called spi-mem. He also initiated in Linux MTD subsystem the move
of all 'raw' NAND related code to a raw/ subdirectory, adding at the
same time a NAND core that would be shared with all NAND devices. Then,
he contributed a generic SPI-NAND driver, making use of this NAND core,
as well as some vendor code to drive a few chips.

On top of this work, I made some cleanups in the MTD layer and added an
'mtd' U-Boot command to handle all sort of MTD devices. This should
become the default command instead of having one per flash flavor
('sf', 'nand', 'spi-nand' ?).

The series has been tested on an Ocelot board PCB123 (VSC7514),
featuring a Macronix SPI NAND chip.

TL;DR: the series contains (stripped version since ~30 patches have
already been taken):
- Support for spi-nand devices in mtdparts.
- Generics mtdparts/mtdids parsers.
- A new 'mtd' command.
- A note to set mtdparts command legacy.

To test your SPI-NAND device with U-Boot, you can test someting like:

> setenv mtdparts 'spi-nand0:1m(foo),-(bar)'
> setenv mtdids 'spi-nand0=spi0.0' # spi0.0 is Linux MTD name for this device
> ubi part bar         # create a static UBI volume in the bar partition
> mtd list             # show the current MTD devices/partitions

Thanks,
Miquèl


NB1: If UBI refuses to attach, verify the partition is epty with
     # mtd erase bar

NB2: If your U-Boot crashes and you are using a non SPI-NAND device,
     don't forget to probe your device *first* (sf probe, ...).

Changes since v12:
------------------
* Dropped the patch removing a DM-helper without users that was breaking
  the build when included from a file that can be compiled either with
  and without DM support. Instead, added a forward declaration of struct
  udevice, then enclosed the declarations in a #if defined(CONFIG_DM)
  conditional with dummy helpers on the other side.
* Build test with Travis CI:
  https://travis-ci.org/miquelraynal/u-boot/builds/435575048

Changes since v11:
------------------
* Due to the number of small changes I had to do to handle the various
  build failures reported by Travis, I decided to send a full v12 so
  that all the patches can be replaced and are known to compile
  properly.
* Adding a patch to drop an unused helper in mtd_uboot.c that in some
  cases causes build issues (if compiled without DM support enabled).
* Travis CI status (build success except for one unrelated issue):
  https://travis-ci.org/miquelraynal/u-boot/builds/434796123

Changes since v10:
------------------
* Only two patches sent independently with small fixes to handle build
  failures for some configurations (reported by Travis)

Changes since v9:
-----------------
* mtd_search_alternate_name() is moved in mtd_uboot.c (generic code,
  everybody wants to use mtdids).
* mtd_parse_partitions() is still in mtdparts.c because it depends on
  partitions support, but the header file declaring it
  (include/linux/mtd/partitions.h) also has a dummy function if
  #if IS_ENABLED(CONFIG_MTD_PARTITIONS) is false.
* Typo corrected in mtd_parse_partitions prototype
  (s/_nb_parts/_nparts/).
* Added Boris' R-b tags.

Changes since v8 (called v7 by mistake):
----------------------------------------
* Moved most of the generic logic to the core (mtd_uboot.c) so that it
  can be reused by other parts of U-Boot without depending on anything
  else than the MTD core itself.
* Removed the "#ifdef CONFIG_MTD" around mtd_probe_devices() calls now
  that the code is in the core.
* Created an helper for partitions deletion (as there is one to
  parse/create partition objects).
* Drop "cmd: mtdparts: try to probe the MTD devices as a fallback" to
  actually deprecate the command.
* Enhanced a bit the text in Kconfig about deprecating mtdparts.
* Fixed checkpatch.pl warnings in the mtdparts driver.

cmd/mtd.c:
* The logic in the mtd_is_aligned_with_*() functions was wrong, inversed
  it so the result is what the reader expects (the logic in the end was
  valid, though).
* Discriminate two path: for NAND-like devices (pages, OOB, raw mode,
  bad blocks) and the others.
* Add the "bad" feature to display all bad blocks (if any).
* Fix some typos/display strings.
* Moved the refcounting put_mtd_device() below in the code as suggested
  by Boris.
* Avoid writing empty pages by default (add an option to force the
  writing).
* Always skip bad blocks.
* Lightened the code by creating helpers.

Changes since v7:
-----------------
* Added Stefan R-b tags.
* Used tolower() as suggested by Stefan in lib/strto.c.
* Added a mention saying that we continue to abuse the kB suffix in
  lib/strto.c by not making a difference between kB and kiB which both
  mean "* 1024" for us. This has been added in the commit log.
* Fixed various bugs in the mtd command and in the parsers, they should
  be pretty stable now (tested with two MTD devices probed and several
  different partition configurations).
* mtdids is not deprecated at all as opposed at what I wrote in
  v6. U-Boot still uses its own MTD names (being <type><idx> like nor0
  or spi-nand1) and mtdids is still needed to do the glue.
* Removed a useless patch removing a Kconfig entry I added myself since
  during a rebase someone else also added this symbol.

Changes since v6:
-----------------
* Squashed Boris' fixes about build issues in Travis.
* Merged Stefan Roese's contributions.
* cmd: mtdparts:
  * added fallthrough comments in switch blocks deriving sizes.
  * balanced debug messages to compare freed and allocated partitions.
  * move mtdparts_init() declaration in mtd/partitions.h to be used in
    mtd command as well.
  * introduced a "compatibility" function to return what the MTD device
    name could be thanks to the mtdids environment variable (which is
    useless with the new partitioning logic).
* mtd: mtdpart:
  * reworked the way partitions are created/handled.
* cmd: mtd:
  * implement a partitioning logic that takes the best out of the MTD
    layer without re-inventing the wheel. Partitions are all freed
    correctly when the value of mtdparts changes.
  * balance get_mtd_device() by put_mtd_device() calls.
  * prevent memory leak by reorganizing the code a bit in do_mtd.
  * do not reconstruct partition list when a partition is already in use
    (complain about that instead).
  * add support for the legacy mtdids (not needed anymore if mtdparts
    directly uses the MTD device names as in Linux.
* cmd: ubi:
  * clean and simplify the partition handling a bit to make use the best
    use of the MTD layer as well and keep the code simple.

Changes since v5:
-----------------
* Included Boris fixup about the build issues.
* Added Rb/Ab tags from Jagan on patchs 20/21.

Changes since v4:
-----------------
* Added Jagan's Acked-by tags to every patch related to the
  SPI-mem/SPI-NAND addition.
* Rebased on top of master.

Changes since v3:
-----------------
* Fixed the debug messages in spi-mem to print either Rx or Tx data.
* Fixed a Kconfig error that prevented to build mtdparts with plain
  defconfig.
* Fixed a compilation error due to the above error that prevented one
  file to be compiled.
* Adapted the mtd command to probe MTD partitions also.
* Declared mtd_probe_devices() in a header so mtdparts or UBI could
  use it too (to probe all devices and MTD partitions in a clean way).
* As I worked on mtdparts, I found annoying and completely useless the
  fact that we need to prefix the environment variable with
  "mtdparts=". Canceled this obligation.
* Added one patch to allow spi-nand devices to be recognized by mtdparts
  (this is purely useless but needed to be done in order to use this
  command).
* Removed useless definitions of MTD device types in UBI code.
* Wrote a generic mtdparts environment variable parser, used by the mtd
  command.
* Used the mtd_probe_devices() function from get_mtd_info() in
  cmd/mtdparts.c to be sure the desired partition really does not exist
  (otherwise it will be probed and then found).

Changes since v2:
-----------------
* Rebased on u-boot master branch.
* Removed extra-parenthesis in
  "mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing"
* s/fiels/files/ in "mtd: move NAND fiels into a raw/ subdirectory"
* Do not describe generic SPI device properties in SPI NAND bindings.
* Changes in the mtd command:
  * Printing more information in 'mtd list' (device type, device
    characteristics)
  * Switch to do_div() instead of '(u32)value64b % value32b' which only
    worked because value32b was a power of 2.
  * Removed erase.chip option.
  * By default, erase/read/write happen on the full MTD device while a
    dump will only work on a single page.

Changes since v1:
-----------------
* Fixed the nand_memorg structure of the MX35LF2GE4AB chip.
* Added Reviewed-by tags from Jagan.
* Backported and squashed two patches fixing things in the SPI NAND core
  received on the Linux ML.
* Backported more changes in mtdcore.c from Linux.
* Added a patch to add a fallback on mtd->_read/_write() in mtdcore.c
  when mtd->_read/write_oob() is not supported.
* Removed the DT changes, useless as the DTs are not available in
  mainline yet.
* Addressed Boris/Stefan comments on the 'mtd' command.
* Added support for multi-pages OOB read/write.


Miquel Raynal (7):
  mtd: uclass: add probe function
  mtd: mtdpart: add a generic mtdparts-like parser
  mtd: uboot: search for an equivalent MTD name with the mtdids
  mtd: mtdpart: implement proper partition handling
  cmd: mtd: add 'mtd' command
  cmd: ubi: clean the partition handling
  cmd: mtdparts: describe as legacy

 cmd/Kconfig                    |  18 +-
 cmd/Makefile                   |   1 +
 cmd/mtd.c                      | 473 +++++++++++++++++++++++++
 cmd/ubi.c                      |  96 ++---
 drivers/mtd/Makefile           |   2 +-
 drivers/mtd/mtd-uclass.c       |  16 +
 drivers/mtd/mtd_uboot.c        | 224 +++++++++++-
 drivers/mtd/mtdcore.c          |   2 +
 drivers/mtd/mtdpart.c          | 623 ++++++++++++++++++++-------------
 include/linux/mtd/mtd.h        |  37 ++
 include/linux/mtd/partitions.h |  22 +-
 include/mtd.h                  |  18 +
 12 files changed, 1217 insertions(+), 315 deletions(-)
 create mode 100644 cmd/mtd.c

-- 
2.17.1

             reply	other threads:[~2018-10-01 13:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 13:43 Miquel Raynal [this message]
2018-10-01 13:43 ` [U-Boot] [PATCH v13 1/7] mtd: uclass: add probe function Miquel Raynal
2018-10-01 13:43 ` [U-Boot] [PATCH v13 2/7] mtd: mtdpart: add a generic mtdparts-like parser Miquel Raynal
2018-10-01 13:43 ` [U-Boot] [PATCH v13 3/7] mtd: uboot: search for an equivalent MTD name with the mtdids Miquel Raynal
2018-10-01 13:43 ` [U-Boot] [PATCH v13 4/7] mtd: mtdpart: implement proper partition handling Miquel Raynal
2018-10-01 13:43 ` [U-Boot] [PATCH v13 5/7] cmd: mtd: add 'mtd' command Miquel Raynal
2018-10-01 16:19   ` Jagan Teki
2018-10-01 20:39     ` Miquel Raynal
2018-10-03 12:35   ` Adam Ford
2018-10-03 12:42     ` Miquel Raynal
2018-10-03 12:47       ` Adam Ford
2018-10-03 12:57         ` Miquel Raynal
2018-10-03 13:35           ` Miquel Raynal
2018-10-03 13:41             ` Adam Ford
2018-10-08 16:13               ` Adam Ford
2018-10-08 16:28                 ` Boris Brezillon
2018-10-08 16:52                   ` Adam Ford
2018-10-08 16:58                     ` Adam Ford
2018-10-08 17:27                       ` Boris Brezillon
2018-10-08 17:46   ` Boris Brezillon
2018-10-08 18:26     ` Adam Ford
2018-10-08 19:07     ` Thomas Petazzoni
2018-10-08 19:14       ` Adam Ford
2018-10-01 13:43 ` [U-Boot] [PATCH v13 6/7] cmd: ubi: clean the partition handling Miquel Raynal
2018-10-01 13:43 ` [U-Boot] [PATCH v13 7/7] cmd: mtdparts: describe as legacy Miquel Raynal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181001134331.9756-1-miquel.raynal@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.