top.mk 5.7 KB
Newer Older
1
2
3
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright (C) Arm Limited, 2020
4
5
6
7
8
9
10
11
12
13
#
# Makefile Conventions:
# Variable names:
# TARGET:   U-Boot configuration name; TFA, OP-TEE, and other target
#           configuration names key off the U-Boot configuration; this is a
#           U-Boot oriented tool after all.
# *_PATH:   Full path to project source directories or other assets
# *_OUTPUT: Build directories for each of the sub projects
# *_EXTRA:  Extra parameters to the make call. Gets added to make targets, e.g.
#           "$(MAKE) -C ${PROJECT_PATH} ... ${PROJECT_EXTRA} ..."
14

15
16
17
ifndef TARGET
  $(error TARGET is not set)
endif
18
19

# Set some defaults that can be overridden by the target  makefile include
20
export DT_PATH    := $(CURDIR)/devicetree-rebasing
21
export DT_OUTPUT  := $(DT_PATH)
22
export TFA_PATH   := $(CURDIR)/trusted-firmware-a
23
export UBOOT_PATH := $(CURDIR)/u-boot
24
25
26
27
28
29
30
31
32
33
34
35

# Give the option of building in a separate directory
ifdef BUILD_OUTPUT
  __BUILD := $(realpath $(BUILD_OUTPUT))
  export TFA_OUTPUT := $(__BUILD)/tfa
  export TFA_EXTRA += BUILD_BASE=$(TFA_OUTPUT)
  export UBOOT_OUTPUT := $(__BUILD)/u-boot
  export UBOOT_EXTRA += KBUILD_OUTPUT=$(UBOOT_OUTPUT)
else
  export TFA_OUTPUT := $(TFA_PATH)/build
  export UBOOT_OUTPUT := $(UBOOT_PATH)
endif
36

37
38
# ===========================================================================
# Rules shared between *config targets and build targets
39

40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# To make sure we do not include .config for any of the *config targets
# catch them early
# It is allowed to specify more targets when calling make, including
# mixing *config targets and build targets.
# For example 'make oldconfig all'.
# Detect when mixed targets is specified, and make a second invocation
# of make so .config is not included in this case either (for *config).

no-dot-config-targets := clean

config-targets := 0
mixed-targets  := 0
dot-config     := 1

ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
		dot-config := 0
	endif
endif

ifneq ($(filter %config,$(MAKECMDGOALS)),)
        config-targets := 1
        ifneq ($(words $(MAKECMDGOALS)),1)
                mixed-targets := 1
        endif
endif

ifeq ($(mixed-targets),1)
# ===========================================================================
# We're called with mixed targets (*config and build targets).
# Handle them one by one.
PHONY += $(MAKECMDGOALS) __build_one_by_one

$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
	@:
75

76
77
78
79
80
81
82
83
84
85
86
87
88
__build_one_by_one:
	$(Q)set -e; \
	for i in $(MAKECMDGOALS); do \
		$(MAKE) $$i; \
	done

else
ifeq ($(config-targets),1)
# ===========================================================================
# *config targets only - make sure prerequisites are updated, and descend
# in scripts/kconfig to make the *config target

%config: u-boot/%config
89
90
91
92
93
	echo CONFIG_CMD_BOOTEFI_HELLO=y >> $(UBOOT_OUTPUT)/.config
	echo CONFIG_CMD_BOOTEFI_SELFTEST=y >> $(UBOOT_OUTPUT)/.config
	echo CONFIG_CMD_NVEDIT_EFI=y >> $(UBOOT_OUTPUT)/.config
	echo CONFIG_CMD_EFIDEBUG=y >> $(UBOOT_OUTPUT)/.config
	echo CONFIG_CMD_GPT=y >> $(UBOOT_OUTPUT)/.config
94
	$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) olddefconfig
95

96
97
98
99
100
101
102
103
104
105
PHONY += defconfig
defconfig: ${TARGET}_defconfig ;

else
# ===========================================================================
# Build targets only
# In general all targets that make use of the selected configuration

ifeq ($(dot-config),1)
# Read in config
106
include $(UBOOT_OUTPUT)/.config
107
108
109

# ===================================
# Platform/SOC specific configuration
110
111
112
113
114
115
116
117
#
# Try including platform specific configs
# Platform specific config could be SOC, Vendor, or config

-include $(CURDIR)/scripts/vendor-$(subst ",,$(CONFIG_SYS_VENDOR)).mk
-include $(CURDIR)/scripts/soc-$(subst ",,$(CONFIG_SYS_SOC)).mk
-include $(CURDIR)/scripts/board-$(subst ",,$(CONFIG_SYS_BOARD)).mk
-include $(CURDIR)/scripts/config-$(subst ",,$(CONFIG_SYS_CONFIG_NAME)).mk
118
119

ifndef TFA_PLAT
120
121
122
123
  $(info CONFIG_SYS_VENDOR=$(CONFIG_SYS_VENDOR))
  $(info CONFIG_SYS_SOC=$(CONFIG_SYS_SOC))
  $(info CONFIG_SYS_BOARD=$(CONFIG_SYS_BOARD))
  $(info CONFIG_SYS_CONFIG_NAME=$(CONFIG_SYS_CONFIG_NAME))
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
  $(warning TFA_PLAT is not set. Either TARGET=$(TARGET) is not yet supported)
  $(error by this tool, or there is a bug)
endif

TFA_EXTRA += PLAT=$(TFA_PLAT)
TFA_EXTRA += LOG_LEVEL=20
TFA_EXTRA += BL33=$(UBOOT_OUTPUT)/u-boot.bin

FLASH_IMAGE ?= $(TFA_OUTPUT)/$(TFA_PLAT)/release/flash-image.bin
FLASH_IMAGE_DEPS ?= tfa/all tfa/fip
SD_IMAGE := $(TARGET)-sdcard.img
ESP_SIZE ?= $$((64*1024*1024))
ESP_OFFSET ?= $$((4*1024*1024))

endif # ifeq ($(dot-config),1)

PHONY += dtb
dtb: ${DTB_TARGET}
	fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / u-boot-ver `cd ${UBOOT_PATH} && git describe`
	fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / tfa-ver `cd ${TFA_PATH} && git describe`
	fdtput ${DT_OUTPUT}/${DTB_TARGET} -t s / dt-ver `cd ${DT_PATH} && git describe`

PHONY += flashimage sdimage

flashimage ${FLASH_IMAGE}: ${FLASH_IMAGE_DEPS}

sdimage: flashimage

PHONY += clean
clean: u-boot/mrproper
	cd $(TFA_PATH) && git clean -fdx
	cd $(DT_PATH) && git clean -fdx
	cd $(CURDIR)/mv-ddr && git clean -fdx

endif #ifeq ($(config-targets),1)

# ===========================================================================
# Common targets - Mostly delegates to the individual project build systems

# ================================================
# Delegate to devicetree-rebasing build
devicetree-rebasing/%.dtb:
	${MAKE} -C ${DT_PATH} $*.dtb

# ================================================
# Delegate to trusted-firmware-a build
tfa/%:
	${MAKE} -C ${TFA_PATH} ${TFA_EXTRA} $*

tfa/fip: u-boot/all

# ================================================
# Delegate to u-boot build
u-boot/%:
	$(MAKE) -C $(UBOOT_PATH) $(UBOOT_EXTRA) $*

endif #ifeq ($(mixed-targets),1)
181