Makefile 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. # This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is
  23. # enabled. See doc/README.fdt-control for more details.
  24. include $(TOPDIR)/config.mk
  25. LIB = $(obj)libdts.o
  26. ifeq ($(DEVICE_TREE),)
  27. $(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
  28. $(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
  29. DEVICE_TREE = $(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE))
  30. endif
  31. $(if $(CONFIG_ARCH_DEVICE_TREE),,\
  32. $(error Your architecture does not have device tree support enabled. \
  33. Please define CONFIG_ARCH_DEVICE_TREE))
  34. # We preprocess the device tree file provide a useful define
  35. DTS_CPPFLAGS := -x assembler-with-cpp \
  36. -DARCH_CPU_DTS=\"$(SRCTREE)/arch/$(ARCH)/dts/$(CONFIG_ARCH_DEVICE_TREE).dtsi\" \
  37. -DBOARD_DTS=\"$(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts/$(DEVICE_TREE).dts\" \
  38. -I$(SRCTREE)/board/$(VENDOR)/dts -I$(SRCTREE)/arch/$(ARCH)/dts
  39. all: $(obj).depend $(LIB)
  40. # Use a constant name for this so we can access it from C code.
  41. # objcopy doesn't seem to allow us to set the symbol name independently of
  42. # the filename.
  43. DT_BIN := $(obj)dt.dtb
  44. $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
  45. rc=$$( \
  46. cat $< | $(CPP) -P $(DTS_CPPFLAGS) - | \
  47. { { $(DTC) -R 4 -p 0x1000 -O dtb -o ${DT_BIN} - 2>&1 ; \
  48. echo $$? >&3 ; } | \
  49. grep -v '^DTC: dts->dtb on file' ; \
  50. } 3>&1 1>&2 ) ; \
  51. exit $$rc
  52. process_lds = \
  53. $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
  54. # Run the compiler and get the link script from the linker
  55. GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
  56. $(obj)dt.o: $(DT_BIN)
  57. # We want the output format and arch.
  58. # We also hope to win a prize for ugliest Makefile / shell interaction
  59. # We look in the LDSCRIPT first.
  60. # Then try the linker which should give us the answer.
  61. # Then check it worked.
  62. [ -n "$(LDSCRIPT)" ] && \
  63. oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
  64. oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
  65. \
  66. [ -z $${oformat} ] && \
  67. oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
  68. [ -z $${oarch} ] && \
  69. oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
  70. \
  71. [ -z $${oformat} ] && \
  72. echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
  73. exit 1 || true ;\
  74. [ -z $${oarch} ] && \
  75. echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
  76. exit 1 || true ;\
  77. \
  78. cd $(dir ${DT_BIN}) && \
  79. $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
  80. $(notdir ${DT_BIN}) $@
  81. rm $(DT_BIN)
  82. OBJS-$(CONFIG_OF_EMBED) := dt.o
  83. COBJS := $(OBJS-y)
  84. OBJS := $(addprefix $(obj),$(COBJS))
  85. binary: $(DT_BIN)
  86. $(LIB): $(OBJS) $(DTB)
  87. $(call cmd_link_o_target, $(OBJS))
  88. #########################################################################
  89. # defines $(obj).depend target
  90. include $(SRCTREE)/rules.mk
  91. sinclude $(obj).depend
  92. #########################################################################