Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 1 | # |
| 2 | # Copyright (c) 2011 The Chromium OS Authors. |
| 3 | # |
| 4 | # See file CREDITS for list of people who contributed to this |
| 5 | # project. |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or |
| 8 | # modify it under the terms of the GNU General Public License as |
| 9 | # published by the Free Software Foundatio; either version 2 of |
| 10 | # the License, or (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program; if not, write to the Free Software |
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | # MA 02111-1307 USA |
| 21 | # |
| 22 | |
| 23 | # This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is |
| 24 | # enabled. See doc/README.fdt-control for more details. |
| 25 | |
| 26 | include $(TOPDIR)/config.mk |
| 27 | |
| 28 | LIB = $(obj)libdts.o |
| 29 | |
| 30 | $(if $(CONFIG_DEFAULT_DEVICE_TREE),,\ |
| 31 | $(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file)) |
| 32 | DEVICE_TREE = $(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE)) |
| 33 | |
| 34 | $(if $(CONFIG_ARCH_DEVICE_TREE),,\ |
| 35 | $(error Your architecture does not have device tree support enabled. \ |
| 36 | Please define CONFIG_ARCH_DEVICE_TREE)) |
| 37 | |
| 38 | # We preprocess the device tree file provide a useful define |
Allen Martin | 6487d88 | 2013-01-08 16:07:54 +0000 | [diff] [blame] | 39 | DTS_CPPFLAGS := -x assembler-with-cpp \ |
Horst Kronstorfer | b4f106b | 2012-07-13 03:03:40 +0000 | [diff] [blame] | 40 | -DARCH_CPU_DTS=\"$(SRCTREE)/arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi\" \ |
Stephan Linz | a1d2478 | 2012-07-04 22:25:29 +0200 | [diff] [blame] | 41 | -DBOARD_DTS=\"$(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts/$(DEVICE_TREE).dts\" |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 42 | |
| 43 | all: $(obj).depend $(LIB) |
| 44 | |
| 45 | # Use a constant name for this so we can access it from C code. |
| 46 | # objcopy doesn't seem to allow us to set the symbol name independently of |
| 47 | # the filename. |
| 48 | DT_BIN := $(obj)dt.dtb |
| 49 | |
| 50 | $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts |
Wolfgang Denk | 896bbb5 | 2012-04-19 02:36:44 +0000 | [diff] [blame] | 51 | rc=$$( \ |
| 52 | cat $< | $(CPP) -P $(DTS_CPPFLAGS) - | \ |
| 53 | { { $(DTC) -R 4 -p 0x1000 -O dtb -o ${DT_BIN} - 2>&1 ; \ |
| 54 | echo $$? >&3 ; } | \ |
| 55 | grep -v '^DTC: dts->dtb on file' ; \ |
Stephen Warren | 58e22f8 | 2012-06-08 12:28:17 +0000 | [diff] [blame] | 56 | } 3>&1 1>&2 ) ; \ |
Wolfgang Denk | 896bbb5 | 2012-04-19 02:36:44 +0000 | [diff] [blame] | 57 | exit $$rc |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 58 | |
| 59 | process_lds = \ |
| 60 | $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' |
| 61 | |
| 62 | # Run the compiler and get the link script from the linker |
| 63 | GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 |
| 64 | |
| 65 | $(obj)dt.o: $(DT_BIN) |
| 66 | # We want the output format and arch. |
| 67 | # We also hope to win a prize for ugliest Makefile / shell interaction |
| 68 | # We look in the LDSCRIPT first. |
| 69 | # Then try the linker which should give us the answer. |
| 70 | # Then check it worked. |
Horst Kronstorfer | a4ff471 | 2012-07-12 02:58:32 +0000 | [diff] [blame] | 71 | [ -n "$(LDSCRIPT)" ] && \ |
| 72 | oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \ |
| 73 | oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ |
Simon Glass | bbb0b12 | 2011-10-15 05:48:21 +0000 | [diff] [blame] | 74 | \ |
| 75 | [ -z $${oformat} ] && \ |
| 76 | oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ |
| 77 | [ -z $${oarch} ] && \ |
| 78 | oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ |
| 79 | \ |
| 80 | [ -z $${oformat} ] && \ |
| 81 | echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ |
| 82 | exit 1 || true ;\ |
| 83 | [ -z $${oarch} ] && \ |
| 84 | echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ |
| 85 | exit 1 || true ;\ |
| 86 | \ |
| 87 | cd $(dir ${DT_BIN}) && \ |
| 88 | $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ |
| 89 | $(notdir ${DT_BIN}) $@ |
| 90 | rm $(DT_BIN) |
| 91 | |
| 92 | OBJS-$(CONFIG_OF_EMBED) := dt.o |
| 93 | |
| 94 | COBJS := $(OBJS-y) |
| 95 | |
| 96 | OBJS := $(addprefix $(obj),$(COBJS)) |
| 97 | |
| 98 | binary: $(DT_BIN) |
| 99 | |
| 100 | $(LIB): $(OBJS) $(DTB) |
| 101 | $(call cmd_link_o_target, $(OBJS)) |
| 102 | |
| 103 | ######################################################################### |
| 104 | |
| 105 | # defines $(obj).depend target |
| 106 | include $(SRCTREE)/rules.mk |
| 107 | |
| 108 | sinclude $(obj).depend |
| 109 | |
| 110 | ######################################################################### |