Makefile.dtbs 5.3 KB

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