common_rules.mk 2.5 KB

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