Add support for structured tags and v18 dtb version
Re: [PATCH v3 14/15] libfdt: Handle unknown tags on dtb modifications
In reply to David GibsonHi David,
Quoted 107 lines · On Mon, 28 Sep 2026 14:39:18 +1000 David Gibson <[email protected]>…
Quoted 22 lines · Herve Codina
Quoted 19 lines · On Mon, 21 Sep 2026 16:06:13 +1000 David Gibson <[email protected]>…
Quoted 17 lines · Herve Codina
The structured tag value definition introduced recently gives the ability to ignore unknown tags without any error.
When the dtb is modified those unknown tags have to be taken into account.
First, depending on the unknown tag location, the item associated with the tag is identified:
- An unknown tag located just after aFDT_BEGIN_NODEis related to the node.- An unknown tag located just after a
FDT_PROPis related to the property.- An unknown tag out of any node (i.e located before the first
FDT_BEGIN_NODEor after the lastFDT_END_NODE) is a global tag related to the dtb itself.Quoted 6 lines
Quoted 4 lines
Since we rely on those constraings here, it seems like those should probably be written into the structured tag specs / description. Which to my mind strengthens the case for explicitly calling them "metadata tags".
Yes this need to be documented somewhere but where?
Yeah, that's a good question.
Quoted 1 line
In the end it should be present in the Devicetree Specification.
Right, eventually. But that will take a while, plus it's preferable to have the documentation as close as possible to the things you'd be looking at when it becomes relevant.
So, for starters, I think your commit messages should include this kind of context and rationale at the point the concepts are introdcued to the code. It also might make sense to have some of this in comments in
fdt.h. We haven't done much of that so far, but providing more detail around the bare structure and constant definitions is probably worthwhile.Quoted 3 lines
Related to the term "metadata" I am not sure that all future tags will be "metadata" tags. Especially global tags (out of any nodes). At this point we have "skippable" tags without any more knowledge.
Hm, ok.
Quoted 16 lines
But anyway, I will use the term "metadata".
Quoted 14 lines
Quoted 5 lines
Then, if we are allowed to write a dtb containing unknown tags, the following rules are used:
- When a property is modified, tags related to this property are removed and the dtb version is downgraded.Hmm. This seems weird to me, but maybe that's because we haven't pinned down in specs / docs what the interaction is between new skippable tags and the overall version.
My assumption had been that tags - even structured tags - newer than vNNN must not appear in a dtb with version == NNN (but they can appear in a dtb with
last_compat_version< NNN).Quoted 6 lines
Quoted 3 lines
With that model, this seems kind of backwards - downgrading the version would require removing newer tags throughout the tree, rather than removing some tags causing the version to be downgraded.
The discussion which led to this mechanism is available at [1].
Ah, thanks for the reminder.
Quoted 3 lines
If all tags are removed, there is no way to forward a dtb with unknown tags from a bootloader point of view (support for Vnnn in bootloader) to a Linux Kernel having support for newer dtb version.
I'm guessing that's with the assumption that the bootloader is making at least minor changes to the tree? Certainly a tree with unknown tags can be forwarded unmodified.
Quoted 1 line
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
TBH, I'm finding it pretty hard to follow what Rob's saying there. It does help me understand some things you've said elsewhere.
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
- When a property is removed, tags related to this property are obviously removed. The dtb version is kept unchanged.
- When a property or a node is added, obviously no unknown tags are added and the dtb version is kept unchanged.
This seems weird to me in combination with the behaviour on modification. The previous one makes more sense to me in the context of an alternative model: newer versions might *require* certain metadata tags are present. But in that case this part doesn't work.
Quoted 6 lines
Suppose a tag defined at Vnnn. An older libfdt can add a property to a node but cannot add the tag defined at Vnnn. Indeed this tag is unknown.
At a given version, libfdt cannot add unknown tags and so as unknown tags are not involved when a property is added, there is no need to dowgrade the version.
Quoted 9 lines
Only if we assume "skippable" tags are always optional. Making this assumption means we can't, for example, say: from v23, all properties _must_ have an
FDT_XXXmetadata tag. Constraining future versions that way seems undesirable to me, since a number of previous revisions exist to say "you can count on this particular information being present". That's been in the form of extra header fields previously, but I think the same principle applies. e.g. it seems like it would be pretty useful to tell an addon aware bootloader "if version >= NNN then you can rely on all necessary fixup tags being present.
An old version doesn't add constraints to new version but new version allows or not possible modification done by old version.
Focusing on property only, all libfdt version need to handle cases where a unknown skippable tag is present.
A skippable is a tag with bit31 set to 1 and, by definition, has needed information to skip related data.
An unknown tag is a tag not defined in the current libfdt version. It can be in a skippable format but the current libfdt version doesn't known about the exact meaning of the tag nor about the related data.
Also, we know that a skippable tag locate after FDT_PROP is related to the property. So, even if the current libfdt version cannot determine the exact meaning of the tag, it can determine that the tag is related to the property.
For the current libfdt version, we have a property and a skippable unknown tag related to this property. The current version of libfdt wants to modify the property. What to do with the unknown tag?
Rules are defined to handle this case:
- First can I perform some modification in this dtb (last_comp_version_w compared against my last supported dtb version). If I cannot perform a modification I don't do the modification and report an error.
This prevent old libfdt version (me) to do a modification because I am too old and I haven't enough knownledge to perform the modification.
- Ok, I can do the modification. I apply the following rule known by all libfdt version:
If a property is modify, related unknown tags are removed and the dtb version is downgrade.
I modify the property, remove skippable unknown tags and downgrade the dtb version (i.e. set the dtb version to my last supported version).
That's the rule used by all libfdt version when an unknwon tag related to a property is present. This rule have to be kept in mind when a new skippable tag is defined.
When the tag is defined we need to check if this rule is correct. If the tag cannot be removed when the property is modified by old libfdt version, the new libfd/dtc version generating the dtb blob must set the last_comp_version_w to prevent any modification.
I mentioned only unknown tags for this rule. Indeed, if the tag is known (tag defined at current libfdt version with a perfect knownledge of related data), the problem is different. A property is modified and a known tag related to this property is present. In this case, the way of handling the tag depends on the tag itself.
For instance, in the support for addon series. The FDT_PROPDATA_PHANDLE is added. This tag identify a phandle at some offset in a property data.
When the property is modified, code in the series chooses to remove the tag only if modification are done at the offset where the phandle is present. Otherwise, the tag is still valid and there is no reason to remove it.
Now the question can be: Do we need a finer grain and use a flag per tag in addition to the global last_comp_version_w field. We can imagine the following rules for unknown tag:
- First check last_comp_version_w with non semantic change (global write enable/disable).
- Check the unknown tag value to see if the bit "Allow remove on modification" is set. If not set, do not perform the modification and report an error.
- If we can remove on modification, modify the property, remove the unknown tags and downgrade the dtb version
This new "Allow remove on modification" bit, if it makes sense, has to be added in the skippable tag format (alongside the data lengh encoding bits).
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
- When a node is removed, tags related to this node are obviously removed. The dtb version is kept unchanged.
- Adding, removing or modifying a property is not considered as a node modification and so, those operations have no impacts on unknown tags related to the node. Those node related tags are kept unchanged.
Quoted 8 lines
Quoted 3 lines
That.. certainly constrains what it's possible to put in skippable tags, in a way that we'd have to document, though it's not especially easy to do so.
Yes, and that's why the
FDT_BEGIN_NODE_REFtag defined by the support for addon cannot be skipped. If this tag is skipped by older libfdt weird behavior will happen. The old libfdt will think that the root node is a subnode of an orphan node.
Quoted 6 lines
Sure, it's pretty clear than anything that would alter the tree structure can't be skipped. But the constraints on what needs to be dropped on what sorts of modification constrict things substantially further. For example. the fact that property modifications don't affect node tags means it wouldn't be possible to have a node tag which was, say, "total number of properties in this subtree". That's
If such a tag is introduced, last_comp_version_w will be also set to avoid old libfdt version (this tag is an unknown tag for old version) to perform some modification.
Only version having knownledge about this tag can perform modification, probably updating the tag data if a property is added or removed.
Quoted 117 lines
a contrived example, obviously, but it's not obvious to me there wouldn't be some use for "summary" tags of this nature, that is, something which collates information for an entire node or subtree for quick reference.
Quoted 89 lines
top level dtb:
FDT_BEGIN_NODE_REF<--- Skip by old libfdt
FDT_BEGIN_NODE<---- Root node identified by old libfdtTo avoid that
FDT_BEGIN_NODE_REFcannot be skipped and so old libfdt will report an error: Unknown tag which cannot be skipped.Quoted 73 lines
Quoted 47 lines
- The only modification considered as a node modification is setting its name. We consider that this operation has no impact on tags related to the node. Here also, those node related tags and the dtb version are kept unchanged.
- Global (dtb related) unknown tags are kept unchanged regardless the modification done.
Implement those rules when a dtb is modified.
Signed-off-by Herve Codina <[email protected]>Reviewed-by Luca Ceresoli <[email protected]>--- libfdt/fdt_rw.c | 129 +++++++++++++++++- libfdt/fdt_wip.c | 28 +++- libfdt/libfdt_internal.h | 3 + tests/run_tests.sh | 78 +++++++++++ ...own_tags_can_skip.fdtput.test.dtb.0.expect | 31 +++++ ...own_tags_can_skip.fdtput.test.dtb.1.expect | 35 +++++ ...own_tags_can_skip.fdtput.test.dtb.2.expect | 33 +++++ ...own_tags_can_skip.fdtput.test.dtb.3.expect | 35 +++++ ...own_tags_can_skip.fdtput.test.dtb.4.expect | 34 +++++ ...own_tags_can_skip.fdtput.test.dtb.5.expect | 32 +++++ ...own_tags_can_skip.fdtput.test.dtb.6.expect | 27 ++++ ...nknown_tags_can_skip.wip.test.dtb.0.expect | 31 +++++ ...nknown_tags_can_skip.wip.test.dtb.1.expect | 35 +++++ ...nknown_tags_can_skip.wip.test.dtb.2.expect | 37 +++++ ...nknown_tags_can_skip.wip.test.dtb.3.expect | 38 ++++++ 15 files changed, 603 insertions(+), 3 deletions(-) create mode 100644 tests/unknown_tags_can_skip.fdtput.test.dtb.0.expect create mode 100644 tests/unknown_tags_can_skip.fdtput.test.dtb.1.expect create mode 100644 tests/unknown_tags_can_skip.fdtput.test.dtb.2.expect create mode 100644 tests/unknown_tags_can_skip.fdtput.test.dtb.3.expect create mode 100644 tests/unknown_tags_can_skip.fdtput.test.dtb.4.expect create mode 100644 tests/unknown_tags_can_skip.fdtput.test.dtb.5.expect create mode 100644 tests/unknown_tags_can_skip.fdtput.test.dtb.6.expect create mode 100644 tests/unknown_tags_can_skip.wip.test.dtb.0.expect create mode 100644 tests/unknown_tags_can_skip.wip.test.dtb.1.expect create mode 100644 tests/unknown_tags_can_skip.wip.test.dtb.2.expect create mode 100644 tests/unknown_tags_can_skip.wip.test.dtb.3.expectlibfdt/fdt_rw.c +0
-0libfdt/fdt_rw.c int fdt_del_mem_rsv(void *fdt, int n) · line 200
Quoted 4 lines
libfdt/fdt_rw.c +1
-0@@ -197,10 +197,69 @@ int fdt_del_mem_rsv(void *fdt, int n)return fdt_splice_mem_rsv_ (fdt, re,1 ,0 ); } +static void fdt_nopify_area (void *fdt,int start_offset,int next_offset)This should be written in terms of
fdt_nop_region_()fromfdt_wip.c(or else the other way around). It should also probably live infdt_wip.c.Quoted 17 lines
libfdt/fdt_rw.c +17
-0+{ +int count = (next_offset - start_offset) /sizeof (fdt32_t); +fdt32_t fdt32_nop =cpu_to_fdt32 (FDT_NOP ); +fdt32_t *ptr; + + ptr =fdt_offset_ptr_w_ (fdt, start_offset); +while (count--) + *(ptr++) = fdt32_nop; +}; + +int fdt_prop_remove_unknown_tags (void *fdt,bool force_inplace, +int prop_offset,bool downgrade_version) +{ +int nextoffset, offset; +bool is_unknown; +uint32_t tag; +Quoted 8 lines
libfdt/fdt_rw.c int fdt_del_mem_rsv(void *fdt, int n) · line 220
Quoted 3 lines
libfdt/fdt_rw.c +3
-0+/* +* Only inplace using nopify is supported even if we could use an other +* method involving splices if force_inplace is set to false. This comment is fairly hard to understand without reading a lot of the rest of the patch first. It's also really not ideal - when we're in the
fdt_rwcontext, we want to be able to really truly remove the stale tags, not just NOP them.Quoted 2 lines
Well nopifying them is not optimized in the
fdt_rwcontext but it is not incorrect.It breaks the principle of least surprise, though. Especially since we don't have a "strip nops" function (aside: that would be a nice addition).
Quoted 3 lines
Well if nopifying them in the
fdt_rwcontext is a no go, I will add more complexity in the next iteration to really remove them instead of just nopifying them. Let me know what do you prefer.I don't think it's actually that much more complex. You already have to deal with tree splicing in this case.
Quoted 9 lines
Quoted 8 lines
libfdt/fdt_rw.c int fdt_del_mem_rsv(void *fdt, int n) · line 226
Quoted 6 lines
libfdt/fdt_rw.c +6
-0+*/ + + tag =fdt_next_tag (fdt, prop_offset, &nextoffset); +if (tag ==FDT_END ) +return nextoffset; +Should this error out if tag !=
FDT_PROP?
Quoted 6 lines
Quoted 1 line
prop_offsetpoints to aFDT_PROP. Already ckecked.Not in this function, AFAICT. I assume the callers ensure this, but that's not obvious when looking just at this code. I'd prefer to see this checked here (unless
can_assume(ASSUME_LIBFDT_FLAWLESS)) returningFDT_ERR_INTERNALif it fails.
Ok, I will add a check even if this function is not part of the libfdt API.
Quoted 203 lines
Quoted 4 lines
The check here is done to be sure that nextoffset if set to the next offset and not to a error code. Indeed, we use nextoffset as the next offset in the following loop.
Yes, but I get nervous whenever I see a non-exhaustive check on a return value.
Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
libfdt/fdt_rw.c +14
-0+/* +* Look at all tags related to the current property. I.e. tags after the +* current property and before either the next property, a sub-node or +* the end of current node +*/ + do { + offset = nextoffset; + tag = fdt_next_tag_(fdt, offset, &nextoffset, &is_unknown); + if (tag == FDT_END) + return nextoffset; + + /* + * Unknown tags are returned as NOP. Force FDT_NOP to be really + * present in the area to remove the unknown tag and its relatedQuoted 8 lines
libfdt/fdt_rw.c int fdt_del_mem_rsv(void *fdt, int n) · line 244
Quoted 4 lines
libfdt/fdt_rw.c +4
-0+* data. Also, as a tag is removed, downgrade the dtb version +* if asked for. +*/ +if (tag ==FDT_NOP ) {It seems to me this would be more natural using
fdt_next_tag_all()(or whatever it ends up being called) and handling the nopping in the 'default' case.Quoted 6 lines
This doesn't work in current implementation. All unknown tags are returned as
FDT_NOPtags. That'sfdt_next_tag_()is used. It allows to know if the returnedFDT_NOPtag is a realFDT_NOPor an unknown tag translated toFDT_NOP.This is the only use case where we really have to handle unknown tags. We need to remove them and so not skipping them.
Yes, exactly, that's why I'm saying it would make more sense to use the iterator that *doesn't* skip unknown tags (whatever it gets called).
Quoted 3 lines
Of course, you asked to change the
fdt_next_tag()behavior to have it returned all tags (known and unknown skippable ones) and so this part of code will be updated accordingly.Sure.
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
libfdt/fdt_rw.c +23
-0+if (is_unknown) { +if (downgrade_version) +fdt_downgrade_version (fdt); +fdt_nopify_area (fdt, offset, nextoffset); + } + } + + }while ((tag !=FDT_PROP ) && (tag !=FDT_BEGIN_NODE ) && + (tag !=FDT_END_NODE )); + +return 0 ; +} +static int fdt_resize_property_ (void *fdt,int nodeoffset,const char *name,int namelen,int len,struct fdt_property **prop) { +int prop_offset;int oldlen;int err;@@ -209,6 +268,15 @@ static int fdt_resize_property_(void *fdt, int nodeoffset,if (!*prop)return oldlen; +/* +* The property is resized. Remove possible unknown tags related to the +* property downgrading the dtb version. +*/ + prop_offset =fdt_ptr_offset_ (fdt, *prop); + err =fdt_prop_remove_unknown_tags (fdt, false, prop_offset, true); +if (err) +return err; +if ((err =fdt_splice_struct_ (fdt, (*prop)->data,FDT_TAGALIGN (oldlen),FDT_TAGALIGN (len))))return err;@@ -217,6 +285,29 @@ static int fdt_resize_property_(void *fdt, int nodeoffset,return 0 ; }Quoted 6 lines
Quoted 4 lines
libfdt/fdt_rw.c static int fdt_resize_property_(void *fdt, int nodeoffset, · line 288
Quoted 1 line
libfdt/fdt_rw.c +1
-0+static int fdt_node_skip_unknown_tags (void *fdt,int next)Is 'next' the offset of a node? If so it should probably have a more suggestive name.
No, next is the offset of the first tag available after a
FDT_BEGIN_NODE.Ah, right.
Quoted 1 line
Should I rename to '
node_next' ?No, it's ok as is.
Quoted 102 lines
Quoted 49 lines
Quoted 49 lines
libfdt/fdt_rw.c +32
-0+{ +int nextoffset = next; +int offset; +uint32_t tag; + +/* +* Skip all tags related to the current node. I.e. tags after the +* current node and before either the next property, a sub-node or the +* end of current node. +*/ +do { + offset = nextoffset; + tag =fdt_next_tag (fdt, offset, &nextoffset); +if (tag ==FDT_END ) +return nextoffset; + + }while ((tag !=FDT_PROP ) && (tag !=FDT_BEGIN_NODE ) && + (tag !=FDT_END_NODE )); + +return offset; +} +static int fdt_add_property_ (void *fdt,int nodeoffset,const char *name,int namelen,int len,struct fdt_property **prop) {@@ -235,6 +326,15 @@ static int fdt_add_property_(void *fdt, int nodeoffset, const char *name,if ((nextoffset =fdt_check_node_offset_ (fdt, nodeoffset)) <0 )return nextoffset; +/* +* nextoffset it at the first tag after the node. +* Skip possible unknown tags related to the node in order to add the +* property after those tags. +*/ + nextoffset =fdt_node_skip_unknown_tags (fdt, nextoffset); +if (nextoffset <0 ) +return nextoffset; + namestroff =fdt_find_add_string_ (fdt, name, namelen, &allocated);if (namestroff <0 )return namestroff;@@ -333,11 +433,22 @@ int fdt_appendprop(void *fdt, int nodeoffset, const char *name, {struct fdt_property *prop;int err, oldlen, newlen; +int prop_offset;FDT_RW_PROBE (fdt);Quoted 15 lines
libfdt/fdt_rw.c int fdt_appendprop(void *fdt, int nodeoffset, const char *name, · line 450
Quoted 11 lines
libfdt/fdt_rw.c +9
-0prop =fdt_get_property_w (fdt, nodeoffset, name, &oldlen);if (prop) { +/* +* The property is going to be modified. Remove possible unknown +* tags related to this property downgrading the dtb version. +*/ + prop_offset =fdt_ptr_offset_ (fdt, prop); + err =fdt_prop_remove_unknown_tags (fdt, false, prop_offset, + true); +if (err) +return err;Just NOPing the unknown tags isn't ideal here. This function can already insert/remove stuff from the structure block, so removing the tags entirely would be preferable.
I can add the complexity needed to fully remove those tags. IHMO it could be added later as an optimisation.
Quoted 33 lines
Quoted 16 lines
libfdt/fdt_rw.c +2
-0newlen = len + oldlen; err = fdt_splice_struct_(fdt, prop->data, FDT_TAGALIGN(oldlen),@@ -360,6 +471,8 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name) {struct fdt_property *prop;int len, proplen; +int prop_offset; +int err;FDT_RW_PROBE (fdt);@@ -367,6 +480,15 @@ int fdt_delprop(void *fdt, int nodeoffset, const char *name)if (!prop)libfdt/fdt_rw.c int fdt_delprop(void *fdt, int nodeoffset, const char *name) · line 490
Quoted 10 lines
libfdt/fdt_rw.c +8
-0return len; +/* +* The property is going to be removed. Remove also possible unknown +* tags related to this property. Keep the dtb version unchanged. +*/ + prop_offset =fdt_ptr_offset_ (fdt, prop); + err =fdt_prop_remove_unknown_tags (fdt, false, prop_offset, false); +if (err) +return err;Here, only NOPing the tags is worse, since delprop is expected to entirely remove the property without leaving NOPs.
Also.. just NOPing unknown tags isn't correct either. The property is being removed, so *all* the associated skippable tags should be removed as well (ideally with a single
fdt_splice_struct_()).
Quoted 5 lines
Quoted 1 line
Skippable tags are remove. They don't exist anymore in the resulting DT.
No, *unknown* (by this libfdt version) tags are nopped. Known skippable tags are left unaltered. Presumably they would then apply to the previous property, which is definitely wrong.
There is no "known skippable" tags at this libfdt version.
Can you list them on you side?
You cannot. When you compile the library all known tags are defined in fdt.h header file. In this libfdt version, no new tags were added. No new tags, no new "knwown" tags.
If you look at the addon series where new tags are added, known tags added are handled to avoid the problem you reports [1].
If later more new tags are added, they have to be handled as soon as they are added depending of the tag meaning, the handling could be different.
[1] https://github.com/bootlin/dtc/blob/c68038e0ff4cde5de37a21419df8a082032ef994/libfdt/fdt_rw.c#L540
Quoted 109 lines
Quoted 6 lines
You have
FDT_NOPtags. No issue with that.It is not optimized but it is correct.
Here again, I can fully remove them.
That would be good, but it's not the issue I'm pointing out above.
Quoted 100 lines
Quoted 8 lines
Quoted 8 lines
libfdt/fdt_rw.c +1
-0+ proplen =sizeof (*prop) +FDT_TAGALIGN (len);return fdt_splice_struct_ (fdt, prop, proplen,0 ); }@@ -395,7 +517,12 @@ int fdt_add_subnode_namelen(void *fdt, int parentoffset,else if (offset != -FDT_ERR_NOTFOUND )return offset;Quoted 9 lines
libfdt/fdt_rw.c int fdt_add_subnode_namelen(void *fdt, int parentoffset, · line 524
Quoted 6 lines
libfdt/fdt_rw.c +5
-1-/* Try to place the new node after the parent's properties */ +/* +* Try to place the new node after the parent's properties and unknown +* tags related to those properties. +* Unknown tags are reported as FDT_NOP tags by fdt_next_tag. +* Skipping FDT_NOP tags will correctly skip unknown tags. True, but I think it would be clearer and more robust to explicitly look for an
FDT_BEGIN_NODEorFDT_END_NODEtag instead.Ok, will have look in that direction.
Quoted 31 lines
Quoted 31 lines
libfdt/fdt_rw.c +1
-0+*/ tag =fdt_next_tag (fdt, parentoffset, &nextoffset);/* the fdt_subnode_offset_namelen() should ensure this never hits */ if (!can_assume (LIBFDT_FLAWLESS ) && (tag !=FDT_BEGIN_NODE ))libfdt/fdt_wip.c +7
-2@@ -15,17 +15,30 @@ int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, uint32_t idx, const void *val, int len) { + int prop_offset;void *propval;int proplen; +int err; - propval =fdt_getprop_namelen_w (fdt, nodeoffset, name, namelen, - &proplen); + prop_offset =fdt_getprop_offset_namelen (fdt, nodeoffset, name, namelen); +if (prop_offset <0 ) +return prop_offset; + + propval =fdt_getprop_by_offset_w (fdt, prop_offset,NULL , &proplen);if (!propval)return proplen;if ((unsigned )proplen < (len + idx))return -FDT_ERR_NOSPACE ;Quoted 12 lines
libfdt/fdt_wip.c int fdt_setprop_inplace_namelen_partial(void *fdt, int nodeoffset, · line 38
Quoted 5 lines
libfdt/fdt_wip.c +5
-0+/* +* Remove unknown tags related to the property downgrading the dtb +* version. +*/ + err =fdt_prop_remove_unknown_tags (fdt, true, prop_offset, true);Functions in
fdt_wip.cshould not depend on functions infdw_rw.c. Part of the reason for organising things this way is so that a client only uses write-in-place functions, the linker will omit the more complex full read-write code (even if an old or limited linker that doesn't do e.g. function sections).fdt_rw.cby contrast _is_ permitted to rely onfdt_wip.cMakes sense.
I will take this relationship into account in the next iteration.
Quoted 31 lines
Quoted 17 lines
libfdt/fdt_wip.c +5
-0+if (err) +return err; +memcpy ((char *)propval + idx, val, len);return 0 ; }@@ -59,12 +72,23 @@ static void fdt_nop_region_(void *start, int len)int fdt_nop_property (void *fdt,int nodeoffset,const char *name) {struct fdt_property *prop; +int prop_offset;int len; +int err; prop =fdt_get_property_w (fdt, nodeoffset, name, &len);if (!prop)libfdt/fdt_wip.c static void fdt_nop_region_(void *start, int len) · line 90
Quoted 10 lines
libfdt/fdt_wip.c +8
-0return len; +/* +* The property is going to be removed (nopified). Remove unknown tags +* related to this property. Keep the dtb version unchanged. +*/ + prop_offset =fdt_ptr_offset_ (fdt, prop); + err =fdt_prop_remove_unknown_tags (fdt, true, prop_offset, false); +if (err) +return err;Similar to
fdt_delprop()this needs to NOP *all* the properties associated with the property we're killing, not just the unknown ones (again, ideally with a singlefdt_nop_region_()).
Quoted 8 lines
Quoted 4 lines
I don't follow you.
Only unknown tags need to be removed for the moment. What other tags do you want to remove?
Again, all skippable tags on the property need to be nopped, not just unknown ones. Otherwise they'll stay there and now apply to the previous property.
No, only unknown skippable tag for the moment. There is no "known" skippable tag in this libfdt version.
New skippable tags added in future version are seen as unknown skippable ones by older version.
At a given version, we need to remove all unknown tags and handle all tags known at this version.
In this first libfdt version introducing skippable tag, no new tags are added. and so all skippable tags seen are "unknown" tags at this first libfdt version.
Quoted 53 lines
Quoted 41 lines
Quoted 32 lines
Quoted 32 lines
libfdt/fdt_wip.c +0
-0fdt_nop_region_ (prop, len +sizeof (*prop));return 0 ;libfdt/libfdt_internal.h +3
-0@@ -26,6 +26,9 @@ uint32_t fdt_next_tag_(const void *fdt, int startoffset, int *nextoffset,int fdt_check_node_offset_ (const void *fdt,int offset);int fdt_check_prop_offset_ (const void *fdt,int offset); +int fdt_prop_remove_unknown_tags (void *fdt,bool force_inplace, +int prop_offset,bool downgrade_version); +int fdt_getprop_offset_namelen (const void *fdt,int nodeoffset,const char *name,int namelen); static inline int fdt_getprop_offset(const void *fdt, int nodeoffset,tests/run_tests.sh +6
-0@@ -586,6 +586,34 @@ libfdt_tests () { unknown_tags_no_skip.dtb; do run_test check_full -n $bad done + + # Check inplace modification with "unknown" tags that can be skipped + dtb=unknown_tags_can_skip.wip.test.dtb + cp unknown_tags_can_skip.dtb $dtb + base_run_test wrap_fdtdump $dtb $dtb.0.out + # Remove unneeded header fields (keep those related to versions)Quoted 8 lines
tests/run_tests.sh libfdt_tests () { · line 596
Quoted 2 lines
tests/run_tests.sh +2
-0+ sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.0.out + base_run_test check_diff $dtb.0.out "$SRCDIR/$dtb.0.expect"As noted earlier in the series, tests of binary-level behaviour shouldn't depend on specific source formatting. The use of
wip_functo essentially do some of the test steps in shell seems clumsy to me - I think this would be nicer as explicit tests written in C which directly look at the binary dtb contents.Quoted 4 lines
I don't like that.
We need to check all the output dtb to be sure that everything is correct and avoid missing something.
Yes.. a C program can do that...
Quoted 2 lines
Here with unknown tag handling and with future metadata tags, we have to observe those tags in the binary blob.
Certainly.
Quoted 7 lines
Quoted 2 lines
If fdtdump is an issue, I will write fdtanalyze which dump a dtb blob in an other human readable format. We need to see all tags, and they raw data values an hex.
fdtdump is an issue - it's a sometimes-useful hack, not a tool to be relied on. What would probably make more sense here is a '
dtbs_equal_with_tags' or something, that performs a stricter comparison that the existingdtbs_equal_ordered.
dtbs_equal_with_tags will compare a binary against a binary. Also, looking at the dtbs_equal_ordered(), libfdt function are used to get informations. fdt_next_tag() is used.
I don't want to rely on libfdt to check that the binary blob is correct. I use libfdt to modify the binary blob, using also libfdt to check it can hide issues.
What I would like is a tool to transform the binary to something more human friendly without any use of libfdt functions and perform a diff between an expected file I can check myself (human friendly format) and a dtb generated by the test sequence and just converted to the human friendly format.
What do you think is wrong with this approach?
Quoted 51 lines
Quoted 51 lines
When I wrote the code, I did some mistake and using only binary files is really not easy to debug stuff. When a given test is broken by some modification, we need to have an easy way to see the root cause.
Quoted 45 lines
Quoted 30 lines
tests/run_tests.sh +22
-0+ run_test wip_func $dtb set_prop / prop-str 0 "vwxy" + base_run_test wrap_fdtdump $dtb $dtb.1.out + # Remove unneeded header fields (keep those related to versions) + sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.1.out + base_run_test check_diff $dtb.1.out "$SRCDIR/$dtb.1.expect" + + cp unknown_tags_can_skip.dtb $dtb + run_test wip_func $dtb nop_prop /subnode2 prop-int1 + base_run_test wrap_fdtdump $dtb $dtb.2.out + # Remove unneeded header fields (keep those related to versions) + sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.2.out + base_run_test check_diff $dtb.2.out "$SRCDIR/$dtb.2.expect" + + cp unknown_tags_can_skip.dtb $dtb + run_test wip_func $dtb nop_node /subnode2/subsubnode + base_run_test wrap_fdtdump $dtb $dtb.3.out + # Remove unneeded header fields (keep those related to versions) + sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.3.out + base_run_test check_diff $dtb.3.out "$SRCDIR/$dtb.3.expect" } dtc_tests () {@@ -1045,6 +1073,56 @@ fdtput_tests () { run_wrap_error_test $DTPUT $dtb -d /chosen non-existent-prop # TODO: Add tests for verbose mode? + + # Modify a dtb containing some "unknown" tags that can be skipped + dtb=unknown_tags_can_skip.fdtput.test.dtbtests/run_tests.sh fdtput_tests () { · line 1088
Quoted 10 lines
tests/run_tests.sh +10
-0+ cp unknown_tags_can_skip.dtb $dtb + base_run_test wrap_fdtdump $dtb $dtb.0.out + # Remove unneeded header fields (keep those related to versions) + sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.0.out + base_run_test check_diff $dtb.0.out "$SRCDIR/$dtb.0.expect" + run_fdtput_test "vwxyz" $dtb / prop-str -ts "vwxyz" + base_run_test wrap_fdtdump $dtb $dtb.1.out + # Remove unneeded header fields (keep those related to versions) + sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.1.out + base_run_test check_diff $dtb.1.out "$SRCDIR/$dtb.1.expect"Doing these as fdtput tests again seems kind of clumsy, unless the point is explicitly to check the fdtput utility's behaviour. The core library functionality should be tested directly without introducing extra layers.
Quoted 4 lines
Quoted 2 lines
Need to check the whole resulting binary skippable tags removed, version downgrade. We need to check that the whole binary is still correct.
Yes, but how does that relate to the use of fdtput?
fdtput is used to modify the dtb and so trigger the rules when unknown tags are involved. I see fdtput as a wrapper usable from a bash script. Nothing more.
No similar tools were available for fdt_wip.c functions. I introduced wip_func tools to wrap fdt_wip.c function and perform several tests consisting in different fdt_wip function call sequences.
Quoted 23 lines
Quoted 3 lines
'hexdump $dtb' could be used but having an array of hex value without any other formatting related to dtb defined format will be ugly.
Sure. Again, seems like what you want is a
dtbs_equal_with_tags.Quoted 16 lines
Here also fdtanalyzer could output hex values with some formating based on dtb format definition. For instance:
(0x1-FDT_BEGIN_NODE): "my_node"(0x3-FDT_PROP): ... (0x3-FDT_PROP): ...(0x2-FDT_END_NODE)
...
(0x9-FDT_END)Maybe offset (absolute and/or based on the beginning of the structure block) could also be interesting in this kind of dumps.
Best regards,
Hervé
Best regards,
Hervé
PATCH v3 15/15 Introduce v18 dtb version
In reply to Herve CodinaThis v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.
libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
- dt_flags header field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.
- last_comp_version_w header field.
This field is similar to last_comp_version but for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to a FDT_ERR_BADVERSION error.
For modification, when an unknown tag that can be skipped is involved and last_comp_version_w allows modifications, the following rules apply:
- When a property is modified, tags related to this property are removed and the dtb version is downgraded.
- When a property is removed, tags related to this property are obviously removed. The dtb version is kept unchanged.
- When a property or a node is added, obviously no unknown tags are added and the dtb version is kept unchanged.
- When a node is removed, tags related to this node are obviously removed. The dtb version is kept unchanged.
- Adding, removing or modifying a property is not considered as a node modification and so, those operations have no impacts on unknown tags related to the node. Those node related tags are kept unchanged.
- The only modification considered as a node modification is setting its name. We consider that this operation has no impact on tags related to the node. Here also, those node related tags and the dtb version are kept unchanged.
- Global (dtb related) unknown tags are kept unchanged regardless the modification done.
In all cases, if unknown tags are not involved in a modification, the dtb version is not downgraded when the modification is made.
It is worth noting that with this v18 version, the dtb version is not downgraded for any modification but only when unknown tags are removed due to a property modification. In v17 or older version any modification led to a dtb version downgrade.
--- dtc.h | 2 +- fdtdump.c | 8 ++- flattree.c | 37 ++++++++++--- libfdt/fdt.h | 5 ++ libfdt/fdt_rw.c | 20 +++++-- libfdt/fdt_sw.c | 3 ++ libfdt/libfdt.h | 7 ++- pylibfdt/libfdt.i | 18 +++++++ tests/Makefile.tests | 2 +- tests/dtflags_default.dtb.expect | 1 + tests/dtflags_default.dts | 10 ++++ tests/meson.build | 1 + tests/pylibfdt_tests.py | 10 ++-- tests/run_tests.sh | 42 ++++++++++----- tests/testutils.c | 2 +- tests/treegen.c | 53 +++++++++++++++++-- ...own_tags_can_skip.fdtput.test.dtb.0.expect | 1 + ...own_tags_can_skip.fdtput.test.dtb.1.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.2.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.3.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.4.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.5.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.6.expect | 3 +- ...nknown_tags_can_skip.wip.test.dtb.0.expect | 1 + ...nknown_tags_can_skip.wip.test.dtb.1.expect | 3 +- ...nknown_tags_can_skip.wip.test.dtb.2.expect | 1 + ...nknown_tags_can_skip.wip.test.dtb.3.expect | 1 + 27 files changed, 202 insertions(+), 44 deletions(-) create mode 100644 tests/dtflags_default.dtb.expect create mode 100644 tests/dtflags_default.dts
dtc.h +1 -1
@@ -29,7 +29,7 @@#define debug (...)#endif -#define DEFAULT_FDT_VERSION 17 +#define DEFAULT_FDT_VERSION 18/* * Command line options
fdtdump.c +7 -1
@@ -18,7 +18,7 @@#include "util.h" #define FDT_MAGIC_SIZE 4 -#define MAX_VERSION 17U +#define MAX_VERSION 18U#define ALIGN (x, a) (((x) + ((a) - 1)) & ~((a) - 1))#define PALIGN (p, a) ((void *)(ALIGN((uintptr_t)(p), (a))))
@@ -86,6 +86,12 @@ static void dump_blob(void *blob, bool debug, int dump_unknown)if (version >=17 )printf ("// size_dt_struct:\t0x%" PRIx32"\n" ,fdt32_to_cpu (bph->size_dt_struct)); +if (version >=18 ) { +printf ("// dt_flags:\t\t0x%" PRIx32"\n" , +fdt32_to_cpu (bph->dt_flags)); +printf ("// last_comp_version_w:\t%" PRIu32"\n" , +fdt32_to_cpu (bph->last_comp_version_w)); + }printf ("\n" );for (i =0 ; ; i++) {
flattree.c +30 -7
@@ -13,23 +13,29 @@#define FTF_STRTABSIZE 0x10#define FTF_STRUCTSIZE 0x20#define FTF_NOPS 0x40 +#define FTF_DTFLAGS 0x80 +#define FTF_LCVERSW 0x100static struct version_info {int version;int last_comp_version; +int last_comp_version_w;int hdr_size;int flags; } version_table[] = { - {1 ,1 ,FDT_V1_SIZE , + {1 ,1 ,0 ,FDT_V1_SIZE ,FTF_FULLPATH |FTF_VARALIGN |FTF_NAMEPROPS }, - {2 ,1 ,FDT_V2_SIZE , + {2 ,1 ,0 ,FDT_V2_SIZE ,FTF_FULLPATH |FTF_VARALIGN |FTF_NAMEPROPS |FTF_BOOTCPUID }, - {3 ,1 ,FDT_V3_SIZE , + {3 ,1 ,0 ,FDT_V3_SIZE ,FTF_FULLPATH |FTF_VARALIGN |FTF_NAMEPROPS |FTF_BOOTCPUID |FTF_STRTABSIZE }, - {16 ,16 ,FDT_V3_SIZE , + {16 ,16 ,0 ,FDT_V3_SIZE ,FTF_BOOTCPUID |FTF_STRTABSIZE |FTF_NOPS }, - {17 ,16 ,FDT_V17_SIZE , + {17 ,16 ,0 ,FDT_V17_SIZE ,FTF_BOOTCPUID |FTF_STRTABSIZE |FTF_STRUCTSIZE |FTF_NOPS }, + {18 ,16 ,17 ,FDT_V18_SIZE , +FTF_BOOTCPUID |FTF_STRTABSIZE |FTF_STRUCTSIZE |FTF_NOPS |FTF_DTFLAGS | +FTF_LCVERSW }, };struct emitter {
@@ -314,7 +320,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist,static void make_fdt_header (struct fdt_header *fdt,struct version_info *vi,int reservesize,int dtsize,int strsize, -int boot_cpuid_phys) +int boot_cpuid_phys,uint32_t dt_flags) {int reserve_off;
@@ -341,6 +347,10 @@ static void make_fdt_header(struct fdt_header *fdt, fdt->size_dt_strings =cpu_to_fdt32 (strsize);if (vi->flags &FTF_STRUCTSIZE ) fdt->size_dt_struct =cpu_to_fdt32 (dtsize); +if (vi->flags &FTF_DTFLAGS ) + fdt->dt_flags =cpu_to_fdt32 (dt_flags); +if (vi->flags &FTF_LCVERSW ) + fdt->last_comp_version_w =cpu_to_fdt32 (vi->last_comp_version_w); }void dt_to_blob (FILE *f,struct dt_info *dti,int version)
@@ -368,7 +378,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)/* Make header */ make_fdt_header (&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len, - dti->boot_cpuid_phys); + dti->boot_cpuid_phys,0 );/* * If the user asked for more space than is used, adjust the totalsize.
@@ -499,6 +509,16 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version) symprefix, symprefix); } +if (vi->flags &FTF_DTFLAGS ) { +fprintf (f,"\t/* dt_flags */\n" ); +asm_emit_cell (f,0 ); + } + +if (vi->flags &FTF_LCVERSW ) { +fprintf (f,"\t/* last_comp_version_w */\n" ); +asm_emit_cell (f, vi->last_comp_version_w); + } +/* * Reserve map entries. * Align the reserve map to a doubleword boundary.
@@ -955,6 +975,9 @@ struct dt_info *dt_from_blob(const char *fname) flags |=FTF_NOPS ; } +if (version >=18 ) + flags |=FTF_DTFLAGS |FTF_LCVERSW ; +inbuf_init (&memresvbuf, blob + off_mem_rsvmap, blob + totalsize);inbuf_init (&dtbuf, blob + off_dt, blob + totalsize);
libfdt/fdt.h +5 -0
@@ -26,6 +26,10 @@ struct fdt_header {/* version 17 fields below */ fdt32_t size_dt_struct;/* size of the structure block */ + +/* version 18 fields below */ +fdt32_t dt_flags;/* Ored value of FDT_FLAG_XXXX */ +fdt32_t last_comp_version_w;/* last compatible version for writing */ };struct fdt_reserve_entry {
@@ -85,5 +89,6 @@ struct fdt_property {#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))#define FDT_V16_SIZE FDT_V3_SIZE#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) +#define FDT_V18_SIZE (FDT_V17_SIZE + 2 * sizeof(fdt32_t))#endif /* FDT_H */
libfdt/fdt_rw.c +15 -5
@@ -34,13 +34,17 @@ static int fdt_rw_probe_(void *fdt)return 0 ;FDT_RO_PROBE (fdt); -if (!can_assume (LATEST ) &&fdt_version (fdt) <17 ) -return -FDT_ERR_BADVERSION ; +if (!can_assume (LATEST )) { +if (fdt_version (fdt) <17 ) +return -FDT_ERR_BADVERSION ; +else if (fdt_version (fdt) >=18 && +fdt_last_comp_version_w (fdt) >FDT_LAST_SUPPORTED_VERSION ) +return -FDT_ERR_BADVERSION ; + }if (fdt_blocks_misordered_ (fdt,sizeof (struct fdt_reserve_entry ),fdt_size_dt_struct (fdt)))return -FDT_ERR_BADLAYOUT ; -fdt_downgrade_version (fdt);return 0 ; }
@@ -624,7 +628,11 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize) err =fdt_move (fdt, buf, bufsize);if (err)return err; -fdt_set_version (buf,17 ); +if (can_assume (LATEST ) ||fdt_version (fdt) <18 ) { +fdt_set_version (buf,18 ); +fdt_set_dt_flags (buf,0 ); +fdt_set_last_comp_version_w (buf,17 ); + }fdt_set_size_dt_struct (buf, struct_size);fdt_set_totalsize (buf, bufsize);return 0 ;
@@ -653,8 +661,10 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)fdt_set_magic (buf,FDT_MAGIC );fdt_set_totalsize (buf, bufsize); -fdt_set_version (buf,17 ); +fdt_set_version (buf,18 );fdt_set_last_comp_version (buf,16 ); +fdt_set_dt_flags (buf,0 ); +fdt_set_last_comp_version_w (buf,17 );fdt_set_boot_cpuid_phys (buf,fdt_boot_cpuid_phys (fdt));return 0 ;
libfdt/fdt_sw.c +3 -0
@@ -137,6 +137,9 @@ int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags)fdt_set_off_dt_struct (fdt,fdt_off_mem_rsvmap (fdt));fdt_set_off_dt_strings (fdt,0 ); +fdt_set_dt_flags (fdt,0 ); +fdt_set_last_comp_version_w (fdt,FDT_LAST_COMPATIBLE_VERSION_W ); +return 0 ; }
libfdt/libfdt.h +6 -1
@@ -15,7 +15,8 @@ extern "C" {#define FDT_FIRST_SUPPORTED_VERSION 0x02#define FDT_LAST_COMPATIBLE_VERSION 0x10 -#define FDT_LAST_SUPPORTED_VERSION 0x11 +#define FDT_LAST_COMPATIBLE_VERSION_W 0x11 +#define FDT_LAST_SUPPORTED_VERSION 0x12/* Error codes: informative error codes */ #define FDT_ERR_NOTFOUND 1
@@ -284,6 +285,8 @@ int fdt_next_subnode(const void *fdt, int offset);#define fdt_boot_cpuid_phys (fdt) (fdt_get_header(fdt, boot_cpuid_phys))#define fdt_size_dt_strings (fdt) (fdt_get_header(fdt, size_dt_strings))#define fdt_size_dt_struct (fdt) (fdt_get_header(fdt, size_dt_struct)) +#define fdt_dt_flags (fdt) (fdt_get_header(fdt, dt_flags)) +#define fdt_last_comp_version_w (fdt) (fdt_get_header(fdt, last_comp_version_w))#define fdt_set_hdr_ (name) \ static inline void fdt_set_##name(void *fdt, uint32_t val) \
@@ -301,6 +304,8 @@ fdt_set_hdr_(last_comp_version) fdt_set_hdr_(boot_cpuid_phys) fdt_set_hdr_(size_dt_strings) fdt_set_hdr_(size_dt_struct) +fdt_set_hdr_(dt_flags) +fdt_set_hdr_(last_comp_version_w) #undef fdt_set_hdr_/**
pylibfdt/libfdt.i +18 -0
@@ -281,6 +281,22 @@ class FdtRo(object): """ return fdt_size_dt_struct(self._fdt) + def dt_flags(self): + """Return flags from the header + + Returns: + flags value from the header + """ + return fdt_dt_flags(self._fdt) + + def last_comp_version_w(self): + """Return the last compatible version for writing of the device tree + + Returns: + Last compatible version number for writing of the device tree + """ + return fdt_last_comp_version_w(self._fdt) + def num_mem_rsv(self, quiet=()): """Return the number of memory reserve-map records
@@ -1287,6 +1303,8 @@ uint32_t fdt_last_comp_version(const void *fdt); uint32_t fdt_boot_cpuid_phys(const void *fdt); uint32_t fdt_size_dt_strings(const void *fdt); uint32_t fdt_size_dt_struct(const void *fdt); +uint32_t fdt_dt_flags(const void *fdt); +uint32_t fdt_last_comp_version_w(const void *fdt); int fdt_property_string(void *fdt, const char *name, const char *val); int fdt_property_cell(void *fdt, const char *name, uint32_t val);
tests/Makefile.tests +1 -1
@@ -46,7 +46,7 @@ TESTS_TREES_L = test_tree1.dtb bad_node_char.dtb bad_node_format.dtb \ bad_prop_char.dtb ovf_size_strings.dtb truncated_property.dtb \ truncated_string.dtb truncated_memrsv.dtb unterminated_memrsv.dtb \ two_roots.dtb named_root.dtb unknown_tags_can_skip.dtb \ - unknown_tags_no_skip.dtb + unknown_tags_no_skip.dtb last_comp_version_w_future.dtb TESTS_TREES = $(TESTS_TREES_L:%=$(TESTS_PREFIX)%) TESTS_TARGETS = $(TESTS) $(TESTS_TREES)
tests/dtflags_default.dtb.expect new file +1 -0
@@ -0,0 +1 @@ +// dt_flags: 0x0
tests/dtflags_default.dts new file +10 -0
@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + prop = <1>; +};
tests/meson.build +1 -0
@@ -19,6 +19,7 @@ treegen_dtb = custom_target( 'named_root.dtb', 'unknown_tags_can_skip.dtb', 'unknown_tags_no_skip.dtb', + 'last_comp_version_w_future.dtb', ] )
tests/pylibfdt_tests.py +6 -4
@@ -274,14 +274,16 @@ class PyLibfdtBasicTests(unittest.TestCase): """Test that we can access the header values""" self.assertEqual(self.fdt.magic(), 0xd00dfeed) self.assertEqual(self.fdt.totalsize(), len(self.fdt._fdt)) - self.assertEqual(self.fdt.off_dt_struct(), 88) - self.assertEqual(self.fdt.off_dt_strings(), 652) - self.assertEqual(self.fdt.off_mem_rsvmap(), 40) - self.assertEqual(self.fdt.version(), 17) + self.assertEqual(self.fdt.off_dt_struct(), 96) + self.assertEqual(self.fdt.off_dt_strings(), 660) + self.assertEqual(self.fdt.off_mem_rsvmap(), 48) + self.assertEqual(self.fdt.version(), 18) self.assertEqual(self.fdt.last_comp_version(), 16) self.assertEqual(self.fdt.boot_cpuid_phys(), 0) self.assertEqual(self.fdt.size_dt_strings(), 105) self.assertEqual(self.fdt.size_dt_struct(), 564) + self.assertEqual(self.fdt.dt_flags(), 0) + self.assertEqual(self.fdt.last_comp_version_w(), 17) def testPack(self): """Test that we can pack the tree after deleting something"""
tests/run_tests.sh +30 -12
123 lines not on this page · raw message
tests/testutils.c +1 -1
@@ -354,7 +354,7 @@ void *open_blob_rw(const void *blob) {int err;void *buf; -int newsize =fdt_totalsize (blob) +8 ; +int newsize =fdt_totalsize (blob) +8 +2 *4 ; buf =xmalloc (newsize); err =fdt_open_into (blob, buf, newsize);
tests/treegen.c +49 -4
94 lines not on this page · raw message
tests/unknown_tags_can_skip.fdtput.test.dtb.0.expect +1 -0
@@ -1,6 +1,7 @@ /dts-v1/; // version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.fdtput.test.dtb.1.expect +2 -1
@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 18 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.fdtput.test.dtb.2.expect +2 -1
@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.fdtput.test.dtb.3.expect +2 -1
@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.fdtput.test.dtb.4.expect +2 -1
@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.fdtput.test.dtb.5.expect +2 -1
@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.fdtput.test.dtb.6.expect +2 -1
@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.wip.test.dtb.0.expect +1 -0
@@ -1,6 +1,7 @@ /dts-v1/; // version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.wip.test.dtb.1.expect +2 -1
@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 18 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.wip.test.dtb.2.expect +1 -0
@@ -1,6 +1,7 @@ /dts-v1/; // version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
tests/unknown_tags_can_skip.wip.test.dtb.3.expect +1 -0
@@ -1,6 +1,7 @@ /dts-v1/; // version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {
Signature · 1 line
2.55.0
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:
"last_comp_version_w allows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?
Quoted 2 lines
- When a property is modified, tags related to this property are removed and the dtb version is downgraded.
We need a definition of what "related to" means somewhere.
Quoted 5 lines
- When a property is removed, tags related to this property are obviously removed. The dtb version is kept unchanged.
- When a property or a node is added, obviously no unknown tags are added and the dtb version is kept unchanged.
Again, this rule doesn't make sense to me at the same time as the property modification rule.
Quoted 16 lines
- When a node is removed, tags related to this node are obviously removed. The dtb version is kept unchanged.
- Adding, removing or modifying a property is not considered as a node modification and so, those operations have no impacts on unknown tags related to the node. Those node related tags are kept unchanged.
- The only modification considered as a node modification is setting its name. We consider that this operation has no impact on tags related to the node. Here also, those node related tags and the dtb version are kept unchanged.
- Global (dtb related) unknown tags are kept unchanged regardless the modification done.
Quoted 7 lines
In all cases, if unknown tags are not involved in a modification, the dtb version is not downgraded when the modification is made.
It is worth noting that with this v18 version, the dtb version is not downgraded for any modification but only when unknown tags are removed due to a property modification. In v17 or older version any modification led to a dtb version downgrade.
I don't think removing that behaviour is safe. Even if the rules above make sense specifically for the metadata tags (which I'm not yet convinced of), that's not sufficient. If nothing else, future versions could add extra header fields. If we modify the tree, those header fields could be stale, or even removed.
Quoted 786 lines
Signed-off-by Herve Codina <[email protected]>Reviewed-by Frank Li <[email protected]>--- dtc.h | 2 +- fdtdump.c | 8 ++- flattree.c | 37 ++++++++++--- libfdt/fdt.h | 5 ++ libfdt/fdt_rw.c | 20 +++++-- libfdt/fdt_sw.c | 3 ++ libfdt/libfdt.h | 7 ++- pylibfdt/libfdt.i | 18 +++++++ tests/Makefile.tests | 2 +- tests/dtflags_default.dtb.expect | 1 + tests/dtflags_default.dts | 10 ++++ tests/meson.build | 1 + tests/pylibfdt_tests.py | 10 ++-- tests/run_tests.sh | 42 ++++++++++----- tests/testutils.c | 2 +- tests/treegen.c | 53 +++++++++++++++++-- ...own_tags_can_skip.fdtput.test.dtb.0.expect | 1 + ...own_tags_can_skip.fdtput.test.dtb.1.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.2.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.3.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.4.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.5.expect | 3 +- ...own_tags_can_skip.fdtput.test.dtb.6.expect | 3 +- ...nknown_tags_can_skip.wip.test.dtb.0.expect | 1 + ...nknown_tags_can_skip.wip.test.dtb.1.expect | 3 +- ...nknown_tags_can_skip.wip.test.dtb.2.expect | 1 + ...nknown_tags_can_skip.wip.test.dtb.3.expect | 1 + 27 files changed, 202 insertions(+), 44 deletions(-) create mode 100644 tests/dtflags_default.dtb.expect create mode 100644 tests/dtflags_default.dtsdtc.h +1
-1@@ -29,7 +29,7 @@#define debug (...)#endif -#define DEFAULT_FDT_VERSION 17 +#define DEFAULT_FDT_VERSION 18/* * Command line options fdtdump.c +7
-1@@ -18,7 +18,7 @@#include "util.h" #define FDT_MAGIC_SIZE 4 -#define MAX_VERSION 17U +#define MAX_VERSION 18U#define ALIGN (x, a) (((x) + ((a) - 1)) & ~((a) - 1))#define PALIGN (p, a) ((void *)(ALIGN((uintptr_t)(p), (a))))@@ -86,6 +86,12 @@ static void dump_blob(void *blob, bool debug, int dump_unknown)if (version >=17 )printf ("// size_dt_struct:\t0x%" PRIx32"\n" ,fdt32_to_cpu (bph->size_dt_struct)); +if (version >=18 ) { +printf ("// dt_flags:\t\t0x%" PRIx32"\n" , +fdt32_to_cpu (bph->dt_flags)); +printf ("// last_comp_version_w:\t%" PRIu32"\n" , +fdt32_to_cpu (bph->last_comp_version_w)); + }printf ("\n" );for (i =0 ; ; i++) {flattree.c +30
-7@@ -13,23 +13,29 @@#define FTF_STRTABSIZE 0x10#define FTF_STRUCTSIZE 0x20#define FTF_NOPS 0x40 +#define FTF_DTFLAGS 0x80 +#define FTF_LCVERSW 0x100static struct version_info {int version;int last_comp_version; +int last_comp_version_w;int hdr_size;int flags; } version_table[] = { - {1 ,1 ,FDT_V1_SIZE , + {1 ,1 ,0 ,FDT_V1_SIZE ,FTF_FULLPATH |FTF_VARALIGN |FTF_NAMEPROPS }, - {2 ,1 ,FDT_V2_SIZE , + {2 ,1 ,0 ,FDT_V2_SIZE ,FTF_FULLPATH |FTF_VARALIGN |FTF_NAMEPROPS |FTF_BOOTCPUID }, - {3 ,1 ,FDT_V3_SIZE , + {3 ,1 ,0 ,FDT_V3_SIZE ,FTF_FULLPATH |FTF_VARALIGN |FTF_NAMEPROPS |FTF_BOOTCPUID |FTF_STRTABSIZE }, - {16 ,16 ,FDT_V3_SIZE , + {16 ,16 ,0 ,FDT_V3_SIZE ,FTF_BOOTCPUID |FTF_STRTABSIZE |FTF_NOPS }, - {17 ,16 ,FDT_V17_SIZE , + {17 ,16 ,0 ,FDT_V17_SIZE ,FTF_BOOTCPUID |FTF_STRTABSIZE |FTF_STRUCTSIZE |FTF_NOPS }, + {18 ,16 ,17 ,FDT_V18_SIZE , +FTF_BOOTCPUID |FTF_STRTABSIZE |FTF_STRUCTSIZE |FTF_NOPS |FTF_DTFLAGS | +FTF_LCVERSW }, };struct emitter {@@ -314,7 +320,7 @@ static struct data flatten_reserve_list(struct reserve_info *reservelist,static void make_fdt_header (struct fdt_header *fdt,struct version_info *vi,int reservesize,int dtsize,int strsize, -int boot_cpuid_phys) +int boot_cpuid_phys,uint32_t dt_flags) {int reserve_off;@@ -341,6 +347,10 @@ static void make_fdt_header(struct fdt_header *fdt, fdt->size_dt_strings =cpu_to_fdt32 (strsize);if (vi->flags &FTF_STRUCTSIZE ) fdt->size_dt_struct =cpu_to_fdt32 (dtsize); +if (vi->flags &FTF_DTFLAGS ) + fdt->dt_flags =cpu_to_fdt32 (dt_flags); +if (vi->flags &FTF_LCVERSW ) + fdt->last_comp_version_w =cpu_to_fdt32 (vi->last_comp_version_w); }void dt_to_blob (FILE *f,struct dt_info *dti,int version)@@ -368,7 +378,7 @@ void dt_to_blob(FILE *f, struct dt_info *dti, int version)/* Make header */ make_fdt_header (&fdt, vi, reservebuf.len, dtbuf.len, strbuf.len, - dti->boot_cpuid_phys); + dti->boot_cpuid_phys,0 );/* * If the user asked for more space than is used, adjust the totalsize. @@ -499,6 +509,16 @@ void dt_to_asm(FILE *f, struct dt_info *dti, int version) symprefix, symprefix); } +if (vi->flags &FTF_DTFLAGS ) { +fprintf (f,"\t/* dt_flags */\n" ); +asm_emit_cell (f,0 ); + } + +if (vi->flags &FTF_LCVERSW ) { +fprintf (f,"\t/* last_comp_version_w */\n" ); +asm_emit_cell (f, vi->last_comp_version_w); + } +/* * Reserve map entries. * Align the reserve map to a doubleword boundary. @@ -955,6 +975,9 @@ struct dt_info *dt_from_blob(const char *fname) flags |=FTF_NOPS ; } +if (version >=18 ) + flags |=FTF_DTFLAGS |FTF_LCVERSW ; +inbuf_init (&memresvbuf, blob + off_mem_rsvmap, blob + totalsize);inbuf_init (&dtbuf, blob + off_dt, blob + totalsize);libfdt/fdt.h +5
-0@@ -26,6 +26,10 @@ struct fdt_header {/* version 17 fields below */ fdt32_t size_dt_struct;/* size of the structure block */ + +/* version 18 fields below */ +fdt32_t dt_flags;/* Ored value of FDT_FLAG_XXXX */ +fdt32_t last_comp_version_w;/* last compatible version for writing */ };struct fdt_reserve_entry {@@ -85,5 +89,6 @@ struct fdt_property {#define FDT_V3_SIZE (FDT_V2_SIZE + sizeof(fdt32_t))#define FDT_V16_SIZE FDT_V3_SIZE#define FDT_V17_SIZE (FDT_V16_SIZE + sizeof(fdt32_t)) +#define FDT_V18_SIZE (FDT_V17_SIZE + 2 * sizeof(fdt32_t))#endif /* FDT_H */ libfdt/fdt_rw.c +15
-5@@ -34,13 +34,17 @@ static int fdt_rw_probe_(void *fdt)return 0 ;FDT_RO_PROBE (fdt); -if (!can_assume (LATEST ) &&fdt_version (fdt) <17 ) -return -FDT_ERR_BADVERSION ; +if (!can_assume (LATEST )) { +if (fdt_version (fdt) <17 ) +return -FDT_ERR_BADVERSION ; +else if (fdt_version (fdt) >=18 && +fdt_last_comp_version_w (fdt) >FDT_LAST_SUPPORTED_VERSION ) +return -FDT_ERR_BADVERSION ; + }if (fdt_blocks_misordered_ (fdt,sizeof (struct fdt_reserve_entry ),fdt_size_dt_struct (fdt)))return -FDT_ERR_BADLAYOUT ; -fdt_downgrade_version (fdt);return 0 ; }@@ -624,7 +628,11 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize) err =fdt_move (fdt, buf, bufsize);if (err)return err; -fdt_set_version (buf,17 ); +if (can_assume (LATEST ) ||fdt_version (fdt) <18 ) { +fdt_set_version (buf,18 ); +fdt_set_dt_flags (buf,0 ); +fdt_set_last_comp_version_w (buf,17 ); + }fdt_set_size_dt_struct (buf, struct_size);fdt_set_totalsize (buf, bufsize);return 0 ;@@ -653,8 +661,10 @@ int fdt_open_into(const void *fdt, void *buf, int bufsize)fdt_set_magic (buf,FDT_MAGIC );fdt_set_totalsize (buf, bufsize); -fdt_set_version (buf,17 ); +fdt_set_version (buf,18 );fdt_set_last_comp_version (buf,16 ); +fdt_set_dt_flags (buf,0 ); +fdt_set_last_comp_version_w (buf,17 );fdt_set_boot_cpuid_phys (buf,fdt_boot_cpuid_phys (fdt));return 0 ;libfdt/fdt_sw.c +3
-0@@ -137,6 +137,9 @@ int fdt_create_with_flags(void *buf, int bufsize, uint32_t flags)fdt_set_off_dt_struct (fdt,fdt_off_mem_rsvmap (fdt));fdt_set_off_dt_strings (fdt,0 ); +fdt_set_dt_flags (fdt,0 ); +fdt_set_last_comp_version_w (fdt,FDT_LAST_COMPATIBLE_VERSION_W ); +return 0 ; }libfdt/libfdt.h +6
-1@@ -15,7 +15,8 @@ extern "C" {#define FDT_FIRST_SUPPORTED_VERSION 0x02#define FDT_LAST_COMPATIBLE_VERSION 0x10 -#define FDT_LAST_SUPPORTED_VERSION 0x11 +#define FDT_LAST_COMPATIBLE_VERSION_W 0x11 +#define FDT_LAST_SUPPORTED_VERSION 0x12/* Error codes: informative error codes */ #define FDT_ERR_NOTFOUND 1@@ -284,6 +285,8 @@ int fdt_next_subnode(const void *fdt, int offset);#define fdt_boot_cpuid_phys (fdt) (fdt_get_header(fdt, boot_cpuid_phys))#define fdt_size_dt_strings (fdt) (fdt_get_header(fdt, size_dt_strings))#define fdt_size_dt_struct (fdt) (fdt_get_header(fdt, size_dt_struct)) +#define fdt_dt_flags (fdt) (fdt_get_header(fdt, dt_flags)) +#define fdt_last_comp_version_w (fdt) (fdt_get_header(fdt, last_comp_version_w))#define fdt_set_hdr_ (name) \ static inline void fdt_set_##name(void *fdt, uint32_t val) \@@ -301,6 +304,8 @@ fdt_set_hdr_(last_comp_version) fdt_set_hdr_(boot_cpuid_phys) fdt_set_hdr_(size_dt_strings) fdt_set_hdr_(size_dt_struct) +fdt_set_hdr_(dt_flags) +fdt_set_hdr_(last_comp_version_w) #undef fdt_set_hdr_/** pylibfdt/libfdt.i +18
-0@@ -281,6 +281,22 @@ class FdtRo(object): """ return fdt_size_dt_struct(self._fdt) + def dt_flags(self): + """Return flags from the header + + Returns: + flags value from the header + """ + return fdt_dt_flags(self._fdt) + + def last_comp_version_w(self): + """Return the last compatible version for writing of the device tree + + Returns: + Last compatible version number for writing of the device tree + """ + return fdt_last_comp_version_w(self._fdt) + def num_mem_rsv(self, quiet=()): """Return the number of memory reserve-map records@@ -1287,6 +1303,8 @@ uint32_t fdt_last_comp_version(const void *fdt); uint32_t fdt_boot_cpuid_phys(const void *fdt); uint32_t fdt_size_dt_strings(const void *fdt); uint32_t fdt_size_dt_struct(const void *fdt); +uint32_t fdt_dt_flags(const void *fdt); +uint32_t fdt_last_comp_version_w(const void *fdt); int fdt_property_string(void *fdt, const char *name, const char *val); int fdt_property_cell(void *fdt, const char *name, uint32_t val);tests/Makefile.tests +1
-1@@ -46,7 +46,7 @@ TESTS_TREES_L = test_tree1.dtb bad_node_char.dtb bad_node_format.dtb \ bad_prop_char.dtb ovf_size_strings.dtb truncated_property.dtb \ truncated_string.dtb truncated_memrsv.dtb unterminated_memrsv.dtb \ two_roots.dtb named_root.dtb unknown_tags_can_skip.dtb \ - unknown_tags_no_skip.dtb + unknown_tags_no_skip.dtb last_comp_version_w_future.dtb TESTS_TREES = $(TESTS_TREES_L:%=$(TESTS_PREFIX)%) TESTS_TARGETS = $(TESTS) $(TESTS_TREES)tests/dtflags_default.dtb.expect new file +1
-0@@ -0,0 +1 @@ +// dt_flags: 0x0tests/dtflags_default.dts new file +10
-0@@ -0,0 +1,10 @@ +// SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) +/* + * Copyright (C) 2026 Bootlin + */ + +/dts-v1/; + +/ { + prop = <1>; +};tests/meson.build +1
-0@@ -19,6 +19,7 @@ treegen_dtb = custom_target( 'named_root.dtb', 'unknown_tags_can_skip.dtb', 'unknown_tags_no_skip.dtb', + 'last_comp_version_w_future.dtb', ] )tests/pylibfdt_tests.py +6
-4@@ -274,14 +274,16 @@ class PyLibfdtBasicTests(unittest.TestCase): """Test that we can access the header values""" self.assertEqual(self.fdt.magic(), 0xd00dfeed) self.assertEqual(self.fdt.totalsize(), len(self.fdt._fdt)) - self.assertEqual(self.fdt.off_dt_struct(), 88) - self.assertEqual(self.fdt.off_dt_strings(), 652) - self.assertEqual(self.fdt.off_mem_rsvmap(), 40) - self.assertEqual(self.fdt.version(), 17) + self.assertEqual(self.fdt.off_dt_struct(), 96) + self.assertEqual(self.fdt.off_dt_strings(), 660) + self.assertEqual(self.fdt.off_mem_rsvmap(), 48) + self.assertEqual(self.fdt.version(), 18) self.assertEqual(self.fdt.last_comp_version(), 16) self.assertEqual(self.fdt.boot_cpuid_phys(), 0) self.assertEqual(self.fdt.size_dt_strings(), 105) self.assertEqual(self.fdt.size_dt_struct(), 564) + self.assertEqual(self.fdt.dt_flags(), 0) + self.assertEqual(self.fdt.last_comp_version_w(), 17) def testPack(self): """Test that we can pack the tree after deleting something"""tests/run_tests.sh +30
-12@@ -578,7 +578,8 @@ libfdt_tests () { run_test dtbs_equal_ordered cell-overflow.test.dtb cell-overflow-results.test.dtb # check full tests - for good in test_tree1.dtb unknown_tags_can_skip.dtb; do + for good in test_tree1.dtb unknown_tags_can_skip.dtb \ + last_comp_version_w_future.dtb; do run_test check_full $good done for bad in truncated_property.dtb truncated_string.dtb \@@ -592,27 +593,27 @@ libfdt_tests () { cp unknown_tags_can_skip.dtb $dtb base_run_test wrap_fdtdump $dtb $dtb.0.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.0.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.0.out base_run_test check_diff $dtb.0.out "$SRCDIR/$dtb.0.expect" run_test wip_func $dtb set_prop / prop-str 0 "vwxy" base_run_test wrap_fdtdump $dtb $dtb.1.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.1.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.1.out base_run_test check_diff $dtb.1.out "$SRCDIR/$dtb.1.expect" cp unknown_tags_can_skip.dtb $dtb run_test wip_func $dtb nop_prop /subnode2 prop-int1 base_run_test wrap_fdtdump $dtb $dtb.2.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.2.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.2.out base_run_test check_diff $dtb.2.out "$SRCDIR/$dtb.2.expect" cp unknown_tags_can_skip.dtb $dtb run_test wip_func $dtb nop_node /subnode2/subsubnode base_run_test wrap_fdtdump $dtb $dtb.3.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.3.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.3.out base_run_test check_diff $dtb.3.out "$SRCDIR/$dtb.3.expect" }@@ -917,6 +918,14 @@ dtc_tests () { run_dtc_test -I dtb -O dts -o unknown_tags_can_skip.dtb.dts unknown_tags_can_skip.dtb base_run_test check_diff unknown_tags_can_skip.dtb.dts "$SRCDIR/unknown_tags_can_skip.dtb.dts.expect" run_wrap_error_test $DTC -I dtb -O dts -o unknown_tags_no_skip.dtb.dts unknown_tags_no_skip.dtb + + # Tests dt_flags header field (default value) + run_dtc_test -I dts -O dtb -o dtflags_default.dtb "$SRCDIR/dtflags_default.dts" + base_run_test wrap_fdtdump dtflags_default.dtb dtflags_default.dtb.out + # Keep only lines containing 'dt_flags' + sed -i '/dt_flags/!d' dtflags_default.dtb.out + base_run_test check_diff dtflags_default.dtb.out "$SRCDIR/dtflags_default.dtb.expect" + run_test check_full dtflags_default.dtb } cmp_tests () {@@ -1074,32 +1083,41 @@ fdtput_tests () { # TODO: Add tests for verbose mode? + # Not allowed to modify a dtb due to last_comp_version_w + # FDT_ERR_BADVERSION error code is returned + dtb=last_comp_version_w_future.fdtput.test.dtb + cp last_comp_version_w_future.dtb $dtb + run_wrap_error_test $DTPUT $dtb /subnode prop-int -tu 123 + run_wrap_error_test $DTPUT $dtb -d /subnode prop-int + run_wrap_error_test $DTPUT $dtb -c /new-node + run_wrap_error_test $DTPUT $dtb -r /subnode + # Modify a dtb containing some "unknown" tags that can be skipped dtb=unknown_tags_can_skip.fdtput.test.dtb cp unknown_tags_can_skip.dtb $dtb base_run_test wrap_fdtdump $dtb $dtb.0.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.0.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.0.out base_run_test check_diff $dtb.0.out "$SRCDIR/$dtb.0.expect" run_fdtput_test "vwxyz" $dtb / prop-str -ts "vwxyz" base_run_test wrap_fdtdump $dtb $dtb.1.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.1.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.1.out base_run_test check_diff $dtb.1.out "$SRCDIR/$dtb.1.expect" cp unknown_tags_can_skip.dtb $dtb run_wrap_test $DTPUT $dtb -c /tst-fdtput base_run_test wrap_fdtdump $dtb $dtb.2.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.2.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.2.out base_run_test check_diff $dtb.2.out "$SRCDIR/$dtb.2.expect" run_wrap_test $DTPUT $dtb -c /tst-fdtput/n1 /tst-fdtput/n2 /tst-fdtput/n3 run_wrap_test $DTPUT $dtb -r /tst-fdtput/n1 /tst-fdtput/n3 run_fdtget_test "n2" $dtb -l /tst-fdtput base_run_test wrap_fdtdump $dtb $dtb.3.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.3.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.3.out base_run_test check_diff $dtb.3.out "$SRCDIR/$dtb.3.expect" cp unknown_tags_can_skip.dtb $dtb@@ -1107,21 +1125,21 @@ fdtput_tests () { run_fdtget_test "prop-int" $dtb -p / base_run_test wrap_fdtdump $dtb $dtb.4.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.4.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.4.out base_run_test check_diff $dtb.4.out "$SRCDIR/$dtb.4.expect" cp unknown_tags_can_skip.dtb $dtb run_wrap_test $DTPUT $dtb /subnode2 prop-tst-fdtput -ts "Test fdtput" base_run_test wrap_fdtdump $dtb $dtb.5.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.5.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.5.out base_run_test check_diff $dtb.5.out "$SRCDIR/$dtb.5.expect" cp unknown_tags_can_skip.dtb $dtb run_wrap_test $DTPUT $dtb -r /subnode2/subsubnode base_run_test wrap_fdtdump $dtb $dtb.6.out # Remove unneeded header fields (keep those related to versions) - sed -i '/^\/.*\(magic\|off\|size\|cpu\)/d' $dtb.6.out + sed -i '/^\/.*\(magic\|off\|size\|cpu\|flags\)/d' $dtb.6.out base_run_test check_diff $dtb.6.out "$SRCDIR/$dtb.6.expect" }tests/testutils.c +1
-1@@ -354,7 +354,7 @@ void *open_blob_rw(const void *blob) {int err;void *buf; -int newsize =fdt_totalsize (blob) +8 ; +int newsize =fdt_totalsize (blob) +8 +2 *4 ; buf =xmalloc (newsize); err =fdt_open_into (blob, buf, newsize);tests/treegen.c +49
-4@@ -106,7 +106,8 @@ static void fill_prop_name(struct buf *b, size_t strs, size_t prop, size_t strof/* FDT structure helpers */ static size_t emit_fdt_header_vers (struct buf *b,uint32_t version, -uint32_t last_comp_version) +uint32_t last_comp_version, +uint32_t last_comp_version_w) {size_t off =emit_u32 (b,FDT_MAGIC );@@ -119,12 +120,14 @@ static size_t emit_fdt_header_vers(struct buf *b, uint32_t version,emit_u32 (b,0 );/* boot_cpuid_phys */ emit_u32 (b,0 );/* size_dt_strings */ emit_u32 (b,0 );/* size_dt_struct */ +emit_u32 (b,0 );/* dt_flags */ +emit_u32 (b, last_comp_version_w);/* last_comp_version_w */ return off; }static size_t emit_fdt_header (struct buf *b) { -return emit_fdt_header_vers (b,0x11 ,0x10 ); +return emit_fdt_header_vers (b,0x12 ,0x10 ,0x11 ); }static void finish_rsvmap (struct buf *b,size_t hdr,size_t rsvmap)@@ -720,7 +723,7 @@ static struct buf make_unknown_tags_can_skip(void)size_t p_sn2_int1, p_sn2_int2;size_t p_sn2ssn_bool; - hdr =emit_fdt_header_vers (&b,0xffffffff ,0x10 ); + hdr =emit_fdt_header_vers (&b,0xffffffff ,0x10 ,0x11 );emit_align (&b,8 );emit_rsvmap_empty (&b, hdr);@@ -833,7 +836,7 @@ static struct buf make_unknown_tags_no_skip(void)size_t hdr;size_t p_prop_u64; - hdr =emit_fdt_header_vers (&b,0xffffffff ,0x10 ); + hdr =emit_fdt_header_vers (&b,0xffffffff ,0x10 ,0x11 );emit_align (&b,8 );emit_rsvmap_empty (&b, hdr);@@ -867,6 +870,47 @@ static struct buf make_unknown_tags_no_skip(void)return b; } +/* Tree with "unknown" tags that can be skipped +* Use a really future dtb version to check version downgrade on +* modification. +*/ +static struct buf make_last_comp_version_w_future (void ) +{ +struct buf b =buf_init (); +size_t hdr; +size_t p_int; + + hdr =emit_fdt_header_vers (&b,0xffffffff ,0x10 ,0xffffffff ); +emit_align (&b,8 ); + +emit_rsvmap_empty (&b, hdr); + + { +size_t ss =start_block (&b); + +emit_begin_node (&b,"" ); + p_int =emit_prop_u64 (&b,0 ,0x100000002 ); +emit_end_node (&b); +emit_fdt_end (&b); + +finish_struct_block (&b, hdr, ss); + } + + { +size_t strs =start_block (&b); +size_t s; + + s =emit_string (&b,"prop-int" ); +fill_prop_name (&b, strs, p_int, s); + +finish_strings_block (&b, hdr, strs); + } + +finish_totalsize (&b, hdr); + +return b; +} +/* Tree table and main */ static struct {@@ -884,6 +928,7 @@ static struct {TREE (named_root),TREE (unknown_tags_can_skip),TREE (unknown_tags_no_skip), + TREE(last_comp_version_w_future), };int main (int argc,char *argv[])tests/unknown_tags_can_skip.fdtput.test.dtb.0.expect +1
-0@@ -1,6 +1,7 @@ /dts-v1/; // version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.fdtput.test.dtb.1.expect +2
-1@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 18 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.fdtput.test.dtb.2.expect +2
-1@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.fdtput.test.dtb.3.expect +2
-1@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.fdtput.test.dtb.4.expect +2
-1@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.fdtput.test.dtb.5.expect +2
-1@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.fdtput.test.dtb.6.expect +2
-1@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.wip.test.dtb.0.expect +1
-0@@ -1,6 +1,7 @@ /dts-v1/; // version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.wip.test.dtb.1.expect +2
-1@@ -1,6 +1,7 @@ /dts-v1/; -// version: 17 +// version: 18 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.wip.test.dtb.2.expect +1
-0@@ -1,6 +1,7 @@ /dts-v1/; // version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {tests/unknown_tags_can_skip.wip.test.dtb.3.expect +1
-0@@ -1,6 +1,7 @@ /dts-v1/; // version: 4294967295 // last_comp_version: 16 +// last_comp_version_w: 17 // Unknown tag ignored: 0xd0000000, data len 4 00000001 / {Signature · 1 line
2.55.0
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.
Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?
We had one last_comp_version.
Now we have two last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.
This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Quoted 5 lines
Quoted 3 lines
- When a property is modified, tags related to this property are removed and the dtb version is downgraded.
We need a definition of what "related to" means somewhere.
Yes a tag is said related to a property if it is available after its FDT_PROP and before the next FDT_PROP (other proterty) of FDT_BEGIN_NODE (subnode) for FDT_NODE_END (end of node).
This is defined by "structured tag"
Devicetree Specification will be updated to have all of this documentation available.
Quoted 9 lines
Quoted 6 lines
- When a property is removed, tags related to this property are obviously removed. The dtb version is kept unchanged.
- When a property or a node is added, obviously no unknown tags are added and the dtb version is kept unchanged.
Again, this rule doesn't make sense to me at the same time as the property modification rule.
A current libfdt/dtc version cannot add tags which will be defined in the future.
Quoted 25 lines
Quoted 17 lines
- When a node is removed, tags related to this node are obviously removed. The dtb version is kept unchanged.
- Adding, removing or modifying a property is not considered as a node modification and so, those operations have no impacts on unknown tags related to the node. Those node related tags are kept unchanged.
- The only modification considered as a node modification is setting its name. We consider that this operation has no impact on tags related to the node. Here also, those node related tags and the dtb version are kept unchanged.
- Global (dtb related) unknown tags are kept unchanged regardless the modification done.
Quoted 7 lines
In all cases, if unknown tags are not involved in a modification, the dtb version is not downgraded when the modification is made.
It is worth noting that with this v18 version, the dtb version is not downgraded for any modification but only when unknown tags are removed due to a property modification. In v17 or older version any modification led to a dtb version downgrade.
Quoted 5 lines
I don't think removing that behaviour is safe. Even if the rules above make sense specifically for the metadata tags (which I'm not yet convinced of), that's not sufficient. If nothing else, future versions could add extra header fields. If we modify the tree, those header fields could be stale, or even removed.
last_comp_version_w will be used by the future version to prevent this kind of issue with old version.
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 38 lines · Herve Codina
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?
Quoted 8 lines
We had one
last_comp_version.Now we have two
last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Ok, I now see that the logic is you simply fail to proceed with writes if the library's latest understood version is < last_comp_version_w.
As I said elsewhere, this approach doesn't particularly make sense to me. If lib_version >= last_comp_version you *can* write, even if it means stripping everything that's not understood at lib_version.
So the real question here is how do we know, for any given structured tag, what write operations require the version to be downgraded (which might in turn require this and/or other structured tags to be stripped entirely).
This is related to (though not the same as) the question of whether introducing a new structured tags requires a bump to the dtb version (though not to last_comp_version, of course).
Here's the simplest model I can think of. It's what I'd suggest, unless one of it's limitations is a showstopper for what you have in mind:
- version and last_comp_version retain their meanings. No new header version.
- New structured tags *do* require a new version. If a dtb wants to include a specific tag, it must label itself with a version that defines that tag. To enforce that:
- For read operations, if we encounter a (known) tag that doesn't belong in the header version, we throw an error (either BADSTRUCTURE, or a new error for the purpose).
- If version <= FDT_LAST_SUPPORTED_VERSION and we encounter an unknown tag that also trips the error (since if it was defined in this version, we should know about it).
- For write operations (including in-place), we always error if version > FDT_LAST_SUPPORTED_VERSION (done in fdt_rw_probe_()).
- fdt_open_into() _is_ permitted if version > FDT_LAST_SUPPORTED_VERSION. It will strip all unknown structured tags from the entire tree and downgrade the version to FDT_LAST_SUPPORTED_VERSION.
This does mean that every new tag does require a new version, which may make experimenting with new tags more awkward. More significantly, it also means that any change requires a version downgrade, even if it's just updating a handful of properties.
On the plus side, it's fairly simple, retains as much as possible current version semantics. Most especially there's no tricky questions about what sorts of writes might invalidate an unknown tag (they'll all be stripped by the time we permit a write operation).
If those limitations really are a showstopper, I do have a few other models that might work, though.
Quoted 5 lines
Quoted 4 lines
Quoted 2 lines
- When a property is modified, tags related to this property are removed and the dtb version is downgraded.
We need a definition of what "related to" means somewhere.
Quoted 8 lines
Yes a tag is said related to a property if it is available after its
FDT_PROPand before the nextFDT_PROP(other proterty) ofFDT_BEGIN_NODE(subnode) forFDT_NODE_END(end of node).This is defined by "structured tag"
Devicetree Specification will be updated to have all of this documentation available.
Ok.
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
- When a property is removed, tags related to this property are obviously removed. The dtb version is kept unchanged.
- When a property or a node is added, obviously no unknown tags are added and the dtb version is kept unchanged.
Again, this rule doesn't make sense to me at the same time as the property modification rule.
A current libfdt/dtc version cannot add tags which will be defined in the future.
Sure, but it can still add whole new nodes or properties. The question is whether a version can mandate the presence of certain tags. Dowgrading the version when we strip tags from a modified property suggests "yes", but _not_ downgrading the version when we add new property suggests "no".
Quoted 37 lines
Quoted 24 lines
Quoted 16 lines
- When a node is removed, tags related to this node are obviously removed. The dtb version is kept unchanged.
- Adding, removing or modifying a property is not considered as a node modification and so, those operations have no impacts on unknown tags related to the node. Those node related tags are kept unchanged.
- The only modification considered as a node modification is setting its name. We consider that this operation has no impact on tags related to the node. Here also, those node related tags and the dtb version are kept unchanged.
- Global (dtb related) unknown tags are kept unchanged regardless the modification done.
Quoted 7 lines
In all cases, if unknown tags are not involved in a modification, the dtb version is not downgraded when the modification is made.
It is worth noting that with this v18 version, the dtb version is not downgraded for any modification but only when unknown tags are removed due to a property modification. In v17 or older version any modification led to a dtb version downgrade.
Quoted 5 lines
I don't think removing that behaviour is safe. Even if the rules above make sense specifically for the metadata tags (which I'm not yet convinced of), that's not sufficient. If nothing else, future versions could add extra header fields. If we modify the tree, those header fields could be stale, or even removed.
last_comp_version_wwill be used by the future version to prevent this kind of issue with old version.Best regards,
Hervé
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David, Rob,
Quoted 51 lines · On Tue, 13 Oct 2026 18:10:39 +1100 David Gibson <[email protected]>…
Quoted 38 lines · Herve Codina
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?Quoted 8 lines
We had one
last_comp_version.Now we have two
last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Ok, I now see that the logic is you simply fail to proceed with writes if the library's latest understood version is <
last_comp_version_w.
Quoted 8 lines
As I said elsewhere, this approach doesn't particularly make sense to me. If
lib_version>=last_comp_versionyou *can* write, even if it means stripping everything that's not understood atlib_version.So the real question here is how do we know, for any given structured tag, what write operations require the version to be downgraded (which might in turn require this and/or other structured tags to be stripped entirely).
The rules is well known. An old libfdt version will strip the tag and downgrade the version. If, when we define a new tags this rules cannot be follow by olf libfdt version, last_comp_version_w will be set to protect against modification.
Maybe the problem is just downgrading the version.
Instead of downgrading it could be better if we mark the dtb "one or more 'unknown' tags have been removed due to a write by an old libfdt version" ?
We have a dt_flags header field. We can dedicate one bit for this marker.
Could it make sense ?
Quoted 30 lines
This is related to (though not the same as) the question of whether introducing a new structured tags requires a bump to the dtb version (though not to
last_comp_version, of course).Here's the simplest model I can think of. It's what I'd suggest, unless one of it's limitations is a showstopper for what you have in mind:
- version and
last_comp_versionretain their meanings. No new header version.
- New structured tags *do* require a new version. If a dtb wants to include a specific tag, it must label itself with a version that defines that tag. To enforce that:
- For read operations, if we encounter a (known) tag that doesn't belong in the header version, we throw an error (either BADSTRUCTURE, or a new error for the purpose).
- If version <=FDT_LAST_SUPPORTED_VERSIONand we encounter an unknown tag that also trips the error (since if it was defined in this version, we should know about it).
- For write operations (including in-place), we always error if version >FDT_LAST_SUPPORTED_VERSION(done infdt_rw_probe_()).
-fdt_open_into()_is_ permitted if version >FDT_LAST_SUPPORTED_VERSION. It will strip all unknown structured tags from the entire tree and downgrade the version toFDT_LAST_SUPPORTED_VERSION.This does mean that every new tag does require a new version, which may make experimenting with new tags more awkward. More significantly, it also means that any change requires a version downgrade, even if it's just updating a handful of properties.
Quoted 7 lines
On the plus side, it's fairly simple, retains as much as possible current version semantics. Most especially there's no tricky questions about what sorts of writes might invalidate an unknown tag (they'll all be stripped by the time we permit a write operation).
If those limitations really are a showstopper, I do have a few other models that might work, though.
The use case we want to support (initially mentioned by Rob) can be summarize in the following.
Assume:
- bootloader: supported version 2.0
- kernel: supported version 3.0
- dtb version 3.0: New tags, skippable but unknown in version 2.0
The bootloader has to modify the dtb version 3.0. I has to add nodes such as 'choosen', 'memory', 'reserved-memory', plus probably modify some others properties (usual fixup() stuff).
Then it passes this dtb to the kernel.
This bootloader (version 2.0) will encounter unknown tags. We don't want the bootloader stops in that case and we just want him to do the best it can do ending to pass the dtb to the kernel.
Indeed, if this bootloader writes a property with an unknown related tag, it has to handle this unknwon related tag (rules already exposed).
When the dtb version 3.0 has defined new tags, the rules related to modification performed are well known and several thinks can be done to avoid the old bootloader applying modification rules.
- The tag is not skippable
Game over for the old bootloader, an error is reported if the tag is found
- last_comp_version_w
Game over for the old bootloader, modification not allowed.
In that case, the only solution is to bump the bootloader version.
Quoted 26 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
- When a property is modified, tags related to this property are removed and the dtb version is downgraded.
We need a definition of what "related to" means somewhere.
Quoted 8 lines
Yes a tag is said related to a property if it is available after its
FDT_PROPand before the nextFDT_PROP(other proterty) ofFDT_BEGIN_NODE(subnode) forFDT_NODE_END(end of node).This is defined by "structured tag"
Devicetree Specification will be updated to have all of this documentation available.
Ok.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
- When a property is removed, tags related to this property are obviously removed. The dtb version is kept unchanged.
- When a property or a node is added, obviously no unknown tags are added and the dtb version is kept unchanged.
Again, this rule doesn't make sense to me at the same time as the property modification rule.
Quoted 8 lines
Quoted 2 lines
A current libfdt/dtc version cannot add tags which will be defined in the future.
Sure, but it can still add whole new nodes or properties. The question is whether a version can mandate the presence of certain tags. Dowgrading the version when we strip tags from a modified property suggests "yes", but _not_ downgrading the version when we add new property suggests "no".
If the version mandate some tags on nodes and properties, last_comp_version_w will be used to block old bootloaders. They are not more allowed to modify the dtb. They need to be bumped to newer versions.
Quoted 31 lines
Quoted 31 lines
Quoted 30 lines
Quoted 17 lines
- When a node is removed, tags related to this node are obviously removed. The dtb version is kept unchanged.
- Adding, removing or modifying a property is not considered as a node modification and so, those operations have no impacts on unknown tags related to the node. Those node related tags are kept unchanged.
- The only modification considered as a node modification is setting its name. We consider that this operation has no impact on tags related to the node. Here also, those node related tags and the dtb version are kept unchanged.
- Global (dtb related) unknown tags are kept unchanged regardless the modification done.
Quoted 7 lines
In all cases, if unknown tags are not involved in a modification, the dtb version is not downgraded when the modification is made.
It is worth noting that with this v18 version, the dtb version is not downgraded for any modification but only when unknown tags are removed due to a property modification. In v17 or older version any modification led to a dtb version downgrade.
I don't think removing that behaviour is safe. Even if the rules above make sense specifically for the metadata tags (which I'm not yet convinced of), that's not sufficient. If nothing else, future versions could add extra header fields. If we modify the tree, those header fields could be stale, or even removed.
Quoted 3 lines
Quoted 3 lines
last_comp_version_wwill be used by the future version to prevent this kind of issue with old version.
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 60 lines · Herve Codina
Hi David, Rob,
Quoted 55 lines · On Tue, 13 Oct 2026 18:10:39 +1100 David Gibson <[email protected]>…
Quoted 38 lines · Herve Codina
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?Quoted 8 lines
We had one
last_comp_version.Now we have two
last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Ok, I now see that the logic is you simply fail to proceed with writes if the library's latest understood version is <
last_comp_version_w.As I said elsewhere, this approach doesn't particularly make sense to me. If
lib_version>=last_comp_versionyou *can* write, even if it means stripping everything that's not understood atlib_version.
Quoted 6 lines
Quoted 4 lines
So the real question here is how do we know, for any given structured tag, what write operations require the version to be downgraded (which might in turn require this and/or other structured tags to be stripped entirely).
The rules is well known.
I really don't think they are. You've proposed one set of rules (as code) - although I don't think they quite make sense. I've proposed another. Other variants are possible.
Quoted 5 lines
An old libfdt version will strip the tag and
downgrade the version. If, when we define a new tags this rules cannot be follow by olf libfdt version,last_comp_version_wwill be set to protect against modification.
Quoted 8 lines
Maybe the problem is just downgrading the version.
Instead of downgrading it could be better if we mark the dtb "one or more 'unknown' tags have been removed due to a write by an old libfdt version" ?
We have a
dt_flagsheader field. We can dedicate one bit for this marker.Could it make sense ?
I really dislike this idea. It means we effectively have at least two variants of every version which strikes me as pretty confusing.
Quoted 49 lines
Quoted 29 lines
This is related to (though not the same as) the question of whether introducing a new structured tags requires a bump to the dtb version (though not to
last_comp_version, of course).Here's the simplest model I can think of. It's what I'd suggest, unless one of it's limitations is a showstopper for what you have in mind:
- version and
last_comp_versionretain their meanings. No new header version.
- New structured tags *do* require a new version. If a dtb wants to include a specific tag, it must label itself with a version that defines that tag. To enforce that:
- For read operations, if we encounter a (known) tag that doesn't belong in the header version, we throw an error (either BADSTRUCTURE, or a new error for the purpose).
- If version <=FDT_LAST_SUPPORTED_VERSIONand we encounter an unknown tag that also trips the error (since if it was defined in this version, we should know about it).
- For write operations (including in-place), we always error if version >FDT_LAST_SUPPORTED_VERSION(done infdt_rw_probe_()).
-fdt_open_into()_is_ permitted if version >FDT_LAST_SUPPORTED_VERSION. It will strip all unknown structured tags from the entire tree and downgrade the version toFDT_LAST_SUPPORTED_VERSION.This does mean that every new tag does require a new version, which may make experimenting with new tags more awkward. More significantly, it also means that any change requires a version downgrade, even if it's just updating a handful of properties.
Quoted 7 lines
On the plus side, it's fairly simple, retains as much as possible current version semantics. Most especially there's no tricky questions about what sorts of writes might invalidate an unknown tag (they'll all be stripped by the time we permit a write operation).
If those limitations really are a showstopper, I do have a few other models that might work, though.
The use case we want to support (initially mentioned by Rob) can be summarize in the following.
Assume:
- bootloader: supported version 2.0
- kernel: supported version 3.0
- dtb version 3.0: New tags, skippable but unknown in version 2.0The bootloader has to modify the dtb version 3.0. I has to add nodes such as 'choosen', 'memory', 'reserved-memory', plus probably modify some others properties (usual
fixup()stuff).
Quoted 5 lines
Then it passes this dtb to the kernel.
This bootloader (version 2.0) will encounter unknown tags. We don't want the bootloader stops in that case and we just want him to do the best it can do ending to pass the dtb to the kernel.
With my proposal it won't stop in this case, but it will downgrade the dtb to version 2.0, denying the kernel the use of any 3.0 features.
I can see why that's undesirable, but allowing modifications without stripping unknown tags requires some very careful consideration. In fact I don't think it's possible without adding more bits to the structured tag definition to indicate what changes will invalidate the tag.
For example, take a tag indicating that part of a property represents a phandle (I believe you'll need something like this for addons). In order to rely on this tag the consumer which needs it will generally need to know that *every* phandle is marked with such a tag. So, suppose vZZZ requires this tag be present for every phandle.
A bootloader which only supports vYYY, not vZZZ _must_ downgrade if it modifies or adds any properties, because it could break the vZZZ constraint that every phandle must be tagger.
Some other tags might be safer, they're always optional and can be safely stripped from a modified property. But if the bootloader doesn't know the specific tag, the only way it could know this is if we encode it into the structured tag itself.
Quoted 2 lines
Indeed, if this bootloader writes a property with an unknown related tag, it has to handle this unknwon related tag (rules already exposed).
Right, but it also has to handle the case of adding a new property, because it can't know if v<future> might require certain future tags.
Quoted 2 lines
When the dtb version 3.0 has defined new tags, the rules related to modification performed are well known
They're really not. You've proposed a set, but I don't think they're adequate for some very forseeable cases.
Quoted 6 lines
and several thinks can be done to avoid
the old bootloader applying modification rules.
- The tag is not skippable
Game over for the old bootloader, an error is reported if the tag is found
-last_comp_version_w
Game over for the old bootloader, modification not allowed.
As I said, I really don't like that semantic. To be clear, I'm not against adding a new version field, I just think the semantics proposed for last_comp_version_w are not very helpful.
A version which says, if you don't understand this, you must downgrade the whole dtb (stripping all unknown tags) would be better. Although then there's a secondary question of what should the downgraded version be.
Quoted 37 lines
In that case, the only solution is to bump the bootloader version.
Quoted 26 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
- When a property is modified, tags related to this property are removed and the dtb version is downgraded.
We need a definition of what "related to" means somewhere.
Quoted 8 lines
Yes a tag is said related to a property if it is available after its
FDT_PROPand before the nextFDT_PROP(other proterty) ofFDT_BEGIN_NODE(subnode) forFDT_NODE_END(end of node).This is defined by "structured tag"
Devicetree Specification will be updated to have all of this documentation available.
Ok.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
- When a property is removed, tags related to this property are obviously removed. The dtb version is kept unchanged.
- When a property or a node is added, obviously no unknown tags are added and the dtb version is kept unchanged.
Again, this rule doesn't make sense to me at the same time as the property modification rule.
Quoted 8 lines
Quoted 2 lines
A current libfdt/dtc version cannot add tags which will be defined in the future.
Sure, but it can still add whole new nodes or properties. The question is whether a version can mandate the presence of certain tags. Dowgrading the version when we strip tags from a modified property suggests "yes", but _not_ downgrading the version when we add new property suggests "no".
Quoted 3 lines
If the version mandate some tags on nodes and properties,
last_comp_version_wwill be used to block old bootloaders. They are not more allowed to modify the dtb. They need to be bumped to newer versions.
So, this will only be useful if it's common to add new tags which are _not_ mandatory. I'm not convinced that will be the case, since most previous version revisions have been about advertising that the tree *must* include certain information that was previously not available.
Quoted 37 lines
Quoted 30 lines
Quoted 30 lines
Quoted 29 lines
Quoted 16 lines
- When a node is removed, tags related to this node are obviously removed. The dtb version is kept unchanged.
- Adding, removing or modifying a property is not considered as a node modification and so, those operations have no impacts on unknown tags related to the node. Those node related tags are kept unchanged.
- The only modification considered as a node modification is setting its name. We consider that this operation has no impact on tags related to the node. Here also, those node related tags and the dtb version are kept unchanged.
- Global (dtb related) unknown tags are kept unchanged regardless the modification done.
Quoted 7 lines
In all cases, if unknown tags are not involved in a modification, the dtb version is not downgraded when the modification is made.
It is worth noting that with this v18 version, the dtb version is not downgraded for any modification but only when unknown tags are removed due to a property modification. In v17 or older version any modification led to a dtb version downgrade.
I don't think removing that behaviour is safe. Even if the rules above make sense specifically for the metadata tags (which I'm not yet convinced of), that's not sufficient. If nothing else, future versions could add extra header fields. If we modify the tree, those header fields could be stale, or even removed.
Quoted 3 lines
Quoted 3 lines
last_comp_version_wwill be used by the future version to prevent this kind of issue with old version.Best regards,
Hervé
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David,
Quoted 82 lines · On Fri, 16 Oct 2026 16:18:03 +1100 David Gibson <[email protected]>…
Quoted 60 lines · Herve Codina
Hi David, Rob,
Quoted 55 lines · On Tue, 13 Oct 2026 18:10:39 +1100 David Gibson <[email protected]>…
Quoted 38 lines · Herve Codina
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?Quoted 8 lines
We had one
last_comp_version.Now we have two
last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Ok, I now see that the logic is you simply fail to proceed with writes if the library's latest understood version is <
last_comp_version_w.As I said elsewhere, this approach doesn't particularly make sense to me. If
lib_version>=last_comp_versionyou *can* write, even if it means stripping everything that's not understood atlib_version.Quoted 6 lines
Quoted 4 lines
So the real question here is how do we know, for any given structured tag, what write operations require the version to be downgraded (which might in turn require this and/or other structured tags to be stripped entirely).
The rules is well known.
I really don't think they are. You've proposed one set of rules (as code) - although I don't think they quite make sense. I've proposed another. Other variants are possible.
Quoted 10 lines
An old libfdt version will strip the tag and
downgrade the version. If, when we define a new tags this rules cannot be follow by olf libfdt version,last_comp_version_wwill be set to protect against modification.Maybe the problem is just downgrading the version.
Instead of downgrading it could be better if we mark the dtb "one or more 'unknown' tags have been removed due to a write by an old libfdt version" ?
Quoted 31 lines
Quoted 3 lines
We have a
dt_flagsheader field. We can dedicate one bit for this marker.Could it make sense ?
I really dislike this idea. It means we effectively have at least two variants of every version which strikes me as pretty confusing.
Quoted 24 lines
Quoted 24 lines
This is related to (though not the same as) the question of whether introducing a new structured tags requires a bump to the dtb version (though not to
last_comp_version, of course).Here's the simplest model I can think of. It's what I'd suggest, unless one of it's limitations is a showstopper for what you have in mind:
- version and
last_comp_versionretain their meanings. No new header version.
- New structured tags *do* require a new version. If a dtb wants to include a specific tag, it must label itself with a version that defines that tag. To enforce that:
- For read operations, if we encounter a (known) tag that doesn't belong in the header version, we throw an error (either BADSTRUCTURE, or a new error for the purpose).
- If version <=FDT_LAST_SUPPORTED_VERSIONand we encounter an unknown tag that also trips the error (since if it was defined in this version, we should know about it).
- For write operations (including in-place), we always error if version >FDT_LAST_SUPPORTED_VERSION(done infdt_rw_probe_()).
-fdt_open_into()_is_ permitted if version >FDT_LAST_SUPPORTED_VERSION. It will strip all unknown structured tags from the entire tree and downgrade the version toFDT_LAST_SUPPORTED_VERSION.
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
Just to clarify, correct me if I am wrong.
When read if we encountered a skippable unknown tag (this is possible if version > FDT_LAST_SUPPORTED_VERSION), we just skip the tag without any error.
For write, "we always error if version > FDT_LAST_SUPPORTED_VERSION". If fdt_open_into() has been called before the write operation, this will not happen. Indeed, we have downgraded the version to FDT_LAST_SUPPORTED_VERSION and removed all unknown skippable tags.
Also, during this downgrade process (downgrade version + remove skippable unknown tags), if a unknown tag that cannot be skipped is found, the downgrade process fails an return an error.
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 119 lines · Herve Codina
Hi David,
Quoted 82 lines · On Fri, 16 Oct 2026 16:18:03 +1100 David Gibson <[email protected]>…
Quoted 60 lines · Herve Codina
Hi David, Rob,
Quoted 55 lines · On Tue, 13 Oct 2026 18:10:39 +1100 David Gibson <[email protected]>…
Quoted 38 lines · Herve Codina
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?Quoted 8 lines
We had one
last_comp_version.Now we have two
last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Ok, I now see that the logic is you simply fail to proceed with writes if the library's latest understood version is <
last_comp_version_w.As I said elsewhere, this approach doesn't particularly make sense to me. If
lib_version>=last_comp_versionyou *can* write, even if it means stripping everything that's not understood atlib_version.Quoted 6 lines
Quoted 4 lines
So the real question here is how do we know, for any given structured tag, what write operations require the version to be downgraded (which might in turn require this and/or other structured tags to be stripped entirely).
The rules is well known.
I really don't think they are. You've proposed one set of rules (as code) - although I don't think they quite make sense. I've proposed another. Other variants are possible.
Quoted 10 lines
An old libfdt version will strip the tag and
downgrade the version. If, when we define a new tags this rules cannot be follow by olf libfdt version,last_comp_version_wwill be set to protect against modification.Maybe the problem is just downgrading the version.
Instead of downgrading it could be better if we mark the dtb "one or more 'unknown' tags have been removed due to a write by an old libfdt version" ?
Quoted 31 lines
Quoted 3 lines
We have a
dt_flagsheader field. We can dedicate one bit for this marker.Could it make sense ?
I really dislike this idea. It means we effectively have at least two variants of every version which strikes me as pretty confusing.
Quoted 24 lines
Quoted 24 lines
This is related to (though not the same as) the question of whether introducing a new structured tags requires a bump to the dtb version (though not to
last_comp_version, of course).Here's the simplest model I can think of. It's what I'd suggest, unless one of it's limitations is a showstopper for what you have in mind:
- version and
last_comp_versionretain their meanings. No new header version.
- New structured tags *do* require a new version. If a dtb wants to include a specific tag, it must label itself with a version that defines that tag. To enforce that:
- For read operations, if we encounter a (known) tag that doesn't belong in the header version, we throw an error (either BADSTRUCTURE, or a new error for the purpose).
- If version <=FDT_LAST_SUPPORTED_VERSIONand we encounter an unknown tag that also trips the error (since if it was defined in this version, we should know about it).
- For write operations (including in-place), we always error if version >FDT_LAST_SUPPORTED_VERSION(done infdt_rw_probe_()).
-fdt_open_into()_is_ permitted if version >FDT_LAST_SUPPORTED_VERSION. It will strip all unknown structured tags from the entire tree and downgrade the version toFDT_LAST_SUPPORTED_VERSION.
Quoted 2 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
Quoted 5 lines
Just to clarify, correct me if I am wrong.
When read if we encountered a skippable unknown tag (this is possible if version >
FDT_LAST_SUPPORTED_VERSION), we just skip the tag without any error.
Correct. Btw, I know I suggested "skippable tag" as a term, but given how that gets kind of misleading in the case of writes, I'm coming to prefer the orignal "structured tag" term.
Quoted 4 lines
For write, "we always error if version >
FDT_LAST_SUPPORTED_VERSION". Iffdt_open_into()has been called before the write operation, this will not happen. Indeed, we have downgraded the version toFDT_LAST_SUPPORTED_VERSIONand removed all unknown skippable tags.
Correct.
Quoted 3 lines
Also, during this downgrade process (downgrade version + remove skippable unknown tags), if a unknown tag that cannot be skipped is found, the downgrade process fails an return an error.
Yes. This kind of happens naturally: since non-skippable tags are no longer structured tags in current thinking, we won't be able to complete scanning the tree to strip tags if we encounter any non-skippable unknown tags.
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and last_comp_version retain their meanings. No new header version.
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. suppose FDT_FOO tag is introduced in v20. A client reading a v19 tree _might_ see some FDT_FOO tags (because of (2)), but cannot rely on them being present in all the places they should be.
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
5. Any write to a property invalidates all unknown tags on that property's node
6. Adding or deleting a property on a node invalidates all unknown tags on the node
7. Adding or deleting a subnode invalidates all unknown tags on the node
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Note that because writes don't invalidate tags on ancestor nodes beyond one level, this proposal doesn't permit tags to contain summary information about an entire subtree that could be invalidated by writes further down in that tree.
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David,
Quoted 4 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Correct. Btw, I know I suggested "skippable tag" as a term, but given how that gets kind of misleading in the case of writes, I'm coming to prefer the orignal "structured tag" term.
Ok, no problem to switch back to "structured tag". On my side also, I prefer this term.
Now I think that the bit indicating if a structured tag can be skip or not should be kept. I know the we can use "old" tag format when a tag cannot be skipped but I thing that using structured tags for those tags can lead to some benefit. For instance, in fdt_tag_next() we can benefit of the data size encoded for structured tags for all king of structured tags (skippable and not skippable) and retrieve the next tag without the need for parsing data related to a tag. When tag has a string as data, without the length we have to scan the string to find its end. Of course we can add the length if the tag definition but this is automatically implied if we use a structured tag.
So for structured tag, I can propose:
- bit 31: 1 to identify a structured tag
- bit 30: SAFE_SKIP bit (1 if we can skip, O otherwise)
- bit 29..24: Data lendth encoding
0b000000: No data
0b000001: 1 32bit word of data
...
0b111110: 63 x 32bit words data
0b111111: varlen encoding (1 32bit word added after the tag to encode the
data length in bytes.
- bit 23..0: Tag id
Without the SAFE_SKIP bit, all structured tags must be skippable. IMHO, we could regret this limitation in the future.
The cost of the SAFE_SKIP bit is not a lot. When we check to see if an unkwown tag can be skipped, we are going to move from
if (tag & 1<31)
to
if ((tag & (1<31 | 1<<30)) == (1<31 | 1<<30))
IHMO, this is acceptable.
Of course, if the SAFE_SKIP bit is re-introduced, I will also re-add the test checking that unknown structured tag that cannot be skipped leads to an error.
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David,
I know you are busy but if you could give me your opinion on this last message that would be greatly appreciated.
I've started to prepare the next iteration of the series adding support for "structured" tags and their definition need to be stable to move forward.
The question to answer to complete the definition of the "structured" tag format is: Should SAFE_SKIP bit be re-introduced?
IMHO, it should.
Best regards,
Hervé
Quoted 51 lines · On Wed, 21 Oct 2026 15:59:23 +0200 Herve Codina <[email protected]>…
Hi David,
Quoted 4 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Correct. Btw, I know I suggested "skippable tag" as a term, but given how that gets kind of misleading in the case of writes, I'm coming to prefer the orignal "structured tag" term.
Ok, no problem to switch back to "structured tag". On my side also, I prefer this term.
Now I think that the bit indicating if a structured tag can be skip or not should be kept. I know the we can use "old" tag format when a tag cannot be skipped but I thing that using structured tags for those tags can lead to some benefit. For instance, in
fdt_tag_next()we can benefit of the data size encoded for structured tags for all king of structured tags (skippable and not skippable) and retrieve the next tag without the need for parsing data related to a tag. When tag has a string as data, without the length we have to scan the string to find its end. Of course we can add the length if the tag definition but this is automatically implied if we use a structured tag.So for structured tag, I can propose:
- bit 31: 1 to identify a structured tag
- bit 30:SAFE_SKIPbit (1 if we can skip, O otherwise)
- bit 29..24: Data lendth encoding
0b000000: No data
0b000001: 1 32bit word of data
...
0b111110: 63 x 32bit words data
0b111111: varlen encoding (1 32bit word added after the tag to encode the
data length in bytes.
- bit 23..0: Tag idWithout the
SAFE_SKIPbit, all structured tags must be skippable. IMHO, we could regret this limitation in the future.The cost of the
SAFE_SKIPbit is not a lot. When we check to see if an unkwown tag can be skipped, we are going to move from
if (tag & 1<31)
to
if ((tag & (1<31 | 1<<30)) == (1<31 | 1<<30))IHMO, this is acceptable.
Of course, if the
SAFE_SKIPbit is re-introduced, I will also re-add the test checking that unknown structured tag that cannot be skipped leads to an error.Best regards,
Hervé
Signature · 3 lines
Hervé Codina, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 10 lines · Herve Codina
Hi David,
I know you are busy but if you could give me your opinion on this last message that would be greatly appreciated.
I've started to prepare the next iteration of the series adding support for "structured" tags and their definition need to be stable to move forward.
The question to answer to complete the definition of the "structured" tag format is: Should
SAFE_SKIPbit be re-introduced?
Sorry, I lost track of this one amongst all the rest of the activity.
Quoted 57 lines
IMHO, it should.
Best regards,
HervéQuoted 49 lines · On Wed, 21 Oct 2026 15:59:23 +0200 Herve Codina <[email protected]>…
Hi David,
Quoted 4 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Correct. Btw, I know I suggested "skippable tag" as a term, but given how that gets kind of misleading in the case of writes, I'm coming to prefer the orignal "structured tag" term.
Ok, no problem to switch back to "structured tag". On my side also, I prefer this term.
Now I think that the bit indicating if a structured tag can be skip or not should be kept. I know the we can use "old" tag format when a tag cannot be skipped but I thing that using structured tags for those tags can lead to some benefit. For instance, in
fdt_tag_next()we can benefit of the data size encoded for structured tags for all king of structured tags (skippable and not skippable) and retrieve the next tag without the need for parsing data related to a tag. When tag has a string as data, without the length we have to scan the string to find its end. Of course we can add the length if the tag definition but this is automatically implied if we use a structured tag.So for structured tag, I can propose:
- bit 31: 1 to identify a structured tag
- bit 30:SAFE_SKIPbit (1 if we can skip, O otherwise)
- bit 29..24: Data lendth encoding
0b000000: No data
0b000001: 1 32bit word of data
...
0b111110: 63 x 32bit words data
0b111111: varlen encoding (1 32bit word added after the tag to encode the
data length in bytes.
- bit 23..0: Tag idWithout the
SAFE_SKIPbit, all structured tags must be skippable. IMHO, we could regret this limitation in the future.The cost of the
SAFE_SKIPbit is not a lot. When we check to see if an unkwown tag can be skipped, we are going to move from
if (tag & 1<31)
to
if ((tag & (1<31 | 1<<30)) == (1<31 | 1<<30))IHMO, this is acceptable.
Of course, if the
SAFE_SKIPbit is re-introduced, I will also re-add the test checking that unknown structured tag that cannot be skipped leads to an error.
So, I'm not entirely convinced either way. However, I have a semi-related thought that might sidestep the question for the time being.
I think it would be a good idea to leave some bits reserved, in case there's some more structured information we want to put in later. One candidate might be "invalidated-when-X-happens" type bits which we considered when discussing the versioning. I think we can spare the bits, since both tag and especially id fields are pretty generous at the moment (23 bits when our entire current existing tagset fits in 4 bits with a bunch of spare room).
For reserved bits to be safe to use later we must insist and enforce that they be 0 for now. That means setting any reserved bit effectively makes it a non-skippable tag for the time being. Or to put it another way, that means we can amongst other things add an (inverted) SAFE_SKIP bit in future if we discover we want it.
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David,
Quoted 76 lines · On Fri, 30 Oct 2026 13:48:25 +1100 David Gibson <[email protected]>…
Quoted 10 lines · Herve Codina
Hi David,
I know you are busy but if you could give me your opinion on this last message that would be greatly appreciated.
I've started to prepare the next iteration of the series adding support for "structured" tags and their definition need to be stable to move forward.
The question to answer to complete the definition of the "structured" tag format is: Should
SAFE_SKIPbit be re-introduced?Sorry, I lost track of this one amongst all the rest of the activity.
Quoted 57 lines
IMHO, it should.
Best regards,
HervéQuoted 49 lines · On Wed, 21 Oct 2026 15:59:23 +0200 Herve Codina <[email protected]>…
Hi David,
Quoted 4 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Correct. Btw, I know I suggested "skippable tag" as a term, but given how that gets kind of misleading in the case of writes, I'm coming to prefer the orignal "structured tag" term.
Ok, no problem to switch back to "structured tag". On my side also, I prefer this term.
Now I think that the bit indicating if a structured tag can be skip or not should be kept. I know the we can use "old" tag format when a tag cannot be skipped but I thing that using structured tags for those tags can lead to some benefit. For instance, in
fdt_tag_next()we can benefit of the data size encoded for structured tags for all king of structured tags (skippable and not skippable) and retrieve the next tag without the need for parsing data related to a tag. When tag has a string as data, without the length we have to scan the string to find its end. Of course we can add the length if the tag definition but this is automatically implied if we use a structured tag.So for structured tag, I can propose:
- bit 31: 1 to identify a structured tag
- bit 30:SAFE_SKIPbit (1 if we can skip, O otherwise)
- bit 29..24: Data lendth encoding
0b000000: No data
0b000001: 1 32bit word of data
...
0b111110: 63 x 32bit words data
0b111111: varlen encoding (1 32bit word added after the tag to encode the
data length in bytes.
- bit 23..0: Tag idWithout the
SAFE_SKIPbit, all structured tags must be skippable. IMHO, we could regret this limitation in the future.The cost of the
SAFE_SKIPbit is not a lot. When we check to see if an unkwown tag can be skipped, we are going to move from
if (tag & 1<31)
to
if ((tag & (1<31 | 1<<30)) == (1<31 | 1<<30))IHMO, this is acceptable.
Of course, if the
SAFE_SKIPbit is re-introduced, I will also re-add the test checking that unknown structured tag that cannot be skipped leads to an error.So, I'm not entirely convinced either way. However, I have a semi-related thought that might sidestep the question for the time being.
Quoted 7 lines
I think it would be a good idea to leave some bits reserved, in case there's some more structured information we want to put in later. One candidate might be "invalidated-when-X-happens" type bits which we considered when discussing the versioning. I think we can spare the bits, since both tag and especially id fields are pretty generous at the moment (23 bits when our entire current existing tagset fits in 4 bits with a bunch of spare room).
Yes, I agree.
Quoted 7 lines
For reserved bits to be safe to use later we must insist and enforce that they be 0 for now. That means setting any reserved bit effectively makes it a non-skippable tag for the time being. Or to put it another way, that means we can amongst other things add an (inverted)
SAFE_SKIPbit in future if we discover we want it.
Yes indeed.
The structured tag definition becomes:
- bit 31: 1 to identify a structured tag
- bit 30..24: Reserved (7 bits)
Those bits are reserved for future use. They must be cleared (0 value). If any of these bits is set, an error should be reported.
- bit 23..18: Data length encoding (6 bits)
0b000000: No data
0b000001: 1 32bit word of data
...
0b111110: 62 x 32bit words data
0b111111: varlen encoding (1 32bit word added after the tag to encode the
data length in bytes).- bit 17..0: Tag id
Is this mapping ok on your side?
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 112 lines · Herve Codina
Hi David,
Quoted 76 lines · On Fri, 30 Oct 2026 13:48:25 +1100 David Gibson <[email protected]>…
Quoted 10 lines · Herve Codina
Hi David,
I know you are busy but if you could give me your opinion on this last message that would be greatly appreciated.
I've started to prepare the next iteration of the series adding support for "structured" tags and their definition need to be stable to move forward.
The question to answer to complete the definition of the "structured" tag format is: Should
SAFE_SKIPbit be re-introduced?Sorry, I lost track of this one amongst all the rest of the activity.
Quoted 57 lines
IMHO, it should.
Best regards,
HervéQuoted 49 lines · On Wed, 21 Oct 2026 15:59:23 +0200 Herve Codina <[email protected]>…
Hi David,
Quoted 4 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Correct. Btw, I know I suggested "skippable tag" as a term, but given how that gets kind of misleading in the case of writes, I'm coming to prefer the orignal "structured tag" term.
Ok, no problem to switch back to "structured tag". On my side also, I prefer this term.
Now I think that the bit indicating if a structured tag can be skip or not should be kept. I know the we can use "old" tag format when a tag cannot be skipped but I thing that using structured tags for those tags can lead to some benefit. For instance, in
fdt_tag_next()we can benefit of the data size encoded for structured tags for all king of structured tags (skippable and not skippable) and retrieve the next tag without the need for parsing data related to a tag. When tag has a string as data, without the length we have to scan the string to find its end. Of course we can add the length if the tag definition but this is automatically implied if we use a structured tag.So for structured tag, I can propose:
- bit 31: 1 to identify a structured tag
- bit 30:SAFE_SKIPbit (1 if we can skip, O otherwise)
- bit 29..24: Data lendth encoding
0b000000: No data
0b000001: 1 32bit word of data
...
0b111110: 63 x 32bit words data
0b111111: varlen encoding (1 32bit word added after the tag to encode the
data length in bytes.
- bit 23..0: Tag idWithout the
SAFE_SKIPbit, all structured tags must be skippable. IMHO, we could regret this limitation in the future.The cost of the
SAFE_SKIPbit is not a lot. When we check to see if an unkwown tag can be skipped, we are going to move from
if (tag & 1<31)
to
if ((tag & (1<31 | 1<<30)) == (1<31 | 1<<30))IHMO, this is acceptable.
Of course, if the
SAFE_SKIPbit is re-introduced, I will also re-add the test checking that unknown structured tag that cannot be skipped leads to an error.So, I'm not entirely convinced either way. However, I have a semi-related thought that might sidestep the question for the time being.
Quoted 7 lines
I think it would be a good idea to leave some bits reserved, in case there's some more structured information we want to put in later. One candidate might be "invalidated-when-X-happens" type bits which we considered when discussing the versioning. I think we can spare the bits, since both tag and especially id fields are pretty generous at the moment (23 bits when our entire current existing tagset fits in 4 bits with a bunch of spare room).
Yes, I agree.
Quoted 6 lines
For reserved bits to be safe to use later we must insist and enforce that they be 0 for now. That means setting any reserved bit effectively makes it a non-skippable tag for the time being. Or to put it another way, that means we can amongst other things add an (inverted)
SAFE_SKIPbit in future if we discover we want it.Yes indeed.
The structured tag definition becomes:
- bit 31: 1 to identify a structured tag
- bit 30..24: Reserved (7 bits)
Those bits are reserved for future use. They must be cleared (0 value). If any of these bits is set, an error should be reported.
- bit 23..18: Data length encoding (6 bits)0b000000: No data 0b000001: 1 32bit word of data ... 0b111110: 62 x 32bit words data 0b111111: varlen encoding (1 32bit word added after the tag to encode the data length in bytes).
Quoted 3 lines
- bit 17..0: Tag id
Is this mapping ok on your side?
Sounds good, thanks.
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
In reply to David GibsonHi David,
Quoted 10 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
No problem, I understand your point.
...
Quoted 6 lines
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.
Quoted 6 lines
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and
last_comp_versionretain their meanings. No new header version.
Ok
Quoted 2 lines
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
Ok
Quoted 7 lines
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. supposeFDT_FOOtag is introduced in v20. A client reading a v19 tree _might_ see someFDT_FOOtags (because of (2)), but cannot rely on them being present in all the places they should be.
Ok, kind of degraded mode. Whether or not a v20 compatible client can continue or not will depend of each tags known by this v20 client. For some tags, having them removed will not be a problem whereas it will be a problem for some other.
Makes sense.
Quoted 2 lines
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
Ok
Quoted 2 lines
5. Any write to a property invalidates all unknown tags on that property's node
Will see in the implementation. The offset of the written property will be incorrect after the write. Indeed, some tags (tags related to the node) available before the property can be removed. With splices instead of FDT_NOP, offsets change.
This also brings a question. Are API functions such as fdt_get_property_by_offset_w() need to be deprecated?
Those kind of functions return a pointer to the data of a property for modification by the caller. We don't know if the caller will modify or not the property.
Without deprecated it we can change the function to ---- 8< ----
struct fdt_property *fdt_get_property_by_offset_w(void *fdt,
int offset, int *lenp)
{
int new_offset;
/*
* The modification is goind to be done out of libfdt.
* Unknown tags are removed (rules for modification when unknown tags
* are involved) but also known tags. Indeed, we cannot know if the
* modification will have impacts on known tags
*/
new_offset = fdt_remove_all_tags_due_to_property_modification(fdt, offset);
return (struct fdt_property *)(uintptr_t)
fdt_get_property_by_offset(fdt, new_offset, lenp);
}---- 8< ----
The idea is to be conservative here also and consider that property data retrieved for writing will be modified by the caller.
Also, the offset used as parameter of fdt_get_property_by_offset_w() is no more valid after the call.
Last point to have in mind, getting the node offset from the property offset will need to walk the tree from the beginning. It can be costly.
Quoted 2 lines
6. Adding or deleting a property on a node invalidates all unknown tags on the node
Ok.
Quoted 2 lines
7. Adding or deleting a subnode invalidates all unknown tags on the node
Ok.
Quoted 3 lines
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Ok.
Quoted 3 lines
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Well, this new proposal is more complex to implement than your first proposal but it has a finer grain to handle unknown tags on modification.
I can try to implement something based on this new proposal.
Quoted 6 lines
Note that because writes don't invalidate tags on ancestor nodes beyond one level, this proposal doesn't permit tags to contain summary information about an entire subtree that could be invalidated by writes further down in that tree.
Well this doesn't look like an issue on my side. At some point if such tags are added, we can avoid any modification using the last_comp_version field.
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 48 lines · Herve Codina
Hi David,
Quoted 10 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
No problem, I understand your point.
...
Quoted 6 lines
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.Quoted 6 lines
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and
last_comp_versionretain their meanings. No new header version.Ok
Quoted 2 lines
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
Ok
Quoted 7 lines
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. supposeFDT_FOOtag is introduced in v20. A client reading a v19 tree _might_ see someFDT_FOOtags (because of (2)), but cannot rely on them being present in all the places they should be.
Quoted 3 lines
Ok, kind of degraded mode. Whether or not a v20 compatible client can continue or not will depend of each tags known by this v20 client. For some tags, having them removed will not be a problem whereas it will be a problem for some other.
Exactly.
Quoted 7 lines
Makes sense.
Quoted 2 lines
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
Ok
Quoted 7 lines
Quoted 2 lines
5. Any write to a property invalidates all unknown tags on that property's node
Will see in the implementation. The offset of the written property will be incorrect after the write. Indeed, some tags (tags related to the node) available before the property can be removed. With splices instead of
FDT_NOP, offsets change.
Oh, good point, this rule doesn't work. I think we still have a consistent set of rules if property writes don't invalidate parent node tags (subnode add/delete still would). Of coutse, that does further restrict what sorts of information you could safely put in node tags under this scheme.
Quoted 2 lines
This also brings a question. Are API functions such as
fdt_get_property_by_offset_w()need to be deprecated?
I think we can keep it - kind of like fdt_next_tag() this is a low-level function. If you use it, you're opting in to having to deal with tag invalidation.
Quoted 24 lines
Those kind of functions return a pointer to the data of a property for modification by the caller. We don't know if the caller will modify or not the property.
Without deprecated it we can change the function to ---- 8< ----
structfdt_property*fdt_get_property_by_offset_w(void *fdt,
int offset, int *lenp){ int new_offset; /* * The modification is goind to be done out of libfdt. * Unknown tags are removed (rules for modification when unknown tags * are involved) but also known tags. Indeed, we cannot know if the * modification will have impacts on known tags */ new_offset = fdt_remove_all_tags_due_to_property_modification(fdt, offset); return (struct fdt_property *)(uintptr_t) fdt_get_property_by_offset(fdt, new_offset, lenp); }---- 8< ----
Quoted 8 lines
The idea is to be conservative here also and consider that property data retrieved for writing will be modified by the caller.
Also, the offset used as parameter of
fdt_get_property_by_offset_w()is no more valid after the call.Last point to have in mind, getting the node offset from the property offset will need to walk the tree from the beginning. It can be costly.
Right, that's what I was thinking of when I said this might not be practical to implement. It's doable in the common case where we alter properties by node offset + property name, but not when we use a property offset. But the fact that this would change the offset of the property in queestion is a much bigger showstopper.
Quoted 14 lines
Quoted 2 lines
6. Adding or deleting a property on a node invalidates all unknown tags on the node
Ok.
Quoted 2 lines
7. Adding or deleting a subnode invalidates all unknown tags on the node
Ok.
Quoted 3 lines
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Quoted 8 lines
Ok.
Quoted 3 lines
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Well, this new proposal is more complex to implement than your first proposal but it has a finer grain to handle unknown tags on modification.
Certainly - that's why I proposed the other one first :).
Quoted 1 line
I can try to implement something based on this new proposal.
To be clear, I kind of prefer my first proposal still. The question is whether what the updated scheme buys (preserving more tags when a bootloader makes minor writes) worth the added complexity of implementation. You're better placed to answer that question than I am.
Quoted 9 lines
Quoted 5 lines
Note that because writes don't invalidate tags on ancestor nodes beyond one level, this proposal doesn't permit tags to contain summary information about an entire subtree that could be invalidated by writes further down in that tree.
Well this doesn't look like an issue on my side. At some point if such tags are added, we can avoid any modification using the
last_comp_versionfield.
Yes.
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David,
Quoted 147 lines · On Thu, 22 Oct 2026 14:17:38 +1100 David Gibson <[email protected]>…
Quoted 48 lines · Herve Codina
Hi David,
Quoted 10 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
No problem, I understand your point.
...
Quoted 6 lines
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.Quoted 6 lines
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and
last_comp_versionretain their meanings. No new header version.Ok
Quoted 2 lines
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
Ok
Quoted 7 lines
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. supposeFDT_FOOtag is introduced in v20. A client reading a v19 tree _might_ see someFDT_FOOtags (because of (2)), but cannot rely on them being present in all the places they should be.Quoted 3 lines
Ok, kind of degraded mode. Whether or not a v20 compatible client can continue or not will depend of each tags known by this v20 client. For some tags, having them removed will not be a problem whereas it will be a problem for some other.
Exactly.
Quoted 7 lines
Makes sense.
Quoted 2 lines
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
Ok
Quoted 7 lines
Quoted 2 lines
5. Any write to a property invalidates all unknown tags on that property's node
Will see in the implementation. The offset of the written property will be incorrect after the write. Indeed, some tags (tags related to the node) available before the property can be removed. With splices instead of
FDT_NOP, offsets change.Oh, good point, this rule doesn't work. I think we still have a consistent set of rules if property writes don't invalidate parent node tags (subnode add/delete still would). Of coutse, that does further restrict what sorts of information you could safely put in node tags under this scheme.
Quoted 2 lines
This also brings a question. Are API functions such as
fdt_get_property_by_offset_w()need to be deprecated?I think we can keep it - kind of like
fdt_next_tag()this is a low-level function. If you use it, you're opting in to having to deal with tag invalidation.Quoted 24 lines
Those kind of functions return a pointer to the data of a property for modification by the caller. We don't know if the caller will modify or not the property.
Without deprecated it we can change the function to ---- 8< ----
structfdt_property*fdt_get_property_by_offset_w(void *fdt,
int offset, int *lenp){ int new_offset; /* * The modification is goind to be done out of libfdt. * Unknown tags are removed (rules for modification when unknown tags * are involved) but also known tags. Indeed, we cannot know if the * modification will have impacts on known tags */ new_offset = fdt_remove_all_tags_due_to_property_modification(fdt, offset); return (struct fdt_property *)(uintptr_t) fdt_get_property_by_offset(fdt, new_offset, lenp); }---- 8< ----
Quoted 8 lines
The idea is to be conservative here also and consider that property data retrieved for writing will be modified by the caller.
Also, the offset used as parameter of
fdt_get_property_by_offset_w()is no more valid after the call.Last point to have in mind, getting the node offset from the property offset will need to walk the tree from the beginning. It can be costly.
Right, that's what I was thinking of when I said this might not be practical to implement. It's doable in the common case where we alter properties by node offset + property name, but not when we use a property offset. But the fact that this would change the offset of the property in queestion is a much bigger showstopper.
Quoted 14 lines
Quoted 2 lines
6. Adding or deleting a property on a node invalidates all unknown tags on the node
Ok.
Quoted 2 lines
7. Adding or deleting a subnode invalidates all unknown tags on the node
Ok.
Quoted 3 lines
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Quoted 8 lines
Ok.
Quoted 3 lines
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Well, this new proposal is more complex to implement than your first proposal but it has a finer grain to handle unknown tags on modification.
Certainly - that's why I proposed the other one first :).
Quoted 7 lines
Quoted 1 line
I can try to implement something based on this new proposal.
To be clear, I kind of prefer my first proposal still. The question is whether what the updated scheme buys (preserving more tags when a bootloader makes minor writes) worth the added complexity of implementation. You're better placed to answer that question than I am.
I would like to avoid bootloaders being blocking points and so:
a) They should not failed if they encounter an unknown skippable tag. We are in sync on this point.
b) They should preserve tags as much as possible.
The goal is to allow following software components (probably the Kernel) to handle new tags.
This is the point where the right balance has be found.
Your first proposal is maybe too much aggressive on b). That's why, even it is more complex to implement I would prefer your last proposal (taking into account the property offset issue) which can be summarize with the following table:
| existing prop | existing node (1) | Downgrade
| unknown tag | unknown tag | version (2)
----------------------+---------------+---------------------+-----------
Modify a property (5) | Remove | Keep (3) | Yes
Add a property | NA | Remove | Yes
Delete a property | Remove | Remove | Yes (4)
Add a sub-node | NA | Remove | Yes
Delete a sub-node | NA | Remove | Yes----------------------+---------------+---------------------+-----------
(1) The existing node is the node were the property or sub-node involved are present. Not all nodes, not the parent node but the node directly impacted by the modification.
(2) We downgrade the version only if tag are removed. If no unknown tags are involved (and so not removed), the version will not be be downgraded.
(3) Removing unknown tags in the node when a property is modified will lead to the property offset change. Prefer avoid the property offset change and so keep node related unknown tags in that case.
(4) The version is downgrade only if we remove some tags related to the node. If we remove only tags related to the property we delete, there is no reason to downgrade the version.
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal.
This point is for the usage of fdt_get_property_by_offset_w(), fdt_get_property_namelen_w(), fdt_get_property_w(), fdt_getprop_by_offset_w(), fdt_getprop_namelen_w(), fdt_getprop_w() and maybe other similar functions where the property is returned writable for possible modification. 'modify a property' mentioned in the table is related to modification done using fdt_setprop_*() and fdt_appendprop_*() function families.
On your side, is all of that conservative enough to be used when modification involved unknown tags?
Quoted 13 lines
Quoted 10 lines
Quoted 6 lines
Note that because writes don't invalidate tags on ancestor nodes beyond one level, this proposal doesn't permit tags to contain summary information about an entire subtree that could be invalidated by writes further down in that tree.
Well this doesn't look like an issue on my side. At some point if such tags are added, we can avoid any modification using the
last_comp_versionfield.Yes.
Signature · 3 lines
Hervé Codina, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 160 lines · Herve Codina
Hi David,
Quoted 147 lines · On Thu, 22 Oct 2026 14:17:38 +1100 David Gibson <[email protected]>…
Quoted 48 lines · Herve Codina
Hi David,
Quoted 10 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
No problem, I understand your point.
...
Quoted 6 lines
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.Quoted 6 lines
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and
last_comp_versionretain their meanings. No new header version.Ok
Quoted 2 lines
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
Ok
Quoted 7 lines
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. supposeFDT_FOOtag is introduced in v20. A client reading a v19 tree _might_ see someFDT_FOOtags (because of (2)), but cannot rely on them being present in all the places they should be.Quoted 3 lines
Ok, kind of degraded mode. Whether or not a v20 compatible client can continue or not will depend of each tags known by this v20 client. For some tags, having them removed will not be a problem whereas it will be a problem for some other.
Exactly.
Quoted 7 lines
Makes sense.
Quoted 2 lines
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
Ok
Quoted 7 lines
Quoted 2 lines
5. Any write to a property invalidates all unknown tags on that property's node
Will see in the implementation. The offset of the written property will be incorrect after the write. Indeed, some tags (tags related to the node) available before the property can be removed. With splices instead of
FDT_NOP, offsets change.Oh, good point, this rule doesn't work. I think we still have a consistent set of rules if property writes don't invalidate parent node tags (subnode add/delete still would). Of coutse, that does further restrict what sorts of information you could safely put in node tags under this scheme.
Quoted 2 lines
This also brings a question. Are API functions such as
fdt_get_property_by_offset_w()need to be deprecated?I think we can keep it - kind of like
fdt_next_tag()this is a low-level function. If you use it, you're opting in to having to deal with tag invalidation.Quoted 24 lines
Those kind of functions return a pointer to the data of a property for modification by the caller. We don't know if the caller will modify or not the property.
Without deprecated it we can change the function to ---- 8< ----
structfdt_property*fdt_get_property_by_offset_w(void *fdt,
int offset, int *lenp){ int new_offset; /* * The modification is goind to be done out of libfdt. * Unknown tags are removed (rules for modification when unknown tags * are involved) but also known tags. Indeed, we cannot know if the * modification will have impacts on known tags */ new_offset = fdt_remove_all_tags_due_to_property_modification(fdt, offset); return (struct fdt_property *)(uintptr_t) fdt_get_property_by_offset(fdt, new_offset, lenp); }---- 8< ----
Quoted 8 lines
The idea is to be conservative here also and consider that property data retrieved for writing will be modified by the caller.
Also, the offset used as parameter of
fdt_get_property_by_offset_w()is no more valid after the call.Last point to have in mind, getting the node offset from the property offset will need to walk the tree from the beginning. It can be costly.
Right, that's what I was thinking of when I said this might not be practical to implement. It's doable in the common case where we alter properties by node offset + property name, but not when we use a property offset. But the fact that this would change the offset of the property in queestion is a much bigger showstopper.
Quoted 14 lines
Quoted 2 lines
6. Adding or deleting a property on a node invalidates all unknown tags on the node
Ok.
Quoted 2 lines
7. Adding or deleting a subnode invalidates all unknown tags on the node
Ok.
Quoted 3 lines
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Quoted 8 lines
Ok.
Quoted 3 lines
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Well, this new proposal is more complex to implement than your first proposal but it has a finer grain to handle unknown tags on modification.
Certainly - that's why I proposed the other one first :).
Quoted 7 lines
Quoted 1 line
I can try to implement something based on this new proposal.
To be clear, I kind of prefer my first proposal still. The question is whether what the updated scheme buys (preserving more tags when a bootloader makes minor writes) worth the added complexity of implementation. You're better placed to answer that question than I am.
Quoted 8 lines
I would like to avoid bootloaders being blocking points and so:
a) They should not failed if they encounter an unknown skippable tag. We are in sync on this point.b) They should preserve tags as much as possible.
The goal is to allow following software components (probably the Kernel) to handle new tags.
This is the point where the right balance has be found.
Right. I understand why these are both desirable. However (b) is pretty tricky, because of the question of invalidation. It necessarily involves a tradeoff between how much can be preserved versus what sorts of information future tags can carry.
Quoted 13 lines
Your first proposal is maybe too much aggressive on b). That's why, even it is more complex to implement I would prefer your last proposal (taking into account the property offset issue) which can be summarize with the following table:
| existing prop | existing node (1) | Downgrade | unknown tag | unknown tag | version (2) ----------------------+---------------+---------------------+----------- Modify a property (5) | Remove | Keep (3) | Yes Add a property | NA | Remove | Yes Delete a property | Remove | Remove | Yes (4) Add a sub-node | NA | Remove | Yes Delete a sub-node | NA | Remove | Yes
Quoted 1 line
----------------------+---------------+---------------------+-----------
Great summary, thanks.
Quoted 6 lines
(1) The existing node is the node were the property or sub-node involved are present. Not all nodes, not the parent node but the node directly impacted by the modification.
(2) We downgrade the version only if tag are removed. If no unknown tags are involved (and so not removed), the version will not be be downgraded.
Sadly, that doesn't work. We have to downgrade on property modification for the same reason we must downgrade on adding a
property: it might be adding data that requires certain tags in the later version.
Quoted 3 lines
(3) Removing unknown tags in the node when a property is modified will lead to the property offset change. Prefer avoid the property offset change and so keep node related unknown tags in that case.
Right, if we did that it would basically mean totally (and incompatibly) redesigning the libfdt interface.
Quoted 3 lines
(4) The version is downgrade only if we remove some tags related to the node. If we remove only tags related to the property we delete, there is no reason to downgrade the version.
Unlike (2), I'm not certain if this one is unsafe. But I suspect it might be, and having it behave differently from case (2) seems confusing to me.
Quoted 10 lines
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal.
This point is for the usage of
fdt_get_property_by_offset_w(),fdt_get_property_namelen_w(),fdt_get_property_w(),fdt_getprop_by_offset_w(),fdt_getprop_namelen_w(),fdt_getprop_w()and maybe other similar functions where the property is returned writable for possible modification. 'modify a property' mentioned in the table is related to modification done using fdt_setprop_*() and fdt_appendprop_*() function families.
Right. "I know what I'm doing" is part of the implicit contract when using those functions.
Quoted 2 lines
On your side, is all of that conservative enough to be used when modification involved unknown tags?
Not quite, as noted, but we might be able to get it there.
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David,
Quoted 196 lines · On Fri, 23 Oct 2026 13:57:54 +1100 David Gibson <[email protected]>…
Quoted 160 lines · Herve Codina
Hi David,
Quoted 147 lines · On Thu, 22 Oct 2026 14:17:38 +1100 David Gibson <[email protected]>…
Quoted 48 lines · Herve Codina
Hi David,
Quoted 10 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
No problem, I understand your point.
...
Quoted 6 lines
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.Quoted 6 lines
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and
last_comp_versionretain their meanings. No new header version.Ok
Quoted 2 lines
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
Ok
Quoted 7 lines
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. supposeFDT_FOOtag is introduced in v20. A client reading a v19 tree _might_ see someFDT_FOOtags (because of (2)), but cannot rely on them being present in all the places they should be.Quoted 3 lines
Ok, kind of degraded mode. Whether or not a v20 compatible client can continue or not will depend of each tags known by this v20 client. For some tags, having them removed will not be a problem whereas it will be a problem for some other.
Exactly.
Quoted 7 lines
Makes sense.
Quoted 2 lines
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
Ok
Quoted 7 lines
Quoted 2 lines
5. Any write to a property invalidates all unknown tags on that property's node
Will see in the implementation. The offset of the written property will be incorrect after the write. Indeed, some tags (tags related to the node) available before the property can be removed. With splices instead of
FDT_NOP, offsets change.Oh, good point, this rule doesn't work. I think we still have a consistent set of rules if property writes don't invalidate parent node tags (subnode add/delete still would). Of coutse, that does further restrict what sorts of information you could safely put in node tags under this scheme.
Quoted 2 lines
This also brings a question. Are API functions such as
fdt_get_property_by_offset_w()need to be deprecated?I think we can keep it - kind of like
fdt_next_tag()this is a low-level function. If you use it, you're opting in to having to deal with tag invalidation.Quoted 24 lines
Those kind of functions return a pointer to the data of a property for modification by the caller. We don't know if the caller will modify or not the property.
Without deprecated it we can change the function to ---- 8< ----
structfdt_property*fdt_get_property_by_offset_w(void *fdt,
int offset, int *lenp){ int new_offset; /* * The modification is goind to be done out of libfdt. * Unknown tags are removed (rules for modification when unknown tags * are involved) but also known tags. Indeed, we cannot know if the * modification will have impacts on known tags */ new_offset = fdt_remove_all_tags_due_to_property_modification(fdt, offset); return (struct fdt_property *)(uintptr_t) fdt_get_property_by_offset(fdt, new_offset, lenp); }---- 8< ----
Quoted 8 lines
The idea is to be conservative here also and consider that property data retrieved for writing will be modified by the caller.
Also, the offset used as parameter of
fdt_get_property_by_offset_w()is no more valid after the call.Last point to have in mind, getting the node offset from the property offset will need to walk the tree from the beginning. It can be costly.
Right, that's what I was thinking of when I said this might not be practical to implement. It's doable in the common case where we alter properties by node offset + property name, but not when we use a property offset. But the fact that this would change the offset of the property in queestion is a much bigger showstopper.
Quoted 14 lines
Quoted 2 lines
6. Adding or deleting a property on a node invalidates all unknown tags on the node
Ok.
Quoted 2 lines
7. Adding or deleting a subnode invalidates all unknown tags on the node
Ok.
Quoted 3 lines
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Quoted 8 lines
Ok.
Quoted 3 lines
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Well, this new proposal is more complex to implement than your first proposal but it has a finer grain to handle unknown tags on modification.
Certainly - that's why I proposed the other one first :).
Quoted 7 lines
Quoted 1 line
I can try to implement something based on this new proposal.
To be clear, I kind of prefer my first proposal still. The question is whether what the updated scheme buys (preserving more tags when a bootloader makes minor writes) worth the added complexity of implementation. You're better placed to answer that question than I am.
Quoted 8 lines
I would like to avoid bootloaders being blocking points and so:
a) They should not failed if they encounter an unknown skippable tag. We are in sync on this point.b) They should preserve tags as much as possible.
The goal is to allow following software components (probably the Kernel) to handle new tags.
This is the point where the right balance has be found.Right. I understand why these are both desirable. However (b) is pretty tricky, because of the question of invalidation. It necessarily involves a tradeoff between how much can be preserved versus what sorts of information future tags can carry.
Quoted 13 lines
Your first proposal is maybe too much aggressive on b). That's why, even it is more complex to implement I would prefer your last proposal (taking into account the property offset issue) which can be summarize with the following table:
| existing prop | existing node (1) | Downgrade | unknown tag | unknown tag | version (2) ----------------------+---------------+---------------------+----------- Modify a property (5) | Remove | Keep (3) | Yes Add a property | NA | Remove | Yes Delete a property | Remove | Remove | Yes (4) Add a sub-node | NA | Remove | Yes Delete a sub-node | NA | Remove | YesQuoted 1 line
----------------------+---------------+---------------------+-----------
Great summary, thanks.
Quoted 4 lines
(1) The existing node is the node were the property or sub-node involved are present. Not all nodes, not the parent node but the node directly impacted by the modification.
Quoted 7 lines
Quoted 2 lines
(2) We downgrade the version only if tag are removed. If no unknown tags are involved (and so not removed), the version will not be be downgraded.
Sadly, that doesn't work. We have to downgrade on property modification for the same reason we must downgrade on adding a
property: it might be adding data that requires certain tags in the later version.
Oh yes, I missed that point.
(2) The version is always downgrade on any changes (modification, addition, deletion of a property or a sub-node) even if no tags are removed. Indeed the modification done (even a property or sub-node deletion) can requires certain tags in the later version.
Downgrading the version on all changes is the way to state that the resulting dtb may be no more compliant with the later version.
Quoted 8 lines
Quoted 4 lines
(3) Removing unknown tags in the node when a property is modified will lead to the property offset change. Prefer avoid the property offset change and so keep node related unknown tags in that case.
Right, if we did that it would basically mean totally (and incompatibly) redesigning the libfdt interface.
Quoted 7 lines
Quoted 3 lines
(4) The version is downgrade only if we remove some tags related to the node. If we remove only tags related to the property we delete, there is no reason to downgrade the version.
Unlike (2), I'm not certain if this one is unsafe. But I suspect it might be, and having it behave differently from case (2) seems confusing to me.
Hum ok, let be conservative and remove the note (4).
The updated note (2) handles all modification. On any changes with and without tag removal, the version is downgraded.
Quoted 12 lines
Quoted 11 lines
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal.
This point is for the usage of
fdt_get_property_by_offset_w(),fdt_get_property_namelen_w(),fdt_get_property_w(),fdt_getprop_by_offset_w(),fdt_getprop_namelen_w(),fdt_getprop_w()and maybe other similar functions where the property is returned writable for possible modification. 'modify a property' mentioned in the table is related to modification done using fdt_setprop_*() and fdt_appendprop_*() function families.
Quoted 2 lines
Right. "I know what I'm doing" is part of the implicit contract when using those functions.
Also this note (5) will be updated
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal nor a version downgrade.
Quoted 5 lines
Quoted 3 lines
On your side, is all of that conservative enough to be used when modification involved unknown tags?
Not quite, as noted, but we might be able to get it there.
Is it better?
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 209 lines · Herve Codina
Hi David,
Quoted 196 lines · On Fri, 23 Oct 2026 13:57:54 +1100 David Gibson <[email protected]>…
Quoted 160 lines · Herve Codina
Hi David,
Quoted 147 lines · On Thu, 22 Oct 2026 14:17:38 +1100 David Gibson <[email protected]>…
Quoted 48 lines · Herve Codina
Hi David,
Quoted 10 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
No problem, I understand your point.
...
Quoted 6 lines
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.Quoted 6 lines
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and
last_comp_versionretain their meanings. No new header version.Ok
Quoted 2 lines
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
Ok
Quoted 7 lines
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. supposeFDT_FOOtag is introduced in v20. A client reading a v19 tree _might_ see someFDT_FOOtags (because of (2)), but cannot rely on them being present in all the places they should be.Quoted 3 lines
Ok, kind of degraded mode. Whether or not a v20 compatible client can continue or not will depend of each tags known by this v20 client. For some tags, having them removed will not be a problem whereas it will be a problem for some other.
Exactly.
Quoted 7 lines
Makes sense.
Quoted 2 lines
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
Ok
Quoted 7 lines
Quoted 2 lines
5. Any write to a property invalidates all unknown tags on that property's node
Will see in the implementation. The offset of the written property will be incorrect after the write. Indeed, some tags (tags related to the node) available before the property can be removed. With splices instead of
FDT_NOP, offsets change.Oh, good point, this rule doesn't work. I think we still have a consistent set of rules if property writes don't invalidate parent node tags (subnode add/delete still would). Of coutse, that does further restrict what sorts of information you could safely put in node tags under this scheme.
Quoted 2 lines
This also brings a question. Are API functions such as
fdt_get_property_by_offset_w()need to be deprecated?I think we can keep it - kind of like
fdt_next_tag()this is a low-level function. If you use it, you're opting in to having to deal with tag invalidation.Quoted 24 lines
Those kind of functions return a pointer to the data of a property for modification by the caller. We don't know if the caller will modify or not the property.
Without deprecated it we can change the function to ---- 8< ----
structfdt_property*fdt_get_property_by_offset_w(void *fdt,
int offset, int *lenp){ int new_offset; /* * The modification is goind to be done out of libfdt. * Unknown tags are removed (rules for modification when unknown tags * are involved) but also known tags. Indeed, we cannot know if the * modification will have impacts on known tags */ new_offset = fdt_remove_all_tags_due_to_property_modification(fdt, offset); return (struct fdt_property *)(uintptr_t) fdt_get_property_by_offset(fdt, new_offset, lenp); }---- 8< ----
Quoted 8 lines
The idea is to be conservative here also and consider that property data retrieved for writing will be modified by the caller.
Also, the offset used as parameter of
fdt_get_property_by_offset_w()is no more valid after the call.Last point to have in mind, getting the node offset from the property offset will need to walk the tree from the beginning. It can be costly.
Right, that's what I was thinking of when I said this might not be practical to implement. It's doable in the common case where we alter properties by node offset + property name, but not when we use a property offset. But the fact that this would change the offset of the property in queestion is a much bigger showstopper.
Quoted 14 lines
Quoted 2 lines
6. Adding or deleting a property on a node invalidates all unknown tags on the node
Ok.
Quoted 2 lines
7. Adding or deleting a subnode invalidates all unknown tags on the node
Ok.
Quoted 3 lines
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Quoted 8 lines
Ok.
Quoted 3 lines
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Well, this new proposal is more complex to implement than your first proposal but it has a finer grain to handle unknown tags on modification.
Certainly - that's why I proposed the other one first :).
Quoted 7 lines
Quoted 1 line
I can try to implement something based on this new proposal.
To be clear, I kind of prefer my first proposal still. The question is whether what the updated scheme buys (preserving more tags when a bootloader makes minor writes) worth the added complexity of implementation. You're better placed to answer that question than I am.
Quoted 8 lines
I would like to avoid bootloaders being blocking points and so:
a) They should not failed if they encounter an unknown skippable tag. We are in sync on this point.b) They should preserve tags as much as possible.
The goal is to allow following software components (probably the Kernel) to handle new tags.
This is the point where the right balance has be found.Right. I understand why these are both desirable. However (b) is pretty tricky, because of the question of invalidation. It necessarily involves a tradeoff between how much can be preserved versus what sorts of information future tags can carry.
Quoted 13 lines
Your first proposal is maybe too much aggressive on b). That's why, even it is more complex to implement I would prefer your last proposal (taking into account the property offset issue) which can be summarize with the following table:
| existing prop | existing node (1) | Downgrade | unknown tag | unknown tag | version (2) ----------------------+---------------+---------------------+----------- Modify a property (5) | Remove | Keep (3) | Yes Add a property | NA | Remove | Yes Delete a property | Remove | Remove | Yes (4) Add a sub-node | NA | Remove | Yes Delete a sub-node | NA | Remove | YesQuoted 1 line
----------------------+---------------+---------------------+-----------
Great summary, thanks.
Quoted 4 lines
(1) The existing node is the node were the property or sub-node involved are present. Not all nodes, not the parent node but the node directly impacted by the modification.
Quoted 7 lines
Quoted 2 lines
(2) We downgrade the version only if tag are removed. If no unknown tags are involved (and so not removed), the version will not be be downgraded.
Sadly, that doesn't work. We have to downgrade on property modification for the same reason we must downgrade on adding a
property: it might be adding data that requires certain tags in the later version.
Quoted 8 lines
Oh yes, I missed that point.
(2) The version is always downgrade on any changes (modification, addition, deletion of a property or a sub-node) even if no tags are removed. Indeed the modification done (even a property or sub-node deletion) can requires certain tags in the later version.
Downgrading the version on all changes is the way to state that the resulting dtb may be no more compliant with the later version.
Probably wants some editing for clarity in the final version, but basically sounds good.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
(3) Removing unknown tags in the node when a property is modified will lead to the property offset change. Prefer avoid the property offset change and so keep node related unknown tags in that case.
Right, if we did that it would basically mean totally (and incompatibly) redesigning the libfdt interface.
Quoted 3 lines
(4) The version is downgrade only if we remove some tags related to the node. If we remove only tags related to the property we delete, there is no reason to downgrade the version.
Quoted 8 lines
Quoted 3 lines
Unlike (2), I'm not certain if this one is unsafe. But I suspect it might be, and having it behave differently from case (2) seems confusing to me.
Hum ok, let be conservative and remove the note (4).
The updated note (2) handles all modification. On any changes with and without tag removal, the version is downgraded.
Ok.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal.
This point is for the usage of
fdt_get_property_by_offset_w(),fdt_get_property_namelen_w(),fdt_get_property_w(),fdt_getprop_by_offset_w(),fdt_getprop_namelen_w(),fdt_getprop_w()and maybe other similar functions where the property is returned writable for possible modification. 'modify a property' mentioned in the table is related to modification done using fdt_setprop_*() and fdt_appendprop_*() function families.
Quoted 8 lines
Quoted 2 lines
Right. "I know what I'm doing" is part of the implicit contract when using those functions.
Also this note (5) will be updated
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal nor a version downgrade.
The idea's right, though I don't think that expresses it particularly well. Not a priority right now, we can revise that later.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
On your side, is all of that conservative enough to be used when modification involved unknown tags?
Not quite, as noted, but we might be able to get it there.
Is it better?
Yes, it is.
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi David,
Quoted 267 lines · On Sun, 25 Oct 2026 13:11:14 +1100 David Gibson <[email protected]>…
Quoted 209 lines · Herve Codina
Hi David,
Quoted 196 lines · On Fri, 23 Oct 2026 13:57:54 +1100 David Gibson <[email protected]>…
Quoted 160 lines · Herve Codina
Hi David,
Quoted 147 lines · On Thu, 22 Oct 2026 14:17:38 +1100 David Gibson <[email protected]>…
Quoted 48 lines · Herve Codina
Hi David,
Quoted 10 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
No problem, I understand your point.
...
Quoted 6 lines
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.Quoted 6 lines
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and
last_comp_versionretain their meanings. No new header version.Ok
Quoted 2 lines
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
Ok
Quoted 7 lines
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. supposeFDT_FOOtag is introduced in v20. A client reading a v19 tree _might_ see someFDT_FOOtags (because of (2)), but cannot rely on them being present in all the places they should be.Quoted 3 lines
Ok, kind of degraded mode. Whether or not a v20 compatible client can continue or not will depend of each tags known by this v20 client. For some tags, having them removed will not be a problem whereas it will be a problem for some other.
Exactly.
Quoted 7 lines
Makes sense.
Quoted 2 lines
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
Ok
Quoted 7 lines
Quoted 2 lines
5. Any write to a property invalidates all unknown tags on that property's node
Will see in the implementation. The offset of the written property will be incorrect after the write. Indeed, some tags (tags related to the node) available before the property can be removed. With splices instead of
FDT_NOP, offsets change.Oh, good point, this rule doesn't work. I think we still have a consistent set of rules if property writes don't invalidate parent node tags (subnode add/delete still would). Of coutse, that does further restrict what sorts of information you could safely put in node tags under this scheme.
Quoted 2 lines
This also brings a question. Are API functions such as
fdt_get_property_by_offset_w()need to be deprecated?I think we can keep it - kind of like
fdt_next_tag()this is a low-level function. If you use it, you're opting in to having to deal with tag invalidation.Quoted 24 lines
Those kind of functions return a pointer to the data of a property for modification by the caller. We don't know if the caller will modify or not the property.
Without deprecated it we can change the function to ---- 8< ----
structfdt_property*fdt_get_property_by_offset_w(void *fdt,
int offset, int *lenp){ int new_offset; /* * The modification is goind to be done out of libfdt. * Unknown tags are removed (rules for modification when unknown tags * are involved) but also known tags. Indeed, we cannot know if the * modification will have impacts on known tags */ new_offset = fdt_remove_all_tags_due_to_property_modification(fdt, offset); return (struct fdt_property *)(uintptr_t) fdt_get_property_by_offset(fdt, new_offset, lenp); }---- 8< ----
Quoted 8 lines
The idea is to be conservative here also and consider that property data retrieved for writing will be modified by the caller.
Also, the offset used as parameter of
fdt_get_property_by_offset_w()is no more valid after the call.Last point to have in mind, getting the node offset from the property offset will need to walk the tree from the beginning. It can be costly.
Right, that's what I was thinking of when I said this might not be practical to implement. It's doable in the common case where we alter properties by node offset + property name, but not when we use a property offset. But the fact that this would change the offset of the property in queestion is a much bigger showstopper.
Quoted 14 lines
Quoted 2 lines
6. Adding or deleting a property on a node invalidates all unknown tags on the node
Ok.
Quoted 2 lines
7. Adding or deleting a subnode invalidates all unknown tags on the node
Ok.
Quoted 3 lines
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Quoted 8 lines
Ok.
Quoted 3 lines
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Well, this new proposal is more complex to implement than your first proposal but it has a finer grain to handle unknown tags on modification.
Certainly - that's why I proposed the other one first :).
Quoted 7 lines
Quoted 1 line
I can try to implement something based on this new proposal.
To be clear, I kind of prefer my first proposal still. The question is whether what the updated scheme buys (preserving more tags when a bootloader makes minor writes) worth the added complexity of implementation. You're better placed to answer that question than I am.
Quoted 8 lines
I would like to avoid bootloaders being blocking points and so:
a) They should not failed if they encounter an unknown skippable tag. We are in sync on this point.b) They should preserve tags as much as possible.
The goal is to allow following software components (probably the Kernel) to handle new tags.
This is the point where the right balance has be found.Right. I understand why these are both desirable. However (b) is pretty tricky, because of the question of invalidation. It necessarily involves a tradeoff between how much can be preserved versus what sorts of information future tags can carry.
Quoted 13 lines
Your first proposal is maybe too much aggressive on b). That's why, even it is more complex to implement I would prefer your last proposal (taking into account the property offset issue) which can be summarize with the following table:
| existing prop | existing node (1) | Downgrade | unknown tag | unknown tag | version (2) ----------------------+---------------+---------------------+----------- Modify a property (5) | Remove | Keep (3) | Yes Add a property | NA | Remove | Yes Delete a property | Remove | Remove | Yes (4) Add a sub-node | NA | Remove | Yes Delete a sub-node | NA | Remove | YesQuoted 1 line
----------------------+---------------+---------------------+-----------
Great summary, thanks.
Quoted 4 lines
(1) The existing node is the node were the property or sub-node involved are present. Not all nodes, not the parent node but the node directly impacted by the modification.
Quoted 7 lines
Quoted 2 lines
(2) We downgrade the version only if tag are removed. If no unknown tags are involved (and so not removed), the version will not be be downgraded.
Sadly, that doesn't work. We have to downgrade on property modification for the same reason we must downgrade on adding a
property: it might be adding data that requires certain tags in the later version.Quoted 8 lines
Oh yes, I missed that point.
(2) The version is always downgrade on any changes (modification, addition, deletion of a property or a sub-node) even if no tags are removed. Indeed the modification done (even a property or sub-node deletion) can requires certain tags in the later version.
Downgrading the version on all changes is the way to state that the resulting dtb may be no more compliant with the later version.Probably wants some editing for clarity in the final version, but basically sounds good.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
(3) Removing unknown tags in the node when a property is modified will lead to the property offset change. Prefer avoid the property offset change and so keep node related unknown tags in that case.
Right, if we did that it would basically mean totally (and incompatibly) redesigning the libfdt interface.
Quoted 3 lines
(4) The version is downgrade only if we remove some tags related to the node. If we remove only tags related to the property we delete, there is no reason to downgrade the version.
Quoted 8 lines
Quoted 3 lines
Unlike (2), I'm not certain if this one is unsafe. But I suspect it might be, and having it behave differently from case (2) seems confusing to me.
Hum ok, let be conservative and remove the note (4).
The updated note (2) handles all modification. On any changes with and without tag removal, the version is downgraded.
Ok.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal.
This point is for the usage of
fdt_get_property_by_offset_w(),fdt_get_property_namelen_w(),fdt_get_property_w(),fdt_getprop_by_offset_w(),fdt_getprop_namelen_w(),fdt_getprop_w()and maybe other similar functions where the property is returned writable for possible modification. 'modify a property' mentioned in the table is related to modification done using fdt_setprop_*() and fdt_appendprop_*() function families.Quoted 8 lines
Quoted 2 lines
Right. "I know what I'm doing" is part of the implicit contract when using those functions.
Also this note (5) will be updated
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal nor a version downgrade.
The idea's right, though I don't think that expresses it particularly well. Not a priority right now, we can revise that later.
Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
On your side, is all of that conservative enough to be used when modification involved unknown tags?
Not quite, as noted, but we might be able to get it there.
Is it better?
Yes, it is.
Ok, I think we've reached an agreement :)
We have a new set of rules for handling "unknwon" tags on modification. I will implement this set in the next iteration.
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 275 lines · Herve Codina
Hi David,
Quoted 270 lines · On Sun, 25 Oct 2026 13:11:14 +1100 David Gibson <[email protected]>…
Quoted 209 lines · Herve Codina
Hi David,
Quoted 196 lines · On Fri, 23 Oct 2026 13:57:54 +1100 David Gibson <[email protected]>…
Quoted 160 lines · Herve Codina
Hi David,
Quoted 147 lines · On Thu, 22 Oct 2026 14:17:38 +1100 David Gibson <[email protected]>…
Quoted 48 lines · Herve Codina
Hi David,
Quoted 10 lines · On Wed, 21 Oct 2026 13:26:49 +1100 David Gibson <[email protected]>…
Quoted 3 lines
Ok, my proposal seems to be a no-go and so I will follow your proposal given above.
To be clear, I'm rejecting the original proposal because I think it's internally inconsistent (if you follow the consequences of decisions far enough). I'm not necessarily opposed to something other than the above, as long as the rules for when unknown tags must be invalidated (and what that does to the version) are made very clear in the structured tag spec. e.g. see an alternative proposal below.
No problem, I understand your point.
...
Quoted 6 lines
Essentially the theory of the proposal above is to be maximally
conservative: any write (adding, removing, changing, in-place, whatever) will invalidate all unknown tags and downgrade the version.Quoted 6 lines
But, here's an alternative proposal for invalidation/version semantics that I think is consistent, while being a bit closer to your original proposal.
1. version and
last_comp_versionretain their meanings. No new header version.Ok
Quoted 2 lines
2. If version >= 18 the tree may include any structured tags, even if they weren't defined as of v18.
Ok
Quoted 7 lines
3. Some future version might _require_ certain structured tags to be present. But a client must only rely on those tags if the version indicates it can.
- e.g. supposeFDT_FOOtag is introduced in v20. A client reading a v19 tree _might_ see someFDT_FOOtags (because of (2)), but cannot rely on them being present in all the places they should be.Quoted 3 lines
Ok, kind of degraded mode. Whether or not a v20 compatible client can continue or not will depend of each tags known by this v20 client. For some tags, having them removed will not be a problem whereas it will be a problem for some other.
Exactly.
Quoted 7 lines
Makes sense.
Quoted 2 lines
4. Any write to a property (including in place) invalidates all unknown tags on that property (they must be stripped)
Ok
Quoted 7 lines
Quoted 2 lines
5. Any write to a property invalidates all unknown tags on that property's node
Will see in the implementation. The offset of the written property will be incorrect after the write. Indeed, some tags (tags related to the node) available before the property can be removed. With splices instead of
FDT_NOP, offsets change.Oh, good point, this rule doesn't work. I think we still have a consistent set of rules if property writes don't invalidate parent node tags (subnode add/delete still would). Of coutse, that does further restrict what sorts of information you could safely put in node tags under this scheme.
Quoted 2 lines
This also brings a question. Are API functions such as
fdt_get_property_by_offset_w()need to be deprecated?I think we can keep it - kind of like
fdt_next_tag()this is a low-level function. If you use it, you're opting in to having to deal with tag invalidation.Quoted 24 lines
Those kind of functions return a pointer to the data of a property for modification by the caller. We don't know if the caller will modify or not the property.
Without deprecated it we can change the function to ---- 8< ----
structfdt_property*fdt_get_property_by_offset_w(void *fdt,
int offset, int *lenp){ int new_offset; /* * The modification is goind to be done out of libfdt. * Unknown tags are removed (rules for modification when unknown tags * are involved) but also known tags. Indeed, we cannot know if the * modification will have impacts on known tags */ new_offset = fdt_remove_all_tags_due_to_property_modification(fdt, offset); return (struct fdt_property *)(uintptr_t) fdt_get_property_by_offset(fdt, new_offset, lenp); }---- 8< ----
Quoted 8 lines
The idea is to be conservative here also and consider that property data retrieved for writing will be modified by the caller.
Also, the offset used as parameter of
fdt_get_property_by_offset_w()is no more valid after the call.Last point to have in mind, getting the node offset from the property offset will need to walk the tree from the beginning. It can be costly.
Right, that's what I was thinking of when I said this might not be practical to implement. It's doable in the common case where we alter properties by node offset + property name, but not when we use a property offset. But the fact that this would change the offset of the property in queestion is a much bigger showstopper.
Quoted 14 lines
Quoted 2 lines
6. Adding or deleting a property on a node invalidates all unknown tags on the node
Ok.
Quoted 2 lines
7. Adding or deleting a subnode invalidates all unknown tags on the node
Ok.
Quoted 3 lines
8. Whenever a tag is invalidated and stripped, the overall version must be downgraded (to let clients know they can't count on tags being present)
Quoted 8 lines
Ok.
Quoted 3 lines
Points (4)-(7) are all somewhat negotiable. In particular, I'm not sure how feasible (6) is to implement.
Well, this new proposal is more complex to implement than your first proposal but it has a finer grain to handle unknown tags on modification.
Certainly - that's why I proposed the other one first :).
Quoted 7 lines
Quoted 1 line
I can try to implement something based on this new proposal.
To be clear, I kind of prefer my first proposal still. The question is whether what the updated scheme buys (preserving more tags when a bootloader makes minor writes) worth the added complexity of implementation. You're better placed to answer that question than I am.
Quoted 8 lines
I would like to avoid bootloaders being blocking points and so:
a) They should not failed if they encounter an unknown skippable tag. We are in sync on this point.b) They should preserve tags as much as possible.
The goal is to allow following software components (probably the Kernel) to handle new tags.
This is the point where the right balance has be found.Right. I understand why these are both desirable. However (b) is pretty tricky, because of the question of invalidation. It necessarily involves a tradeoff between how much can be preserved versus what sorts of information future tags can carry.
Quoted 13 lines
Your first proposal is maybe too much aggressive on b). That's why, even it is more complex to implement I would prefer your last proposal (taking into account the property offset issue) which can be summarize with the following table:
| existing prop | existing node (1) | Downgrade | unknown tag | unknown tag | version (2) ----------------------+---------------+---------------------+----------- Modify a property (5) | Remove | Keep (3) | Yes Add a property | NA | Remove | Yes Delete a property | Remove | Remove | Yes (4) Add a sub-node | NA | Remove | Yes Delete a sub-node | NA | Remove | YesQuoted 1 line
----------------------+---------------+---------------------+-----------
Great summary, thanks.
Quoted 4 lines
(1) The existing node is the node were the property or sub-node involved are present. Not all nodes, not the parent node but the node directly impacted by the modification.
Quoted 7 lines
Quoted 2 lines
(2) We downgrade the version only if tag are removed. If no unknown tags are involved (and so not removed), the version will not be be downgraded.
Sadly, that doesn't work. We have to downgrade on property modification for the same reason we must downgrade on adding a
property: it might be adding data that requires certain tags in the later version.Quoted 8 lines
Oh yes, I missed that point.
(2) The version is always downgrade on any changes (modification, addition, deletion of a property or a sub-node) even if no tags are removed. Indeed the modification done (even a property or sub-node deletion) can requires certain tags in the later version.
Downgrading the version on all changes is the way to state that the resulting dtb may be no more compliant with the later version.Probably wants some editing for clarity in the final version, but basically sounds good.
Quoted 11 lines
Quoted 11 lines
Quoted 3 lines
(3) Removing unknown tags in the node when a property is modified will lead to the property offset change. Prefer avoid the property offset change and so keep node related unknown tags in that case.
Right, if we did that it would basically mean totally (and incompatibly) redesigning the libfdt interface.
Quoted 3 lines
(4) The version is downgrade only if we remove some tags related to the node. If we remove only tags related to the property we delete, there is no reason to downgrade the version.
Quoted 8 lines
Quoted 3 lines
Unlike (2), I'm not certain if this one is unsafe. But I suspect it might be, and having it behave differently from case (2) seems confusing to me.
Hum ok, let be conservative and remove the note (4).
The updated note (2) handles all modification. On any changes with and without tag removal, the version is downgraded.
Ok.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal.
This point is for the usage of
fdt_get_property_by_offset_w(),fdt_get_property_namelen_w(),fdt_get_property_w(),fdt_getprop_by_offset_w(),fdt_getprop_namelen_w(),fdt_getprop_w()and maybe other similar functions where the property is returned writable for possible modification. 'modify a property' mentioned in the table is related to modification done using fdt_setprop_*() and fdt_appendprop_*() function families.Quoted 8 lines
Quoted 2 lines
Right. "I know what I'm doing" is part of the implicit contract when using those functions.
Also this note (5) will be updated
(5) All property modifications done outside libfdt using directly the property data pointer will not lead to any unknown tag removal nor a version downgrade.
The idea's right, though I don't think that expresses it particularly well. Not a priority right now, we can revise that later.
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
On your side, is all of that conservative enough to be used when modification involved unknown tags?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Not quite, as noted, but we might be able to get it there.
Is it better?
Yes, it is.
Ok, I think we've reached an agreement :)
I concur.
Quoted 2 lines
We have a new set of rules for handling "unknwon" tags on modification. I will implement this set in the next iteration.
Sounds good. Let's hope there's not some showstopper inconsistency neither of us spotted yet.
Signature · 4 lines
David Gibson (he or they) | 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
Re: [PATCH v3 15/15] Introduce v18 dtb version
In reply to David GibsonQuoted 89 lines · David Gibson
Quoted 38 lines · Herve Codina
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?Quoted 8 lines
We had one
last_comp_version.Now we have two
last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Ok, I now see that the logic is you simply fail to proceed with writes if the library's latest understood version is <
last_comp_version_w.As I said elsewhere, this approach doesn't particularly make sense to me. If
lib_version>=last_comp_versionyou *can* write, even if it means stripping everything that's not understood atlib_version.So the real question here is how do we know, for any given structured tag, what write operations require the version to be downgraded (which might in turn require this and/or other structured tags to be stripped entirely).
This is related to (though not the same as) the question of whether introducing a new structured tags requires a bump to the dtb version (though not to
last_comp_version, of course).Here's the simplest model I can think of. It's what I'd suggest, unless one of it's limitations is a showstopper for what you have in mind:
- version and
last_comp_versionretain their meanings. No new header version.
- New structured tags *do* require a new version. If a dtb wants to include a specific tag, it must label itself with a version that defines that tag. To enforce that:
- For read operations, if we encounter a (known) tag that doesn't belong in the header version, we throw an error (either BADSTRUCTURE, or a new error for the purpose).
- If version <=FDT_LAST_SUPPORTED_VERSIONand we encounter an unknown tag that also trips the error (since if it was defined in this version, we should know about it).
- For write operations (including in-place), we always error if version >FDT_LAST_SUPPORTED_VERSION(done infdt_rw_probe_()).
-fdt_open_into()_is_ permitted if version >FDT_LAST_SUPPORTED_VERSION. It will strip all unknown structured tags from the entire tree and downgrade the version toFDT_LAST_SUPPORTED_VERSION.This does mean that every new tag does require a new version, which may make experimenting with new tags more awkward. More significantly, it also means that any change requires a version downgrade, even if it's just updating a handful of properties.
Quoted 7 lines
On the plus side, it's fairly simple, retains as much as possible current version semantics. Most especially there's no tricky questions about what sorts of writes might invalidate an unknown tag (they'll all be stripped by the time we permit a write operation).
If those limitations really are a showstopper, I do have a few other models that might work, though.
The limitations do not sound too bad. And it feels easier to implement than keeping track of read and write versions separately for each new tag.
Quoted 26 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines
- When a property is modified, tags related to this property are removed and the dtb version is downgraded.
We need a definition of what "related to" means somewhere.
Quoted 8 lines
Yes a tag is said related to a property if it is available after its
FDT_PROPand before the nextFDT_PROP(other proterty) ofFDT_BEGIN_NODE(subnode) forFDT_NODE_END(end of node).This is defined by "structured tag"
Devicetree Specification will be updated to have all of this documentation available.
Ok.
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
- When a property is removed, tags related to this property are obviously removed. The dtb version is kept unchanged.
- When a property or a node is added, obviously no unknown tags are added and the dtb version is kept unchanged.
Again, this rule doesn't make sense to me at the same time as the property modification rule.
Quoted 8 lines
Quoted 2 lines
A current libfdt/dtc version cannot add tags which will be defined in the future.
Sure, but it can still add whole new nodes or properties. The question is whether a version can mandate the presence of certain tags. Dowgrading the version when we strip tags from a modified property suggests "yes", but _not_ downgrading the version when we add new property suggests "no".
Well, I could see version mandating the presence of certain tags for devicetree overlays at least. Not quite sure if the same would apply for new addon board overlays though.
Quoted 31 lines
Quoted 31 lines
Quoted 30 lines
Quoted 17 lines
- When a node is removed, tags related to this node are obviously removed. The dtb version is kept unchanged.
- Adding, removing or modifying a property is not considered as a node modification and so, those operations have no impacts on unknown tags related to the node. Those node related tags are kept unchanged.
- The only modification considered as a node modification is setting its name. We consider that this operation has no impact on tags related to the node. Here also, those node related tags and the dtb version are kept unchanged.
- Global (dtb related) unknown tags are kept unchanged regardless the modification done.
Quoted 7 lines
In all cases, if unknown tags are not involved in a modification, the dtb version is not downgraded when the modification is made.
It is worth noting that with this v18 version, the dtb version is not downgraded for any modification but only when unknown tags are removed due to a property modification. In v17 or older version any modification led to a dtb version downgrade.
I don't think removing that behaviour is safe. Even if the rules above make sense specifically for the metadata tags (which I'm not yet convinced of), that's not sufficient. If nothing else, future versions could add extra header fields. If we modify the tree, those header fields could be stale, or even removed.
Quoted 7 lines
Quoted 7 lines
last_comp_version_wwill be used by the future version to prevent this kind of issue with old version.Best regards,
Hervé
Best Regards,
Ayush Singh
Signature · 2 lines
BeagleBoard.org Foundation https://www.beagleboard.org
Re: [PATCH v3 15/15] Introduce v18 dtb version
Hi Ajush,
Quoted 96 lines · On Tue, 13 Oct 2026 22:34:57 +0530 Ayush Singh <[email protected]> wrote:
Quoted 94 lines · David Gibson
Quoted 38 lines · Herve Codina
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?Quoted 8 lines
We had one
last_comp_version.Now we have two
last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Ok, I now see that the logic is you simply fail to proceed with writes if the library's latest understood version is <
last_comp_version_w.As I said elsewhere, this approach doesn't particularly make sense to me. If
lib_version>=last_comp_versionyou *can* write, even if it means stripping everything that's not understood atlib_version.So the real question here is how do we know, for any given structured tag, what write operations require the version to be downgraded (which might in turn require this and/or other structured tags to be stripped entirely).
This is related to (though not the same as) the question of whether introducing a new structured tags requires a bump to the dtb version (though not to
last_comp_version, of course).Here's the simplest model I can think of. It's what I'd suggest, unless one of it's limitations is a showstopper for what you have in mind:
- version and
last_comp_versionretain their meanings. No new header version.
- New structured tags *do* require a new version. If a dtb wants to include a specific tag, it must label itself with a version that defines that tag. To enforce that:
- For read operations, if we encounter a (known) tag that doesn't belong in the header version, we throw an error (either BADSTRUCTURE, or a new error for the purpose).
- If version <=FDT_LAST_SUPPORTED_VERSIONand we encounter an unknown tag that also trips the error (since if it was defined in this version, we should know about it).
- For write operations (including in-place), we always error if version >FDT_LAST_SUPPORTED_VERSION(done infdt_rw_probe_()).
-fdt_open_into()_is_ permitted if version >FDT_LAST_SUPPORTED_VERSION. It will strip all unknown structured tags from the entire tree and downgrade the version toFDT_LAST_SUPPORTED_VERSION.This does mean that every new tag does require a new version, which may make experimenting with new tags more awkward. More significantly, it also means that any change requires a version downgrade, even if it's just updating a handful of properties.
On the plus side, it's fairly simple, retains as much as possible current version semantics. Most especially there's no tricky questions about what sorts of writes might invalidate an unknown tag (they'll all be stripped by the time we permit a write operation).
Quoted 5 lines
Quoted 2 lines
If those limitations really are a showstopper, I do have a few other models that might work, though.
The limitations do not sound too bad. And it feels easier to implement than keeping track of read and write versions separately for each new tag.
But it doesn't handle the use case I mentioned in a previous reply :(
bootloader knows about version 2.0
kernel knowns about version 3.0
dtb 3.0 we want the bootloader to skip tags it doesn't know about but this same bootloader has to handle 'unknown' tags on some modification. We want to have possibilities to let this bootloader perform those modifications (under precise known rules) and pass this dtb to the kernel.
Best regards,
Hervé
Re: [PATCH v3 15/15] Introduce v18 dtb version
Quoted 112 lines · Herve Codina
Hi Ajush,
Quoted 96 lines · On Tue, 13 Oct 2026 22:34:57 +0530 Ayush Singh <[email protected]> wrote:
Quoted 94 lines · David Gibson
Quoted 38 lines · Herve Codina
Hi David,
Quoted 25 lines · On Mon, 21 Sep 2026 16:20:02 +1000 David Gibson <[email protected]>…
Quoted 24 lines · Herve Codina
This v18 version will add support for
- Structured tags.
Those tags value definition will allow "old" libfdt, dtc and other tools to skip unknown tags if encountered in future dtb version.libfdt, dtc and other tools implementing version v18 will be able to skip unknown tags available in dtbd generated with later version of dtc.
-
dt_flagsheader field.
For now this flag field is set to 0. It is a placeholder for future dtb version and could be used to store some dtb related information such as the kind of dtb. For instance, the future addons format will use this field to clearly identify that the dtb is an addon dtb.-
last_comp_version_wheader field.
This field is similar tolast_comp_versionbut for writing. It contains the lowest version of the devicetree data structure with which the version used can safely perform modifications (taking into account following rules related to unknown tags).
If this lowest version is greater than the last known supported version, modification are simply forbidden and lead to aFDT_ERR_BADVERSIONerror.Quoted 7 lines
Quoted 3 lines
For modification, when an unknown tag that can be skipped is involved and
last_comp_version_wallows modifications, the following rules apply:"
last_comp_version_wallows modifications" is a bit hard to understand. What exactly is the version number against which we're comparing that value?Quoted 8 lines
We had one
last_comp_version.Now we have two
last_comp_version, one for reading and one for writing. We compare again the dtb version supported by our libfdt version.This comes from the discussion [1]
[1] https://lore.kernel.org/all/CAL_JsqLRrbZje_gGZPBDni6StFa+6rdiECtk49on8VfkP7CDvw@mail.gmail.com/
Ok, I now see that the logic is you simply fail to proceed with writes if the library's latest understood version is <
last_comp_version_w.As I said elsewhere, this approach doesn't particularly make sense to me. If
lib_version>=last_comp_versionyou *can* write, even if it means stripping everything that's not understood atlib_version.So the real question here is how do we know, for any given structured tag, what write operations require the version to be downgraded (which might in turn require this and/or other structured tags to be stripped entirely).
This is related to (though not the same as) the question of whether introducing a new structured tags requires a bump to the dtb version (though not to
last_comp_version, of course).Here's the simplest model I can think of. It's what I'd suggest, unless one of it's limitations is a showstopper for what you have in mind:
- version and
last_comp_versionretain their meanings. No new header version.
- New structured tags *do* require a new version. If a dtb wants to include a specific tag, it must label itself with a version that defines that tag. To enforce that:
- For read operations, if we encounter a (known) tag that doesn't belong in the header version, we throw an error (either BADSTRUCTURE, or a new error for the purpose).
- If version <=FDT_LAST_SUPPORTED_VERSIONand we encounter an unknown tag that also trips the error (since if it was defined in this version, we should know about it).
- For write operations (including in-place), we always error if version >FDT_LAST_SUPPORTED_VERSION(done infdt_rw_probe_()).
-fdt_open_into()_is_ permitted if version >FDT_LAST_SUPPORTED_VERSION. It will strip all unknown structured tags from the entire tree and downgrade the version toFDT_LAST_SUPPORTED_VERSION.This does mean that every new tag does require a new version, which may make experimenting with new tags more awkward. More significantly, it also means that any change requires a version downgrade, even if it's just updating a handful of properties.
On the plus side, it's fairly simple, retains as much as possible current version semantics. Most especially there's no tricky questions about what sorts of writes might invalidate an unknown tag (they'll all be stripped by the time we permit a write operation).
Quoted 5 lines
Quoted 2 lines
If those limitations really are a showstopper, I do have a few other models that might work, though.
The limitations do not sound too bad. And it feels easier to implement than keeping track of read and write versions separately for each new tag.
But it doesn't handle the use case I mentioned in a previous reply :(
bootloader knows about version 2.0
kernel knowns about version 3.0
Quoted 7 lines
dtb 3.0 we want the bootloader to skip tags it doesn't know about but this same bootloader has to handle 'unknown' tags on some modification. We want to have possibilities to let this bootloader perform those modifications (under precise known rules) and pass this dtb to the kernel.
Best regards,
Hervé
Apologies, I guess your email with the bootloader case came while I was composing, hence missed it.
Anyway, that is an interesting case, and well, it does happen rather frequently in embedded devices. I just did not consider it in the earlier reply. If I remember correctly, U-boot does some dt fixups after detecting things like GPU in case of TI AM62 (used in BeaglePlay and PocketBeagle 2).
Best Regards,
Ayush Singh
Signature · 2 lines
BeagleBoard.org Foundation https://www.beagleboard.org