libfdt: Change last_comp_version to fit spec
cover libfdt: Change last_comp_version to fit spec
This adds a new FDT_LAST_COMPATIBLE_VERSION constant that should keep up to date to match devicetree spec. Since the latest format spec specifies that version 17 is compatible with version 16, but not earlier versions, this constant has been set to indicate that newly generated devicetrees are compatible with version 16.
Justin Covell (1):
libfdt: Change last_comp_version to fit spec
libfdt/fdt_sw.c | 2 +- libfdt/libfdt.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
A message that is not in the archive (sent off-list or not yet received): 20201124174945.5399-1-jujugoboom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH 1/1 libfdt: Change last_comp_version to fit spec
--- libfdt/fdt_sw.c | 2 +- libfdt/libfdt.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
libfdt/fdt_sw.c +1 -1
@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)fdt_set_totalsize (fdt, newstroffset +fdt_size_dt_strings (fdt));/* And fix up fields that were keeping intermediate state. */ -fdt_set_last_comp_version (fdt,FDT_FIRST_SUPPORTED_VERSION ); +fdt_set_last_comp_version (fdt,FDT_LAST_COMPATIBLE_VERSION );fdt_set_magic (fdt,FDT_MAGIC );return 0 ;
libfdt/libfdt.h +1 -0
@@ -14,6 +14,7 @@ extern "C" {#endif #define FDT_FIRST_SUPPORTED_VERSION 0x02 +#define FDT_LAST_COMPATIBLE_VERSION 0x10#define FDT_LAST_SUPPORTED_VERSION 0x11/* Error codes: informative error codes */
Signature · 1 line
2.25.1
A message that is not in the archive (sent off-list or not yet received): 20201124174945.5399-2-jujugoboom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 1 line · Justin Covell
Needs a commit message. For a single patch, you don't need a cover letter. The explanation should be here.
Besides matching the spec, what problem are you trying to solve?
Quoted 23 lines
--- libfdt/fdt_sw.c | 2 +- libfdt/libfdt.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)libfdt/fdt_sw.c +1
-1@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)fdt_set_totalsize (fdt, newstroffset +fdt_size_dt_strings (fdt));/* And fix up fields that were keeping intermediate state. */ -fdt_set_last_comp_version (fdt,FDT_FIRST_SUPPORTED_VERSION ); +fdt_set_last_comp_version (fdt,FDT_LAST_COMPATIBLE_VERSION );fdt_set_magic (fdt,FDT_MAGIC );return 0 ;libfdt/libfdt.h +0
-0
libfdt/libfdt.h extern "C" { · line 17
Quoted 4 lines
libfdt/libfdt.h +1
-0@@ -14,6 +14,7 @@ extern "C" {#endif #define FDT_FIRST_SUPPORTED_VERSION 0x02 +#define FDT_LAST_COMPATIBLE_VERSION 0x10
If the above change is correct (I'm not sure it is offhand), why not just bump up FDT_FIRST_SUPPORTED_VERSION value?
Quoted 6 lines
libfdt/libfdt.h +0
-1#define FDT_LAST_SUPPORTED_VERSION 0x11/* Error codes: informative error codes */ --2.25.1
A message that is not in the archive (sent off-list or not yet received): CAL_Jsq+CZA8weCYPcJYOdY3-z8fnwibsKhfGwO8nuy+7RH=pvg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 8 lines · Rob Herring
Quoted 1 line · Justin Covell
Needs a commit message. For a single patch, you don't need a cover letter. The explanation should be here.
Besides matching the spec, what problem are you trying to solve?
Sorry about that, first time contributing. I'm trying to help with interoperability with other libraries that are made to read/write DTBs by matching the spec.
Quoted 25 lines
Quoted 25 lines
--- libfdt/fdt_sw.c | 2 +- libfdt/libfdt.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)libfdt/fdt_sw.c +1
-1@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)fdt_set_totalsize (fdt, newstroffset +fdt_size_dt_strings (fdt));/* And fix up fields that were keeping intermediate state. */ -fdt_set_last_comp_version (fdt,FDT_FIRST_SUPPORTED_VERSION ); +fdt_set_last_comp_version (fdt,FDT_LAST_COMPATIBLE_VERSION );fdt_set_magic (fdt,FDT_MAGIC );return 0 ;libfdt/libfdt.h +0
-0@@ -14,6 +14,7 @@ extern "C" {#endif
Quoted 6 lines
libfdt/libfdt.h extern "C" { · line 17
Quoted 2 lines
libfdt/libfdt.h +1
-0#define FDT_FIRST_SUPPORTED_VERSION 0x02 +#define FDT_LAST_COMPATIBLE_VERSION 0x10If the above change is correct (I'm not sure it is offhand), why not just bump up
FDT_FIRST_SUPPORTED_VERSIONvalue?
I didn't want to bump the FDT_FIRST_SUPPORTED_VERSION to maintin backwards compatability, and assumed that libfdt actually does support working with DTBs down to version 2.
Quoted 6 lines
Quoted 6 lines
libfdt/libfdt.h +0
-1#define FDT_LAST_SUPPORTED_VERSION 0x11/* Error codes: informative error codes */ --2.25.1
A message that is not in the archive (sent off-list or not yet received): 20201202074627.GA87-cyTpl0DnfLBQ0J4zD59KJAH0AcctZ4a01BehtkLrGTY@public.gmane.org
Quoted 8 lines · Justin Covell
Quoted 6 lines · Rob Herring
Quoted 1 line · Justin Covell
Needs a commit message. For a single patch, you don't need a cover letter. The explanation should be here.
Quoted 6 lines
Quoted 2 lines
Besides matching the spec, what problem are you trying to solve?
Sorry about that, first time contributing. I'm trying to help with interoperability with other libraries that are made to read/write DTBs by matching the spec.
What library? Why does libfdt not work?
Quoted 32 lines
Quoted 25 lines
Quoted 25 lines
--- libfdt/fdt_sw.c | 2 +- libfdt/libfdt.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)libfdt/fdt_sw.c +1
-1@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)fdt_set_totalsize (fdt, newstroffset +fdt_size_dt_strings (fdt));/* And fix up fields that were keeping intermediate state. */ -fdt_set_last_comp_version (fdt,FDT_FIRST_SUPPORTED_VERSION ); +fdt_set_last_comp_version (fdt,FDT_LAST_COMPATIBLE_VERSION );fdt_set_magic (fdt,FDT_MAGIC );return 0 ;libfdt/libfdt.h +0
-0@@ -14,6 +14,7 @@ extern "C" {#endif Quoted 6 lines
libfdt/libfdt.h extern "C" { · line 17
Quoted 2 lines
libfdt/libfdt.h +1
-0#define FDT_FIRST_SUPPORTED_VERSION 0x02 +#define FDT_LAST_COMPATIBLE_VERSION 0x10If the above change is correct (I'm not sure it is offhand), why not just bump up
FDT_FIRST_SUPPORTED_VERSIONvalue?
Quoted 3 lines
I didn't want to bump the
FDT_FIRST_SUPPORTED_VERSIONto maintin backwards compatability, and assumed that libfdt actually does support working with DTBs down to version 2.
Looking at this more closely, I think your change is correct. It's actually fixing a regression. Prior to commit f1879e1a50eb ("Add limited read-only support for older (V2 and V3) device tree to libfdt."), libfdt would set last_comp_version to 16. Now it sets it to 2, but really 2 is what libfdt can read, not what should be in last_comp_version.
Also, I'm not certain what happens if you tried to modify a version 2 dtb. It doesn't look like we do anything to fail gracefully.
Rob
A message that is not in the archive (sent off-list or not yet received): CAL_Jsq+aio50a18QrwA6VbxZmOYyzcC+tRkkxPkBPyLNcfh-5w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 9 lines · Rob Herring
Quoted 8 lines · Justin Covell
Quoted 6 lines · Rob Herring
Quoted 1 line · Justin Covell
Needs a commit message. For a single patch, you don't need a cover letter. The explanation should be here.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Besides matching the spec, what problem are you trying to solve?
Sorry about that, first time contributing. I'm trying to help with interoperability with other libraries that are made to read/write DTBs by matching the spec.
What library? Why does libfdt not work?
I was attempting to use a DTB library for Rust, and it will fail if the set last_comp_version doesn't match what is expected.
Quoted 43 lines
Quoted 32 lines
Quoted 25 lines
Quoted 25 lines
--- libfdt/fdt_sw.c | 2 +- libfdt/libfdt.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)libfdt/fdt_sw.c +1
-1@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)fdt_set_totalsize (fdt, newstroffset +fdt_size_dt_strings (fdt));/* And fix up fields that were keeping intermediate state. */ -fdt_set_last_comp_version (fdt,FDT_FIRST_SUPPORTED_VERSION ); +fdt_set_last_comp_version (fdt,FDT_LAST_COMPATIBLE_VERSION );fdt_set_magic (fdt,FDT_MAGIC );return 0 ;libfdt/libfdt.h +0
-0@@ -14,6 +14,7 @@ extern "C" {#endif Quoted 6 lines
libfdt/libfdt.h extern "C" { · line 17
Quoted 2 lines
libfdt/libfdt.h +1
-0#define FDT_FIRST_SUPPORTED_VERSION 0x02 +#define FDT_LAST_COMPATIBLE_VERSION 0x10If the above change is correct (I'm not sure it is offhand), why not just bump up
FDT_FIRST_SUPPORTED_VERSIONvalue?Quoted 3 lines
I didn't want to bump the
FDT_FIRST_SUPPORTED_VERSIONto maintin backwards compatability, and assumed that libfdt actually does support working with DTBs down to version 2.Looking at this more closely, I think your change is correct. It's actually fixing a regression. Prior to commit
f1879e1a50eb("Add limited read-only support for older (V2 and V3) device tree to libfdt."), libfdt would setlast_comp_versionto 16. Now it sets it to 2, but really 2 is what libfdt can read, not what should be inlast_comp_version.
Quoted 4 lines
Also, I'm not certain what happens if you tried to modify a version 2 dtb. It doesn't look like we do anything to fail gracefully.
Rob
I'm happy to test modifying a version 2 dtb and see what happens, but I don't have one around, and feel that might be a little out of the scope of this patch.
A message that is not in the archive (sent off-list or not yet received): 20201203012147.GA87-cyTpl0DnfLBQ0J4zD59KJAH0AcctZ4a01BehtkLrGTY@public.gmane.org
Quoted 17 lines · Justin Covell
Quoted 16 lines · Rob Herring
Quoted 14 lines · Justin Covell
Quoted 8 lines · Rob Herring
Quoted 1 line · Justin Covell
Needs a commit message. For a single patch, you don't need a cover letter. The explanation should be here.
Besides matching the spec, what problem are you trying to solve?
Sorry about that, first time contributing. I'm trying to help with interoperability with other libraries that are made to read/write DTBs by matching the spec.
Quoted 5 lines
Quoted 2 lines
What library? Why does libfdt not work?
I was attempting to use a DTB library for Rust, and it will fail if the set
last_comp_versiondoesn't match what is expected.
Hmm. Although there's definitely a bug in libfdt here, depending on exactly what "expected" means, that doesn't necessarily sound like correct behaviour on the part of the Rust library.
Quoted 43 lines
Quoted 43 lines
Quoted 32 lines
Quoted 25 lines
Quoted 25 lines
--- libfdt/fdt_sw.c | 2 +- libfdt/libfdt.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)libfdt/fdt_sw.c +1
-1@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)fdt_set_totalsize (fdt, newstroffset +fdt_size_dt_strings (fdt));/* And fix up fields that were keeping intermediate state. */ -fdt_set_last_comp_version (fdt,FDT_FIRST_SUPPORTED_VERSION ); +fdt_set_last_comp_version (fdt,FDT_LAST_COMPATIBLE_VERSION );fdt_set_magic (fdt,FDT_MAGIC );return 0 ;libfdt/libfdt.h +0
-0@@ -14,6 +14,7 @@ extern "C" {#endif Quoted 6 lines
libfdt/libfdt.h extern "C" { · line 17
Quoted 2 lines
libfdt/libfdt.h +1
-0#define FDT_FIRST_SUPPORTED_VERSION 0x02 +#define FDT_LAST_COMPATIBLE_VERSION 0x10If the above change is correct (I'm not sure it is offhand), why not just bump up
FDT_FIRST_SUPPORTED_VERSIONvalue?Quoted 3 lines
I didn't want to bump the
FDT_FIRST_SUPPORTED_VERSIONto maintin backwards compatability, and assumed that libfdt actually does support working with DTBs down to version 2.Looking at this more closely, I think your change is correct. It's actually fixing a regression. Prior to commit
f1879e1a50eb("Add limited read-only support for older (V2 and V3) device tree to libfdt."), libfdt would setlast_comp_versionto 16. Now it sets it to 2, but really 2 is what libfdt can read, not what should be inlast_comp_version.
Quoted 8 lines
Quoted 4 lines
Also, I'm not certain what happens if you tried to modify a version 2 dtb. It doesn't look like we do anything to fail gracefully.
Rob
I'm happy to test modifying a version 2 dtb and see what happens, but I don't have one around, and feel that might be a little out of the scope of this patch.
AFAICT, dtc still supports generating old dtb versions, using the -V flag. So you could convert a dtb into v2 with:
dtc -I dtb -O dtb -V 2 input.dtb -o output.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
Quoted 8 lines · Rob Herring
Quoted 7 lines · Justin Covell
Quoted 5 lines · Rob Herring
Quoted 1 line · Justin Covell
Needs a commit message. For a single patch, you don't need a cover letter. The explanation should be here.
Right. This will need to be resent with a real commit message and a Signed-off-by line.
Quoted 45 lines
Quoted 6 lines
Quoted 2 lines
Besides matching the spec, what problem are you trying to solve?
Sorry about that, first time contributing. I'm trying to help with interoperability with other libraries that are made to read/write DTBs by matching the spec.
What library? Why does libfdt not work?
Quoted 32 lines
Quoted 25 lines
Quoted 25 lines
--- libfdt/fdt_sw.c | 2 +- libfdt/libfdt.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)libfdt/fdt_sw.c +1
-1@@ -377,7 +377,7 @@ int fdt_finish(void *fdt)fdt_set_totalsize (fdt, newstroffset +fdt_size_dt_strings (fdt));/* And fix up fields that were keeping intermediate state. */ -fdt_set_last_comp_version (fdt,FDT_FIRST_SUPPORTED_VERSION ); +fdt_set_last_comp_version (fdt,FDT_LAST_COMPATIBLE_VERSION );fdt_set_magic (fdt,FDT_MAGIC );return 0 ;libfdt/libfdt.h +0
-0@@ -14,6 +14,7 @@ extern "C" {#endif Quoted 6 lines
libfdt/libfdt.h extern "C" { · line 17
Quoted 2 lines
libfdt/libfdt.h +1
-0#define FDT_FIRST_SUPPORTED_VERSION 0x02 +#define FDT_LAST_COMPATIBLE_VERSION 0x10If the above change is correct (I'm not sure it is offhand), why not just bump up
FDT_FIRST_SUPPORTED_VERSIONvalue?Quoted 3 lines
I didn't want to bump the
FDT_FIRST_SUPPORTED_VERSIONto maintin backwards compatability, and assumed that libfdt actually does support working with DTBs down to version 2.
Quoted 6 lines
Looking at this more closely, I think your change is correct. It's actually fixing a regression. Prior to commit
f1879e1a50eb("Add limited read-only support for older (V2 and V3) device tree to libfdt."), libfdt would setlast_comp_versionto 16. Now it sets it to 2, but really 2 is what libfdt can read, not what should be inlast_comp_version.
Right, we can read version 2, but we can't write it, so yes that looks like a regression (which the commit message should explain). It certainly looks like a correct fix - a version 0x11 tree can't possibly be compatible with a version 0x2 tree.
Quoted 2 lines
Also, I'm not certain what happens if you tried to modify a version 2 dtb. It doesn't look like we do anything to fail gracefully.
Ah.. good point. If you tried to use an rw function immediately, it would fail correctly with BADVERSION in fdt_rw_probe_(). However fdt_open_into() will incorrectly think it can handle it (when in reality it can only handle 0x10 and later) then mark it as version 0x11 so now the rest of the functions will think they can handle it and fail horribly.
Justin, if you can fix up some of those additional problems that would be great. Otherwise I'll try to look at it, but no promises when.
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