2 # Copyright (c) 2011 The Chromium OS Authors.
4 # SPDX-License-Identifier: GPL-2.0+
7 # This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is
8 # enabled. See doc/README.fdt-control for more details.
10 ifeq ($(DEVICE_TREE
),)
11 $(if
$(CONFIG_DEFAULT_DEVICE_TREE
),,\
12 $(error Please
define CONFIG_DEFAULT_DEVICE_TREE in your board header file
))
13 DEVICE_TREE
= $(CONFIG_DEFAULT_DEVICE_TREE
:"%"=%)
16 DTS_INCDIRS
= $(SRCTREE
)/board
/$(VENDOR
)/$(BOARD
)/dts
17 DTS_INCDIRS
+= $(SRCTREE
)/board
/$(VENDOR
)/dts
18 DTS_INCDIRS
+= $(SRCTREE
)/arch
/$(ARCH
)/dts
20 DTS_CPPFLAGS
:= -x assembler-with-cpp
-undef
-D__DTS__ \
21 -nostdinc
$(addprefix -I
,$(DTS_INCDIRS
))
23 DTC_FLAGS
:= -R
4 -p
0x1000 \
24 $(addprefix -i
,$(DTS_INCDIRS
))
26 # Use a constant name for this so we can access it from C code.
27 # objcopy doesn't seem to allow us to set the symbol name independently of
29 DT_BIN
:= $(obj
)dt.dtb
31 $(DT_BIN
): $(TOPDIR
)/board
/$(VENDOR
)/dts
/$(DEVICE_TREE
).dts
32 $(CPP
) $(DTS_CPPFLAGS
) $< -o
$(DT_BIN
).dts.tmp
33 $(DTC
) $(DTC_FLAGS
) -O dtb
-o
${DT_BIN} $(DT_BIN
).dts.tmp
36 $(1) | sed
-r
-n
's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
38 # Run the compiler and get the link script from the linker
39 GET_LDS
= $(CC
) $(CFLAGS
) $(LDFLAGS
) -Wl
,--verbose
2>&1
42 # We want the output format and arch.
43 # We also hope to win a prize for ugliest Makefile / shell interaction
44 # We look in the LDSCRIPT first.
45 # Then try the linker which should give us the answer.
46 # Then check it worked.
47 [ -n
"$(LDSCRIPT)" ] && \
48 oformat
=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
49 oarch
=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
51 [ -z
$${oformat} ] && \
52 oformat
=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
54 oarch
=`$(call process_lds,$(GET_LDS),ARCH)` ;\
56 [ -z
$${oformat} ] && \
57 echo
"Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
60 echo
"Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
63 cd
$(dir ${DT_BIN}) && \
64 $(OBJCOPY
) -I binary
-O
$${oformat} -B
$${oarch} \
65 $(notdir ${DT_BIN}) $@
68 obj-
$(CONFIG_OF_EMBED
) := dt.o