libfdt: a fix but still broken
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both tree.S and jdl's dtc). I have not started on that layer of the onion yet.
Best regards,
gvb
$ git diff fdt.h
fdt.h +1 -1
@@ -36,8 +36,8 @@ struct fdt_node_header {struct fdt_property {uint32_t tag; -uint32_t nameoff;uint32_t len; +uint32_t nameoff;char data[0 ]; };
$ git diff tests/trees.S
tests/trees.S +2 -2
@@ -39,8 +39,8 @@ tree: \ #define PROPHDR(tree, name, len) \ FDTLONG(FDT_PROP) ; \ - FDTLONG(tree##_##name - tree##_strings) ; \ - FDTLONG(len) ; + FDTLONG(len) ; \ + FDTLONG(tree##_##name - tree##_strings) ; #define PROP_INT(tree, name, val) \ PROPHDR(tree, name, 4) \
______________________________________________________________________
CAUTION: This message was sent via the Public Internet and its authenticity cannot be guaranteed.
______________________________________________________
Quoted 6 lines · Jerry Van Baren
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
Ouch. That's.. a very embarrassing bug. Actually, I know where it came from: I was looking at flat_dt.h from dtc, which also gets this wrong (but the declaration in question is unused). Of course, I also wrote flat_dt.h ...
Quoted 3 lines
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both
tree.Sand jdl's dtc). I have not started on that layer of the onion yet.
Found it, there was a direct use of the position of the length in _fdt_next_tag(). Just pushed out a fix for this in the libfdt tree, along with some other small fixes which I found while tracking this one down.
Oh, incidentally, I applied your patch by eye rather than with patch(1), which was handy, because it appears to have been whitespace damaged.
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
Quoted 12 lines · David Gibson
Quoted 3 lines · Jerry Van Baren
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
Ouch. That's.. a very embarrassing bug. Actually, I know where it came from: I was looking at
flat_dt.hfrom dtc, which also gets this wrong (but the declaration in question is unused). Of course, I also wroteflat_dt.h...Quoted 1 line
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both
tree.Sand jdl's dtc). I have not started on that layer of the onion yet.
Quoted 8 lines
Found it, there was a direct use of the position of the length in
_fdt_next_tag(). Just pushed out a fix for this in the libfdt tree, along with some other small fixes which I found while tracking this one down.Oh, incidentally, I applied your patch by eye rather than with patch(1), which was handy, because it appears to have been whitespace damaged.
Hi David,
Sorry about the whitespace, I actually generated it at home, emailed it to my day job, and edited and forwarded it from there (I'm not subscribed at home - probably should be).
It sounds like we found and fixed the same bug last night.
I went quite a bit further (before finding and fixing the real bug). I was looking at the *_type "function like" #defines that generate a temporary variable of indeterminate (until compile time) type. An example:
#define fdt_setprop_inplace_typed(fdt, nodeoffset, name, val) \
({ \
typeof(val) x = val; \
fdt_setprop_inplace(fdt, nodeoffset, name, &x, sizeof(x)); \
})IMHO this is borderline evil and unnecessary, and I removed all of them by replacing the call of the *_type macros with the equivalent actual function. What I was suspicious of is when I changed all the calls to use proper endian by calling cpu_to_fdt32(), the parameter "val" is no longer a simple constant or variable but is, instead, a function call or macro or nothing at all, depending on the host endian and compiler implementation. It turns out that this apparently wasn't a problem, but I'm still of the opinion that those #defines have minimal value and makes the code baroque. ;-)
I've attached a patch file that shouldn't be whitespace damaged this time. :-/ I can also make my git repository accessible if that is helpful.
Best regards,
gvb
Tests are working again. Most tests work with dtc, but a couple of
tests fail with the dtc-generated blob due to the version being 16 instead of 17.
--- fdt.c | 2 +- fdt_ro.c | 4 ++-- libfdt.h | 23 ----------------------- tests/del_node.c | 16 +++++++++++----- tests/del_property.c | 4 +++- tests/find_property.c | 4 +++- tests/getprop.c | 4 +++- tests/nop_node.c | 16 +++++++++++----- tests/nop_property.c | 4 +++- tests/path_offset.c | 2 +- tests/root_node.c | 2 +- tests/rw_tree1.c | 18 ++++++++++++------ tests/setprop.c | 8 +++++--- tests/setprop_inplace.c | 11 ++++++++--- tests/subnode_offset.c | 17 ++++++++++++----- tests/sw_tree1.c | 18 ++++++++++++------ tests/test_tree1.dts | 12 ++++++------ tests/tests.h | 13 ------------- 18 files changed, 94 insertions(+), 84 deletions(-)
fdt.c +1 -1
@@ -83,7 +83,7 @@ uint32_t _fdt_next_tag(const void *fdt, int offset, int *nextoffset)return FDT_END ;break ;case FDT_PROP : - lenp =fdt_offset_ptr (fdt, offset +FDT_TAGSIZE ,sizeof (*lenp)); + lenp =fdt_offset_ptr (fdt, offset,sizeof (*lenp));if (! lenp)return FDT_END ;/* skip name offset, length and value */
fdt_ro.c +2 -2
@@ -226,7 +226,7 @@ struct fdt_property *fdt_get_property(const void *fdt,continue ; err = -FDT_ERR_BADSTRUCTURE ; - prop =fdt_offset_ptr_typed (fdt, offset, prop); + prop =fdt_offset_ptr (fdt, offset,sizeof (fdt_property));if (! prop) goto fail; namestroff =fdt32_to_cpu (prop->nameoff);
@@ -274,5 +274,5 @@ void *fdt_getprop(const void *fdt, int nodeoffset,if (! prop)return NULL ; -return prop->data; +return (void *)prop->data; }
libfdt.h +0 -23
@@ -62,9 +62,6 @@void *fdt_offset_ptr (const void *fdt,int offset,int checklen); -#define fdt_offset_ptr_typed (fdt, offset, var) \ - ((typeof(var))(fdt_offset_ptr((fdt), (offset), sizeof(*(var))))) -int fdt_move (const void *fdt,void *buf,int bufsize);/* Read-only functions */
@@ -85,12 +82,6 @@ void *fdt_getprop(const void *fdt, int nodeoffset,int fdt_setprop_inplace (void *fdt,int nodeoffset,const char *name,const void *val,int len); -#define fdt_setprop_inplace_typed (fdt, nodeoffset, name, val) \ - ({ \ - typeof(val) x = val; \ - fdt_setprop_inplace(fdt, nodeoffset, name, &x, sizeof(x)); \ - }) -int fdt_nop_property (void *fdt,int nodeoffset,const char *name);int fdt_nop_node (void *fdt,int nodeoffset);
@@ -100,13 +91,6 @@ int fdt_add_reservemap_entry(void *fdt, uint64_t addr, uint64_t size);int fdt_finish_reservemap (void *fdt);int fdt_begin_node (void *fdt,const char *name);int fdt_property (void *fdt,const char *name,const void *val,int len); -#define fdt_property_typed (fdt, name, val) \ - ({ \ - typeof(val) x = (val); \ - fdt_property((fdt), (name), &x, sizeof(x)); \ - }) -#define fdt_property_string (fdt, name, str) \ - fdt_property(fdt, name, str, strlen(str)+1)int fdt_end_node (void *fdt);int fdt_finish (void *fdt);
@@ -116,13 +100,6 @@ int fdt_pack(void *fdt);int fdt_setprop (void *fdt,int nodeoffset,const char *name,const void *val,int len); -#define fdt_setprop_typed (fdt, nodeoffset, name, val) \ - ({ \ - typeof(val) x = (val); \ - fdt_setprop((fdt), (nodeoffset), (name), &x, sizeof(x)); \ - }) -#define fdt_setprop_string (fdt, nodeoffset, name, str) \ - fdt_setprop((fdt), (nodeoffset), (name), (str), strlen(str)+1)int fdt_delprop (void *fdt,int nodeoffset,const char *name);int fdt_add_subnode_namelen (void *fdt,int parentoffset,const char *name,int namelen);
tests/del_node.c +11 -5
@@ -35,6 +35,7 @@ int main(int argc, char *argv[])int subnode1_offset, subnode2_offset, subsubnode2_offset;int err;int oldsize, delsize, newsize; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv);
@@ -45,19 +46,22 @@ int main(int argc, char *argv[])if (subnode1_offset <0 )FAIL ("Couldn't find \"/subnode1\": %s" ,fdt_strerror (subnode1_offset)); -check_getprop_typed (fdt, subnode1_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +check_getprop (fdt, subnode1_offset,"prop-int" ,sizeof (x), &x); subnode2_offset =fdt_path_offset (fdt,"/subnode2" );if (subnode2_offset <0 )FAIL ("Couldn't find \"/subnode2\": %s" ,fdt_strerror (subnode2_offset)); -check_getprop_typed (fdt, subnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_getprop (fdt, subnode2_offset,"prop-int" ,sizeof (x), &x); subsubnode2_offset =fdt_path_offset (fdt,"/subnode2/subsubnode" );if (subsubnode2_offset <0 )FAIL ("Couldn't find \"/subnode2/subsubnode\": %s" ,fdt_strerror (subsubnode2_offset)); -check_getprop_typed (fdt, subsubnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_getprop (fdt, subsubnode2_offset,"prop-int" ,sizeof (x), &x); err =fdt_del_node (fdt, subnode1_offset);if (err)
@@ -73,13 +77,15 @@ int main(int argc, char *argv[])if (subnode2_offset <0 )FAIL ("Couldn't find \"/subnode2\": %s" ,fdt_strerror (subnode2_offset)); -check_getprop_typed (fdt, subnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_getprop (fdt, subnode2_offset,"prop-int" ,sizeof (x), &x); subsubnode2_offset =fdt_path_offset (fdt,"/subnode2/subsubnode" );if (subsubnode2_offset <0 )FAIL ("Couldn't find \"/subnode2/subsubnode\": %s" ,fdt_strerror (subsubnode2_offset)); -check_getprop_typed (fdt, subsubnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_getprop (fdt, subsubnode2_offset,"prop-int" ,sizeof (x), &x); err =fdt_del_node (fdt, subnode2_offset);if (err)
tests/del_property.c +3 -1
@@ -36,13 +36,15 @@ int main(int argc, char *argv[])char *strp;int err, lenerr;int oldsize, delsize, newsize; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv); oldsize =fdt_totalsize (fdt); - intp =check_getprop_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); + intp =check_getprop (fdt,0 ,"prop-int" ,sizeof (x), &x);verbose_printf ("int value was 0x%08x\n" , *intp); err =fdt_delprop (fdt,0 ,"prop-int" );
tests/find_property.c +3 -1
@@ -30,11 +30,13 @@int main (int argc,char *argv[]) {void *fdt; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv); -check_property_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +check_property (fdt,0 ,"prop-int" ,sizeof (x), &x);check_property (fdt,0 ,"prop-str" ,strlen (TEST_STRING_1 )+1 ,TEST_STRING_1 );PASS ();
tests/getprop.c +3 -1
@@ -31,11 +31,13 @@int main (int argc,char *argv[]) {void *fdt; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv); -check_getprop_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +check_getprop (fdt,0 ,"prop-int" ,sizeof (x), &x);check_getprop (fdt,0 ,"prop-str" ,strlen (TEST_STRING_1 )+1 ,TEST_STRING_1 );PASS ();
tests/nop_node.c +11 -5
@@ -34,6 +34,7 @@ int main(int argc, char *argv[])void *fdt;int subnode1_offset, subnode2_offset, subsubnode2_offset;int err; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv);
@@ -42,19 +43,22 @@ int main(int argc, char *argv[])if (subnode1_offset <0 )FAIL ("Couldn't find \"/subnode1\": %s" ,fdt_strerror (subnode1_offset)); -check_getprop_typed (fdt, subnode1_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +check_getprop (fdt, subnode1_offset,"prop-int" ,sizeof (x), &x); subnode2_offset =fdt_path_offset (fdt,"/subnode2" );if (subnode2_offset <0 )FAIL ("Couldn't find \"/subnode2\": %s" ,fdt_strerror (subnode2_offset)); -check_getprop_typed (fdt, subnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_getprop (fdt, subnode2_offset,"prop-int" ,sizeof (x), &x); subsubnode2_offset =fdt_path_offset (fdt,"/subnode2/subsubnode" );if (subsubnode2_offset <0 )FAIL ("Couldn't find \"/subnode2/subsubnode\": %s" ,fdt_strerror (subsubnode2_offset)); -check_getprop_typed (fdt, subsubnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_getprop (fdt, subsubnode2_offset,"prop-int" ,sizeof (x), &x); err =fdt_nop_node (fdt, subnode1_offset);if (err)
@@ -70,13 +74,15 @@ int main(int argc, char *argv[])if (subnode2_offset <0 )FAIL ("Couldn't find \"/subnode2\": %s" ,fdt_strerror (subnode2_offset)); -check_getprop_typed (fdt, subnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_getprop (fdt, subnode2_offset,"prop-int" ,sizeof (x), &x); subsubnode2_offset =fdt_path_offset (fdt,"/subnode2/subsubnode" );if (subsubnode2_offset <0 )FAIL ("Couldn't find \"/subnode2/subsubnode\": %s" ,fdt_strerror (subsubnode2_offset)); -check_getprop_typed (fdt, subsubnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_getprop (fdt, subsubnode2_offset,"prop-int" ,sizeof (x), &x); err =fdt_nop_node (fdt, subnode2_offset);if (err)
tests/nop_property.c +3 -1
@@ -36,11 +36,13 @@ int main(int argc, char *argv[])char *strp;int err;int lenerr; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv); - intp =check_getprop_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); + intp =check_getprop (fdt,0 ,"prop-int" ,sizeof (x), &x);verbose_printf ("int value was 0x%08x\n" , *intp); err =fdt_nop_property (fdt,0 ,"prop-int" );
tests/path_offset.c +1 -1
@@ -38,7 +38,7 @@ int check_subnode(void *fdt, int parent, const char *name)verbose_printf ("offset %d..." , offset);if (offset <0 )FAIL ("fdt_subnode_offset(\"%s\"): %s" , name,fdt_strerror (offset)); - nh =fdt_offset_ptr_typed (fdt, offset, nh); + nh =fdt_offset_ptr (fdt, offset,sizeof (*nh));verbose_printf ("pointer %p\n" , nh);if (! nh)FAIL ("NULL retrieving subnode \"%s\"" , name);
tests/root_node.c +1 -1
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])test_init (argc, argv); fdt =load_blob_arg (argc, argv); - nh =fdt_offset_ptr_typed (fdt,0 , nh); + nh =fdt_offset_ptr (fdt,0 ,sizeof (*nh));if (! nh)FAIL ("NULL retrieving root node" );
tests/rw_tree1.c +12 -6
@@ -50,6 +50,7 @@ int main(int argc, char *argv[])void *fdt;int err;int offset; +uint32_t x;test_init (argc, argv);
@@ -68,19 +69,24 @@ int main(int argc, char *argv[])CHECK (fdt_open_into (fdt, fdt,SPACE )); -CHECK (fdt_setprop_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 ))); -CHECK (fdt_setprop_string (fdt,0 ,"prop-str" ,TEST_STRING_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +CHECK (fdt_setprop (fdt,0 ,"prop-int" , &x,sizeof (x))); +CHECK (fdt_setprop (fdt,0 ,"prop-str" ,TEST_STRING_1 ,strlen (TEST_STRING_1 )+1 ));OFF_CHECK (offset,fdt_add_subnode (fdt,0 ,"subnode1" )); -CHECK (fdt_setprop_typed (fdt, offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 ))); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +CHECK (fdt_setprop (fdt, offset,"prop-int" , &x,sizeof (x)));OFF_CHECK (offset,fdt_add_subnode (fdt, offset,"subsubnode" )); -CHECK (fdt_setprop_typed (fdt, offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 ))); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +CHECK (fdt_setprop (fdt, offset,"prop-int" , &x,sizeof (x)));OFF_CHECK (offset,fdt_add_subnode (fdt,0 ,"subnode2" )); -CHECK (fdt_setprop_typed (fdt, offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 ))); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +CHECK (fdt_setprop (fdt, offset,"prop-int" , &x,sizeof (x)));OFF_CHECK (offset,fdt_add_subnode (fdt, offset,"subsubnode" )); -CHECK (fdt_setprop_typed (fdt, offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 ))); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +CHECK (fdt_setprop (fdt, offset,"prop-int" , &x,sizeof (x)));CHECK (fdt_pack (fdt));
tests/setprop.c +5 -3
@@ -39,6 +39,7 @@ int main(int argc, char *argv[])uint32_t *intp;char *strp;int err; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv);
@@ -51,15 +52,16 @@ int main(int argc, char *argv[]) fdt = buf; - intp =check_getprop_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); + intp =check_getprop (fdt,0 ,"prop-int" ,sizeof (x), &x);verbose_printf ("Old int value was 0x%08x\n" , *intp); - err =fdt_setprop_string (fdt,0 ,"prop-int" ,NEW_STRING ); + err =fdt_setprop (fdt,0 ,"prop-int" ,NEW_STRING ,strlen (NEW_STRING )+1 );if (err)FAIL ("Failed to set \"prop-int\" to \"%s\": %s" ,NEW_STRING ,fdt_strerror (err)); - strp =check_getprop_string (fdt,0 ,"prop-int" ,NEW_STRING ); + strp =check_getprop (fdt,0 ,"prop-int" ,strlen (NEW_STRING )+1 ,NEW_STRING );verbose_printf ("New value is \"%s\"\n" , strp);
strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
tests/setprop_inplace.c +8 -3
@@ -36,18 +36,23 @@ int main(int argc, char *argv[])char *strp, *xstr;int xlen, i;int err; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv); - intp =check_getprop_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); + intp =check_getprop (fdt,0 ,"prop-int" ,sizeof (x), &x);verbose_printf ("Old int value was 0x%08x\n" , *intp); - err =fdt_setprop_inplace_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (~TEST_VALUE_1 )); + x =cpu_to_fdt32 (~TEST_VALUE_1 ); + err =fdt_setprop_inplace (fdt,0 ,"prop-int" , &x,sizeof (x)); +if (err)FAIL ("Failed to set \"prop-int\" to 0x08%x: %s" ,cpu_to_fdt32 (~TEST_VALUE_1 ),fdt_strerror (err)); - intp =check_getprop_typed (fdt,0 ,"prop-int" ,cpu_to_fdt32 (~TEST_VALUE_1 )); + x =cpu_to_fdt32 (~TEST_VALUE_1 ); + intp =check_getprop (fdt,0 ,"prop-int" ,sizeof (x), &x);verbose_printf ("New int value is 0x%08x\n" , *intp); strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
tests/subnode_offset.c +12 -5
@@ -38,7 +38,7 @@ int check_subnode(struct fdt_header *fdt, int parent, const char *name)verbose_printf ("offset %d..." , offset);if (offset <0 )FAIL ("fdt_subnode_offset(\"%s\"): %s" , name,fdt_strerror (offset)); - nh =fdt_offset_ptr_typed (fdt, offset, nh); + nh =fdt_offset_ptr (fdt, offset,sizeof (*nh));verbose_printf ("pointer %p\n" , nh);if (! nh)FAIL ("NULL retrieving subnode \"%s\"" , name);
@@ -59,6 +59,7 @@ int main(int argc, char *argv[])void *fdt;int subnode1_offset, subnode2_offset;int subsubnode1_offset, subsubnode2_offset; +uint32_t x;test_init (argc, argv); fdt =load_blob_arg (argc, argv);
@@ -69,14 +70,20 @@ int main(int argc, char *argv[])if (subnode1_offset == subnode2_offset)FAIL ("Different subnodes have same offset" ); -check_property_typed (fdt, subnode1_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); -check_property_typed (fdt, subnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +check_property (fdt, subnode1_offset,"prop-int" ,sizeof (x), &x); + + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_property (fdt, subnode2_offset,"prop-int" ,sizeof (x), &x); subsubnode1_offset =check_subnode (fdt, subnode1_offset,"subsubnode" ); subsubnode2_offset =check_subnode (fdt, subnode2_offset,"subsubnode" ); -check_property_typed (fdt, subsubnode1_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 )); -check_property_typed (fdt, subsubnode2_offset,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +check_property (fdt, subsubnode1_offset,"prop-int" ,sizeof (x), &x); + + x =cpu_to_fdt32 (TEST_VALUE_2 ); +check_property (fdt, subsubnode2_offset,"prop-int" ,sizeof (x), &x);PASS (); }
tests/sw_tree1.c +12 -6
@@ -42,6 +42,7 @@ int main(int argc, char *argv[]) {void *fdt;int err; +uint32_t x;test_init (argc, argv);
@@ -50,20 +51,25 @@ int main(int argc, char *argv[])CHECK (fdt_finish_reservemap (fdt));CHECK (fdt_begin_node (fdt,"" )); -CHECK (fdt_property_typed (fdt,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 ))); -CHECK (fdt_property_string (fdt,"prop-str" ,TEST_STRING_1 )); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +CHECK (fdt_property (fdt,"prop-int" , &x,sizeof (x))); +CHECK (fdt_property (fdt,"prop-str" ,TEST_STRING_1 ,strlen (TEST_STRING_1 )+1 ));CHECK (fdt_begin_node (fdt,"subnode1" )); -CHECK (fdt_property_typed (fdt,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 ))); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +CHECK (fdt_property (fdt,"prop-int" , &x,sizeof (x)));CHECK (fdt_begin_node (fdt,"subsubnode" )); -CHECK (fdt_property_typed (fdt,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_1 ))); + x =cpu_to_fdt32 (TEST_VALUE_1 ); +CHECK (fdt_property (fdt,"prop-int" , &x,sizeof (x)));CHECK (fdt_end_node (fdt));CHECK (fdt_end_node (fdt));CHECK (fdt_begin_node (fdt,"subnode2" )); -CHECK (fdt_property_typed (fdt,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 ))); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +CHECK (fdt_property (fdt,"prop-int" , &x,sizeof (x)));CHECK (fdt_begin_node (fdt,"subsubnode" )); -CHECK (fdt_property_typed (fdt,"prop-int" ,cpu_to_fdt32 (TEST_VALUE_2 ))); + x =cpu_to_fdt32 (TEST_VALUE_2 ); +CHECK (fdt_property (fdt,"prop-int" , &x,sizeof (x)));CHECK (fdt_end_node (fdt));CHECK (fdt_end_node (fdt));
tests/test_tree1.dts +6 -6
@@ -6,18 +6,18 @@ /* * Test nodes and values... */ - prop_int = <deadbeef>; - prop_str = "hello world"; + prop-int = <deadbeef>; + prop-str = "hello world"; subnode1 { - prop_int = <deadbeef>; + prop-int = <deadbeef>; subsubnode { - prop_int = <deadbeef>; + prop-int = <deadbeef>; }; }; subnode2 { - prop_int = <abcd1234>; + prop-int = <abcd1234>; subsubnode { - prop_int = <abcd1234>; + prop-int = <abcd1234>; }; }; };
tests/tests.h +0 -13
@@ -110,22 +110,9 @@ static inline void *xrealloc(void *p, size_t size)void check_property (void *fdt,int nodeoffset,const char *name,int len,const void *val); -#define check_property_typed (fdt, nodeoffset, name, val) \ - ({ \ - typeof(val) x = val; \ - check_property(fdt, nodeoffset, name, sizeof(x), &x); \ - }) -void *check_getprop (void *fdt,int nodeoffset,const char *name,int len,const void *val); -#define check_getprop_typed (fdt, nodeoffset, name, val) \ - ({ \ - typeof(val) x = val; \ - check_getprop(fdt, nodeoffset, name, sizeof(x), &x); \ - }) -#define check_getprop_string (fdt, nodeoffset, name, s) \ - check_getprop((fdt), (nodeoffset), (name), strlen(s)+1, (s))//void *load_blob(const char *filename); void *load_blob_arg (int argc,char *argv[]);void save_blob (const char *filename,void *blob);
--
1.4.4.4
______________________________________________________________________
CAUTION: This message was sent via the Public Internet and its authenticity cannot be guaranteed.
______________________________________________________
Quoted 36 lines · Jerry Van Baren
Quoted 12 lines · David Gibson
Quoted 3 lines · Jerry Van Baren
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
Ouch. That's.. a very embarrassing bug. Actually, I know where it came from: I was looking at
flat_dt.hfrom dtc, which also gets this wrong (but the declaration in question is unused). Of course, I also wroteflat_dt.h...Quoted 1 line
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both
tree.Sand jdl's dtc). I have not started on that layer of the onion yet.Quoted 8 lines
Found it, there was a direct use of the position of the length in
_fdt_next_tag(). Just pushed out a fix for this in the libfdt tree, along with some other small fixes which I found while tracking this one down.Oh, incidentally, I applied your patch by eye rather than with patch(1), which was handy, because it appears to have been whitespace damaged.
Hi David,
Sorry about the whitespace, I actually generated it at home, emailed it to my day job, and edited and forwarded it from there (I'm not subscribed at home - probably should be).
It sounds like we found and fixed the same bug last night.
I went quite a bit further (before finding and fixing the real bug). I was looking at the
*_type"function like" #defines that generate a temporary variable of indeterminate (until compile time) type. An example:#define fdt_setprop_inplace_typed(fdt, nodeoffset, name, val) \ ({ \ typeof(val) x = val; \ fdt_setprop_inplace(fdt, nodeoffset, name, &x, sizeof(x)); \ })
Quoted 6 lines
IMHO this is borderline evil and unnecessary, and I removed all of them by replacing the call of the
*_typemacros with the equivalent actual function. What I was suspicious of is when I changed all the calls to use proper endian by callingcpu_to_fdt32(), the parameter "val" is no longer a simple constant or variable but is, instead, a function call or macro or nothing at all, depending on the host endian and compiler implementation. It turns out that this apparently wasn't a problem, but I'm still of the opinion that those #defines have minimal value and makes the code baroque. ;-)I've attached a patch file that shouldn't be whitespace damaged this time. :-/ I can also make my git repository accessible if that is helpful.
Best regards,
gvb
Hi David,
I exposed my git repository for my hacks on libfdt:
<http://www.cideas.us/cgi-bin/gitweb.cgi?p=linux/libfdt.git;a=summary>
BTW, a patch I didn't publish (yet)added some comments:
<http://www.cideas.us/cgi-bin/gitweb.cgi?p=linux/libfdt.git;a=commitdiff;h=775fee94444b4cda010e3d55f8c2aa1a0efe8856>
I also neglected to mention that, in the patch that was attached to the parent email, I added a configuration option to tests/Makefile to more easily select trees.S vs. dtc (now it is just ugly instead of fugly).
Best regards,
gvb
Quoted 45 lines · Jerry Van Baren
Quoted 17 lines · David Gibson
Quoted 6 lines · Jerry Van Baren
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
Ouch. That's.. a very embarrassing bug. Actually, I know where it came from: I was looking at
flat_dt.hfrom dtc, which also gets this wrong (but the declaration in question is unused). Of course, I also wroteflat_dt.h...Quoted 3 lines
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both
tree.Sand jdl's dtc). I have not started on that layer of the onion yet.Quoted 8 lines
Found it, there was a direct use of the position of the length in
_fdt_next_tag(). Just pushed out a fix for this in the libfdt tree, along with some other small fixes which I found while tracking this one down.Oh, incidentally, I applied your patch by eye rather than with patch(1), which was handy, because it appears to have been whitespace damaged.
Hi David,
Sorry about the whitespace, I actually generated it at home, emailed it to my day job, and edited and forwarded it from there (I'm not subscribed at home - probably should be).
It sounds like we found and fixed the same bug last night.
I went quite a bit further (before finding and fixing the real bug). I was looking at the
*_type"function like" #defines that generate a temporary variable of indeterminate (until compile time) type. An example:#define fdt_setprop_inplace_typed(fdt, nodeoffset, name, val) \ ({ \ typeof(val) x = val; \ fdt_setprop_inplace(fdt, nodeoffset, name, &x, sizeof(x)); \ })
Quoted 9 lines
IMHO this is borderline evil and unnecessary, and I removed all of them by replacing the call of the
*_typemacros with the equivalent actual function. What I was suspicious of is when I changed all the calls to use proper endian by callingcpu_to_fdt32(), the parameter "val" is no longer a simple constant or variable but is, instead, a function call or macro or nothing at all, depending on the host endian and compiler implementation. It turns out that this apparently wasn't a problem, but I'm still of the opinion that those #defines have minimal value and makes the code baroque. ;-)
Um, I'm afraid I don't agree. I think those typed versions make the code using them clearer and simpler. In fact, one of their main uses is to be used with functions or literals directly as the argument, which isn't possible with the raw versions, because they need to take an address.
Now, actually, that macro *is* broken, because there should be parens around all the macro arguments, but you'll need to work much harder to convince me the concept is broken.
Quoted 2 lines
I've attached a patch file that shouldn't be whitespace damaged this time. :-/ I can also make my git repository accessible if that is helpful.
Gah. I really hate saying this, but please don't send me patches until I have the situation sorted out with legal better. I took the last one partly because it was so broken without it, but also because it was so trivial that even IBM's paranoid interpretation regards it as too small to be copyrightable.
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
So, like, the other day David Gibson mumbled:
Quoted 17 lines · Jerry Van Baren
Quoted 6 lines
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
Ouch. That's.. a very embarrassing bug. Actually, I know where it came from: I was looking at
flat_dt.hfrom dtc, which also gets this wrong (but the declaration in question is unused). Of course, I also wroteflat_dt.h...Quoted 3 lines
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both
tree.Sand jdl's dtc). I have not started on that layer of the onion yet.
Quoted 8 lines
Found it, there was a direct use of the position of the length in
_fdt_next_tag(). Just pushed out a fix for this in the libfdt tree, along with some other small fixes which I found while tracking this one down.Oh, incidentally, I applied your patch by eye rather than with patch(1), which was handy, because it appears to have been whitespace damaged.
And amidst all of this, is there an actual DTC change needed? I've not detected one yet, but I'm watching... :-)
jdl
Quoted 16 lines · Jon Loeliger
So, like, the other day David Gibson mumbled:
Quoted 15 lines · Jerry Van Baren
Quoted 3 lines
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
Ouch. That's.. a very embarrassing bug. Actually, I know where it came from: I was looking at
flat_dt.hfrom dtc, which also gets this wrong (but the declaration in question is unused). Of course, I also wroteflat_dt.h...Quoted 1 line
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both
tree.Sand jdl's dtc). I have not started on that layer of the onion yet.Found it, there was a direct use of the position of the length in
_fdt_next_tag(). Just pushed out a fix for this in the libfdt tree, along with some other small fixes which I found while tracking this one down.
Quoted 8 lines
Quoted 3 lines
Oh, incidentally, I applied your patch by eye rather than with patch(1), which was handy, because it appears to have been whitespace damaged.
And amidst all of this, is there an actual DTC change needed? I've not detected one yet, but I'm watching... :-)
jdl
Hi Jon,
Your dtc is the "gold standard." Gold doesn't tarnish. ;-)
David's libfdt supports version 17 that dtc doesn't - I'm not sure where version 17 came from, David or elsewhere. Version 17 adds one more size to the blob header structure and is suppose to be backward compatible with version 16. (A couple of the current libfdt tests fail when run against a dtc-generated version 16 blob - don't know where the fault lies yet.)
Best regards,
gvb
Quoted 26 lines · Jerry Van Baren
Quoted 25 lines · Jon Loeliger
So, like, the other day David Gibson mumbled:
Quoted 23 lines · Jerry Van Baren
Quoted 6 lines
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
Ouch. That's.. a very embarrassing bug. Actually, I know where it came from: I was looking at
flat_dt.hfrom dtc, which also gets this wrong (but the declaration in question is unused). Of course, I also wroteflat_dt.h...Quoted 3 lines
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both
tree.Sand jdl's dtc). I have not started on that layer of the onion yet.Found it, there was a direct use of the position of the length in
_fdt_next_tag(). Just pushed out a fix for this in the libfdt tree, along with some other small fixes which I found while tracking this one down.Oh, incidentally, I applied your patch by eye rather than with patch(1), which was handy, because it appears to have been whitespace damaged.
Quoted 8 lines
Quoted 4 lines
And amidst all of this, is there an actual DTC change needed? I've not detected one yet, but I'm watching... :-)
jdl
Hi Jon,
Your dtc is the "gold standard." Gold doesn't tarnish. ;-)
No, the kernel's parser is the gold standard.
Quoted 6 lines
David's libfdt supports version 17 that dtc doesn't - I'm not sure where version 17 came from, David or elsewhere. Version 17 adds one more size to the blob header structure and is suppose to be backward compatible with version 16. (A couple of the current libfdt tests fail when run against a dtc-generated version 16 blob - don't know where the fault lies yet.)
Version 17 is my invention, though the extension in question was also planned by BenH. And yes, V17 needs to be documented in booting-without-of.txt and support needs to go into dtc.
The V17 extension allows us to do resizing modifications to the device tree without having to allocate an extra context structure somewhere. Your testcase failures are probably because the fdt_rw.c functions are incapable of operating on a V16 tree. fdt_open_into() is supposed to convert a V16 tree into a V17 tree with the correct layout, allowing those functions to operate, but I haven't gotten around to implementing it yet.
Incidentally, jdl took over maintainership of dtc from me when I went on extended leave last year, but the bulk of it is my code.
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
Quoted 23 lines · Jon Loeliger
So, like, the other day David Gibson mumbled:
Quoted 22 lines · Jerry Van Baren
Quoted 6 lines
Hi Dave,
I have good news and bad news. ;-) The good news is that the incompatibility between libfdt and jdl's dtc is that libfdt has the name offset and the length of the name switched. booting_without_of.txt says the length comes first, so libfdt is in the wrong.
Ouch. That's.. a very embarrassing bug. Actually, I know where it came from: I was looking at
flat_dt.hfrom dtc, which also gets this wrong (but the declaration in question is unused). Of course, I also wroteflat_dt.h...Quoted 3 lines
The bad news is that, when I fix this, nearly all of the tests fail (but they fail the same way for both
tree.Sand jdl's dtc). I have not started on that layer of the onion yet.Found it, there was a direct use of the position of the length in
_fdt_next_tag(). Just pushed out a fix for this in the libfdt tree, along with some other small fixes which I found while tracking this one down.
Quoted 6 lines
Quoted 3 lines
Oh, incidentally, I applied your patch by eye rather than with patch(1), which was handy, because it appears to have been whitespace damaged.
And amidst all of this, is there an actual DTC change needed? I've not detected one yet, but I'm watching... :-)
We need to fix flat_dt.h so it doesn't mislead anyone else. The structure in question is never used in dtc, so in fact the fix won't change anything in the object code.
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