-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
213 lines (170 loc) · 6.43 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
.PHONY: FORCE
# Default goal is build all images
.DEFAULT_GOAL := all
# Avoid any implicit propagation of command line variable definitions to
# sub-Makefiles, like CFLAGS that we reserved for the firmware images'
# usage. Other command line options like "-s" are still propagated as usual.
MAKEOVERRIDES =
S := $(shell printf '\033[1;34;40m MAKECMDGOALS %s \033[0m\n' '${MAKECMDGOALS}')
$(info ${S})
ARCH ?=
ifneq ($(origin CROSS_COMPILE),command line)
ifeq ($(ARCH),riscv)
CROSS_COMPILE := ${CROSS_COMPILE_GLIBC_RISCV64}
BOOT_CPU ?= riscv
else
CROSS_COMPILE := ${CROSS_COMPILE_64}
BOOT_CPU := aarch64
ARCH := aarch64
endif
endif
ifeq (${CHIP_ARCH},)
$(error CHIP_ARCH is undefined)
endif
ifeq (${CROSS_COMPILE},)
$(error CROSS_COMPILE is undefined)
endif
ifeq (${FREE_RAM_SIZE},)
$(error FREE_RAM_SIZE is undefined)
endif
################################################################################
# Default values for build configurations, and their dependencies
################################################################################
MAKE_HELPERS_DIRECTORY := make_helpers/
V ?= 1
DEBUG := 0
LOG_LEVEL := 2
ENABLE_ASSERTIONS := 1
PRINTF_TIMESTAMP := 0
NANDBOOT_V2 := 1
# Verbose flag
ifeq (${V},0)
Q:=@
else
Q:=
endif
export Q
PRINTABLE := abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
PRINTABLE_TR := v1JfTUIeqdsE7P0oiczuVbW9aLnOFySG5YtDQ3lHN4rRpZABwmkCg2XhjM6x8K
CHIP_ARCH := $(shell echo '${CHIP_ARCH}' | tr A-Z a-z)
CHIP_ARCH_ALT := $(shell echo '${CHIP_ARCH}' | tr '${PRINTABLE}' '${PRINTABLE_TR}')
BUILD_BASE := ./build
O ?= ${BUILD_BASE}/${CHIP_ARCH}
BUILD_PLAT = ${O}
BUILD_STRING := g$(shell git rev-parse --short HEAD 2> /dev/null)
BUILD_STRING := ${BUILD_STRING}$(shell if git diff-index --name-only HEAD | grep -q "."; then echo -dirty; fi)
VERSION_STRING := ${CHIP_ARCH_ALT}:${BUILD_STRING}
################################################################################
# Toolchain
################################################################################
HOSTCC := gcc
export HOSTCC
CC := ${CROSS_COMPILE}gcc
CPP := ${CROSS_COMPILE}cpp
AS := ${CROSS_COMPILE}gcc
AR := ${CROSS_COMPILE}ar
LD := ${CROSS_COMPILE}ld
OC := ${CROSS_COMPILE}objcopy
OD := ${CROSS_COMPILE}objdump
NM := ${CROSS_COMPILE}nm
PP := ${CROSS_COMPILE}gcc -E
READELF := ${CROSS_COMPILE}readelf
GDB := ${CROSS_COMPILE}gdb
################################################################################
# Generic definitions
################################################################################
include ${MAKE_HELPERS_DIRECTORY}unix.mk
include ${MAKE_HELPERS_DIRECTORY}build_macros.mk
include ${MAKE_HELPERS_DIRECTORY}plat_helpers.mk
################################################################################
# Common sources and include directories
################################################################################
include lib/stdlib/stdlib.mk
################################################################################
# Convert building option
################################################################################
FSBL_SECURE_BOOT_SUPPORT := $(call yn10,${FSBL_SECURE_BOOT_SUPPORT})
################################################################################
# CPU and platform
################################################################################
$(call print_var,CHIP_ARCH)
$(call print_var,BOOT_CPU)
include ${PLAT_MAKEFILE_FULL}
# Check CPU define
$(eval $(call add_define,$(shell echo '${BOOT_CPU}' | tr a-z A-Z)))
ifeq (${BOOT_CPU},aarch64)
else ifeq (${BOOT_CPU},riscv)
else
$(error "BOOT_CPU=${BOOT_CPU} is not supported")
endif
CPPFLAGS += \
${DEFINES} ${INCLUDES} \
-nostdinc \
-Wmissing-include-dirs -Werror
TF_CFLAGS += -ggdb3 -gdwarf-2
ASFLAGS += -g -Wa,--gdwarf-2
# Include the CPU specific operations makefile
include lib/cpu/${BOOT_CPU}/cpu.mk
INCLUDES += -Ibuild
INCLUDES += -Iinclude/cpu
################################################################################
# Build options checks
################################################################################
$(eval $(call assert_boolean,DEBUG))
$(eval $(call assert_boolean,ENABLE_ASSERTIONS))
$(eval $(call assert_boolean,NANDBOOT_V2))
$(eval $(call assert_boolean,NANDBOOT_V2))
$(eval $(call assert_boolean,PAGE_SIZE_64KB))
$(eval $(call assert_boolean,TEST_FROM_SPINOR1))
$(eval $(call assert_boolean,PRINTF_TIMESTAMP))
################################################################################
# Add definitions to the cpp preprocessor based on the current build options.
# This is done after including the platform specific makefile to allow the
# platform to overwrite the default options
################################################################################
$(call print_var,TEST_FROM_SPINOR1)
$(call print_var,PAGE_SIZE_64KB)
$(eval $(call add_define,TEST_FROM_SPINOR1))
$(eval $(call add_define,PAGE_SIZE_64KB))
$(eval $(call add_define,PRINTF_TIMESTAMP))
$(eval $(call add_define,ENABLE_ASSERTIONS))
$(eval $(call add_define,LOG_LEVEL))
$(eval $(call add_define,__CVITEK__))
$(eval $(call add_define,NANDBOOT_V2))
ifeq (${BOOT_CPU},riscv)
$(eval $(call add_define_val,TOC_HEADER_NAME,0xC906B001))
else
$(eval $(call add_define_val,TOC_HEADER_NAME,0xAA640001))
endif
ifeq (${FREE_RAM_SIZE},64MB)
$(eval $(call add_define_val,CVI_BUILDROOT_64MB,1))
else
$(eval $(call add_define_val,CVI_BUILDROOT_ION,1))
endif
ifeq (${RTOS_ENABLE_FREERTOS},y)
$(eval $(call add_define,RTOS_ENABLE_FREERTOS))
$(eval $(call add_define_val,RTOS_DUMP_PRINT_SZ_IDX,${RTOS_DUMP_PRINT_SZ_IDX}))
$(eval $(call add_define_val,RTOS_FAST_IMAGE_TYPE,${RTOS_FAST_IMAGE_TYPE}))
$(eval $(call add_define_val,RTOS_DUMP_PRINT_ENABLE,$(call yn10,${RTOS_DUMP_PRINT_ENABLE})))
endif
ifeq ($(OD_CLK_SEL),y)
$(eval $(call add_define,OD_CLK_SEL))
endif
$(eval $(call add_define,FSBL_SECURE_BOOT_SUPPORT))
$(eval $(call add_define, USB_DL_BY_FSBL))
################################################################################
# Build targets
################################################################################
.PHONY: all fip clean bl-check bl-build fake-blcp
.SUFFIXES:
export BUILD_PLAT NM
all: fip bl2 blmacros
include ${MAKE_HELPERS_DIRECTORY}fip.mk
$(eval $(call MAKE_BL,2))
# Convert '#define ...' to ELF symbols
BLMACROS_LINKERFILE := make_helpers/get_macros.ld.S
BLMACROS_ELF := ${BUILD_PLAT}/blmacros/blmacros.elf
$(eval $(call MAKE_BL,macros))
clean:
$(print_target)
$(call SHELL_REMOVE_DIR,${BUILD_PLAT})