Skip to contentSkip to conversation

A question about generated phandle during dtb=>dts conversion

DISCUSSION Chan Kim 2 participants 4 messages Nov 2, 2021 – Nov 5, 2021

lore
Share & tools
lore

Chan Kim

author
#0 lore raw

Hello, all
I extracted a dtb file from qemu execution (arm virt machine) and converted the dtb file to dts file using dtc.
But for some node that is referenced by other nodes, the phandle is generated like “phandle = <0x8000>” as shown below.

apb-pclk {
        phandle = <0x8000>;
        clock-output-names = "clk24mhz";
        clock-frequency = <0x16e3600>;
        #clock-cells = <0x00>;
        compatible = "fixed-clock";
    };

And another node is using this phandle like this. (the clocks is the phandle for the apb-pclk above.)

pl061@9030000 {
        phandle = <0x8003>;
        clock-names = "apb_pclk";
        clocks = <0x8000>;
        interrupts = <0x00 0x07 0x04>;
        gpio-controller;
        #gpio-cells = <0x02>;
        compatible = "arm,pl061\0arm,primecell";
        reg = <0x00 0x9030000 0x00 0x1000>;
    };

When I convert the dts back to the dtb, dtc doesn’t understand the phandle and complains that it is not a phandle referenece.

dts.dts:276.3-21: Warning (clocks_property): /pl061@9030000:clocks: cell 0 is not a phandle reference

I’ve checked event with this warning, the phandle reference is being preserved through out the procedure.
So, if I want to extract a dtb and convert it to dts, edit some and convert it back to dtb, how can I prevent this kind of phandle warning? And why doesn't dtc add labels to the referenced nodes and let other nodes use that label as phandle?

Thank you!
Regards,

Chan Kim

#1 lore raw
Quoted 5 lines · Chan Kim

Hello, all
I extracted a dtb file from qemu execution (arm virt machine) and converted the dtb file to dts file using dtc.
But for some node that is referenced by other nodes, the phandle is generated like “phandle = <0x8000>” as shown below.

Note that the value is generated by qemu and is in the dtb. It's not generated by dtc during decompilation.

Quoted 28 lines

apb-pclk {
        phandle = <0x8000>;
        clock-output-names = "clk24mhz";
        clock-frequency = <0x16e3600>;
        #clock-cells = <0x00>;
        compatible = "fixed-clock";
    };

And another node is using this phandle like this. (the clocks is the phandle for the apb-pclk above.)

pl061@9030000 {
        phandle = <0x8003>;
        clock-names = "apb_pclk";
        clocks = <0x8000>;
        interrupts = <0x00 0x07 0x04>;
        gpio-controller;
        #gpio-cells = <0x02>;
        compatible = "arm,pl061\0arm,primecell";
        reg = <0x00 0x9030000 0x00 0x1000>;
    };

When I convert the dts back to the dtb, dtc doesn’t understand the phandle and complains that it is not a phandle referenece.

dts.dts:276.3-21: Warning (clocks_property): /pl061@9030000:clocks: cell 0 is not a phandle reference

Quoted 6 lines

I’ve checked event with this warning, the phandle reference is being preserved through out the procedure.
So, if I want to extract a dtb and convert it to dts, edit some and convert it back to dtb, how can I prevent this kind of phandle warning? And why doesn't dtc add labels to the referenced nodes and let other nodes use that label as phandle?

The short answer is because dtc doesn't know it's a phandle. dtb is not a self-describing format - the properties are just bytestrings, and you need to know what you're expecting in there in order to decode them (that's what dt bindings give you).

So the only way that dtc could know that those 4 bytes in the 'clocks' property are actually a phandle is by specifically knowing about the "clocks" property. dtc has *some* knowledge of specific properties in the checks, but it's far from complete (and complete knowledge of the bindings is pretty much out of scope for dtc).

But.. for the normal case of writing a dts file directly, it's useful to get a warning if you don't use a reference somewhere you probably should (anywhere that's a phandle), so dtc does check that.

So, I think basically in just the same way that you might expect generated or decompiled code to be rather messy and generate compiler warnings, so a decompiled dts might have messy things and generate warnings. You can switch off the warnings explicitly if you need (-Wno-clocks_property in this case).

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
author
#2 lore raw

Hi, David Gibson,
Thank you for the answer. I can understand it now. Best regards,
Chan Kim

Quoted 79 lines

-----Original Message-----
From: David Gibson <[email protected]>
Sent: Wednesday, November 3, 2021 11:34 AM
To: Chan Kim <[email protected]>
Cc: [email protected]
Subject: Re: A question about generated phandle during dtb=>dts conversion

Quoted 5 lines · Chan Kim

Hello, all
I extracted a dtb file from qemu execution (arm virt machine) and converted the dtb file to dts file using dtc.
But for some node that is referenced by other nodes, the phandle is generated like “phandle = <0x8000>” as shown below.

Note that the value is generated by qemu and is in the dtb. It's not generated by dtc during decompilation.

Quoted 28 lines

apb-pclk {
        phandle = <0x8000>;
        clock-output-names = "clk24mhz";
        clock-frequency = <0x16e3600>;
        #clock-cells = <0x00>;
        compatible = "fixed-clock";
    };

And another node is using this phandle like this. (the clocks is the phandle for the apb-pclk above.)

pl061@9030000 {
        phandle = <0x8003>;
        clock-names = "apb_pclk";
        clocks = <0x8000>;
        interrupts = <0x00 0x07 0x04>;
        gpio-controller;
        #gpio-cells = <0x02>;
        compatible = "arm,pl061\0arm,primecell";
        reg = <0x00 0x9030000 0x00 0x1000>;
    };

When I convert the dts back to the dtb, dtc doesn’t understand the phandle and complains that it is not a phandle referenece.

dts.dts:276.3-21: Warning (clocks_property): /pl061@9030000:clocks:
cell 0 is not a phandle reference

Quoted 6 lines

I’ve checked event with this warning, the phandle reference is being preserved through out the procedure.
So, if I want to extract a dtb and convert it to dts, edit some and convert it back to dtb, how can I prevent this kind of phandle warning? And why doesn't dtc add labels to the referenced nodes and let other nodes use that label as phandle?

The short answer is because dtc doesn't know it's a phandle. dtb is not a self-describing format - the properties are just bytestrings, and you need to know what you're expecting in there in order to decode them (that's what dt bindings give you).

So the only way that dtc could know that those 4 bytes in the 'clocks' property are actually a phandle is by specifically knowing about the "clocks" property. dtc has *some* knowledge of specific properties in the checks, but it's far from complete (and complete knowledge of the bindings is pretty much out of scope for dtc).

But.. for the normal case of writing a dts file directly, it's useful to get a warning if you don't use a reference somewhere you probably should (anywhere that's a phandle), so dtc does check that.

So, I think basically in just the same way that you might expect generated or decompiled code to be rather messy and generate compiler warnings, so a decompiled dts might have messy things and generate warnings. You can switch off the warnings explicitly if you need (-Wno-clocks_property in this case).

--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_
_other_

				| _way_ _around_!

http://www.ozlabs.org/~dgibson

#3 lore raw
Quoted 77 lines · Chan Kim

Hi, David Gibson,
Thank you for the answer. I can understand it now. Best regards,
Chan Kim

Quoted 72 lines

-----Original Message-----
From: David Gibson <[email protected]>
Sent: Wednesday, November 3, 2021 11:34 AM
To: Chan Kim <[email protected]>
Cc: [email protected]
Subject: Re: A question about generated phandle during dtb=>dts conversion

Quoted 5 lines · Chan Kim

Hello, all
I extracted a dtb file from qemu execution (arm virt machine) and converted the dtb file to dts file using dtc.
But for some node that is referenced by other nodes, the phandle is generated like “phandle = <0x8000>” as shown below.

Note that the value is generated by qemu and is in the dtb. It's not generated by dtc during decompilation.

Quoted 28 lines

apb-pclk {
        phandle = <0x8000>;
        clock-output-names = "clk24mhz";
        clock-frequency = <0x16e3600>;
        #clock-cells = <0x00>;
        compatible = "fixed-clock";
    };

And another node is using this phandle like this. (the clocks is the phandle for the apb-pclk above.)

pl061@9030000 {
        phandle = <0x8003>;
        clock-names = "apb_pclk";
        clocks = <0x8000>;
        interrupts = <0x00 0x07 0x04>;
        gpio-controller;
        #gpio-cells = <0x02>;
        compatible = "arm,pl061\0arm,primecell";
        reg = <0x00 0x9030000 0x00 0x1000>;
    };

When I convert the dts back to the dtb, dtc doesn’t understand the phandle and complains that it is not a phandle referenece.

dts.dts:276.3-21: Warning (clocks_property): /pl061@9030000:clocks:
cell 0 is not a phandle reference

Quoted 6 lines

I’ve checked event with this warning, the phandle reference is being preserved through out the procedure.
So, if I want to extract a dtb and convert it to dts, edit some and convert it back to dtb, how can I prevent this kind of phandle warning? And why doesn't dtc add labels to the referenced nodes and let other nodes use that label as phandle?

The short answer is because dtc doesn't know it's a phandle. dtb is not a self-describing format - the properties are just bytestrings, and you need to know what you're expecting in there in order to decode them (that's what dt bindings give you).

So the only way that dtc could know that those 4 bytes in the 'clocks' property are actually a phandle is by specifically knowing about the "clocks" property. dtc has *some* knowledge of specific properties in the checks, but it's far from complete (and complete knowledge of the bindings is pretty much out of scope for dtc).

But.. for the normal case of writing a dts file directly, it's useful to get a warning if you don't use a reference somewhere you probably should (anywhere that's a phandle), so dtc does check that.

So, I think basically in just the same way that you might expect generated or decompiled code to be rather messy and generate compiler warnings, so a decompiled dts might have messy things and generate warnings. You can switch off the warnings explicitly if you need (-Wno-clocks_property in this case).

Actually, a nicer way of handling this just occurred to me. It would probably be a good idea to add to the dts syntax a new tag, maybe "/strict/". Without this tag, checks which rely on information that's only in the source, not the dtb (types, phandles etc.) would be disabled by default.

The tag itself obviously wouldn't be encoded into the dtb, so if you compiled then decompiled the tag would be lost, meaning that the output dtb wouldn't trigger checks.

Unfortunately, I'm very unlikely to have time to implement this any time soon.

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson