From ee59936e8333792316238caec43c7fa5d8ceb61a Mon Sep 17 00:00:00 2001 From: Karthikeyan Ramasubramanian Date: Wed, 12 Nov 2025 22:07:31 -0700 Subject: [PATCH] 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 Reviewed-on: https://review.coreboot.org/c/coreboot/+/90028 Reviewed-by: Yu-Ping Wu Tested-by: build bot (Jenkins) --- src/commonlib/device_tree.c | 16 ++++++++++++++++ src/commonlib/include/commonlib/device_tree.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/src/commonlib/device_tree.c b/src/commonlib/device_tree.c index d244ad9954..595c3cbb5d 100644 --- a/src/commonlib/device_tree.c +++ b/src/commonlib/device_tree.c @@ -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; +} diff --git a/src/commonlib/include/commonlib/device_tree.h b/src/commonlib/include/commonlib/device_tree.h index be945d93da..b6004fe8c4 100644 --- a/src/commonlib/include/commonlib/device_tree.h +++ b/src/commonlib/include/commonlib/device_tree.h @@ -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__ */