* [PATCH 1/2] of: base: add helper to rename a node
@ 2019-02-11 16:20 Marco Felsch
2019-02-11 16:20 ` [PATCH 2/2] memory: of_fixup: adapt to new memory layout Marco Felsch
2019-02-12 7:32 ` [PATCH 1/2] of: base: add helper to rename a node Sascha Hauer
0 siblings, 2 replies; 8+ messages in thread
From: Marco Felsch @ 2019-02-11 16:20 UTC (permalink / raw)
To: barebox; +Cc: mfe
Sometimes it can be necessary to rename a node, e.g. to override/create
a node which gets renamed upstream.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
drivers/of/base.c | 18 ++++++++++++++++++
include/of.h | 5 +++++
2 files changed, 23 insertions(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index b082f0c656..6644d9b96a 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -2094,6 +2094,24 @@ void of_delete_node(struct device_node *node)
of_set_root_node(NULL);
}
+void of_rename_node(struct device_node *node, char *name)
+{
+ struct device_node *parent;
+
+ if (!node)
+ return;
+
+ parent = node->parent;
+ if (parent) {
+ node->name = name;
+ node->full_name = basprintf("%s/%s", parent->full_name, name);
+ } else {
+ /* root node */
+ node->name = xstrdup("");
+ node->full_name = xstrdup("");
+ }
+}
+
int of_device_is_stdout_path(struct device_d *dev)
{
struct device_node *dn;
diff --git a/include/of.h b/include/of.h
index 184acb4741..403f399d95 100644
--- a/include/of.h
+++ b/include/of.h
@@ -158,6 +158,7 @@ extern struct device_node *of_create_node(struct device_node *root,
extern struct device_node *of_copy_node(struct device_node *parent,
const struct device_node *other);
extern void of_delete_node(struct device_node *node);
+extern void of_rename_node(struct device_node *node, char *name);
extern const char *of_get_machine_compatible(void);
extern int of_machine_is_compatible(const char *compat);
@@ -605,6 +606,10 @@ static inline void of_delete_node(struct device_node *node)
{
}
+static inline void of_rename_node(struct device_node *node, char *name)
+{
+}
+
static inline int of_machine_is_compatible(const char *compat)
{
return 0;
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] memory: of_fixup: adapt to new memory layout
2019-02-11 16:20 [PATCH 1/2] of: base: add helper to rename a node Marco Felsch
@ 2019-02-11 16:20 ` Marco Felsch
2019-02-12 8:03 ` Sascha Hauer
2019-02-12 7:32 ` [PATCH 1/2] of: base: add helper to rename a node Sascha Hauer
1 sibling, 1 reply; 8+ messages in thread
From: Marco Felsch @ 2019-02-11 16:20 UTC (permalink / raw)
To: barebox; +Cc: mfe
Since kernel 4.16 the memory nodes got a @<reg> suffix so the fixup
won't work correctly anymore, because instead of adapting the extisting
one it creates a new node.
To be compatible with the old and new layout delete the found memory
node and create a new one. The new node follows the new @<reg> style.
The patch also renames the node element to root to make it more clear.
Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
---
common/memory.c | 24 ++++++++++++++++++++++--
1 file changed, 22 insertions(+), 2 deletions(-)
diff --git a/common/memory.c b/common/memory.c
index 00fa7c50ff..5402acab8e 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -224,7 +224,7 @@ int memory_bank_first_find_space(resource_size_t *retstart,
#ifdef CONFIG_OFTREE
-static int of_memory_fixup(struct device_node *node, void *unused)
+static int of_memory_fixup(struct device_node *root, void *unused)
{
struct memory_bank *bank;
int err;
@@ -232,7 +232,23 @@ static int of_memory_fixup(struct device_node *node, void *unused)
struct device_node *memnode;
u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
- memnode = of_create_node(node, "/memory");
+ /*
+ * Since kernel 4.16 the memory node got a @<reg> suffix. To support
+ * the old and the new style delete any found memory node and add it
+ * again to be sure that the memory node exists only once. It shouldn't
+ * bother older kernels if the memory node has this suffix so adding it
+ * following the new style.
+ */
+
+ memnode = of_find_node_by_name(root, "memory");
+ if (!memnode)
+ memnode = of_find_node_by_type(root, "memory");
+
+ if (memnode)
+ of_delete_node(memnode);
+
+ /* At this moment we don't know the <reg> val */
+ memnode = of_create_node(root, "/memory");
if (!memnode)
return -ENOMEM;
@@ -256,6 +272,10 @@ static int of_memory_fixup(struct device_node *node, void *unused)
return err;
}
+ /* now adapt the node name */
+ of_rename_node(memnode, basprintf("memory@%llx",
+ of_read_number((u32 *)tmp, addr_cell_len)));
+
return 0;
}
--
2.20.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] of: base: add helper to rename a node
2019-02-11 16:20 [PATCH 1/2] of: base: add helper to rename a node Marco Felsch
2019-02-11 16:20 ` [PATCH 2/2] memory: of_fixup: adapt to new memory layout Marco Felsch
@ 2019-02-12 7:32 ` Sascha Hauer
2019-02-12 8:49 ` Marco Felsch
1 sibling, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2019-02-12 7:32 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox, mfe
Hi Marco,
On Mon, Feb 11, 2019 at 05:20:12PM +0100, Marco Felsch wrote:
> Sometimes it can be necessary to rename a node, e.g. to override/create
> a node which gets renamed upstream.
>
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
> drivers/of/base.c | 18 ++++++++++++++++++
> include/of.h | 5 +++++
> 2 files changed, 23 insertions(+)
>
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index b082f0c656..6644d9b96a 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -2094,6 +2094,24 @@ void of_delete_node(struct device_node *node)
> of_set_root_node(NULL);
> }
>
> +void of_rename_node(struct device_node *node, char *name)
Should be const char * name.
> +{
> + struct device_node *parent;
> +
> + if (!node)
> + return;
> +
> + parent = node->parent;
> + if (parent) {
> + node->name = name;
node->name is an allocated string. It should be freed and then set to an
allocated string again.
> + node->full_name = basprintf("%s/%s", parent->full_name, name);
> + } else {
> + /* root node */
> + node->name = xstrdup("");
> + node->full_name = xstrdup("");
I think we can drop the else path entirely. If we do not allow to give
the root node a name then we can assume that it doesn't have a name
right now, so nothing to do here.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] memory: of_fixup: adapt to new memory layout
2019-02-11 16:20 ` [PATCH 2/2] memory: of_fixup: adapt to new memory layout Marco Felsch
@ 2019-02-12 8:03 ` Sascha Hauer
2019-02-12 8:45 ` Marco Felsch
0 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2019-02-12 8:03 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox, mfe
On Mon, Feb 11, 2019 at 05:20:13PM +0100, Marco Felsch wrote:
> Since kernel 4.16 the memory nodes got a @<reg> suffix so the fixup
> won't work correctly anymore, because instead of adapting the extisting
> one it creates a new node.
>
> To be compatible with the old and new layout delete the found memory
> node and create a new one. The new node follows the new @<reg> style.
>
> The patch also renames the node element to root to make it more clear.
>
> Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> ---
> common/memory.c | 24 ++++++++++++++++++++++--
> 1 file changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/common/memory.c b/common/memory.c
> index 00fa7c50ff..5402acab8e 100644
> --- a/common/memory.c
> +++ b/common/memory.c
> @@ -224,7 +224,7 @@ int memory_bank_first_find_space(resource_size_t *retstart,
>
> #ifdef CONFIG_OFTREE
>
> -static int of_memory_fixup(struct device_node *node, void *unused)
> +static int of_memory_fixup(struct device_node *root, void *unused)
> {
> struct memory_bank *bank;
> int err;
> @@ -232,7 +232,23 @@ static int of_memory_fixup(struct device_node *node, void *unused)
> struct device_node *memnode;
> u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
>
> - memnode = of_create_node(node, "/memory");
> + /*
> + * Since kernel 4.16 the memory node got a @<reg> suffix. To support
> + * the old and the new style delete any found memory node and add it
> + * again to be sure that the memory node exists only once. It shouldn't
> + * bother older kernels if the memory node has this suffix so adding it
> + * following the new style.
> + */
> +
> + memnode = of_find_node_by_name(root, "memory");
We don't need this as the /memory node must have device_type = memory.
> + if (!memnode)
> + memnode = of_find_node_by_type(root, "memory");
You shouldn't assume that there's only one /memory node. There can be
multiple.
The /memory node must be a direct child of the root node, so it's
unnecessary to traverse the whole tree using of_find_node_by_type().
Something like for_each_child_of_node_safe(root, tmp, np) fits better.
> +
> + if (memnode)
> + of_delete_node(memnode);
> +
> + /* At this moment we don't know the <reg> val */
> + memnode = of_create_node(root, "/memory");
> if (!memnode)
> return -ENOMEM;
>
> @@ -256,6 +272,10 @@ static int of_memory_fixup(struct device_node *node, void *unused)
> return err;
> }
>
> + /* now adapt the node name */
> + of_rename_node(memnode, basprintf("memory@%llx",
> + of_read_number((u32 *)tmp, addr_cell_len)));
It's also allowed to create one /memory node per memory bank. Maybe
that's more straightforward to implement.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] memory: of_fixup: adapt to new memory layout
2019-02-12 8:03 ` Sascha Hauer
@ 2019-02-12 8:45 ` Marco Felsch
2019-02-12 8:56 ` Sascha Hauer
0 siblings, 1 reply; 8+ messages in thread
From: Marco Felsch @ 2019-02-12 8:45 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Hi Sascha,
On 19-02-12 09:03, Sascha Hauer wrote:
> On Mon, Feb 11, 2019 at 05:20:13PM +0100, Marco Felsch wrote:
> > Since kernel 4.16 the memory nodes got a @<reg> suffix so the fixup
> > won't work correctly anymore, because instead of adapting the extisting
> > one it creates a new node.
> >
> > To be compatible with the old and new layout delete the found memory
> > node and create a new one. The new node follows the new @<reg> style.
> >
> > The patch also renames the node element to root to make it more clear.
> >
> > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > ---
> > common/memory.c | 24 ++++++++++++++++++++++--
> > 1 file changed, 22 insertions(+), 2 deletions(-)
> >
> > diff --git a/common/memory.c b/common/memory.c
> > index 00fa7c50ff..5402acab8e 100644
> > --- a/common/memory.c
> > +++ b/common/memory.c
> > @@ -224,7 +224,7 @@ int memory_bank_first_find_space(resource_size_t *retstart,
> >
> > #ifdef CONFIG_OFTREE
> >
> > -static int of_memory_fixup(struct device_node *node, void *unused)
> > +static int of_memory_fixup(struct device_node *root, void *unused)
> > {
> > struct memory_bank *bank;
> > int err;
> > @@ -232,7 +232,23 @@ static int of_memory_fixup(struct device_node *node, void *unused)
> > struct device_node *memnode;
> > u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
> >
> > - memnode = of_create_node(node, "/memory");
> > + /*
> > + * Since kernel 4.16 the memory node got a @<reg> suffix. To support
> > + * the old and the new style delete any found memory node and add it
> > + * again to be sure that the memory node exists only once. It shouldn't
> > + * bother older kernels if the memory node has this suffix so adding it
> > + * following the new style.
> > + */
> > +
> > + memnode = of_find_node_by_name(root, "memory");
>
> We don't need this as the /memory node must have device_type = memory.
Okay, tought about the old devicetrees where the QA wasn't that good. I
will drop this.
>
> > + if (!memnode)
> > + memnode = of_find_node_by_type(root, "memory");
>
> You shouldn't assume that there's only one /memory node. There can be
> multiple.
Sure.. damn, checked only a few devicetree's where multiple banks are
mapped to the reg property. I will change this.
> The /memory node must be a direct child of the root node, so it's
> unnecessary to traverse the whole tree using of_find_node_by_type().
> Something like for_each_child_of_node_safe(root, tmp, np) fits better.
Okay.
>
> > +
> > + if (memnode)
> > + of_delete_node(memnode);
> > +
> > + /* At this moment we don't know the <reg> val */
> > + memnode = of_create_node(root, "/memory");
> > if (!memnode)
> > return -ENOMEM;
> >
> > @@ -256,6 +272,10 @@ static int of_memory_fixup(struct device_node *node, void *unused)
> > return err;
> > }
> >
> > + /* now adapt the node name */
> > + of_rename_node(memnode, basprintf("memory@%llx",
> > + of_read_number((u32 *)tmp, addr_cell_len)));
>
> It's also allowed to create one /memory node per memory bank. Maybe
> that's more straightforward to implement.
Is it wrong to adapt the name later? As specified by DT-Spec [1], the
@<reg> should be set to the first address.
[1]
https://github.com/devicetree-org/devicetree-specification/releases/tag/v0.2,
Chapter 2.2.1
Regards,
Marco
>
> Sascha
>
> --
> Pengutronix e.K. | |
> Industrial Linux Solutions | http://www.pengutronix.de/ |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] of: base: add helper to rename a node
2019-02-12 7:32 ` [PATCH 1/2] of: base: add helper to rename a node Sascha Hauer
@ 2019-02-12 8:49 ` Marco Felsch
0 siblings, 0 replies; 8+ messages in thread
From: Marco Felsch @ 2019-02-12 8:49 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
Hi Sascha,
On 19-02-12 08:32, Sascha Hauer wrote:
> Hi Marco,
>
> On Mon, Feb 11, 2019 at 05:20:12PM +0100, Marco Felsch wrote:
> > Sometimes it can be necessary to rename a node, e.g. to override/create
> > a node which gets renamed upstream.
> >
> > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > ---
> > drivers/of/base.c | 18 ++++++++++++++++++
> > include/of.h | 5 +++++
> > 2 files changed, 23 insertions(+)
> >
> > diff --git a/drivers/of/base.c b/drivers/of/base.c
> > index b082f0c656..6644d9b96a 100644
> > --- a/drivers/of/base.c
> > +++ b/drivers/of/base.c
> > @@ -2094,6 +2094,24 @@ void of_delete_node(struct device_node *node)
> > of_set_root_node(NULL);
> > }
> >
> > +void of_rename_node(struct device_node *node, char *name)
>
> Should be const char * name.
Okay.
>
> > +{
> > + struct device_node *parent;
> > +
> > + if (!node)
> > + return;
> > +
> > + parent = node->parent;
> > + if (parent) {
> > + node->name = name;
>
> node->name is an allocated string. It should be freed and then set to an
> allocated string again.
Okay, I will do this.
>
> > + node->full_name = basprintf("%s/%s", parent->full_name, name);
> > + } else {
> > + /* root node */
> > + node->name = xstrdup("");
> > + node->full_name = xstrdup("");
>
> I think we can drop the else path entirely. If we do not allow to give
> the root node a name then we can assume that it doesn't have a name
> right now, so nothing to do here.
Sure, I will change this.
Regards,
Marco
> Sascha
>
> --
> Pengutronix e.K. | |
> Industrial Linux Solutions | http://www.pengutronix.de/ |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] memory: of_fixup: adapt to new memory layout
2019-02-12 8:45 ` Marco Felsch
@ 2019-02-12 8:56 ` Sascha Hauer
2019-02-12 9:01 ` Marco Felsch
0 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2019-02-12 8:56 UTC (permalink / raw)
To: Marco Felsch; +Cc: barebox
On Tue, Feb 12, 2019 at 09:45:25AM +0100, Marco Felsch wrote:
> Hi Sascha,
>
> On 19-02-12 09:03, Sascha Hauer wrote:
> > On Mon, Feb 11, 2019 at 05:20:13PM +0100, Marco Felsch wrote:
> > > Since kernel 4.16 the memory nodes got a @<reg> suffix so the fixup
> > > won't work correctly anymore, because instead of adapting the extisting
> > > one it creates a new node.
> > >
> > > To be compatible with the old and new layout delete the found memory
> > > node and create a new one. The new node follows the new @<reg> style.
> > >
> > > The patch also renames the node element to root to make it more clear.
> > >
> > > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > > ---
> > > common/memory.c | 24 ++++++++++++++++++++++--
> > > 1 file changed, 22 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/common/memory.c b/common/memory.c
> > > index 00fa7c50ff..5402acab8e 100644
> > > --- a/common/memory.c
> > > +++ b/common/memory.c
> > > @@ -224,7 +224,7 @@ int memory_bank_first_find_space(resource_size_t *retstart,
> > >
> > > #ifdef CONFIG_OFTREE
> > >
> > > -static int of_memory_fixup(struct device_node *node, void *unused)
> > > +static int of_memory_fixup(struct device_node *root, void *unused)
> > > {
> > > struct memory_bank *bank;
> > > int err;
> > > @@ -232,7 +232,23 @@ static int of_memory_fixup(struct device_node *node, void *unused)
> > > struct device_node *memnode;
> > > u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
> > >
> > > - memnode = of_create_node(node, "/memory");
> > > + /*
> > > + * Since kernel 4.16 the memory node got a @<reg> suffix. To support
> > > + * the old and the new style delete any found memory node and add it
> > > + * again to be sure that the memory node exists only once. It shouldn't
> > > + * bother older kernels if the memory node has this suffix so adding it
> > > + * following the new style.
> > > + */
> > > +
> > > + memnode = of_find_node_by_name(root, "memory");
> >
> > We don't need this as the /memory node must have device_type = memory.
>
> Okay, tought about the old devicetrees where the QA wasn't that good. I
> will drop this.
>
> >
> > > + if (!memnode)
> > > + memnode = of_find_node_by_type(root, "memory");
> >
> > You shouldn't assume that there's only one /memory node. There can be
> > multiple.
>
> Sure.. damn, checked only a few devicetree's where multiple banks are
> mapped to the reg property. I will change this.
>
> > The /memory node must be a direct child of the root node, so it's
> > unnecessary to traverse the whole tree using of_find_node_by_type().
> > Something like for_each_child_of_node_safe(root, tmp, np) fits better.
>
> Okay.
>
> >
> > > +
> > > + if (memnode)
> > > + of_delete_node(memnode);
> > > +
> > > + /* At this moment we don't know the <reg> val */
> > > + memnode = of_create_node(root, "/memory");
> > > if (!memnode)
> > > return -ENOMEM;
> > >
> > > @@ -256,6 +272,10 @@ static int of_memory_fixup(struct device_node *node, void *unused)
> > > return err;
> > > }
> > >
> > > + /* now adapt the node name */
> > > + of_rename_node(memnode, basprintf("memory@%llx",
> > > + of_read_number((u32 *)tmp, addr_cell_len)));
> >
> > It's also allowed to create one /memory node per memory bank. Maybe
> > that's more straightforward to implement.
>
> Is it wrong to adapt the name later? As specified by DT-Spec [1], the
> @<reg> should be set to the first address.
What do they mean with the first address? Currently the memory banks in
barebox are not sorted, so you are setting @reg indeed to the first
address, but this is not currently necessarily the lowest one.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] memory: of_fixup: adapt to new memory layout
2019-02-12 8:56 ` Sascha Hauer
@ 2019-02-12 9:01 ` Marco Felsch
0 siblings, 0 replies; 8+ messages in thread
From: Marco Felsch @ 2019-02-12 9:01 UTC (permalink / raw)
To: Sascha Hauer; +Cc: barebox
On 19-02-12 09:56, Sascha Hauer wrote:
> On Tue, Feb 12, 2019 at 09:45:25AM +0100, Marco Felsch wrote:
> > Hi Sascha,
> >
> > On 19-02-12 09:03, Sascha Hauer wrote:
> > > On Mon, Feb 11, 2019 at 05:20:13PM +0100, Marco Felsch wrote:
> > > > Since kernel 4.16 the memory nodes got a @<reg> suffix so the fixup
> > > > won't work correctly anymore, because instead of adapting the extisting
> > > > one it creates a new node.
> > > >
> > > > To be compatible with the old and new layout delete the found memory
> > > > node and create a new one. The new node follows the new @<reg> style.
> > > >
> > > > The patch also renames the node element to root to make it more clear.
> > > >
> > > > Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
> > > > ---
> > > > common/memory.c | 24 ++++++++++++++++++++++--
> > > > 1 file changed, 22 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/common/memory.c b/common/memory.c
> > > > index 00fa7c50ff..5402acab8e 100644
> > > > --- a/common/memory.c
> > > > +++ b/common/memory.c
> > > > @@ -224,7 +224,7 @@ int memory_bank_first_find_space(resource_size_t *retstart,
> > > >
> > > > #ifdef CONFIG_OFTREE
> > > >
> > > > -static int of_memory_fixup(struct device_node *node, void *unused)
> > > > +static int of_memory_fixup(struct device_node *root, void *unused)
> > > > {
> > > > struct memory_bank *bank;
> > > > int err;
> > > > @@ -232,7 +232,23 @@ static int of_memory_fixup(struct device_node *node, void *unused)
> > > > struct device_node *memnode;
> > > > u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
> > > >
> > > > - memnode = of_create_node(node, "/memory");
> > > > + /*
> > > > + * Since kernel 4.16 the memory node got a @<reg> suffix. To support
> > > > + * the old and the new style delete any found memory node and add it
> > > > + * again to be sure that the memory node exists only once. It shouldn't
> > > > + * bother older kernels if the memory node has this suffix so adding it
> > > > + * following the new style.
> > > > + */
> > > > +
> > > > + memnode = of_find_node_by_name(root, "memory");
> > >
> > > We don't need this as the /memory node must have device_type = memory.
> >
> > Okay, tought about the old devicetrees where the QA wasn't that good. I
> > will drop this.
> >
> > >
> > > > + if (!memnode)
> > > > + memnode = of_find_node_by_type(root, "memory");
> > >
> > > You shouldn't assume that there's only one /memory node. There can be
> > > multiple.
> >
> > Sure.. damn, checked only a few devicetree's where multiple banks are
> > mapped to the reg property. I will change this.
> >
> > > The /memory node must be a direct child of the root node, so it's
> > > unnecessary to traverse the whole tree using of_find_node_by_type().
> > > Something like for_each_child_of_node_safe(root, tmp, np) fits better.
> >
> > Okay.
> >
> > >
> > > > +
> > > > + if (memnode)
> > > > + of_delete_node(memnode);
> > > > +
> > > > + /* At this moment we don't know the <reg> val */
> > > > + memnode = of_create_node(root, "/memory");
> > > > if (!memnode)
> > > > return -ENOMEM;
> > > >
> > > > @@ -256,6 +272,10 @@ static int of_memory_fixup(struct device_node *node, void *unused)
> > > > return err;
> > > > }
> > > >
> > > > + /* now adapt the node name */
> > > > + of_rename_node(memnode, basprintf("memory@%llx",
> > > > + of_read_number((u32 *)tmp, addr_cell_len)));
> > >
> > > It's also allowed to create one /memory node per memory bank. Maybe
> > > that's more straightforward to implement.
> >
> > Is it wrong to adapt the name later? As specified by DT-Spec [1], the
> > @<reg> should be set to the first address.
>
> What do they mean with the first address? Currently the memory banks in
> barebox are not sorted, so you are setting @reg indeed to the first
> address, but this is not currently necessarily the lowest one.
By first I mean the lowest, sorry. Oh I tought the banks are sorted, now
I got you. In that case it is easier to add one /memory node per memory
bank, as you mentoined. I will change that in my v2.
Regards,
Marco
>
> Sascha
>
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2019-02-12 9:01 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-11 16:20 [PATCH 1/2] of: base: add helper to rename a node Marco Felsch
2019-02-11 16:20 ` [PATCH 2/2] memory: of_fixup: adapt to new memory layout Marco Felsch
2019-02-12 8:03 ` Sascha Hauer
2019-02-12 8:45 ` Marco Felsch
2019-02-12 8:56 ` Sascha Hauer
2019-02-12 9:01 ` Marco Felsch
2019-02-12 7:32 ` [PATCH 1/2] of: base: add helper to rename a node Sascha Hauer
2019-02-12 8:49 ` Marco Felsch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox