common_rules.mk 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #
  2. # Copyright (c) 2023-2024, STMicroelectronics - All Rights Reserved
  3. #
  4. # SPDX-License-Identifier: BSD-3-Clause
  5. #
  6. # Compilation rules
  7. .PHONY: check_dtc_version stm32image clean_stm32image check_boot_device
  8. all: check_dtc_version stm32image ${STM32_TF_STM32}
  9. distclean realclean clean: clean_stm32image
  10. bl2: check_boot_device
  11. check_boot_device:
  12. $(q)if [ ${STM32MP_EMMC} != 1 ] && \
  13. [ ${STM32MP_SDMMC} != 1 ] && \
  14. [ ${STM32MP_RAW_NAND} != 1 ] && \
  15. [ ${STM32MP_SPI_NAND} != 1 ] && \
  16. [ ${STM32MP_SPI_NOR} != 1 ] && \
  17. [ ${STM32MP_UART_PROGRAMMER} != 1 ] && \
  18. [ ${STM32MP_USB_PROGRAMMER} != 1 ]; then \
  19. echo "No boot device driver is enabled"; \
  20. false; \
  21. fi
  22. stm32image: ${STM32IMAGE}
  23. ${STM32IMAGE}: ${STM32IMAGE_SRC}
  24. $(q)${MAKE} CPPFLAGS="" --no-print-directory -C ${STM32IMAGEPATH}
  25. clean_stm32image:
  26. $(q)${MAKE} --no-print-directory -C ${STM32IMAGEPATH} clean
  27. check_dtc_version:
  28. $(q)if [ ${DTC_VERSION} -lt 10407 ]; then \
  29. echo "dtc version too old (${DTC_V}), you need at least version 1.4.7"; \
  30. false; \
  31. fi
  32. # Create DTB file for BL2
  33. ${BUILD_PLAT}/fdts/%-bl2.dts: fdts/%.dts fdts/${BL2_DTSI} | $$(@D)/
  34. $(q)echo '#include "$(patsubst fdts/%,%,$<)"' > $@
  35. $(q)echo '#include "${BL2_DTSI}"' >> $@
  36. ${BUILD_PLAT}/fdts/%-bl2.dtb: ${BUILD_PLAT}/fdts/%-bl2.dts
  37. ${BUILD_PLAT}/$(PLAT)-%.o: ${BUILD_PLAT}/fdts/%-bl2.dtb $(STM32_BINARY_MAPPING) bl2
  38. $(s)echo " AS $${PLAT}.S"
  39. $(q)$($(ARCH)-as) -x assembler-with-cpp $(TF_CFLAGS_$(ARCH)) ${ASFLAGS} ${TF_CFLAGS} \
  40. -DDTB_BIN_PATH=\"$<\" \
  41. -c $(word 2,$^) -o $@
  42. $(eval $(call MAKE_LD,${STM32_TF_LINKERFILE},$(STM32_LD_FILE),bl2))
  43. tf-a-%.elf: $(PLAT)-%.o ${STM32_TF_LINKERFILE}
  44. $(s)echo " LDS $<"
  45. ifeq ($($(ARCH)-ld-id),gnu-gcc)
  46. $(q)$($(ARCH)-ld) -o $@ $(subst --,-Wl$(comma)--,${STM32_TF_ELF_LDFLAGS}) -nostartfiles -no-pie -Wl,-Map=$(@:.elf=.map) -Wl,-dT ${STM32_TF_LINKERFILE} $<
  47. else
  48. $(q)$($(ARCH)-ld) -o $@ ${STM32_TF_ELF_LDFLAGS} -no-pie -Map=$(@:.elf=.map) --script ${STM32_TF_LINKERFILE} $<
  49. endif
  50. tf-a-%.bin: tf-a-%.elf
  51. $(q)$($(ARCH)-oc) -O binary $< $@
  52. $(s)echo
  53. $(s)echo "Built $@ successfully"
  54. $(s)echo
  55. tf-a-%.stm32: tf-a-%.bin ${STM32_DEPS}
  56. $(s)echo
  57. $(s)echo "Generate $@"
  58. $(eval LOADADDR = $(shell cat $(@:.stm32=.map) | grep '^RAM' | awk '{print $$2}'))
  59. $(eval ENTRY = $(shell cat $(@:.stm32=.map) | grep "__BL2_IMAGE_START" | awk '{print $$1}'))
  60. $(q)${STM32IMAGE} -s $< -d $@ \
  61. -l $(LOADADDR) -e ${ENTRY} \
  62. -v ${STM32_TF_VERSION} \
  63. -m ${STM32_HEADER_VERSION_MAJOR} \
  64. -n ${STM32_HEADER_VERSION_MINOR} \
  65. -b ${STM32_HEADER_BL2_BINARY_TYPE}
  66. $(s)echo