Makefile.dtbs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
  3. dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
  4. # Composite DTB (i.e. DTB constructed by overlay)
  5. multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
  6. # Primitive DTB compiled from *.dts
  7. real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
  8. # Base DTB that overlay is applied onto
  9. base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs))
  10. dtb-y := $(addprefix $(obj)/, $(dtb-y))
  11. multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
  12. real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
  13. always-y += $(dtb-y)
  14. targets += $(real-dtb-y)
  15. # dtbs-list
  16. # ---------------------------------------------------------------------------
  17. ifdef need-dtbslist
  18. subdir-dtbslist := $(addsuffix /dtbs-list, $(subdir-ym))
  19. dtb-y += $(subdir-dtbslist)
  20. always-y += $(obj)/dtbs-list
  21. endif
  22. $(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ;
  23. $(obj)/dtbs-list: $(dtb-y) FORCE
  24. $(call if_changed,gen_order)
  25. # Assembly file to wrap dtb(o)
  26. # ---------------------------------------------------------------------------
  27. builtin-dtb-section = $(if $(filter arch/$(SRCARCH)/boot/dts%, $(obj)),.dtb.init.rodata,.rodata)
  28. # Generate an assembly file to wrap the output of the device tree compiler
  29. quiet_cmd_wrap_S_dtb = WRAP $@
  30. cmd_wrap_S_dtb = { \
  31. symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*)); \
  32. echo '\#include <asm-generic/vmlinux.lds.h>'; \
  33. echo '.section $(builtin-dtb-section),"a"'; \
  34. echo '.balign STRUCT_ALIGNMENT'; \
  35. echo ".global $${symbase}_begin"; \
  36. echo "$${symbase}_begin:"; \
  37. echo '.incbin "$<" '; \
  38. echo ".global $${symbase}_end"; \
  39. echo "$${symbase}_end:"; \
  40. echo '.balign STRUCT_ALIGNMENT'; \
  41. } > $@
  42. $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
  43. $(call if_changed,wrap_S_dtb)
  44. $(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE
  45. $(call if_changed,wrap_S_dtb)
  46. # Schema check
  47. # ---------------------------------------------------------------------------
  48. ifneq ($(CHECK_DTBS),)
  49. DT_CHECKER ?= dt-validate
  50. DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
  51. DT_BINDING_DIR := Documentation/devicetree/bindings
  52. DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
  53. dtb-check-enabled = $(if $(filter %.dtb, $@),y)
  54. endif
  55. quiet_dtb_check_tag = $(if $(dtb-check-enabled),[C], )
  56. cmd_dtb_check = $(if $(dtb-check-enabled),; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true)
  57. # Overlay
  58. # ---------------------------------------------------------------------------
  59. # NOTE:
  60. # Do not replace $(filter %.dtb %.dtbo, $^) with $(real-prereqs). When a single
  61. # DTB is turned into a multi-blob DTB, $^ will contain header file dependencies
  62. # recorded in the .*.cmd file.
  63. quiet_cmd_fdtoverlay = OVL $(quiet_dtb_check_tag) $@
  64. cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(filter %.dtb %.dtbo, $^) $(cmd_dtb_check)
  65. $(multi-dtb-y): $(DT_TMP_SCHEMA) FORCE
  66. $(call if_changed,fdtoverlay)
  67. $(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
  68. # DTC
  69. # ---------------------------------------------------------------------------
  70. DTC ?= $(objtree)/scripts/dtc/dtc
  71. DTC_FLAGS += -Wno-unique_unit_address
  72. # Disable noisy checks by default
  73. ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
  74. DTC_FLAGS += -Wno-unit_address_vs_reg \
  75. -Wno-avoid_unnecessary_addr_size \
  76. -Wno-alias_paths \
  77. -Wno-graph_child_address \
  78. -Wno-simple_bus_reg
  79. else
  80. DTC_FLAGS += -Wunique_unit_address_if_enabled
  81. endif
  82. ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
  83. DTC_FLAGS += -Wnode_name_chars_strict \
  84. -Wproperty_name_chars_strict \
  85. -Wunique_unit_address
  86. endif
  87. DTC_FLAGS += $(DTC_FLAGS_$(target-stem))
  88. # Set -@ if the target is a base DTB that overlay is applied onto
  89. DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
  90. DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
  91. dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc -I $(DTC_INCLUDE) -undef -D__DTS__
  92. dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
  93. quiet_cmd_dtc = DTC $(quiet_dtb_check_tag) $@
  94. cmd_dtc = \
  95. $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
  96. $(DTC) -o $@ -b 0 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) \
  97. $(DTC_FLAGS) -d $(depfile).dtc.tmp $(dtc-tmp) ; \
  98. cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) \
  99. $(cmd_dtb_check)
  100. $(obj)/%.dtb: $(obj)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
  101. $(call if_changed_dep,dtc)
  102. $(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE
  103. $(call if_changed_dep,dtc)
  104. # targets
  105. # ---------------------------------------------------------------------------
  106. targets += $(always-y)
  107. # %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
  108. # %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso
  109. targets += $(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
  110. $(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo)