diff mbox

[U-Boot,1/2] libfdt: Add support for appending the values to a existing property

Message ID 1346114340-5510-1-git-send-email-kim.phillips@freescale.com
State Accepted
Delegated to: Jerry Van Baren
Headers show

Commit Message

Kim Phillips Aug. 28, 2012, 12:38 a.m. UTC
From: Minghuan Lian <Minghuan.Lian@freescale.com>

Some properties may contain multiple values, these values may need
to be added to the property respectively. this patch provides this
functionality. The main purpose of fdt_append_prop() is to append
the values to a existing property, or create a new property if it
dose not exist.

Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 include/libfdt.h    | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/libfdt/fdt_rw.c | 27 +++++++++++++++
 2 files changed, 122 insertions(+)

Comments

Jerry Van Baren Sept. 13, 2012, 1:43 a.m. UTC | #1
Hi Kim, Minghuan,

On 09/12/2012 08:08 PM, Kim Phillips wrote:
> On Mon, 27 Aug 2012 19:38:59 -0500
> Kim Phillips <kim.phillips@freescale.com> wrote:
> 
>> From: Minghuan Lian <Minghuan.Lian@freescale.com>
>>
>> Some properties may contain multiple values, these values may need
>> to be added to the property respectively. this patch provides this
>> functionality. The main purpose of fdt_append_prop() is to append
>> the values to a existing property, or create a new property if it
>> dose not exist.
>>
>> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
>> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
>> ---
> 
> Jerry, can you take a look at applying these?

Yes, I'll queue them up this weekend.

I'll also queue Marek Vasut <marex@denx.de> patch "[U-Boot] [PATCH] fdt:
Check if the FDT address is configured"

The merge window for v2012.10 closed September 18.  Unless there is an
overriding urgency, the patches will go into the following release.

> Thanks,
> Kim

Best regards,
gvb
Jerry Van Baren Sept. 15, 2012, 2:36 p.m. UTC | #2
On 08/27/2012 08:38 PM, Kim Phillips wrote:
> From: Minghuan Lian <Minghuan.Lian@freescale.com>
> 
> Some properties may contain multiple values, these values may need
> to be added to the property respectively. this patch provides this
> functionality. The main purpose of fdt_append_prop() is to append
> the values to a existing property, or create a new property if it
> dose not exist.
> 
> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>

Queued up 2 of 2 patches to the u-boot-fdt "next" branch.  I'll issue a
pull request when the merge window opens.

Thanks,
gvb
Tabi Timur-B04825 Sept. 15, 2012, 3 p.m. UTC | #3
On Sat, Sep 15, 2012 at 9:36 AM, Jerry Van Baren <gvb.uboot@gmail.com> wrote:

> Queued up 2 of 2 patches to the u-boot-fdt "next" branch.  I'll issue a
> pull request when the merge window opens.

I thought libfdt patches were suppose to go to dtc.git?
Jerry Van Baren Sept. 15, 2012, 3:19 p.m. UTC | #4
On 09/15/2012 11:00 AM, Tabi Timur-B04825 wrote:
> On Sat, Sep 15, 2012 at 9:36 AM, Jerry Van Baren <gvb.uboot@gmail.com> wrote:
> 
>> Queued up 2 of 2 patches to the u-boot-fdt "next" branch.  I'll issue a
>> pull request when the merge window opens.
> 
> I thought libfdt patches were suppose to go to dtc.git?

That is where they came from.  Since the u-boot libfdt is a subset of
the whole dtc.git repository (just the libfdt part), I've been cherry
picking only the libfdt/* patches (with the help of others).

I see David has another patch for the libfdt library that I probably
should pick up so that we stay in sync (18 lines of code by counting
semicolons).

commit be6026838e45b67800ac803f4ad8cca3cde57d6d
Author: David Gibson <david@gibson.dropbear.id.au>
Date:   Fri Jun 1 14:12:38 2012 +1000

    libfdt: Add helper function to create a trivial, empty tree

    The libfdt read/write functions are now usable enough that it's become a
    moderately common pattern to use them to build and manipulate a device
    tree from scratch.  For example, we do so ourself in our rw_tree1
testcase,
    and qemu is starting to use this model when building device trees
for some
    targets such as e500.

    However, the read/write functions require some sort of valid tree to
begin
    with, so this necessitates either having a trivial canned dtb to
begin with
    or, more commonly, creating an empty tree using the serial-write
functions
    first.

    This patch adds a helper function which uses the serial-write
functions to
    create a trivial, empty but complete and valid tree in a supplied
buffer,
    ready for manipulation with the read/write functions.

    Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Kim Phillips Nov. 9, 2012, 1:41 a.m. UTC | #5
On Sat, 15 Sep 2012 10:36:28 -0400
Jerry Van Baren <gvb.uboot@gmail.com> wrote:

> On 08/27/2012 08:38 PM, Kim Phillips wrote:
> > From: Minghuan Lian <Minghuan.Lian@freescale.com>
> > 
> > Some properties may contain multiple values, these values may need
> > to be added to the property respectively. this patch provides this
> > functionality. The main purpose of fdt_append_prop() is to append
> > the values to a existing property, or create a new property if it
> > dose not exist.
> > 
> > Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> 
> Queued up 2 of 2 patches to the u-boot-fdt "next" branch.  I'll issue a
> pull request when the merge window opens.

the merge window closed five days ago, and these didn't make it in.
What's the deal?

Kim
Simon Glass Nov. 9, 2012, 1:48 a.m. UTC | #6
On Thu, Nov 8, 2012 at 5:41 PM, Kim Phillips <kim.phillips@freescale.com> wrote:
> On Sat, 15 Sep 2012 10:36:28 -0400
> Jerry Van Baren <gvb.uboot@gmail.com> wrote:
>
>> On 08/27/2012 08:38 PM, Kim Phillips wrote:
>> > From: Minghuan Lian <Minghuan.Lian@freescale.com>
>> >
>> > Some properties may contain multiple values, these values may need
>> > to be added to the property respectively. this patch provides this
>> > functionality. The main purpose of fdt_append_prop() is to append
>> > the values to a existing property, or create a new property if it
>> > dose not exist.
>> >
>> > Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
>> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
>>
>> Queued up 2 of 2 patches to the u-boot-fdt "next" branch.  I'll issue a
>> pull request when the merge window opens.
>
> the merge window closed five days ago, and these didn't make it in.
> What's the deal?

Well it doesn't mean it won't be applied. Probably just need to wait a bit.

>
> Kim
>
> _______________________________________________
> U-Boot mailing list
> U-Boot@lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
Jerry Van Baren Nov. 13, 2012, 2:41 a.m. UTC | #7
On 11/08/2012 08:41 PM, Kim Phillips wrote:
> On Sat, 15 Sep 2012 10:36:28 -0400
> Jerry Van Baren <gvb.uboot@gmail.com> wrote:
> 
>> On 08/27/2012 08:38 PM, Kim Phillips wrote:
>>> From: Minghuan Lian <Minghuan.Lian@freescale.com>
>>>
>>> Some properties may contain multiple values, these values may need
>>> to be added to the property respectively. this patch provides this
>>> functionality. The main purpose of fdt_append_prop() is to append
>>> the values to a existing property, or create a new property if it
>>> dose not exist.
>>>
>>> Signed-off-by: Minghuan Lian <Minghuan.Lian@freescale.com>
>>> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
>>
>> Queued up 2 of 2 patches to the u-boot-fdt "next" branch.  I'll issue a
>> pull request when the merge window opens.
> 
> the merge window closed five days ago, and these didn't make it in.
> What's the deal?
> 
> Kim

It's in there:
<http://git.denx.de/?p=u-boot.git;a=commit;h=36ad18a6db0eec546b83e6500ceb7593be53a1ed>

I sent a pull request Mon, Oct 22, 2012 and Tom applied it on Oct 23:
-----------------------------------------------------------------
David Gibson (1):
      libfdt: Add helpers for 64-bit integer properties

Gerald Van Baren (2):
      libfdt: Add helper function to create a trivial, empty tree
      Merge branch 'next'

Joe Hershberger (5):
      fdt: Check error codes returned from fdtlib when loading ITB
      fdt: Limit printed hex in fdt print and list commands
      fdt: Add get commands to fdt
      fdt: Identify scripts in ITBs as printable strings
      fdt: Check for a token to skip auto-hash validation

Minghuan Lian (1):
      libfdt: Add support for appending the values to a existing property
-----------------------------------------------------------------

Best regards,
gvb
Kim Phillips Nov. 13, 2012, 9:02 p.m. UTC | #8
On Mon, 12 Nov 2012 21:41:17 -0500
Jerry Van Baren <gvb.uboot@gmail.com> wrote:

> On 11/08/2012 08:41 PM, Kim Phillips wrote:
> > On Sat, 15 Sep 2012 10:36:28 -0400
> > Jerry Van Baren <gvb.uboot@gmail.com> wrote:
> >> Queued up 2 of 2 patches to the u-boot-fdt "next" branch.  I'll issue a
> >> pull request when the merge window opens.
> > 
> > the merge window closed five days ago, and these didn't make it in.
> > What's the deal?
> 
> It's in there:
> <http://git.denx.de/?p=u-boot.git;a=commit;h=36ad18a6db0eec546b83e6500ceb7593be53a1ed>
> 
> I sent a pull request Mon, Oct 22, 2012 and Tom applied it on Oct 23:

right you are - don't know what I was looking at - my apologies.

Kim
diff mbox

Patch

diff --git a/include/libfdt.h b/include/libfdt.h
index de82ed5..78798e8 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -1134,6 +1134,101 @@  static inline int fdt_setprop_cell(void *fdt, int nodeoffset, const char *name,
 	fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
 
 /**
+ * fdt_appendprop - append to or create a property
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node whose property to change
+ * @name: name of the property to append to
+ * @val: pointer to data to append to the property value
+ * @len: length of the data to append to the property value
+ *
+ * fdt_appendprop() appends the value to the named property in the
+ * given node, creating the property if it does not already exist.
+ *
+ * This function may insert data into the blob, and will therefore
+ * change the offsets of some existing nodes.
+ *
+ * returns:
+ *	0, on success
+ *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
+ *		contain the new property value
+ *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
+ *	-FDT_ERR_BADLAYOUT,
+ *	-FDT_ERR_BADMAGIC,
+ *	-FDT_ERR_BADVERSION,
+ *	-FDT_ERR_BADSTATE,
+ *	-FDT_ERR_BADSTRUCTURE,
+ *	-FDT_ERR_BADLAYOUT,
+ *	-FDT_ERR_TRUNCATED, standard meanings
+ */
+int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
+		   const void *val, int len);
+
+/**
+ * fdt_appendprop_cell - append a single cell value to a property
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node whose property to change
+ * @name: name of the property to change
+ * @val: 32-bit integer value to append to the property (native endian)
+ *
+ * fdt_appendprop_cell() appends the given cell value (converting to
+ * big-endian if necessary) to the value of the named property in the
+ * given node, or creates a new property with that value if it does
+ * not already exist.
+ *
+ * This function may insert data into the blob, and will therefore
+ * change the offsets of some existing nodes.
+ *
+ * returns:
+ *	0, on success
+ *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
+ *		contain the new property value
+ *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
+ *	-FDT_ERR_BADLAYOUT,
+ *	-FDT_ERR_BADMAGIC,
+ *	-FDT_ERR_BADVERSION,
+ *	-FDT_ERR_BADSTATE,
+ *	-FDT_ERR_BADSTRUCTURE,
+ *	-FDT_ERR_BADLAYOUT,
+ *	-FDT_ERR_TRUNCATED, standard meanings
+ */
+static inline int fdt_appendprop_cell(void *fdt, int nodeoffset,
+				      const char *name, uint32_t val)
+{
+	val = cpu_to_fdt32(val);
+	return fdt_appendprop(fdt, nodeoffset, name, &val, sizeof(val));
+}
+
+/**
+ * fdt_appendprop_string - append a string to a property
+ * @fdt: pointer to the device tree blob
+ * @nodeoffset: offset of the node whose property to change
+ * @name: name of the property to change
+ * @str: string value to append to the property
+ *
+ * fdt_appendprop_string() appends the given string to the value of
+ * the named property in the given node, or creates a new property
+ * with that value if it does not already exist.
+ *
+ * This function may insert data into the blob, and will therefore
+ * change the offsets of some existing nodes.
+ *
+ * returns:
+ *	0, on success
+ *	-FDT_ERR_NOSPACE, there is insufficient free space in the blob to
+ *		contain the new property value
+ *	-FDT_ERR_BADOFFSET, nodeoffset did not point to FDT_BEGIN_NODE tag
+ *	-FDT_ERR_BADLAYOUT,
+ *	-FDT_ERR_BADMAGIC,
+ *	-FDT_ERR_BADVERSION,
+ *	-FDT_ERR_BADSTATE,
+ *	-FDT_ERR_BADSTRUCTURE,
+ *	-FDT_ERR_BADLAYOUT,
+ *	-FDT_ERR_TRUNCATED, standard meanings
+ */
+#define fdt_appendprop_string(fdt, nodeoffset, name, str) \
+	fdt_appendprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)
+
+/**
  * fdt_delprop - delete a property
  * @fdt: pointer to the device tree blob
  * @nodeoffset: offset of the node whose property to nop
diff --git a/lib/libfdt/fdt_rw.c b/lib/libfdt/fdt_rw.c
index 5c27a67..5ed23d6 100644
--- a/lib/libfdt/fdt_rw.c
+++ b/lib/libfdt/fdt_rw.c
@@ -293,6 +293,33 @@  int fdt_setprop(void *fdt, int nodeoffset, const char *name,
 	return 0;
 }
 
+int fdt_appendprop(void *fdt, int nodeoffset, const char *name,
+		   const void *val, int len)
+{
+	struct fdt_property *prop;
+	int err, oldlen, newlen;
+
+	FDT_RW_CHECK_HEADER(fdt);
+
+	prop = fdt_get_property_w(fdt, nodeoffset, name, &oldlen);
+	if (prop) {
+		newlen = len + oldlen;
+		err = _fdt_splice_struct(fdt, prop->data,
+					 FDT_TAGALIGN(oldlen),
+					 FDT_TAGALIGN(newlen));
+		if (err)
+			return err;
+		prop->len = cpu_to_fdt32(newlen);
+		memcpy(prop->data + oldlen, val, len);
+	} else {
+		err = _fdt_add_property(fdt, nodeoffset, name, len, &prop);
+		if (err)
+			return err;
+		memcpy(prop->data, val, len);
+	}
+	return 0;
+}
+
 int fdt_delprop(void *fdt, int nodeoffset, const char *name)
 {
 	struct fdt_property *prop;