* [U-Boot] [PATCH] libfdt: Add function to explicitly expand aliases
@ 2008-10-02 23:05 Jerry Van Baren
2008-10-03 20:00 ` Petri Lehtinen
0 siblings, 1 reply; 5+ messages in thread
From: Jerry Van Baren @ 2008-10-02 23:05 UTC (permalink / raw)
To: u-boot
Kumar has already added alias expansion to fdt_path_offset().
However, in some circumstances it may be convenient for the user of
libfdt to explicitly get the string expansion of an alias. This patch
adds a function to do this, fdt_get_alias(), and uses it to implement
fdt_path_offset().
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
Another patch hot off the dtc/libfdt repository.
gvb
include/libfdt.h | 26 ++++++++++++++++++++++++++
libfdt/fdt_ro.c | 26 +++++++++++++++++++-------
2 files changed, 45 insertions(+), 7 deletions(-)
diff --git a/include/libfdt.h b/include/libfdt.h
index 5492a53..7cad68c 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -459,6 +459,32 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
/**
+ * fdt_get_namelen - get alias based on substring
+ * @fdt: pointer to the device tree blob
+ * @name: name of the alias th look up
+ * @namelen: number of characters of name to consider
+ *
+ * Identical to fdt_get_alias(), but only examine the first namelen
+ * characters of name for matching the alias name.
+ */
+const char *fdt_get_alias_namelen(const void *fdt,
+ const char *name, int namelen);
+
+/**
+ * fdt_get_alias - retreive the path referenced by a given alias
+ * @fdt: pointer to the device tree blob
+ * @name: name of the alias th look up
+ *
+ * fdt_get_alias() retrieves the value of a given alias. That is, the
+ * value of the property named 'name' in the node /aliases.
+ *
+ * returns:
+ * a pointer to the expansion of the alias named 'name', of it exists
+ * NULL, if the given alias or the /aliases node does not exist
+ */
+const char *fdt_get_alias(const void *fdt, const char *name);
+
+/**
* fdt_get_path - determine the full path of a node
* @fdt: pointer to the device tree blob
* @nodeoffset: offset of the node whose path to find
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index f559eed..b705f91 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -145,17 +145,12 @@ int fdt_path_offset(const void *fdt, const char *path)
/* see if we have an alias */
if (*path != '/') {
- const char *q;
- int aliasoffset = fdt_path_offset(fdt, "/aliases");
-
- if (aliasoffset < 0)
- return -FDT_ERR_BADPATH;
+ const char *q = strchr(path, '/');
- q = strchr(path, '/');
if (!q)
q = end;
- p = fdt_getprop_namelen(fdt, aliasoffset, path, q - p, NULL);
+ p = fdt_get_alias_namelen(fdt, p, q - p);
if (!p)
return -FDT_ERR_BADPATH;
offset = fdt_path_offset(fdt, p);
@@ -306,6 +301,23 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
return fdt32_to_cpu(*php);
}
+const char *fdt_get_alias_namelen(const void *fdt,
+ const char *name, int namelen)
+{
+ int aliasoffset;
+
+ aliasoffset = fdt_path_offset(fdt, "/aliases");
+ if (aliasoffset < 0)
+ return NULL;
+
+ return fdt_getprop_namelen(fdt, aliasoffset, name, namelen, NULL);
+}
+
+const char *fdt_get_alias(const void *fdt, const char *name)
+{
+ return fdt_get_alias_namelen(fdt, name, strlen(name));
+}
+
int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen)
{
int pdepth = 0, p = 0;
--
1.5.6.5
^ permalink raw reply related [flat|nested] 5+ messages in thread* [U-Boot] [PATCH] libfdt: Add function to explicitly expand aliases
2008-10-02 23:05 [U-Boot] [PATCH] libfdt: Add function to explicitly expand aliases Jerry Van Baren
@ 2008-10-03 20:00 ` Petri Lehtinen
2008-10-03 20:09 ` Jon Loeliger
0 siblings, 1 reply; 5+ messages in thread
From: Petri Lehtinen @ 2008-10-03 20:00 UTC (permalink / raw)
To: u-boot
On Thu, Oct 02, 2008 at 07:05:53PM -0400, Jerry Van Baren wrote:
[snip]
> diff --git a/include/libfdt.h b/include/libfdt.h
> index 5492a53..7cad68c 100644
> --- a/include/libfdt.h
> +++ b/include/libfdt.h
> @@ -459,6 +459,32 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
> uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
>
> /**
> + * fdt_get_namelen - get alias based on substring
===^^^^^^^^^^^^^^^===
> + * @fdt: pointer to the device tree blob
> + * @name: name of the alias th look up
> + * @namelen: number of characters of name to consider
> + *
> + * Identical to fdt_get_alias(), but only examine the first namelen
> + * characters of name for matching the alias name.
> + */
> +const char *fdt_get_alias_namelen(const void *fdt,
> + const char *name, int namelen);
> +
This should be fdt_get_alias_namelen, right?
Petri
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] libfdt: Add function to explicitly expand aliases
2008-10-03 20:00 ` Petri Lehtinen
@ 2008-10-03 20:09 ` Jon Loeliger
2008-10-04 2:42 ` David Gibson
2008-10-04 4:49 ` David Gibson
0 siblings, 2 replies; 5+ messages in thread
From: Jon Loeliger @ 2008-10-03 20:09 UTC (permalink / raw)
To: u-boot
Petri Lehtinen wrote:
> On Thu, Oct 02, 2008 at 07:05:53PM -0400, Jerry Van Baren wrote:
> [snip]
>> diff --git a/include/libfdt.h b/include/libfdt.h
>> index 5492a53..7cad68c 100644
>> --- a/include/libfdt.h
>> +++ b/include/libfdt.h
>> @@ -459,6 +459,32 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
>> uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
>>
>> /**
>> + * fdt_get_namelen - get alias based on substring
> ===^^^^^^^^^^^^^^^===
>> + * @fdt: pointer to the device tree blob
>> + * @name: name of the alias th look up
>> + * @namelen: number of characters of name to consider
>> + *
>> + * Identical to fdt_get_alias(), but only examine the first namelen
>> + * characters of name for matching the alias name.
>> + */
>> +const char *fdt_get_alias_namelen(const void *fdt,
>> + const char *name, int namelen);
>> +
>
> This should be fdt_get_alias_namelen, right?
>
It does look that way....
This patch has already been applied upstream,
so correcting patches on top of this are welcome.
Thanks,
jdl
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] libfdt: Add function to explicitly expand aliases
2008-10-03 20:09 ` Jon Loeliger
@ 2008-10-04 2:42 ` David Gibson
2008-10-04 4:49 ` David Gibson
1 sibling, 0 replies; 5+ messages in thread
From: David Gibson @ 2008-10-04 2:42 UTC (permalink / raw)
To: u-boot
On Fri, Oct 03, 2008 at 03:09:06PM -0500, Jon Loeliger wrote:
> Petri Lehtinen wrote:
>> On Thu, Oct 02, 2008 at 07:05:53PM -0400, Jerry Van Baren wrote:
>> [snip]
>>> diff --git a/include/libfdt.h b/include/libfdt.h
>>> index 5492a53..7cad68c 100644
>>> --- a/include/libfdt.h
>>> +++ b/include/libfdt.h
>>> @@ -459,6 +459,32 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
>>> uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
>>> /**
>>> + * fdt_get_namelen - get alias based on substring
>> ===^^^^^^^^^^^^^^^===
>>> + * @fdt: pointer to the device tree blob
>>> + * @name: name of the alias th look up
>>> + * @namelen: number of characters of name to consider
>>> + *
>>> + * Identical to fdt_get_alias(), but only examine the first namelen
>>> + * characters of name for matching the alias name.
>>> + */
>>> +const char *fdt_get_alias_namelen(const void *fdt,
>>> + const char *name, int namelen);
>>> +
>>
>> This should be fdt_get_alias_namelen, right?
>>
>
> It does look that way....
>
> This patch has already been applied upstream,
> so correcting patches on top of this are welcome.
Crap, sorry. I'll send a fixup patch if none of you gets to it first.
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH] libfdt: Add function to explicitly expand aliases
2008-10-03 20:09 ` Jon Loeliger
2008-10-04 2:42 ` David Gibson
@ 2008-10-04 4:49 ` David Gibson
1 sibling, 0 replies; 5+ messages in thread
From: David Gibson @ 2008-10-04 4:49 UTC (permalink / raw)
To: u-boot
On Fri, Oct 03, 2008 at 03:09:06PM -0500, Jon Loeliger wrote:
> Petri Lehtinen wrote:
>> On Thu, Oct 02, 2008 at 07:05:53PM -0400, Jerry Van Baren wrote:
>> [snip]
>>> diff --git a/include/libfdt.h b/include/libfdt.h
>>> index 5492a53..7cad68c 100644
>>> --- a/include/libfdt.h
>>> +++ b/include/libfdt.h
>>> @@ -459,6 +459,32 @@ static inline void *fdt_getprop_w(void *fdt, int nodeoffset,
>>> uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
>>> /**
>>> + * fdt_get_namelen - get alias based on substring
>> ===^^^^^^^^^^^^^^^===
>>> + * @fdt: pointer to the device tree blob
>>> + * @name: name of the alias th look up
>>> + * @namelen: number of characters of name to consider
>>> + *
>>> + * Identical to fdt_get_alias(), but only examine the first namelen
>>> + * characters of name for matching the alias name.
>>> + */
>>> +const char *fdt_get_alias_namelen(const void *fdt,
>>> + const char *name, int namelen);
>>> +
>>
>> This should be fdt_get_alias_namelen, right?
>
> It does look that way....
>
> This patch has already been applied upstream,
> so correcting patches on top of this are welcome.
libfdt: Fix error in documentation for fdt_get_alias_namelen()
Oops, screwed up the function name in the documenting comment for this
function. Trivial correction in this patch.
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Index: dtc/libfdt/libfdt.h
===================================================================
--- dtc.orig/libfdt/libfdt.h 2008-10-04 14:46:50.000000000 +1000
+++ dtc/libfdt/libfdt.h 2008-10-04 14:46:56.000000000 +1000
@@ -459,7 +459,7 @@ static inline void *fdt_getprop_w(void *
uint32_t fdt_get_phandle(const void *fdt, int nodeoffset);
/**
- * fdt_get_namelen - get alias based on substring
+ * fdt_get_alias_namelen - get alias based on substring
* @fdt: pointer to the device tree blob
* @name: name of the alias th look up
* @namelen: number of characters of name to consider
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-10-04 4:49 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-02 23:05 [U-Boot] [PATCH] libfdt: Add function to explicitly expand aliases Jerry Van Baren
2008-10-03 20:00 ` Petri Lehtinen
2008-10-03 20:09 ` Jon Loeliger
2008-10-04 2:42 ` David Gibson
2008-10-04 4:49 ` David Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox