From 4fd4be6bbe90b141ff64220165783b8b671dfddf Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Fri, 14 Jun 2024 16:24:12 +0100 Subject: [PATCH] generic: 6.6: move NVMEM-on-UBI patches from pending to backports The series was merged for Linux v6.9, so move it to backports. Signed-off-by: Daniel Golle --- ...ings-mtd-add-basic-bindings-for-UBI.patch} | 16 +- ...bi-volume-allow-UBI-volumes-to-prov.patch} | 10 +- ...-notifier-to-create-ubiblock-from-p.patch} | 152 ++++++++++++------ ...6.9-mtd-ubi-attach-from-device-tree.patch} | 81 ++-------- ...-pre-removal-notification-for-UBI-v.patch} | 62 +------ ...-mtd-ubi-populate-ubi-volume-fwnode.patch} | 7 +- ...rovide-NVMEM-layer-over-UBI-volumes.patch} | 14 +- ...M-over-UBI-volumes-on-32-bit-systems.patch | 34 ++++ ...mtd-device-named-ubi-or-data-on-boot.patch | 4 +- ...to-create-ubiblock-device-for-rootfs.patch | 6 +- ...ROOT_DEV-to-ubiblock-rootfs-if-unset.patch | 4 +- .../041-block-fit-partition-parser.patch | 2 +- 12 files changed, 192 insertions(+), 200 deletions(-) rename target/linux/generic/{pending-6.6/450-01-dt-bindings-mtd-add-basic-bindings-for-UBI.patch => backport-6.6/401-v6.9-dt-bindings-mtd-add-basic-bindings-for-UBI.patch} (87%) rename target/linux/generic/{pending-6.6/450-02-dt-bindings-mtd-ubi-volume-allow-UBI-volumes-to-prov.patch => backport-6.6/402-v6.9-dt-bindings-mtd-ubi-volume-allow-UBI-volumes-to-prov.patch} (83%) rename target/linux/generic/{pending-6.6/450-03-mtd-ubi-block-use-notifier-to-create-ubiblock-from-p.patch => backport-6.6/403-v6.9-mtd-ubi-block-use-notifier-to-create-ubiblock-from-p.patch} (56%) rename target/linux/generic/{pending-6.6/450-04-mtd-ubi-attach-from-device-tree.patch => backport-6.6/404-v6.9-mtd-ubi-attach-from-device-tree.patch} (63%) rename target/linux/generic/{pending-6.6/450-05-mtd-ubi-introduce-pre-removal-notification-for-UBI-v.patch => backport-6.6/405-v6.9-mtd-ubi-introduce-pre-removal-notification-for-UBI-v.patch} (78%) rename target/linux/generic/{pending-6.6/450-06-mtd-ubi-populate-ubi-volume-fwnode.patch => backport-6.6/406-v6.9-mtd-ubi-populate-ubi-volume-fwnode.patch} (89%) rename target/linux/generic/{pending-6.6/450-07-mtd-ubi-provide-NVMEM-layer-over-UBI-volumes.patch => backport-6.6/407-v6.9-mtd-ubi-provide-NVMEM-layer-over-UBI-volumes.patch} (95%) create mode 100644 target/linux/generic/backport-6.6/408-v6.9-mtd-ubi-fix-NVMEM-over-UBI-volumes-on-32-bit-systems.patch diff --git a/target/linux/generic/pending-6.6/450-01-dt-bindings-mtd-add-basic-bindings-for-UBI.patch b/target/linux/generic/backport-6.6/401-v6.9-dt-bindings-mtd-add-basic-bindings-for-UBI.patch similarity index 87% rename from target/linux/generic/pending-6.6/450-01-dt-bindings-mtd-add-basic-bindings-for-UBI.patch rename to target/linux/generic/backport-6.6/401-v6.9-dt-bindings-mtd-add-basic-bindings-for-UBI.patch index 063d3fa79c..811994861c 100644 --- a/target/linux/generic/pending-6.6/450-01-dt-bindings-mtd-add-basic-bindings-for-UBI.patch +++ b/target/linux/generic/backport-6.6/401-v6.9-dt-bindings-mtd-add-basic-bindings-for-UBI.patch @@ -1,11 +1,13 @@ -From ffbbe7d66872ff8957dad2136133e28a1fd5d437 Mon Sep 17 00:00:00 2001 +From 25d88bfd35bac3196eafa666e3b05033b46ffa21 Mon Sep 17 00:00:00 2001 From: Daniel Golle -Date: Mon, 7 Aug 2023 22:51:05 +0100 -Subject: [PATCH 01/15] dt-bindings: mtd: add basic bindings for UBI +Date: Tue, 19 Dec 2023 02:32:00 +0000 +Subject: [PATCH 1/8] dt-bindings: mtd: add basic bindings for UBI Add basic bindings for UBI devices and volumes. Signed-off-by: Daniel Golle +Reviewed-by: Rob Herring +Signed-off-by: Richard Weinberger --- .../bindings/mtd/partitions/linux,ubi.yaml | 65 +++++++++++++++++++ .../bindings/mtd/partitions/ubi-volume.yaml | 35 ++++++++++ @@ -101,21 +103,21 @@ Signed-off-by: Daniel Golle + +properties: + volid: -+ $ref: "/schemas/types.yaml#/definitions/uint32" ++ $ref: /schemas/types.yaml#/definitions/uint32 + description: + Match UBI volume ID + + volname: -+ $ref: "/schemas/types.yaml#/definitions/string" ++ $ref: /schemas/types.yaml#/definitions/string + description: + Match UBI volume ID + +anyOf: + - required: -+ - volid ++ - volid + + - required: -+ - volname ++ - volname + +# This is a generic file other binding inherit from and extend +additionalProperties: true diff --git a/target/linux/generic/pending-6.6/450-02-dt-bindings-mtd-ubi-volume-allow-UBI-volumes-to-prov.patch b/target/linux/generic/backport-6.6/402-v6.9-dt-bindings-mtd-ubi-volume-allow-UBI-volumes-to-prov.patch similarity index 83% rename from target/linux/generic/pending-6.6/450-02-dt-bindings-mtd-ubi-volume-allow-UBI-volumes-to-prov.patch rename to target/linux/generic/backport-6.6/402-v6.9-dt-bindings-mtd-ubi-volume-allow-UBI-volumes-to-prov.patch index 823c8e83b7..a3943387fb 100644 --- a/target/linux/generic/pending-6.6/450-02-dt-bindings-mtd-ubi-volume-allow-UBI-volumes-to-prov.patch +++ b/target/linux/generic/backport-6.6/402-v6.9-dt-bindings-mtd-ubi-volume-allow-UBI-volumes-to-prov.patch @@ -1,13 +1,15 @@ -From e4dad3aa5c3ab9c553555dd23c0b85f725f2eb51 Mon Sep 17 00:00:00 2001 +From 95b113222b5164ac0887eb5c514ff3970a0136f0 Mon Sep 17 00:00:00 2001 From: Daniel Golle -Date: Mon, 7 Aug 2023 22:53:01 +0100 -Subject: [PATCH 02/15] dt-bindings: mtd: ubi-volume: allow UBI volumes to +Date: Tue, 19 Dec 2023 02:32:11 +0000 +Subject: [PATCH 2/8] dt-bindings: mtd: ubi-volume: allow UBI volumes to provide NVMEM UBI volumes may be used to contain NVMEM bits, typically device MAC addresses or wireless radio calibration data. Signed-off-by: Daniel Golle +Reviewed-by: Rob Herring +Signed-off-by: Richard Weinberger --- .../devicetree/bindings/mtd/partitions/linux,ubi.yaml | 10 ++++++++++ .../devicetree/bindings/mtd/partitions/ubi-volume.yaml | 5 +++++ @@ -45,4 +47,4 @@ Signed-off-by: Daniel Golle + anyOf: - required: - - volid + - volid diff --git a/target/linux/generic/pending-6.6/450-03-mtd-ubi-block-use-notifier-to-create-ubiblock-from-p.patch b/target/linux/generic/backport-6.6/403-v6.9-mtd-ubi-block-use-notifier-to-create-ubiblock-from-p.patch similarity index 56% rename from target/linux/generic/pending-6.6/450-03-mtd-ubi-block-use-notifier-to-create-ubiblock-from-p.patch rename to target/linux/generic/backport-6.6/403-v6.9-mtd-ubi-block-use-notifier-to-create-ubiblock-from-p.patch index a1e1d6fa9d..f89330cd10 100644 --- a/target/linux/generic/pending-6.6/450-03-mtd-ubi-block-use-notifier-to-create-ubiblock-from-p.patch +++ b/target/linux/generic/backport-6.6/403-v6.9-mtd-ubi-block-use-notifier-to-create-ubiblock-from-p.patch @@ -1,7 +1,7 @@ -From e5cf19bd8204925f3bd2067df9e867313eac388b Mon Sep 17 00:00:00 2001 +From 2bba1cdcfcd2907d0696cc0139f1bd078d36ee81 Mon Sep 17 00:00:00 2001 From: Daniel Golle -Date: Mon, 1 May 2023 11:57:51 +0100 -Subject: [PATCH 03/15] mtd: ubi: block: use notifier to create ubiblock from +Date: Tue, 19 Dec 2023 02:32:35 +0000 +Subject: [PATCH 3/8] mtd: ubi: block: use notifier to create ubiblock from parameter Use UBI_VOLUME_ADDED notification to create ubiblock device specified @@ -12,21 +12,16 @@ will still be created. Suggested-by: Zhihao Cheng Signed-off-by: Daniel Golle +Signed-off-by: Richard Weinberger --- - drivers/mtd/ubi/block.c | 154 ++++++++++++++++++++++------------------ - 1 file changed, 85 insertions(+), 69 deletions(-) + drivers/mtd/ubi/block.c | 136 ++++++++++++++++++++-------------------- + drivers/mtd/ubi/kapi.c | 54 +++++++++++----- + drivers/mtd/ubi/ubi.h | 1 + + 3 files changed, 106 insertions(+), 85 deletions(-) --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c -@@ -33,6 +33,7 @@ - #include - #include - #include -+#include - #include - #include - #include -@@ -65,10 +66,10 @@ struct ubiblock_pdu { +@@ -65,10 +65,10 @@ struct ubiblock_pdu { }; /* Numbers of elements set in the @ubiblock_param array */ @@ -39,50 +34,26 @@ Signed-off-by: Daniel Golle struct ubiblock { struct ubi_volume_desc *desc; -@@ -469,7 +470,7 @@ int ubiblock_remove(struct ubi_volume_in - } - - /* Found a device, let's lock it so we can check if it's busy */ -- mutex_lock(&dev->dev_mutex); -+ mutex_lock_nested(&dev->dev_mutex, SINGLE_DEPTH_NESTING); - if (dev->refcnt > 0) { - ret = -EBUSY; - goto out_unlock_dev; -@@ -532,6 +533,85 @@ static int ubiblock_resize(struct ubi_vo +@@ -532,6 +532,70 @@ static int ubiblock_resize(struct ubi_vo return 0; } +static bool +match_volume_desc(struct ubi_volume_info *vi, const char *name, int ubi_num, int vol_id) +{ -+ int err, len; -+ struct path path; -+ struct kstat stat; ++ int err, len, cur_ubi_num, cur_vol_id; + + if (ubi_num == -1) { + /* No ubi num, name must be a vol device path */ -+ err = kern_path(name, LOOKUP_FOLLOW, &path); -+ if (err) -+ return false; -+ -+ err = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT); -+ path_put(&path); -+ if (err) -+ return false; -+ -+ if (!S_ISCHR(stat.mode)) -+ return false; -+ -+ if (vi->ubi_num != ubi_major2num(MAJOR(stat.rdev))) -+ return false; -+ -+ if (vi->vol_id != MINOR(stat.rdev) - 1) ++ err = ubi_get_num_by_path(name, &cur_ubi_num, &cur_vol_id); ++ if (err || vi->ubi_num != cur_ubi_num || vi->vol_id != cur_vol_id) + return false; + + return true; + } + + if (vol_id == -1) { ++ /* Got ubi_num, but no vol_id, name must be volume name */ + if (vi->ubi_num != ubi_num) + return false; + @@ -134,7 +105,7 @@ Signed-off-by: Daniel Golle static int ubiblock_notify(struct notifier_block *nb, unsigned long notification_type, void *ns_ptr) { -@@ -539,10 +619,7 @@ static int ubiblock_notify(struct notifi +@@ -539,10 +603,7 @@ static int ubiblock_notify(struct notifi switch (notification_type) { case UBI_VOLUME_ADDED: @@ -146,7 +117,7 @@ Signed-off-by: Daniel Golle break; case UBI_VOLUME_REMOVED: ubiblock_remove(&nt->vi); -@@ -568,56 +645,6 @@ static struct notifier_block ubiblock_no +@@ -568,56 +629,6 @@ static struct notifier_block ubiblock_no .notifier_call = ubiblock_notify, }; @@ -203,7 +174,7 @@ Signed-off-by: Daniel Golle static void ubiblock_remove_all(void) { struct ubiblock *next; -@@ -643,18 +670,7 @@ int __init ubiblock_init(void) +@@ -643,18 +654,7 @@ int __init ubiblock_init(void) if (ubiblock_major < 0) return ubiblock_major; @@ -223,3 +194,92 @@ Signed-off-by: Daniel Golle if (ret) goto err_unreg; return 0; +--- a/drivers/mtd/ubi/kapi.c ++++ b/drivers/mtd/ubi/kapi.c +@@ -280,6 +280,41 @@ struct ubi_volume_desc *ubi_open_volume_ + EXPORT_SYMBOL_GPL(ubi_open_volume_nm); + + /** ++ * ubi_get_num_by_path - get UBI device and volume number from device path ++ * @pathname: volume character device node path ++ * @ubi_num: pointer to UBI device number to be set ++ * @vol_id: pointer to UBI volume ID to be set ++ * ++ * Returns 0 on success and sets ubi_num and vol_id, returns error otherwise. ++ */ ++int ubi_get_num_by_path(const char *pathname, int *ubi_num, int *vol_id) ++{ ++ int error; ++ struct path path; ++ struct kstat stat; ++ ++ error = kern_path(pathname, LOOKUP_FOLLOW, &path); ++ if (error) ++ return error; ++ ++ error = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT); ++ path_put(&path); ++ if (error) ++ return error; ++ ++ if (!S_ISCHR(stat.mode)) ++ return -EINVAL; ++ ++ *ubi_num = ubi_major2num(MAJOR(stat.rdev)); ++ *vol_id = MINOR(stat.rdev) - 1; ++ ++ if (*vol_id < 0 || *ubi_num < 0) ++ return -ENODEV; ++ ++ return 0; ++} ++ ++/** + * ubi_open_volume_path - open UBI volume by its character device node path. + * @pathname: volume character device node path + * @mode: open mode +@@ -290,32 +325,17 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm); + struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) + { + int error, ubi_num, vol_id; +- struct path path; +- struct kstat stat; + + dbg_gen("open volume %s, mode %d", pathname, mode); + + if (!pathname || !*pathname) + return ERR_PTR(-EINVAL); + +- error = kern_path(pathname, LOOKUP_FOLLOW, &path); +- if (error) +- return ERR_PTR(error); +- +- error = vfs_getattr(&path, &stat, STATX_TYPE, AT_STATX_SYNC_AS_STAT); +- path_put(&path); ++ error = ubi_get_num_by_path(pathname, &ubi_num, &vol_id); + if (error) + return ERR_PTR(error); + +- if (!S_ISCHR(stat.mode)) +- return ERR_PTR(-EINVAL); +- +- ubi_num = ubi_major2num(MAJOR(stat.rdev)); +- vol_id = MINOR(stat.rdev) - 1; +- +- if (vol_id >= 0 && ubi_num >= 0) +- return ubi_open_volume(ubi_num, vol_id, mode); +- return ERR_PTR(-ENODEV); ++ return ubi_open_volume(ubi_num, vol_id, mode); + } + EXPORT_SYMBOL_GPL(ubi_open_volume_path); + +--- a/drivers/mtd/ubi/ubi.h ++++ b/drivers/mtd/ubi/ubi.h +@@ -956,6 +956,7 @@ void ubi_free_internal_volumes(struct ub + void ubi_do_get_device_info(struct ubi_device *ubi, struct ubi_device_info *di); + void ubi_do_get_volume_info(struct ubi_device *ubi, struct ubi_volume *vol, + struct ubi_volume_info *vi); ++int ubi_get_num_by_path(const char *pathname, int *ubi_num, int *vol_id); + /* scan.c */ + int ubi_compare_lebs(struct ubi_device *ubi, const struct ubi_ainf_peb *aeb, + int pnum, const struct ubi_vid_hdr *vid_hdr); diff --git a/target/linux/generic/pending-6.6/450-04-mtd-ubi-attach-from-device-tree.patch b/target/linux/generic/backport-6.6/404-v6.9-mtd-ubi-attach-from-device-tree.patch similarity index 63% rename from target/linux/generic/pending-6.6/450-04-mtd-ubi-attach-from-device-tree.patch rename to target/linux/generic/backport-6.6/404-v6.9-mtd-ubi-attach-from-device-tree.patch index a295146aee..ec7b6c3686 100644 --- a/target/linux/generic/pending-6.6/450-04-mtd-ubi-attach-from-device-tree.patch +++ b/target/linux/generic/backport-6.6/404-v6.9-mtd-ubi-attach-from-device-tree.patch @@ -1,7 +1,7 @@ -From 471a17d8d1b838092d1a76e48cdce8b5b67ff809 Mon Sep 17 00:00:00 2001 +From 6e331888643887ce85657527bc03f97d46235e71 Mon Sep 17 00:00:00 2001 From: Daniel Golle -Date: Mon, 27 Nov 2023 01:54:28 +0000 -Subject: [PATCH 04/15] mtd: ubi: attach from device tree +Date: Tue, 19 Dec 2023 02:33:14 +0000 +Subject: [PATCH 4/8] mtd: ubi: attach from device tree Introduce device tree compatible 'linux,ubi' and attach compatible MTD devices using the MTD add notifier. This is needed for a UBI device to @@ -9,11 +9,10 @@ be available early at boot (and not only after late_initcall), so volumes on them can be used eg. as NVMEM providers for other drivers. Signed-off-by: Daniel Golle +Signed-off-by: Richard Weinberger --- - drivers/mtd/ubi/build.c | 146 ++++++++++++++++++++++++++++------------ - drivers/mtd/ubi/cdev.c | 2 +- - drivers/mtd/ubi/ubi.h | 2 +- - 3 files changed, 106 insertions(+), 44 deletions(-) + drivers/mtd/ubi/build.c | 135 ++++++++++++++++++++++++++++------------ + 1 file changed, 96 insertions(+), 39 deletions(-) --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -25,37 +24,7 @@ Signed-off-by: Daniel Golle #include #include #include "ubi.h" -@@ -1072,6 +1073,7 @@ out_free: - * ubi_detach_mtd_dev - detach an MTD device. - * @ubi_num: UBI device number to detach from - * @anyway: detach MTD even if device reference count is not zero -+ * @have_lock: called by MTD notifier holding mtd_table_mutex - * - * This function destroys an UBI device number @ubi_num and detaches the - * underlying MTD device. Returns zero in case of success and %-EBUSY if the -@@ -1081,7 +1083,7 @@ out_free: - * Note, the invocations of this function has to be serialized by the - * @ubi_devices_mutex. - */ --int ubi_detach_mtd_dev(int ubi_num, int anyway) -+int ubi_detach_mtd_dev(int ubi_num, int anyway, bool have_lock) - { - struct ubi_device *ubi; - -@@ -1137,7 +1139,11 @@ int ubi_detach_mtd_dev(int ubi_num, int - vfree(ubi->peb_buf); - vfree(ubi->fm_buf); - ubi_msg(ubi, "mtd%d is detached", ubi->mtd->index); -- put_mtd_device(ubi->mtd); -+ if (have_lock) -+ __put_mtd_device(ubi->mtd); -+ else -+ put_mtd_device(ubi->mtd); -+ - put_device(&ubi->dev); - return 0; - } -@@ -1214,43 +1220,43 @@ static struct mtd_info * __init open_mtd +@@ -1214,43 +1215,43 @@ static struct mtd_info * __init open_mtd return mtd; } @@ -111,7 +80,7 @@ Signed-off-by: Daniel Golle - } +static void ubi_notify_remove(struct mtd_info *mtd) +{ -+ WARN(1, "mtd%d removed despite UBI still being attached", mtd->index); ++ /* do nothing for now */ +} - err = ubi_debugfs_init(); @@ -128,7 +97,7 @@ Signed-off-by: Daniel Golle /* Attach MTD devices */ for (i = 0; i < mtd_devs; i++) { -@@ -1298,25 +1304,79 @@ static int __init ubi_init(void) +@@ -1298,25 +1299,79 @@ static int __init ubi_init(void) } } @@ -138,7 +107,7 @@ Signed-off-by: Daniel Golle + for (k = 0; k < i; k++) + if (ubi_devices[k]) { + mutex_lock(&ubi_devices_mutex); -+ ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1, false); ++ ubi_detach_mtd_dev(ubi_devices[k]->ubi_num, 1); + mutex_unlock(&ubi_devices_mutex); + } + return err; @@ -217,7 +186,7 @@ Signed-off-by: Daniel Golle out_slab: kmem_cache_destroy(ubi_wl_entry_slab); out_dev_unreg: -@@ -1326,18 +1386,20 @@ out: +@@ -1326,13 +1381,15 @@ out: pr_err("UBI error: cannot initialize UBI, error %d\n", err); return err; } @@ -234,31 +203,3 @@ Signed-off-by: Daniel Golle for (i = 0; i < UBI_MAX_DEVICES; i++) if (ubi_devices[i]) { - mutex_lock(&ubi_devices_mutex); -- ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1); -+ ubi_detach_mtd_dev(ubi_devices[i]->ubi_num, 1, false); - mutex_unlock(&ubi_devices_mutex); - } - ubi_debugfs_exit(); ---- a/drivers/mtd/ubi/cdev.c -+++ b/drivers/mtd/ubi/cdev.c -@@ -1065,7 +1065,7 @@ static long ctrl_cdev_ioctl(struct file - } - - mutex_lock(&ubi_devices_mutex); -- err = ubi_detach_mtd_dev(ubi_num, 0); -+ err = ubi_detach_mtd_dev(ubi_num, 0, false); - mutex_unlock(&ubi_devices_mutex); - break; - } ---- a/drivers/mtd/ubi/ubi.h -+++ b/drivers/mtd/ubi/ubi.h -@@ -939,7 +939,7 @@ int ubi_io_write_vid_hdr(struct ubi_devi - int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, - int vid_hdr_offset, int max_beb_per1024, - bool disable_fm); --int ubi_detach_mtd_dev(int ubi_num, int anyway); -+int ubi_detach_mtd_dev(int ubi_num, int anyway, bool have_lock); - struct ubi_device *ubi_get_device(int ubi_num); - void ubi_put_device(struct ubi_device *ubi); - struct ubi_device *ubi_get_by_major(int major); diff --git a/target/linux/generic/pending-6.6/450-05-mtd-ubi-introduce-pre-removal-notification-for-UBI-v.patch b/target/linux/generic/backport-6.6/405-v6.9-mtd-ubi-introduce-pre-removal-notification-for-UBI-v.patch similarity index 78% rename from target/linux/generic/pending-6.6/450-05-mtd-ubi-introduce-pre-removal-notification-for-UBI-v.patch rename to target/linux/generic/backport-6.6/405-v6.9-mtd-ubi-introduce-pre-removal-notification-for-UBI-v.patch index c7c058f8f4..fb76ffc443 100644 --- a/target/linux/generic/pending-6.6/450-05-mtd-ubi-introduce-pre-removal-notification-for-UBI-v.patch +++ b/target/linux/generic/backport-6.6/405-v6.9-mtd-ubi-introduce-pre-removal-notification-for-UBI-v.patch @@ -1,7 +1,7 @@ -From 2d664266cfdd114cc7a1fa28dd64275e99222455 Mon Sep 17 00:00:00 2001 +From 924731fbed3247e3b82b8ab17db587ee28c2e781 Mon Sep 17 00:00:00 2001 From: Daniel Golle -Date: Thu, 8 Jun 2023 17:18:09 +0100 -Subject: [PATCH 05/15] mtd: ubi: introduce pre-removal notification for UBI +Date: Tue, 19 Dec 2023 02:33:24 +0000 +Subject: [PATCH 5/8] mtd: ubi: introduce pre-removal notification for UBI volumes Introduce a new notification type UBI_VOLUME_SHUTDOWN to inform users @@ -12,57 +12,15 @@ still available (for removal of sysfs nodes, for example, in case of NVMEM which otherwise WARNs on volume removal). Signed-off-by: Daniel Golle +Signed-off-by: Richard Weinberger --- - drivers/mtd/ubi/block.c | 26 ++++++++++++++++++++++++++ - drivers/mtd/ubi/build.c | 20 +++++++++++++++----- + drivers/mtd/ubi/build.c | 19 ++++++++++++++----- drivers/mtd/ubi/kapi.c | 2 +- drivers/mtd/ubi/ubi.h | 2 ++ drivers/mtd/ubi/vmt.c | 17 +++++++++++++++-- include/linux/mtd/ubi.h | 2 ++ - 6 files changed, 61 insertions(+), 8 deletions(-) + 5 files changed, 34 insertions(+), 8 deletions(-) ---- a/drivers/mtd/ubi/block.c -+++ b/drivers/mtd/ubi/block.c -@@ -533,6 +533,29 @@ static int ubiblock_resize(struct ubi_vo - return 0; - } - -+static int ubiblock_shutdown(struct ubi_volume_info *vi) -+{ -+ struct ubiblock *dev; -+ struct gendisk *disk; -+ int ret = 0; -+ -+ mutex_lock(&devices_mutex); -+ dev = find_dev_nolock(vi->ubi_num, vi->vol_id); -+ if (!dev) { -+ ret = -ENODEV; -+ goto out_unlock; -+ } -+ disk = dev->gd; -+ -+out_unlock: -+ mutex_unlock(&devices_mutex); -+ -+ if (!ret) -+ blk_mark_disk_dead(disk); -+ -+ return ret; -+}; -+ - static bool - match_volume_desc(struct ubi_volume_info *vi, const char *name, int ubi_num, int vol_id) - { -@@ -624,6 +647,9 @@ static int ubiblock_notify(struct notifi - case UBI_VOLUME_REMOVED: - ubiblock_remove(&nt->vi); - break; -+ case UBI_VOLUME_SHUTDOWN: -+ ubiblock_shutdown(&nt->vi); -+ break; - case UBI_VOLUME_RESIZED: - ubiblock_resize(&nt->vi); - break; --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -91,7 +91,7 @@ static struct ubi_device *ubi_devices[UB @@ -111,7 +69,7 @@ Signed-off-by: Daniel Golle continue; ubi_eba_replace_table(ubi->volumes[i], NULL); ubi_fastmap_destroy_checkmap(ubi->volumes[i]); -@@ -1095,10 +1098,10 @@ int ubi_detach_mtd_dev(int ubi_num, int +@@ -1094,7 +1097,6 @@ int ubi_detach_mtd_dev(int ubi_num, int return -EINVAL; spin_lock(&ubi_devices_lock); @@ -119,11 +77,7 @@ Signed-off-by: Daniel Golle ubi->ref_count -= 1; if (ubi->ref_count) { if (!anyway) { -+ ubi->ref_count += 1; - spin_unlock(&ubi_devices_lock); - return -EBUSY; - } -@@ -1106,6 +1109,13 @@ int ubi_detach_mtd_dev(int ubi_num, int +@@ -1105,6 +1107,13 @@ int ubi_detach_mtd_dev(int ubi_num, int ubi_err(ubi, "%s reference count %d, destroy anyway", ubi->ubi_name, ubi->ref_count); } diff --git a/target/linux/generic/pending-6.6/450-06-mtd-ubi-populate-ubi-volume-fwnode.patch b/target/linux/generic/backport-6.6/406-v6.9-mtd-ubi-populate-ubi-volume-fwnode.patch similarity index 89% rename from target/linux/generic/pending-6.6/450-06-mtd-ubi-populate-ubi-volume-fwnode.patch rename to target/linux/generic/backport-6.6/406-v6.9-mtd-ubi-populate-ubi-volume-fwnode.patch index 1322766965..232e74da59 100644 --- a/target/linux/generic/pending-6.6/450-06-mtd-ubi-populate-ubi-volume-fwnode.patch +++ b/target/linux/generic/backport-6.6/406-v6.9-mtd-ubi-populate-ubi-volume-fwnode.patch @@ -1,7 +1,7 @@ -From 3a041ee543cdf2e707a1dd72946cd6a583509b28 Mon Sep 17 00:00:00 2001 +From 1c54542170819e36baa43c17ca55bb3d7da89a53 Mon Sep 17 00:00:00 2001 From: Daniel Golle -Date: Fri, 21 Jul 2023 19:26:37 +0100 -Subject: [PATCH 06/15] mtd: ubi: populate ubi volume fwnode +Date: Tue, 19 Dec 2023 02:33:38 +0000 +Subject: [PATCH 6/8] mtd: ubi: populate ubi volume fwnode Look for the 'volumes' subnode of an MTD partition attached to a UBI device and attach matching child nodes to UBI volumes. @@ -9,6 +9,7 @@ This allows UBI volumes to be referenced in device tree, e.g. for use as NVMEM providers. Signed-off-by: Daniel Golle +Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/vmt.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/target/linux/generic/pending-6.6/450-07-mtd-ubi-provide-NVMEM-layer-over-UBI-volumes.patch b/target/linux/generic/backport-6.6/407-v6.9-mtd-ubi-provide-NVMEM-layer-over-UBI-volumes.patch similarity index 95% rename from target/linux/generic/pending-6.6/450-07-mtd-ubi-provide-NVMEM-layer-over-UBI-volumes.patch rename to target/linux/generic/backport-6.6/407-v6.9-mtd-ubi-provide-NVMEM-layer-over-UBI-volumes.patch index 59a1eb9374..18fd1fb437 100644 --- a/target/linux/generic/pending-6.6/450-07-mtd-ubi-provide-NVMEM-layer-over-UBI-volumes.patch +++ b/target/linux/generic/backport-6.6/407-v6.9-mtd-ubi-provide-NVMEM-layer-over-UBI-volumes.patch @@ -1,7 +1,7 @@ -From 7eb6666348f3f2d1f7308c712fa5903cbe189401 Mon Sep 17 00:00:00 2001 +From 15fc7dc926c91c871f6c0305b2938dbdeb14203b Mon Sep 17 00:00:00 2001 From: Daniel Golle -Date: Thu, 8 Jun 2023 17:22:04 +0100 -Subject: [PATCH 07/15] mtd: ubi: provide NVMEM layer over UBI volumes +Date: Tue, 19 Dec 2023 02:33:48 +0000 +Subject: [PATCH 7/8] mtd: ubi: provide NVMEM layer over UBI volumes In an ideal world we would like UBI to be used where ever possible on a NAND chip. And with UBI support in ARM Trusted Firmware and U-Boot it @@ -17,6 +17,7 @@ read-only, and it is slow, opening and closing the UBI volume for each access due to limitations of the NVMEM provider API. Signed-off-by: Daniel Golle +Signed-off-by: Richard Weinberger --- drivers/mtd/ubi/Kconfig | 12 +++ drivers/mtd/ubi/Makefile | 1 + @@ -52,7 +53,7 @@ Signed-off-by: Daniel Golle +obj-$(CONFIG_MTD_UBI_NVMEM) += nvmem.o --- /dev/null +++ b/drivers/mtd/ubi/nvmem.c -@@ -0,0 +1,191 @@ +@@ -0,0 +1,188 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023 Daniel Golle @@ -78,17 +79,14 @@ Signed-off-by: Daniel Golle +static int ubi_nvmem_reg_read(void *priv, unsigned int from, + void *val, size_t bytes) +{ -+ uint32_t offs, to_read, bytes_left; ++ int err = 0, lnum = from, offs, bytes_left = bytes, to_read; + struct ubi_nvmem *unv = priv; + struct ubi_volume_desc *desc; -+ uint64_t lnum = from; -+ int err = 0; + + desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY); + if (IS_ERR(desc)) + return PTR_ERR(desc); + -+ bytes_left = bytes; + offs = do_div(lnum, unv->usable_leb_size); + while (bytes_left) { + to_read = unv->usable_leb_size - offs; diff --git a/target/linux/generic/backport-6.6/408-v6.9-mtd-ubi-fix-NVMEM-over-UBI-volumes-on-32-bit-systems.patch b/target/linux/generic/backport-6.6/408-v6.9-mtd-ubi-fix-NVMEM-over-UBI-volumes-on-32-bit-systems.patch new file mode 100644 index 0000000000..8ce2b46691 --- /dev/null +++ b/target/linux/generic/backport-6.6/408-v6.9-mtd-ubi-fix-NVMEM-over-UBI-volumes-on-32-bit-systems.patch @@ -0,0 +1,34 @@ +From 04231c61dcd51db0f12061e49bb761b197109f2f Mon Sep 17 00:00:00 2001 +From: Daniel Golle +Date: Thu, 29 Feb 2024 03:47:24 +0000 +Subject: [PATCH 8/8] mtd: ubi: fix NVMEM over UBI volumes on 32-bit systems + +A compiler warning related to sizeof(int) != 8 when calling do_div() +is triggered when building on 32-bit platforms. +Address this by using integer types having a well-defined size. + +Fixes: 3ce485803da1 ("mtd: ubi: provide NVMEM layer over UBI volumes") +Signed-off-by: Daniel Golle +Reviewed-by: Zhihao Cheng +Tested-by: Randy Dunlap +Signed-off-by: Richard Weinberger +--- + drivers/mtd/ubi/nvmem.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +--- a/drivers/mtd/ubi/nvmem.c ++++ b/drivers/mtd/ubi/nvmem.c +@@ -23,9 +23,12 @@ struct ubi_nvmem { + static int ubi_nvmem_reg_read(void *priv, unsigned int from, + void *val, size_t bytes) + { +- int err = 0, lnum = from, offs, bytes_left = bytes, to_read; ++ size_t to_read, bytes_left = bytes; + struct ubi_nvmem *unv = priv; + struct ubi_volume_desc *desc; ++ uint32_t offs; ++ uint64_t lnum = from; ++ int err = 0; + + desc = ubi_open_volume(unv->ubi_num, unv->vol_id, UBI_READONLY); + if (IS_ERR(desc)) diff --git a/target/linux/generic/pending-6.6/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch b/target/linux/generic/pending-6.6/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch index 5a897d5d6f..6405865c45 100644 --- a/target/linux/generic/pending-6.6/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch +++ b/target/linux/generic/pending-6.6/490-ubi-auto-attach-mtd-device-named-ubi-or-data-on-boot.patch @@ -8,7 +8,7 @@ Signed-off-by: Daniel Golle --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c -@@ -1264,6 +1264,74 @@ static struct mtd_notifier ubi_mtd_notif +@@ -1258,6 +1258,74 @@ static struct mtd_notifier ubi_mtd_notif .remove = ubi_notify_remove, }; @@ -83,7 +83,7 @@ Signed-off-by: Daniel Golle static int __init ubi_init_attach(void) { int err, i, k; -@@ -1314,6 +1382,12 @@ static int __init ubi_init_attach(void) +@@ -1308,6 +1376,12 @@ static int __init ubi_init_attach(void) } } diff --git a/target/linux/generic/pending-6.6/491-ubi-auto-create-ubiblock-device-for-rootfs.patch b/target/linux/generic/pending-6.6/491-ubi-auto-create-ubiblock-device-for-rootfs.patch index e0134e876a..6081d1d9e5 100644 --- a/target/linux/generic/pending-6.6/491-ubi-auto-create-ubiblock-device-for-rootfs.patch +++ b/target/linux/generic/pending-6.6/491-ubi-auto-create-ubiblock-device-for-rootfs.patch @@ -8,7 +8,7 @@ Signed-off-by: Daniel Golle --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c -@@ -609,10 +609,47 @@ match_volume_desc(struct ubi_volume_info +@@ -570,10 +570,47 @@ match_volume_desc(struct ubi_volume_info return true; } @@ -56,7 +56,7 @@ Signed-off-by: Daniel Golle struct ubiblock_param *p; /* -@@ -625,6 +662,7 @@ ubiblock_create_from_param(struct ubi_vo +@@ -586,6 +623,7 @@ ubiblock_create_from_param(struct ubi_vo if (!match_volume_desc(vi, p->name, p->ubi_num, p->vol_id)) continue; @@ -64,7 +64,7 @@ Signed-off-by: Daniel Golle ret = ubiblock_create(vi); if (ret) { pr_err( -@@ -633,6 +671,10 @@ ubiblock_create_from_param(struct ubi_vo +@@ -594,6 +632,10 @@ ubiblock_create_from_param(struct ubi_vo } break; } diff --git a/target/linux/generic/pending-6.6/493-ubi-set-ROOT_DEV-to-ubiblock-rootfs-if-unset.patch b/target/linux/generic/pending-6.6/493-ubi-set-ROOT_DEV-to-ubiblock-rootfs-if-unset.patch index 788690088a..367bf6598e 100644 --- a/target/linux/generic/pending-6.6/493-ubi-set-ROOT_DEV-to-ubiblock-rootfs-if-unset.patch +++ b/target/linux/generic/pending-6.6/493-ubi-set-ROOT_DEV-to-ubiblock-rootfs-if-unset.patch @@ -8,7 +8,7 @@ Signed-off-by: Daniel Golle --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c -@@ -42,6 +42,7 @@ +@@ -41,6 +41,7 @@ #include #include #include @@ -16,7 +16,7 @@ Signed-off-by: Daniel Golle #include "ubi-media.h" #include "ubi.h" -@@ -429,6 +430,15 @@ int ubiblock_create(struct ubi_volume_in +@@ -428,6 +429,15 @@ int ubiblock_create(struct ubi_volume_in dev_info(disk_to_dev(dev->gd), "created from ubi%d:%d(%s)", dev->ubi_num, dev->vol_id, vi->name); mutex_unlock(&devices_mutex); diff --git a/target/linux/mediatek/patches-6.6/041-block-fit-partition-parser.patch b/target/linux/mediatek/patches-6.6/041-block-fit-partition-parser.patch index 2d85313f8d..185ec105d0 100644 --- a/target/linux/mediatek/patches-6.6/041-block-fit-partition-parser.patch +++ b/target/linux/mediatek/patches-6.6/041-block-fit-partition-parser.patch @@ -193,7 +193,7 @@ Subject: [PATCH] kernel: add block fit partition parser set_capacity(gd, ((u64)new->size * tr->blksize) >> 9); --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c -@@ -411,7 +411,9 @@ int ubiblock_create(struct ubi_volume_in +@@ -410,7 +410,9 @@ int ubiblock_create(struct ubi_volume_in ret = -ENODEV; goto out_cleanup_disk; } -- 2.30.2