dtc: Disable semantic checks by default
At present, dtc makes a lot of semantic checks on the device tree by default, and will refuse to produce output if they fail. This means people tend to need -f to force output despite failing semantic checks rather a lot.
This patch splits the device tree checks into structural checks (no bad or duplicate names or phandles) and semantic checks (everything else). By default, only the structural checks are performed, and are fatal. -f will force output even with structural errors (using this in -Idts mode would essentially always be a bad idea, but it might be useful in -Idtb mode for examining a malformed dtb).
Semantic checks are only performed if the new -c command line option is supplied, and are always warnings only. Semantic checks will never be performed on a tree with structural errors.
This patch is only a stopgap before implementing proper fine-grained error/warning handling, but it should at least get rid of the far-too-frequent need for -f for the time being.
This patch removes the -f from the dtc testcases now that it's no longer necessary.
dtc.c +24 -7
@@ -112,19 +112,20 @@char *inform ="dts" ;char *outform ="dts" ;char *outname ="-" ; -int force =0 ; +int force =0 , check =0 ;char *arg;int opt;FILE *inf =NULL ;FILE *outf =NULL ;int outversion =DEFAULT_FDT_VERSION ;int boot_cpuid_phys =0xfeedbeef ; +int structure_ok; quiet =0 ; reservenum =0 ; minsize =0 ; -while ((opt =getopt (argc, argv,"hI:O:o:V:R:S:fqb:v" )) !=EOF ) { +while ((opt =getopt (argc, argv,"hI:O:o:V:R:S:fcqb:v" )) !=EOF ) {switch (opt) {case 'I' : inform = optarg;
@@ -147,6 +148,9 @@case 'f' : force =1 ;break ; +case 'c' : + check =1 ; +break ;case 'q' : quiet++;break ;
@@ -189,12 +193,25 @@if (! bi || ! bi->dt)die ("Couldn't read input tree\n" ); -if (!check_device_tree (bi->dt, outversion, boot_cpuid_phys)) { -if ((force) && (quiet <3 )) -fprintf (stderr,"Input tree has errors, output forced\n" ); -if (! force) { -fprintf (stderr,"Input tree has errors, not writing output (use -f to force output)\n" ); + structure_ok =check_structure (bi->dt); +if (!structure_ok) { +if (!force) { +fprintf (stderr,"ERROR: Input tree has structural errors, aborting (use -f to force output)\n" );exit (1 ); + }else if (quiet <3 ) { +fprintf (stderr,"Warning: Input tree has structural errors, output forced\n" ); + } + } + +fixup_references (bi->dt); + +if (check) { +if (!structure_ok) { +fprintf (stderr,"Warning: Skipping semantic checks due to structural errors\n" ); + }else { +if (!check_semantics (bi->dt, outversion, + boot_cpuid_phys)) +fprintf (stderr,"Warning: Input tree has semantic errors\n" ); } }
dtc.h +4 -0
@@ -188,6 +188,10 @@void add_property (struct node *node,struct property *prop);void add_child (struct node *parent,struct node *child); +int check_structure (struct node *dt); +void fixup_references (struct node *dt); +int check_semantics (struct node *dt,int outversion,int boot_cpuid_phys); +int check_device_tree (struct node *dt,int outversion,int boot_cpuid_phys);/* Boot info (tree plus memreserve information */
livetree.c +187 -183
418 lines not on this page · raw message
tests/run_tests.sh +2 -2
@@ -101,11 +101,11 @@ } dtc_tests () { - run_test dtc.sh -f -I dts -O dtb -o dtc_tree1.test.dtb test_tree1.dts + run_test dtc.sh -I dts -O dtb -o dtc_tree1.test.dtb test_tree1.dts tree1_tests dtc_tree1.test.dtb tree1_tests_rw dtc_tree1.test.dtb - run_test dtc.sh -f -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts + run_test dtc.sh -I dts -O dtb -o dtc_escapes.test.dtb escapes.dts run_test string_escapes dtc_escapes.test.dtb }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Jon Loeliger
AppliedSo, like, the other day David Gibson mumbled:
Quoted 16 lines
At present, dtc makes a lot of semantic checks on the device tree by default, and will refuse to produce output if they fail. This means people tend to need -f to force output despite failing semantic checks rather a lot.
This patch splits the device tree checks into structural checks (no bad or duplicate names or phandles) and semantic checks (everything else). By default, only the structural checks are performed, and are fatal. -f will force output even with structural errors (using this in -Idts mode would essentially always be a bad idea, but it might be useful in -Idtb mode for examining a malformed dtb).
Semantic checks are only performed if the new -c command line option is supplied, and are always warnings only. Semantic checks will never be performed on a tree with structural errors.
Quoted 8 lines
This patch is only a stopgap before implementing proper fine-grained error/warning handling, but it should at least get rid of the far-too-frequent need for -f for the time being.
This patch removes the -f from the dtc testcases now that it's no longer necessary.
Signed-off-by David Gibson <[email protected]>
Applied.
jdl