Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2011 The Chromium OS Authors. |
| 3 | # |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 5 | # |
| 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 | |
Stephen Warren | c8391a0 | 2013-07-24 10:09:19 -0700 | [diff] [blame] | 10 | DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts |
| 11 | DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts |
| 12 | DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts |
| 13 | |
Stephen Warren | f53932a | 2013-07-24 10:09:24 -0700 | [diff] [blame] | 14 | DTS_CPPFLAGS := -x assembler-with-cpp -undef -D__DTS__ \ |
Stephen Warren | c8391a0 | 2013-07-24 10:09:19 -0700 | [diff] [blame] | 15 | -nostdinc $(addprefix -I,$(DTS_INCDIRS)) |
| 16 | |
| 17 | DTC_FLAGS := -R 4 -p 0x1000 \ |
| 18 | $(addprefix -i ,$(DTS_INCDIRS)) |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 19 | |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 20 | # Use a constant name for this so we can access it from C code. |
| 21 | # objcopy doesn't seem to allow us to set the symbol name independently of |
| 22 | # the filename. |
Masahiro Yamada | 9e41403 | 2014-02-04 17:24:24 +0900 | [diff] [blame] | 23 | DT_BIN := $(obj)/dt.dtb |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 24 | |
Masahiro Yamada | efcf861 | 2014-02-04 17:24:40 +0900 | [diff] [blame^] | 25 | DEVICE_TREE ?= $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%) |
| 26 | ifeq ($(DEVICE_TREE),) |
| 27 | $(DT_BIN): FORCE |
| 28 | echo >&2 "Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file" |
| 29 | else |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 30 | $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts |
Stephen Warren | 32ac4bd | 2013-07-24 10:09:23 -0700 | [diff] [blame] | 31 | $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp |
Stephen Warren | c8391a0 | 2013-07-24 10:09:19 -0700 | [diff] [blame] | 32 | $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp |
Masahiro Yamada | efcf861 | 2014-02-04 17:24:40 +0900 | [diff] [blame^] | 33 | endif |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 34 | |
| 35 | process_lds = \ |
| 36 | $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' |
| 37 | |
| 38 | # Run the compiler and get the link script from the linker |
Masahiro Yamada | 6825a95 | 2014-02-04 17:24:28 +0900 | [diff] [blame] | 39 | GET_LDS = $(CC) $(c_flags) $(ld_flags) -Wl,--verbose 2>&1 |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 40 | |
Masahiro Yamada | 9e41403 | 2014-02-04 17:24:24 +0900 | [diff] [blame] | 41 | $(obj)/dt.o: $(DT_BIN) |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 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 Kronstorfer | a4ff471 | 2012-07-12 02:58:32 +0000 | [diff] [blame] | 47 | [ -n "$(LDSCRIPT)" ] && \ |
| 48 | oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \ |
| 49 | oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 50 | \ |
| 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} \ |
Masahiro Yamada | 9e41403 | 2014-02-04 17:24:24 +0900 | [diff] [blame] | 65 | $(notdir ${DT_BIN}) $(notdir $@) |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 66 | rm $(DT_BIN) |
| 67 | |
Masahiro Yamada | bcfe8fd | 2013-10-21 11:53:40 +0900 | [diff] [blame] | 68 | obj-$(CONFIG_OF_EMBED) := dt.o |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 69 | |
| 70 | binary: $(DT_BIN) |