diff mbox

[U-Boot,v2,04/40] fdt: Add functions to retrieve strings

Message ID 1409067268-956-5-git-send-email-thierry.reding@gmail.com
State Awaiting Upstream
Delegated to: Simon Glass
Headers show

Commit Message

Thierry Reding Aug. 26, 2014, 3:33 p.m. UTC
From: Thierry Reding <treding@nvidia.com>

Given a device tree node, a property name and an index, the new function
fdt_get_string_index() will return in an output argument a pointer to
the index'th string in the property's value.

The fdt_get_string() is a shortcut for the above with the index being 0.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 include/libfdt.h    | 27 +++++++++++++++++++++++++++
 lib/libfdt/fdt_ro.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)

Comments

Simon Glass Aug. 27, 2014, 6:53 p.m. UTC | #1
Hi Thierry,

On 26 August 2014 09:33, Thierry Reding <thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> Given a device tree node, a property name and an index, the new function
> fdt_get_string_index() will return in an output argument a pointer to
> the index'th string in the property's value.
>
> The fdt_get_string() is a shortcut for the above with the index being 0.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Simon Glass <sjg@chromium.org>

Could be fdt_stringlist_lookup() maybe. But there's no point guessing
until you send this upstream.

Regards,
Simon
Simon Glass Sept. 8, 2014, 3:02 p.m. UTC | #2
Applied to u-boot-fdt/next, thanks!
Simon Glass March 25, 2015, 11:23 p.m. UTC | #3
Hi Thierry,

On 8 September 2014 at 09:02, Simon Glass <sjg@chromium.org> wrote:
> Applied to u-boot-fdt/next, thanks!

Did you submit these patches to dtc upstream? I don't see them applied.

Regards,
SImon
Simon Glass July 14, 2015, 7:48 p.m. UTC | #4
+Scott, Masahiro

Hi Thierry,

On 25 March 2015 at 17:23, Simon Glass <sjg@chromium.org> wrote:
> Hi Thierry,
>
> On 8 September 2014 at 09:02, Simon Glass <sjg@chromium.org> wrote:
>> Applied to u-boot-fdt/next, thanks!
>
> Did you submit these patches to dtc upstream? I don't see them applied.

Ping? Masahiro has now sent a series on top of your patches, so we
need to sort this out.

Regards,
Simon
Thierry Reding July 15, 2015, 11:17 a.m. UTC | #5
On Tue, Jul 14, 2015 at 01:48:45PM -0600, Simon Glass wrote:
> +Scott, Masahiro
> 
> Hi Thierry,
> 
> On 25 March 2015 at 17:23, Simon Glass <sjg@chromium.org> wrote:
> > Hi Thierry,
> >
> > On 8 September 2014 at 09:02, Simon Glass <sjg@chromium.org> wrote:
> >> Applied to u-boot-fdt/next, thanks!
> >
> > Did you submit these patches to dtc upstream? I don't see them applied.
> 
> Ping? Masahiro has now sent a series on top of your patches, so we
> need to sort this out.

I sent these to the DTC maintainers and the list, with you and Masahiro
in Cc. They patches should be eqivalent to what's in U-Boot except for
the node parameter that I renamed nodeoffset for consistency with libfdt
and the testsuite bits.

Thierry
Albert ARIBAUD July 15, 2015, 11:35 a.m. UTC | #6
Hello Thierry,

On Wed, 15 Jul 2015 13:17:18 +0200, Thierry Reding
<thierry.reding@gmail.com> wrote:
> On Tue, Jul 14, 2015 at 01:48:45PM -0600, Simon Glass wrote:
> > +Scott, Masahiro
> > 
> > Hi Thierry,
> > 
> > On 25 March 2015 at 17:23, Simon Glass <sjg@chromium.org> wrote:
> > > Hi Thierry,
> > >
> > > On 8 September 2014 at 09:02, Simon Glass <sjg@chromium.org> wrote:
> > >> Applied to u-boot-fdt/next, thanks!
> > >
> > > Did you submit these patches to dtc upstream? I don't see them applied.
> > 
> > Ping? Masahiro has now sent a series on top of your patches, so we
> > need to sort this out.
> 
> I sent these to the DTC maintainers and the list, with you and Masahiro
> in Cc. They patches should be eqivalent to what's in U-Boot except for
> the node parameter that I renamed nodeoffset for consistency with libfdt
> and the testsuite bits.

Do you mean there are intrinsic incompatibilities between U-Boot and
Linux that make it impossible to use the same name in both?

> Thierry

Amicalement,
Thierry Reding July 15, 2015, 11:52 a.m. UTC | #7
On Wed, Jul 15, 2015 at 01:35:26PM +0200, Albert ARIBAUD wrote:
> Hello Thierry,
> 
> On Wed, 15 Jul 2015 13:17:18 +0200, Thierry Reding
> <thierry.reding@gmail.com> wrote:
> > On Tue, Jul 14, 2015 at 01:48:45PM -0600, Simon Glass wrote:
> > > +Scott, Masahiro
> > > 
> > > Hi Thierry,
> > > 
> > > On 25 March 2015 at 17:23, Simon Glass <sjg@chromium.org> wrote:
> > > > Hi Thierry,
> > > >
> > > > On 8 September 2014 at 09:02, Simon Glass <sjg@chromium.org> wrote:
> > > >> Applied to u-boot-fdt/next, thanks!
> > > >
> > > > Did you submit these patches to dtc upstream? I don't see them applied.
> > > 
> > > Ping? Masahiro has now sent a series on top of your patches, so we
> > > need to sort this out.
> > 
> > I sent these to the DTC maintainers and the list, with you and Masahiro
> > in Cc. They patches should be eqivalent to what's in U-Boot except for
> > the node parameter that I renamed nodeoffset for consistency with libfdt
> > and the testsuite bits.
> 
> Do you mean there are intrinsic incompatibilities between U-Boot and
> Linux that make it impossible to use the same name in both?

No, I don't think so. Back at the time I must have assumed that node was
the consistent name used in U-Boot, but it seems like these string
functions are now the only ones in libfdt that use this. I'd expect that
to fix itself when libfdt gets sync'ed back from the upstream copy.

Thierry
diff mbox

Patch

diff --git a/include/libfdt.h b/include/libfdt.h
index d0dea668eea2..2dfc6d9e5ce7 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -877,6 +877,33 @@  int fdt_count_strings(const void *fdt, int node, const char *property);
 int fdt_find_string(const void *fdt, int node, const char *property,
 		    const char *string);
 
+/**
+ * fdt_get_string_index() - obtain the string at a given index in a string list
+ * @fdt: pointer to the device tree blob
+ * @node: offset of the node
+ * @property: name of the property containing the string list
+ * @index: index of the string to return
+ * @output: return location for the string
+ * @return: 0 if the string was found or a negative error code otherwise
+ */
+int fdt_get_string_index(const void *fdt, int node, const char *property,
+			 int index, const char **output);
+
+/**
+ * fdt_get_string() - obtain the string at a given index in a string list
+ * @fdt: pointer to the device tree blob
+ * @node: offset of the node
+ * @property: name of the property containing the string list
+ * @output: return location for the string
+ * @return: 0 if the string was found or a negative error code otherwise
+ *
+ * This is a shortcut for:
+ *
+ *	fdt_get_string_index(fdt, node, property, 0, output).
+ */
+int fdt_get_string(const void *fdt, int node, const char *property,
+		   const char **output);
+
 /**********************************************************************/
 /* Read-only functions (addressing related)                           */
 /**********************************************************************/
diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c
index fec4a0a141fd..03733e574f71 100644
--- a/lib/libfdt/fdt_ro.c
+++ b/lib/libfdt/fdt_ro.c
@@ -537,6 +537,36 @@  int fdt_find_string(const void *fdt, int node, const char *property,
 	return -FDT_ERR_NOTFOUND;
 }
 
+int fdt_get_string_index(const void *fdt, int node, const char *property,
+			 int index, const char **output)
+{
+	const char *list;
+	int length, i;
+
+	list = fdt_getprop(fdt, node, property, &length);
+
+	for (i = 0; i < length; i++) {
+		int len = strlen(list);
+
+		if (index == 0) {
+			*output = list;
+			return 0;
+		}
+
+		list += len + 1;
+		i += len;
+		index--;
+	}
+
+	return FDT_ERR_NOTFOUND;
+}
+
+int fdt_get_string(const void *fdt, int node, const char *property,
+		   const char **output)
+{
+	return fdt_get_string_index(fdt, node, property, 0, output);
+}
+
 int fdt_node_check_compatible(const void *fdt, int nodeoffset,
 			      const char *compatible)
 {