dtc: Make -I dtb mode use fill_fullpaths()

At present -I dts and -I fs modes both use the fill_fullpaths() helper
function to fill in the fullpath and basenamelen fields of struct
node, which are useful in later parts of the code.  -I dtb mode,
however, fills these in itself.

This patch simplifies flattree.c by making -I dtb mode use
fill_fullpaths() like the others.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2008-02-29 16:51:28 +11:00 committed by Jon Loeliger
parent 5ac97df149
commit b2de518b80
5 changed files with 18 additions and 45 deletions

3
dtc.c
View file

@ -55,7 +55,7 @@ char *join_path(const char *path, const char *name)
return str; return str;
} }
void fill_fullpaths(struct node *tree, const char *prefix) static void fill_fullpaths(struct node *tree, const char *prefix)
{ {
struct node *child; struct node *child;
const char *unit; const char *unit;
@ -208,6 +208,7 @@ int main(int argc, char *argv[])
if (! bi || ! bi->dt || bi->error) if (! bi || ! bi->dt || bi->error)
die("Couldn't read input tree\n"); die("Couldn't read input tree\n");
fill_fullpaths(bi->dt, "");
process_checks(force, bi); process_checks(force, bi);
if (streq(outname, "-")) { if (streq(outname, "-")) {

1
dtc.h
View file

@ -264,6 +264,5 @@ struct boot_info *dt_from_fs(const char *dirname);
/* misc */ /* misc */
char *join_path(const char *path, const char *name); char *join_path(const char *path, const char *name);
void fill_fullpaths(struct node *tree, const char *prefix);
#endif /* _DTC_H */ #endif /* _DTC_H */

View file

@ -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) static char *nodename_from_path(const char *ppath, const char *cpath)
{ {
const char *lslash;
int plen; int plen;
lslash = strrchr(cpath, '/'); plen = strlen(ppath);
if (! lslash)
return NULL;
plen = lslash - cpath;
if (streq(cpath, "/") && streq(ppath, ""))
return "";
if ((plen == 0) && streq(ppath, "/"))
return strdup(lslash+1);
if (!strneq(ppath, cpath, plen)) if (!strneq(ppath, cpath, plen))
return NULL; die("Path \"%s\" is not valid as a child of \"%s\"\n",
cpath, ppath);
return strdup(lslash+1); /* root node is a special case */
} if (!streq(ppath, "/"))
plen++;
static int find_basenamelen(const char *name) return strdup(cpath + plen);
{
const char *atpos = strchr(name, '@');
if (atpos)
return atpos - name;
else
return strlen(name);
} }
static struct node *unflatten_tree(struct inbuf *dtbuf, static struct node *unflatten_tree(struct inbuf *dtbuf,
struct inbuf *strbuf, struct inbuf *strbuf,
const char *parent_path, int flags) const char *parent_flatname, int flags)
{ {
struct node *node; struct node *node;
char *flatname;
u32 val; u32 val;
node = build_node(NULL, NULL); node = build_node(NULL, NULL);
if (flags & FTF_FULLPATH) { flatname = flat_read_string(dtbuf);
node->fullpath = flat_read_string(dtbuf);
node->name = nodename_from_path(parent_path, node->fullpath);
if (! node->name) if (flags & FTF_FULLPATH)
die("Path \"%s\" is not valid as a child of \"%s\"\n", node->name = nodename_from_path(parent_flatname, flatname);
node->fullpath, parent_path); else
} else { node->name = flatname;
node->name = flat_read_string(dtbuf);
node->fullpath = join_path(parent_path, node->name);
}
node->basenamelen = find_basenamelen(node->name);
do { do {
struct property *prop; struct property *prop;
@ -773,8 +751,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
break; break;
case FDT_BEGIN_NODE: case FDT_BEGIN_NODE:
child = unflatten_tree(dtbuf,strbuf, node->fullpath, child = unflatten_tree(dtbuf,strbuf, flatname, flags);
flags);
add_child(node, child); add_child(node, child);
break; break;

View file

@ -87,8 +87,6 @@ struct boot_info *dt_from_fs(const char *dirname)
tree = read_fstree(dirname); tree = read_fstree(dirname);
tree = name_node(tree, "", NULL); tree = name_node(tree, "", NULL);
fill_fullpaths(tree, "");
return build_boot_info(NULL, tree); return build_boot_info(NULL, tree);
} }

View file

@ -37,8 +37,6 @@ struct boot_info *dt_from_source(const char *fname)
if (yyparse() != 0) if (yyparse() != 0)
return NULL; return NULL;
fill_fullpaths(the_boot_info->dt, "");
the_boot_info->error = treesource_error; the_boot_info->error = treesource_error;
return the_boot_info; return the_boot_info;
} }