]> git.ipfire.org Git - people/ms/u-boot.git/blob - dts/Makefile
Merge branch 'master' of git://www.denx.de/git/u-boot-cfi-flash
[people/ms/u-boot.git] / dts / Makefile
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
26 include $(TOPDIR)/config.mk
27
28 LIB = $(obj)libdts.o
29
30 ifeq ($(DEVICE_TREE),)
31 $(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
32 $(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
33 DEVICE_TREE = $(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE))
34 endif
35
36 $(if $(CONFIG_ARCH_DEVICE_TREE),,\
37 $(error Your architecture does not have device tree support enabled. \
38 Please define CONFIG_ARCH_DEVICE_TREE))
39
40 # We preprocess the device tree file provide a useful define
41 DTS_CPPFLAGS := -x assembler-with-cpp \
42 -DARCH_CPU_DTS=\"$(SRCTREE)/arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi\" \
43 -DBOARD_DTS=\"$(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts/$(DEVICE_TREE).dts\" \
44 -I$(SRCTREE)/board/$(VENDOR)/dts -I$(SRCTREE)/arch/$(ARCH)/dts
45
46 all: $(obj).depend $(LIB)
47
48 # Use a constant name for this so we can access it from C code.
49 # objcopy doesn't seem to allow us to set the symbol name independently of
50 # the filename.
51 DT_BIN := $(obj)dt.dtb
52
53 $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
54 rc=$$( \
55 cat $< | $(CPP) -P $(DTS_CPPFLAGS) - | \
56 { { $(DTC) -R 4 -p 0x1000 -O dtb -o ${DT_BIN} - 2>&1 ; \
57 echo $$? >&3 ; } | \
58 grep -v '^DTC: dts->dtb on file' ; \
59 } 3>&1 1>&2 ) ; \
60 exit $$rc
61
62 process_lds = \
63 $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
64
65 # Run the compiler and get the link script from the linker
66 GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
67
68 $(obj)dt.o: $(DT_BIN)
69 # We want the output format and arch.
70 # We also hope to win a prize for ugliest Makefile / shell interaction
71 # We look in the LDSCRIPT first.
72 # Then try the linker which should give us the answer.
73 # Then check it worked.
74 [ -n "$(LDSCRIPT)" ] && \
75 oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
76 oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
77 \
78 [ -z $${oformat} ] && \
79 oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
80 [ -z $${oarch} ] && \
81 oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
82 \
83 [ -z $${oformat} ] && \
84 echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
85 exit 1 || true ;\
86 [ -z $${oarch} ] && \
87 echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
88 exit 1 || true ;\
89 \
90 cd $(dir ${DT_BIN}) && \
91 $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
92 $(notdir ${DT_BIN}) $@
93 rm $(DT_BIN)
94
95 OBJS-$(CONFIG_OF_EMBED) := dt.o
96
97 COBJS := $(OBJS-y)
98
99 OBJS := $(addprefix $(obj),$(COBJS))
100
101 binary: $(DT_BIN)
102
103 $(LIB): $(OBJS) $(DTB)
104 $(call cmd_link_o_target, $(OBJS))
105
106 #########################################################################
107
108 # defines $(obj).depend target
109 include $(SRCTREE)/rules.mk
110
111 sinclude $(obj).depend
112
113 #########################################################################