From patchwork Mon Aug 21 12:49:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Binbin Zhou X-Patchwork-Id: 715543 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 CACF4EE4996 for ; Mon, 21 Aug 2023 12:49:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235046AbjHUMtl (ORCPT ); Mon, 21 Aug 2023 08:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232461AbjHUMtk (ORCPT ); Mon, 21 Aug 2023 08:49:40 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 50141E6 for ; Mon, 21 Aug 2023 05:49:38 -0700 (PDT) Received: from loongson.cn (unknown [112.20.109.102]) by gateway (Coremail) with SMTP id _____8BxyepfXeNkUJcaAA--.44956S3; Mon, 21 Aug 2023 20:49:35 +0800 (CST) Received: from localhost.localdomain (unknown [112.20.109.102]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Bx3yNWXeNkqYJfAA--.61781S5; Mon, 21 Aug 2023 20:49:34 +0800 (CST) From: Binbin Zhou To: Binbin Zhou , Huacai Chen , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org Cc: Huacai Chen , loongson-kernel@lists.loongnix.cn, Xuerui Wang , loongarch@lists.linux.dev, Jiaxun Yang , Hongliang Wang , Binbin Zhou Subject: [PATCH v3 3/7] LoongArch: Allow device trees to be built into the kernel Date: Mon, 21 Aug 2023 20:49:19 +0800 Message-Id: X-Mailer: git-send-email 2.39.3 In-Reply-To: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20xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw2 0EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x02 67AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8_gA5UUUUU== Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Some systems do not provide a useful device tree to the kernel at boot time. Let's keep a device tree table in the kernel, keyed by the dts filename, containing the relevant DTBs. Signed-off-by: Binbin Zhou Signed-off-by: Huacai Chen --- arch/loongarch/Kconfig | 16 ++++++++++++++++ arch/loongarch/Makefile | 10 ++++++++-- arch/loongarch/boot/dts/Makefile | 3 +-- arch/loongarch/kernel/setup.c | 9 +++++++-- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 46b4c217da14..61febadd4fce 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -326,6 +326,22 @@ config 64KB_3LEVEL endchoice +config BUILTIN_DTB + bool "Enable builtin dtb in kernel" + depends on OF + help + Some systems do not provide a useful device tree to the kernel at boot + time. Let's keep a device tree table in the kernel, keyed by the dts + filename, containing the relevant DTBs. + +config BUILTIN_DTB_NAME + string "Source file for LoongArch builtin dtb" + depends on BUILTIN_DTB + help + Base name (without suffix, relative to arch/loongarch/boot/dts/) + for the DTS file that will be used to produce the DTB linked into the + kernel. + config CMDLINE string "Built-in kernel command line" help diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index fb0fada43197..abaa3df9fd6f 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -5,7 +5,8 @@ boot := arch/loongarch/boot -KBUILD_DEFCONFIG := loongson3_defconfig +KBUILD_DEFCONFIG := loongson3_defconfig +KBUILD_DTBS := dtbs image-name-y := vmlinux image-name-$(CONFIG_EFI_ZBOOT) := vmlinuz @@ -140,11 +141,14 @@ PHONY += vdso_install vdso_install: $(Q)$(MAKE) $(build)=arch/loongarch/vdso $@ -all: $(notdir $(KBUILD_IMAGE)) +all: $(notdir $(KBUILD_IMAGE)) $(KBUILD_DTBS) vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ +# device-trees +core-y += arch/loongarch/boot/dts/ + install: $(Q)install -D -m 755 $(KBUILD_IMAGE) $(INSTALL_PATH)/$(image-name-y)-$(KERNELRELEASE) $(Q)install -D -m 644 .config $(INSTALL_PATH)/config-$(KERNELRELEASE) @@ -152,5 +156,7 @@ install: define archhelp echo ' install - install kernel into $(INSTALL_PATH)' + echo ' dtbs - Device-tree blobs for enabled boards' + echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)' echo endef diff --git a/arch/loongarch/boot/dts/Makefile b/arch/loongarch/boot/dts/Makefile index 5f1f55e911ad..1e24cdb5180a 100644 --- a/arch/loongarch/boot/dts/Makefile +++ b/arch/loongarch/boot/dts/Makefile @@ -1,4 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -dtstree := $(srctree)/$(src) -dtb-y := $(patsubst $(dtstree)/%.dts,%.dtb, $(wildcard $(dtstree)/*.dts)) +obj-$(CONFIG_BUILTIN_DTB) += $(addsuffix .dtb.o, $(CONFIG_BUILTIN_DTB_NAME)) diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c index 7783f0a3d742..e5008890beda 100644 --- a/arch/loongarch/kernel/setup.c +++ b/arch/loongarch/kernel/setup.c @@ -296,8 +296,13 @@ static void __init fdt_setup(void) if (acpi_os_get_root_pointer()) return; - /* Look for a device tree configuration table entry */ - fdt_pointer = efi_fdt_pointer(); + /* We prefer to try to use built-in dtb, checking its legality first. */ + if (!fdt_check_header(__dtb_start)) + fdt_pointer = __dtb_start; + else + /* Fallback to efi dtb, when built-in dtb is not available. */ + fdt_pointer = efi_fdt_pointer(); + if (!fdt_pointer || fdt_check_header(fdt_pointer)) return;