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 DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts
21 DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts
22 DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts
24 DTS_CPPFLAGS := -x assembler-with-cpp -undef -D__DTS__ \
25 -nostdinc $(addprefix -I,$(DTS_INCDIRS))
27 DTC_FLAGS := -R 4 -p 0x1000 \
28 $(addprefix -i ,$(DTS_INCDIRS))
30 all: $(obj).depend $(LIB)
32 # Use a constant name for this so we can access it from C code.
33 # objcopy doesn't seem to allow us to set the symbol name independently of
35 DT_BIN := $(obj)dt.dtb
37 $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
38 $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp
39 $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp
42 $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
44 # Run the compiler and get the link script from the linker
45 GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
48 # We want the output format and arch.
49 # We also hope to win a prize for ugliest Makefile / shell interaction
50 # We look in the LDSCRIPT first.
51 # Then try the linker which should give us the answer.
52 # Then check it worked.
53 [ -n "$(LDSCRIPT)" ] && \
54 oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
55 oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
57 [ -z $${oformat} ] && \
58 oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
60 oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
62 [ -z $${oformat} ] && \
63 echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
66 echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
69 cd $(dir ${DT_BIN}) && \
70 $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
71 $(notdir ${DT_BIN}) $@
74 OBJS-$(CONFIG_OF_EMBED) := dt.o
78 OBJS := $(addprefix $(obj),$(COBJS))
82 $(LIB): $(OBJS) $(DTB)
83 $(call cmd_link_o_target, $(OBJS))
85 #########################################################################
87 # defines $(obj).depend target
88 include $(SRCTREE)/rules.mk
90 sinclude $(obj).depend
92 #########################################################################