xref: /openbmc/u-boot/dts/Makefile (revision 5187d8dd)
1#
2# Copyright (c) 2011 The Chromium OS Authors.
3#
4# See file CREDITS for list of people who contributed to this
5# project.
6#
7# This program is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundatio; either version 2 of
10# the License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, write to the Free Software
19# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20# MA 02111-1307 USA
21#
22
23# This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is
24# enabled. See doc/README.fdt-control for more details.
25
26include $(TOPDIR)/config.mk
27
28LIB	= $(obj)libdts.o
29
30$(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
31$(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
32DEVICE_TREE = $(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE))
33
34$(if $(CONFIG_ARCH_DEVICE_TREE),,\
35$(error Your architecture does not have device tree support enabled. \
36Please define CONFIG_ARCH_DEVICE_TREE))
37
38# We preprocess the device tree file provide a useful define
39DTS_CPPFLAGS := -DARCH_CPU_DTS=\"../arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi\"
40
41all:	$(obj).depend $(LIB)
42
43# Use a constant name for this so we can access it from C code.
44# objcopy doesn't seem to allow us to set the symbol name independently of
45# the filename.
46DT_BIN	:= $(obj)dt.dtb
47
48$(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
49	cat $< | $(CPP) -P $(DTS_CPPFLAGS) - >$@.tmp
50	$(DTC) -R 4 -p 0x1000 -O dtb -o ${DT_BIN} $@.tmp
51	rm $@.tmp
52
53process_lds = \
54	$(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
55
56# Run the compiler and get the link script from the linker
57GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
58
59$(obj)dt.o: $(DT_BIN)
60	# We want the output format and arch.
61	# We also hope to win a prize for ugliest Makefile / shell interaction
62	# We look in the LDSCRIPT first.
63	# Then try the linker which should give us the answer.
64	# Then check it worked.
65	oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` ;\
66	oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
67	\
68	[ -z $${oformat} ] && \
69		oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
70	[ -z $${oarch} ] && \
71		oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
72	\
73	[ -z $${oformat} ] && \
74		echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
75		exit 1 || true ;\
76	[ -z $${oarch} ] && \
77		echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
78		exit 1 || true ;\
79	\
80	cd $(dir ${DT_BIN}) && \
81	$(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
82		$(notdir ${DT_BIN}) $@
83	rm $(DT_BIN)
84
85OBJS-$(CONFIG_OF_EMBED)	:= dt.o
86
87COBJS	:= $(OBJS-y)
88
89OBJS	:= $(addprefix $(obj),$(COBJS))
90
91binary:	$(DT_BIN)
92
93$(LIB):	$(OBJS) $(DTB)
94	$(call cmd_link_o_target, $(OBJS))
95
96#########################################################################
97
98# defines $(obj).depend target
99include $(SRCTREE)/rules.mk
100
101sinclude $(obj).depend
102
103#########################################################################
104