Skip to content

Commit 37c8a5f

Browse files
committed
kbuild: consolidate Devicetree dtb build rules
There is nothing arch specific about building dtb files other than their location under /arch/*/boot/dts/. Keeping each arch aligned is a pain. The dependencies and supported targets are all slightly different. Also, a cross-compiler for each arch is needed, but really the host compiler preprocessor is perfectly fine for building dtbs. Move the build rules to a common location and remove the arch specific ones. This is done in a single step to avoid warnings about overriding rules. The build dependencies had been a mixture of 'scripts' and/or 'prepare'. These pull in several dependencies some of which need a target compiler (specifically devicetable-offsets.h) and aren't needed to build dtbs. All that is really needed is dtc, so adjust the dependencies to only be dtc. This change enables support 'dtbs_install' on some arches which were missing the target. Acked-by: Will Deacon <will.deacon@arm.com> Acked-by: Paul Burton <paul.burton@mips.com> Acked-by: Ley Foon Tan <ley.foon.tan@intel.com> Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com> Cc: Michal Marek <michal.lkml@markovi.net> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Russell King <linux@armlinux.org.uk> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Cc: Michal Simek <monstr@monstr.eu> Cc: Ralf Baechle <ralf@linux-mips.org> Cc: James Hogan <jhogan@kernel.org> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Chris Zankel <chris@zankel.net> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: linux-kbuild@vger.kernel.org Cc: linux-snps-arc@lists.infradead.org Cc: linux-arm-kernel@lists.infradead.org Cc: uclinux-h8-devel@lists.sourceforge.jp Cc: linux-mips@linux-mips.org Cc: nios2-dev@lists.rocketboards.org Cc: linuxppc-dev@lists.ozlabs.org Cc: linux-xtensa@linux-xtensa.org Signed-off-by: Rob Herring <robh@kernel.org>
1 parent be7cd2d commit 37c8a5f

File tree

17 files changed

+48
-101
lines changed

17 files changed

+48
-101
lines changed

Makefile

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ include/config/kernel.release: $(srctree)/Makefile FORCE
10711071
# Carefully list dependencies so we do not try to build scripts twice
10721072
# in parallel
10731073
PHONY += scripts
1074-
scripts: scripts_basic asm-generic gcc-plugins $(autoksyms_h)
1074+
scripts: scripts_basic scripts_dtc asm-generic gcc-plugins $(autoksyms_h)
10751075
$(Q)$(MAKE) $(build)=$(@)
10761076

10771077
# Things we need to do before we recursively start building the kernel
@@ -1215,6 +1215,35 @@ kselftest-merge:
12151215
$(srctree)/tools/testing/selftests/*/config
12161216
+$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
12171217

1218+
# ---------------------------------------------------------------------------
1219+
# Devicetree files
1220+
1221+
ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
1222+
dtstree := arch/$(SRCARCH)/boot/dts
1223+
endif
1224+
1225+
ifneq ($(dtstree),)
1226+
1227+
%.dtb: prepare3 scripts_dtc
1228+
$(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
1229+
1230+
PHONY += dtbs dtbs_install
1231+
dtbs: prepare3 scripts_dtc
1232+
$(Q)$(MAKE) $(build)=$(dtstree)
1233+
1234+
dtbs_install:
1235+
$(Q)$(MAKE) $(dtbinst)=$(dtstree)
1236+
1237+
ifdef CONFIG_OF_EARLY_FLATTREE
1238+
all: dtbs
1239+
endif
1240+
1241+
endif
1242+
1243+
PHONY += scripts_dtc
1244+
scripts_dtc: scripts_basic
1245+
$(Q)$(MAKE) $(build)=scripts/dtc
1246+
12181247
# ---------------------------------------------------------------------------
12191248
# Modules
12201249

@@ -1424,6 +1453,12 @@ help:
14241453
@echo ' kselftest-merge - Merge all the config dependencies of kselftest to existing'
14251454
@echo ' .config.'
14261455
@echo ''
1456+
@$(if $(dtstree), \
1457+
echo 'Devicetree:'; \
1458+
echo '* dtbs - Build device tree blobs for enabled boards'; \
1459+
echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1460+
echo '')
1461+
14271462
@echo 'Userspace tools targets:'
14281463
@echo ' use "make tools/help"'
14291464
@echo ' or "cd tools; make help"'

arch/arc/Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,5 @@ boot_targets += uImage uImage.bin uImage.gz
132132
$(boot_targets): vmlinux
133133
$(Q)$(MAKE) $(build)=$(boot) $(boot)/$@
134134

135-
%.dtb %.dtb.S %.dtb.o: scripts
136-
$(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
137-
138-
dtbs: scripts
139-
$(Q)$(MAKE) $(build)=$(boot)/dts
140-
141135
archclean:
142136
$(Q)$(MAKE) $(clean)=$(boot)

arch/arm/Makefile

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,7 @@ else
307307
KBUILD_IMAGE := $(boot)/zImage
308308
endif
309309

310-
# Build the DT binary blobs if we have OF configured
311-
ifeq ($(CONFIG_USE_OF),y)
312-
KBUILD_DTBS := dtbs
313-
endif
314-
315-
all: $(notdir $(KBUILD_IMAGE)) $(KBUILD_DTBS)
310+
all: $(notdir $(KBUILD_IMAGE))
316311

317312

318313
archheaders:
@@ -339,17 +334,6 @@ $(BOOT_TARGETS): vmlinux
339334
$(INSTALL_TARGETS):
340335
$(Q)$(MAKE) $(build)=$(boot) MACHINE=$(MACHINE) $@
341336

342-
%.dtb: | scripts
343-
$(Q)$(MAKE) $(build)=$(boot)/dts MACHINE=$(MACHINE) $(boot)/dts/$@
344-
345-
PHONY += dtbs dtbs_install
346-
347-
dtbs: prepare scripts
348-
$(Q)$(MAKE) $(build)=$(boot)/dts
349-
350-
dtbs_install:
351-
$(Q)$(MAKE) $(dtbinst)=$(boot)/dts
352-
353337
PHONY += vdso_install
354338
vdso_install:
355339
ifeq ($(CONFIG_VDSO),y)
@@ -371,8 +355,6 @@ define archhelp
371355
echo ' uImage - U-Boot wrapped zImage'
372356
echo ' bootpImage - Combined zImage and initial RAM disk'
373357
echo ' (supply initrd image via make variable INITRD=<path>)'
374-
echo '* dtbs - Build device tree blobs for enabled boards'
375-
echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'
376358
echo ' install - Install uncompressed kernel'
377359
echo ' zinstall - Install compressed kernel'
378360
echo ' uinstall - Install U-Boot wrapped compressed kernel'

arch/arm64/Makefile

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ core-$(CONFIG_EFI_STUB) += $(objtree)/drivers/firmware/efi/libstub/lib.a
113113
# Default target when executing plain make
114114
boot := arch/arm64/boot
115115
KBUILD_IMAGE := $(boot)/Image.gz
116-
KBUILD_DTBS := dtbs
117116

118-
all: Image.gz $(KBUILD_DTBS)
117+
all: Image.gz
119118

120119

121120
Image: vmlinux
@@ -127,25 +126,13 @@ Image.%: Image
127126
zinstall install:
128127
$(Q)$(MAKE) $(build)=$(boot) $@
129128

130-
%.dtb: scripts
131-
$(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
132-
133-
PHONY += dtbs dtbs_install
134-
135-
dtbs: prepare scripts
136-
$(Q)$(MAKE) $(build)=$(boot)/dts
137-
138-
dtbs_install:
139-
$(Q)$(MAKE) $(dtbinst)=$(boot)/dts
140-
141129
PHONY += vdso_install
142130
vdso_install:
143131
$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso $@
144132

145133
# We use MRPROPER_FILES and CLEAN_FILES now
146134
archclean:
147135
$(Q)$(MAKE) $(clean)=$(boot)
148-
$(Q)$(MAKE) $(clean)=$(boot)/dts
149136

150137
# We need to generate vdso-offsets.h before compiling certain files in kernel/.
151138
# In order to do that, we should use the archprepare target, but we can't since
@@ -160,8 +147,6 @@ vdso_prepare: prepare0
160147
define archhelp
161148
echo '* Image.gz - Compressed kernel image (arch/$(ARCH)/boot/Image.gz)'
162149
echo ' Image - Uncompressed kernel image (arch/$(ARCH)/boot/Image)'
163-
echo '* dtbs - Build device tree blobs for enabled boards'
164-
echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'
165150
echo ' install - Install uncompressed kernel'
166151
echo ' zinstall - Install compressed kernel'
167152
echo ' Install using (your) ~/bin/installkernel or'

arch/c6x/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ boot := arch/$(ARCH)/boot
4040
DTB:=$(subst dtbImage.,,$(filter dtbImage.%, $(MAKECMDGOALS)))
4141
export DTB
4242

43-
ifneq ($(DTB),)
4443
core-y += $(boot)/dts/
45-
endif
4644

4745
# With make 3.82 we cannot mix normal and wildcard targets
4846

arch/h8300/Makefile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,12 @@ CROSS_COMPILE := h8300-unknown-linux-
3131
endif
3232

3333
core-y += arch/$(ARCH)/kernel/ arch/$(ARCH)/mm/
34-
ifneq '$(CONFIG_H8300_BUILTIN_DTB)' '""'
35-
core-y += arch/h8300/boot/dts/
36-
endif
34+
core-y += arch/$(ARCH)/boot/dts/
3735

3836
libs-y += arch/$(ARCH)/lib/
3937

4038
boot := arch/h8300/boot
4139

42-
%.dtb %.dtb.S %.dtb.o: | scripts
43-
$(Q)$(MAKE) $(build)=arch/h8300/boot/dts arch/h8300/boot/dts/$@
44-
45-
PHONY += dtbs
46-
dtbs: scripts
47-
$(Q)$(MAKE) $(build)=arch/h8300/boot/dts
48-
4940
archmrproper:
5041

5142
archclean:

arch/microblaze/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ boot := arch/microblaze/boot
6565
# Are we making a simpleImage.<boardname> target? If so, crack out the boardname
6666
DTB:=$(subst simpleImage.,,$(filter simpleImage.%, $(MAKECMDGOALS)))
6767

68-
ifneq ($(DTB),)
69-
core-y += $(boot)/dts/
70-
endif
68+
core-y += $(boot)/dts/
7169

7270
# defines filename extension depending memory management type
7371
ifeq ($(CONFIG_MMU),)

arch/microblaze/boot/dts/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
#
33

4+
ifneq ($(DTB),)
45
obj-y += linked_dtb.o
56

67
# Ensure system.dtb exists
@@ -11,6 +12,7 @@ ifneq ($(DTB),system)
1112
$(obj)/system.dtb: $(obj)/$(DTB).dtb
1213
$(call if_changed,cp)
1314
endif
15+
endif
1416

1517
quiet_cmd_cp = CP $< $@$2
1618
cmd_cp = cat $< >$@$2 || (rm -f $@ && echo false)

arch/mips/Makefile

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,7 @@ endif
407407
CLEAN_FILES += vmlinux.32 vmlinux.64
408408

409409
# device-trees
410-
core-$(CONFIG_BUILTIN_DTB) += arch/mips/boot/dts/
411-
412-
%.dtb %.dtb.S %.dtb.o: | scripts
413-
$(Q)$(MAKE) $(build)=arch/mips/boot/dts arch/mips/boot/dts/$@
414-
415-
PHONY += dtbs
416-
dtbs: scripts
417-
$(Q)$(MAKE) $(build)=arch/mips/boot/dts
418-
419-
PHONY += dtbs_install
420-
dtbs_install:
421-
$(Q)$(MAKE) $(dtbinst)=arch/mips/boot/dts
410+
core-y += arch/mips/boot/dts/
422411

423412
archprepare:
424413
ifdef CONFIG_MIPS32_N32
@@ -461,8 +450,6 @@ define archhelp
461450
echo ' uImage.lzma - U-Boot image (lzma)'
462451
echo ' uImage.lzo - U-Boot image (lzo)'
463452
echo ' uzImage.bin - U-Boot image (self-extracting)'
464-
echo ' dtbs - Device-tree blobs for enabled boards'
465-
echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'
466453
echo
467454
echo ' These will be default as appropriate for a configured platform.'
468455
echo

arch/nds32/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ CHECKFLAGS += -D__NDS32_EB__
4343
endif
4444

4545
boot := arch/nds32/boot
46-
core-$(BUILTIN_DTB) += $(boot)/dts/
46+
core-y += $(boot)/dts/
4747

4848
.PHONY: FORCE
4949

arch/nios2/Makefile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ all: vmImage
5656
archclean:
5757
$(Q)$(MAKE) $(clean)=$(nios2-boot)
5858

59-
%.dtb %.dtb.S %.dtb.o: | scripts
60-
$(Q)$(MAKE) $(build)=$(nios2-boot)/dts $(nios2-boot)/dts/$@
61-
62-
dtbs:
63-
$(Q)$(MAKE) $(build)=$(nios2-boot)/dts
64-
6559
$(BOOT_TARGETS): vmlinux
6660
$(Q)$(MAKE) $(build)=$(nios2-boot) $(nios2-boot)/$@
6761

@@ -74,5 +68,4 @@ define archhelp
7468
echo ' (your) ~/bin/$(INSTALLKERNEL) or'
7569
echo ' (distribution) /sbin/$(INSTALLKERNEL) or'
7670
echo ' install to $$(INSTALL_PATH)'
77-
echo ' dtbs - Build device tree blobs for enabled boards'
7871
endef

arch/nios2/boot/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,5 @@ $(obj)/zImage: $(obj)/compressed/vmlinux FORCE
3131
$(obj)/compressed/vmlinux: $(obj)/vmlinux.gz FORCE
3232
$(Q)$(MAKE) $(build)=$(obj)/compressed $@
3333

34-
targets += $(dtb-y)
35-
36-
$(obj)/dtbs: $(addprefix $(obj)/, $(dtb-y))
37-
3834
install:
3935
sh $(srctree)/$(src)/install.sh $(KERNELRELEASE) $(BOOTIMAGE) System.map "$(INSTALL_PATH)"

arch/powerpc/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,6 @@ $(BOOT_TARGETS2): vmlinux
293293
bootwrapper_install:
294294
$(Q)$(MAKE) $(build)=$(boot) $(patsubst %,$(boot)/%,$@)
295295

296-
%.dtb: scripts
297-
$(Q)$(MAKE) $(build)=$(boot)/dts $(patsubst %,$(boot)/dts/%,$@)
298-
299296
# Used to create 'merged defconfigs'
300297
# To use it $(call) it with the first argument as the base defconfig
301298
# and the second argument as a space separated list of .config files to merge,

arch/xtensa/Makefile

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,28 +84,18 @@ LIBGCC := $(shell $(CC) $(KBUILD_CFLAGS) -print-libgcc-file-name)
8484
head-y := arch/xtensa/kernel/head.o
8585
core-y += arch/xtensa/kernel/ arch/xtensa/mm/
8686
core-y += $(buildvar) $(buildplf)
87+
core-y += arch/xtensa/boot/dts/
8788

8889
libs-y += arch/xtensa/lib/ $(LIBGCC)
8990
drivers-$(CONFIG_OPROFILE) += arch/xtensa/oprofile/
9091

91-
ifneq ($(CONFIG_BUILTIN_DTB),"")
92-
core-$(CONFIG_OF) += arch/xtensa/boot/dts/
93-
endif
94-
9592
boot := arch/xtensa/boot
9693

9794
all Image zImage uImage: vmlinux
9895
$(Q)$(MAKE) $(build)=$(boot) $@
9996

100-
%.dtb:
101-
$(Q)$(MAKE) $(build)=$(boot)/dts $(boot)/dts/$@
102-
103-
dtbs: scripts
104-
$(Q)$(MAKE) $(build)=$(boot)/dts
105-
10697
define archhelp
10798
@echo '* Image - Kernel ELF image with reset vector'
10899
@echo '* zImage - Compressed kernel image (arch/xtensa/boot/images/zImage.*)'
109100
@echo '* uImage - U-Boot wrapped image'
110-
@echo ' dtbs - Build device tree blobs for enabled boards'
111101
endef

scripts/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ build_unifdef: $(obj)/unifdef
3939
subdir-$(CONFIG_MODVERSIONS) += genksyms
4040
subdir-y += mod
4141
subdir-$(CONFIG_SECURITY_SELINUX) += selinux
42-
subdir-$(CONFIG_DTC) += dtc
4342
subdir-$(CONFIG_GDB_SCRIPTS) += gdb
4443

4544
# Let clean descend into subdirs
46-
subdir- += basic kconfig package gcc-plugins
45+
subdir- += basic dtc kconfig package gcc-plugins

scripts/Makefile.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
283283

284284
quiet_cmd_dtc = DTC $@
285285
cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
286-
$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
286+
$(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
287287
$(DTC) -O dtb -o $@ -b 0 \
288288
$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
289289
-d $(depfile).dtc.tmp $(dtc-tmp) ; \

scripts/dtc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0
22
# scripts/dtc makefile
33

4-
hostprogs-y := dtc
4+
hostprogs-$(CONFIG_DTC) := dtc
55
always := $(hostprogs-y)
66

77
dtc-objs := dtc.o flattree.o fstree.o data.o livetree.o treesource.o \

0 commit comments

Comments
 (0)