All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fdtdec: support multiple phandles in memory carveout
@ 2020-03-31 13:16 Laurentiu Tudor
  2020-04-02  2:34 ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: Laurentiu Tudor @ 2020-03-31 13:16 UTC (permalink / raw)
  To: u-boot

fdtdec_set_carveout() is limited to only one phandle. Fix this
limitation by adding support for multiple phandles.

Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
---
 lib/fdtdec.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index eb11fc898e..9ecfa2a2d7 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1433,14 +1433,9 @@ int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
 			const struct fdt_memory *carveout)
 {
 	uint32_t phandle;
-	int err, offset;
+	int err, offset, len;
 	fdt32_t value;
-
-	/* XXX implement support for multiple phandles */
-	if (index > 0) {
-		debug("invalid index %u\n", index);
-		return -FDT_ERR_BADOFFSET;
-	}
+	void *prop;
 
 	err = fdtdec_add_reserved_memory(blob, name, carveout, &phandle);
 	if (err < 0) {
@@ -1456,10 +1451,31 @@ int fdtdec_set_carveout(void *blob, const char *node, const char *prop_name,
 
 	value = cpu_to_fdt32(phandle);
 
-	err = fdt_setprop(blob, offset, prop_name, &value, sizeof(value));
+	if (!fdt_getprop(blob, offset, prop_name, &len)) {
+		if (len == -FDT_ERR_NOTFOUND)
+			len = 0;
+		else
+			return len;
+	}
+
+	if ((index + 1) * sizeof(value) > len) {
+		err = fdt_setprop_placeholder(blob, offset, prop_name,
+					      (index + 1) * sizeof(value),
+					      &prop);
+		if (err < 0) {
+			debug("failed to resize reserved memory property: %s\n",
+			      fdt_strerror(err));
+			return err;
+		}
+	}
+
+	err = fdt_setprop_inplace_namelen_partial(blob, offset, prop_name,
+						  strlen(prop_name),
+						  index * sizeof(value),
+						  &value, sizeof(value));
 	if (err < 0) {
-		debug("failed to set %s property for node %s: %d\n", prop_name,
-		      node, err);
+		debug("failed to update %s property for node %s: %s\n",
+		      prop_name, node, fdt_strerror(err));
 		return err;
 	}
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] fdtdec: support multiple phandles in memory carveout
  2020-03-31 13:16 [PATCH] fdtdec: support multiple phandles in memory carveout Laurentiu Tudor
@ 2020-04-02  2:34 ` Simon Glass
  2020-04-02  9:13   ` Laurentiu Tudor
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Glass @ 2020-04-02  2:34 UTC (permalink / raw)
  To: u-boot

Hi,

On Tue, 31 Mar 2020 at 07:16, Laurentiu Tudor <laurentiu.tudor@nxp.com> wrote:
>
> fdtdec_set_carveout() is limited to only one phandle. Fix this
> limitation by adding support for multiple phandles.
>
> Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
> ---
>  lib/fdtdec.c | 36 ++++++++++++++++++++++++++----------
>  1 file changed, 26 insertions(+), 10 deletions(-)
>

Please can you add a test for this function? You could put it in
test/dm/fdtdec.c - see ofnode.c for an example.

Regards,
Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] fdtdec: support multiple phandles in memory carveout
  2020-04-02  2:34 ` Simon Glass
@ 2020-04-02  9:13   ` Laurentiu Tudor
  0 siblings, 0 replies; 3+ messages in thread
From: Laurentiu Tudor @ 2020-04-02  9:13 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On 4/2/2020 5:34 AM, Simon Glass wrote:
> Hi,
> 
> On Tue, 31 Mar 2020 at 07:16, Laurentiu Tudor <laurentiu.tudor@nxp.com> wrote:
>>
>> fdtdec_set_carveout() is limited to only one phandle. Fix this
>> limitation by adding support for multiple phandles.
>>
>> Signed-off-by: Laurentiu Tudor <laurentiu.tudor@nxp.com>
>> ---
>>  lib/fdtdec.c | 36 ++++++++++++++++++++++++++----------
>>  1 file changed, 26 insertions(+), 10 deletions(-)
>>
> 
> Please can you add a test for this function? You could put it in
> test/dm/fdtdec.c - see ofnode.c for an example.
> 

Sure, I'll look into it. Thanks.

---
Best regards, Laurentiu

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-02  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-31 13:16 [PATCH] fdtdec: support multiple phandles in memory carveout Laurentiu Tudor
2020-04-02  2:34 ` Simon Glass
2020-04-02  9:13   ` Laurentiu Tudor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.