Skip to content

Commit 654102d

Browse files
committed
kbuild: add generic support for built-in boot DTBs
Some architectures embed boot DTBs in vmlinux. A potential issue for these architectures is a race condition during parallel builds because Kbuild descends into arch/*/boot/dts/ twice. One build thread is initiated by the 'dtbs' target, which is a prerequisite of the 'all' target in the top-level Makefile: ifdef CONFIG_OF_EARLY_FLATTREE all: dtbs endif For architectures that support the built-in boot dtb, arch/*/boot/dts/ is visited also during the ordinary directory traversal in order to build obj-y objects that wrap DTBs. Since these build threads are unaware of each other, they can run simultaneously during parallel builds. This commit introduces a generic build rule to scripts/Makefile.vmlinux to support embedded boot DTBs in a race-free way. Architectures that want to use this rule need to select CONFIG_GENERIC_BUILTIN_DTB. After the migration, Makefiles under arch/*/boot/dts/ will be visited only once to build only *.dtb files. This change also aims to unify the CONFIG options used for built-in DTBs support. Currently, different architectures use different CONFIG options for the same purposes. With this commit, the CONFIG options will be unified as follows: - CONFIG_GENERIC_BUILTIN_DTB This enables the generic rule for built-in boot DTBs. This will be renamed to CONFIG_BUILTIN_DTB after all architectures migrate to the generic rule. - CONFIG_BUILTIN_DTB_NAME This specifies the path to the embedded DTB. (relative to arch/*/boot/dts/) - CONFIG_BUILTIN_DTB_ALL If this is enabled, all DTB files compiled under arch/*/boot/dts/ are embedded into vmlinux. Only used by MIPS. Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 985d6cc commit 654102d

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,10 @@ ifdef CONFIG_OF_EARLY_FLATTREE
14331433
all: dtbs
14341434
endif
14351435

1436+
ifdef CONFIG_GENERIC_BUILTIN_DTB
1437+
vmlinux: dtbs
1438+
endif
1439+
14361440
endif
14371441

14381442
PHONY += scripts_dtc
@@ -1500,7 +1504,8 @@ CLEAN_FILES += vmlinux.symvers modules-only.symvers \
15001504
modules.builtin modules.builtin.modinfo modules.nsdeps \
15011505
modules.builtin.ranges vmlinux.o.map \
15021506
compile_commands.json rust/test \
1503-
rust-project.json .vmlinux.objs .vmlinux.export.c
1507+
rust-project.json .vmlinux.objs .vmlinux.export.c \
1508+
.builtin-dtbs-list .builtin-dtb.S
15041509

15051510
# Directories & files removed with 'make mrproper'
15061511
MRPROPER_FILES += include/config include/generated \

drivers/of/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
config DTC
33
bool
44

5+
config GENERIC_BUILTIN_DTB
6+
bool
7+
8+
config BUILTIN_DTB_ALL
9+
bool
10+
511
menuconfig OF
612
bool "Device Tree and Open Firmware support"
713
help

scripts/Makefile.vmlinux

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,50 @@ quiet_cmd_cc_o_c = CC $@
1717
%.o: %.c FORCE
1818
$(call if_changed_dep,cc_o_c)
1919

20+
quiet_cmd_as_o_S = AS $@
21+
cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $<
22+
23+
%.o: %.S FORCE
24+
$(call if_changed_dep,as_o_S)
25+
26+
# Built-in dtb
27+
# ---------------------------------------------------------------------------
28+
29+
quiet_cmd_wrap_dtbs = WRAP $@
30+
cmd_wrap_dtbs = { \
31+
echo '\#include <asm-generic/vmlinux.lds.h>'; \
32+
echo '.section .dtb.init.rodata,"a"'; \
33+
while read dtb; do \
34+
symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \
35+
echo '.balign STRUCT_ALIGNMENT'; \
36+
echo ".global $${symbase}_begin"; \
37+
echo "$${symbase}_begin:"; \
38+
echo '.incbin "'$$dtb'" '; \
39+
echo ".global $${symbase}_end"; \
40+
echo "$${symbase}_end:"; \
41+
done < $<; \
42+
} > $@
43+
44+
.builtin-dtbs.S: .builtin-dtbs-list FORCE
45+
$(call if_changed,wrap_dtbs)
46+
47+
quiet_cmd_gen_dtbs_list = GEN $@
48+
cmd_gen_dtbs_list = \
49+
$(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@
50+
51+
.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE
52+
$(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list))
53+
54+
targets += .builtin-dtbs-list
55+
56+
ifdef CONFIG_GENERIC_BUILTIN_DTB
57+
targets += .builtin-dtbs.S .builtin-dtbs.o
58+
vmlinux: .builtin-dtbs.o
59+
endif
60+
61+
# vmlinux
62+
# ---------------------------------------------------------------------------
63+
2064
ifdef CONFIG_MODULES
2165
targets += .vmlinux.export.o
2266
vmlinux: .vmlinux.export.o

scripts/link-vmlinux.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ vmlinux_link()
6868
libs="${KBUILD_VMLINUX_LIBS}"
6969
fi
7070

71+
if is_enabled CONFIG_GENERIC_BUILTIN_DTB; then
72+
objs="${objs} .builtin-dtbs.o"
73+
fi
74+
7175
if is_enabled CONFIG_MODULES; then
7276
objs="${objs} .vmlinux.export.o"
7377
fi

0 commit comments

Comments
 (0)