summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dtc.c3
-rw-r--r--dtc.h1
-rw-r--r--flattree.c55
-rw-r--r--fstree.c2
-rw-r--r--treesource.c2
5 files changed, 18 insertions, 45 deletions
diff --git a/dtc.c b/dtc.c
index c1814c1..90e1cce 100644
--- a/dtc.c
+++ b/dtc.c
@@ -55,7 +55,7 @@ char *join_path(const char *path, const char *name)
return str;
}
-void fill_fullpaths(struct node *tree, const char *prefix)
+static void fill_fullpaths(struct node *tree, const char *prefix)
{
struct node *child;
const char *unit;
@@ -208,6 +208,7 @@ int main(int argc, char *argv[])
if (! bi || ! bi->dt || bi->error)
die("Couldn't read input tree\n");
+ fill_fullpaths(bi->dt, "");
process_checks(force, bi);
if (streq(outname, "-")) {
diff --git a/dtc.h b/dtc.h
index cba9d28..dbff5e8 100644
--- a/dtc.h
+++ b/dtc.h
@@ -264,6 +264,5 @@ struct boot_info *dt_from_fs(const char *dirname);
/* misc */
char *join_path(const char *path, const char *name);
-void fill_fullpaths(struct node *tree, const char *prefix);
#endif /* _DTC_H */
diff --git a/flattree.c b/flattree.c
index 41cb740..8675857 100644
--- a/flattree.c
+++ b/flattree.c
@@ -704,59 +704,37 @@ static struct reserve_info *flat_read_mem_reserve(struct inbuf *inb)
static char *nodename_from_path(const char *ppath, const char *cpath)
{
- const char *lslash;
int plen;
- lslash = strrchr(cpath, '/');
- if (! lslash)
- return NULL;
+ plen = strlen(ppath);
- plen = lslash - cpath;
+ if (!strneq(ppath, cpath, plen))
+ die("Path \"%s\" is not valid as a child of \"%s\"\n",
+ cpath, ppath);
- if (streq(cpath, "/") && streq(ppath, ""))
- return "";
+ /* root node is a special case */
+ if (!streq(ppath, "/"))
+ plen++;
- if ((plen == 0) && streq(ppath, "/"))
- return strdup(lslash+1);
-
- if (! strneq(ppath, cpath, plen))
- return NULL;
-
- return strdup(lslash+1);
-}
-
-static int find_basenamelen(const char *name)
-{
- const char *atpos = strchr(name, '@');
-
- if (atpos)
- return atpos - name;
- else
- return strlen(name);
+ return strdup(cpath + plen);
}
static struct node *unflatten_tree(struct inbuf *dtbuf,
struct inbuf *strbuf,
- const char *parent_path, int flags)
+ const char *parent_flatname, int flags)
{
struct node *node;
+ char *flatname;
u32 val;
node = build_node(NULL, NULL);
- if (flags & FTF_FULLPATH) {
- node->fullpath = flat_read_string(dtbuf);
- node->name = nodename_from_path(parent_path, node->fullpath);
+ flatname = flat_read_string(dtbuf);
- if (! node->name)
- die("Path \"%s\" is not valid as a child of \"%s\"\n",
- node->fullpath, parent_path);
- } else {
- node->name = flat_read_string(dtbuf);
- node->fullpath = join_path(parent_path, node->name);
- }
-
- node->basenamelen = find_basenamelen(node->name);
+ if (flags & FTF_FULLPATH)
+ node->name = nodename_from_path(parent_flatname, flatname);
+ else
+ node->name = flatname;
do {
struct property *prop;
@@ -773,8 +751,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
break;
case FDT_BEGIN_NODE:
- child = unflatten_tree(dtbuf,strbuf, node->fullpath,
- flags);
+ child = unflatten_tree(dtbuf,strbuf, flatname, flags);
add_child(node, child);
break;
diff --git a/fstree.c b/fstree.c
index 2a160a4..2fc5773 100644
--- a/fstree.c
+++ b/fstree.c
@@ -87,8 +87,6 @@ struct boot_info *dt_from_fs(const char *dirname)
tree = read_fstree(dirname);
tree = name_node(tree, "", NULL);
- fill_fullpaths(tree, "");
-
return build_boot_info(NULL, tree);
}
diff --git a/treesource.c b/treesource.c
index 980bda7..9cbf0a9 100644
--- a/treesource.c
+++ b/treesource.c
@@ -37,8 +37,6 @@ struct boot_info *dt_from_source(const char *fname)
if (yyparse() != 0)
return NULL;
- fill_fullpaths(the_boot_info->dt, "");
-
the_boot_info->error = treesource_error;
return the_boot_info;
}