commonlib/device_tree: Add an API to check if a DT is an overlay

Add dt_is_overlay() API to check whether the input devicetree is
actually an overlay DT. Payload will use this API when parsing an input
image which is a collection of base and overlay devicetree blobs.

BUG=b:394980221
TEST=Build firmware image for Rauru/Hylia and boot to OS. Ensure that
the API correctly identifies the base and overlay DTs.

Change-Id: I2fc54e3d9e63ebc993c8ce6a7d4a7224a9251497
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/90028
Reviewed-by: Yu-Ping Wu <yupingso@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Karthikeyan Ramasubramanian 2025-11-12 22:07:31 -07:00 committed by Matt DeVillier
commit ee59936e83
2 changed files with 19 additions and 0 deletions

View file

@ -2149,3 +2149,19 @@ int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay)
return 0;
}
bool dt_is_overlay(struct device_tree *tree)
{
/* The actual overlaid nodes/props are in an __overlay__ child node. */
const char * const overlay_path[] = { "__overlay__", NULL };
struct device_tree_node *fragment;
if (!tree)
return false;
list_for_each(fragment, tree->root->children, list_node)
if (dt_find_node(fragment, overlay_path, NULL, NULL, 0))
return true;
return false;
}

View file

@ -234,4 +234,7 @@ int dt_apply_fixups(struct device_tree *tree);
*/
struct device_tree_node *dt_init_reserved_memory_node(struct device_tree *tree);
/* Check whether a devicetree is an overlay device tree */
bool dt_is_overlay(struct device_tree *tree);
#endif /* __COMMONLIB_DEVICE_TREE_H__ */