blob: ccd552fa0031e02c82790d209058f75f8a002492 [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
Stephen Warrenc8391a02013-07-24 10:09:19 -070020DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts
21DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts
22DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts
23
Allen Martin6487d882013-01-08 16:07:54 +000024DTS_CPPFLAGS := -x assembler-with-cpp \
Stephen Warrenc8391a02013-07-24 10:09:19 -070025 -nostdinc $(addprefix -I,$(DTS_INCDIRS))
26
27DTC_FLAGS := -R 4 -p 0x1000 \
28 $(addprefix -i ,$(DTS_INCDIRS))
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
Stephen Warren32ac4bd2013-07-24 10:09:23 -070038 $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp
Stephen Warrenc8391a02013-07-24 10:09:19 -070039 $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp
Simon Glassbbb0b122011-10-15 05:48:21 +000040
41process_lds = \
42 $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
43
44# Run the compiler and get the link script from the linker
45GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
46
47$(obj)dt.o: $(DT_BIN)
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.
Horst Kronstorfera4ff4712012-07-12 02:58:32 +000053 [ -n "$(LDSCRIPT)" ] && \
54 oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
55 oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
Simon Glassbbb0b122011-10-15 05:48:21 +000056 \
57 [ -z $${oformat} ] && \
58 oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
59 [ -z $${oarch} ] && \
60 oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
61 \
62 [ -z $${oformat} ] && \
63 echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
64 exit 1 || true ;\
65 [ -z $${oarch} ] && \
66 echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
67 exit 1 || true ;\
68 \
69 cd $(dir ${DT_BIN}) && \
70 $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
71 $(notdir ${DT_BIN}) $@
72 rm $(DT_BIN)
73
74OBJS-$(CONFIG_OF_EMBED) := dt.o
75
76COBJS := $(OBJS-y)
77
78OBJS := $(addprefix $(obj),$(COBJS))
79
80binary: $(DT_BIN)
81
82$(LIB): $(OBJS) $(DTB)
83 $(call cmd_link_o_target, $(OBJS))
84
85#########################################################################
86
87# defines $(obj).depend target
88include $(SRCTREE)/rules.mk
89
90sinclude $(obj).depend
91
92#########################################################################