dtc: cpp co-existence: allow names starting with # to be escaped
The device tree language as currently defined conflicts with the C pre- processor in one aspect - when a property or node name begins with a # character, a pre-processor would attempt to interpret it as a directive, fail, and most likely error out. This change allows a property/node name to be prefixed with \. This prevents a pre-processor from seeing # as the first non-whitespace character on the line, and hence prevents the conflict. \ was previously an illegal character in property/node names, so this change is backwards compatible. The \ is stripped from the name during parsing by dtc. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: David Gibson <david@gibson.dropbear.id.au>main
parent
45013d8619
commit
1ff3d3f8de
|
@ -162,9 +162,10 @@ static int pop_input_file(void);
|
||||||
return ']';
|
return ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
<PROPNODENAME>{PROPNODECHAR}+ {
|
<PROPNODENAME>\\?{PROPNODECHAR}+ {
|
||||||
DPRINT("PropNodeName: %s\n", yytext);
|
DPRINT("PropNodeName: %s\n", yytext);
|
||||||
yylval.propnodename = xstrdup(yytext);
|
yylval.propnodename = xstrdup((yytext[0] == '\\') ?
|
||||||
|
yytext + 1 : yytext);
|
||||||
BEGIN_DEFAULT();
|
BEGIN_DEFAULT();
|
||||||
return DT_PROPNODENAME;
|
return DT_PROPNODENAME;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ tmp.*
|
||||||
/path_offset
|
/path_offset
|
||||||
/path_offset_aliases
|
/path_offset_aliases
|
||||||
/phandle_format
|
/phandle_format
|
||||||
|
/propname_escapes
|
||||||
/references
|
/references
|
||||||
/root_node
|
/root_node
|
||||||
/rw_tree1
|
/rw_tree1
|
||||||
|
|
|
@ -12,7 +12,7 @@ LIB_TESTS_L = get_mem_rsv \
|
||||||
sw_tree1 \
|
sw_tree1 \
|
||||||
move_and_save mangle-layout nopulate \
|
move_and_save mangle-layout nopulate \
|
||||||
open_pack rw_tree1 set_name setprop del_property del_node \
|
open_pack rw_tree1 set_name setprop del_property del_node \
|
||||||
appendprop1 appendprop2 \
|
appendprop1 appendprop2 propname_escapes \
|
||||||
string_escapes references path-references phandle_format \
|
string_escapes references path-references phandle_format \
|
||||||
boot-cpuid incbin \
|
boot-cpuid incbin \
|
||||||
extra-terminating-null \
|
extra-terminating-null \
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* libfdt - Flat Device Tree manipulation
|
||||||
|
* Testcase for fdt_getprop()
|
||||||
|
* Copyright (C) 2006 David Gibson, IBM Corporation.
|
||||||
|
* Copyright (C) 2012 NVIDIA CORPORATION. All rights reserved.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public License
|
||||||
|
* as published by the Free Software Foundation; either version 2.1 of
|
||||||
|
* the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <fdt.h>
|
||||||
|
#include <libfdt.h>
|
||||||
|
|
||||||
|
#include "tests.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
void *fdt;
|
||||||
|
|
||||||
|
test_init(argc, argv);
|
||||||
|
fdt = load_blob_arg(argc, argv);
|
||||||
|
|
||||||
|
check_getprop_cell(fdt, 0, "#address-cells", 1);
|
||||||
|
check_getprop_cell(fdt, 0, "#gpio-cells", 2);
|
||||||
|
|
||||||
|
PASS();
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
/dts-v1/;
|
||||||
|
|
||||||
|
/ {
|
||||||
|
#address-cells = <1>;
|
||||||
|
\#gpio-cells = <2>;
|
||||||
|
};
|
|
@ -254,6 +254,9 @@ dtc_tests () {
|
||||||
tree1_tests_rw dtc_tree1.test.dtb
|
tree1_tests_rw dtc_tree1.test.dtb
|
||||||
run_test dtbs_equal_ordered dtc_tree1.test.dtb test_tree1.dtb
|
run_test dtbs_equal_ordered dtc_tree1.test.dtb test_tree1.dtb
|
||||||
|
|
||||||
|
run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb propname_escapes.dts
|
||||||
|
run_test propname_escapes dtc_escapes.test.dtb
|
||||||
|
|
||||||
run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts
|
run_dtc_test -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts
|
||||||
run_test string_escapes dtc_escapes.test.dtb
|
run_test string_escapes dtc_escapes.test.dtb
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue