SPI-NAND support
Subsystems (16)
Miquel Raynal
maintainerv6 cover SPI-NAND support
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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- Support for spi-nand devices in mtdparts.
To test your SPI-NAND device with U-Boot simply follow these lines:
Quoted 3 lines
setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
ubi part bar # create a static UBI volume in the bar partition
mtd list # show the current MTD devices/partitions
Thanks,
Miquèl
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.
Boris Brezillon (7):
mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
mtd: Add sanity checks in mtd_write/read_oob()
mtd: nand: Add core infrastructure to deal with NAND devices
mtd: nand: Pass mode information to nand_page_io_req
spi: Extend the core to ease integration of SPI memory controllers
mtd: spinand: Add initial support for the MX35LF1GE4AB chip
dt-bindings: Add bindings for SPI NAND devices
Brian Norris (1):
mtd: add get/set of_node/flash_node helpers
Ezequiel Garcia (1):
mtd: Uninline mtd_write_oob and move it to mtdcore.c
Frieder Schrempf (1):
mtd: spinand: Add initial support for Winbond W25M02GV
Miquel Raynal (19):
mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing
mtd: fix build issue with includes
mtd: move definitions to enlarge their range
mtd: move all flash categories inside MTD submenu
mtd: move NAND files into a raw/ subdirectory
mtd: rename nand into rawnand in Kconfig prompt
mtd: spinand: Add initial support for the MX35LF2GE4AB chip
mtd: declare MTD_PARTITIONS symbol in Kconfig
mtd: mtdpart: balance debug messages
cmd: ubi: delete useless and misleading definitions
cmd: mtdparts: add fallthrough in switch statement
cmd: mtdparts: accept spi-nand devices
cmd: mtdparts: add a generic 'mtdparts' parser
mtd: uclass: add probe function
mtd: move mtdparts_init() declaration
mtd: mtdpart: implement proper partition handling
cmd: mtd: add 'mtd' command
cmd: mtdparts: try to probe the MTD devices as a fallback
cmd: ubi: clean the partition handling
Peter Pan (2):
mtd: nand: Add core infrastructure to support SPI NANDs
mtd: spinand: Add initial support for Micron MT29F2G01ABAGD
MAINTAINERS | 6 +-
Makefile | 2 +-
README | 6 +-
arch/arm/mach-uniphier/board_late_init.c | 2 +-
cmd/Kconfig | 7 +
cmd/Makefile | 1 +
cmd/flash.c | 1 +
cmd/jffs2.c | 1 +
cmd/mtd.c | 513 +++++++
cmd/mtdparts.c | 134 +-
cmd/nand.c | 1 +
cmd/ubi.c | 100 +-
common/fdt_support.c | 1 +
common/spl/Kconfig | 2 +-
common/spl/spl_spi.c | 2 +-
doc/README.SPL | 4 +-
doc/README.arm-relocation | 2 +-
doc/README.nand | 6 +-
doc/README.zynq | 2 +-
doc/device-tree-bindings/mtd/spi-nand.txt | 5 +
drivers/Makefile | 2 +-
drivers/dfu/dfu_nand.c | 1 +
drivers/fastboot/fb_nand.c | 1 +
drivers/mtd/Kconfig | 7 +-
drivers/mtd/Makefile | 4 +-
drivers/mtd/mtd-uclass.c | 20 +
drivers/mtd/mtd_uboot.c | 1 +
drivers/mtd/mtdcore.c | 106 +-
drivers/mtd/mtdcore.h | 6 -
drivers/mtd/mtdpart.c | 389 +++--
drivers/mtd/nand/Kconfig | 299 +---
drivers/mtd/nand/Makefile | 78 +-
drivers/mtd/nand/bbt.c | 132 ++
drivers/mtd/nand/core.c | 243 ++++
drivers/mtd/nand/raw/Kconfig | 297 ++++
drivers/mtd/nand/raw/Makefile | 77 +
drivers/mtd/nand/{ => raw}/am335x_spl_bch.c | 0
drivers/mtd/nand/{ => raw}/arasan_nfc.c | 0
drivers/mtd/nand/{ => raw}/atmel_nand.c | 0
drivers/mtd/nand/{ => raw}/atmel_nand_ecc.h | 0
drivers/mtd/nand/{ => raw}/davinci_nand.c | 2 +-
drivers/mtd/nand/{ => raw}/denali.c | 0
drivers/mtd/nand/{ => raw}/denali.h | 0
drivers/mtd/nand/{ => raw}/denali_dt.c | 0
drivers/mtd/nand/{ => raw}/denali_spl.c | 0
drivers/mtd/nand/{ => raw}/fsl_elbc_nand.c | 0
drivers/mtd/nand/{ => raw}/fsl_elbc_spl.c | 0
drivers/mtd/nand/{ => raw}/fsl_ifc_nand.c | 0
drivers/mtd/nand/{ => raw}/fsl_ifc_spl.c | 0
drivers/mtd/nand/{ => raw}/fsl_upm.c | 0
drivers/mtd/nand/{ => raw}/fsmc_nand.c | 0
drivers/mtd/nand/{ => raw}/kb9202_nand.c | 0
drivers/mtd/nand/{ => raw}/kirkwood_nand.c | 0
drivers/mtd/nand/{ => raw}/kmeter1_nand.c | 0
drivers/mtd/nand/{ => raw}/lpc32xx_nand_mlc.c | 0
drivers/mtd/nand/{ => raw}/lpc32xx_nand_slc.c | 0
drivers/mtd/nand/{ => raw}/mxc_nand.c | 0
drivers/mtd/nand/{ => raw}/mxc_nand.h | 0
drivers/mtd/nand/{ => raw}/mxc_nand_spl.c | 0
drivers/mtd/nand/{ => raw}/mxs_nand.c | 0
drivers/mtd/nand/{ => raw}/mxs_nand.h | 0
drivers/mtd/nand/{ => raw}/mxs_nand_dt.c | 0
drivers/mtd/nand/{ => raw}/mxs_nand_spl.c | 0
drivers/mtd/nand/{ => raw}/nand.c | 0
drivers/mtd/nand/{ => raw}/nand_base.c | 56 -
drivers/mtd/nand/{ => raw}/nand_bbt.c | 0
drivers/mtd/nand/{ => raw}/nand_bch.c | 0
drivers/mtd/nand/{ => raw}/nand_ecc.c | 2 +-
drivers/mtd/nand/{ => raw}/nand_ids.c | 0
drivers/mtd/nand/{ => raw}/nand_plat.c | 0
drivers/mtd/nand/{ => raw}/nand_spl_load.c | 0
drivers/mtd/nand/{ => raw}/nand_spl_loaders.c | 0
drivers/mtd/nand/{ => raw}/nand_spl_simple.c | 0
drivers/mtd/nand/{ => raw}/nand_timings.c | 0
drivers/mtd/nand/{ => raw}/nand_util.c | 2 +-
drivers/mtd/nand/{ => raw}/omap_elm.c | 0
drivers/mtd/nand/{ => raw}/omap_gpmc.c | 0
drivers/mtd/nand/{ => raw}/pxa3xx_nand.c | 2 +-
drivers/mtd/nand/{ => raw}/pxa3xx_nand.h | 0
drivers/mtd/nand/{ => raw}/sunxi_nand.c | 0
drivers/mtd/nand/{ => raw}/sunxi_nand_spl.c | 0
drivers/mtd/nand/{ => raw}/tegra_nand.c | 0
drivers/mtd/nand/{ => raw}/tegra_nand.h | 0
drivers/mtd/nand/{ => raw}/vf610_nfc.c | 0
drivers/mtd/nand/{ => raw}/zynq_nand.c | 0
drivers/mtd/nand/spi/Kconfig | 7 +
drivers/mtd/nand/spi/Makefile | 4 +
drivers/mtd/nand/spi/core.c | 1254 +++++++++++++++++
drivers/mtd/nand/spi/macronix.c | 146 ++
drivers/mtd/nand/spi/micron.c | 135 ++
drivers/mtd/nand/spi/winbond.c | 143 ++
drivers/mtd/onenand/onenand_base.c | 2 -
drivers/spi/Kconfig | 7 +
drivers/spi/Makefile | 1 +
drivers/spi/spi-mem.c | 501 +++++++
include/configs/MPC8313ERDB.h | 2 +-
include/jffs2/load_kernel.h | 8 +-
include/linux/mtd/mtd.h | 69 +-
include/linux/mtd/nand.h | 734 ++++++++++
include/linux/mtd/partitions.h | 7 +-
include/linux/mtd/spinand.h | 432 ++++++
include/spi-mem.h | 258 ++++
include/spi.h | 11 +
103 files changed, 5441 insertions(+), 805 deletions(-)
create mode 100644 cmd/mtd.c
create mode 100644 doc/device-tree-bindings/mtd/spi-nand.txt
create mode 100644 drivers/mtd/nand/bbt.c
create mode 100644 drivers/mtd/nand/core.c
create mode 100644 drivers/mtd/nand/raw/Kconfig
create mode 100644 drivers/mtd/nand/raw/Makefile
rename drivers/mtd/nand/{ => raw}/am335x_spl_bch.c (100%)
rename drivers/mtd/nand/{ => raw}/arasan_nfc.c (100%)
rename drivers/mtd/nand/{ => raw}/atmel_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/atmel_nand_ecc.h (100%)
rename drivers/mtd/nand/{ => raw}/davinci_nand.c (99%)
rename drivers/mtd/nand/{ => raw}/denali.c (100%)
rename drivers/mtd/nand/{ => raw}/denali.h (100%)
rename drivers/mtd/nand/{ => raw}/denali_dt.c (100%)
rename drivers/mtd/nand/{ => raw}/denali_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_elbc_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_elbc_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_ifc_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_ifc_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_upm.c (100%)
rename drivers/mtd/nand/{ => raw}/fsmc_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/kb9202_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/kirkwood_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/kmeter1_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/lpc32xx_nand_mlc.c (100%)
rename drivers/mtd/nand/{ => raw}/lpc32xx_nand_slc.c (100%)
rename drivers/mtd/nand/{ => raw}/mxc_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/mxc_nand.h (100%)
rename drivers/mtd/nand/{ => raw}/mxc_nand_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/mxs_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/mxs_nand.h (100%)
rename drivers/mtd/nand/{ => raw}/mxs_nand_dt.c (100%)
rename drivers/mtd/nand/{ => raw}/mxs_nand_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/nand.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_base.c (98%)
rename drivers/mtd/nand/{ => raw}/nand_bbt.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_bch.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_ecc.c (99%)
rename drivers/mtd/nand/{ => raw}/nand_ids.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_plat.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_spl_load.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_spl_loaders.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_spl_simple.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_timings.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_util.c (99%)
rename drivers/mtd/nand/{ => raw}/omap_elm.c (100%)
rename drivers/mtd/nand/{ => raw}/omap_gpmc.c (100%)
rename drivers/mtd/nand/{ => raw}/pxa3xx_nand.c (99%)
rename drivers/mtd/nand/{ => raw}/pxa3xx_nand.h (100%)
rename drivers/mtd/nand/{ => raw}/sunxi_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/sunxi_nand_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/tegra_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/tegra_nand.h (100%)
rename drivers/mtd/nand/{ => raw}/vf610_nfc.c (100%)
rename drivers/mtd/nand/{ => raw}/zynq_nand.c (100%)
create mode 100644 drivers/mtd/nand/spi/Kconfig
create mode 100644 drivers/mtd/nand/spi/Makefile
create mode 100644 drivers/mtd/nand/spi/core.c
create mode 100644 drivers/mtd/nand/spi/macronix.c
create mode 100644 drivers/mtd/nand/spi/micron.c
create mode 100644 drivers/mtd/nand/spi/winbond.c
create mode 100644 drivers/spi/spi-mem.c
create mode 100644 include/linux/mtd/nand.h
create mode 100644 include/linux/mtd/spinand.h
create mode 100644 include/spi-mem.hSignature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 1/31 mtd: Fallback to ->_read/write_oob() when ->_read/write() is missing
From: Boris Brezillon <[email protected]>
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.
--- drivers/mtd/mtdcore.c | 31 +++++++++++++++-- drivers/mtd/mtdpart.c | 6 ++-- drivers/mtd/nand/nand_base.c | 56 ------------------------------ drivers/mtd/onenand/onenand_base.c | 2 -- 4 files changed, 33 insertions(+), 62 deletions(-)
drivers/mtd/mtdcore.c +29 -2
@@ -937,7 +937,20 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,* representing the maximum number of bitflips that were corrected on * any one ecc region (if applicable; zero otherwise). */ - ret_code = mtd->_read (mtd, from, len, retlen, buf); +if (mtd->_read) { + ret_code = mtd->_read (mtd, from, len, retlen, buf); + }else if (mtd->_read_oob) { +struct mtd_oob_ops ops = { + .len = len, + .datbuf = buf, + }; + + ret_code = mtd->_read_oob (mtd, from, &ops); + *retlen = ops.retlen; + }else { +return -ENOTSUPP ; + } +if (unlikely (ret_code <0 ))return ret_code;if (mtd->ecc_strength ==0 )
@@ -952,10 +965,24 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, *retlen =0 ;if (to <0 || to > mtd->size || len > mtd->size - to)return -EINVAL ; -if (!mtd->_write || !(mtd->flags &MTD_WRITEABLE )) +if ((!mtd->_write && !mtd->_write_oob) || + !(mtd->flags &MTD_WRITEABLE ))return -EROFS ;if (!len)return 0 ; + +if (!mtd->_write) { +struct mtd_oob_ops ops = { + .len = len, + .datbuf = (u8 *)buf, + }; +int ret; + + ret = mtd->_write_oob (mtd, to, &ops); + *retlen = ops.retlen; +return ret; + } +return mtd->_write (mtd, to, len, retlen, buf); }EXPORT_SYMBOL_GPL (mtd_write);
drivers/mtd/mtdpart.c +4 -2
@@ -417,8 +417,10 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, slave->mtd.dev.parent = master->dev.parent;#endif - slave->mtd._read = part_read; - slave->mtd._write = part_write; +if (master->_read) + slave->mtd._read = part_read; +if (master->_write) + slave->mtd._write = part_write;if (master->_panic_write) slave->mtd._panic_write = part_panic_write;
drivers/mtd/nand/nand_base.c +0 -56
74 lines not on this page · raw message
drivers/mtd/onenand/onenand_base.c +0 -2
@@ -2656,8 +2656,6 @@ int onenand_probe(struct mtd_info *mtd) mtd->flags =MTD_CAP_NANDFLASH ; mtd->_erase = onenand_erase; - mtd->_read = onenand_read; - mtd->_write = onenand_write; mtd->_read_oob = onenand_read_oob; mtd->_write_oob = onenand_write_oob; mtd->_sync = onenand_sync;
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 2/31 mtd: Uninline mtd_write_oob and move it to mtdcore.c
In reply to Miquel RaynalFrom: Ezequiel Garcia <[email protected]>
There's no reason for having mtd_write_oob inlined in mtd.h header. Move it to mtdcore.c where it belongs.
--- drivers/mtd/mtdcore.c | 12 ++++++++++++ include/linux/mtd/mtd.h | 12 +----------- 2 files changed, 13 insertions(+), 11 deletions(-)
drivers/mtd/mtdcore.c +12 -0
@@ -1031,6 +1031,18 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) }EXPORT_SYMBOL_GPL (mtd_read_oob); +int mtd_write_oob (struct mtd_info *mtd,loff_t to, +struct mtd_oob_ops *ops) +{ + ops->retlen = ops->oobretlen =0 ; +if (!mtd->_write_oob) +return -EOPNOTSUPP ; +if (!(mtd->flags &MTD_WRITEABLE )) +return -EROFS ; +return mtd->_write_oob (mtd, to, ops); +} +EXPORT_SYMBOL_GPL (mtd_write_oob); +/** * mtd_ooblayout_ecc - Get the OOB region definition of a specific ECC section * @mtd: MTD device structure
include/linux/mtd/mtd.h +1 -11
@@ -351,17 +351,7 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);int mtd_read_oob (struct mtd_info *mtd,loff_t from,struct mtd_oob_ops *ops); - -static inline int mtd_write_oob (struct mtd_info *mtd,loff_t to, -struct mtd_oob_ops *ops) -{ - ops->retlen = ops->oobretlen =0 ; -if (!mtd->_write_oob) -return -EOPNOTSUPP ; -if (!(mtd->flags &MTD_WRITEABLE )) -return -EROFS ; -return mtd->_write_oob (mtd, to, ops); -} +int mtd_write_oob (struct mtd_info *mtd,loff_t to,struct mtd_oob_ops *ops);int mtd_get_fact_prot_info (struct mtd_info *mtd,size_t len,size_t *retlen,struct otp_info *buf);
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 3/31 mtd: Add sanity checks in mtd_write/read_oob()
In reply to Miquel RaynalFrom: Boris Brezillon <[email protected]>
Unlike what's done in mtd_read/write(), there are no checks to make sure the parameters passed to mtd_read/write_oob() are consistent, which forces implementers of ->_read/write_oob() to do it, which in turn leads to code duplication and possibly errors in the logic.
Do general sanity checks, like ops fields consistency and range checking.
--- drivers/mtd/mtdcore.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
drivers/mtd/mtdcore.c +45 -0
@@ -1010,12 +1010,50 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, }EXPORT_SYMBOL_GPL (mtd_panic_write); +static int mtd_check_oob_ops (struct mtd_info *mtd,loff_t offs, +struct mtd_oob_ops *ops) +{ +/* +* Some users are setting ->datbuf or ->oobbuf to NULL, but are leaving +* ->len or ->ooblen uninitialized. Force ->len and ->ooblen to 0 in +* this case. +*/ +if (!ops->datbuf) + ops->len =0 ; + +if (!ops->oobbuf) + ops->ooblen =0 ; + +if (offs <0 || offs + ops->len > mtd->size) +return -EINVAL ; + +if (ops->ooblen) { +u64 maxooblen; + +if (ops->ooboffs >=mtd_oobavail (mtd, ops)) +return -EINVAL ; + + maxooblen = ((mtd_div_by_ws (mtd->size, mtd) - +mtd_div_by_ws (offs, mtd)) * +mtd_oobavail (mtd, ops)) - ops->ooboffs; +if (ops->ooblen > maxooblen) +return -EINVAL ; + } + +return 0 ; +} +int mtd_read_oob (struct mtd_info *mtd,loff_t from,struct mtd_oob_ops *ops) {int ret_code; ops->retlen = ops->oobretlen =0 ;if (!mtd->_read_oob)return -EOPNOTSUPP ; + + ret_code =mtd_check_oob_ops (mtd, from, ops); +if (ret_code) +return ret_code; +/* * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics * similar to mtd->_read(), returning a non-negative integer
@@ -1034,11 +1072,18 @@ EXPORT_SYMBOL_GPL(mtd_read_oob);int mtd_write_oob (struct mtd_info *mtd,loff_t to,struct mtd_oob_ops *ops) { +int ret; + ops->retlen = ops->oobretlen =0 ;if (!mtd->_write_oob)return -EOPNOTSUPP ;if (!(mtd->flags &MTD_WRITEABLE ))return -EROFS ; + + ret =mtd_check_oob_ops (mtd, to, ops); +if (ret) +return ret; +return mtd->_write_oob (mtd, to, ops); }EXPORT_SYMBOL_GPL (mtd_write_oob);
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 4/31 mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing
In reply to Miquel RaynalSome MTD sublayers/drivers are implementing ->_read/write() and not ->_read/write_oob().
While for NAND devices both are usually valid, for NOR devices, using the _oob variant has no real meaning. But, as the MTD layer is supposed to hide as much as possible the flash complexity to the user, there is no reason to error out while it is just a matter of rewritting things internally.
Add a fallback on mtd->_read() (resp. mtd->_write()) when the user calls mtd_read_oob() (resp. mtd_write_oob()) while mtd->_read_oob() (resp. mtd->_write_oob) is not implemented. There is already a fallback on the _oob variant if the former is used.
--- drivers/mtd/mtdcore.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/mtd/mtdcore.c +20 -6
@@ -1047,20 +1047,27 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) {int ret_code; ops->retlen = ops->oobretlen =0 ; -if (!mtd->_read_oob) -return -EOPNOTSUPP ; ret_code =mtd_check_oob_ops (mtd, from, ops);if (ret_code)return ret_code; +/* Check the validity of a potential fallback on mtd->_read */ +if (!mtd->_read_oob && (!mtd->_read || ops->oobbuf)) +return -EOPNOTSUPP ; + +if (mtd->_read_oob) + ret_code = mtd->_read_oob (mtd, from, ops); +else + ret_code = mtd->_read (mtd, from, ops->len, &ops->retlen, + ops->datbuf); +/* * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics * similar to mtd->_read(), returning a non-negative integer * representing max bitflips. In other cases, mtd->_read_oob() may * return -EUCLEAN. In all cases, perform similar logic to mtd_read(). */ - ret_code = mtd->_read_oob (mtd, from, ops);if (unlikely (ret_code <0 ))return ret_code;if (mtd->ecc_strength ==0 )
@@ -1075,8 +1082,7 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,int ret; ops->retlen = ops->oobretlen =0 ; -if (!mtd->_write_oob) -return -EOPNOTSUPP ; +if (!(mtd->flags &MTD_WRITEABLE ))return -EROFS ;
@@ -1084,7 +1090,15 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,if (ret)return ret; -return mtd->_write_oob (mtd, to, ops); +/* Check the validity of a potential fallback on mtd->_write */ +if (!mtd->_write_oob && (!mtd->_write || ops->oobbuf)) +return -EOPNOTSUPP ; + +if (mtd->_write_oob) +return mtd->_write_oob (mtd, to, ops); +else +return mtd->_write (mtd, to, ops->len, &ops->retlen, + ops->datbuf); }EXPORT_SYMBOL_GPL (mtd_write_oob);
Signature · 1 line
2.17.1
PATCH v6 4/31 mtd: Fallback to ->_read/write() when ->_read/write_oob() is missing
Quoted 9 lines · On Thu, 16 Aug 2018 17:30:02 +0200 Miquel Raynal <[email protected]>…
Some MTD sublayers/drivers are implementing ->_read/write() and not ->_read/write_oob().
While for NAND devices both are usually valid, for NOR devices, using the
_oobvariant has no real meaning. But, as the MTD layer is supposed to hide as much as possible the flash complexity to the user, there is no reason to error out while it is just a matter of rewritting things internally.
Quoted 6 lines
Add a fallback on
mtd->_read()(resp.mtd->_write()) when the user callsmtd_read_oob()(resp.mtd_write_oob()) whilemtd->_read_oob()(resp.mtd->_write_oob) is not implemented. There is already a fallback on the_oobvariant if the former is used.Signed-off-by Miquel Raynal <[email protected]>
Quoted 66 lines
--- drivers/mtd/mtdcore.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)drivers/mtd/mtdcore.c +20
-6@@ -1047,20 +1047,27 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) {int ret_code; ops->retlen = ops->oobretlen =0 ; -if (!mtd->_read_oob) -return -EOPNOTSUPP ; ret_code =mtd_check_oob_ops (mtd, from, ops);if (ret_code)return ret_code; +/* Check the validity of a potential fallback on mtd->_read */ +if (!mtd->_read_oob && (!mtd->_read || ops->oobbuf)) +return -EOPNOTSUPP ; + +if (mtd->_read_oob) + ret_code = mtd->_read_oob (mtd, from, ops); +else + ret_code = mtd->_read (mtd, from, ops->len, &ops->retlen, + ops->datbuf); +/* * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics * similar to mtd->_read(), returning a non-negative integer * representing max bitflips. In other cases, mtd->_read_oob() may * return -EUCLEAN. In all cases, perform similar logic to mtd_read(). */ - ret_code = mtd->_read_oob (mtd, from, ops);if (unlikely (ret_code <0 ))return ret_code;if (mtd->ecc_strength ==0 )@@ -1075,8 +1082,7 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,int ret; ops->retlen = ops->oobretlen =0 ; -if (!mtd->_write_oob) -return -EOPNOTSUPP ; +if (!(mtd->flags &MTD_WRITEABLE ))return -EROFS ;@@ -1084,7 +1090,15 @@ int mtd_write_oob(struct mtd_info *mtd, loff_t to,if (ret)return ret; -return mtd->_write_oob (mtd, to, ops); +/* Check the validity of a potential fallback on mtd->_write */ +if (!mtd->_write_oob && (!mtd->_write || ops->oobbuf)) +return -EOPNOTSUPP ; + +if (mtd->_write_oob) +return mtd->_write_oob (mtd, to, ops); +else +return mtd->_write (mtd, to, ops->len, &ops->retlen, + ops->datbuf); }EXPORT_SYMBOL_GPL (mtd_write_oob);
Miquel Raynal
maintainerPATCH v6 5/31 mtd: add get/set of_node/flash_node helpers
In reply to Miquel RaynalFrom: Brian Norris <[email protected]>
We are going to begin using the mtd->dev.of_node field for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions on spi_nor (and nand_chip eventually) too, so get that ready with their own helpers.
--- include/linux/mtd/mtd.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
include/linux/mtd/mtd.h +25 -0
@@ -306,6 +306,31 @@ struct mtd_info {int usecount; }; +#if IS_ENABLED (CONFIG_DM ) +static inline void mtd_set_of_node (struct mtd_info *mtd, +const struct device_node *np) +{ + mtd->dev->node.np = np; +} + +static inline const struct device_node *mtd_get_of_node (struct mtd_info *mtd) +{ +return mtd->dev->node.np; +} +#else +struct device_node ; + +static inline void mtd_set_of_node (struct mtd_info *mtd, +const struct device_node *np) +{ +} + +static inline const struct device_node *mtd_get_of_node (struct mtd_info *mtd) +{ +return NULL ; +} +#endif +int mtd_ooblayout_ecc (struct mtd_info *mtd,int section,struct mtd_oob_region *oobecc); int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 6/31 mtd: fix build issue with includes
In reply to Miquel RaynalFix build errors produced by mtd.h and dm/device.h if not included in the right order.
--- include/linux/mtd/mtd.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/mtd/mtd.h +3 -0
@@ -21,6 +21,9 @@#include <mtd/mtd-abi.h> #include <linux/errno.h> #include <div64.h> +#if IS_ENABLED (CONFIG_DM ) +#include <dm/device.h> +#endif #define MAX_MTD_DEVICES 32#endif
Signature · 1 line
2.17.1
PATCH v6 6/31 mtd: fix build issue with includes
Quoted 5 lines · On Thu, 16 Aug 2018 17:30:04 +0200 Miquel Raynal <[email protected]>…
Fix build errors produced by
mtd.handdm/device.hif not included in the right order.Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Jagan Teki <[email protected]>
I'm pretty sure this patch is not needed, the build failure has been fixed in patch 5.
Quoted 18 lines
--- include/linux/mtd/mtd.h | 3 +++ 1 file changed, 3 insertions(+)include/linux/mtd/mtd.h +3
-0@@ -21,6 +21,9 @@#include <mtd/mtd-abi.h> #include <linux/errno.h> #include <div64.h> +#if IS_ENABLED (CONFIG_DM ) +#include <dm/device.h> +#endif #define MAX_MTD_DEVICES 32#endif
PATCH v6 6/31 mtd: fix build issue with includes
Quoted 11 lines · On Thu, 16 Aug 2018 17:33:18 +0200 Boris Brezillon…
Quoted 5 lines · On Thu, 16 Aug 2018 17:30:04 +0200 Miquel Raynal <[email protected]>…
Fix build errors produced by
mtd.handdm/device.hif not included in the right order.Signed-off-by Miquel Raynal <[email protected]>Reviewed-by Jagan Teki <[email protected]>I'm pretty sure this patch is not needed, the build failure has been fixed in patch 5.
My bad. It's needed, but it should be squashed in patch 5, since this is patch 5 who introduces the error.
Quoted 20 lines
Quoted 19 lines
--- include/linux/mtd/mtd.h | 3 +++ 1 file changed, 3 insertions(+)include/linux/mtd/mtd.h +3
-0@@ -21,6 +21,9 @@#include <mtd/mtd-abi.h> #include <linux/errno.h> #include <div64.h> +#if IS_ENABLED (CONFIG_DM ) +#include <dm/device.h> +#endif #define MAX_MTD_DEVICES 32#endif
Miquel Raynal
maintainerPATCH v6 7/31 mtd: move definitions to enlarge their range
In reply to Miquel RaynalSome helpers might be useful in a future 'mtd' U-Boot command to parse MTD device list.
--- drivers/mtd/mtdcore.h | 6 ------ include/linux/mtd/mtd.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/mtd/mtdcore.h +0 -6
@@ -5,7 +5,6 @@extern struct mutex mtd_table_mutex; -struct mtd_info *__mtd_next_device (int i);int add_mtd_device (struct mtd_info *mtd);int del_mtd_device (struct mtd_info *mtd);int add_mtd_partitions (struct mtd_info *,const struct mtd_partition *,int );
@@ -16,8 +15,3 @@ int parse_mtd_partitions(struct mtd_info *master, const char * const *types,int __init init_mtdchar (void ); void __exit cleanup_mtdchar(void); - -#define mtd_for_each_device (mtd) \ - for ((mtd) = __mtd_next_device(0); \ - (mtd) != NULL; \ - (mtd) = __mtd_next_device(mtd->index + 1))
include/linux/mtd/mtd.h +6 -0
@@ -533,6 +533,12 @@ int del_mtd_device(struct mtd_info *mtd);int add_mtd_partitions (struct mtd_info *,const struct mtd_partition *,int );int del_mtd_partitions (struct mtd_info *); +struct mtd_info *__mtd_next_device (int i); +#define mtd_for_each_device (mtd) \ + for ((mtd) = __mtd_next_device(0); \ + (mtd) != NULL; \ + (mtd) = __mtd_next_device(mtd->index + 1)) +int mtd_arg_off (const char *arg,int *idx,loff_t *off,loff_t *size,loff_t *maxsize,int devtype,uint64_t chipsize); int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 8/31 mtd: move all flash categories inside MTD submenu
In reply to Miquel RaynalThere is no reason to have NAND, SPI flashes and UBI sections outside of the MTD submenu in Kconfig.
--- drivers/mtd/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/Kconfig +2 -2
@@ -59,10 +59,10 @@ config RENESAS_RPC_HF This enables access to Hyperflash memory through the Renesas RCar Gen3 RPC controller. -endmenu - source "drivers/mtd/nand/Kconfig" source "drivers/mtd/spi/Kconfig" source "drivers/mtd/ubi/Kconfig" + +endmenu
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 9/31 mtd: move NAND files into a raw/ subdirectory
In reply to Miquel RaynalNAND flavors, like serial and parallel, have a lot in common and would benefit to share code. Let's move raw (parallel) NAND specific code in a raw/ subdirectory, to ease the addition of a core file in nand/ and the introduction of a spi/ subdirectory specific to SPI NANDs.
---
MAINTAINERS | 6 +-
Makefile | 2 +-
README | 6 +-
arch/arm/mach-uniphier/board_late_init.c | 2 +-
common/spl/Kconfig | 2 +-
common/spl/spl_spi.c | 2 +-
doc/README.SPL | 4 +-
doc/README.arm-relocation | 2 +-
doc/README.nand | 6 +-
doc/README.zynq | 2 +-
drivers/Makefile | 2 +-
drivers/mtd/Makefile | 2 +
drivers/mtd/nand/Kconfig | 298 +-----------------
drivers/mtd/nand/Makefile | 75 -----
drivers/mtd/nand/raw/Kconfig | 297 +++++++++++++++++
drivers/mtd/nand/raw/Makefile | 77 +++++
drivers/mtd/nand/{ => raw}/am335x_spl_bch.c | 0
drivers/mtd/nand/{ => raw}/arasan_nfc.c | 0
drivers/mtd/nand/{ => raw}/atmel_nand.c | 0
drivers/mtd/nand/{ => raw}/atmel_nand_ecc.h | 0
drivers/mtd/nand/{ => raw}/davinci_nand.c | 2 +-
drivers/mtd/nand/{ => raw}/denali.c | 0
drivers/mtd/nand/{ => raw}/denali.h | 0
drivers/mtd/nand/{ => raw}/denali_dt.c | 0
drivers/mtd/nand/{ => raw}/denali_spl.c | 0
drivers/mtd/nand/{ => raw}/fsl_elbc_nand.c | 0
drivers/mtd/nand/{ => raw}/fsl_elbc_spl.c | 0
drivers/mtd/nand/{ => raw}/fsl_ifc_nand.c | 0
drivers/mtd/nand/{ => raw}/fsl_ifc_spl.c | 0
drivers/mtd/nand/{ => raw}/fsl_upm.c | 0
drivers/mtd/nand/{ => raw}/fsmc_nand.c | 0
drivers/mtd/nand/{ => raw}/kb9202_nand.c | 0
drivers/mtd/nand/{ => raw}/kirkwood_nand.c | 0
drivers/mtd/nand/{ => raw}/kmeter1_nand.c | 0
drivers/mtd/nand/{ => raw}/lpc32xx_nand_mlc.c | 0
drivers/mtd/nand/{ => raw}/lpc32xx_nand_slc.c | 0
drivers/mtd/nand/{ => raw}/mxc_nand.c | 0
drivers/mtd/nand/{ => raw}/mxc_nand.h | 0
drivers/mtd/nand/{ => raw}/mxc_nand_spl.c | 0
drivers/mtd/nand/{ => raw}/mxs_nand.c | 0
drivers/mtd/nand/{ => raw}/mxs_nand.h | 0
drivers/mtd/nand/{ => raw}/mxs_nand_dt.c | 0
drivers/mtd/nand/{ => raw}/mxs_nand_spl.c | 0
drivers/mtd/nand/{ => raw}/nand.c | 0
drivers/mtd/nand/{ => raw}/nand_base.c | 0
drivers/mtd/nand/{ => raw}/nand_bbt.c | 0
drivers/mtd/nand/{ => raw}/nand_bch.c | 0
drivers/mtd/nand/{ => raw}/nand_ecc.c | 2 +-
drivers/mtd/nand/{ => raw}/nand_ids.c | 0
drivers/mtd/nand/{ => raw}/nand_plat.c | 0
drivers/mtd/nand/{ => raw}/nand_spl_load.c | 0
drivers/mtd/nand/{ => raw}/nand_spl_loaders.c | 0
drivers/mtd/nand/{ => raw}/nand_spl_simple.c | 0
drivers/mtd/nand/{ => raw}/nand_timings.c | 0
drivers/mtd/nand/{ => raw}/nand_util.c | 2 +-
drivers/mtd/nand/{ => raw}/omap_elm.c | 0
drivers/mtd/nand/{ => raw}/omap_gpmc.c | 0
drivers/mtd/nand/{ => raw}/pxa3xx_nand.c | 2 +-
drivers/mtd/nand/{ => raw}/pxa3xx_nand.h | 0
drivers/mtd/nand/{ => raw}/sunxi_nand.c | 0
drivers/mtd/nand/{ => raw}/sunxi_nand_spl.c | 0
drivers/mtd/nand/{ => raw}/tegra_nand.c | 0
drivers/mtd/nand/{ => raw}/tegra_nand.h | 0
drivers/mtd/nand/{ => raw}/vf610_nfc.c | 0
drivers/mtd/nand/{ => raw}/zynq_nand.c | 0
include/configs/MPC8313ERDB.h | 2 +-
66 files changed, 400 insertions(+), 395 deletions(-)
create mode 100644 drivers/mtd/nand/raw/Kconfig
create mode 100644 drivers/mtd/nand/raw/Makefile
rename drivers/mtd/nand/{ => raw}/am335x_spl_bch.c (100%)
rename drivers/mtd/nand/{ => raw}/arasan_nfc.c (100%)
rename drivers/mtd/nand/{ => raw}/atmel_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/atmel_nand_ecc.h (100%)
rename drivers/mtd/nand/{ => raw}/davinci_nand.c (99%)
rename drivers/mtd/nand/{ => raw}/denali.c (100%)
rename drivers/mtd/nand/{ => raw}/denali.h (100%)
rename drivers/mtd/nand/{ => raw}/denali_dt.c (100%)
rename drivers/mtd/nand/{ => raw}/denali_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_elbc_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_elbc_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_ifc_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_ifc_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/fsl_upm.c (100%)
rename drivers/mtd/nand/{ => raw}/fsmc_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/kb9202_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/kirkwood_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/kmeter1_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/lpc32xx_nand_mlc.c (100%)
rename drivers/mtd/nand/{ => raw}/lpc32xx_nand_slc.c (100%)
rename drivers/mtd/nand/{ => raw}/mxc_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/mxc_nand.h (100%)
rename drivers/mtd/nand/{ => raw}/mxc_nand_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/mxs_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/mxs_nand.h (100%)
rename drivers/mtd/nand/{ => raw}/mxs_nand_dt.c (100%)
rename drivers/mtd/nand/{ => raw}/mxs_nand_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/nand.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_base.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_bbt.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_bch.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_ecc.c (99%)
rename drivers/mtd/nand/{ => raw}/nand_ids.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_plat.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_spl_load.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_spl_loaders.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_spl_simple.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_timings.c (100%)
rename drivers/mtd/nand/{ => raw}/nand_util.c (99%)
rename drivers/mtd/nand/{ => raw}/omap_elm.c (100%)
rename drivers/mtd/nand/{ => raw}/omap_gpmc.c (100%)
rename drivers/mtd/nand/{ => raw}/pxa3xx_nand.c (99%)
rename drivers/mtd/nand/{ => raw}/pxa3xx_nand.h (100%)
rename drivers/mtd/nand/{ => raw}/sunxi_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/sunxi_nand_spl.c (100%)
rename drivers/mtd/nand/{ => raw}/tegra_nand.c (100%)
rename drivers/mtd/nand/{ => raw}/tegra_nand.h (100%)
rename drivers/mtd/nand/{ => raw}/vf610_nfc.c (100%)
rename drivers/mtd/nand/{ => raw}/zynq_nand.c (100%)MAINTAINERS +3 -3
@@ -282,7 +282,7 @@ F: drivers/i2c/i2c-cdns.c F: drivers/i2c/muxes/pca954x.c F: drivers/i2c/zynq_i2c.c F: drivers/mmc/zynq_sdhci.c -F: drivers/mtd/nand/zynq_nand.c +F: drivers/mtd/nand/raw/zynq_nand.c F: drivers/net/phy/xilinx_phy.c F: drivers/net/zynq_gem.c F: drivers/serial/serial_zynq.c
@@ -306,7 +306,7 @@ F: drivers/i2c/i2c-cdns.c F: drivers/i2c/muxes/pca954x.c F: drivers/i2c/zynq_i2c.c F: drivers/mmc/zynq_sdhci.c -F: drivers/mtd/nand/zynq_nand.c +F: drivers/mtd/nand/raw/zynq_nand.c F: drivers/net/phy/xilinx_phy.c F: drivers/net/zynq_gem.c F: drivers/serial/serial_zynq.c
@@ -443,7 +443,7 @@ NAND FLASH #M: Scott Wood <[email protected]> S: Orphaned (Since 2018-07) T: git git://git.denx.de/u-boot-nand-flash.git -F: drivers/mtd/nand/ +F: drivers/mtd/nand/raw/ NDS32 M: Macpaul Lin <[email protected]>
Makefile +1 -1
@@ -685,7 +685,7 @@ libs-y += drivers/dma/ libs-y += drivers/gpio/ libs-y += drivers/i2c/ libs-y += drivers/mtd/ -libs-$(CONFIG_CMD_NAND) += drivers/mtd/nand/ +libs-$(CONFIG_CMD_NAND) += drivers/mtd/nand/raw/ libs-y += drivers/mtd/onenand/ libs-$(CONFIG_CMD_UBI) += drivers/mtd/ubi/ libs-y += drivers/mtd/spi/
README +3 -3
@@ -3264,8 +3264,8 @@ Low Level (hardware related) configuration options: a 16 bit bus. Not all NAND drivers use this symbol. Example of drivers that use it: - - drivers/mtd/nand/ndfc.c - - drivers/mtd/nand/mxc_nand.c + - drivers/mtd/nand/raw/ndfc.c + - drivers/mtd/nand/raw/mxc_nand.c - CONFIG_SYS_NDFC_EBC0_CFG Sets the EBC0_CFG register for the NDFC. If not defined
@@ -3382,7 +3382,7 @@ Low Level (hardware related) configuration options: - CONFIG_SYS_NAND_NO_SUBPAGE_WRITE Option to disable subpage write in NAND driver driver that uses this: - drivers/mtd/nand/davinci_nand.c + drivers/mtd/nand/raw/davinci_nand.c Freescale QE/FMAN Firmware Support: -----------------------------------
arch/arm/mach-uniphier/board_late_init.c +1 -1
@@ -12,7 +12,7 @@#include <stdio.h> #include <linux/io.h> #include <linux/printk.h> -#include <../drivers/mtd/nand/denali.h> +#include <../drivers/mtd/nand/raw/denali.h> #include "init.h"
common/spl/Kconfig +1 -1
@@ -479,7 +479,7 @@ config SPL_NAND_SUPPORT help Enable support for NAND (Negative AND) flash in SPL. NAND flash can be used to allow SPL to load U-Boot from supported devices. - This enables the drivers in drivers/mtd/nand as part of an SPL + This enables the drivers in drivers/mtd/nand/raw as part of an SPL build. config SPL_NET_SUPPORT
common/spl/spl_spi.c +1 -1
@@ -2,7 +2,7 @@/* * Copyright (C) 2011 OMICRON electronics GmbH * -* based on drivers/mtd/nand/nand_spl_load.c +* based on drivers/mtd/nand/raw/nand_spl_load.c * * Copyright (C) 2011 * Heiko Schocher, DENX Software Engineering, hs at denx.de.
doc/README.SPL +2 -2
@@ -57,11 +57,11 @@ CONFIG_SPL_FAT_SUPPORT (fs/fat/libfat.o) CONFIG_SPL_EXT_SUPPORT CONFIG_SPL_LIBGENERIC_SUPPORT (lib/libgeneric.o) CONFIG_SPL_POWER_SUPPORT (drivers/power/libpower.o) -CONFIG_SPL_NAND_SUPPORT (drivers/mtd/nand/libnand.o) +CONFIG_SPL_NAND_SUPPORT (drivers/mtd/nand/raw/libnand.o) CONFIG_SPL_DRIVERS_MISC_SUPPORT (drivers/misc) CONFIG_SPL_DMA_SUPPORT (drivers/dma/libdma.o) CONFIG_SPL_POST_MEM_SUPPORT (post/drivers/memory.o) -CONFIG_SPL_NAND_LOAD (drivers/mtd/nand/nand_spl_load.o) +CONFIG_SPL_NAND_LOAD (drivers/mtd/nand/raw/nand_spl_load.o) CONFIG_SPL_SPI_LOAD (drivers/mtd/spi/spi_spl_load.o) CONFIG_SPL_RAM_DEVICE (common/spl/spl.c) CONFIG_SPL_WATCHDOG_SUPPORT (drivers/watchdog/libwatchdog.o)
doc/README.arm-relocation +1 -1
@@ -84,7 +84,7 @@ Relocation with SPL (example for the tx25 booting from NAND Flash): - cpu copies the first page from NAND to 0xbb000000 (IMX_NFC_BASE) and start with code execution on this address. -- The First page contains u-boot code from drivers/mtd/nand/mxc_nand_spl.c +- The First page contains u-boot code from drivers/mtd/nand/raw/mxc_nand_spl.c which inits the dram, cpu registers, reloacte itself to CONFIG_SPL_TEXT_BASE and loads the "real" u-boot to CONFIG_SYS_NAND_U_BOOT_DST and starts execution @CONFIG_SYS_NAND_U_BOOT_START
doc/README.nand +3 -3
@@ -116,7 +116,7 @@ Configuration Options: The maximum number of NAND chips per device to be supported. CONFIG_SYS_NAND_SELF_INIT - Traditionally, glue code in drivers/mtd/nand/nand.c has driven + Traditionally, glue code in drivers/mtd/nand/raw/nand.c has driven the initialization process -- it provides the mtd and nand structs, calls a board init function for a specific device, calls nand_scan(), and registers with mtd.
@@ -125,7 +125,7 @@ Configuration Options: run code between nand_scan_ident() and nand_scan_tail(), or other deviations from the "normal" flow. - If a board defines CONFIG_SYS_NAND_SELF_INIT, drivers/mtd/nand/nand.c + If a board defines CONFIG_SYS_NAND_SELF_INIT, drivers/mtd/nand/raw/nand.c will make one call to board_nand_init(), with no arguments. That function is responsible for calling a driver init function for each NAND device on the board, that performs all initialization
@@ -280,7 +280,7 @@ NOTE: ===== The Disk On Chip driver is currently broken and has been for some time. -There is a driver in drivers/mtd/nand, taken from Linux, that works with +There is a driver in drivers/mtd/nand/raw, taken from Linux, that works with the current NAND system but has not yet been adapted to the u-boot environment.
doc/README.zynq +1 -1
@@ -63,7 +63,7 @@ bootmode strings at runtime. spi - drivers/spi/zynq_spi.c qspi - drivers/spi/zynq_qspi.c i2c - drivers/i2c/zynq_i2c.c - nand - drivers/mtd/nand/zynq_nand.c + nand - drivers/mtd/nand/raw/zynq_nand.c - Done proper cleanups on board configurations - Added basic FDT support for zynq boards - d-cache support for zynq_gem.c
drivers/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_$(SPL_TPL_)DRIVERS_MISC_SUPPORT) += misc/ sysreset/ firmware/ obj-$(CONFIG_$(SPL_TPL_)I2C_SUPPORT) += i2c/ obj-$(CONFIG_$(SPL_TPL_)LED) += led/ obj-$(CONFIG_$(SPL_TPL_)MMC_SUPPORT) += mmc/ -obj-$(CONFIG_$(SPL_TPL_)NAND_SUPPORT) += mtd/nand/ +obj-$(CONFIG_$(SPL_TPL_)NAND_SUPPORT) += mtd/nand/raw/ obj-$(CONFIG_$(SPL_TPL_)PHY) += phy/ obj-$(CONFIG_$(SPL_TPL_)PINCTRL) += pinctrl/ obj-$(CONFIG_$(SPL_TPL_)RAM) += ram/
drivers/mtd/Makefile +2 -0
@@ -18,3 +18,5 @@ obj-$(CONFIG_FLASH_PIC32) += pic32_flash.o obj-$(CONFIG_ST_SMI) += st_smi.o obj-$(CONFIG_STM32_FLASH) += stm32_flash.o obj-$(CONFIG_RENESAS_RPC_HF) += renesas_rpc_hf.o + +obj-y += nand/
drivers/mtd/nand/Kconfig +1 -297
298 lines not on this page · raw message
drivers/mtd/nand/Makefile +0 -75
77 lines not on this page · raw message
drivers/mtd/nand/raw/Kconfig new file +297 -0
297 lines not on this page · raw message
drivers/mtd/nand/raw/Makefile new file +77 -0
77 lines not on this page · raw message
drivers/mtd/nand/raw/am335x_spl_bch.c renamed from drivers/mtd/nand/am335x_spl_bch.c +0 -0
drivers/mtd/nand/raw/arasan_nfc.c renamed from drivers/mtd/nand/arasan_nfc.c +0 -0
drivers/mtd/nand/raw/atmel_nand.c renamed from drivers/mtd/nand/atmel_nand.c +0 -0
drivers/mtd/nand/raw/atmel_nand_ecc.h renamed from drivers/mtd/nand/atmel_nand_ecc.h +0 -0
drivers/mtd/nand/raw/davinci_nand.c renamed from drivers/mtd/nand/davinci_nand.c +1 -1
@@ -9,7 +9,7 @@/* * -* linux/drivers/mtd/nand/nand_davinci.c +* linux/drivers/mtd/nand/raw/nand_davinci.c * * NAND Flash Driver *
drivers/mtd/nand/raw/denali.c renamed from drivers/mtd/nand/denali.c +0 -0
drivers/mtd/nand/raw/denali.h renamed from drivers/mtd/nand/denali.h +0 -0
drivers/mtd/nand/raw/denali_dt.c renamed from drivers/mtd/nand/denali_dt.c +0 -0
drivers/mtd/nand/raw/denali_spl.c renamed from drivers/mtd/nand/denali_spl.c +0 -0
drivers/mtd/nand/raw/fsl_elbc_nand.c renamed from drivers/mtd/nand/fsl_elbc_nand.c +0 -0
drivers/mtd/nand/raw/fsl_elbc_spl.c renamed from drivers/mtd/nand/fsl_elbc_spl.c +0 -0
drivers/mtd/nand/raw/fsl_ifc_nand.c renamed from drivers/mtd/nand/fsl_ifc_nand.c +0 -0
drivers/mtd/nand/raw/fsl_ifc_spl.c renamed from drivers/mtd/nand/fsl_ifc_spl.c +0 -0
drivers/mtd/nand/raw/fsl_upm.c renamed from drivers/mtd/nand/fsl_upm.c +0 -0
drivers/mtd/nand/raw/fsmc_nand.c renamed from drivers/mtd/nand/fsmc_nand.c +0 -0
drivers/mtd/nand/raw/kb9202_nand.c renamed from drivers/mtd/nand/kb9202_nand.c +0 -0
drivers/mtd/nand/raw/kirkwood_nand.c renamed from drivers/mtd/nand/kirkwood_nand.c +0 -0
drivers/mtd/nand/raw/kmeter1_nand.c renamed from drivers/mtd/nand/kmeter1_nand.c +0 -0
drivers/mtd/nand/raw/lpc32xx_nand_mlc.c renamed from drivers/mtd/nand/lpc32xx_nand_mlc.c +0 -0
drivers/mtd/nand/raw/lpc32xx_nand_slc.c renamed from drivers/mtd/nand/lpc32xx_nand_slc.c +0 -0
drivers/mtd/nand/raw/mxc_nand.c renamed from drivers/mtd/nand/mxc_nand.c +0 -0
drivers/mtd/nand/raw/mxc_nand.h renamed from drivers/mtd/nand/mxc_nand.h +0 -0
drivers/mtd/nand/raw/mxc_nand_spl.c renamed from drivers/mtd/nand/mxc_nand_spl.c +0 -0
drivers/mtd/nand/raw/mxs_nand.c renamed from drivers/mtd/nand/mxs_nand.c +0 -0
drivers/mtd/nand/raw/mxs_nand.h renamed from drivers/mtd/nand/mxs_nand.h +0 -0
drivers/mtd/nand/raw/mxs_nand_dt.c renamed from drivers/mtd/nand/mxs_nand_dt.c +0 -0
drivers/mtd/nand/raw/mxs_nand_spl.c renamed from drivers/mtd/nand/mxs_nand_spl.c +0 -0
drivers/mtd/nand/raw/nand.c renamed from drivers/mtd/nand/nand.c +0 -0
drivers/mtd/nand/raw/nand_base.c renamed from drivers/mtd/nand/nand_base.c +0 -0
drivers/mtd/nand/raw/nand_bbt.c renamed from drivers/mtd/nand/nand_bbt.c +0 -0
drivers/mtd/nand/raw/nand_bch.c renamed from drivers/mtd/nand/nand_bch.c +0 -0
drivers/mtd/nand/raw/nand_ecc.c renamed from drivers/mtd/nand/nand_ecc.c +1 -1
@@ -3,7 +3,7 @@* This file contains an ECC algorithm from Toshiba that detects and * corrects 1 bit errors in a 256 byte block of data. * -* drivers/mtd/nand/nand_ecc.c +* drivers/mtd/nand/raw/nand_ecc.c * * Copyright (C) 2000-2004 Steven J. Hill (sjhill at realitydiluted.com) * Toshiba America Electronics Components, Inc.
drivers/mtd/nand/raw/nand_ids.c renamed from drivers/mtd/nand/nand_ids.c +0 -0
drivers/mtd/nand/raw/nand_plat.c renamed from drivers/mtd/nand/nand_plat.c +0 -0
drivers/mtd/nand/raw/nand_spl_load.c renamed from drivers/mtd/nand/nand_spl_load.c +0 -0
drivers/mtd/nand/raw/nand_spl_loaders.c renamed from drivers/mtd/nand/nand_spl_loaders.c +0 -0
drivers/mtd/nand/raw/nand_spl_simple.c renamed from drivers/mtd/nand/nand_spl_simple.c +0 -0
drivers/mtd/nand/raw/nand_timings.c renamed from drivers/mtd/nand/nand_timings.c +0 -0
drivers/mtd/nand/raw/nand_util.c renamed from drivers/mtd/nand/nand_util.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* drivers/mtd/nand/nand_util.c +* drivers/mtd/nand/raw/nand_util.c * * Copyright (C) 2006 by Weiss-Electronic GmbH. * All rights reserved.
drivers/mtd/nand/raw/omap_elm.c renamed from drivers/mtd/nand/omap_elm.c +0 -0
drivers/mtd/nand/raw/omap_gpmc.c renamed from drivers/mtd/nand/omap_gpmc.c +0 -0
drivers/mtd/nand/raw/pxa3xx_nand.c renamed from drivers/mtd/nand/pxa3xx_nand.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /* -* drivers/mtd/nand/pxa3xx_nand.c +* drivers/mtd/nand/raw/pxa3xx_nand.c * * Copyright © 2005 Intel Corporation * Copyright © 2006 Marvell International Ltd.
drivers/mtd/nand/raw/pxa3xx_nand.h renamed from drivers/mtd/nand/pxa3xx_nand.h +0 -0
drivers/mtd/nand/raw/sunxi_nand.c renamed from drivers/mtd/nand/sunxi_nand.c +0 -0
drivers/mtd/nand/raw/sunxi_nand_spl.c renamed from drivers/mtd/nand/sunxi_nand_spl.c +0 -0
drivers/mtd/nand/raw/tegra_nand.c renamed from drivers/mtd/nand/tegra_nand.c +0 -0
drivers/mtd/nand/raw/tegra_nand.h renamed from drivers/mtd/nand/tegra_nand.h +0 -0
drivers/mtd/nand/raw/vf610_nfc.c renamed from drivers/mtd/nand/vf610_nfc.c +0 -0
drivers/mtd/nand/raw/zynq_nand.c renamed from drivers/mtd/nand/zynq_nand.c +0 -0
include/configs/MPC8313ERDB.h +1 -1
@@ -242,7 +242,7 @@/* LB refresh timer prescal, 266MHz/32 */ #define CONFIG_SYS_LBC_MRTPR 0x20000000/*TODO */ -/* drivers/mtd/nand/nand.c */ +/* drivers/mtd/nand/raw/nand.c */ #if defined(CONFIG_NAND ) && defined(CONFIG_SPL_BUILD )#define CONFIG_SYS_NAND_BASE 0xFFF00000#else
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 10/31 mtd: rename nand into rawnand in Kconfig prompt
In reply to Miquel RaynalSync the Kconfig raw NAND entry title with the code architecture.
--- drivers/mtd/nand/raw/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/raw/Kconfig +1 -1
@@ -1,6 +1,6 @@ menuconfig NAND - bool "NAND Device Support" + bool "Raw NAND Device Support" if NAND config SYS_NAND_SELF_INIT
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 11/31 mtd: nand: Add core infrastructure to deal with NAND devices
In reply to Miquel RaynalFrom: Boris Brezillon <[email protected]>
Add an intermediate layer to abstract NAND device interface so that some logic can be shared between SPI NANDs, parallel/raw NANDs, OneNANDs, ...
--- drivers/mtd/nand/Kconfig | 3 + drivers/mtd/nand/Makefile | 2 + drivers/mtd/nand/bbt.c | 132 +++++++ drivers/mtd/nand/core.c | 243 +++++++++++++ include/linux/mtd/nand.h | 731 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 1111 insertions(+) create mode 100644 drivers/mtd/nand/bbt.c create mode 100644 drivers/mtd/nand/core.c create mode 100644 include/linux/mtd/nand.h
drivers/mtd/nand/Kconfig +3 -0
@@ -1 +1,4 @@ +config MTD_NAND_CORE + tristate + source "drivers/mtd/nand/raw/Kconfig"
drivers/mtd/nand/Makefile +2 -0
@@ -1,2 +1,4 @@ # SPDX-License-Identifier: GPL-2.0+ +nandcore-objs := core.o bbt.o +obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
drivers/mtd/nand/bbt.c new file +132 -0
132 lines not on this page · raw message
drivers/mtd/nand/core.c new file +243 -0
243 lines not on this page · raw message
include/linux/mtd/nand.h new file +731 -0
731 lines not on this page · raw message
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 12/31 mtd: nand: Pass mode information to nand_page_io_req
In reply to Miquel RaynalFrom: Boris Brezillon <[email protected]>
The NAND sub-layers are likely to need the MTD_OPS_XXX mode information in order to decide if they should enable/disable ECC or how they should place the OOB bytes in the provided OOB buffer.
Add a field to nand_page_io_req to pass this information.
--- include/linux/mtd/nand.h | 3 +++ 1 file changed, 3 insertions(+)
include/linux/mtd/nand.h +3 -0
@@ -86,6 +86,7 @@ struct nand_pos {* @ooboffs: the OOB offset within the page * @ooblen: the number of OOB bytes to read from/write to this page * @oobbuf: buffer to store OOB data in or get OOB data from +* @mode: one of the %MTD_OPS_XXX mode * * This object is used to pass per-page I/O requests to NAND sub-layers. This * way all useful information are already formatted in a useful way and
@@ -106,6 +107,7 @@ struct nand_page_io_req {const void *out;void *in; } oobbuf; +int mode; };/**
@@ -599,6 +601,7 @@ static inline void nanddev_io_iter_init(struct nand_device *nand, {struct mtd_info *mtd =nanddev_to_mtd (nand); + iter->req.mode = req->mode; iter->req.dataoffs =nanddev_offs_to_pos (nand, offs, &iter->req.pos); iter->req.ooboffs = req->ooboffs; iter->oobbytes_per_page =mtd_oobavail (mtd, req);
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 13/31 spi: Extend the core to ease integration of SPI memory controllers
In reply to Miquel RaynalFrom: Boris Brezillon <[email protected]>
Some controllers are exposing high-level interfaces to access various kind of SPI memories. Unfortunately they do not fit in the current spi_controller model and usually have drivers placed in drivers/mtd/spi-nor which are only supporting SPI NORs and not SPI memories in general.
This is an attempt at defining a SPI memory interface which works for all kinds of SPI memories (NORs, NANDs, SRAMs).
--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-mem.c | 501 ++++++++++++++++++++++++++++++++++++++++++ include/spi-mem.h | 258 ++++++++++++++++++++++ include/spi.h | 11 + 5 files changed, 778 insertions(+) create mode 100644 drivers/spi/spi-mem.c create mode 100644 include/spi-mem.h
drivers/spi/Kconfig +7 -0
@@ -18,6 +18,13 @@ config DM_SPI if DM_SPI +config SPI_MEM + bool "SPI memory extension" + help + Enable this option if you want to enable the SPI memory extension. + This extension is meant to simplify interaction with SPI memories + by providing an high-level interface to send memory-like commands. + config ALTERA_SPI bool "Altera SPI driver" help
drivers/spi/Makefile +1 -0
@@ -8,6 +8,7 @@ ifdef CONFIG_DM_SPI obj-y += spi-uclass.o obj-$(CONFIG_SANDBOX) += spi-emul-uclass.o obj-$(CONFIG_SOFT_SPI) += soft_spi.o +obj-$(CONFIG_SPI_MEM) += spi-mem.o else obj-y += spi.o obj-$(CONFIG_SOFT_SPI) += soft_spi_legacy.o
drivers/spi/spi-mem.c new file +501 -0
501 lines not on this page · raw message
include/spi-mem.h new file +258 -0
258 lines not on this page · raw message
include/spi.h +11 -0
@@ -9,6 +9,8 @@#ifndef _SPI_H_#define _SPI_H_ +#include <common.h> +/* SPI mode flags */ #define SPI_CPHA BIT(0)/* clock phase */ #define SPI_CPOL BIT(1)/* clock polarity */
@@ -402,6 +404,15 @@ struct dm_spi_ops {int (*xfer)(struct udevice *dev,unsigned int bitlen,const void *dout,void *din,unsigned long flags); +/** +* Optimized handlers for SPI memory-like operations. +* +* Optimized/dedicated operations for interactions with SPI memory. This +* field is optional and should only be implemented if the controller +* has native support for memory like operations. +*/ +const struct spi_controller_mem_ops *mem_ops; +/** * Set transfer speed. * This sets a new speed to be applied for next spi_xfer().
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 14/31 mtd: nand: Add core infrastructure to support SPI NANDs
In reply to Miquel RaynalFrom: Peter Pan <[email protected]>
Add a SPI NAND framework based on the generic NAND framework and the spi-mem infrastructure.
In its current state, this framework supports the following features:
- single/dual/quad IO modes
- on-die ECC
--- drivers/mtd/nand/Kconfig | 2 + drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/spi/Kconfig | 7 + drivers/mtd/nand/spi/Makefile | 4 + drivers/mtd/nand/spi/core.c | 1235 +++++++++++++++++++++++++++++++++ include/linux/mtd/spinand.h | 427 ++++++++++++ 6 files changed, 1676 insertions(+) create mode 100644 drivers/mtd/nand/spi/Kconfig create mode 100644 drivers/mtd/nand/spi/Makefile create mode 100644 drivers/mtd/nand/spi/core.c create mode 100644 include/linux/mtd/spinand.h
drivers/mtd/nand/Kconfig +2 -0
@@ -2,3 +2,5 @@ config MTD_NAND_CORE tristate source "drivers/mtd/nand/raw/Kconfig" + +source "drivers/mtd/nand/spi/Kconfig"
drivers/mtd/nand/Makefile +1 -0
@@ -2,3 +2,4 @@ nandcore-objs := core.o bbt.o obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o +obj-$(CONFIG_MTD_SPI_NAND) += spi/
drivers/mtd/nand/spi/Kconfig new file +7 -0
@@ -0,0 +1,7 @@ +menuconfig MTD_SPI_NAND + bool "SPI NAND device Support" + depends on MTD && DM_SPI + select MTD_NAND_CORE + select SPI_MEM + help + This is the framework for the SPI NAND device drivers.
drivers/mtd/nand/spi/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +spinand-objs := core.o +obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
drivers/mtd/nand/spi/core.c new file +1235 -0
1,235 lines not on this page · raw message
include/linux/mtd/spinand.h new file +427 -0
427 lines not on this page · raw message
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 15/31 mtd: spinand: Add initial support for Micron MT29F2G01ABAGD
In reply to Miquel RaynalFrom: Peter Pan <[email protected]>
Add a basic driver for Micron SPI NANDs. Only one device is supported right now, but the driver will be extended to support more devices afterwards.
--- drivers/mtd/nand/spi/Makefile | 2 +- drivers/mtd/nand/spi/core.c | 17 +++++ drivers/mtd/nand/spi/micron.c | 135 ++++++++++++++++++++++++++++++++++ include/linux/mtd/spinand.h | 3 + 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 drivers/mtd/nand/spi/micron.c
drivers/mtd/nand/spi/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 -spinand-objs := core.o +spinand-objs := core.o micron.o obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
drivers/mtd/nand/spi/core.c +17 -0
@@ -829,8 +829,25 @@ static const struct nand_ops spinand_ops = { .isbad = spinand_isbad, }; +static const struct spinand_manufacturer *spinand_manufacturers[] = { + µn_spinand_manufacturer, +}; +static int spinand_manufacturer_detect (struct spinand_device *spinand) { +unsigned int i; +int ret; + +for (i =0 ; i <ARRAY_SIZE (spinand_manufacturers); i++) { + ret = spinand_manufacturers[i]->ops->detect (spinand); +if (ret >0 ) { + spinand->manufacturer = spinand_manufacturers[i]; +return 0 ; + }else if (ret <0 ) { +return ret; + } + } +return -ENOTSUPP ; }
drivers/mtd/nand/spi/micron.c new file +135 -0
135 lines not on this page · raw message
include/linux/mtd/spinand.h +3 -0
@@ -200,6 +200,9 @@ struct spinand_manufacturer {const struct spinand_manufacturer_ops *ops; }; +/* SPI NAND manufacturers */ +extern const struct spinand_manufacturer micron_spinand_manufacturer; +/** * struct spinand_op_variants - SPI NAND operation variants * @ops: the list of variants for a given operation
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 16/31 mtd: spinand: Add initial support for Winbond W25M02GV
In reply to Miquel RaynalFrom: Frieder Schrempf <[email protected]>
Add support for the W25M02GV chip.
--- drivers/mtd/nand/spi/Makefile | 2 +- drivers/mtd/nand/spi/core.c | 1 + drivers/mtd/nand/spi/winbond.c | 143 +++++++++++++++++++++++++++++++++ include/linux/mtd/spinand.h | 1 + 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 drivers/mtd/nand/spi/winbond.c
drivers/mtd/nand/spi/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 -spinand-objs := core.o micron.o +spinand-objs := core.o micron.o winbond.o obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
drivers/mtd/nand/spi/core.c +1 -0
@@ -831,6 +831,7 @@ static const struct nand_ops spinand_ops = {static const struct spinand_manufacturer *spinand_manufacturers[] = { µn_spinand_manufacturer, + &winbond_spinand_manufacturer, };static int spinand_manufacturer_detect (struct spinand_device *spinand)
drivers/mtd/nand/spi/winbond.c new file +143 -0
143 lines not on this page · raw message
include/linux/mtd/spinand.h +1 -0
@@ -202,6 +202,7 @@ struct spinand_manufacturer {/* SPI NAND manufacturers */ extern const struct spinand_manufacturer micron_spinand_manufacturer; +extern const struct spinand_manufacturer winbond_spinand_manufacturer;/** * struct spinand_op_variants - SPI NAND operation variants
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 17/31 mtd: spinand: Add initial support for the MX35LF1GE4AB chip
In reply to Miquel RaynalFrom: Boris Brezillon <[email protected]>
Add minimal support for the MX35LF1GE4AB SPI NAND chip.
--- drivers/mtd/nand/spi/Makefile | 2 +- drivers/mtd/nand/spi/core.c | 1 + drivers/mtd/nand/spi/macronix.c | 138 ++++++++++++++++++++++++++++++++ include/linux/mtd/spinand.h | 1 + 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 drivers/mtd/nand/spi/macronix.c
drivers/mtd/nand/spi/Makefile +1 -1
@@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 -spinand-objs := core.o micron.o winbond.o +spinand-objs := core.o macronix.o micron.o winbond.o obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
drivers/mtd/nand/spi/core.c +1 -0
@@ -830,6 +830,7 @@ static const struct nand_ops spinand_ops = { };static const struct spinand_manufacturer *spinand_manufacturers[] = { + ¯onix_spinand_manufacturer, µn_spinand_manufacturer, &winbond_spinand_manufacturer, };
drivers/mtd/nand/spi/macronix.c new file +138 -0
138 lines not on this page · raw message
include/linux/mtd/spinand.h +1 -0
@@ -201,6 +201,7 @@ struct spinand_manufacturer { };/* SPI NAND manufacturers */ +extern const struct spinand_manufacturer macronix_spinand_manufacturer;extern const struct spinand_manufacturer micron_spinand_manufacturer;extern const struct spinand_manufacturer winbond_spinand_manufacturer;
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 18/31 mtd: spinand: Add initial support for the MX35LF2GE4AB chip
In reply to Miquel RaynalAdd support for the MX35LF2GE4AB chip, which is similar to its cousin MX35LF1GE4AB, with two planes instead of one.
--- drivers/mtd/nand/spi/macronix.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/mtd/nand/spi/macronix.c +14 -6
@@ -27,13 +27,13 @@ static SPINAND_OP_VARIANTS(update_cache_variants,SPINAND_PROG_LOAD_X4 (false,0 ,NULL ,0 ), SPINAND_PROG_LOAD(false, 0, NULL, 0)); -static int mx35lf1ge4ab_ooblayout_ecc (struct mtd_info *mtd,int section, +static int mx35lfxge4ab_ooblayout_ecc (struct mtd_info *mtd,int section,struct mtd_oob_region *region) {return -ERANGE ; } -static int mx35lf1ge4ab_ooblayout_free (struct mtd_info *mtd,int section, +static int mx35lfxge4ab_ooblayout_free (struct mtd_info *mtd,int section,struct mtd_oob_region *region) {if (section)
@@ -45,9 +45,9 @@ static int mx35lf1ge4ab_ooblayout_free(struct mtd_info *mtd, int section,return 0 ; } -static const struct mtd_ooblayout_ops mx35lf1ge4ab_ooblayout = { - .ecc = mx35lf1ge4ab_ooblayout_ecc, - .free = mx35lf1ge4ab_ooblayout_free, +static const struct mtd_ooblayout_ops mx35lfxge4ab_ooblayout = { + .ecc = mx35lfxge4ab_ooblayout_ecc, + .free = mx35lfxge4ab_ooblayout_free, };static int mx35lf1ge4ab_get_eccsr (struct spinand_device *spinand,u8 *eccsr)
@@ -102,8 +102,16 @@ static const struct spinand_info macronix_spinand_table[] = { &write_cache_variants, &update_cache_variants), SPINAND_HAS_QE_BIT, - SPINAND_ECCINFO(&mx35lf1ge4ab_ooblayout, + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, mx35lf1ge4ab_ecc_get_status)), +SPINAND_INFO ("MX35LF2GE4AB" ,0x22 , +NAND_MEMORG (1 ,2048 ,64 ,64 ,2048 ,2 ,1 ,1 ), +NAND_ECCREQ (4 ,512 ), +SPINAND_INFO_OP_VARIANTS (&read_cache_variants, + &write_cache_variants, + &update_cache_variants), +SPINAND_HAS_QE_BIT , + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)), };static int macronix_spinand_detect (struct spinand_device *spinand)
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 19/31 dt-bindings: Add bindings for SPI NAND devices
In reply to Miquel RaynalFrom: Boris Brezillon <[email protected]>
Add bindings for SPI NAND chips.
--- doc/device-tree-bindings/mtd/spi-nand.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/device-tree-bindings/mtd/spi-nand.txt
doc/device-tree-bindings/mtd/spi-nand.txt new file +5 -0
@@ -0,0 +1,5 @@ +SPI NAND flash + +Required properties: +- compatible: should be "spi-nand" +- reg: should encode the chip-select line used to access the NAND chip
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 20/31 mtd: declare MTD_PARTITIONS symbol in Kconfig
In reply to Miquel RaynalUBI selects MTD_PARTITIONS which is the symbol to compile drivers/mtd/mtdpart.c. Unfortunately, the symbol was not defined in Kconfig and this worked only with board files defining it. Fix this by adding a boolean in Kconfig so boards defined by defconfig files only will work as expected.
--- drivers/mtd/Kconfig | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/Kconfig +3 -0
@@ -1,5 +1,8 @@ menu "MTD Support" +config MTD_PARTITIONS + bool + config MTD bool "Enable Driver Model for MTD drivers" depends on DM
Signature · 1 line
2.17.1
PATCH v6 20/31 mtd: declare MTD_PARTITIONS symbol in Kconfig
Quoted 7 lines · On Thu, 16 Aug 2018 17:30:18 +0200 Miquel Raynal <[email protected]>…
UBI selects
MTD_PARTITIONSwhich is the symbol to compiledrivers/mtd/mtdpart.c. Unfortunately, the symbol was not defined inKconfigand this worked only with board files defining it. Fix this by adding a boolean inKconfigso boards defined by defconfig files only will work as expected.Signed-off-by Miquel Raynal <[email protected]>
Quoted 17 lines
--- drivers/mtd/Kconfig | 3 +++ 1 file changed, 3 insertions(+)drivers/mtd/Kconfig +3
-0@@ -1,5 +1,8 @@ menu "MTD Support" +config MTD_PARTITIONS + bool + config MTD bool "Enable Driver Model for MTD drivers" depends on DM
PATCH v6 20/31 mtd: declare MTD_PARTITIONS symbol in Kconfig
In reply to Miquel RaynalQuoted 16 lines · Miquel Raynal
UBI selects
MTD_PARTITIONSwhich is the symbol to compiledrivers/mtd/mtdpart.c. Unfortunately, the symbol was not defined inKconfigand this worked only with board files defining it. Fix this by adding a boolean inKconfigso boards defined by defconfig files only will work as expected.Signed-off-by Miquel Raynal <[email protected]>--- drivers/mtd/Kconfig | 3 +++ 1 file changed, 3 insertions(+)drivers/mtd/Kconfig +0
-0
drivers/mtd/Kconfig line 5
Quoted 5 lines
drivers/mtd/Kconfig +3
-0@@ -1,5 +1,8 @@ menu "MTD Support" +config MTD_PARTITIONS + bool +
I think I can drop this patch, along with
"mtd: declare MTD_PARTITIONS symbol in Kconfig"
Miquel Raynal
maintainerPATCH v6 20/31 mtd: declare MTD_PARTITIONS symbol in Kconfig
Hi Jagan,
Jagan Teki <[email protected]> wrote on Mon, 3 Sep 2018 13:17:13 +0530:
Quoted 20 lines
Quoted 18 lines · Miquel Raynal
UBI selects
MTD_PARTITIONSwhich is the symbol to compiledrivers/mtd/mtdpart.c. Unfortunately, the symbol was not defined inKconfigand this worked only with board files defining it. Fix this by adding a boolean inKconfigso boards defined by defconfig files only will work as expected.Signed-off-by Miquel Raynal <[email protected]>--- drivers/mtd/Kconfig | 3 +++ 1 file changed, 3 insertions(+)drivers/mtd/Kconfig +0
-0@@ -1,5 +1,8 @@ menu "MTD Support"
Quoted 6 lines
drivers/mtd/Kconfig line 5
Quoted 3 lines
drivers/mtd/Kconfig +3
-0+config MTD_PARTITIONS + bool +I think I can drop this patch, along with
"mtd: declareMTD_PARTITIONSsymbol inKconfig"
I am not sure to understand correctly what you intend to do?
Thanks,
Miquèl
Miquel Raynal
maintainerPATCH v6 20/31 mtd: declare MTD_PARTITIONS symbol in Kconfig
In reply to Jagan TekiHi Jagan,
Jagan Teki <[email protected]> wrote on Mon, 3 Sep 2018 13:17:13 +0530:
Quoted 20 lines
Quoted 18 lines · Miquel Raynal
UBI selects
MTD_PARTITIONSwhich is the symbol to compiledrivers/mtd/mtdpart.c. Unfortunately, the symbol was not defined inKconfigand this worked only with board files defining it. Fix this by adding a boolean inKconfigso boards defined by defconfig files only will work as expected.Signed-off-by Miquel Raynal <[email protected]>--- drivers/mtd/Kconfig | 3 +++ 1 file changed, 3 insertions(+)drivers/mtd/Kconfig +0
-0@@ -1,5 +1,8 @@ menu "MTD Support"
Quoted 6 lines
drivers/mtd/Kconfig line 5
Quoted 3 lines
drivers/mtd/Kconfig +3
-0+config MTD_PARTITIONS + bool +I think I can drop this patch, along with
"mtd: declareMTD_PARTITIONSsymbol inKconfig"
Oh I see what you mean! It looks like the problem reported here has already been fixed by:
commit 9c5b00973bceb7c0192bd6b03672d69b092700b4
Author: Adam Ford <[email protected]> Date: Sat Jul 7 22:18:22 2018 -0500
Convert CONFIG_MTD_PARTITIONS et al to Kconfig
This converts the following to Kconfig:
CONFIG_MTD_PARTITIONS
CONFIG_MTD_DEVICE
And indeed I saw the double entry when I rebased and removed the duplicate. So yes, you can drop this one, and I will drop the unneeded patch in the "Clean MTD partition..." series.
Good catch!
Miquèl
Miquel Raynal
maintainerPATCH v6 21/31 mtd: mtdpart: balance debug messages
In reply to Miquel RaynalBalance debug message in the partition allocation/removal process in order to keep track of them more easily.
--- drivers/mtd/mtdpart.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mtd/mtdpart.c +2 -0
@@ -362,6 +362,8 @@ int del_mtd_partitions(struct mtd_info *master)struct mtd_part *slave, *next;int ret, err =0 ; +debug ("Deleting MTD partitions on \"%s\":\n" , master->name); +mutex_lock (&mtd_partitions_mutex);list_for_each_entry_safe (slave, next, &mtd_partitions, list)if (slave->master == master) {
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 22/31 cmd: ubi: delete useless and misleading definitions
In reply to Miquel RaynalThese definitions are simply not used and are misleading because similar definitions exist in jffs2/load_kernel.h and are used widely to define MTD device types (which is, by the way, totally redundant with what the MTD core does). Remove these definitions.
--- cmd/ubi.c | 5 ----- 1 file changed, 5 deletions(-)
cmd/ubi.c +0 -5
@@ -27,11 +27,6 @@#undef ubi_msg#define ubi_msg (fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__) -#define DEV_TYPE_NONE 0 -#define DEV_TYPE_NAND 1 -#define DEV_TYPE_ONENAND 2 -#define DEV_TYPE_NOR 3 -/* Private own data */ static struct ubi_device *ubi;static char buffer[80 ];
Signature · 1 line
2.17.1
PATCH v6 22/31 cmd: ubi: delete useless and misleading definitions
Quoted 7 lines · On Thu, 16 Aug 2018 17:30:20 +0200 Miquel Raynal <[email protected]>…
These definitions are simply not used and are misleading because similar definitions exist in
jffs2/load_kernel.hand are used widely to define MTD device types (which is, by the way, totally redundant with what the MTD core does). Remove these definitions.Signed-off-by Miquel Raynal <[email protected]>Acked-by Jagan Teki <[email protected]>
Quoted 20 lines
--- cmd/ubi.c | 5 ----- 1 file changed, 5 deletions(-)cmd/ubi.c +0
-5@@ -27,11 +27,6 @@#undef ubi_msg#define ubi_msg (fmt, ...) printf("UBI: " fmt "\n", ##__VA_ARGS__) -#define DEV_TYPE_NONE 0 -#define DEV_TYPE_NAND 1 -#define DEV_TYPE_ONENAND 2 -#define DEV_TYPE_NOR 3 -/* Private own data */ static struct ubi_device *ubi;static char buffer[80 ];
Miquel Raynal
maintainerPATCH v6 23/31 cmd: mtdparts: add fallthrough in switch statement
In reply to Miquel RaynalSwitch blocks for deriving size naturally use fallthrough between 'case' statements. Make it explicit.
--- cmd/mtdparts.c | 3 +++ 1 file changed, 3 insertions(+)
cmd/mtdparts.c +3 -0
@@ -177,13 +177,16 @@ static u64 memsize_parse (const char *const ptr, const char **retptr)case 'G' :case 'g' : ret <<=10 ; +/* Fallthrough */ case 'M' :case 'm' : ret <<=10 ; +/* Fallthrough */ case 'K' :case 'k' : ret <<=10 ; (*retptr)++; +/* Fallthrough */ default :break ; }
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 24/31 cmd: mtdparts: accept spi-nand devices
In reply to Miquel RaynalLet spi-nand devices be recognized by mtdparts. This is superfluous but a full mtdparts rework would be very time-consuming.
--- cmd/mtdparts.c | 13 ++++++++----- include/jffs2/load_kernel.h | 7 +++++-- 2 files changed, 13 insertions(+), 7 deletions(-)
cmd/mtdparts.c +8 -5
@@ -37,7 +37,7 @@* mtdids=<idmap>[,<idmap>,...] * * <idmap> := <dev-id>=<mtd-id> -* <dev-id> := 'nand'|'nor'|'onenand'<dev-num> +* <dev-id> := 'nand'|'nor'|'onenand'|'spi-nand'<dev-num> * <dev-num> := mtd device number, 0... * <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name) *
@@ -339,7 +339,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)if (!mtd->numeraseregions) {/* -* Only one eraseregion (NAND, OneNAND or uniform NOR), +* Only one eraseregion (NAND, SPI-NAND, OneNAND or uniform NOR), * checking for alignment is easy here */ offset = part->offset;
@@ -1030,7 +1030,7 @@ static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_ }/** -* Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>, +* Parse device id string <dev-id> := 'nand'|'nor'|'onenand'|'spi-nand'<dev-num>, * return device type and number. * * @param id string describing device id
@@ -1054,6 +1054,9 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, }else if (strncmp (p,"onenand" ,7 ) ==0 ) { *dev_type =MTD_DEV_TYPE_ONENAND ; p +=7 ; + }else if (strncmp (p,"spi-nand" ,8 ) ==0 ) { + *dev_type =MTD_DEV_TYPE_SPINAND ; + p +=8 ; }else {printf ("incorrect device type in %s\n" , id);return 1 ;
@@ -1636,7 +1639,7 @@ static int parse_mtdids(const char *const ids)while (p && (*p !='\0' )) { ret =1 ; -/* parse 'nor'|'nand'|'onenand'<dev-num> */ +/* parse 'nor'|'nand'|'onenand'|'spi-nand'<dev-num> */ if (mtd_id_parse (p, &p, &type, &num) !=0 )break ;
@@ -2112,7 +2115,7 @@ static char mtdparts_help_text[] ="'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n" "mtdids=<idmap>[,<idmap>,...]\n\n" "<idmap> := <dev-id>=<mtd-id>\n" -"<dev-id> := 'nand'|'nor'|'onenand'<dev-num>\n" +"<dev-id> := 'nand'|'nor'|'onenand'|'spi-nand'<dev-num>\n" "<dev-num> := mtd device number, 0...\n" "<mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)\n\n" "'mtdparts' - partition list\n\n"
include/jffs2/load_kernel.h +5 -2
@@ -15,9 +15,12 @@#define MTD_DEV_TYPE_NOR 0x0001#define MTD_DEV_TYPE_NAND 0x0002#define MTD_DEV_TYPE_ONENAND 0x0004 +#define MTD_DEV_TYPE_SPINAND 0x0008 -#define MTD_DEV_TYPE (type) ((type == MTD_DEV_TYPE_NAND) ? "nand" : \ - (type == MTD_DEV_TYPE_ONENAND) ? "onenand" : "nor") +#define MTD_DEV_TYPE (type) (type == MTD_DEV_TYPE_NAND ? "nand" : \ + (type == MTD_DEV_TYPE_NOR ? "nor" : \ + (type == MTD_DEV_TYPE_ONENAND ? "onenand" : \ + "spi-nand"))) \struct mtd_device {struct list_head link;
Signature · 1 line
2.17.1
PATCH v6 24/31 cmd: mtdparts: accept spi-nand devices
Quoted 5 lines · On Thu, 16 Aug 2018 17:30:22 +0200 Miquel Raynal <[email protected]>…
Let spi-nand devices be recognized by mtdparts. This is superfluous but a full mtdparts rework would be very time-consuming.
Signed-off-by Miquel Raynal <[email protected]>Acked-by Jagan Teki <[email protected]>
Quoted 83 lines
--- cmd/mtdparts.c | 13 ++++++++----- include/jffs2/load_kernel.h | 7 +++++-- 2 files changed, 13 insertions(+), 7 deletions(-)cmd/mtdparts.c +8
-5@@ -37,7 +37,7 @@* mtdids=<idmap>[,<idmap>,...] * * <idmap> := <dev-id>=<mtd-id> -* <dev-id> := 'nand'|'nor'|'onenand'<dev-num> +* <dev-id> := 'nand'|'nor'|'onenand'|'spi-nand'<dev-num> * <dev-num> := mtd device number, 0... * <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name) * @@ -339,7 +339,7 @@ static int part_validate_eraseblock(struct mtdids *id, struct part_info *part)if (!mtd->numeraseregions) {/* -* Only one eraseregion (NAND, OneNAND or uniform NOR), +* Only one eraseregion (NAND, SPI-NAND, OneNAND or uniform NOR), * checking for alignment is easy here */ offset = part->offset;@@ -1030,7 +1030,7 @@ static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_ }/** -* Parse device id string <dev-id> := 'nand'|'nor'|'onenand'<dev-num>, +* Parse device id string <dev-id> := 'nand'|'nor'|'onenand'|'spi-nand'<dev-num>, * return device type and number. * * @param id string describing device id @@ -1054,6 +1054,9 @@ int mtd_id_parse(const char *id, const char **ret_id, u8 *dev_type, }else if (strncmp (p,"onenand" ,7 ) ==0 ) { *dev_type =MTD_DEV_TYPE_ONENAND ; p +=7 ; + }else if (strncmp (p,"spi-nand" ,8 ) ==0 ) { + *dev_type =MTD_DEV_TYPE_SPINAND ; + p +=8 ; }else {printf ("incorrect device type in %s\n" , id);return 1 ;@@ -1636,7 +1639,7 @@ static int parse_mtdids(const char *const ids)while (p && (*p !='\0' )) { ret =1 ; -/* parse 'nor'|'nand'|'onenand'<dev-num> */ +/* parse 'nor'|'nand'|'onenand'|'spi-nand'<dev-num> */ if (mtd_id_parse (p, &p, &type, &num) !=0 )break ;@@ -2112,7 +2115,7 @@ static char mtdparts_help_text[] ="'mtdids' - linux kernel mtd device id <-> u-boot device id mapping\n\n" "mtdids=<idmap>[,<idmap>,...]\n\n" "<idmap> := <dev-id>=<mtd-id>\n" -"<dev-id> := 'nand'|'nor'|'onenand'<dev-num>\n" +"<dev-id> := 'nand'|'nor'|'onenand'|'spi-nand'<dev-num>\n" "<dev-num> := mtd device number, 0...\n" "<mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)\n\n" "'mtdparts' - partition list\n\n" include/jffs2/load_kernel.h +5
-2@@ -15,9 +15,12 @@#define MTD_DEV_TYPE_NOR 0x0001#define MTD_DEV_TYPE_NAND 0x0002#define MTD_DEV_TYPE_ONENAND 0x0004 +#define MTD_DEV_TYPE_SPINAND 0x0008 -#define MTD_DEV_TYPE (type) ((type == MTD_DEV_TYPE_NAND) ? "nand" : \ - (type == MTD_DEV_TYPE_ONENAND) ? "onenand" : "nor") +#define MTD_DEV_TYPE (type) (type == MTD_DEV_TYPE_NAND ? "nand" : \ + (type == MTD_DEV_TYPE_NOR ? "nor" : \ + (type == MTD_DEV_TYPE_ONENAND ? "onenand" : \ + "spi-nand"))) \struct mtd_device {struct list_head link;
Miquel Raynal
maintainerPATCH v6 25/31 cmd: mtdparts: add a generic 'mtdparts' parser
In reply to Miquel RaynalThe current parser is very specific to U-Boot mtdparts implementation. It does not use MTD structures like mtd_info and mtd_partition. Write some kind of a wrapper around the current implementation to allow other commands to benefit from this parsing in a user-friendly way.
This new command will allocate an mtd_partition array for each successful call. This array must be freed after use by the caller. The given 'mtdparts' buffer pointer will be moved forward to the next MTD device (if any, it will point towards a '\0' character otherwise).
--- cmd/mtdparts.c | 71 ++++++++++++++++++++++++++++++++++ include/linux/mtd/partitions.h | 3 ++ 2 files changed, 74 insertions(+)
cmd/mtdparts.c +71 -0
@@ -78,6 +78,7 @@#include <linux/ctype.h> #include <linux/err.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #if defined(CONFIG_CMD_NAND )#include <linux/mtd/rawnand.h>
@@ -708,6 +709,76 @@ static int part_parse(const char *const partdef, const char **ret, struct part_ireturn 0 ; } +int mtdparts_parse_part (struct mtd_info *parent,const char **_mtdparts, +struct mtd_partition **_parts,int *_nb_parts) +{ +const char *mtdparts = *_mtdparts; +struct part_info *part_legacy; +struct mtd_partition *parts; +int cur_off =0 , cur_sz =0 ; +int nb_parts =0 ; +char *names; +int ret, idx; + + *_parts =NULL ; + *_nb_parts =0 ; + +/* First, iterate over the partitions until we know their number */ +while (mtdparts[0 ] !='\0' && mtdparts[0 ] !=';' ) { + ret =part_parse (mtdparts, &mtdparts, &part_legacy); +if (ret) +return ret; + + nb_parts++; +free (part_legacy); + } + +/* Allocate an array of partitions to give back to the caller */ + parts =malloc ((sizeof (*parts) +20 ) * nb_parts); + names = (char *)&parts[nb_parts]; +if (!parts) { +printf ("Could not allocate enough space to save partitions meta-data\n" ); +return -ENOMEM ; + } + +/* Iterate again over each partition to save the data in our array */ +for (idx =0 ; idx < nb_parts; idx++) { +char *name; + + ret =part_parse (*_mtdparts, _mtdparts, &part_legacy); +if (ret) +return ret; + + name = &names[idx *20 ]; +strncpy (name, part_legacy->name,20 ); + parts[idx].name = name; + + parts[idx].size = part_legacy->size; +if (parts[idx].size ==SIZE_REMAINING ) + parts[idx].size = parent->size - cur_sz; + cur_sz += parts[idx].size; + + parts[idx].offset = part_legacy->offset; +if (parts[idx].offset ==OFFSET_NOT_SPECIFIED ) + parts[idx].offset = cur_off; + cur_off += parts[idx].size; + + parts[idx].mask_flags = part_legacy->mask_flags; + parts[idx].ecclayout = parent->ecclayout; + +free (part_legacy); + } + +/* Offset by one mtdparts to point to the next device if needed */ +if (*_mtdparts[0 ] ==';' ) + _mtdparts++; + + *_parts = parts; + *_nb_parts = nb_parts; + +return 0 ; +} +/** * Check device number to be within valid range for given device type. *
include/linux/mtd/partitions.h +3 -0
@@ -87,4 +87,7 @@ int mtd_add_partition(struct mtd_info *master, const char *name,int mtd_del_partition (struct mtd_info *master,int partno);uint64_t mtd_get_device_size (const struct mtd_info *mtd); +int mtdparts_parse_part (struct mtd_info *parent,const char **_mtdparts, +struct mtd_partition **_parts,int *_nb_parts); +#endif
Signature · 1 line
2.17.1
PATCH v6 25/31 cmd: mtdparts: add a generic 'mtdparts' parser
Quoted 61 lines · On Thu, 16 Aug 2018 17:30:23 +0200 Miquel Raynal <[email protected]>…
cmd/mtdparts.c +59
-0+int mtdparts_parse_part (struct mtd_info *parent,const char **_mtdparts, +struct mtd_partition **_parts,int *_nb_parts) +{ +const char *mtdparts = *_mtdparts; +struct part_info *part_legacy; +struct mtd_partition *parts; +int cur_off =0 , cur_sz =0 ; +int nb_parts =0 ; +char *names; +int ret, idx; + + *_parts =NULL ; + *_nb_parts =0 ; + +/* First, iterate over the partitions until we know their number */ +while (mtdparts[0 ] !='\0' && mtdparts[0 ] !=';' ) { + ret =part_parse (mtdparts, &mtdparts, &part_legacy); +if (ret) +return ret; + + nb_parts++; +free (part_legacy); + } + +/* Allocate an array of partitions to give back to the caller */ + parts =malloc ((sizeof (*parts) +20 ) * nb_parts); + names = (char *)&parts[nb_parts]; +if (!parts) { +printf ("Could not allocate enough space to save partitions meta-data\n" ); +return -ENOMEM ; + } + +/* Iterate again over each partition to save the data in our array */ +for (idx =0 ; idx < nb_parts; idx++) { +char *name; + + ret =part_parse (*_mtdparts, _mtdparts, &part_legacy); +if (ret) +return ret; + + name = &names[idx *20 ]; +strncpy (name, part_legacy->name,20 ); + parts[idx].name = name; + + parts[idx].size = part_legacy->size; +if (parts[idx].size ==SIZE_REMAINING ) + parts[idx].size = parent->size - cur_sz; + cur_sz += parts[idx].size; + + parts[idx].offset = part_legacy->offset; +if (parts[idx].offset ==OFFSET_NOT_SPECIFIED ) + parts[idx].offset = cur_off; + cur_off += parts[idx].size; + + parts[idx].mask_flags = part_legacy->mask_flags; + parts[idx].ecclayout = parent->ecclayout; + +free (part_legacy); + }
cmd/mtdparts.c static int part_parse(const char *const partdef, const char **ret, struct part_i · line 780
Quoted 10 lines
cmd/mtdparts.c +10
-0+ +/* Offset by one mtdparts to point to the next device if needed */ +if (*_mtdparts[0 ] ==';' ) + _mtdparts++; + + *_parts = parts; + *_nb_parts = nb_parts; + +return 0 ; +}
I guess the CMD_MTD dependency on CMD_MTDPARTS comes from here. Can't we just move mtdparts_parse_part()+part_parse() somewhere in drivers/mtd/ and remove this dependency?
Miquel Raynal
maintainerPATCH v6 26/31 mtd: uclass: add probe function
In reply to Miquel RaynalThe user might want to trigger the probe of any MTD device, export these functions so they can be called from a command source file.
--- drivers/mtd/mtd-uclass.c | 9 +++++++++ include/linux/mtd/mtd.h | 3 +++ 2 files changed, 12 insertions(+)
drivers/mtd/mtd-uclass.c +9 -0
@@ -5,6 +5,7 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> #include <errno.h> #include <mtd.h>
@@ -13,6 +14,14 @@* The uclass private is pointed to mtd_info. */ +int mtd_probe (struct udevice *dev) +{ +if (device_active (dev)) +return 0 ; + +return device_probe (dev); +} +UCLASS_DRIVER (mtd) = { .id =UCLASS_MTD , .name ="mtd" ,
include/linux/mtd/mtd.h +3 -0
@@ -549,5 +549,8 @@ int mtd_arg_off_size(int argc, char *const argv[], int *idx, loff_t *off,void mtd_get_len_incl_bad (struct mtd_info *mtd,uint64_t offset,const uint64_t length,uint64_t *len_incl_bad,int *truncated); + +int mtd_probe (struct udevice *dev); +#endif #endif /* __MTD_MTD_H__ */
Signature · 1 line
2.17.1
Miquel Raynal
maintainerPATCH v6 27/31 mtd: move mtdparts_init() declaration
In reply to Miquel Raynalmtdparts_init() is called from various source files. It is declared in include/jffs2/load_kernel.h while it has nothing to do with jffs2 anymore.
Move its declaration to include/linux/mtd/partitions.h which has way more meaning.
--- cmd/flash.c | 1 + cmd/jffs2.c | 1 + cmd/mtdparts.c | 35 +++++++++++++++++++++++----------- cmd/nand.c | 1 + common/fdt_support.c | 1 + drivers/dfu/dfu_nand.c | 1 + drivers/fastboot/fb_nand.c | 1 + drivers/mtd/mtd_uboot.c | 1 + include/jffs2/load_kernel.h | 1 - include/linux/mtd/partitions.h | 3 +++ 10 files changed, 34 insertions(+), 12 deletions(-)
cmd/flash.c +1 -0
@@ -12,6 +12,7 @@#if defined(CONFIG_CMD_MTDPARTS )#include <jffs2/jffs2.h> +#include <linux/mtd/partitions.h> /* partition handling routines */ int mtdparts_init (void );
cmd/jffs2.c +1 -0
@@ -76,6 +76,7 @@#include <jffs2/jffs2.h> #include <linux/list.h> #include <linux/ctype.h> +#include <linux/mtd/partitions.h> #include <cramfs/cramfs_fs.h> #if defined(CONFIG_CMD_NAND )
cmd/mtdparts.c +24 -11
@@ -44,7 +44,7 @@* * 'mtdparts' - partition list * -* mtdparts=mtdparts=<mtd-def>[;<mtd-def>...] +* mtdparts=[mtdparts=]<mtd-def>[;<mtd-def>...] * * <mtd-def> := <mtd-id>:<part-def>[,<part-def>...] * <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name)
@@ -62,11 +62,11 @@* * 1 NOR Flash, with 1 single writable partition: * mtdids=nor0=edb7312-nor -* mtdparts=mtdparts=edb7312-nor:- +* mtdparts=[mtdparts=]edb7312-nor:- * * 1 NOR Flash with 2 partitions, 1 NAND with one * mtdids=nor0=edb7312-nor,nand0=edb7312-nand -* mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home) +* mtdparts=[mtdparts=]edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home) * */
@@ -1170,9 +1170,6 @@ static int generate_mtdparts(char *buf, u32 buflen)return 0 ; } -strcpy (p,"mtdparts=" ); - p +=9 ; -list_for_each (dentry, &devices) { dev = list_entry(dentry, struct mtd_device, link);
@@ -1643,11 +1640,9 @@ static int parse_mtdparts(const char *const mtdparts)if (!p) p = mtdparts; -if (strncmp (p,"mtdparts=" ,9 ) !=0 ) { -printf ("mtdparts variable doesn't start with 'mtdparts='\n" ); -return err; - } - p +=9 ; +/* Skip the useless prefix, if any */ +if (strncmp (p,"mtdparts=" ,9 ) ==0 ) + p +=9 ;while (*p !='\0' ) { err =1 ;
@@ -1786,6 +1781,24 @@ static int parse_mtdids(const char *const ids)return 0 ; } +int mtdids_search_alternate_name (const char *mtdname,char *altname, +unsigned int max_len) +{ +struct list_head *entry; +struct mtdids *id; + +list_for_each (entry, &mtdids) { + id = list_entry(entry, struct mtdids, link); +if (!strncmp (mtdname, id->mtd_id, max_len)) { +snprintf (altname, max_len,"%s%d" , +MTD_DEV_TYPE (id->type), id->num); + +return 0 ; + } + } + +return -EINVAL ; +}/** * Parse and initialize global mtdids mapping and create global
cmd/nand.c +1 -0
@@ -21,6 +21,7 @@#include <common.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #include <command.h> #include <console.h> #include <watchdog.h>
common/fdt_support.c +1 -0
@@ -11,6 +11,7 @@#include <stdio_dev.h> #include <linux/ctype.h> #include <linux/types.h> +#include <linux/mtd/partitions.h> #include <asm/global_data.h> #include <linux/libfdt.h> #include <fdt_support.h>
drivers/dfu/dfu_nand.c +1 -0
@@ -15,6 +15,7 @@#include <div64.h> #include <dfu.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #include <jffs2/load_kernel.h> #include <nand.h>
drivers/fastboot/fb_nand.c +1 -0
@@ -11,6 +11,7 @@#include <image-sparse.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #include <jffs2/jffs2.h> #include <nand.h>
drivers/mtd/mtd_uboot.c +1 -0
@@ -5,6 +5,7 @@*/ #include <common.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #include <jffs2/jffs2.h> static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,
include/jffs2/load_kernel.h +0 -1
@@ -62,7 +62,6 @@ struct mtdids {#define led_blink (x, y, z, a)/* common/cmd_jffs2.c */ -extern int mtdparts_init (void );extern int find_dev_and_part (const char *id,struct mtd_device **dev,u8 *part_num,struct part_info **part);extern struct mtd_device *device_find (u8 type,u8 num);
include/linux/mtd/partitions.h +3 -0
@@ -87,6 +87,9 @@ int mtd_add_partition(struct mtd_info *master, const char *name,int mtd_del_partition (struct mtd_info *master,int partno);uint64_t mtd_get_device_size (const struct mtd_info *mtd); +int mtdparts_init (void ); +int mtdids_search_alternate_name (const char *mtdname,char *altname, +unsigned int max_len);int mtdparts_parse_part (struct mtd_info *parent,const char **_mtdparts,struct mtd_partition **_parts,int *_nb_parts);
Signature · 1 line
2.17.1
PATCH v6 27/31 mtd: move mtdparts_init() declaration
Quoted 6 lines · On Thu, 16 Aug 2018 17:30:25 +0200 Miquel Raynal <[email protected]>…
mtdparts_init()is called from various source files. It is declared ininclude/jffs2/load_kernel.hwhile it has nothing to do with jffs2 anymore.Move its declaration to
include/linux/mtd/partitions.hwhich has way more meaning.
Looks like that's not the only change you're doing in this patch.
Quoted 202 lines
Signed-off-by Miquel Raynal <[email protected]>--- cmd/flash.c | 1 + cmd/jffs2.c | 1 + cmd/mtdparts.c | 35 +++++++++++++++++++++++----------- cmd/nand.c | 1 + common/fdt_support.c | 1 + drivers/dfu/dfu_nand.c | 1 + drivers/fastboot/fb_nand.c | 1 + drivers/mtd/mtd_uboot.c | 1 + include/jffs2/load_kernel.h | 1 - include/linux/mtd/partitions.h | 3 +++ 10 files changed, 34 insertions(+), 12 deletions(-)cmd/flash.c +1
-0@@ -12,6 +12,7 @@#if defined(CONFIG_CMD_MTDPARTS )#include <jffs2/jffs2.h> +#include <linux/mtd/partitions.h> /* partition handling routines */ int mtdparts_init (void );cmd/jffs2.c +1
-0@@ -76,6 +76,7 @@#include <jffs2/jffs2.h> #include <linux/list.h> #include <linux/ctype.h> +#include <linux/mtd/partitions.h> #include <cramfs/cramfs_fs.h> #if defined(CONFIG_CMD_NAND )cmd/mtdparts.c +24
-11@@ -44,7 +44,7 @@* * 'mtdparts' - partition list * -* mtdparts=mtdparts=<mtd-def>[;<mtd-def>...] +* mtdparts=[mtdparts=]<mtd-def>[;<mtd-def>...] * * <mtd-def> := <mtd-id>:<part-def>[,<part-def>...] * <mtd-id> := unique device tag used by linux kernel to find mtd device (mtd->name) @@ -62,11 +62,11 @@* * 1 NOR Flash, with 1 single writable partition: * mtdids=nor0=edb7312-nor -* mtdparts=mtdparts=edb7312-nor:- +* mtdparts=[mtdparts=]edb7312-nor:- * * 1 NOR Flash with 2 partitions, 1 NAND with one * mtdids=nor0=edb7312-nor,nand0=edb7312-nand -* mtdparts=mtdparts=edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home) +* mtdparts=[mtdparts=]edb7312-nor:256k(ARMboot)ro,-(root);edb7312-nand:-(home) * */ @@ -1170,9 +1170,6 @@ static int generate_mtdparts(char *buf, u32 buflen)return 0 ; } -strcpy (p,"mtdparts=" ); - p +=9 ; -list_for_each (dentry, &devices) { dev = list_entry(dentry, struct mtd_device, link);@@ -1643,11 +1640,9 @@ static int parse_mtdparts(const char *const mtdparts)if (!p) p = mtdparts; -if (strncmp (p,"mtdparts=" ,9 ) !=0 ) { -printf ("mtdparts variable doesn't start with 'mtdparts='\n" ); -return err; - } - p +=9 ; +/* Skip the useless prefix, if any */ +if (strncmp (p,"mtdparts=" ,9 ) ==0 ) + p +=9 ;while (*p !='\0' ) { err =1 ;@@ -1786,6 +1781,24 @@ static int parse_mtdids(const char *const ids)return 0 ; } +int mtdids_search_alternate_name (const char *mtdname,char *altname, +unsigned int max_len) +{ +struct list_head *entry; +struct mtdids *id; + +list_for_each (entry, &mtdids) { + id = list_entry(entry, struct mtdids, link); +if (!strncmp (mtdname, id->mtd_id, max_len)) { +snprintf (altname, max_len,"%s%d" , +MTD_DEV_TYPE (id->type), id->num); + +return 0 ; + } + } + +return -EINVAL ; +}/** * Parse and initialize global mtdids mapping and create global cmd/nand.c +1
-0@@ -21,6 +21,7 @@#include <common.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #include <command.h> #include <console.h> #include <watchdog.h> common/fdt_support.c +1
-0@@ -11,6 +11,7 @@#include <stdio_dev.h> #include <linux/ctype.h> #include <linux/types.h> +#include <linux/mtd/partitions.h> #include <asm/global_data.h> #include <linux/libfdt.h> #include <fdt_support.h> drivers/dfu/dfu_nand.c +1
-0@@ -15,6 +15,7 @@#include <div64.h> #include <dfu.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #include <jffs2/load_kernel.h> #include <nand.h> drivers/fastboot/fb_nand.c +1
-0@@ -11,6 +11,7 @@#include <image-sparse.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #include <jffs2/jffs2.h> #include <nand.h> drivers/mtd/mtd_uboot.c +1
-0@@ -5,6 +5,7 @@*/ #include <common.h> #include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> #include <jffs2/jffs2.h> static int get_part(const char *partname, int *idx, loff_t *off, loff_t *size,include/jffs2/load_kernel.h +0
-1@@ -62,7 +62,6 @@ struct mtdids {#define led_blink (x, y, z, a)/* common/cmd_jffs2.c */ -extern int mtdparts_init (void );extern int find_dev_and_part (const char *id,struct mtd_device **dev,u8 *part_num,struct part_info **part);extern struct mtd_device *device_find (u8 type,u8 num);include/linux/mtd/partitions.h +3
-0@@ -87,6 +87,9 @@ int mtd_add_partition(struct mtd_info *master, const char *name,int mtd_del_partition (struct mtd_info *master,int partno);uint64_t mtd_get_device_size (const struct mtd_info *mtd); +int mtdparts_init (void ); +int mtdids_search_alternate_name (const char *mtdname,char *altname, +unsigned int max_len);int mtdparts_parse_part (struct mtd_info *parent,const char **_mtdparts,struct mtd_partition **_parts,int *_nb_parts);
Miquel Raynal
maintainerPATCH v6 27/31 mtd: move mtdparts_init() declaration
Hi Boris,
Boris Brezillon <[email protected]> wrote on Thu, 16 Aug 2018 18:05:26 +0200:
Quoted 11 lines
Quoted 6 lines · On Thu, 16 Aug 2018 17:30:25 +0200 Miquel Raynal <[email protected]>…
mtdparts_init()is called from various source files. It is declared ininclude/jffs2/load_kernel.hwhile it has nothing to do with jffs2 anymore.Move its declaration to
include/linux/mtd/partitions.hwhich has way more meaning.Looks like that's not the only change you're doing in this patch.
Wow, my mistake, during rebase it seems I squashed three different commits. Will fix this in next submission.
Thanks,
Miquèl
Miquel Raynal
maintainerPATCH v6 28/31 mtd: mtdpart: implement proper partition handling
In reply to Miquel RaynalInstead 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.
--- drivers/mtd/mtd-uclass.c | 13 +- drivers/mtd/mtdpart.c | 385 +++++++++++++-------------------- include/linux/mtd/mtd.h | 19 ++ include/linux/mtd/partitions.h | 1 - 4 files changed, 185 insertions(+), 233 deletions(-)
drivers/mtd/mtd-uclass.c +12 -1
@@ -16,10 +16,21 @@int mtd_probe (struct udevice *dev) { +struct mtd_info *mtd; +int ret; +if (device_active (dev))return 0 ; -return device_probe (dev); + ret =device_probe (dev); +if (ret) +return ret; + + mtd =dev_get_uclass_priv (dev); +INIT_LIST_HEAD (&mtd->partitions); +INIT_LIST_HEAD (&mtd->node); + +return 0 ; }UCLASS_DRIVER (mtd) = {
drivers/mtd/mtdpart.c +154 -231
733 lines not on this page · raw message
include/linux/mtd/mtd.h +19 -0
@@ -307,6 +307,15 @@ struct mtd_info {struct udevice *dev;#endif int usecount; + +/* MTD devices do not have any parent. MTD partitions do. */ +struct mtd_info *parent; +/* Offset of the partition relatively to the parent offset */ +u64 offset; +/* List node for this MTD device */ +struct list_head node; +/* List of this MTD devices partitions (if any) */ +struct list_head partitions; };#if IS_ENABLED (CONFIG_DM )
@@ -334,6 +343,16 @@ static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd) }#endif +static inline bool mtd_is_partition (const struct mtd_info *mtd) +{ +return mtd->parent; +} + +static inline struct mtd_info *mtd_part_node_to_info (struct list_head *n) +{ + return container_of(n, struct mtd_info, node); +} +int mtd_ooblayout_ecc (struct mtd_info *mtd,int section,struct mtd_oob_region *oobecc); int mtd_ooblayout_find_eccregion(struct mtd_info *mtd, int eccbyte,
include/linux/mtd/partitions.h +0 -1
@@ -81,7 +81,6 @@ extern void register_mtd_parser(struct mtd_part_parser *parser);extern void deregister_mtd_parser (struct mtd_part_parser *parser);#endif -int mtd_is_partition (const struct mtd_info *mtd);int mtd_add_partition (struct mtd_info *master,const char *name,long long offset,long long length);int mtd_del_partition (struct mtd_info *master,int partno);
Signature · 1 line
2.17.1
PATCH v6 28/31 mtd: mtdpart: implement proper partition handling
+Rafal
Quoted 8 lines · On Thu, 16 Aug 2018 17:30:26 +0200 Miquel Raynal <[email protected]>…
Instead of collecting partitions in a flat list, create a hierarchy within the
mtd_infostructure: 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_infothe offset of the partition, we can get rid of themtd_partstructure.
That's also something I'd like to have in Linux ;-). But you'll probably have to sync with Rafal before porting that to Linux.
Quoted 3 lines
Signed-off-by Miquel Raynal <[email protected]>---
[...]
include/linux/mtd/mtd.h struct mtd_info { · line 312
Quoted 11 lines
include/linux/mtd/mtd.h +3
-0@@ -307,6 +307,15 @@ struct mtd_info {struct udevice *dev;#endif int usecount; + +/* MTD devices do not have any parent. MTD partitions do. */ +struct mtd_info *parent;
Add a blank line after each declaration.
include/linux/mtd/mtd.h struct mtd_info { · line 313
Quoted 1 line
include/linux/mtd/mtd.h +1
-0+/* Offset of the partition relatively to the parent offset */
Say that it must be 0 for real MTD devices (those that are not partitions).
include/linux/mtd/mtd.h struct mtd_info { · line 315
Quoted 2 lines
include/linux/mtd/mtd.h +2
-0+u64 offset; +/* List node for this MTD device */
/* * List node used to add an MTD partition to the parent * partition list. */
include/linux/mtd/mtd.h struct mtd_info { · line 317
Quoted 2 lines
include/linux/mtd/mtd.h +2
-0+struct list_head node; +/* List of this MTD devices partitions (if any) */
/* * List of partitions attached to this MTD device (the parent * MTD device can itself be a partition). */
Quoted 7 lines
include/linux/mtd/mtd.h +1
-0+struct list_head partitions; };#if IS_ENABLED (CONFIG_DM )@@ -334,6 +343,16 @@ static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd) }#endif
include/linux/mtd/mtd.h static inline const struct device_node *mtd_get_of_node(struct mtd_info *mtd) · line 354
Quoted 10 lines
include/linux/mtd/mtd.h +9
-0+static inline bool mtd_is_partition (const struct mtd_info *mtd) +{ +return mtd->parent; +} + +static inline struct mtd_info *mtd_part_node_to_info (struct list_head *n) +{ + return container_of(n, struct mtd_info, node); +}
Do you really need that one? Don't we have a list_for_each_entry() in uboot?
Miquel Raynal
maintainerPATCH v6 29/31 cmd: mtd: add 'mtd' command
In reply to Miquel RaynalThere should not be a 'nand' command, a 'sf' command and certainly not a new 'spi-nand' command. Write a 'mtd' command instead to manage all MTD devices/partitions at once. This should be the preferred way to access any MTD device.
--- cmd/Kconfig | 7 + cmd/Makefile | 1 + cmd/mtd.c | 513 ++++++++++++++++++++++++++++++++++++++++ drivers/mtd/Makefile | 2 +- include/linux/mtd/mtd.h | 1 + 5 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 cmd/mtd.c
cmd/Kconfig +7 -0
@@ -847,6 +847,13 @@ config CMD_MMC_SWRITE Enable support for the "mmc swrite" command to write Android sparse images to eMMC. +config CMD_MTD + bool "mtd" + depends on CMD_MTDPARTS + select MTD_PARTITIONS + help + MTD commands support. + config CMD_NAND bool "nand" default y if NAND_SUNXI
cmd/Makefile +1 -0
@@ -90,6 +90,7 @@ obj-$(CONFIG_CMD_MISC) += misc.o obj-$(CONFIG_CMD_MMC) += mmc.o obj-$(CONFIG_CMD_MMC_SPI) += mmc_spi.o obj-$(CONFIG_MP) += mp.o +obj-$(CONFIG_CMD_MTD) += mtd.o obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o obj-$(CONFIG_CMD_NAND) += nand.o obj-$(CONFIG_CMD_NET) += net.o
cmd/mtd.c new file +513 -0
513 lines not on this page · raw message
drivers/mtd/Makefile +1 -1
@@ -3,7 +3,7 @@ # (C) Copyright 2000-2007 # Wolfgang Denk, DENX Software Engineering, wd at denx.de. -ifneq (,$(findstring y,$(CONFIG_MTD_DEVICE)$(CONFIG_CMD_NAND)$(CONFIG_CMD_ONENAND)$(CONFIG_CMD_SF))) +ifneq (,$(findstring y,$(CONFIG_MTD_DEVICE)$(CONFIG_CMD_NAND)$(CONFIG_CMD_ONENAND)$(CONFIG_CMD_SF)$(CONFIG_CMD_MTD))) obj-y += mtdcore.o mtd_uboot.o endif obj-$(CONFIG_MTD) += mtd-uclass.o
include/linux/mtd/mtd.h +1 -0
@@ -570,6 +570,7 @@ void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset, int *truncated);int mtd_probe (struct udevice *dev); +int mtd_probe_devices (void );#endif #endif /* __MTD_MTD_H__ */
Signature · 1 line
2.17.1
PATCH v6 29/31 cmd: mtd: add 'mtd' command
Quoted 7 lines · On Thu, 16 Aug 2018 17:30:27 +0200 Miquel Raynal <[email protected]>…
There should not be a 'nand' command, a 'sf' command and certainly not a new 'spi-nand' command. Write a 'mtd' command instead to manage all MTD devices/partitions at once. This should be the preferred way to access any MTD device.
Signed-off-by Miquel Raynal <[email protected]>Acked-by Jagan Teki <[email protected]>
[...]
cmd/Kconfig config CMD_MMC_SWRITE · line 852
Quoted 4 lines
cmd/Kconfig +3
-0+config CMD_MTD + bool "mtd" + depends on CMD_MTDPARTS
Shouldn't we select it instead?
Quoted 4 lines
cmd/Kconfig +4
-0+ select MTD_PARTITIONS + help + MTD commands support. +
Miquel Raynal
maintainerPATCH v6 29/31 cmd: mtd: add 'mtd' command
Hi Boris,
Boris Brezillon <[email protected]> wrote on Thu, 16 Aug 2018 18:22:03 +0200:
Quoted 11 lines
Quoted 7 lines · On Thu, 16 Aug 2018 17:30:27 +0200 Miquel Raynal <[email protected]>…
There should not be a 'nand' command, a 'sf' command and certainly not a new 'spi-nand' command. Write a 'mtd' command instead to manage all MTD devices/partitions at once. This should be the preferred way to access any MTD device.
Signed-off-by Miquel Raynal <[email protected]>Acked-by Jagan Teki <[email protected]>
Quoted 8 lines
[...]
cmd/Kconfig config CMD_MMC_SWRITE · line 852
Quoted 4 lines
cmd/Kconfig +3
-0+config CMD_MTD + bool "mtd" + depends on CMD_MTDPARTSShouldn't we select it instead?
No need anymore, I will entirely re-write the functions that are needed to have stateless clean MTD functions taking the best out of the MTD stack.
All of them will be in mtd-uclass.c, declared in include/mtd.h.
Quoted 6 lines
cmd/Kconfig config CMD_MMC_SWRITE · line 856
Quoted 5 lines
cmd/Kconfig +4
-0+ select MTD_PARTITIONS + help + MTD commands support. +
Thanks,
Miquèl
PATCH v6 29/31 cmd: mtd: add 'mtd' command
Quoted 25 lines · On Mon, 20 Aug 2018 18:08:14 +0200 Miquel Raynal <[email protected]>…
Hi Boris,
Boris Brezillon <[email protected]> wrote on Thu, 16 Aug 2018 18:22:03 +0200:
Quoted 11 lines
Quoted 7 lines · On Thu, 16 Aug 2018 17:30:27 +0200 Miquel Raynal <[email protected]>…
There should not be a 'nand' command, a 'sf' command and certainly not a new 'spi-nand' command. Write a 'mtd' command instead to manage all MTD devices/partitions at once. This should be the preferred way to access any MTD device.
Signed-off-by Miquel Raynal <[email protected]>Acked-by Jagan Teki <[email protected]>Quoted 8 lines
[...]
cmd/Kconfig config CMD_MMC_SWRITE · line 852
Quoted 4 lines
cmd/Kconfig +3
-0+config CMD_MTD + bool "mtd" + depends on CMD_MTDPARTSShouldn't we select it instead?
Quoted 5 lines
No need anymore, I will entirely re-write the functions that are needed to have stateless clean MTD functions taking the best out of the MTD stack.
All of them will be in
mtd-uclass.c, declared ininclude/mtd.h.
Hm, I would have put those functions in mtdpart.c, but, as long as mtd-uclass.c is compiled even if CONFIG_DM is not enabled I'm fine with that.
PATCH v6 29/31 cmd: mtd: add 'mtd' command
In reply to Miquel RaynalQuoted 212 lines · On Thu, 16 Aug 2018 17:30:27 +0200 Miquel Raynal <[email protected]>…
There should not be a 'nand' command, a 'sf' command and certainly not a new 'spi-nand' command. Write a 'mtd' command instead to manage all MTD devices/partitions at once. This should be the preferred way to access any MTD device.
Signed-off-by Miquel Raynal <[email protected]>Acked-by Jagan Teki <[email protected]>--- cmd/Kconfig | 7 + cmd/Makefile | 1 + cmd/mtd.c | 513 ++++++++++++++++++++++++++++++++++++++++ drivers/mtd/Makefile | 2 +- include/linux/mtd/mtd.h | 1 + 5 files changed, 523 insertions(+), 1 deletion(-) create mode 100644 cmd/mtd.ccmd/Kconfig +7
-0@@ -847,6 +847,13 @@ config CMD_MMC_SWRITE Enable support for the "mmc swrite" command to write Android sparse images to eMMC. +config CMD_MTD + bool "mtd" + depends on CMD_MTDPARTS + select MTD_PARTITIONS + help + MTD commands support. + config CMD_NAND bool "nand" default y if NAND_SUNXIcmd/Makefile +1
-0@@ -90,6 +90,7 @@ obj-$(CONFIG_CMD_MISC) += misc.o obj-$(CONFIG_CMD_MMC) += mmc.o obj-$(CONFIG_CMD_MMC_SPI) += mmc_spi.o obj-$(CONFIG_MP) += mp.o +obj-$(CONFIG_CMD_MTD) += mtd.o obj-$(CONFIG_CMD_MTDPARTS) += mtdparts.o obj-$(CONFIG_CMD_NAND) += nand.o obj-$(CONFIG_CMD_NET) += net.ocmd/mtd.c new file +160
-0@@ -0,0 +1,513 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* mtd.c +* +* Generic command to handle basic operations on any memory device. +* +* Copyright: Bootlin, 2018 +* Author: Miquèl Raynal <[email protected]> +*/ + +#include <command.h> +#include <common.h> +#include <console.h> +#include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> +#include <malloc.h> +#include <mapmem.h> +#include <dm/device.h> +#include <dm/uclass-internal.h> + +#define MTD_NAME_MAX_LEN 20 + +static void mtd_dump_buf (u8 *buf,uint len,uint offset) +{ +int i, j; + +for (i =0 ; i < len; ) { +printf ("0x%08x:\t" , offset + i); +for (j =0 ; j <8 ; j++) +printf ("%02x " , buf[i + j]); +printf (" " ); + i +=8 ; +for (j =0 ; j <8 ; j++) +printf ("%02x " , buf[i + j]); +printf ("\n" ); + i +=8 ; + } +} + +static void mtd_show_parts (struct mtd_info *mtd,int level) +{ +struct mtd_info *part; +int i; + +if (list_empty (&mtd->partitions)) +return ; + +list_for_each_entry (part, &mtd->partitions, node) { +for (i =0 ; i < level; i++) +printf ("\t" ); +printf ("* %s\n" , part->name); +for (i =0 ; i < level; i++) +printf ("\t" ); +printf (" > Offset: 0x%llx bytes\n" , part->offset); +for (i =0 ; i < level; i++) +printf ("\t" ); +printf (" > Size: 0x%llx bytes\n" , part->size); + +mtd_show_parts (part, level +1 ); + } +} + +static void mtd_show_device (struct mtd_info *mtd) +{ +/* Device */ +printf ("* %s" , mtd->name); +if (mtd->dev) +printf (" [device: %s] [parent: %s] [driver: %s]" , + mtd->dev->name, mtd->dev->parent->name, + mtd->dev->driver->name); +printf ("\n" ); + +/* MTD device information */ +printf (" > type: " ); +switch (mtd->type) { +case MTD_RAM : +printf ("RAM\n" ); +break ; +case MTD_ROM : +printf ("ROM\n" ); +break ; +case MTD_NORFLASH : +printf ("NOR flash\n" ); +break ; +case MTD_NANDFLASH : +printf ("NAND flash\n" ); +break ; +case MTD_DATAFLASH : +printf ("Data flash\n" ); +break ; +case MTD_UBIVOLUME : +printf ("UBI volume\n" ); +break ; +case MTD_MLCNANDFLASH : +printf ("MLC NAND flash\n" ); +break ; +case MTD_ABSENT : +default : +printf ("Unknown\n" ); +break ; + } + +printf (" > Size: 0x%llx bytes\n" , mtd->size); +printf (" > Block: 0x%x bytes\n" , mtd->erasesize); +printf (" > Min I/O: 0x%x bytes\n" , mtd->writesize); + +if (mtd->oobsize) { +printf (" > OOB size: %u bytes\n" , mtd->oobsize); +printf (" > OOB available: %u bytes\n" , mtd->oobavail); + } + +if (mtd->ecc_strength) { +printf (" > ECC strength: %u bits\n" , mtd->ecc_strength); +printf (" > ECC step size: %u bytes\n" , mtd->ecc_step_size); +printf (" > Bitflip threshold: %u bits\n" , + mtd->bitflip_threshold); + } + +/* MTD partitions, if any */ +mtd_show_parts (mtd,1 ); +} + +/* +* Ensure the MTD device partition list has been initialized already (needed for +* non DM-compliant devices). +*/ +static void mtd_quirk_init_non_dm_device_lists (void ) +{ +struct mtd_info *mtd; + +mtd_for_each_device (mtd) { +if (!mtd_is_partition (mtd) && !mtd->partitions.next) { +INIT_LIST_HEAD (&mtd->partitions); +INIT_LIST_HEAD (&mtd->node); + } + } +} + +#if IS_ENABLED (CONFIG_DM ) +static void mtd_probe_uclass_mtd_devs (void ) +{ +struct udevice *dev; +int idx =0 ; + +/* Probe devices with DM compliant drivers */ +while (!uclass_find_device (UCLASS_MTD , idx, &dev) && dev) { +mtd_probe (dev); + idx++; + } +} +#else +static void mtd_probe_uclass_mtd_devs (void ) { } +#endif + +int mtd_probe_devices (void ) +{ +const char *mtdparts =env_get ("mtdparts" ); + +mtd_quirk_init_non_dm_device_lists (); +
cmd/mtd.c line 170
Quoted 10 lines
cmd/mtd.c new file +10
-0+mtd_probe_uclass_mtd_devs (); + +/* Create the partitions defined in mtdparts, here the fun begins */ + +/* Ignore the extra 'mtdparts=' prefix if any */ +if (strstr (mtdparts,"mtdparts=" )) + mtdparts +=9 ; + +/* For each MTD device in mtdparts */ +while (mtdparts[0 ] !='\0' ) {
Hm, so you're unconditionally re-parsing mtdparts, even if nothing changed since the last time you parsed it? Might be expensing if mtd read/write is called iteratively on small MTD portions.
cmd/mtd.c line 178
Quoted 8 lines
cmd/mtd.c new file +8
-0+struct mtd_partition *parts; +struct list_head *iterator; +bool part_in_use = false; +struct mtd_info *parent; +char mtdname[MTD_NAME_MAX_LEN ]; +int mtdname_len, len, ret; + + mtdname_len =strchr (mtdparts,':' ) - mtdparts;
What if mtdparts is malformed? strchr() might return NULL if it didn't find ':', and you probably want to stop parsing mtdparts in that case.
Quoted 97 lines
cmd/mtd.c new file +97
-0+strncpy (mtdname, mtdparts, mtdname_len); + mtdname[mtdname_len] ='\0' ; +/* Move the pointer forward (including the ':') */ + mtdparts += mtdname_len +1 ; + parent =get_mtd_device_nm (mtdname); +if (IS_ERR_OR_NULL (parent)) { +char altname[MTD_NAME_MAX_LEN ]; + +/* +* The MTD device named "mtdname" does not exist. Try to +* find a correspondance with an MTD device having the +* same type and number as defined in the mtdids. +*/ +printf ("No device named %s\n" , mtdname); + + ret =mtdparts_init (); +if (ret) { +printf ("Could not initialize mtdparts\n" ); +return ret; + } + + ret =mtdids_search_alternate_name (mtdname, altname, +MTD_NAME_MAX_LEN ); +if (ret) { +printf ("Did not found an equivalent in mtdids\n" ); +return ret; + } + + parent =get_mtd_device_nm (altname); +if (IS_ERR_OR_NULL (parent)) { +printf ("No device named %s\n" , altname); +return -EINVAL ; + } + } +put_mtd_device (parent); + +/* +* Parse the MTD device partitions. It will update the mtdparts +* pointer, create an array of parts (that must be freed), and +* return the number of partition structures in the array. +*/ + ret =mtdparts_parse_part (parent, &mtdparts, &parts, &len); +if (ret) { +printf ("Could not parse device %s\n" , parent->name); +return -EINVAL ; + } + +if (!len) +continue ; + +/* Check that no partition is actually in use */ +list_for_each (iterator, &parent->partitions) { +struct mtd_info *p =mtd_part_node_to_info (iterator); + +if (p->usecount) { +printf ("MTD partition \"%s\" already in use.\n" , + p->name); + part_in_use = true; + } + } + +if (part_in_use) { +printf ("Not reconstructing partition list for MTD device %s\n" , + parent->name); +continue ; + } + +/* Free the existing partitions */ +del_mtd_partitions (parent); + +/* Create the new MTD partitions */ +add_mtd_partitions (parent, parts, len); +free (parts); + } + +return 0 ; +} + +static uint mtd_len_to_pages (struct mtd_info *mtd,u64 len) +{ +do_div (len, mtd->writesize); + +return len; +} + +static bool mtd_is_aligned_with_min_io_size (struct mtd_info *mtd,u64 size) +{ +return do_div (size, mtd->writesize); +} + +static bool mtd_is_aligned_with_block_size (struct mtd_info *mtd,u64 size) +{ +return do_div (size, mtd->erasesize); +} + +static int do_mtd_list (void ) +{
cmd/mtd.c line 285
Quoted 10 lines
cmd/mtd.c new file +10
-0+struct mtd_info *mtd; +int dev_nb =0 ; + +/* Ensure all devices (and their partitions) are probed */ +mtd_probe_devices (); + +printf ("List of MTD devices:\n" ); +mtd_for_each_device (mtd) { +if (!mtd_is_partition (mtd)) +mtd_show_device (mtd);
I would print partitions too, and if possible, put them under the master device with an extra level of indentation.
Quoted 31 lines
cmd/mtd.c new file +31
-0+ + dev_nb++; + } + +if (!dev_nb) { +printf ("No MTD device found\n" ); +return CMD_RET_FAILURE ; + } + +return 0 ; +} + +static int do_mtd (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +struct mtd_info *mtd; +const char *cmd; +char *mtdname; +int ret; + +/* All MTD commands need at least two arguments */ +if (argc <2 ) +return CMD_RET_USAGE ; + +/* Parse the command name and its optional suffixes */ + cmd = argv[1 ]; + +/* List the MTD devices if that is what the user wants */ +if (strcmp (cmd,"list" ) ==0 ) +return do_mtd_list (); + +/*
cmd/mtd.c line 326
Quoted 10 lines
cmd/mtd.c new file +10
-0+* The remaining commands require also at least a device ID. +* Check the selected device is valid. Ensure it is probed. +*/ +if (argc <3 ) +return CMD_RET_USAGE ; + + mtdname = argv[2 ]; + mtd =get_mtd_device_nm (mtdname); +if (IS_ERR_OR_NULL (mtd)) { +mtd_probe_devices ();
Actually this should be done unconditionally, just in case the object returned by get_mtd_device_nm() is a partition. mtdparts env var might have changed between the 2 mtd xxx calls, and the partition we've been given might no longer be valid. The solution would be to avoid re-parsing things when mtdparts didn't change (you can check that in mtd_probe_devices()).
cmd/mtd.c line 331
Quoted 5 lines
cmd/mtd.c new file +5
-0+ mtd =get_mtd_device_nm (mtdname); +if (IS_ERR_OR_NULL (mtd)) { +printf ("MTD device %s not found, ret %ld\n" , + mtdname,PTR_ERR (mtd)); +return 1 ;
return CMD_RET_FAILURE;
cmd/mtd.c line 335
Quoted 4 lines
cmd/mtd.c new file +4
-0+ } + } +put_mtd_device (mtd); +
Why do you call put_mtd_device() here? You should retain the reference until you're done interacting with the device.
PATCH v6 29/31 cmd: mtd: add 'mtd' command
In reply to Miquel RaynalQuoted 3 lines · On Thu, 16 Aug 2018 17:30:27 +0200 Miquel Raynal <[email protected]>…
+/*
+ * Ensure the MTD device partition list has been initialized already (needed for
+ * non DM-compliant devices).
I don't see what this has to do with DM vs non-DM drivers. All MTD devices are registered to the MTD framework, right? So there's probably a place where this list initialization can be done for everyone.
cmd/mtd.c line 134
Quoted 9 lines
+ */
cmd/mtd.c new file +8
-0+static void mtd_quirk_init_non_dm_device_lists (void ) +{ +struct mtd_info *mtd; + +mtd_for_each_device (mtd) { +if (!mtd_is_partition (mtd) && !mtd->partitions.next) { +INIT_LIST_HEAD (&mtd->partitions); +INIT_LIST_HEAD (&mtd->node);
Hm, how about moving this initialization in add_mtd_device()?
Quoted 4 lines
cmd/mtd.c new file +4
-0+ } + } +} +
Miquel Raynal
maintainerPATCH v6 30/31 cmd: mtdparts: try to probe the MTD devices as a fallback
In reply to Miquel RaynalCurrent implementation of mtdparts command errors out if the desired MTD device is not found. Fallback to the new probe function in this case before erroring out.
This will the save the user the need to call something like 'mtd list' before mtdparts.
--- cmd/mtdparts.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
cmd/mtdparts.c +9 -3
@@ -308,9 +308,15 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)sprintf (mtd_dev,"%s%d" ,MTD_DEV_TYPE (type), num); *mtd =get_mtd_device_nm (mtd_dev); -if (IS_ERR (*mtd)) { -printf ("Device %s not found!\n" , mtd_dev); -return 1 ; +if (IS_ERR_OR_NULL (*mtd)) { +#ifdef CONFIG_CMD_MTD +mtd_probe_devices (); + *mtd =get_mtd_device_nm (mtd_dev); +#endif +if (IS_ERR_OR_NULL (*mtd)) { +printf ("Device %s not found!\n" , mtd_dev); +return 1 ; + } }put_mtd_device (*mtd);
Signature · 1 line
2.17.1
PATCH v6 30/31 cmd: mtdparts: try to probe the MTD devices as a fallback
Quoted 18 lines · On Thu, 16 Aug 2018 17:30:28 +0200 Miquel Raynal <[email protected]>…
Current implementation of mtdparts command errors out if the desired MTD device is not found. Fallback to the new probe function in this case before erroring out.
This will the save the user the need to call something like 'mtd list' before mtdparts.
Signed-off-by Miquel Raynal <[email protected]>Acked-by Jagan Teki <[email protected]>--- cmd/mtdparts.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)cmd/mtdparts.c +0
-0
cmd/mtdparts.c static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd) · line 314
Quoted 10 lines
cmd/mtdparts.c +4
-3@@ -308,9 +308,15 @@ static int get_mtd_info(u8 type, u8 num, struct mtd_info **mtd)sprintf (mtd_dev,"%s%d" ,MTD_DEV_TYPE (type), num); *mtd =get_mtd_device_nm (mtd_dev); -if (IS_ERR (*mtd)) { -printf ("Device %s not found!\n" , mtd_dev); -return 1 ; +if (IS_ERR_OR_NULL (*mtd)) { +#ifdef CONFIG_CMD_MTD +mtd_probe_devices (); + *mtd =get_mtd_device_nm (mtd_dev);
Hm, just like for mtdparts_parse_part(), maybe we should have mtd_probe_devices() defined in drivers/mtd/mtd-uclass.c and selected with CONFIG_MTD, not CMD_MTD.
Quoted 8 lines
cmd/mtdparts.c +5
-0+#endif +if (IS_ERR_OR_NULL (*mtd)) { +printf ("Device %s not found!\n" , mtd_dev); +return 1 ; + } }put_mtd_device (*mtd);
Miquel Raynal
maintainerPATCH v6 31/31 cmd: ubi: clean the partition handling
In reply to Miquel RaynalUBI should not mess with MTD partitions, now that the partitions are handled in a clean way, clean the ubi command and avoid using this uneeded extra-glue to reference the devices.
--- cmd/ubi.c | 95 ++++++++++++++----------------------------------------- 1 file changed, 24 insertions(+), 71 deletions(-)
cmd/ubi.c +24 -71
@@ -29,17 +29,6 @@/* Private own data */ static struct ubi_device *ubi; -static char buffer[80 ]; -static int ubi_initialized; - -struct selected_dev { -char part_name[80 ]; -int selected; -int nr; -struct mtd_info *mtd_info; -}; - -static struct selected_dev ubi_dev;#ifdef CONFIG_CMD_UBIFS int ubifs_is_mounted (void );
@@ -404,43 +393,24 @@ int ubi_volume_read(char *volume, char *buf, size_t size)return err; } -static int ubi_dev_scan (struct mtd_info *info,char *ubidev, -const char *vid_header_offset) +static int ubi_dev_scan (struct mtd_info *info,const char *vid_header_offset) { -struct mtd_device *dev; -struct part_info *part; -struct mtd_partition mtd_part;char ubi_mtd_param_buffer[80 ]; -u8 pnum;int err; -if (find_dev_and_part (ubidev, &dev, &pnum, &part) !=0 ) -return 1 ; +if (!vid_header_offset) +sprintf (ubi_mtd_param_buffer,"%s" , info->name); +else +sprintf (ubi_mtd_param_buffer,"%s,%s" , info->name, + vid_header_offset); -sprintf (buffer,"mtd=%d" , pnum); -memset (&mtd_part,0 ,sizeof (mtd_part)); - mtd_part.name = buffer; - mtd_part.size = part->size; - mtd_part.offset = part->offset; -add_mtd_partitions (info, &mtd_part,1 ); - -strcpy (ubi_mtd_param_buffer, buffer); -if (vid_header_offset) -sprintf (ubi_mtd_param_buffer,"mtd=%d,%s" , pnum, - vid_header_offset); err =ubi_mtd_param_parse (ubi_mtd_param_buffer,NULL ); -if (err) { -del_mtd_partitions (info); +if (err)return -err; - } err =ubi_init (); -if (err) { -del_mtd_partitions (info); +if (err)return -err; - } - - ubi_initialized =1 ;return 0 ; }
@@ -465,50 +435,33 @@ int ubi_detach(void)/* * Call ubi_exit() before re-initializing the UBI subsystem */ -if (ubi_initialized) { +if (ubi)ubi_exit (); -del_mtd_partitions (ubi_dev.mtd_info); - ubi_initialized =0 ; - } - ubi_dev.selected =0 ; + ubi =NULL ; +return 0 ; }int ubi_part (char *part_name,const char *vid_header_offset) { +struct mtd_info *mtd;int err =0 ; -char mtd_dev[16 ]; -struct mtd_device *dev; -struct part_info *part; -u8 pnum;ubi_detach (); -/* -* Search the mtd device number where this partition -* is located -*/ -if (find_dev_and_part (part_name, &dev, &pnum, &part)) { + +mtd_probe_devices (); + mtd =get_mtd_device_nm (part_name); +if (IS_ERR (mtd)) {printf ("Partition %s not found!\n" , part_name);return 1 ; } -sprintf (mtd_dev,"%s%d" ,MTD_DEV_TYPE (dev->id->type), dev->id->num); - ubi_dev.mtd_info =get_mtd_device_nm (mtd_dev); -if (IS_ERR (ubi_dev.mtd_info)) { -printf ("Partition %s not found on device %s!\n" , part_name, - mtd_dev); -return 1 ; - } +put_mtd_device (mtd); - ubi_dev.selected =1 ; - -strcpy (ubi_dev.part_name, part_name); - err =ubi_dev_scan (ubi_dev.mtd_info, ubi_dev.part_name, - vid_header_offset); + err =ubi_dev_scan (mtd, vid_header_offset);if (err) {printf ("UBI init error %d\n" , err);printf ("Please check, if the correct MTD partition is used (size big enough?)\n" ); - ubi_dev.selected =0 ;return err; }
@@ -539,13 +492,13 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])/* Print current partition */ if (argc ==2 ) { -if (!ubi_dev.selected) { -printf ("Error, no UBI device/partition selected!\n" ); +if (!ubi) { +printf ("Error, no UBI device selected!\n" );return 1 ; } -printf ("Device %d: %s, partition %s\n" , - ubi_dev.nr, ubi_dev.mtd_info->name, ubi_dev.part_name); +printf ("Device %d: %s, MTD partition %s\n" , + ubi->ubi_num, ubi->ubi_name, ubi->mtd->name);return 0 ; }
@@ -558,8 +511,8 @@ static int do_ubi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])return ubi_part (argv[2 ], vid_header_offset); } -if ((strcmp (argv[1 ],"part" ) !=0 ) && (!ubi_dev.selected)) { -printf ("Error, no UBI device/partition selected!\n" ); +if ((strcmp (argv[1 ],"part" ) !=0 ) && !ubi) { +printf ("Error, no UBI device selected!\n" );return 1 ; }
Signature · 1 line
2.17.1
PATCH v6 31/31 cmd: ubi: clean the partition handling
Quoted 8 lines · On Thu, 16 Aug 2018 17:30:29 +0200 Miquel Raynal <[email protected]>…
int
ubi_part(char *part_name, const char *vid_header_offset){cmd/ubi.c +1
-3+struct mtd_info *mtd;int err =0 ; -char mtd_dev[16 ]; -struct mtd_device *dev; -struct part_info *part;
cmd/ubi.c int ubi_detach(void) · line 453
Quoted 10 lines
cmd/ubi.c +2
-6-u8 pnum;ubi_detach (); -/* -* Search the mtd device number where this partition -* is located -*/ -if (find_dev_and_part (part_name, &dev, &pnum, &part)) { + +mtd_probe_devices ();
This function is only available if CONFIG_CMD_MTD=y, and you didn't add the dependency on CMD_MTD. Anyway, as said earlier, I think this function should be moved out of cmd/mtd.c.
Quoted 5 lines
cmd/ubi.c +2
-0+ mtd =get_mtd_device_nm (part_name); +if (IS_ERR (mtd)) {printf ("Partition %s not found!\n" , part_name);return 1 ; }
v6 cover SPI-NAND support
In reply to Miquel RaynalTom, Jagan,
Quoted 25 lines · On Thu, 16 Aug 2018 17:29:58 +0200 Miquel Raynal <[email protected]>…
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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- Support for spi-nand devices in mtdparts.
Quoted 9 lines
To test your SPI-NAND device with U-Boot simply follow these lines:
Quoted 3 lines
setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
ubi part bar # create a static UBI volume in the bar partition
mtd list # show the current MTD devices/partitionsThanks,
Miquèl
[...]
Can we get some of those patches merged to avoid sending another version containing more than 30 patches. Here is a list of patches which IMO are ready to be merged:
- 1 to 4
- 5 and 6 if 6 is squashed in 5
- 7 to 23
Regards,
Boris
Miquel Raynal
maintainerv6 cover SPI-NAND support
Hi Tom, Jagan,
Boris Brezillon <[email protected]> wrote on Thu, 16 Aug 2018 18:58:58 +0200:
Quoted 42 lines
Tom, Jagan,
Quoted 34 lines · On Thu, 16 Aug 2018 17:29:58 +0200 Miquel Raynal <[email protected]>…
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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- Support for spi-nand devices in mtdparts.To test your SPI-NAND device with U-Boot simply follow these lines:
Quoted 3 lines
setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
ubi part bar # create a static UBI volume in the bar partition
mtd list # show the current MTD devices/partitionsThanks,
Miquèl[...]
Quoted 8 lines
Can we get some of those patches merged to avoid sending another version containing more than 30 patches. Here is a list of patches which IMO are ready to be merged:
- 1 to 4
- 5 and 6 if 6 is squashed in 5
- 7 to 23
Yes, I agree with Boris, I do not want to resend another 30+ patch series while the changes are on the last 5 only, could one of you please apply them from 1 to 23 (with 6 squashed in 5) ?
Next week I will send a v7 for patches 24..31.
Thanks,
Miquèl
Miquel Raynal
maintainerv6 cover SPI-NAND support
Hello,
Miquel Raynal <[email protected]> wrote on Fri, 17 Aug 2018 10:38:46 +0200:
Quoted 56 lines
Hi Tom, Jagan,
Boris Brezillon <[email protected]> wrote on Thu, 16 Aug 2018 18:58:58 +0200:
Quoted 42 lines
Tom, Jagan,
Quoted 34 lines · On Thu, 16 Aug 2018 17:29:58 +0200 Miquel Raynal <[email protected]>…
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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- Support for spi-nand devices in mtdparts.To test your SPI-NAND device with U-Boot simply follow these lines:
Quoted 3 lines
setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
ubi part bar # create a static UBI volume in the bar partition
mtd list # show the current MTD devices/partitionsThanks,
Miquèl[...]
Quoted 8 lines
Can we get some of those patches merged to avoid sending another version containing more than 30 patches. Here is a list of patches which IMO are ready to be merged:
- 1 to 4
- 5 and 6 if 6 is squashed in 5
- 7 to 23
Quoted 5 lines
Yes, I agree with Boris, I do not want to resend another 30+ patch series while the changes are on the last 5 only, could one of you please apply them from 1 to 23 (with 6 squashed in 5) ?
Next week I will send a v7 for patches 24..31.
I am almost ready to send a new iteration for the last set of patches, can I have your feedback on the first set (up to 23)?
Thanks,
Miquèl
v6 cover SPI-NAND support
Quoted 59 lines · Miquel Raynal
Hello,
Miquel Raynal <[email protected]> wrote on Fri, 17 Aug 2018 10:38:46 +0200:
Quoted 54 lines
Hi Tom, Jagan,
Boris Brezillon <[email protected]> wrote on Thu, 16 Aug 2018 18:58:58 +0200:
Quoted 49 lines
Tom, Jagan,
Quoted 25 lines · On Thu, 16 Aug 2018 17:29:58 +0200 Miquel Raynal <[email protected]>…
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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- Support for spi-nand devices in mtdparts.Quoted 9 lines
To test your SPI-NAND device with U-Boot simply follow these lines:
Quoted 3 lines
setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
ubi part bar # create a static UBI volume in the bar partition
mtd list # show the current MTD devices/partitionsThanks,
Miquèl[...]
Can we get some of those patches merged to avoid sending another version containing more than 30 patches. Here is a list of patches which IMO are ready to be merged:
- 1 to 4
- 5 and 6 if 6 is squashed in 5
- 7 to 23
Yes, I've picked these and build is under progress [1]
[1] https://travis-ci.org/openedev/u-boot-amarula/builds/423668176
Miquel Raynal
maintainerv6 cover SPI-NAND support
Hi Jagan,
Jagan Teki <[email protected]> wrote on Sun, 2 Sep 2018 23:47:37 +0530:
Quoted 58 lines
Quoted 56 lines · Miquel Raynal
Hello,
Miquel Raynal <[email protected]> wrote on Fri, 17 Aug 2018 10:38:46 +0200:
Quoted 51 lines
Hi Tom, Jagan,
Boris Brezillon <[email protected]> wrote on Thu, 16 Aug 2018 18:58:58 +0200:
Quoted 46 lines
Tom, Jagan,
Quoted 25 lines · On Thu, 16 Aug 2018 17:29:58 +0200 Miquel Raynal <[email protected]>…
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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- Support for spi-nand devices in mtdparts.Quoted 9 lines
To test your SPI-NAND device with U-Boot simply follow these lines:
Quoted 3 lines
setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
ubi part bar # create a static UBI volume in the bar partition
mtd list # show the current MTD devices/partitionsThanks,
Miquèl[...]
Can we get some of those patches merged to avoid sending another version containing more than 30 patches. Here is a list of patches which IMO are ready to be merged:
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
- 1 to 4
- 5 and 6 if 6 is squashed in 5
- 7 to 23Yes, I've picked these and build is under progress [1]
[1] https://travis-ci.org/openedev/u-boot-amarula/builds/423668176
Cool! I'll poll the page for build errors but do not hesitate to ping if you see something wrong.
Thanks,
Miquèl
v6 cover SPI-NAND support
Quoted 67 lines · Miquel Raynal
Hi Jagan,
Jagan Teki <[email protected]> wrote on Sun, 2 Sep 2018 23:47:37 +0530:
Quoted 62 lines
Quoted 59 lines · Miquel Raynal
Hello,
Miquel Raynal <[email protected]> wrote on Fri, 17 Aug 2018 10:38:46 +0200:
Quoted 54 lines
Hi Tom, Jagan,
Boris Brezillon <[email protected]> wrote on Thu, 16 Aug 2018 18:58:58 +0200:
Quoted 49 lines
Tom, Jagan,
Quoted 25 lines · On Thu, 16 Aug 2018 17:29:58 +0200 Miquel Raynal <[email protected]>…
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:
- A few patches from Linux to resynchronize some areas of the MTD layer.
- Various fixes and re-organization of the MTD subsystem.
- The introduction of the SPI-mem interface.
- The addition of the generic SPI-NAND driver (and its bindings).
- Several SPI NAND chip drivers (Macronix, Micron, Winbond).
- A new 'mtd' command.
- Support for spi-nand devices in mtdparts.Quoted 9 lines
To test your SPI-NAND device with U-Boot simply follow these lines:
Quoted 3 lines
setenv mtdparts mtdparts=spi-nand0:1m(foo),-(bar)
ubi part bar # create a static UBI volume in the bar partition
mtd list # show the current MTD devices/partitionsThanks,
Miquèl[...]
Can we get some of those patches merged to avoid sending another version containing more than 30 patches. Here is a list of patches which IMO are ready to be merged:
- 1 to 4
- 5 and 6 if 6 is squashed in 5
- 7 to 23
Quoted 6 lines
Quoted 3 lines
Yes, I've picked these and build is under progress [1]
[1] https://travis-ci.org/openedev/u-boot-amarula/builds/423668176
Cool! I'll poll the page for build errors but do not hesitate to ping if you see something wrong.
Build look fine, let me know about final version of "Cleaner MTD devices management"