Skip to content

Commit 4e52998

Browse files
committed
dtmerge: Support literal assignments of path strings
The dtc compiler expands &node1 (as opposed to <&node1>) to the full path to the node with the label "node1". Note that if this label is on a node in an overlay that the path will reflect that, even if the node with the label eventually ends up in the base dtb. If a parameter of a base dtb is used to make an alias point to another node in the base dtb, it is nice to be able to specify that replacement path using a label on that node, rather than have to write it out longhand. Doing so requires one simple change - treating literal assignments of empty strings as a special case: console_uart0 = <&aliases>, "console=", &uart0; Prior to this commit, this would have resulted in an error when the console_uart0 was applied because the start of the &uart0 path string would have been interpreted as a phandle to the next override target. With this commit, the parser sees the empty string assigment and treats the next thing as a string to assign (rather like assigning a phandle value to an integer property). A consequence of this change is that intentionally assigning an empty string (probably a very rare occurence) requires an explicit empty string to be added, i.e. "...=","" or that the empty assignment falls at the end of the list of overrides for that parameter.
1 parent d43fef7 commit 4e52998

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

dtmerge/dtoverlay.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2047,6 +2047,47 @@ static int dtoverlay_extract_override(const char *override_name,
20472047
literal_value[0])
20482048
{
20492049
/* String */
2050+
if (type == DTOVERRIDE_STRING && !literal_value[0])
2051+
{
2052+
/* The empty string is a special case indicating that the literal
2053+
* string follows the NUL. This could appear as
2054+
* "foo=","bar";
2055+
* but the expecged use case is to support label paths:
2056+
* "console=",&uart1;
2057+
* which dtc will expand to something like:
2058+
* "console=","/soc/serial@7e215040";
2059+
* Note that the corollary of this is that assigning an empty
2060+
* string (not a likely scenario, and not one encountered at the
2061+
* time of writing) requires an empty string to appear
2062+
* immediately afterwards:
2063+
* <&aliases>,"console=","",<&node>,"other:0";
2064+
* or that the empty string assignment is at the end:
2065+
* <&aliases>,"console=";
2066+
* although the same effect can be achieved with:
2067+
* <&aliases>,"console[=00";
2068+
*/
2069+
len = data_end - data;
2070+
if (!len)
2071+
{
2072+
/* end-of-property case - treat as an empty string */
2073+
literal_value = data - 1;
2074+
override_len = 1;
2075+
}
2076+
else
2077+
{
2078+
override_end = memchr(data, 0, len);
2079+
if (!override_end)
2080+
{
2081+
dtoverlay_error(" override %s: string is not NUL-terminated",
2082+
override_name);
2083+
return -FDT_ERR_BADSTRUCTURE;
2084+
}
2085+
2086+
literal_value = data;
2087+
data = override_end + 1;
2088+
}
2089+
*datap = data;
2090+
}
20502091
strcpy(override_value, literal_value);
20512092
}
20522093
else

0 commit comments

Comments
 (0)