-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve dtdiff by avoiding or nulling the phandles #145
Comments
I agree, this would be very useful to have. |
Here is a temporary hack to print NULL for all phandles: diff --git a/treesource.c b/treesource.c
index ae15839..8fb3bf4 100644
--- a/treesource.c
+++ b/treesource.c
@@ -204,6 +204,11 @@ static void write_propval(FILE *f, struct property *prop)
enum markertype emit_type = TYPE_NONE;
char *srcstr;
+ if (strcmp(prop->name, "phandle") == 0) {
+ fprintf(f, " = NULL;\n");
+ return;
+ }
+
if (len == 0) {
fprintf(f, ";");
if (annotate) { |
If you just want to skip the actual If you wanted to skip phandles included in other properties, that would be much, much harder. |
Would you recommend handling that in the input side of things or the output? The above hack is doing it on the output. Just looking for a starting place to look.
Yeah I mean that would be good as well but agreed that it would be more involved. Is it reasonable to try and handle both scenarios by replacing the handle hex value with the node name its pointing too? Also, do you have any suggestions for what you would like the new argument to be? I mentioned the phandle format option but looking at the code I'm unclear what that's doing, or if its even relevant. Would you prefer to add a generic --diff-format option that could be improved/expanded later. Or a more specific option (--skip-phandles) that describes what this change is doing. |
Output definitely. That way all the internal processing of phandles remains unchanged.
Actually, that's a good point. If you're coming from dts input, the type markers we already have mean that references to phandles should already be shown as
I'd suggest something specific, much like |
Ahh I didn't know about that. I just read through https://elinux.org/Device_Tree_Mysteries#Phandle which explains it quite well.
|
A simpler change would be something like the following, though it will add a dependency on sed or grep. It brings up the question of do you want dtdiff to always drop phandles or is it okay to add argument handling to this script? --- a/dtdiff
+++ b/dtdiff
@@ -28,7 +28,7 @@ source_and_sort () {
exit 2
fi
- $DTC -I $IFORMAT -O dts -qq -f -s -o - "$DT"
+ $DTC -I $IFORMAT -O dts -qq -f -s -o - "$DT" | grep -v 'phandle ='
}
if [ $# != 2 ]; then |
Simpler, but not necessarily reliable. It will incorrectly omit lines that happen to have "phandle =" in them, even if it's a string in the property value. |
Sure, I don't think "phandle =" is likely to show up in a property value but if you'd prefer the more thorough implementation, I'll look into it. |
It's certainly not likely, but I'd rather not a hard to debug edge case as a landmine for the future. |
Makes sense. Separately I was thinking about trying to track phandles and thought up a possible method.
I will write something up in python to give this a try. |
Here is a first pass at implementing a dtdiff in python https://gist.github.com/jcormier/4af3e1a33cfc4d20690350cfa9e134a1 |
I don't think this is a wise approach. The basic idea of attempting to recognize phandle changes by the values is flawed, I think. It'll get it right most of the time, but it will be very confusing when it interprets some unrelated change as a phandle update. More superficially this is using regexes to re-parse parts of the tree from source, which seems a very roundabout way of doing things when dtc can already parse and knows some of the mappings you're trying to determine internally. I'm not very convinced about the robustness of a bunch of those regexes either (phandles need not have exactly two hex digits, for one example). In short, this seems like a lot of trouble and complexity to go to, to get a result that won't even be reliable. |
FYI, #100 by @ukleinek was meant to be a first step towards improving dtdiff. By keeping around the information about labels, it's possible to decompile them and have This doesn't help you however if the only thing you have is the compiled device trees that lack the fixup information. |
First I don't think the tool I'm looking for needs to be perfect. I just want to find likely changes between two device trees for when things stop working between one version and another. And the old dtdiff easily prints out several thousand lines of diff. And even this quick hack, drops that down to a hundred. There is a pretty low risk that a phandle changes from 0xa1 to 0xa5, and a completely unrelated value also changes from 0xa1 to 0xa5.
This is fair, however I'm not familiar with this code base or parsing code in general. My first pass through the code told me it would take me too long to figure out how to implement a phandle map, when this was just going to be a proof of concept. And making one in python was simple enough, I was going to do it using "awk" but that would have been even less readable. Note that since dtc itself cannot determine what is a phandle or not since it is only ever fed one file at a time. This method requires looking at both dtb files together, to get the context of what is or isn't a phandle value. I'm pretty sure that's not a feature that would make sense to bake into dtc. But dtc could easily create some kind of phandle map file...
Good catch. Hexvalues are always going to end with a space or non-alphanumeric character so no need to limit them to 1-byte |
Basically, yes.
Ok. For your own tool do whatever works for you, obviously. But I'm saying that approach would not be suitable for an "official" tool packaged as part of the dtc/libfdt tree.
Pretty low, yes, but not so low I'm comfortable with it: I've seen a whole heap of unlikely coincidences like this cause very cryptic problems in my time. Also consider that while an unrelated change from
Right. As I think @a3f is obliquely suggesting you could use the
That's kind of what
|
I should have checked, --symbols is enabled to support overlays at least in the 6.1 kernel. So my device trees don't have fixups built in.
Fair enough. I still suspect it would be a useful tool for more than just me. Maybe this issue will serve as a starting place for someone else looking for this feature. I suppose if the kernel outputted intermediate dts files with all the #includes handled, I wouldn't need to compare dtb files. Then all of this wouldn't be needed in most cases. |
I don't think the second sentence follows from the first. But I guess your point is that the kernel uses
It should be pretty easy to make it do that. Just find the rules in the makefile that invoke dtc to build the dtbs, and change it from |
Hmm, I see a symbols struct in my dtb but I don't see any fixup related entries. So I assumed they weren't being added. In fact it doesn't look like the -L option was included in the kernel until 6.11
Okay. Good idea. I however cannot find a instance of '-O dtb' in the kernel source tree, that isn't linked to mips or powerpc. So it must be using some variables or similar to obscure it... I did however find something surprising and potentially useful. A kernel supplied dtb/s diff tool
This does handle diffing dts files with #includes. Unfortunately, it doesn't do anything to handle the phandle changes so it's just as painful to dig through the diff. How feasible would it be to have an option which allows -O dts, to leave the phandle labels in place? So
|
On Fri, Sep 20, 2024 at 02:24:22PM -0700, jcormier wrote:
> I don't think the second sentence follows from the first. But I guess your point is that the kernel uses `-@` but not `-L` which would generate the fixups as well
Hmm, I see a symbols struct in my dtb but I don't see any fixup
related entries. So I assumed they weren't being added. In fact it
doesn't look like the -L option was included in the kernel until
6.11
You mean it was included in the options given to dtc after that? Or
that at that point the embedded dtc version had support for the flag?
> It should be pretty easy to make it do that. Just find the rules
> in the makefile that invoke dtc to build the dtbs, and change it
> from `-O dtb` to `-O dts`.
Okay. Good idea. I however cannot find a instance of '-O dtb' in the
kernel source tree, that isn't linked to mips or powerpc. So it must
be using some variables or similar to obscure it...
Oof, yeah, it's pretty hard to find the right place in Kbuild. I
eventually tracked it to cmd_dtc in scripts/Makefile.lib. Looks like
it's relying on the fact that -O dtb is the default. So it would be a
matter of adding -O dts. How to get that to play with the rest of the
Kbuild stuff.... does seem a bit tricky, yes.
I did however find something surprising and potentially useful. A
kernel supplied dtb/s diff tool
```
./scripts/dtc/dtx_diff -h
Huh, I didn't know about that.
Usage:
dtx_diff DTx
decompile DTx
dtx_diff DTx_1 DTx_2
diff DTx_1 and DTx_2
--annotate synonym for -T
--color synonym for -c (requires diff with --color support)
-c enable colored output
-f print full dts in diff (--unified=99999)
-h synonym for --help
-help synonym for --help
--help print this message and exit
-s SRCTREE linux kernel source tree is at path SRCTREE
(default is current directory)
-S linux kernel source tree is at root of current git repo
-T annotate output .dts with input source file and line
(-T -T for more details)
-u unsorted, do not sort DTx
Each DTx is processed by the dtc compiler to produce a sorted dts source
file. If DTx is a dts source file then it is pre-processed in the same
manner as done for the compile of the dts source file in the Linux kernel
build system ('#include' and '/include/' directives are processed).
```
This does handle diffing dts files with #includes. Unfortunately, it
doesn't do anything to handle the phandle changes so it's just as
painful to dig through the diff. How feasible would it be to have
an option which allows -O dts, to leave the phandle labels in place?
So `syscon = <0x35>;` would be `syscon = <&wkup_conf>;` instead.
If coming *from* dts, not at all tricky - we already do this. If
coming from dtb, impossible in general. That information simply isn't
in there, by the time it's compiled the phandle value is known and its
just bytes.
If compiled as an overlay or with -L *some* of that information can be
reconstructed. For things that end up in __fixups__ it wouldn't be
too bad. For things that end up in __local_fixups__ it's harder.
__local_fixups__ itself doesn't include the label names, but it
*might* be possible to reconstruct that from __symbols__.
But again, in general, not possible.
…--
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
|
The embedded dtc got support for the flag. I didn't see any commits actually using it.
Yeah, this is the scenario I was thinking about. I understand the limitations with the dtb's, at least the ones discussed in this issue.
When running the dtx_diff tool on two dts files, it still outputted the phandles instead of labels. Is it a simple matter to keep it from doing that? |
Ok.
I don't know, sorry. I had a brief look at dtx_diff and found it surprisingly complicated and hard to follow. It's also possible this is a question of the embedded dtc version again. |
Yeah no kidding.
Is this something the normal dtc binary does by default when you |
The dtdiff tool is super useful when trying to compare two different device trees. However, it generally generates a ton of noise flagging all the phandles as changed between the two devices. This makes it hard to see the real changes.
How hard would it be to add a flag to the dtc compiler, maybe a phandle format that reports all phandles as 0x0?
The text was updated successfully, but these errors were encountered: