Re: [PATCH 2/7] of: Create of_root if no dtb provided by firmware

From: Rob Herring
Date: Wed Feb 21 2024 - 09:08:04 EST


On Fri, Feb 16, 2024 at 11:08 PM Saurabh Singh Sengar
<ssengar@xxxxxxxxxxxxxxxxxxx> wrote:
>
> On Fri, Feb 16, 2024 at 05:05:51PM -0800, Frank Rowand wrote:
> > When enabling CONFIG_OF on a platform where 'of_root' is not populated
> > by firmware, we end up without a root node. In order to apply overlays
> > and create subnodes of the root node, we need one. Create this root node
> > by unflattening an empty builtin dtb.
> >
> > If firmware provides a flattened device tree (FDT) then the FDT is
> > unflattened via setup_arch(). Otherwise, the call to
> > unflatten(_and_copy)?_device_tree() will create an empty root node.
> >
> > We make of_have_populated_dt() return true only if the DTB was loaded by
> > firmware so that existing callers don't change behavior after this
> > patch. The call in the of platform code is removed because it prevents
> > overlays from creating platform devices when the empty root node is
> > used.
> >
> > [sboyd@xxxxxxxxxx: Update of_have_populated_dt() to treat this empty dtb
> > as not populated. Drop setup_of() initcall]
> >
> > Signed-off-by: Frank Rowand <frowand.list@xxxxxxxxx>
> > Link: https://lore.kernel.org/r/20230317053415.2254616-2-frowand.list@xxxxxxxxx
> > Cc: Rob Herring <robh+dt@xxxxxxxxxx>
> > Signed-off-by: Stephen Boyd <sboyd@xxxxxxxxxx>
> > ---


> > @@ -1645,6 +1635,21 @@ static inline bool of_device_is_system_power_controller(const struct device_node
> > return of_property_read_bool(np, "system-power-controller");
> > }
> >
> > +/**
> > + * of_have_populated_dt() - Has DT been populated by bootloader
> > + *
> > + * Return: True if a DTB has been populated by the bootloader and it isn't the
> > + * empty builtin one. False otherwise.
> > + */
> > +static inline bool of_have_populated_dt(void)
> > +{
> > +#ifdef CONFIG_OF
> > + return of_property_present(of_root, "compatible");
>
> This adds the strict check for compatible which makes compatible
> to be mandatory for root nodes. So far, DeviceTree without compatible
> property in root nodes can work. Do we want to make this documented
> somewhere ?

It already is in the DT spec and schemas.

Rob