@@ -1,3 +1,4 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y += kernel/ mm/ net/
+obj-$(CONFIG_USE_BUILTIN_DTB) += boot/dts/
@@ -355,6 +355,25 @@ config CMDLINE_FORCE
endchoice
+config USE_BUILTIN_DTB
+ bool "Use builtin DTB"
+ depends on !MMU
+ help
+ Link a device tree blob for particular hardware into the kernel,
+ suppressing use of the DTB pointer provided by the bootloader.
+ This option should only be used with hardware or bootloaders that
+ are not capable of providing a DTB to the kernel, or for
+ experimental hardware without stable device tree bindings.
+
+config BUILTIN_DTB_SOURCE
+ string "Source file for builtin DTB"
+ default ""
+ depends on USE_BUILTIN_DTB
+ help
+ Base name (without suffix, relative to arch/riscv/boot/dts) for
+ the a DTS file that will be used to produce the DTB linked into
+ the kernel.
+
endmenu
menu "Power management options"
@@ -1,2 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
+ifneq ($(CONFIG_BUILTIN_DTB_SOURCE),"")
+obj-$(CONFIG_USE_BUILTIN_DTB) += $(patsubst "%",%,$(CONFIG_BUILTIN_DTB_SOURCE)).dtb.o
+else
subdir-y += sifive
+endif
@@ -68,7 +68,13 @@ void __init setup_arch(char **cmdline_p)
setup_bootmem();
paging_init();
+
+#if IS_ENABLED(CONFIG_USE_BUILTIN_DTB)
+ unflatten_and_copy_device_tree();
+#else
unflatten_device_tree();
+#endif
+
clint_init_boot_cpu();
#ifdef CONFIG_SWIOTLB
@@ -480,7 +480,11 @@ static void __init setup_vm_final(void)
#else
asmlinkage void __init setup_vm(uintptr_t dtb_pa)
{
+#if IS_ENABLED(CONFIG_USE_BUILTIN_DTB)
+ dtb_early_va = __dtb_start;
+#else
dtb_early_va = (void *)dtb_pa;
+#endif
}
static inline void setup_vm_final(void)