blob: 35303f7c5a8fdab0e5391c09d3a2bd9acb232c56 [file] [log] [blame]
Simon Glassbbb0b122011-10-15 05:48:21 +00001#
2# Copyright (c) 2011 The Chromium OS Authors.
3#
Wolfgang Denk1a459662013-07-08 09:37:19 +02004# SPDX-License-Identifier: GPL-2.0+
Simon Glassbbb0b122011-10-15 05:48:21 +00005#
6
7# This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is
8# enabled. See doc/README.fdt-control for more details.
9
10include $(TOPDIR)/config.mk
11
12LIB = $(obj)libdts.o
13
Jagannadha Sutradharudu Teki74de8c92013-02-28 10:20:18 +000014ifeq ($(DEVICE_TREE),)
Simon Glassbbb0b122011-10-15 05:48:21 +000015$(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
16$(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
17DEVICE_TREE = $(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE))
Jagannadha Sutradharudu Teki74de8c92013-02-28 10:20:18 +000018endif
Simon Glassbbb0b122011-10-15 05:48:21 +000019
20$(if $(CONFIG_ARCH_DEVICE_TREE),,\
21$(error Your architecture does not have device tree support enabled. \
22Please define CONFIG_ARCH_DEVICE_TREE))
23
24# We preprocess the device tree file provide a useful define
Allen Martin6487d882013-01-08 16:07:54 +000025DTS_CPPFLAGS := -x assembler-with-cpp \
Horst Kronstorferb4f106b2012-07-13 03:03:40 +000026 -DARCH_CPU_DTS=\"$(SRCTREE)/arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi\" \
Tom Warren6c5be642013-02-21 12:31:27 +000027 -DBOARD_DTS=\"$(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts/$(DEVICE_TREE).dts\" \
28 -I$(SRCTREE)/board/$(VENDOR)/dts -I$(SRCTREE)/arch/$(ARCH)/dts
Simon Glassbbb0b122011-10-15 05:48:21 +000029
30all: $(obj).depend $(LIB)
31
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
34# the filename.
35DT_BIN := $(obj)dt.dtb
36
37$(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
Wolfgang Denk896bbb52012-04-19 02:36:44 +000038 rc=$$( \
39 cat $< | $(CPP) -P $(DTS_CPPFLAGS) - | \
40 { { $(DTC) -R 4 -p 0x1000 -O dtb -o ${DT_BIN} - 2>&1 ; \
41 echo $$? >&3 ; } | \
42 grep -v '^DTC: dts->dtb on file' ; \
Stephen Warren58e22f82012-06-08 12:28:17 +000043 } 3>&1 1>&2 ) ; \
Wolfgang Denk896bbb52012-04-19 02:36:44 +000044 exit $$rc
Simon Glassbbb0b122011-10-15 05:48:21 +000045
46process_lds = \
47 $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
48
49# Run the compiler and get the link script from the linker
50GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
51
52$(obj)dt.o: $(DT_BIN)
53 # We want the output format and arch.
54 # We also hope to win a prize for ugliest Makefile / shell interaction
55 # We look in the LDSCRIPT first.
56 # Then try the linker which should give us the answer.
57 # Then check it worked.
Horst Kronstorfera4ff4712012-07-12 02:58:32 +000058 [ -n "$(LDSCRIPT)" ] && \
59 oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
60 oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
Simon Glassbbb0b122011-10-15 05:48:21 +000061 \
62 [ -z $${oformat} ] && \
63 oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
64 [ -z $${oarch} ] && \
65 oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
66 \
67 [ -z $${oformat} ] && \
68 echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
69 exit 1 || true ;\
70 [ -z $${oarch} ] && \
71 echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
72 exit 1 || true ;\
73 \
74 cd $(dir ${DT_BIN}) && \
75 $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
76 $(notdir ${DT_BIN}) $@
77 rm $(DT_BIN)
78
79OBJS-$(CONFIG_OF_EMBED) := dt.o
80
81COBJS := $(OBJS-y)
82
83OBJS := $(addprefix $(obj),$(COBJS))
84
85binary: $(DT_BIN)
86
87$(LIB): $(OBJS) $(DTB)
88 $(call cmd_link_o_target, $(OBJS))
89
90#########################################################################
91
92# defines $(obj).depend target
93include $(SRCTREE)/rules.mk
94
95sinclude $(obj).depend
96
97#########################################################################