Skip to content

Commit 5f346a6

Browse files
AaronDotchenhuacai
authored andcommitted
LoongArch: Allow device trees be built into the kernel
During the upstream progress of those DT-based drivers, DT properties are changed a lot so very different from those in existing bootloaders. It is inevitably that some existing systems do not provide a standard, canonical device tree to the kernel at boot time. So let's provide a device tree table in the kernel, keyed by the dts filename, containing the relevant DTBs. We can use the built-in dts files as references. Each SoC has only one built-in dts file which describes all possible device information of that SoC, so the dts files are good examples during development. And as a reference, our built-in dts file only enables the most basic bootable combinations (so it is generic enough), acts as an alternative in case the dts in the bootloader is unexpected. Signed-off-by: Binbin Zhou <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent db8ce24 commit 5f346a6

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

arch/loongarch/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ obj-y += net/
44
obj-y += vdso/
55

66
obj-$(CONFIG_KVM) += kvm/
7+
obj-$(CONFIG_BUILTIN_DTB) += boot/dts/
78

89
# for cleaning
910
subdir- += boot

arch/loongarch/Kconfig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,24 @@ config CMDLINE_FORCE
375375

376376
endchoice
377377

378+
config BUILTIN_DTB
379+
bool "Enable built-in dtb in kernel"
380+
depends on OF
381+
help
382+
Some existing systems do not provide a canonical device tree to
383+
the kernel at boot time. Let's provide a device tree table in the
384+
kernel, keyed by the dts filename, containing the relevant DTBs.
385+
386+
Built-in DTBs are generic enough and can be used as references.
387+
388+
config BUILTIN_DTB_NAME
389+
string "Source file for built-in dtb"
390+
depends on BUILTIN_DTB
391+
help
392+
Base name (without suffix, relative to arch/loongarch/boot/dts/)
393+
for the DTS file that will be used to produce the DTB linked into
394+
the kernel.
395+
378396
config DMI
379397
bool "Enable DMI scanning"
380398
select DMI_SCAN_MACHINE_NON_EFI_FALLBACK

arch/loongarch/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
boot := arch/loongarch/boot
77

88
KBUILD_DEFCONFIG := loongson3_defconfig
9+
KBUILD_DTBS := dtbs
910

1011
image-name-y := vmlinux
1112
image-name-$(CONFIG_EFI_ZBOOT) := vmlinuz
@@ -144,7 +145,7 @@ endif
144145

145146
vdso-install-y += arch/loongarch/vdso/vdso.so.dbg
146147

147-
all: $(notdir $(KBUILD_IMAGE))
148+
all: $(notdir $(KBUILD_IMAGE)) $(KBUILD_DTBS)
148149

149150
vmlinuz.efi: vmlinux.efi
150151

arch/loongarch/boot/dts/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0-only
2-
dtstree := $(srctree)/$(src)
32

4-
dtb-y := $(patsubst $(dtstree)/%.dts,%.dtb, $(wildcard $(dtstree)/*.dts))
3+
obj-$(CONFIG_BUILTIN_DTB) += $(addsuffix .dtb.o, $(CONFIG_BUILTIN_DTB_NAME))

arch/loongarch/kernel/setup.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,12 @@ static void __init fdt_setup(void)
295295
if (acpi_os_get_root_pointer())
296296
return;
297297

298-
/* Look for a device tree configuration table entry */
299-
fdt_pointer = efi_fdt_pointer();
298+
/* Prefer to use built-in dtb, checking its legality first. */
299+
if (!fdt_check_header(__dtb_start))
300+
fdt_pointer = __dtb_start;
301+
else
302+
fdt_pointer = efi_fdt_pointer(); /* Fallback to firmware dtb */
303+
300304
if (!fdt_pointer || fdt_check_header(fdt_pointer))
301305
return;
302306

@@ -330,7 +334,9 @@ static void __init bootcmdline_init(char **cmdline_p)
330334
if (boot_command_line[0])
331335
strlcat(boot_command_line, " ", COMMAND_LINE_SIZE);
332336

333-
strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
337+
if (!strstr(boot_command_line, init_command_line))
338+
strlcat(boot_command_line, init_command_line, COMMAND_LINE_SIZE);
339+
334340
goto out;
335341
}
336342
#endif

0 commit comments

Comments
 (0)