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 | |
| 10 | include $(TOPDIR)/config.mk |
| 11 | |
| 12 | LIB = $(obj)libdts.o |
| 13 | |
Jagannadha Sutradharudu Teki | 74de8c9 | 2013-02-28 10:20:18 +0000 | [diff] [blame] | 14 | ifeq ($(DEVICE_TREE),) |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 15 | $(if $(CONFIG_DEFAULT_DEVICE_TREE),,\ |
| 16 | $(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file)) |
| 17 | DEVICE_TREE = $(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE)) |
Jagannadha Sutradharudu Teki | 74de8c9 | 2013-02-28 10:20:18 +0000 | [diff] [blame] | 18 | endif |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 19 | |
| 20 | $(if $(CONFIG_ARCH_DEVICE_TREE),,\ |
| 21 | $(error Your architecture does not have device tree support enabled. \ |
| 22 | Please define CONFIG_ARCH_DEVICE_TREE)) |
| 23 | |
Stephen Warren | c8391a0 | 2013-07-24 10:09:19 -0700 | [diff] [blame^] | 24 | DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts |
| 25 | DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts |
| 26 | DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts |
| 27 | |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 28 | # We preprocess the device tree file provide a useful define |
Allen Martin | 6487d88 | 2013-01-08 16:07:54 +0000 | [diff] [blame] | 29 | DTS_CPPFLAGS := -x assembler-with-cpp \ |
Horst Kronstorfer | b4f106b | 2012-07-13 03:03:40 +0000 | [diff] [blame] | 30 | -DARCH_CPU_DTS=\"$(SRCTREE)/arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi\" \ |
Tom Warren | 6c5be64 | 2013-02-21 12:31:27 +0000 | [diff] [blame] | 31 | -DBOARD_DTS=\"$(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts/$(DEVICE_TREE).dts\" \ |
Stephen Warren | c8391a0 | 2013-07-24 10:09:19 -0700 | [diff] [blame^] | 32 | -nostdinc $(addprefix -I,$(DTS_INCDIRS)) |
| 33 | |
| 34 | DTC_FLAGS := -R 4 -p 0x1000 \ |
| 35 | $(addprefix -i ,$(DTS_INCDIRS)) |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 36 | |
| 37 | all: $(obj).depend $(LIB) |
| 38 | |
| 39 | # Use a constant name for this so we can access it from C code. |
| 40 | # objcopy doesn't seem to allow us to set the symbol name independently of |
| 41 | # the filename. |
| 42 | DT_BIN := $(obj)dt.dtb |
| 43 | |
| 44 | $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts |
Stephen Warren | cc4f427 | 2013-07-24 10:09:18 -0700 | [diff] [blame] | 45 | $(CPP) -P $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp |
Stephen Warren | c8391a0 | 2013-07-24 10:09:19 -0700 | [diff] [blame^] | 46 | $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 47 | |
| 48 | process_lds = \ |
| 49 | $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' |
| 50 | |
| 51 | # Run the compiler and get the link script from the linker |
| 52 | GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 |
| 53 | |
| 54 | $(obj)dt.o: $(DT_BIN) |
| 55 | # We want the output format and arch. |
| 56 | # We also hope to win a prize for ugliest Makefile / shell interaction |
| 57 | # We look in the LDSCRIPT first. |
| 58 | # Then try the linker which should give us the answer. |
| 59 | # Then check it worked. |
Horst Kronstorfer | a4ff471 | 2012-07-12 02:58:32 +0000 | [diff] [blame] | 60 | [ -n "$(LDSCRIPT)" ] && \ |
| 61 | oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \ |
| 62 | oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 63 | \ |
| 64 | [ -z $${oformat} ] && \ |
| 65 | oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ |
| 66 | [ -z $${oarch} ] && \ |
| 67 | oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ |
| 68 | \ |
| 69 | [ -z $${oformat} ] && \ |
| 70 | echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ |
| 71 | exit 1 || true ;\ |
| 72 | [ -z $${oarch} ] && \ |
| 73 | echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ |
| 74 | exit 1 || true ;\ |
| 75 | \ |
| 76 | cd $(dir ${DT_BIN}) && \ |
| 77 | $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ |
| 78 | $(notdir ${DT_BIN}) $@ |
| 79 | rm $(DT_BIN) |
| 80 | |
| 81 | OBJS-$(CONFIG_OF_EMBED) := dt.o |
| 82 | |
| 83 | COBJS := $(OBJS-y) |
| 84 | |
| 85 | OBJS := $(addprefix $(obj),$(COBJS)) |
| 86 | |
| 87 | binary: $(DT_BIN) |
| 88 | |
| 89 | $(LIB): $(OBJS) $(DTB) |
| 90 | $(call cmd_link_o_target, $(OBJS)) |
| 91 | |
| 92 | ######################################################################### |
| 93 | |
| 94 | # defines $(obj).depend target |
| 95 | include $(SRCTREE)/rules.mk |
| 96 | |
| 97 | sinclude $(obj).depend |
| 98 | |
| 99 | ######################################################################### |