dtc: Implement checks for the format of node and property names

This patch adds checks to the checking framework to verify that node
and property names contain only legal characters, and in the case of
node names there is at most one '@'.

At present when coming from dts input, this is mostly already ensured
by the grammer, however putting the check later means its easier to
generate helpful error messages rather than just "syntax error".  For
dtb input, these checks replace the older similar check built into
flattree.c.

Testcases for the checks are also implemented.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2008-02-27 13:45:13 +11:00 committed by Jon Loeliger
parent 7c635dcb2f
commit fa5b520ccb
6 changed files with 97 additions and 23 deletions

View file

@ -729,29 +729,14 @@ static char *nodename_from_path(const char *ppath, const char *cpath)
return strdup(lslash+1);
}
static const char PROPCHAR[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,._+*#?-";
static const char UNITCHAR[] = "0123456789abcdef,";
static int check_node_name(const char *name)
static int find_basenamelen(const char *name)
{
const char *atpos;
int basenamelen;
atpos = strrchr(name, '@');
const char *atpos = strchr(name, '@');
if (atpos)
basenamelen = atpos - name;
return atpos - name;
else
basenamelen = strlen(name);
if (strspn(name, PROPCHAR) < basenamelen)
return -1;
if (atpos
&& ((basenamelen + 1 + strspn(atpos+1, UNITCHAR)) < strlen(name)))
return -1;
return basenamelen;
return strlen(name);
}
static struct node *unflatten_tree(struct inbuf *dtbuf,
@ -775,10 +760,7 @@ static struct node *unflatten_tree(struct inbuf *dtbuf,
node->fullpath = join_path(parent_path, node->name);
}
node->basenamelen = check_node_name(node->name);
if (node->basenamelen < 0) {
fprintf(stderr, "Warning \"%s\" has incorrect format\n", node->name);
}
node->basenamelen = find_basenamelen(node->name);
do {
struct property *prop;