Skip to content

Commit 22435f3

Browse files
Stephen Warrenglikely
authored andcommitted
kbuild: create a rule to run the pre-processor on *.dts files
Create cmd_dtc_cpp to run the C pre-processor on *.dts file before passing them to dtc for final compilation. This allows the use of #define and #include within the .dts file. Acked-by: Simon Glass <sjg@chromium.org> Acked-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Acked-by: Michal Marek <mmarek@suse.cz> Acked-by: Srinivas Kandagatla <srinivas.kandagatla@st.com> Signed-off-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent 1d0b1c7 commit 22435f3

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎Documentation/kbuild/makefiles.txt‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,29 @@ When kbuild executes, the following steps are followed (roughly):
11861186
clean-files += *.dtb
11871187
DTC_FLAGS ?= -p 1024
11881188

1189+
dtc_cpp
1190+
This is just like dtc as describe above, except that the C pre-
1191+
processor is invoked upon the .dtsp file before compiling the result
1192+
with dtc.
1193+
1194+
In order for build dependencies to work, all files compiled using
1195+
dtc_cpp must use the C pre-processor's #include functionality and not
1196+
dtc's /include/ functionality.
1197+
1198+
Using the C pre-processor allows use of #define to create named
1199+
constants. In turn, the #defines will typically appear in a header
1200+
file, which may be shared with regular C code. Since the dtc language
1201+
represents a data structure rather than code in C syntax, similar
1202+
restrictions are placed on a header file included by a device tree
1203+
file as for a header file included by an assembly language file.
1204+
In particular, the C pre-processor is passed -x assembler-with-cpp,
1205+
which sets macro __ASSEMBLY__. __DTS__ is also set. These allow header
1206+
files to restrict their content to that compatible with device tree
1207+
source.
1208+
1209+
A central rule exists to create $(obj)/%.dtb from $(src)/%.dtsp;
1210+
architecture Makefiles do no need to explicitly write out that rule.
1211+
11891212
--- 6.8 Custom kbuild commands
11901213

11911214
When kbuild is executing with KBUILD_VERBOSE=0, then only a shorthand

‎scripts/Makefile.lib‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ cmd_dtc = $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) -d $(depfile
269269
$(obj)/%.dtb: $(src)/%.dts FORCE
270270
$(call if_changed_dep,dtc)
271271

272+
dtc-tmp = $(subst $(comma),_,$(dot-target).dts)
273+
274+
quiet_cmd_dtc_cpp = DTC+CPP $@
275+
cmd_dtc_cpp = $(CPP) $(cpp_flags) -x assembler-with-cpp -undef -D__DTS__ \
276+
-o $(dtc-tmp) $< ; \
277+
$(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) $(dtc-tmp)
278+
279+
$(obj)/%.dtb: $(src)/%.dtsp FORCE
280+
$(call if_changed_dep,dtc_cpp)
281+
272282
# Bzip2
273283
# ---------------------------------------------------------------------------
274284

0 commit comments

Comments
 (0)