dgibson / dtc

Device Tree Compiler
235 stars 134 forks source link

Compilation of invalid overlays #68

Closed jimpo closed 4 weeks ago

jimpo commented 2 years ago

The dtc compiler allows compilation of DTS overlay files which fail when applied with FDT_ERR_NOTFOUND. I discovered this issue first with a Raspberry Pi overlay and reported the issue with instructions to reproduce in issue https://github.com/raspberrypi/firmware/issues/1718.

It only fails when the overlay is compiled with --symbols as the issue appears to be with overlay symbols which have stale phandle references after the original node phandle is overwritten by the overlay.

A minimal example to reproduce is:

File base.dts:

/dts-v1/;

/ {
    soc {
        minibt: bluetooth {
            compatible = "brcm,bcm43438-bt";
            max-speed = <0x70800>;
            status = "disabled";
        };
    };
};

File blah.dts:

/dts-v1/;
/plugin/;

/ {
    fragment@0 {
        target = <&minibt>;
        minibt_frag: __overlay__ {
        };
    };
};
% dtc --symbols -I dts -O dtb overlay.dts > blah.dtbo
% dtc --symbols -I dts -O dtb base.dts > base.dtb
% fdtoverlay -v -i base.dtb -o base-with-overlay.dtb blah.dtbo
input  = base.dtb
output = base-with-overlay.dtb
overlay[0] = blah.dtbo

Failed to apply 'blah.dtbo': FDT_ERR_NOTFOUND
dgibson commented 4 weeks ago

This was part of a wider set of problems where the overlay could overwrite a base node's phandle. This should be corrected by this commit.