xref: /linux/scripts/Makefile.dtbs (revision c94cd9508b1335b949fd13ebd269313c65492df0)
1# SPDX-License-Identifier: GPL-2.0-only
2
3# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
4dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
5
6# Composite DTB (i.e. DTB constructed by overlay)
7multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
8# Primitive DTB compiled from *.dts
9real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
10# Base DTB that overlay is applied onto
11base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs))
12
13dtb-y           := $(addprefix $(obj)/, $(dtb-y))
14multi-dtb-y     := $(addprefix $(obj)/, $(multi-dtb-y))
15real-dtb-y      := $(addprefix $(obj)/, $(real-dtb-y))
16
17always-y        += $(dtb-y)
18targets         += $(real-dtb-y)
19
20# dtbs-list
21# ---------------------------------------------------------------------------
22
23ifdef need-dtbslist
24subdir-dtbslist := $(addsuffix /dtbs-list, $(subdir-ym))
25dtb-y           += $(subdir-dtbslist)
26always-y        += $(obj)/dtbs-list
27endif
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
38quiet_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
61ifneq ($(CHECK_DTBS),)
62DT_CHECKER ?= dt-validate
63DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
64DT_BINDING_DIR := Documentation/devicetree/bindings
65DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
66dtb-check-enabled = $(if $(filter %.dtb, $@),y)
67endif
68
69quiet_dtb_check_tag = $(if $(dtb-check-enabled),[C],   )
70cmd_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.
79quiet_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
89DTC ?= $(objtree)/scripts/dtc/dtc
90DTC_FLAGS += -Wno-unique_unit_address
91
92# Disable noisy checks by default
93ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
94DTC_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
99else
100DTC_FLAGS += -Wunique_unit_address_if_enabled
101endif
102
103ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
104DTC_FLAGS += -Wnode_name_chars_strict \
105             -Wproperty_name_chars_strict \
106             -Wunique_unit_address
107endif
108
109DTC_FLAGS += $(DTC_FLAGS_$(target-stem))
110
111# Set -@ if the target is a base DTB that overlay is applied onto
112DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
113
114DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
115
116dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc -I $(DTC_INCLUDE) -undef -D__DTS__
117
118dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
119
120quiet_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
137targets += $(always-y)
138
139# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
140# %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso
141targets += $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
142           $(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo)
143