-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile
executable file
·384 lines (322 loc) · 12.3 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# @file
#
# Copyright (c) 2020, Ampere Computing LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: ISC
#
# EDK2 Makefile
#
# Input ATF_SLIM
ifeq ("$(shell echo $(ATF_SLIM) | cut -c1-1)", "/")
ATF_SLIM_IMG = $(ATF_SLIM)
else
ATF_SLIM_IMG = $(PWD)/$(ATF_SLIM)
endif
# Input BOARD_SETTING
ifeq ("$(shell echo $(BOARD_SETTING) | cut -c1-1)", "/")
BOARD_SETTING_INPUT = $(BOARD_SETTING)
else
BOARD_SETTING_INPUT = $(PWD)/$(BOARD_SETTING)
endif
# Default Input variables
ATF_TBB ?= 1
DEBUG ?= 0
BOARD_NAME ?= jade
BOARD_NAME_UPPER := $(shell echo $(BOARD_NAME) | tr a-z A-Z)
BOARD_NAME_UPPER_FIRST_LETTER := $(shell echo $(BOARD_NAME) | sed 's/.*/\u&/')
# Directory variables
SCRIPTS_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
ROOT_DIR := $(shell dirname $(SCRIPTS_DIR))
EDK2_SRC_DIR := $(ROOT_DIR)/edk2
EDK2_NON_OSI_SRC_DIR := $(ROOT_DIR)/edk2-non-osi
EDK2_PLATFORMS_SRC_DIR := $(ROOT_DIR)/edk2-platforms
EDK2_PLATFORMS_PKG_DIR := $(EDK2_PLATFORMS_SRC_DIR)/Platform/Ampere/$(BOARD_NAME_UPPER_FIRST_LETTER)Pkg
ATF_TOOLS_DIR := $(SCRIPTS_DIR)/toolchain/atf-tools
COMPILER_DIR := $(SCRIPTS_DIR)/toolchain/ampere
IASL_DIR := $(SCRIPTS_DIR)/toolchain/iasl
export WORKSPACE := $(PWD)
# Input DEST_DIR
ifeq (, $(DEST_DIR))
OUTPUT_BIN_DIR = $(PWD)/BUILDS/$(BOARD_NAME)_$(BUILD_IMG_TYPE)_atf$(OUTPUT_VARIANT)_$(VER).$(BUILD)
else
ifeq ("$(shell echo $(DEST_DIR) | cut -c1-1)", "/")
OUTPUT_BIN_DIR = $(DEST_DIR)
else
OUTPUT_BIN_DIR = $(PWD)/$(DEST_DIR)
endif
endif
# Misc variables
EDK2_GCC_TAG := GCC5
CROSS_COMPILE_PREFIX := aarch64-ampere-linux-gnu-
AARCH64_TOOLS_DIR := $(COMPILER_DIR)/bin
export PATH := $(PATH):$(IASL_DIR):$(ATF_TOOLS_DIR)
NUM_THREADS := $(shell echo $$(( $(shell getconf _NPROCESSORS_ONLN) + $(shell getconf _NPROCESSORS_ONLN))))
ATF_REPO_URL := https://github.com/ARM-software/arm-trusted-firmware.git
export ATF_TOOLS_LIST := include/tools_share \nmake_helpers \ntools/cert_create \ntools/fiptool
IASL_VER = "20200110"
IASL_NAME = acpica-unix2-$(IASL_VER)
IASL_URL = "https://acpica.org/sites/acpica/files/$(IASL_NAME).tar.gz"
COMPILER_NAME = ampere-8.3.0-20191025-dynamic-nosysroot-crosstools.tar.xz
COMPILER_URL = https://cdn.amperecomputing.com/tools/compilers/cross/8.3.0/$(COMPILER_NAME)
IASL := iasl
FIPTOOL := fiptool
CERTTOOL := cert_create
NVGENCMD := python nvparam.py
# Build variant variables
ifeq ($(DEBUG),1)
BUILD_VARIANT = DEBUG
OUTPUT_VARIANT = _debug
else
BUILD_VARIANT = RELEASE
OUTPUT_VARIANT =
endif
ifeq ($(BUILD_LINUXBOOT),1)
LINUXBOOTPKG = Linuxboot
BUILD_IMG_TYPE = linuxboot
else
LINUXBOOTPKG =
BUILD_IMG_TYPE = tianocore
endif
BUILD_VARIANT_LOWER = $(shell echo $(BUILD_VARIANT) | tr A-Z a-z)
BUILD_VARIANT_UPPER_FIRST_LETTER = $(shell echo $(BUILD_VARIANT_LOWER) | sed 's/.*/\u&/')
GIT_VER = $(shell cd $(EDK2_PLATFORMS_SRC_DIR) && git describe --tags --dirty --long | grep ampere | grep -v dirty | cut -d \- -f 1 | cut -d \v -f 2)
# Input VER
VER ?= $(shell echo $(GIT_VER) | cut -d \. -f 1,2)
ifeq ($(VER),)
VER = 0.00
endif
# Input BUILD
BUILD ?= $(shell echo $(GIT_VER) | cut -d \. -f 3)
ifeq ($(BUILD),)
BUILD = 100
endif
MAJOR_VER = $(shell echo $(VER) | cut -d \. -f 1 )
MINOR_VER = $(shell echo $(VER) | cut -d \. -f 2 )
# File path variables
OUTPUT_IMAGE := $(OUTPUT_BIN_DIR)/$(BOARD_NAME)_$(BUILD_IMG_TYPE)_atf$(OUTPUT_VARIANT)_$(VER).$(BUILD).img
OUTPUT_CAPSULE := $(OUTPUT_BIN_DIR)/$(BOARD_NAME)_$(BUILD_IMG_TYPE)_atf$(OUTPUT_VARIANT)_$(VER).$(BUILD).cap
OUTPUT_FD_IMAGE := $(OUTPUT_BIN_DIR)/$(BOARD_NAME)_$(BUILD_IMG_TYPE)$(OUTPUT_VARIANT)_$(VER).$(BUILD).fd
OUTPUT_FD_SIGNED_IMAGE := $(OUTPUT_BIN_DIR)/$(BOARD_NAME)_$(BUILD_IMG_TYPE)$(OUTPUT_VARIANT)_$(VER).$(BUILD).fd.signed
OUTPUT_BST_TXT = $(OUTPUT_BIN_DIR)/$(BOARD_NAME)_board_setting.txt
OUTPUT_BST_BIN = $(OUTPUT_BIN_DIR)/$(BOARD_NAME)_board_setting.bin
DEFAULT_BOARD_SETTING = $(EDK2_PLATFORMS_SRC_DIR)/Platform/Ampere/$(BOARD_NAME_UPPER_FIRST_LETTER)Pkg/$(BOARD_NAME)_board_setting.txt
DBB_KEY := $(EDK2_PLATFORMS_SRC_DIR)/Platform/Ampere/$(BOARD_NAME_UPPER_FIRST_LETTER)Pkg/TestKeys/Dbb_AmpereTest.priv.pem
DBU_KEY := $(EDK2_PLATFORMS_SRC_DIR)/Platform/Ampere/$(BOARD_NAME_UPPER_FIRST_LETTER)Pkg/TestKeys/Dbu_AmpereTest.priv.pem
EDK2_ATF_SIGNED_IMAGE := $(WORKSPACE)/Build/$(BOARD_NAME_UPPER_FIRST_LETTER)/$(BOARD_NAME)_atfedk2.img.signed
EDK2_FV_DIR := $(WORKSPACE)/Build/$(BOARD_NAME_UPPER_FIRST_LETTER)/$(BUILD_VARIANT)_$(EDK2_GCC_TAG)/FV
EDK2_FD_IMAGE := $(EDK2_FV_DIR)/BL33_$(BOARD_NAME_UPPER)_UEFI.fd
ifeq ($(or $(shell $(CROSS_COMPILE)gcc --version | grep -v Ampere | grep aarch64),$(shell $(CROSS_COMPILE)gcc --version | grep Ampere | grep dynamic-nosysroot)),)
CROSS_COMPILE := $(AARCH64_TOOLS_DIR)/$(CROSS_COMPILE_PREFIX)
endif
# Targets
define HELP_MSG
Ampere EDK2 Tools
============================================================
Usage: make <Targets> [Options]
Options:
ATF_SLIM=<Path> : Path to atf.slim image
BOARD_SETTING=<Path> : Path to board_setting.[txt/bin]
- Default: $(BOARD_NAME)_board_setting.txt
BUILD=<Build> : Specify image build id
- Default: 100
DEST_DIR=<Path> : Path to output directory
- Default: $(PWD)/BUILDS
DEBUG=[0,1] : Enable debug build
- Default: 0
VER=<Major.Minor> : Specify image version
- Default: 0.0
Target:
endef
export HELP_MSG
## help : Print this help
.PHONY: help
help:
@echo "$$HELP_MSG"
@sed -ne '/@sed/!s/## / /p' $(MAKEFILE_LIST)
## all : Build all
.PHONY: all
all: tianocore_capsule linuxboot_img
## clean : Clean basetool and tianocore build
.PHONY: clean
clean: tianocore_basetools_clean tianocore_clean
## linuxboot_img : Linuxboot image
.PHONY: linuxboot_img
linuxboot_img:
@$(MAKE) tianocore_img BUILD_LINUXBOOT=1
_check_edk2_source:
@echo -n "Checking edk2..."
ifeq (, $(wildcard $(EDK2_SRC_DIR)))
$(error "$(EDK2_SRC_DIR) not found.")
else
@echo "OK"
endif
@echo -n "Checking edk2-platforms..."
ifeq (, $(wildcard $(EDK2_PLATFORMS_SRC_DIR)))
$(error "$(EDK2_PLATFORMS_SRC_DIR) not found.")
else
@echo "OK"
endif
_check_tools:
@echo -n "Checking openssl..."
ifeq (, $(shell which openssl))
$(error "Not Found. Please install to your system!")
else
@echo "OK"
endif
@echo -n "Checking git..."
ifeq (, $(shell which git))
$(error "Not Found. Please install to your system!")
else
@echo "OK"
endif
@echo -n "Checking cut..."
ifeq (, $(shell which cut))
$(error "Not Found. Please install to your system!")
else
@echo "OK"
endif
@echo -n "Checking sed..."
ifeq (, $(shell which sed))
$(error "Not Found. Please install to your system!")
else
@echo "OK"
endif
_check_compiler:
@echo -n "Checking compiler..."
ifneq ($(shell echo $(CROSS_COMPILE) | grep $(AARCH64_TOOLS_DIR)),)
ifeq ($(wildcard $(AARCH64_TOOLS_DIR)/$(CROSS_COMPILE_PREFIX)gcc),)
@echo "Not Found"
@echo "Downloading and setting Ampere compiler..."
@mkdir -p $(COMPILER_DIR)
@wget -O - -q $(COMPILER_URL) | tar xJf - -C $(COMPILER_DIR) --strip-components=1 --checkpoint=.100
else
@echo "OK default"
endif
else
@echo "OK external"
endif
@echo "$(shell $(CROSS_COMPILE)gcc --version | awk 'FNR == 1')"
_check_atf_tools:
@echo -n "Checking ATF Tools..."
ifneq (, $(and $(shell which $(CERTTOOL)),$(shell which $(FIPTOOL))))
@echo "OK"
else
ifneq (, $(and $(wildcard $(ATF_TOOLS_DIR)/$(CERTTOOL)),$(wildcard $(ATF_TOOLS_DIR)/$(FIPTOOL))))
@echo "OK"
else
@echo "Not Found"
@echo "Downloading and building atf tools..."
@mkdir -p $(SCRIPTS_DIR)/AtfTools
@cd $(SCRIPTS_DIR)/AtfTools && git init && git remote add origin -f $(ATF_REPO_URL) && git config core.sparseCheckout true
@echo -e $$ATF_TOOLS_LIST > $(SCRIPTS_DIR)/AtfTools/.git/info/sparse-checkout
@cd $(SCRIPTS_DIR)/AtfTools && git -C . checkout --track origin/master
@cd $(SCRIPTS_DIR)/AtfTools/tools/cert_create && $(MAKE) CRTTOOL=cert_create
@cd $(SCRIPTS_DIR)/AtfTools/tools/fiptool && $(MAKE) FIPTOOL=fiptool
@rm -rf $(ATF_TOOLS_DIR)
@mkdir -p $(ATF_TOOLS_DIR)
@cp $(SCRIPTS_DIR)/AtfTools/tools/cert_create/cert_create $(ATF_TOOLS_DIR)/$(CERTTOOL)
@cp $(SCRIPTS_DIR)/AtfTools/tools/fiptool/fiptool $(ATF_TOOLS_DIR)/$(FIPTOOL)
@rm -rf $(SCRIPTS_DIR)/AtfTools
endif
endif
_check_iasl:
@echo -n "Checking iasl..."
ifneq (, $(and $(shell which $(IASL)),$(shell $(IASL) -v | grep version | grep 20200110)))
@echo "OK"
else
ifneq (, $(wildcard $(IASL_DIR)/$(IASL)))
@echo "OK"
else
@echo "Not Found"
@echo "Downloading and building iasl..."
@rm -fr $(IASL_DIR)
@mkdir -p $(IASL_DIR)
@wget -O - -q $(IASL_URL) | tar xzf - -C $(SCRIPTS_DIR)
@$(MAKE) -C $(SCRIPTS_DIR)/$(IASL_NAME) -j $(NUM_THREADS)
@cp ${SCRIPTS_DIR}/${IASL_NAME}/generate/unix/bin/iasl $(IASL_DIR)/$(IASL)
@rm -rf $(SCRIPTS_DIR)/$(IASL_NAME)
endif
endif
_check_atf_slim:
@echo -n "Checking ATF_SLIM..."
ifeq ("$(suffix $(wildcard $(ATF_SLIM_IMG)))", ".slim")
@echo "OK"
else
$(error "ATF Slim is invalid")
endif
_check_board_setting:
@echo -n "Checking BOARD_SETTING..."
@mkdir -p $(OUTPUT_BIN_DIR)
ifeq ("$(suffix $(wildcard $(BOARD_SETTING_INPUT)))",".bin")
@cp $(BOARD_SETTING_INPUT) $(OUTPUT_BST_BIN)
@echo "OK"
else
ifeq ("$(suffix $(wildcard $(BOARD_SETTING_INPUT)))",".txt")
@cp $(BOARD_SETTING_INPUT) $(OUTPUT_BST_TXT)
else
@cp $(DEFAULT_BOARD_SETTING) $(OUTPUT_BST_TXT)
endif
@echo "Generate board setting..."
$(NVGENCMD) -f $(OUTPUT_BST_TXT) -o $(OUTPUT_BST_BIN)
@rm -r $(OUTPUT_BIN_DIR)/$(BOARD_NAME)_board_setting.bin.padded
endif
_tianocore_prepare: _check_edk2_source _check_tools _check_iasl _check_compiler
ifeq (, $(wildcard $(EDK2_SRC_DIR)/BaseTools/Source/C/bin))
@echo "Build Tianocore Basetools..."
$(MAKE) -C $(EDK2_SRC_DIR)/BaseTools
endif
$(eval export PACKAGES_PATH = $(EDK2_SRC_DIR):$(EDK2_PLATFORMS_SRC_DIR):$(EDK2_NON_OSI_SRC_DIR))
$(eval export $(EDK2_GCC_TAG)_AARCH64_PREFIX = $(CROSS_COMPILE))
_tianocore_sign_fd: _check_atf_tools
@echo "Creating certitficate for $(OUTPUT_FD_IMAGE)"
@$(CERTTOOL) -n --ntfw-nvctr 0 --key-alg rsa --nt-fw-key $(DBB_KEY) --nt-fw-cert $(OUTPUT_FD_IMAGE).crt --nt-fw $(OUTPUT_FD_IMAGE)
@$(FIPTOOL) create --nt-fw-cert $(OUTPUT_FD_IMAGE).crt --nt-fw $(OUTPUT_FD_IMAGE) $(OUTPUT_FD_SIGNED_IMAGE)
@rm $(OUTPUT_FD_IMAGE).crt
## tianocore_fd : Tianocore FD image
.PHONY: tianocore_fd
tianocore_fd: _tianocore_prepare
@echo "Build Tianocore $(BUILD_VARIANT_UPPER_FIRST_LETTER) FD..."
. $(EDK2_SRC_DIR)/edksetup.sh && build -a AARCH64 -t $(EDK2_GCC_TAG) -b $(BUILD_VARIANT) -n $(NUM_THREADS) \
-D FIRMWARE_VER="$(MAJOR_VER).$(MINOR_VER).$(BUILD) Build $(shell date '+%Y%m%d')" \
-D MAJOR_VER=$(MAJOR_VER) \
-D MINOR_VER=$(MINOR_VER) \
-D SECURE_BOOT_ENABLE \
-p Platform/Ampere/$(BOARD_NAME_UPPER_FIRST_LETTER)Pkg/$(BOARD_NAME_UPPER_FIRST_LETTER)$(LINUXBOOTPKG).dsc
@mkdir -p $(OUTPUT_BIN_DIR)
@cp -f $(EDK2_FD_IMAGE) $(OUTPUT_FD_IMAGE)
## tianocore_img : Tianocore Integrated image
.PHONY: tianocore_img
tianocore_img: _check_atf_slim _check_board_setting tianocore_fd
@echo "Build Tianocore $(BUILD_VARIANT_UPPER_FIRST_LETTER) Image.."
@dd bs=1024 count=2048 if=/dev/zero | tr "\000" "\377" > $(OUTPUT_IMAGE)
@dd bs=1 conv=notrunc if=$(ATF_SLIM_IMG) of=$(OUTPUT_IMAGE)
@dd bs=1 seek=2031616 conv=notrunc if=$(OUTPUT_BST_BIN) of=$(OUTPUT_IMAGE)
ifeq ($(ATF_TBB),1)
@$(MAKE) _tianocore_sign_fd
@dd bs=1024 seek=2048 if=$(OUTPUT_FD_SIGNED_IMAGE) of=$(OUTPUT_IMAGE)
@rm $(OUTPUT_FD_SIGNED_IMAGE)
else
dd bs=1024 seek=2048 if=$(OUTPUT_FD_IMAGE) of=$(OUTPUT_IMAGE)
endif
## tianocore_capsule : Tianocore Capsule image
.PHONY: tianocore_capsule
tianocore_capsule: tianocore_img
@echo "Build Tianocore $(BUILD_VARIANT_UPPER_FIRST_LETTER) Capsule..."
@echo "Sign Tianocore Image"
@openssl dgst -sha256 -sign $(DBU_KEY) -out $(OUTPUT_IMAGE).sig $(OUTPUT_IMAGE)
@cat $(OUTPUT_IMAGE).sig $(OUTPUT_IMAGE) > $(OUTPUT_IMAGE).signed
@cp -f $(OUTPUT_IMAGE).signed $(EDK2_ATF_SIGNED_IMAGE)
@echo "Build Capsule Image"
. $(EDK2_SRC_DIR)/edksetup.sh && build -a AARCH64 -t $(EDK2_GCC_TAG) -b $(BUILD_VARIANT) \
-p Platform/Ampere/$(BOARD_NAME_UPPER_FIRST_LETTER)Pkg/$(BOARD_NAME_UPPER_FIRST_LETTER)Capsule.dsc
@cp -f $(EDK2_FV_DIR)/JADEFIRMWAREUPDATECAPSULEFMPPKCS7.Cap $(OUTPUT_CAPSULE)
@rm $(OUTPUT_IMAGE).sig $(OUTPUT_IMAGE).signed
.PHONY: tianocore_basetools_clean
tianocore_basetools_clean:
@echo "Tianocore clean BaseTools..."
$(MAKE) -C $(EDK2_SRC_DIR)/BaseTools clean
.PHONY: tianocore_clean
tianocore_clean:
@echo "Tianocore clean..."
@rm -rf $(WORKSPACE)/Build
# end of makefile