* [PATCH 1/2] of: partition: Move some parts of of_fixup_partitions() into separate function
@ 2024-03-08 9:15 Uwe Kleine-König
2024-03-08 9:15 ` [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant Uwe Kleine-König
0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2024-03-08 9:15 UTC (permalink / raw)
To: barebox; +Cc: Uwe Kleine-König
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
This is a preparation for the next commit that fixes mtd partition
creation.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/of/partition.c | 81 ++++++++++++++++++++++++------------------
1 file changed, 47 insertions(+), 34 deletions(-)
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index 7c9f443ee7bd..d11e1d1690f9 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -167,10 +167,55 @@ static void delete_subnodes(struct device_node *np)
}
}
+static int of_fixup_one_partition(struct device_node *partnode, loff_t partoffset,
+ loff_t size, const char *partname,
+ unsigned int flags)
+{
+ int na, ns, len = 0;
+ char *name;
+ void *p;
+ u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
+ struct device_node *part;
+ int ret;
+
+ name = basprintf("partition@%0llx", partoffset);
+ if (!name)
+ return -ENOMEM;
+
+ part = of_new_node(partnode, name);
+ free(name);
+ if (!part)
+ return -ENOMEM;
+
+ p = of_new_property(part, "label", partname, strlen(partname) + 1);
+ if (!p)
+ return -ENOMEM;
+
+ na = of_n_addr_cells(part);
+ ns = of_n_size_cells(part);
+
+ of_write_number(tmp + len, partoffset, na);
+ len += na * 4;
+ of_write_number(tmp + len, size, ns);
+ len += ns * 4;
+
+ ret = of_set_property(part, "reg", tmp, len, 1);
+ if (ret)
+ return ret;
+
+ if (flags & DEVFS_PARTITION_READONLY) {
+ ret = of_set_property(part, "read-only", NULL, 0, 1);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
{
struct cdev *partcdev;
- struct device_node *part, *partnode;
+ struct device_node *partnode;
int ret;
int n_cells, n_parts = 0;
@@ -223,10 +268,6 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
return ret;
list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
- int na, ns, len = 0;
- char *name;
- void *p;
- u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
loff_t partoffset;
if (!(partcdev->flags & DEVFS_PARTITION_FROM_OF))
@@ -237,37 +278,9 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
else
partoffset = partcdev->offset;
- name = basprintf("partition@%0llx", partoffset);
- if (!name)
- return -ENOMEM;
-
- part = of_new_node(partnode, name);
- free(name);
- if (!part)
- return -ENOMEM;
-
- p = of_new_property(part, "label", partcdev->partname,
- strlen(partcdev->partname) + 1);
- if (!p)
- return -ENOMEM;
-
- na = of_n_addr_cells(part);
- ns = of_n_size_cells(part);
-
- of_write_number(tmp + len, partoffset, na);
- len += na * 4;
- of_write_number(tmp + len, partcdev->size, ns);
- len += ns * 4;
-
- ret = of_set_property(part, "reg", tmp, len, 1);
+ ret = of_fixup_one_partition(partnode, partoffset, partcdev->size, partcdev->partname, partcdev->flags);
if (ret)
return ret;
-
- if (partcdev->flags & DEVFS_PARTITION_READONLY) {
- ret = of_set_property(part, "read-only", NULL, 0, 1);
- if (ret)
- return ret;
- }
}
return 0;
base-commit: ed7c14536d521793199abf0597164a46ba68e8e5
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant
2024-03-08 9:15 [PATCH 1/2] of: partition: Move some parts of of_fixup_partitions() into separate function Uwe Kleine-König
@ 2024-03-08 9:15 ` Uwe Kleine-König
2024-03-08 9:27 ` Ahmad Fatoum
0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2024-03-08 9:15 UTC (permalink / raw)
To: barebox; +Cc: Uwe Kleine-König
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
It was already noticed in commit 9d42c77f126e ("devfs: take into account
for the partitions check that mtd is different") that the partitioning
info is stored differently for mtd devices. Instead of only getting the
partion size from the right spot, use the right data completely.
Fixes: 9d42c77f126e ("devfs: take into account for the partitions check that mtd is different")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/of/partition.c | 30 ++++++++++++++++++++++--------
1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/drivers/of/partition.c b/drivers/of/partition.c
index d11e1d1690f9..598ac5240d79 100644
--- a/drivers/of/partition.c
+++ b/drivers/of/partition.c
@@ -267,18 +267,32 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
if (ret)
return ret;
- list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
- loff_t partoffset;
+ if (cdev->mtd) {
+ struct mtd_info *mtdpart;
+ list_for_each_entry(mtdpart, &cdev->mtd->partitions, partitions_entry) {
+ const char *name = mtdpart->name;
+
+ if (mtdpart->parent) {
+ const char *parentname = dev_name(&mtdpart->parent->dev);
+ size_t parentnamelen = strlen(parentname);
+
+ if (!strncmp(parentname, name, parentnamelen) && name[parentnamelen] == '.')
+ name += parentnamelen + 1;
+ }
+
+ ret = of_fixup_one_partition(partnode, mtdpart->master_offset, mtdpart->size, name, partcdev->flags);
+ if (ret)
+ return ret;
+ }
+ return 0;
+ }
+
+ list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
if (!(partcdev->flags & DEVFS_PARTITION_FROM_OF))
continue;
- if (partcdev->mtd)
- partoffset = partcdev->mtd->master_offset;
- else
- partoffset = partcdev->offset;
-
- ret = of_fixup_one_partition(partnode, partoffset, partcdev->size, partcdev->partname, partcdev->flags);
+ ret = of_fixup_one_partition(partnode, partcdev->offset, partcdev->size, partcdev->partname, partcdev->flags);
if (ret)
return ret;
}
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant
2024-03-08 9:15 ` [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant Uwe Kleine-König
@ 2024-03-08 9:27 ` Ahmad Fatoum
2024-03-08 10:14 ` Uwe Kleine-König
0 siblings, 1 reply; 5+ messages in thread
From: Ahmad Fatoum @ 2024-03-08 9:27 UTC (permalink / raw)
To: Uwe Kleine-König, barebox; +Cc: Uwe Kleine-König
Hello Uwe,
On 08.03.24 10:15, Uwe Kleine-König wrote:
> From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
>
> It was already noticed in commit 9d42c77f126e ("devfs: take into account
> for the partitions check that mtd is different") that the partitioning
> info is stored differently for mtd devices. Instead of only getting the
> partion size from the right spot, use the right data completely.
I read both this commit message and that of the referenced commit and I
don't quite understand what the issue is. Could you add a short sentence
about what particular issue this fix addresses?
Thanks,
Ahmad
>
> Fixes: 9d42c77f126e ("devfs: take into account for the partitions check that mtd is different")
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> drivers/of/partition.c | 30 ++++++++++++++++++++++--------
> 1 file changed, 22 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/of/partition.c b/drivers/of/partition.c
> index d11e1d1690f9..598ac5240d79 100644
> --- a/drivers/of/partition.c
> +++ b/drivers/of/partition.c
> @@ -267,18 +267,32 @@ int of_fixup_partitions(struct device_node *np, struct cdev *cdev)
> if (ret)
> return ret;
>
> - list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
> - loff_t partoffset;
> + if (cdev->mtd) {
> + struct mtd_info *mtdpart;
>
> + list_for_each_entry(mtdpart, &cdev->mtd->partitions, partitions_entry) {
> + const char *name = mtdpart->name;
> +
> + if (mtdpart->parent) {
> + const char *parentname = dev_name(&mtdpart->parent->dev);
> + size_t parentnamelen = strlen(parentname);
> +
> + if (!strncmp(parentname, name, parentnamelen) && name[parentnamelen] == '.')
> + name += parentnamelen + 1;
> + }
> +
> + ret = of_fixup_one_partition(partnode, mtdpart->master_offset, mtdpart->size, name, partcdev->flags);
> + if (ret)
> + return ret;
> + }
> + return 0;
> + }
> +
> + list_for_each_entry(partcdev, &cdev->partitions, partition_entry) {
> if (!(partcdev->flags & DEVFS_PARTITION_FROM_OF))
> continue;
>
> - if (partcdev->mtd)
> - partoffset = partcdev->mtd->master_offset;
> - else
> - partoffset = partcdev->offset;
> -
> - ret = of_fixup_one_partition(partnode, partoffset, partcdev->size, partcdev->partname, partcdev->flags);
> + ret = of_fixup_one_partition(partnode, partcdev->offset, partcdev->size, partcdev->partname, partcdev->flags);
> if (ret)
> return ret;
> }
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant
2024-03-08 9:27 ` Ahmad Fatoum
@ 2024-03-08 10:14 ` Uwe Kleine-König
2024-03-08 10:51 ` Sascha Hauer
0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2024-03-08 10:14 UTC (permalink / raw)
To: Ahmad Fatoum; +Cc: Uwe Kleine-König, barebox
[-- Attachment #1: Type: text/plain, Size: 1294 bytes --]
Hello,
On Fri, Mar 08, 2024 at 10:27:21AM +0100, Ahmad Fatoum wrote:
> On 08.03.24 10:15, Uwe Kleine-König wrote:
> > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> >
> > It was already noticed in commit 9d42c77f126e ("devfs: take into account
> > for the partitions check that mtd is different") that the partitioning
> > info is stored differently for mtd devices. Instead of only getting the
> > partion size from the right spot, use the right data completely.
>
> I read both this commit message and that of the referenced commit and I
> don't quite understand what the issue is. Could you add a short sentence
> about what particular issue this fix addresses?
The situation fixed here is:
After bootup the partitioning information for mtd devices exists in both
locations (cdev->partitions and cdev->mtd->partitions). An interactive
addpart only adds the the latter. This patch fixes the of fixup to also
use the latter.
In the described error case the partition added to the bootup layout
(defined in the dtb) doesn't make it into the device tree provided to
Linux.
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | https://www.pengutronix.de/ |
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant
2024-03-08 10:14 ` Uwe Kleine-König
@ 2024-03-08 10:51 ` Sascha Hauer
0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2024-03-08 10:51 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: Ahmad Fatoum, Uwe Kleine-König, barebox
On Fri, Mar 08, 2024 at 11:14:28AM +0100, Uwe Kleine-König wrote:
> Hello,
>
> On Fri, Mar 08, 2024 at 10:27:21AM +0100, Ahmad Fatoum wrote:
> > On 08.03.24 10:15, Uwe Kleine-König wrote:
> > > From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > >
> > > It was already noticed in commit 9d42c77f126e ("devfs: take into account
> > > for the partitions check that mtd is different") that the partitioning
> > > info is stored differently for mtd devices. Instead of only getting the
> > > partion size from the right spot, use the right data completely.
> >
> > I read both this commit message and that of the referenced commit and I
> > don't quite understand what the issue is. Could you add a short sentence
> > about what particular issue this fix addresses?
>
> The situation fixed here is:
>
> After bootup the partitioning information for mtd devices exists in both
> locations (cdev->partitions and cdev->mtd->partitions). An interactive
> addpart only adds the the latter. This patch fixes the of fixup to also
> use the latter.
I don't think this is true. Looking at __devfs_add_partition() we have:
if (IS_ENABLED(CONFIG_MTD) && cdev->mtd) {
struct mtd_info *mtd;
mtd = mtd_add_partition(cdev->mtd, offset, size,
partinfo->flags, partinfo->name);
if (IS_ERR(mtd))
return (void *)mtd;
list_add_tail(&mtd->cdev.partition_entry, &cdev->partitions);
return &mtd->cdev;
}
...
list_add_tail(&new->partition_entry, &cdev->partitions);
So all partitions end up in the &cdev->partitions list.
of_fixup_partitions() currently iterates over &cdev->partitions, but it
has:
if (!(partcdev->flags & DEVFS_PARTITION_FROM_OF))
continue;
And I think this is your problem. The newly created partition is ignored
during fixup because it doesn't have the DEVFS_PARTITION_FROM_OF flag
set. What you do is a complicated way of ignoring this flag in your
additional iteration over &cdev->partitions.
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-03-08 10:51 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08 9:15 [PATCH 1/2] of: partition: Move some parts of of_fixup_partitions() into separate function Uwe Kleine-König
2024-03-08 9:15 ` [PATCH 2/2] of: partition: Use mtd partitioning for of_fixup instead of the cdev variant Uwe Kleine-König
2024-03-08 9:27 ` Ahmad Fatoum
2024-03-08 10:14 ` Uwe Kleine-König
2024-03-08 10:51 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox