110-mtd-limit-OTP-nvmem-to-non-nand-devices.patch 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. From 540dcef6f39d6356d2a65230a8d4e9738ee2d25b Mon Sep 17 00:00:00 2001
  2. From: Christian Marangi <[email protected]>
  3. Date: Wed, 20 Mar 2024 16:43:01 +0100
  4. Subject: [PATCH] mtd: limit OTP nvmem to non nand devices
  5. MTD OTP logic is very fragile and can be problematic with some specific
  6. kind of devices.
  7. NVMEM across the years had various iteration on how Cells could be
  8. declared in DT and MTD OTP probably was left behind and
  9. add_legacy_fixed_of_cells was enabled without thinking of the consequences.
  10. That option enables NVMEM to scan the provided of_node and treat each
  11. child as a NVMEM Cell, this was to support legacy NVMEM implementation
  12. and don't cause regression.
  13. This is problematic if we have devices like Nand where the OTP is
  14. triggered by setting a special mode in the flash. In this context real
  15. partitions declared in the Nand node are registered as OTP Cells and
  16. this cause probe fail with -EINVAL error.
  17. This was never notice due to the fact that till now, no Nand supported
  18. the OTP feature. With commit e87161321a40 ("mtd: rawnand: macronix: OTP
  19. access for MX30LFxG18AC") this changed and coincidentally this Nand is
  20. used on an FritzBox 7530 supported on OpenWrt.
  21. Alternative and more robust way to declare OTP Cells are already
  22. prossible by using the fixed-layout node or by declaring a child node
  23. with the compatible set to "otp-user" or "otp-factory".
  24. To fix this and limit any regression with other MTD that makes use of
  25. declaring OTP as direct child of the dev node, disable
  26. add_legacy_fixed_of_cells if we have a node called nand since it's the
  27. standard property name to identify Nand devices attached to a Nand
  28. Controller.
  29. With the following logic, the OTP NVMEM entry is correctly created with
  30. no Cells and the MTD Nand is correctly probed and partitions are
  31. correctly exposed.
  32. Fixes: 2cc3b37f5b6d ("nvmem: add explicit config option to read old syntax fixed OF cells")
  33. Cc: <[email protected]>
  34. Signed-off-by: Christian Marangi <[email protected]>
  35. ---
  36. drivers/mtd/mtdcore.c | 2 +-
  37. 1 file changed, 1 insertion(+), 1 deletion(-)
  38. --- a/drivers/mtd/mtdcore.c
  39. +++ b/drivers/mtd/mtdcore.c
  40. @@ -933,7 +933,7 @@ static struct nvmem_device *mtd_otp_nvme
  41. config.name = compatible;
  42. config.id = NVMEM_DEVID_AUTO;
  43. config.owner = THIS_MODULE;
  44. - config.add_legacy_fixed_of_cells = true;
  45. + config.add_legacy_fixed_of_cells = !of_node_name_eq(mtd->dev.of_node, "nand");
  46. config.type = NVMEM_TYPE_OTP;
  47. config.root_only = true;
  48. config.ignore_wp = true;