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 include $(TOPDIR)/config.mk
14 ifeq ($(DEVICE_TREE),)
15 $(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
16 $(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
17 DEVICE_TREE = $(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE))
20 $(if $(CONFIG_ARCH_DEVICE_TREE),,\
21 $(error Your architecture does not have device tree support enabled. \
22 Please define CONFIG_ARCH_DEVICE_TREE))
24 DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts
25 DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts
26 DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts
28 # We preprocess the device tree file provide a useful define
29 DTS_CPPFLAGS := -x assembler-with-cpp \
30 -DARCH_CPU_DTS=\"$(SRCTREE)/arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi\" \
31 -DBOARD_DTS=\"$(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts/$(DEVICE_TREE).dts\" \
32 -nostdinc $(addprefix -I,$(DTS_INCDIRS))
34 DTC_FLAGS := -R 4 -p 0x1000 \
35 $(addprefix -i ,$(DTS_INCDIRS))
37 all: $(obj).depend $(LIB)
39 # Use a constant name for this so we can access it from C code.
40 # objcopy doesn't seem to allow us to set the symbol name independently of
42 DT_BIN := $(obj)dt.dtb
44 $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
45 $(CPP) -P $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp
46 $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp
49 $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
51 # Run the compiler and get the link script from the linker
52 GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
55 # We want the output format and arch.
56 # We also hope to win a prize for ugliest Makefile / shell interaction
57 # We look in the LDSCRIPT first.
58 # Then try the linker which should give us the answer.
59 # Then check it worked.
60 [ -n "$(LDSCRIPT)" ] && \
61 oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
62 oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
64 [ -z $${oformat} ] && \
65 oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
67 oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
69 [ -z $${oformat} ] && \
70 echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
73 echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
76 cd $(dir ${DT_BIN}) && \
77 $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
78 $(notdir ${DT_BIN}) $@
81 OBJS-$(CONFIG_OF_EMBED) := dt.o
85 OBJS := $(addprefix $(obj),$(COBJS))
89 $(LIB): $(OBJS) $(DTB)
90 $(call cmd_link_o_target, $(OBJS))
92 #########################################################################
94 # defines $(obj).depend target
95 include $(SRCTREE)/rules.mk
97 sinclude $(obj).depend
99 #########################################################################