Skip to contentSkip to conversation

dtc 1.6.0 overlay full-path reference in array produces broken property names

DISCUSSION Vincent Pelletier 2 participants 5 messages Sep 27, 2021 – Jul 31, 2022 2 messages not in the archive

lore
Share & tools
lore
#0 lore raw

(please keep me cc'ed in replies)

Hello,

I suspect this may be a dtc bug, but I am not too familiar with devicetree specs to tell.

Here is a simplified example reproducing this issue:

(SNIP)
/dts-v1/;
/plugin/;

/ {
compatible = "foo";
};

&{/soc/gpio@7e200000} {
    status = "okay";
};
&{/soc/spi@7e204000} {
    cs-gpios = <&{/soc/gpio@7e200000} 8 0x01>;
};

(SNIP)

This code builds fine:

  $ dtc -I dts -O dtb -o test.dtbo test.dts
  $
But then when disassembling the output, I get:
  $ dtc -I dtb -O dts test.dtbo
  <stdout>: ERROR (property_name_chars): /__fixups__:/soc/gpio@7e200000: Bad character '/' in property name
  ERROR: Input tree has errors, aborting (use -f to force output)
And forcing output:
  $ dtc -I dtb -O dts -f test.dtbo
  <stdout>: ERROR (property_name_chars): /__fixups__:/soc/gpio@7e200000: Bad character '/' in property name
  Warning: Input tree has errors, output forced
  /dts-v1/;
  / {
          compatible = "foo";
          fragment@0 {
                  target-path = "/soc/gpio@7e200000";

                  __overlay__ {
                          status = "okay";
                  };
          };

          fragment@1 {
                  target-path = "/soc/spi@7e204000";

                  __overlay__ {
                          cs-gpios = <0xffffffff 0x08 0x01>;
                  };
          };

          __fixups__ {
                  /soc/gpio@7e200000 = "/fragment@1/__overlay__:cs-gpios:0";
          };

};

Indeed, the node in __fixups__ has an invalid name.

I suspect this is uncommon because:
- it probably only occurs in overlays and not in self-contained trees, as a self-contained tree would likely produce an internal phandle and never store the full path anywhere.
- ...which does not attach to labels but full paths
Labels being (probably ?) valid node names, they would avoid the issue.
- ...in arrays
In a node overlay, the full path ends up as a quoted string, not as a name, so it is safe.

Is this a dtc bug ?

I came up with the following workaround which gets me what I need, but it is not very nice (extract):

  &{/soc} {
    gpio: gpio@7e200000 {
      #gpio-cells = <0x02>;
    };
    spi: spi@7e204000 {
      #address-cells = <1>;
      #size-cells = <0>;
    };
  };
  ...
  &spi {
      cs-gpios = <&gpio 8 0x01>;
  };

IOW:
- overlay the parent of the nodes I am interested in, just to declare labels
- ...while at it, repeat a few of the #... properties, which seem magic (this is where my devicetree knowledge ends, really)
- and go on implementing the actual overlays I want, using the just-defined labels.

Regards,

Signature · 2 lines
Vincent Pelletier
GPG fingerprint 983A E8B7 3B91 1598 7A92 3845 CAC9 3691 4257 B0C1
#2 lore raw
In reply to a message not in the archive
Quoted 1 line · Vincent Pelletier

(please keep me cc'ed in replies)

[...]

Quoted 7 lines

This code builds fine:

  $ dtc -I dts -O dtb -o test.dtbo test.dts
  $
But then when disassembling the output, I get:
  $ dtc -I dtb -O dts test.dtbo
  <stdout>: ERROR (property_name_chars): /__fixups__:/soc/gpio@7e200000: Bad character '/' in property name
  ERROR: Input tree has errors, aborting (use -f to force output)

I just noticed 1.6.1 was released (but not packaged yet by my distribution, it seems), so I reproduced from git master as of

commit e33ce1d6a8c7e54e3ad12cff33690b6da0aee1dc (HEAD -> master, origin/master, origin/main, origin/HEAD)
Author: David Gibson <[email protected]>
Date: Fri Sep 24 23:39:56 2021 +1000

flattree: Use '\n', not ';' to separate asm pseudo-ops

and I confirm the error is still present.

Regards,

Signature · 2 lines
Vincent Pelletier
GPG fingerprint 983A E8B7 3B91 1598 7A92 3845 CAC9 3691 4257 B0C1
#4 lore raw
In reply to a message not in the archive
Quoted 14 lines · Vincent Pelletier
Quoted 1 line · Vincent Pelletier

(please keep me cc'ed in replies)

[...]

Quoted 7 lines

This code builds fine:

  $ dtc -I dts -O dtb -o test.dtbo test.dts
  $
But then when disassembling the output, I get:
  $ dtc -I dtb -O dts test.dtbo
  <stdout>: ERROR (property_name_chars): /__fixups__:/soc/gpio@7e200000: Bad character '/' in property name
  ERROR: Input tree has errors, aborting (use -f to force output)

I just noticed 1.6.1 was released (but not packaged yet by my distribution, it seems), so I reproduced from git master as of

Quoted 7 lines

commit e33ce1d6a8c7e54e3ad12cff33690b6da0aee1dc (HEAD -> master, origin/master, origin/main, origin/HEAD)
Author: David Gibson <[email protected]>
Date: Fri Sep 24 23:39:56 2021 +1000

flattree: Use '\n', not ';' to separate asm pseudo-ops

and I confirm the error is still present.

Thanks for checking, and yes, this definitely looks like a dtc bug.

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
#5 lore raw
In reply to a message not in the archive
Quoted 75 lines · Vincent Pelletier

(please keep me cc'ed in replies)

Hello,

I suspect this may be a dtc bug, but I am not too familiar with devicetree specs to tell.

Here is a simplified example reproducing this issue:

(SNIP)
/dts-v1/;
/plugin/;

/ {
compatible = "foo";
};

&{/soc/gpio@7e200000} {
    status = "okay";
};
&{/soc/spi@7e204000} {
    cs-gpios = <&{/soc/gpio@7e200000} 8 0x01>;
};

(SNIP)

This code builds fine:

  $ dtc -I dts -O dtb -o test.dtbo test.dts
  $
But then when disassembling the output, I get:
  $ dtc -I dtb -O dts test.dtbo
  <stdout>: ERROR (property_name_chars): /__fixups__:/soc/gpio@7e200000: Bad character '/' in property name
  ERROR: Input tree has errors, aborting (use -f to force output)
And forcing output:
  $ dtc -I dtb -O dts -f test.dtbo
  <stdout>: ERROR (property_name_chars): /__fixups__:/soc/gpio@7e200000: Bad character '/' in property name
  Warning: Input tree has errors, output forced
  /dts-v1/;
  / {
          compatible = "foo";
          fragment@0 {
                  target-path = "/soc/gpio@7e200000";

                  __overlay__ {
                          status = "okay";
                  };
          };

          fragment@1 {
                  target-path = "/soc/spi@7e204000";

                  __overlay__ {
                          cs-gpios = <0xffffffff 0x08 0x01>;
                  };
          };

          __fixups__ {
                  /soc/gpio@7e200000 = "/fragment@1/__overlay__:cs-gpios:0";
          };

};

Indeed, the node in __fixups__ has an invalid name.

I suspect this is uncommon because:
- it probably only occurs in overlays and not in self-contained trees, as a self-contained tree would likely produce an internal phandle and never store the full path anywhere.
- ...which does not attach to labels but full paths
Labels being (probably ?) valid node names, they would avoid the issue.
- ...in arrays
In a node overlay, the full path ends up as a quoted string, not as a name, so it is safe.

Quoted 1 line

Is this a dtc bug ?

I've looked at this again and... not really.

Unfortunately, such a reference can't work given the specification of the overlay format. The property name in fixups is the target of the reference, which works fine for labels, but will necessarily result in an invalid property name for path references.

dtc should, of course, have a less ugly failure mode.

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
#6 lore raw
Quoted 78 lines · David Gibson
Quoted 75 lines · Vincent Pelletier

(please keep me cc'ed in replies)

Hello,

I suspect this may be a dtc bug, but I am not too familiar with devicetree specs to tell.

Here is a simplified example reproducing this issue:

(SNIP)
/dts-v1/;
/plugin/;

/ {
compatible = "foo";
};

&{/soc/gpio@7e200000} {
    status = "okay";
};
&{/soc/spi@7e204000} {
    cs-gpios = <&{/soc/gpio@7e200000} 8 0x01>;
};

(SNIP)

This code builds fine:

  $ dtc -I dts -O dtb -o test.dtbo test.dts
  $
But then when disassembling the output, I get:
  $ dtc -I dtb -O dts test.dtbo
  <stdout>: ERROR (property_name_chars): /__fixups__:/soc/gpio@7e200000: Bad character '/' in property name
  ERROR: Input tree has errors, aborting (use -f to force output)
And forcing output:
  $ dtc -I dtb -O dts -f test.dtbo
  <stdout>: ERROR (property_name_chars): /__fixups__:/soc/gpio@7e200000: Bad character '/' in property name
  Warning: Input tree has errors, output forced
  /dts-v1/;
  / {
          compatible = "foo";
          fragment@0 {
                  target-path = "/soc/gpio@7e200000";

                  __overlay__ {
                          status = "okay";
                  };
          };

          fragment@1 {
                  target-path = "/soc/spi@7e204000";

                  __overlay__ {
                          cs-gpios = <0xffffffff 0x08 0x01>;
                  };
          };

          __fixups__ {
                  /soc/gpio@7e200000 = "/fragment@1/__overlay__:cs-gpios:0";
          };

};

Indeed, the node in __fixups__ has an invalid name.

I suspect this is uncommon because:
- it probably only occurs in overlays and not in self-contained trees, as a self-contained tree would likely produce an internal phandle and never store the full path anywhere.
- ...which does not attach to labels but full paths
Labels being (probably ?) valid node names, they would avoid the issue.
- ...in arrays
In a node overlay, the full path ends up as a quoted string, not as a name, so it is safe.

Quoted 1 line

Is this a dtc bug ?

Quoted 8 lines

I've looked at this again and... not really.

Unfortunately, such a reference can't work given the specification of the overlay format. The property name in fixups is the target of the reference, which works fine for labels, but will necessarily result in an invalid property name for path references.

dtc should, of course, have a less ugly failure mode.

I finally got a chance to tackle this, and just sent out a patch which should make this case fail on attempting to build the dtbo in the first place, rather than later when processing the bad output.

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