Skip to content

Commit e7e2941

Browse files
committed
kbuild: split device tree build rules into scripts/Makefile.dtbs
scripts/Makefile.lib is included not only from scripts/Makefile.build but also from scripts/Makefile.{modfinal,package,vmlinux,vmlinux_o}, where DT build rules are not required. Split the DT build rules out to scripts/Makefile.dtbs, and include it only when necessary. While I was here, I added $(DT_TMP_SCHEMA) as a prerequisite of $(multi-dtb-y). Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
1 parent fc41a0a commit e7e2941

5 files changed

Lines changed: 153 additions & 135 deletions

File tree

drivers/of/fdt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
/*
3636
* __dtb_empty_root_begin[] and __dtb_empty_root_end[] magically created by
37-
* cmd_dt_S_dtb in scripts/Makefile.lib
37+
* cmd_wrap_S_dtb in scripts/Makefile.dtbs
3838
*/
3939
extern uint8_t __dtb_empty_root_begin[];
4040
extern uint8_t __dtb_empty_root_end[];

drivers/of/unittest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ static int __init unittest_data_add(void)
18611861
struct device_node *unittest_data_node = NULL, *np;
18621862
/*
18631863
* __dtbo_testcases_begin[] and __dtbo_testcases_end[] are magically
1864-
* created by cmd_dt_S_dtbo in scripts/Makefile.lib
1864+
* created by cmd_wrap_S_dtbo in scripts/Makefile.dtbs
18651865
*/
18661866
extern uint8_t __dtbo_testcases_begin[];
18671867
extern uint8_t __dtbo_testcases_end[];
@@ -3525,7 +3525,7 @@ static void __init of_unittest_lifecycle(void)
35253525

35263526
/*
35273527
* __dtbo_##overlay_name##_begin[] and __dtbo_##overlay_name##_end[] are
3528-
* created by cmd_dt_S_dtbo in scripts/Makefile.lib
3528+
* created by cmd_wrap_S_dtbo in scripts/Makefile.dtbs
35293529
*/
35303530

35313531
#define OVERLAY_INFO_EXTERN(overlay_name) \

scripts/Makefile.build

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ endif
5757
# subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
5858
subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
5959
subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
60-
subdir-dtbslist := $(sort $(filter %/dtbs-list, $(dtb-y)))
6160

6261
targets-for-builtin := $(extra-y)
6362

@@ -349,7 +348,7 @@ $(obj)/%.o: $(obj)/%.S FORCE
349348

350349
targets += $(filter-out $(subdir-builtin), $(real-obj-y))
351350
targets += $(filter-out $(subdir-modorder), $(real-obj-m))
352-
targets += $(real-dtb-y) $(lib-y) $(always-y)
351+
targets += $(lib-y) $(always-y)
353352

354353
# Linker scripts preprocessor (.lds.S -> .lds)
355354
# ---------------------------------------------------------------------------
@@ -375,7 +374,6 @@ $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
375374
# To build objects in subdirs, we need to descend into the directories
376375
$(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ;
377376
$(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
378-
$(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ;
379377

380378
#
381379
# Rule to compile a set of .o files into one .a file (without symbol table)
@@ -391,12 +389,8 @@ quiet_cmd_ar_builtin = AR $@
391389
$(obj)/built-in.a: $(real-obj-y) FORCE
392390
$(call if_changed,ar_builtin)
393391

394-
#
395-
# Rule to create modules.order and dtbs-list
396-
#
397-
# This is a list of build artifacts (module or dtb) from the current Makefile
398-
# and its sub-directories. The timestamp should be updated when any of the
399-
# member files.
392+
# This is a list of build artifacts from the current Makefile and its
393+
# sub-directories. The timestamp should be updated when any of the member files.
400394

401395
cmd_gen_order = { $(foreach m, $(real-prereqs), \
402396
$(if $(filter %/$(notdir $@), $m), cat $m, echo $m);) :; } \
@@ -405,9 +399,6 @@ cmd_gen_order = { $(foreach m, $(real-prereqs), \
405399
$(obj)/modules.order: $(obj-m) FORCE
406400
$(call if_changed,gen_order)
407401

408-
$(obj)/dtbs-list: $(dtb-y) FORCE
409-
$(call if_changed,gen_order)
410-
411402
#
412403
# Rule to compile a set of .o files into one .a file (with symbol table)
413404
#
@@ -436,11 +427,7 @@ intermediate_targets = $(foreach sfx, $(2), \
436427
$(patsubst %$(strip $(1)),%$(sfx), \
437428
$(filter %$(strip $(1)), $(targets))))
438429
# %.asn1.o <- %.asn1.[ch] <- %.asn1
439-
# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
440-
# %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso
441-
targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
442-
$(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
443-
$(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo)
430+
targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h)
444431

445432
# Include additional build rules when necessary
446433
# ---------------------------------------------------------------------------
@@ -457,6 +444,10 @@ ifneq ($(userprogs),)
457444
include $(srctree)/scripts/Makefile.userprogs
458445
endif
459446

447+
ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
448+
include $(srctree)/scripts/Makefile.dtbs
449+
endif
450+
460451
# Build
461452
# ---------------------------------------------------------------------------
462453

scripts/Makefile.dtbs

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
4+
dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
5+
6+
# Composite DTB (i.e. DTB constructed by overlay)
7+
multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
8+
# Primitive DTB compiled from *.dts
9+
real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
10+
# Base DTB that overlay is applied onto
11+
base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs))
12+
13+
dtb-y := $(addprefix $(obj)/, $(dtb-y))
14+
multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
15+
real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
16+
17+
always-y += $(dtb-y)
18+
targets += $(real-dtb-y)
19+
20+
# dtbs-list
21+
# ---------------------------------------------------------------------------
22+
23+
ifdef need-dtbslist
24+
subdir-dtbslist := $(addsuffix /dtbs-list, $(subdir-ym))
25+
dtb-y += $(subdir-dtbslist)
26+
always-y += $(obj)/dtbs-list
27+
endif
28+
29+
$(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ;
30+
31+
$(obj)/dtbs-list: $(dtb-y) FORCE
32+
$(call if_changed,gen_order)
33+
34+
# Assembly file to wrap dtb(o)
35+
# ---------------------------------------------------------------------------
36+
37+
# Generate an assembly file to wrap the output of the device tree compiler
38+
quiet_cmd_wrap_S_dtb = WRAP $@
39+
cmd_wrap_S_dtb = { \
40+
symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \
41+
echo '\#include <asm-generic/vmlinux.lds.h>'; \
42+
echo '.section .dtb.init.rodata,"a"'; \
43+
echo '.balign STRUCT_ALIGNMENT'; \
44+
echo ".global $${symbase}_begin"; \
45+
echo "$${symbase}_begin:"; \
46+
echo '.incbin "$<" '; \
47+
echo ".global $${symbase}_end"; \
48+
echo "$${symbase}_end:"; \
49+
echo '.balign STRUCT_ALIGNMENT'; \
50+
} > $@
51+
52+
$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
53+
$(call if_changed,wrap_S_dtb)
54+
55+
$(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE
56+
$(call if_changed,wrap_S_dtb)
57+
58+
# Schema check
59+
# ---------------------------------------------------------------------------
60+
61+
ifneq ($(CHECK_DTBS),)
62+
DT_CHECKER ?= dt-validate
63+
DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
64+
DT_BINDING_DIR := Documentation/devicetree/bindings
65+
DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
66+
dtb-check-enabled = $(if $(filter %.dtb, $@),y)
67+
endif
68+
69+
quiet_dtb_check_tag = $(if $(dtb-check-enabled),[C], )
70+
cmd_dtb_check = $(if $(dtb-check-enabled),; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true)
71+
72+
# Overlay
73+
# ---------------------------------------------------------------------------
74+
75+
# NOTE:
76+
# Do not replace $(filter %.dtb %.dtbo, $^) with $(real-prereqs). When a single
77+
# DTB is turned into a multi-blob DTB, $^ will contain header file dependencies
78+
# recorded in the .*.cmd file.
79+
quiet_cmd_fdtoverlay = OVL $(quiet_dtb_check_tag) $@
80+
cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(filter %.dtb %.dtbo, $^) $(cmd_dtb_check)
81+
82+
$(multi-dtb-y): $(DT_TMP_SCHEMA) FORCE
83+
$(call if_changed,fdtoverlay)
84+
$(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
85+
86+
# DTC
87+
# ---------------------------------------------------------------------------
88+
89+
DTC ?= $(objtree)/scripts/dtc/dtc
90+
DTC_FLAGS += -Wno-unique_unit_address
91+
92+
# Disable noisy checks by default
93+
ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
94+
DTC_FLAGS += -Wno-unit_address_vs_reg \
95+
-Wno-avoid_unnecessary_addr_size \
96+
-Wno-alias_paths \
97+
-Wno-graph_child_address \
98+
-Wno-simple_bus_reg
99+
else
100+
DTC_FLAGS += -Wunique_unit_address_if_enabled
101+
endif
102+
103+
ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
104+
DTC_FLAGS += -Wnode_name_chars_strict \
105+
-Wproperty_name_chars_strict \
106+
-Wunique_unit_address
107+
endif
108+
109+
DTC_FLAGS += $(DTC_FLAGS_$(target-stem))
110+
111+
# Set -@ if the target is a base DTB that overlay is applied onto
112+
DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
113+
114+
DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
115+
116+
dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc -I $(DTC_INCLUDE) -undef -D__DTS__
117+
118+
dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
119+
120+
quiet_cmd_dtc = DTC $(quiet_dtb_check_tag) $@
121+
cmd_dtc = \
122+
$(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
123+
$(DTC) -o $@ -b 0 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) \
124+
$(DTC_FLAGS) -d $(depfile).dtc.tmp $(dtc-tmp) ; \
125+
cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) \
126+
$(cmd_dtb_check)
127+
128+
$(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
129+
$(call if_changed_dep,dtc)
130+
131+
$(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE
132+
$(call if_changed_dep,dtc)
133+
134+
# targets
135+
# ---------------------------------------------------------------------------
136+
137+
targets += $(always-y)
138+
139+
# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
140+
# %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso
141+
targets += $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
142+
$(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo)

scripts/Makefile.lib

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ else
4545
obj-y := $(filter-out %/, $(obj-y))
4646
endif
4747

48-
ifdef need-dtbslist
49-
dtb-y += $(addsuffix /dtbs-list, $(subdir-ym))
50-
always-y += dtbs-list
51-
endif
52-
5348
# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
5449
suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
5550
# List composite targets that are constructed by combining other targets
@@ -80,19 +75,6 @@ always-y += $(hostprogs-always-y) $(hostprogs-always-m)
8075
userprogs += $(userprogs-always-y) $(userprogs-always-m)
8176
always-y += $(userprogs-always-y) $(userprogs-always-m)
8277

83-
# DTB
84-
# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
85-
dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
86-
87-
# Composite DTB (i.e. DTB constructed by overlay)
88-
multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
89-
# Primitive DTB compiled from *.dts
90-
real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
91-
# Base DTB that overlay is applied onto
92-
base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs))
93-
94-
always-y += $(dtb-y)
95-
9678
# Add subdir path
9779

9880
ifneq ($(obj),.)
@@ -104,9 +86,6 @@ lib-y := $(addprefix $(obj)/,$(lib-y))
10486
real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
10587
real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
10688
multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
107-
dtb-y := $(addprefix $(obj)/, $(dtb-y))
108-
multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
109-
real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
11089
subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
11190
endif
11291

@@ -255,12 +234,6 @@ cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
255234

256235
ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
257236

258-
DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
259-
260-
dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \
261-
$(addprefix -I,$(DTC_INCLUDE)) \
262-
-undef -D__DTS__
263-
264237
ifdef CONFIG_OBJTOOL
265238

266239
objtool := $(objtree)/tools/objtool/objtool
@@ -350,94 +323,6 @@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
350323
quiet_cmd_gzip = GZIP $@
351324
cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
352325

353-
# DTC
354-
# ---------------------------------------------------------------------------
355-
DTC ?= $(objtree)/scripts/dtc/dtc
356-
DTC_FLAGS += \
357-
-Wno-unique_unit_address
358-
359-
# Disable noisy checks by default
360-
ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
361-
DTC_FLAGS += -Wno-unit_address_vs_reg \
362-
-Wno-avoid_unnecessary_addr_size \
363-
-Wno-alias_paths \
364-
-Wno-graph_child_address \
365-
-Wno-simple_bus_reg
366-
else
367-
DTC_FLAGS += \
368-
-Wunique_unit_address_if_enabled
369-
endif
370-
371-
ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
372-
DTC_FLAGS += -Wnode_name_chars_strict \
373-
-Wproperty_name_chars_strict \
374-
-Wunique_unit_address
375-
endif
376-
377-
DTC_FLAGS += $(DTC_FLAGS_$(target-stem))
378-
379-
# Set -@ if the target is a base DTB that overlay is applied onto
380-
DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
381-
382-
# Generate an assembly file to wrap the output of the device tree compiler
383-
quiet_cmd_wrap_S_dtb = WRAP $@
384-
cmd_wrap_S_dtb = { \
385-
symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \
386-
echo '\#include <asm-generic/vmlinux.lds.h>'; \
387-
echo '.section .dtb.init.rodata,"a"'; \
388-
echo '.balign STRUCT_ALIGNMENT'; \
389-
echo ".global $${symbase}_begin"; \
390-
echo "$${symbase}_begin:"; \
391-
echo '.incbin "$<" '; \
392-
echo ".global $${symbase}_end"; \
393-
echo "$${symbase}_end:"; \
394-
echo '.balign STRUCT_ALIGNMENT'; \
395-
} > $@
396-
397-
$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
398-
$(call if_changed,wrap_S_dtb)
399-
400-
$(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE
401-
$(call if_changed,wrap_S_dtb)
402-
403-
quiet_dtb_check_tag = $(if $(dtb-check-enabled),[C], )
404-
cmd_dtb_check = $(if $(dtb-check-enabled),; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true)
405-
406-
quiet_cmd_dtc = DTC $(quiet_dtb_check_tag) $@
407-
cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
408-
$(DTC) -o $@ -b 0 \
409-
$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
410-
-d $(depfile).dtc.tmp $(dtc-tmp) ; \
411-
cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) \
412-
$(cmd_dtb_check)
413-
414-
# NOTE:
415-
# Do not replace $(filter %.dtb %.dtbo, $^) with $(real-prereqs). When a single
416-
# DTB is turned into a multi-blob DTB, $^ will contain header file dependencies
417-
# recorded in the .*.cmd file.
418-
quiet_cmd_fdtoverlay = OVL $(quiet_dtb_check_tag) $@
419-
cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(filter %.dtb %.dtbo, $^) $(cmd_dtb_check)
420-
421-
$(multi-dtb-y): FORCE
422-
$(call if_changed,fdtoverlay)
423-
$(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
424-
425-
ifneq ($(CHECK_DTBS),)
426-
DT_CHECKER ?= dt-validate
427-
DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
428-
DT_BINDING_DIR := Documentation/devicetree/bindings
429-
DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
430-
dtb-check-enabled = $(if $(filter %.dtb, $@),y)
431-
endif
432-
433-
$(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
434-
$(call if_changed_dep,dtc)
435-
436-
$(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE
437-
$(call if_changed_dep,dtc)
438-
439-
dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
440-
441326
# Bzip2
442327
# ---------------------------------------------------------------------------
443328

0 commit comments

Comments
 (0)