Makefile.ppl 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. # SPDX-License-Identifier: GPL-2.0+
  2. #
  3. # Copyright (C) 2020 Alibaba Group Holding Limited
  4. #
  5. src := $(obj)
  6. # Create output directory if not already present
  7. _dummy := $(shell [ -d $(obj) ] || mkdir -p $(obj))
  8. include $(srctree)/scripts/Kbuild.include
  9. -include include/config/auto.conf
  10. -include $(obj)/include/autoconf.mk
  11. KBUILD_CPPFLAGS += -DCONFIG_PPL_BUILD
  12. ifeq ($(obj)$(CONFIG_SUPPORT_PPL),ppl)
  13. $(error You cannot build PPL without enabling CONFIG_SUPPORT_PPL)
  14. endif
  15. include $(srctree)/config.mk
  16. include $(srctree)/arch/$(ARCH)/Makefile
  17. include $(srctree)/scripts/Makefile.lib
  18. # Enable garbage collection of un-used sections for SPL
  19. KBUILD_CFLAGS += -ffunction-sections -fdata-sections
  20. LDFLAGS_FINAL += --gc-sections
  21. # FIX ME
  22. cpp_flags := $(KBUILD_CPPFLAGS) $(PLATFORM_CPPFLAGS) $(UBOOTINCLUDE) \
  23. $(NOSTDINC_FLAGS)
  24. c_flags := $(KBUILD_CFLAGS) $(cpp_flags)
  25. HAVE_VENDOR_COMMON_LIB = $(if $(wildcard $(srctree)/board/$(VENDOR)/common/Makefile),y,n)
  26. libs-y += $(if $(BOARDDIR),board/$(BOARDDIR)/)
  27. libs-$(HAVE_VENDOR_COMMON_LIB) += board/$(VENDOR)/common/
  28. head-y := $(addprefix $(obj)/,$(head-y))
  29. libs-y := $(addprefix $(obj)/,$(libs-y))
  30. u-boot-ppl-dirs := $(patsubst %/,%,$(filter %/, $(libs-y)))
  31. libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
  32. u-boot-ppl-init := $(head-y)
  33. u-boot-ppl-main := $(libs-y)
  34. # Linker Script
  35. # First test whether there's a linker-script for the specific stage defined...
  36. ifneq ($(CONFIG_PPL_LDSCRIPT),)
  37. # need to strip off double quotes
  38. LDSCRIPT := $(addprefix $(srctree)/,$(CONFIG_PPL_LDSCRIPT:"%"=%))
  39. endif
  40. ifeq ($(wildcard $(LDSCRIPT)),)
  41. LDSCRIPT := $(srctree)/board/$(BOARDDIR)/u-boot-ppl.lds
  42. endif
  43. ifeq ($(wildcard $(LDSCRIPT)),)
  44. LDSCRIPT := $(srctree)/$(CPUDIR)/u-boot-ppl.lds
  45. endif
  46. ifeq ($(wildcard $(LDSCRIPT)),)
  47. LDSCRIPT := $(srctree)/arch/$(ARCH)/cpu/u-boot-ppl.lds
  48. endif
  49. ifeq ($(wildcard $(LDSCRIPT)),)
  50. $(error could not find linker script)
  51. endif
  52. # Special flags for CPP when processing the linker script.
  53. # Pass the version down so we can handle backwards compatibility
  54. # on the fly.
  55. LDPPFLAGS += \
  56. -include $(srctree)/include/u-boot/u-boot.lds.h \
  57. -include $(objtree)/include/config.h \
  58. -DCPUDIR=$(CPUDIR) \
  59. $(shell $(LD) --version | \
  60. sed -ne 's/GNU ld version \([0-9][0-9]*\)\.\([0-9][0-9]*\).*/-DLD_MAJOR=\1 -DLD_MINOR=\2/p')
  61. # Turn various CONFIG symbols into IMAGE symbols for easy reuse of
  62. # the scripts between SPL and TPL.
  63. ifneq ($(CONFIG_PPL_MAX_SIZE),)
  64. LDPPFLAGS += -DIMAGE_MAX_SIZE=$(CONFIG_PPL_MAX_SIZE)
  65. endif
  66. ifneq ($(CONFIG_PPL_TEXT_BASE),)
  67. LDPPFLAGS += -DIMAGE_TEXT_BASE=$(CONFIG_PPL_TEXT_BASE)
  68. endif
  69. MKIMAGEOUTPUT ?= /dev/null
  70. quiet_cmd_mkimage = MKIMAGE $@
  71. cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \
  72. >$(MKIMAGEOUTPUT) $(if $(KBUILD_VERBOSE:0=), && cat $(MKIMAGEOUTPUT))
  73. ALL-y += $(obj)/u-boot-ppl.bin
  74. all: $(ALL-y)
  75. quiet_cmd_cat = CAT $@
  76. cmd_cat = cat $(filter-out $(PHONY), $^) > $@
  77. quiet_cmd_copy = COPY $@
  78. cmd_copy = cp $< $@
  79. $(obj)/u-boot-ppl.bin: $(obj)/u-boot-ppl-nodtb.bin FORCE
  80. $(call if_changed,copy)
  81. quiet_cmd_objcopy = OBJCOPY $@
  82. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  83. OBJCOPYFLAGS_u-boot-ppl-nodtb.bin = $(PPL_OBJCFLAGS) -O binary
  84. $(obj)/u-boot-ppl-nodtb.bin: $(obj)/u-boot-ppl FORCE
  85. $(call if_changed,objcopy)
  86. LDFLAGS_u-boot-ppl += -T u-boot-ppl.lds $(LDFLAGS_FINAL)
  87. # Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
  88. LDFLAGS_u-boot-ppl += $(call ld-option, --no-dynamic-linker)
  89. # Pick the best-match (i.e. SPL_TEXT_BASE for SPL, TPL_TEXT_BASE for TPL)
  90. ifneq ($(CONFIG_PPL_TEXT_BASE),)
  91. LDFLAGS_u-boot-ppl += -Ttext $(CONFIG_PPL_TEXT_BASE)
  92. endif
  93. # Rule to link u-boot-ppl
  94. # May be overridden by arch/$(ARCH)/config.mk
  95. quiet_cmd_u-boot-ppl ?= LD $@
  96. cmd_u-boot-ppl ?= (cd $(obj) && $(LD) $(LDFLAGS) $(LDFLAGS_$(@F)) \
  97. $(patsubst $(obj)/%,%,$(u-boot-ppl-init)) --start-group \
  98. $(patsubst $(obj)/%,%,$(u-boot-ppl-main)) \
  99. --end-group \
  100. $(PLATFORM_LIBS) -Map u-boot-ppl.map -o u-boot-ppl)
  101. $(obj)/u-boot-ppl: $(u-boot-ppl-init) \
  102. $(u-boot-ppl-main) $(obj)/u-boot-ppl.lds FORCE
  103. $(call if_changed,u-boot-ppl)
  104. $(sort $(u-boot-ppl-init) $(u-boot-ppl-main)): $(u-boot-ppl-dirs) ;
  105. PHONY += $(u-boot-ppl-dirs)
  106. $(u-boot-ppl-dirs):
  107. $(Q)$(MAKE) $(build)=$@
  108. quiet_cmd_cpp_lds = LDS $@
  109. cmd_cpp_lds = $(CPP) -Wp,-MD,$(depfile) $(cpp_flags) $(LDPPFLAGS) -ansi \
  110. -D__ASSEMBLY__ -x assembler-with-cpp -std=c99 -P -o $@ $<
  111. $(obj)/u-boot-ppl.lds: $(LDSCRIPT) FORCE
  112. $(call if_changed_dep,cpp_lds)
  113. # read all saved command lines
  114. targets := $(wildcard $(sort $(targets)))
  115. cmd_files := $(wildcard $(obj)/.*.cmd $(foreach f,$(targets),$(dir $(f)).$(notdir $(f)).cmd))
  116. ifneq ($(cmd_files),)
  117. $(cmd_files): ; # Do not try to update included dependency files
  118. include $(cmd_files)
  119. endif
  120. PHONY += FORCE
  121. FORCE:
  122. # Declare the contents of the .PHONY variable as phony. We keep that
  123. # information in a variable so we can use it in if_changed and friends.
  124. .PHONY: $(PHONY)