blob: fba778391db1de3f243535aee27616c786aa1403 [file] [log] [blame]
Yann Gautierdbe63ac2022-03-16 19:03:20 +01001#
2# Copyright (c) 2023, STMicroelectronics - All Rights Reserved
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7# Compilation rules
8.PHONY: check_dtc_version stm32image clean_stm32image check_boot_device
9.SUFFIXES:
10
11all: check_dtc_version stm32image ${STM32_TF_STM32}
12
13distclean realclean clean: clean_stm32image
14
15bl2: check_boot_device
16
17check_boot_device:
Chris Kay1870c722024-05-02 17:52:37 +000018 $(q)if [ ${STM32MP_EMMC} != 1 ] && \
Yann Gautierdbe63ac2022-03-16 19:03:20 +010019 [ ${STM32MP_SDMMC} != 1 ] && \
20 [ ${STM32MP_RAW_NAND} != 1 ] && \
21 [ ${STM32MP_SPI_NAND} != 1 ] && \
22 [ ${STM32MP_SPI_NOR} != 1 ] && \
23 [ ${STM32MP_UART_PROGRAMMER} != 1 ] && \
24 [ ${STM32MP_USB_PROGRAMMER} != 1 ]; then \
25 echo "No boot device driver is enabled"; \
26 false; \
27 fi
28
29stm32image: ${STM32IMAGE}
30
31${STM32IMAGE}: ${STM32IMAGE_SRC}
Chris Kay1870c722024-05-02 17:52:37 +000032 $(q)${MAKE} CPPFLAGS="" --no-print-directory -C ${STM32IMAGEPATH}
Yann Gautierdbe63ac2022-03-16 19:03:20 +010033
34clean_stm32image:
Chris Kay1870c722024-05-02 17:52:37 +000035 $(q)${MAKE} --no-print-directory -C ${STM32IMAGEPATH} clean
Yann Gautierdbe63ac2022-03-16 19:03:20 +010036
37check_dtc_version:
Chris Kay1870c722024-05-02 17:52:37 +000038 $(q)if [ ${DTC_VERSION} -lt 10407 ]; then \
Yann Gautieraa039142023-03-02 11:20:44 +010039 echo "dtc version too old (${DTC_V}), you need at least version 1.4.7"; \
Yann Gautierdbe63ac2022-03-16 19:03:20 +010040 false; \
41 fi
42
43# Create DTB file for BL2
Chris Kay1559f642024-06-04 00:04:48 +000044${BUILD_PLAT}/fdts/%-bl2.dts: fdts/%.dts fdts/${BL2_DTSI} | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000045 $(q)echo '#include "$(patsubst fdts/%,%,$<)"' > $@
46 $(q)echo '#include "${BL2_DTSI}"' >> $@
Yann Gautierdbe63ac2022-03-16 19:03:20 +010047
48${BUILD_PLAT}/fdts/%-bl2.dtb: ${BUILD_PLAT}/fdts/%-bl2.dts
49
50${BUILD_PLAT}/$(PLAT)-%.o: ${BUILD_PLAT}/fdts/%-bl2.dtb $(STM32_BINARY_MAPPING) bl2
Chris Kay1870c722024-05-02 17:52:37 +000051 $(s)echo " AS $${PLAT}.S"
52 $(q)$($(ARCH)-as) -x assembler-with-cpp $(TF_CFLAGS_$(ARCH)) ${ASFLAGS} ${TF_CFLAGS} \
Yann Gautierdbe63ac2022-03-16 19:03:20 +010053 -DDTB_BIN_PATH=\"$<\" \
54 -c $(word 2,$^) -o $@
55
56$(eval $(call MAKE_LD,${STM32_TF_LINKERFILE},$(STM32_LD_FILE),bl2))
57
58tf-a-%.elf: $(PLAT)-%.o ${STM32_TF_LINKERFILE}
Chris Kay1870c722024-05-02 17:52:37 +000059 $(s)echo " LDS $<"
Chris Kaycfba6452023-12-04 09:55:50 +000060ifeq ($($(ARCH)-ld-id),gnu-gcc)
Chris Kay1870c722024-05-02 17:52:37 +000061 $(q)$($(ARCH)-ld) -o $@ $(subst --,-Wl$(comma)--,${STM32_TF_ELF_LDFLAGS}) -nostartfiles -Wl,-Map=$(@:.elf=.map) -Wl,-dT ${STM32_TF_LINKERFILE} $<
Yann Gautier6c6e6d02023-03-09 13:45:24 +010062else
Chris Kay1870c722024-05-02 17:52:37 +000063 $(q)$($(ARCH)-ld) -o $@ ${STM32_TF_ELF_LDFLAGS} -Map=$(@:.elf=.map) --script ${STM32_TF_LINKERFILE} $<
Yann Gautier6c6e6d02023-03-09 13:45:24 +010064endif
Yann Gautierdbe63ac2022-03-16 19:03:20 +010065
66tf-a-%.bin: tf-a-%.elf
Chris Kay1870c722024-05-02 17:52:37 +000067 $(q)$($(ARCH)-oc) -O binary $< $@
68 $(s)echo
69 $(s)echo "Built $@ successfully"
70 $(s)echo
Yann Gautierdbe63ac2022-03-16 19:03:20 +010071
72tf-a-%.stm32: tf-a-%.bin ${STM32_DEPS}
Chris Kay1870c722024-05-02 17:52:37 +000073 $(s)echo
74 $(s)echo "Generate $@"
Yann Gautier760a2d32023-09-20 15:12:26 +020075 $(eval LOADADDR = $(shell cat $(@:.stm32=.map) | grep '^RAM' | awk '{print $$2}'))
Yann Gautierdbe63ac2022-03-16 19:03:20 +010076 $(eval ENTRY = $(shell cat $(@:.stm32=.map) | grep "__BL2_IMAGE_START" | awk '{print $$1}'))
Chris Kay1870c722024-05-02 17:52:37 +000077 $(q)${STM32IMAGE} -s $< -d $@ \
Yann Gautierdbe63ac2022-03-16 19:03:20 +010078 -l $(LOADADDR) -e ${ENTRY} \
79 -v ${STM32_TF_VERSION} \
80 -m ${STM32_HEADER_VERSION_MAJOR} \
81 -n ${STM32_HEADER_VERSION_MINOR} \
82 -b ${STM32_HEADER_BL2_BINARY_TYPE}
Chris Kay1870c722024-05-02 17:52:37 +000083 $(s)echo