diff options
author | Scott Wood <scottwood@freescale.com> | 2007-09-05 15:21:12 -0400 |
---|---|---|
committer | Paul Mackerras <paulus@samba.org> | 2007-09-13 11:33:23 -0400 |
commit | 21f3fe2f7ab57832ea1fc7f719ec7e167b7ad80e (patch) | |
tree | 5a3bf3c623fb858d61ca7effd9b1f8bd8b5e714f /arch/powerpc/boot/flatdevtree.c | |
parent | 9de782770b84768e1aa2e6454223ef30768de84e (diff) |
[POWERPC] bootwrapper: Add get_path()
This will be used by the PlanetCore firmware support to construct
a linux,stdout-path from the serial node that it finds.
Signed-off-by: Scott Wood <scottwood@freescale.com>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch/powerpc/boot/flatdevtree.c')
-rw-r--r-- | arch/powerpc/boot/flatdevtree.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/arch/powerpc/boot/flatdevtree.c b/arch/powerpc/boot/flatdevtree.c index 0af7291fc67c..cf30675c6116 100644 --- a/arch/powerpc/boot/flatdevtree.c +++ b/arch/powerpc/boot/flatdevtree.c | |||
@@ -975,3 +975,62 @@ void *ft_create_node(struct ft_cxt *cxt, const void *parent, const char *name) | |||
975 | } | 975 | } |
976 | return NULL; | 976 | return NULL; |
977 | } | 977 | } |
978 | |||
979 | /* Returns the start of the path within the provided buffer, or NULL on | ||
980 | * error. | ||
981 | */ | ||
982 | char *ft_get_path(struct ft_cxt *cxt, const void *phandle, | ||
983 | char *buf, int len) | ||
984 | { | ||
985 | const char *path_comp[FT_MAX_DEPTH]; | ||
986 | struct ft_atom atom; | ||
987 | char *p, *next, *pos; | ||
988 | int depth = 0, i; | ||
989 | void *node; | ||
990 | |||
991 | node = ft_node_ph2node(cxt, phandle); | ||
992 | if (node == NULL) | ||
993 | return NULL; | ||
994 | |||
995 | p = ft_root_node(cxt); | ||
996 | |||
997 | while ((next = ft_next(cxt, p, &atom)) != NULL) { | ||
998 | switch (atom.tag) { | ||
999 | case OF_DT_BEGIN_NODE: | ||
1000 | path_comp[depth++] = atom.name; | ||
1001 | if (p == node) | ||
1002 | goto found; | ||
1003 | |||
1004 | break; | ||
1005 | |||
1006 | case OF_DT_END_NODE: | ||
1007 | if (--depth == 0) | ||
1008 | return NULL; | ||
1009 | } | ||
1010 | |||
1011 | p = next; | ||
1012 | } | ||
1013 | |||
1014 | found: | ||
1015 | pos = buf; | ||
1016 | for (i = 1; i < depth; i++) { | ||
1017 | int this_len; | ||
1018 | |||
1019 | if (len <= 1) | ||
1020 | return NULL; | ||
1021 | |||
1022 | *pos++ = '/'; | ||
1023 | len--; | ||
1024 | |||
1025 | strncpy(pos, path_comp[i], len); | ||
1026 | |||
1027 | if (pos[len - 1] != 0) | ||
1028 | return NULL; | ||
1029 | |||
1030 | this_len = strlen(pos); | ||
1031 | len -= this_len; | ||
1032 | pos += this_len; | ||
1033 | } | ||
1034 | |||
1035 | return buf; | ||
1036 | } | ||