Makefile 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #
  2. # Copyright (c) 2011 The Chromium OS Authors.
  3. #
  4. # SPDX-License-Identifier: GPL-2.0+
  5. #
  6. # This Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is
  7. # enabled. See doc/README.fdt-control for more details.
  8. ifeq ($(DEVICE_TREE),)
  9. $(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
  10. $(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
  11. DEVICE_TREE = $(CONFIG_DEFAULT_DEVICE_TREE:"%"=%)
  12. endif
  13. DTS_INCDIRS = $(SRCTREE)/board/$(VENDOR)/$(BOARD)/dts
  14. DTS_INCDIRS += $(SRCTREE)/board/$(VENDOR)/dts
  15. DTS_INCDIRS += $(SRCTREE)/arch/$(ARCH)/dts
  16. DTS_CPPFLAGS := -x assembler-with-cpp -undef -D__DTS__ \
  17. -nostdinc $(addprefix -I,$(DTS_INCDIRS))
  18. DTC_FLAGS := -R 4 -p 0x1000 \
  19. $(addprefix -i ,$(DTS_INCDIRS))
  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.
  23. DT_BIN := $(obj)/dt.dtb
  24. $(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
  25. $(CPP) $(DTS_CPPFLAGS) $< -o $(DT_BIN).dts.tmp
  26. $(DTC) $(DTC_FLAGS) -O dtb -o ${DT_BIN} $(DT_BIN).dts.tmp
  27. process_lds = \
  28. $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p'
  29. # Run the compiler and get the link script from the linker
  30. GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1
  31. $(obj)/dt.o: $(DT_BIN)
  32. # We want the output format and arch.
  33. # We also hope to win a prize for ugliest Makefile / shell interaction
  34. # We look in the LDSCRIPT first.
  35. # Then try the linker which should give us the answer.
  36. # Then check it worked.
  37. [ -n "$(LDSCRIPT)" ] && \
  38. oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` && \
  39. oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\
  40. \
  41. [ -z $${oformat} ] && \
  42. oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\
  43. [ -z $${oarch} ] && \
  44. oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\
  45. \
  46. [ -z $${oformat} ] && \
  47. echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \
  48. exit 1 || true ;\
  49. [ -z $${oarch} ] && \
  50. echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \
  51. exit 1 || true ;\
  52. \
  53. cd $(dir ${DT_BIN}) && \
  54. $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \
  55. $(notdir ${DT_BIN}) $(notdir $@)
  56. rm $(DT_BIN)
  57. obj-$(CONFIG_OF_EMBED) := dt.o
  58. binary: $(DT_BIN)