Skip to content

mtd: ubi: allow UBI volumes to provide NVMEM

Daniel Golle linux-devicetree linux-mtd lkml 8 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest7 patches 0 repliesNew
  2. v77 patches 9 repliesSuperseded
  3. v67 patches 1 replySuperseded
Earlier versions · 5
VersionPostedPatchesRepliesStatus
v57 patches2 repliesSuperseded
v48 patches10 repliesSuperseded
v38 patches2 repliesSuperseded
v27 patches0 repliesSuperseded
v16 patches1 replySuperseded

Changes in v8 from the cover letter

* use integer types with well-defined size for use with do_div(n, base) (addresses compiler warning when building on 32-bit platforms)

Patches in v8 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7dt-bindings: mtd: add basic bindings for UBIDocumentation/devicetree/bindings/mtd/partitions/linux,ubi.yaml Documentation/devicetree/bindings/mtd/partitions/ubi-volume.yaml+100 -00 replies
2/7dt-bindings: mtd: ubi-volume: allow UBI volumes to provide NVMEMDocumentation/devicetree/bindings/mtd/partitions/linux,ubi.yaml Documentation/devicetree/bindings/mtd/partitions/ubi-volume.yaml+15 -00 replies
3/7mtd: ubi: block: use notifier to create ubiblock from parameterdrivers/mtd/ubi/block.c drivers/mtd/ubi/kapi.c drivers/mtd/ubi/ubi.h+106 -850 replies
4/7mtd: ubi: attach from device treedrivers/mtd/ubi/build.c+96 -390 replies
5/7mtd: ubi: introduce pre-removal notification for UBI volumesdrivers/mtd/ubi/build.c drivers/mtd/ubi/kapi.c drivers/mtd/ubi/ubi.h +2 more+34 -80 replies
6/7mtd: ubi: populate ubi volume fwnodedrivers/mtd/ubi/vmt.c+27 -00 replies
7/7mtd: ubi: provide NVMEM layer over UBI volumesdrivers/mtd/ubi/Kconfig drivers/mtd/ubi/Makefile drivers/mtd/ubi/nvmem.c+205 -00 replies

Reviews trailers per patch

2 of 7 patches have a Reviewed-by or Acked-by.

PatchRob Herring
1/7R-b
2/7R-b
3/7
4/7
5/7
6/7
7/7

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v8 thread

Cover letter [PATCH v8 0/7] mtd: ubi: allow UBI volumes to provide NVMEM

Similar to how MAC addresses and Wi-Fi calibration data would be stored inside an MTD partition on devices coming with NOR flash, a UBI volume is used by some vendors in the same way on devices with NAND flash.

The goal of this series is to support such embedded Linux devices which got NVMEM bits stored inside a UBI volume.

Representing the UBI volume in the Device Tree and adding a phandle to be referenced by NVMEM consumers allows such devices to come up with their correct MAC addresses and device-specific Wi-Fi calibration data loaded.

In order for NVMEM bits to be available for other drivers, attaching UBI devices has to be moved from late_initcall (which is too late for other drivers) to happen earlier. As an alternative to the existing kernel cmdline parameter the Device Tree property 'compatible = "linux,ubi";' inside an MTD partition can be used to have that MTD device attached as UBI device. MTD partitions which serve as UBI devices may have a "volumes" subnode with volumes, and volumes may have an "nvmem-layout" object which will trigger the creation of an emulated NVMEM device on top of the UBI volume.

In this way, other drivers (think: Ethernet, Wi-Fi) can resolve and acquire NVMEM bits using the usual device tree phandle, just this time the NVMEM content is read from a UBI volume.

This series is a follow-up and contains most patches of the previous series "mtd: ubi: behave like a good MTD citizen"[1] which was meant in preparation for implementing the NVMEM provider.

As lots of time has passed NVMEM-on-UBI is by now already in-use downstream at OpenWrt to support reading WiFi EEPROMs and MAC addresses on a bunch of ASUS devices[2], [3] which laudably store all in UBI. That also exposed a possible issue on 32-bit platforms which has now been addressed in v8.

[1]: https://patchwork.ozlabs.org/project/linux-mtd/list/?series=353177&state=%2A&archive=both
[2]: https://github.com/openwrt/openwrt/pull/14676 (merged)
[3]: https://github.com/openwrt/openwrt/pull/14729 (pending)

Changes since v7:
* use integer types with well-defined size for use with do_div(n, base) (addresses compiler warning when building on 32-bit platforms)

Changes since v6:
* dt-bindings fixes got squashed into the wrong patch, fix that and newly introduced YAML white space issues

Changes since v5:
* fix whitespace problems in dt-schema additions

Changes since v4:
* split ubi_open_volume_path() breaking out reusable parts for new match_volume_desc() function as suggested by Richard Weinberger. Doing the same for ubi_open_volume_nm() doesn't work as we are working on struct ubi_volume_info in match_volume_desc() while ubi_open_volume_nm() is working on struct ubi_volume. That reduces the common part to a string comparision and length check which doesn't seem worth breaking out of the existing function.
* drop patches and changes not strictly needed for NVMEM use-case:
- don't handle ubi detach on MTD removal notification. It was not done until now and the locking hell I was facing when trying to implement that is non trivial.
- don't relocate the call to ubiblock device creation to the notification handler
- change ubiblock only as far as needed to handle creation from cmdline parameter when a volume is added.
* improve commit messages and comments

Changes since v3:
* dt-bindings fixes as requested

Changes since v2:
* include dt-bindings additions

Changes since v1:
* include patch to fix exiting Kconfig formatting issues
* fix typo and indentation in Kconfig

Daniel Golle (7):
dt-bindings: mtd: add basic bindings for UBI
dt-bindings: mtd: ubi-volume: allow UBI volumes to provide NVMEM
mtd: ubi: block: use notifier to create ubiblock from parameter
mtd: ubi: attach from device tree
mtd: ubi: introduce pre-removal notification for UBI volumes
mtd: ubi: populate ubi volume fwnode
mtd: ubi: provide NVMEM layer over UBI volumes

 .../bindings/mtd/partitions/linux,ubi.yaml    |  75 +++++++
 .../bindings/mtd/partitions/ubi-volume.yaml   |  40 ++++
 drivers/mtd/ubi/Kconfig                       |  13 ++
 drivers/mtd/ubi/Makefile                      |   1 +
 drivers/mtd/ubi/block.c                       | 136 ++++++-------
 drivers/mtd/ubi/build.c                       | 154 ++++++++++----
 drivers/mtd/ubi/kapi.c                        |  56 +++--
 drivers/mtd/ubi/nvmem.c                       | 191 ++++++++++++++++++
 drivers/mtd/ubi/ubi.h                         |   3 +
 drivers/mtd/ubi/vmt.c                         |  44 +++-
 include/linux/mtd/ubi.h                       |   2 +
 11 files changed, 583 insertions(+), 132 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/mtd/partitions/linux,ubi.yaml
 create mode 100644 Documentation/devicetree/bindings/mtd/partitions/ubi-volume.yaml
 create mode 100644 drivers/mtd/ubi/nvmem.c
Signature · 1 line
2.44.0