blob: 6c7198f65ff565da9d305d318f1047551c5764cc [file] [log] [blame]
Simon Glass38d6b8d2011-10-15 05:48:21 +00001#
2# Copyright (c) 2011 The Chromium OS Authors.
3#
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004# SPDX-License-Identifier: GPL-2.0+
Simon Glass38d6b8d2011-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
Jagannadha Sutradharudu Teki79e63a42013-02-28 10:20:18 +000010ifeq ($(DEVICE_TREE),)
Simon Glass38d6b8d2011-10-15 05:48:21 +000011$(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
12$(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
Masahiro Yamada7c9c7442013-12-05 15:08:31 +090013DEVICE_TREE = $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%)
Jagannadha Sutradharudu Teki79e63a42013-02-28 10:20:18 +000014endif
Simon Glass38d6b8d2011-10-15 05:48:21 +000015
Stephen Warrenc198ef72013-07-24 10:09:19 -070016DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts
17DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts
18DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts
19
Stephen Warren4d123012013-07-24 10:09:24 -070020DTS_CPPFLAGS := -x assembler-with-cpp -undef -D__DTS__ \
Stephen Warrenc198ef72013-07-24 10:09:19 -070021 -nostdinc $(addprefix -I,$(DTS_INCDIRS))
22
23DTC_FLAGS := -R 4 -p 0x1000 \
24 $(addprefix -i ,$(DTS_INCDIRS))
Simon Glass38d6b8d2011-10-15 05:48:21 +000025
Simon Glass38d6b8d2011-10-15 05:48:21 +000026# Use a constant name for this so we can access it from C code.
27# objcopy doesn't seem to allow us to set the symbol name independently of
28# the filename.
29DT_BIN := $(obj)dt.dtb
30
31$(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
Stephen Warrenaeedbcf2013-07-24 10:09:23 -070032 $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp
Stephen Warrenc198ef72013-07-24 10:09:19 -070033 $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp
Simon Glass38d6b8d2011-10-15 05:48:21 +000034
35process_lds = \
36 $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
37
38# Run the compiler and get the link script from the linker
39GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
40
41$(obj)dt.o: $(DT_BIN)
42 # We want the output format and arch.
43 # We also hope to win a prize for ugliest Makefile / shell interaction
44 # We look in the LDSCRIPT first.
45 # Then try the linker which should give us the answer.
46 # Then check it worked.
Horst Kronstorfer17838162012-07-12 02:58:32 +000047 [ -n "$(LDSCRIPT)" ] && \
48 oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
49 oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
Simon Glass38d6b8d2011-10-15 05:48:21 +000050 \
51 [ -z $${oformat} ] && \
52 oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
53 [ -z $${oarch} ] && \
54 oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
55 \
56 [ -z $${oformat} ] && \
57 echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
58 exit 1 || true ;\
59 [ -z $${oarch} ] && \
60 echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
61 exit 1 || true ;\
62 \
63 cd $(dir ${DT_BIN}) && \
64 $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
65 $(notdir ${DT_BIN}) $@
66 rm $(DT_BIN)
67
Masahiro Yamada9e097352013-10-21 11:53:40 +090068obj-$(CONFIG_OF_EMBED) := dt.o
Simon Glass38d6b8d2011-10-15 05:48:21 +000069
70binary: $(DT_BIN)