blob: f39caab82c5ecb1ed9f397f813916d3200445f84 [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:
18 @if [ ${STM32MP_EMMC} != 1 ] && \
19 [ ${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}
32 ${Q}${MAKE} CPPFLAGS="" --no-print-directory -C ${STM32IMAGEPATH}
33
34clean_stm32image:
35 ${Q}${MAKE} --no-print-directory -C ${STM32IMAGEPATH} clean
36
37check_dtc_version:
Yann Gautieraa039142023-03-02 11:20:44 +010038 @if [ ${DTC_VERSION} -lt 10407 ]; then \
39 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
44${BUILD_PLAT}/fdts/%-bl2.dts: fdts/%.dts fdts/${BL2_DTSI} | ${BUILD_PLAT} fdt_dirs
45 @echo '#include "$(patsubst fdts/%,%,$<)"' > $@
46 @echo '#include "${BL2_DTSI}"' >> $@
47
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
51 @echo " AS $${PLAT}.S"
52 ${Q}${AS} ${ASFLAGS} ${TF_CFLAGS} \
53 -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}
59 @echo " LDS $<"
Yann Gautier6c6e6d02023-03-09 13:45:24 +010060ifneq ($(findstring gcc,$(notdir $(LD))),)
61 ${Q}${LD} -o $@ $(subst --,-Wl$(comma)--,${STM32_TF_ELF_LDFLAGS}) -nostartfiles -Wl,-Map=$(@:.elf=.map) -Wl,-dT ${STM32_TF_LINKERFILE} $<
62else
Yann Gautierdbe63ac2022-03-16 19:03:20 +010063 ${Q}${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
67 ${Q}${OC} -O binary $< $@
68 @echo
69 @echo "Built $@ successfully"
70 @echo
71
72tf-a-%.stm32: tf-a-%.bin ${STM32_DEPS}
73 @echo
74 @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}'))
77 ${Q}${STM32IMAGE} -s $< -d $@ \
78 -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}
83 @echo