From nobody Mon Apr 20 01:11:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81D9BC43334 for ; Thu, 23 Jun 2022 10:52:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231499AbiFWKwQ (ORCPT ); Thu, 23 Jun 2022 06:52:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231419AbiFWKwC (ORCPT ); Thu, 23 Jun 2022 06:52:02 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::224]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44F5C4B416; Thu, 23 Jun 2022 03:51:58 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id C1364E0002; Thu, 23 Jun 2022 10:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1655981517; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eOnREmjkRmZWXjlITmYHHvZiPZ/RIqrCWToz3hX41C4=; b=ovrxSQHKKOiTeOdkLHzgi8zf619MWczw6rdGJGYRofvl3rA9eA5jtFNNW1lkPZR5qWdzbV 9NREpiK+7v/OIFuzXHGorxHvusafWTMB39pXIuoTs1k9YT8Vs8SMz0ubV1PsscQGsCOr1J /SLwMKiFklW2254dDLEinhFdTKjkKXEJo802nw4ZpHP1UgnQPO6GnMcU22VkGXQ+gpbLK1 cOsbhDw0qPF7jG9k+fsFkbRNodTh1ghbMSXpfoZSDXFd4QKChZ6SiTquvB5Iow+P4U7Nrg UHWBAlz0JMtZ+CHdLZlcc1MzHGW2Q6j1F3+9fzxrZS9Mj8owqD4+QlFeDPLmsA== From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Rob Herring , Frank Rowand Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Lizhi Hou , Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni , Rob Herring Subject: [PATCH v1 1/2] of: base: populate of_root node if not set Date: Thu, 23 Jun 2022 12:50:43 +0200 Message-Id: <20220623105044.152832-2-clement.leger@bootlin.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623105044.152832-1-clement.leger@bootlin.com> References: <20220623105044.152832-1-clement.leger@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 with of_fdt_unflatten(). Co-developed-by: Rob Herring Signed-off-by: Rob Herring Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- drivers/of/Makefile | 2 +- drivers/of/base.c | 18 ++++++++++++++++-- drivers/of/empty_root.dts | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 drivers/of/empty_root.dts diff --git a/drivers/of/Makefile b/drivers/of/Makefile index e0360a44306e..ce56c8b95c83 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y =3D base.o device.o platform.o property.o +obj-y =3D base.o empty_root.dtb.o device.o platform.o property.o obj-$(CONFIG_OF_KOBJ) +=3D kobj.o obj-$(CONFIG_OF_DYNAMIC) +=3D dynamic.o obj-$(CONFIG_OF_FLATTREE) +=3D fdt.o diff --git a/drivers/of/base.c b/drivers/of/base.c index d4f98c8469ed..43e0f027a49c 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -163,6 +164,8 @@ void __of_phandle_cache_inv_entry(phandle handle) phandle_cache[handle_hash] =3D NULL; } =20 +extern const char __dtb_empty_root_begin[]; + void __init of_core_init(void) { struct device_node *np; @@ -176,6 +179,18 @@ void __init of_core_init(void) pr_err("failed to register existing nodes\n"); return; } + + if (!of_root) { + void *dt; + const unsigned long *fdt =3D (const unsigned long *) + __dtb_empty_root_begin; + dt =3D of_fdt_unflatten_tree(fdt, NULL, &of_root); + if (!dt) { + pr_err("Failed to setup empty root dt\n"); + return; + } + } + for_each_of_allnodes(np) { __of_attach_node_sysfs(np); if (np->phandle && !phandle_cache[of_phandle_cache_hash(np->phandle)]) @@ -184,8 +199,7 @@ void __init of_core_init(void) mutex_unlock(&of_mutex); =20 /* Symlink in /proc as required by userspace ABI */ - if (of_root) - proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base"); + proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base"); } =20 static struct property *__of_find_property(const struct device_node *np, diff --git a/drivers/of/empty_root.dts b/drivers/of/empty_root.dts new file mode 100644 index 000000000000..cf9e97a60f48 --- /dev/null +++ b/drivers/of/empty_root.dts @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0-only +/dts-v1/; + +/ { + +}; --=20 2.36.1 From nobody Mon Apr 20 01:11:06 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82B33C433EF for ; Thu, 23 Jun 2022 10:52:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231430AbiFWKwM (ORCPT ); Thu, 23 Jun 2022 06:52:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231381AbiFWKwC (ORCPT ); Thu, 23 Jun 2022 06:52:02 -0400 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D8EE4B42F; Thu, 23 Jun 2022 03:51:59 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id E13C4E001A; Thu, 23 Jun 2022 10:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1655981518; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=24+arAKJhTGIKfgrnJIiZ/9RG62zhef/20t26Jbq8Qs=; b=TDYzkiRWBxX0NL8q0DTTu/8bOwxD73E83l+t8uMK1NtOHcvg5aNHsdlt+ChwGFVe5ekQ70 ewAkv+/eQPBqzptFi3nBa2+D1HR9EwElYSKzt9+PacPGvk50if3hGKeT49jE4EFBi/SGSV jqmkMocV4MAXRxVYGx4Br1tF9Vm7xiGQZHmuRHfsil107eESMUSoXJS//rC/XlyQUny/gQ 190kxwQSdbc20rjGOEMu5I9KGTCmLPkKW3joN8Y6BcpIm5rZd4yrbvGlxIiBmMqpWDtOXM R83MKOs8IkohWqBtNfnIdDE40DUPtbVf6DmtB3P1uuJ6CtPXg0tKWJqpkjBqGA== From: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= To: Rob Herring , Frank Rowand Cc: =?UTF-8?q?Cl=C3=A9ment=20L=C3=A9ger?= , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Lizhi Hou , Allan Nielsen , Horatiu Vultur , Steen Hegelund , Thomas Petazzoni Subject: [PATCH v1 2/2] of: unittest: remove check for of_root Date: Thu, 23 Jun 2022 12:50:44 +0200 Message-Id: <20220623105044.152832-3-clement.leger@bootlin.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220623105044.152832-1-clement.leger@bootlin.com> References: <20220623105044.152832-1-clement.leger@bootlin.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Now that of_root node is always populated in of_core_init(), remove this manual tree creation and assume that the root node always exists. Signed-off-by: Cl=C3=A9ment L=C3=A9ger --- drivers/of/unittest.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 7f6bba18c515..a787d212c0f6 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1469,16 +1469,6 @@ static int __init unittest_data_add(void) return -EINVAL; } =20 - if (!of_root) { - of_root =3D unittest_data_node; - for_each_of_allnodes(np) - __of_attach_node_sysfs(np); - of_aliases =3D of_find_node_by_path("/aliases"); - of_chosen =3D of_find_node_by_path("/chosen"); - of_overlay_mutex_unlock(); - return 0; - } - EXPECT_BEGIN(KERN_INFO, "Duplicate name in testcase-data, renamed to \"duplicate-name#1\""); =20 --=20 2.36.1