blob: 39f9e5328272052adc7f7c116ac0ee2d90d57498 [file] [log] [blame]
Victor Chongbadc7922015-12-08 17:23:20 +00001################################################################################
2# User-defined variables
3# Edit so these match your target
Victor Chong13cad772015-12-05 00:35:19 +09004# NOTE: If making changes after a build, please clean before rebuilding!
Victor Chongbadc7922015-12-08 17:23:20 +00005################################################################################
6# Non-secure user mode (root fs binaries): 32 or 64-bit [default 64]
Victor Chong24475982015-12-02 07:18:13 +00007NSU ?= 64
Victor Chongbadc7922015-12-08 17:23:20 +00008# Secure kernel (OP-TEE OS): 32 or 64-bit [default 64]
Victor Chong24475982015-12-02 07:18:13 +00009SK ?= 64
Victor Chongbadc7922015-12-08 17:23:20 +000010# Secure user mode (Trusted Apps): 32 or 64-bit [default 32, requires SK=64 for 64]
11SU ?= 32
Victor Chong24475982015-12-02 07:18:13 +000012
Victor Chong13cad772015-12-05 00:35:19 +090013# Normal/secure world console UARTs: 3 or 0 [default 3]
14CFG_NW_CONSOLE_UART ?= 3
15CFG_SW_CONSOLE_UART ?= 3
16
Victor Chongbadc7922015-12-08 17:23:20 +000017################################################################################
18# Includes
19################################################################################
Pascal Brandd6536da2015-09-01 10:38:43 +020020-include common.mk
21
22################################################################################
23# Mandatory definition to use common.mk
24################################################################################
Victor Chongbadc7922015-12-08 17:23:20 +000025ifeq ($(SK),32)
26ifeq ($(SU),64)
27$(error 64-bit secure user mode requires 64-bit secure kernel, i.e. SK=64)
28endif
29endif
30
Victor Chong24475982015-12-02 07:18:13 +000031ifeq ($(NSU),64)
Pascal Brandd6536da2015-09-01 10:38:43 +020032CROSS_COMPILE_NS_USER ?= "$(CCACHE)$(AARCH64_CROSS_COMPILE)"
Victor Chong24475982015-12-02 07:18:13 +000033MULTIARCH := aarch64-linux-gnu
34else
35CROSS_COMPILE_NS_USER ?= "$(CCACHE)$(AARCH32_CROSS_COMPILE)"
36MULTIARCH := arm-linux-gnueabihf
37endif
Pascal Brandd6536da2015-09-01 10:38:43 +020038CROSS_COMPILE_NS_KERNEL ?= "$(CCACHE)$(AARCH64_CROSS_COMPILE)"
Victor Chong24475982015-12-02 07:18:13 +000039ifeq ($(SU),64)
40CROSS_COMPILE_S_USER ?= "$(CCACHE)$(AARCH64_CROSS_COMPILE)"
41else
Pascal Brandd6536da2015-09-01 10:38:43 +020042CROSS_COMPILE_S_USER ?= "$(CCACHE)$(AARCH32_CROSS_COMPILE)"
Victor Chong24475982015-12-02 07:18:13 +000043endif
44ifeq ($(SK),64)
Pascal Brandd6536da2015-09-01 10:38:43 +020045CROSS_COMPILE_S_KERNEL ?= "$(CCACHE)$(AARCH64_CROSS_COMPILE)"
Victor Chong24475982015-12-02 07:18:13 +000046else
47CROSS_COMPILE_S_KERNEL ?= "$(CCACHE)$(AARCH32_CROSS_COMPILE)"
48endif
Pascal Brandd6536da2015-09-01 10:38:43 +020049OPTEE_OS_BIN ?= $(OPTEE_OS_PATH)/out/arm-plat-hikey/core/tee.bin
Victor Chongbadc7922015-12-08 17:23:20 +000050OPTEE_OS_TA_DEV_KIT_DIR ?= $(OPTEE_OS_PATH)/out/arm-plat-hikey/export-ta_arm$(SU)
Pascal Brandd6536da2015-09-01 10:38:43 +020051
Joakim Bech427dd632015-05-04 15:52:33 +020052################################################################################
53# Paths to git projects and various binaries
54################################################################################
55ARM_TF_PATH ?= $(ROOT)/arm-trusted-firmware
56ifeq ($(DEBUG),1)
57ARM_TF_BUILD ?= debug
58else
59ARM_TF_BUILD ?= release
Joakim Bech427dd632015-05-04 15:52:33 +020060endif
61
62EDK2_PATH ?= $(ROOT)/edk2
63ifeq ($(DEBUG),1)
64EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey/DEBUG_GCC49/FV/BL33_AP_UEFI.fd
65EDK2_BUILD ?= DEBUG
66else
67EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey/RELEASE_GCC49/FV/BL33_AP_UEFI.fd
68EDK2_BUILD ?= RELEASE
69endif
70
Victor Chong24475982015-12-02 07:18:13 +000071MCUIMAGE_BIN ?=$(EDK2_PATH)/HisiPkg/HiKeyPkg/NonFree/mcuimage.bin
Joakim Bech427dd632015-05-04 15:52:33 +020072STRACE_PATH ?=$(ROOT)/strace
73BOOT_IMG ?=$(ROOT)/out/boot-fat.uefi.img
74LLOADER_PATH ?=$(ROOT)/l-loader
Joakim Bech7f43b922015-10-01 07:24:00 -070075NVME_IMG ?=$(ROOT)/out/nvme.img
Victor Chong24475982015-12-02 07:18:13 +000076OUT_PATH ?=$(ROOT)/out
77GRUB_PATH ?=$(ROOT)/grub
78PATCHES_PATH ?=$(ROOT)/patches_hikey
79AESPERF_PATH ?=$(ROOT)/aes-perf
80SHAPERF_PATH ?=$(ROOT)/sha-perf
Joakim Bech427dd632015-05-04 15:52:33 +020081
82################################################################################
Joakim Bech427dd632015-05-04 15:52:33 +020083# Targets
84################################################################################
Victor Chong24475982015-12-02 07:18:13 +000085all: prepare arm-tf boot-img lloader nvme
Joakim Bech427dd632015-05-04 15:52:33 +020086
Victor Chong24475982015-12-02 07:18:13 +000087clean: arm-tf-clean busybox-clean edk2-clean linux-clean optee-os-clean optee-client-clean optee-linuxdriver-clean xtest-clean strace-clean update_rootfs-clean boot-img-clean lloader-clean aes-perf-clean sha-perf-clean grub-clean
Joakim Bech427dd632015-05-04 15:52:33 +020088
Victor Chong24475982015-12-02 07:18:13 +000089cleaner: clean prepare-cleaner busybox-cleaner linux-cleaner strace-cleaner nvme-cleaner grub-cleaner
Joakim Bech427dd632015-05-04 15:52:33 +020090
91-include toolchain.mk
92
Victor Chong24475982015-12-02 07:18:13 +000093prepare:
94 @if [ ! -d $(ROOT)/out ]; then mkdir $(ROOT)/out; fi
Joakim Bech427dd632015-05-04 15:52:33 +020095
Victor Chong24475982015-12-02 07:18:13 +000096.PHONY: prepare-cleaner
97prepare-cleaner:
98 rm -rf $(ROOT)/out
Joakim Bech427dd632015-05-04 15:52:33 +020099
100################################################################################
101# ARM Trusted Firmware
102################################################################################
Pascal Brandb130ea22015-10-13 13:18:36 +0200103ARM_TF_EXPORTS ?= \
Joakim Bech427dd632015-05-04 15:52:33 +0200104 CFLAGS="-O0 -gdwarf-2" \
Pascal Brandb130ea22015-10-13 13:18:36 +0200105 CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
106
107ARM_TF_FLAGS ?= \
Joakim Bech427dd632015-05-04 15:52:33 +0200108 BL32=$(OPTEE_OS_BIN) \
109 BL33=$(EDK2_BIN) \
Joakim Bech427dd632015-05-04 15:52:33 +0200110 BL30=$(MCUIMAGE_BIN) \
Pascal Brandb130ea22015-10-13 13:18:36 +0200111 DEBUG=$(DEBUG) \
112 PLAT=hikey \
113 SPD=opteed
Joakim Bech427dd632015-05-04 15:52:33 +0200114
Victor Chong13cad772015-12-05 00:35:19 +0900115ARM_TF_CONSOLE_UART ?= $(CFG_SW_CONSOLE_UART)
116ifeq ($(ARM_TF_CONSOLE_UART),0)
117 ARM_TF_FLAGS += CONSOLE_BASE=PL011_UART0_BASE \
118 CRASH_CONSOLE_BASE=PL011_UART0_BASE
119endif
120
Victor Chong24475982015-12-02 07:18:13 +0000121arm-tf: optee-os edk2
Pascal Brandb130ea22015-10-13 13:18:36 +0200122 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) all fip
123
Victor Chong24475982015-12-02 07:18:13 +0000124.PHONY: arm-tf-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200125arm-tf-clean:
Pascal Brandb130ea22015-10-13 13:18:36 +0200126 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) clean
Joakim Bech427dd632015-05-04 15:52:33 +0200127
128################################################################################
129# Busybox
Victor Chong24475982015-12-02 07:18:13 +0000130################################################################################
Pascal Brand440ef9c2015-09-08 16:01:58 +0200131BUSYBOX_COMMON_TARGET = hikey nocpio
132BUSYBOX_CLEAN_COMMON_TARGET = hikey clean
Victor Chong24475982015-12-02 07:18:13 +0000133ifeq ($(NSU),64)
Pascal Brand440ef9c2015-09-08 16:01:58 +0200134BUSYBOX_COMMON_CCDIR = $(AARCH64_PATH)
Victor Chong24475982015-12-02 07:18:13 +0000135else
136BUSYBOX_COMMON_CCDIR = $(AARCH32_PATH)
137endif
Joakim Bech427dd632015-05-04 15:52:33 +0200138
Pascal Brand440ef9c2015-09-08 16:01:58 +0200139busybox: busybox-common
Joakim Bech427dd632015-05-04 15:52:33 +0200140
Joakim Bech7f43b922015-10-01 07:24:00 -0700141.PHONY: busybox-clean
Pascal Brand440ef9c2015-09-08 16:01:58 +0200142busybox-clean: busybox-clean-common
143
Joakim Bech7f43b922015-10-01 07:24:00 -0700144.PHONY: busybox-cleaner
Victor Chong24475982015-12-02 07:18:13 +0000145busybox-cleaner: busybox-clean-common busybox-cleaner-common
Joakim Bech427dd632015-05-04 15:52:33 +0200146
147################################################################################
148# EDK2 / Tianocore
149################################################################################
Victor Chong13cad772015-12-05 00:35:19 +0900150EDK2_VARS ?= EDK2_ARCH=AARCH64 \
151 EDK2_DSC=HisiPkg/HiKeyPkg/HiKey.dsc \
152 EDK2_TOOLCHAIN=GCC49 \
153 EDK2_BUILD=$(EDK2_BUILD)
154
155EDK2_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
156ifeq ($(EDK2_CONSOLE_UART),0)
157 EDK2_VARS += EDK2_MACROS="-DSERIAL_BASE=0xF8015000"
158endif
159
Pascal Brand9a0f50f2015-09-08 15:34:17 +0200160define edk2-call
Joakim Bech427dd632015-05-04 15:52:33 +0200161 GCC49_AARCH64_PREFIX=$(AARCH64_CROSS_COMPILE) \
Pascal Brand9a0f50f2015-09-08 15:34:17 +0200162 $(MAKE) -j1 -C $(EDK2_PATH) \
Victor Chong13cad772015-12-05 00:35:19 +0900163 -f HisiPkg/HiKeyPkg/Makefile $(EDK2_VARS)
Joakim Bech427dd632015-05-04 15:52:33 +0200164endef
165
Pascal Brand9a0f50f2015-09-08 15:34:17 +0200166edk2: edk2-common
Joakim Bech427dd632015-05-04 15:52:33 +0200167
Joakim Bech7f43b922015-10-01 07:24:00 -0700168.PHONY: edk2-clean
Pascal Brand9a0f50f2015-09-08 15:34:17 +0200169edk2-clean: edk2-clean-common
Joakim Bech427dd632015-05-04 15:52:33 +0200170
171################################################################################
172# Linux kernel
173################################################################################
Jerome Forissiere1002382015-11-26 11:36:00 +0100174LINUX_DEFCONFIG_COMMON_ARCH ?= arm64
175LINUX_DEFCONFIG_COMMON_FILES ?= $(LINUX_PATH)/arch/arm64/configs/defconfig \
Victor Chong24475982015-12-02 07:18:13 +0000176 $(CURDIR)/kconfigs/hikey.conf \
177 $(PATCHES_PATH)/kernel_config/usb_net_dm9601.conf \
178 $(PATCHES_PATH)/kernel_config/ftrace.conf
Joakim Bech427dd632015-05-04 15:52:33 +0200179
180linux-defconfig: $(LINUX_PATH)/.config
181
182linux-gen_init_cpio: linux-defconfig
Victor Chong24475982015-12-02 07:18:13 +0000183 $(MAKE) -C $(LINUX_PATH)/usr \
Pascal Brande3d85982015-09-10 17:20:42 +0200184 CROSS_COMPILE=$(CROSS_COMPILE_NS_KERNEL) \
Joakim Bech427dd632015-05-04 15:52:33 +0200185 ARCH=arm64 \
186 LOCALVERSION= \
187 gen_init_cpio
188
Victor Chong24475982015-12-02 07:18:13 +0000189LINUX_COMMON_FLAGS += ARCH=arm64 Image modules
190UPSTREAM_KERNEL := $(if $(wildcard $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts),1,0)
191ifeq ($(UPSTREAM_KERNEL),0)
192LINUX_COMMON_FLAGS += hi6220-hikey.dtb
193DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hi6220-hikey.dtb
194else
195LINUX_COMMON_FLAGS += hisilicon/hi6220-hikey.dtb
196DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb
197endif
Joakim Bech427dd632015-05-04 15:52:33 +0200198
Pascal Brande3d85982015-09-10 17:20:42 +0200199linux: linux-common
200
Joakim Bech7f43b922015-10-01 07:24:00 -0700201.PHONY: linux-defconfig-clean
Pascal Brande3d85982015-09-10 17:20:42 +0200202linux-defconfig-clean: linux-defconfig-clean-common
Joakim Bech427dd632015-05-04 15:52:33 +0200203
Pascal Brande3d85982015-09-10 17:20:42 +0200204LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
Joakim Bech427dd632015-05-04 15:52:33 +0200205
Joakim Bech7f43b922015-10-01 07:24:00 -0700206.PHONY: linux-clean
Pascal Brande3d85982015-09-10 17:20:42 +0200207linux-clean: linux-clean-common
208
209LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
210
Joakim Bech7f43b922015-10-01 07:24:00 -0700211.PHONY: linux-cleaner
Pascal Brande3d85982015-09-10 17:20:42 +0200212linux-cleaner: linux-cleaner-common
Joakim Bech427dd632015-05-04 15:52:33 +0200213
214################################################################################
215# OP-TEE
216################################################################################
Victor Chong13cad772015-12-05 00:35:19 +0900217OPTEE_OS_COMMON_FLAGS += PLATFORM=hikey CFG_TEE_TA_LOG_LEVEL=3 CFG_CONSOLE_UART=$(CFG_SW_CONSOLE_UART)
218OPTEE_OS_CLEAN_COMMON_FLAGS += PLATFORM=hikey
219
Victor Chong24475982015-12-02 07:18:13 +0000220ifeq ($(SK),64)
221OPTEE_OS_COMMON_FLAGS += CFG_ARM64_core=y
222OPTEE_OS_CLEAN_COMMON_FLAGS += CFG_ARM64_core=y
223endif
224
Jerome Forissierae45fbf2015-09-04 09:40:17 +0200225optee-os: optee-os-common
Joakim Bech427dd632015-05-04 15:52:33 +0200226
Joakim Bech7f43b922015-10-01 07:24:00 -0700227.PHONY: optee-os-clean
Jerome Forissierae45fbf2015-09-04 09:40:17 +0200228optee-os-clean: optee-os-clean-common
Joakim Bech427dd632015-05-04 15:52:33 +0200229
Pascal Brand070d9552015-09-01 15:33:22 +0200230optee-client: optee-client-common
Jerome Forissierae45fbf2015-09-04 09:40:17 +0200231
Joakim Bech7f43b922015-10-01 07:24:00 -0700232.PHONY: optee-client-clean
Pascal Brand070d9552015-09-01 15:33:22 +0200233optee-client-clean: optee-client-clean-common
Jerome Forissierae45fbf2015-09-04 09:40:17 +0200234
235OPTEE_LINUXDRIVER_COMMON_FLAGS += ARCH=arm64
236optee-linuxdriver: optee-linuxdriver-common
237
238OPTEE_LINUXDRIVER_CLEAN_COMMON_FLAGS += ARCH=arm64
Joakim Bech7f43b922015-10-01 07:24:00 -0700239.PHONY: optee-linuxdriver-clean
Pascal Brand070d9552015-09-01 15:33:22 +0200240optee-linuxdriver-clean: optee-linuxdriver-clean-common
Joakim Bech427dd632015-05-04 15:52:33 +0200241
242################################################################################
243# xtest / optee_test
244################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000245ifeq ($(NSU),32)
246XTEST_COMMON_FLAGS += CFG_ARM32=y
247XTEST_CLEAN_COMMON_FLAGS += CFG_ARM32=y
248endif
249
Pascal Brandd6536da2015-09-01 10:38:43 +0200250xtest: xtest-common
Joakim Bech7f43b922015-10-01 07:24:00 -0700251
Victor Chong24475982015-12-02 07:18:13 +0000252# FIXME:
253# "make clean" in xtest: fails if optee_os has been cleaned previously
Joakim Bech7f43b922015-10-01 07:24:00 -0700254.PHONY: xtest-clean
Pascal Brandd6536da2015-09-01 10:38:43 +0200255xtest-clean: xtest-clean-common
Victor Chong24475982015-12-02 07:18:13 +0000256 rm -rf $(OPTEE_TEST_OUT_PATH)
Joakim Bech7f43b922015-10-01 07:24:00 -0700257
258.PHONY: xtest-patch
Pascal Brandd6536da2015-09-01 10:38:43 +0200259xtest-patch: xtest-patch-common
Pascal Brand294bfdf2015-08-25 09:27:13 +0200260
Joakim Bech427dd632015-05-04 15:52:33 +0200261################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000262# aes-pef
263################################################################################
264PERF_FLAGS := CROSS_COMPILE_HOST=$(CROSS_COMPILE_NS_USER) \
265 CROSS_COMPILE_TA=$(CROSS_COMPILE_S_USER) \
266 TA_DEV_KIT_DIR=$(OPTEE_OS_TA_DEV_KIT_DIR)
267
268aes-perf: optee-os optee-client
269 $(MAKE) -C $(AESPERF_PATH) $(PERF_FLAGS)
270
271.PHONY: aes-perf-clean
272aes-perf-clean:
273 rm -rf $(AESPERF_PATH)/out
274
275################################################################################
276# sha-perf
277################################################################################
278sha-perf: optee-os optee-client
279 $(MAKE) -C $(SHAPERF_PATH) $(PERF_FLAGS)
280
281.PHONY: sha-perf-clean
282sha-perf-clean:
283 rm -rf $(SHAPERF_PATH)/out
284
285################################################################################
Joakim Bech427dd632015-05-04 15:52:33 +0200286# strace
287################################################################################
288strace:
Victor Chong24475982015-12-02 07:18:13 +0000289 cd $(STRACE_PATH); \
290 ./bootstrap; \
291 set -e; \
292 ./configure --host=$(MULTIARCH) CC="$(CCACHE)$(AARCH64_CROSS_COMPILE)gcc" LD=$(AARCH64_CROSS_COMPILE)ld; \
293 CC="$(CCACHE)$(AARCH64_CROSS_COMPILE)gcc" LD=$(AARCH64_CROSS_COMPILE)ld $(MAKE) -C $(STRACE_PATH)
Joakim Bech427dd632015-05-04 15:52:33 +0200294
Joakim Bech7f43b922015-10-01 07:24:00 -0700295.PHONY: strace-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200296strace-clean:
Victor Chong24475982015-12-02 07:18:13 +0000297 @if [ -e $(STRACE_PATH)/Makefile ]; then $(MAKE) -C $(STRACE_PATH) clean; fi
Joakim Bech427dd632015-05-04 15:52:33 +0200298
Joakim Bech7f43b922015-10-01 07:24:00 -0700299.PHONY: strace-cleaner
Victor Chong24475982015-12-02 07:18:13 +0000300strace-cleaner: strace-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200301 rm -f $(STRACE_PATH)/Makefile $(STRACE_PATH)/configure
302
303################################################################################
304# Root FS
305################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000306# Read stdin, expand ${VAR} environment variables, output to stdout
307# http://superuser.com/a/302847
308define expand-env-var
309awk '{while(match($$0,"[$$]{[^}]*}")) {var=substr($$0,RSTART+2,RLENGTH -3);gsub("[$$]{"var"}",ENVIRON[var])}}1'
310endef
Joakim Bech427dd632015-05-04 15:52:33 +0200311
Victor Chong24475982015-12-02 07:18:13 +0000312filelist-all: busybox
Joakim Bech427dd632015-05-04 15:52:33 +0200313 cat $(GEN_ROOTFS_PATH)/filelist-final.txt | sed '/fbtest/d' > $(GEN_ROOTFS_PATH)/filelist-all.txt
Victor Chong24475982015-12-02 07:18:13 +0000314 export KERNEL_VERSION=$(call KERNEL_VERSION); \
315 export TOP=$(ROOT); export MULTIARCH=$(MULTIARCH); \
316 $(expand-env-var) <$(PATCHES_PATH)/rootfs/initramfs-add-files.txt >> $(GEN_ROOTFS_PATH)/filelist-all.txt; \
317 find $(OPTEE_TEST_OUT_PATH) -type f -name "xtest" | sed 's/\(.*\)/file \/bin\/xtest \1 755 0 0/g' >> $(GEN_ROOTFS_PATH)/filelist-all.txt; \
318 find $(OPTEE_TEST_OUT_PATH) -name "*.ta" | \
319 sed 's/\(.*\)\/\(.*\)/file \/lib\/optee_armtz\/\2 \1\/\2 444 0 0/g' >> $(GEN_ROOTFS_PATH)/filelist-all.txt
Joakim Bech427dd632015-05-04 15:52:33 +0200320
Victor Chong24475982015-12-02 07:18:13 +0000321update_rootfs: optee-client optee-linuxdriver xtest aes-perf sha-perf strace filelist-all linux-gen_init_cpio
Joakim Bech427dd632015-05-04 15:52:33 +0200322 cd $(GEN_ROOTFS_PATH); \
Victor Chong24475982015-12-02 07:18:13 +0000323 $(LINUX_PATH)/usr/gen_init_cpio $(GEN_ROOTFS_PATH)/filelist-all.txt | gzip > $(GEN_ROOTFS_PATH)/filesystem.cpio.gz
324
325.PHONY: update_rootfs-clean
326update_rootfs-clean:
327 rm -f $(GEN_ROOTFS_PATH)/filesystem.cpio.gz $(GEN_ROOTFS_PATH)/filelist-all.txt $(GEN_ROOTFS_PATH)/filelist-tmp.txt
328
329################################################################################
330# grub
331################################################################################
332grub-flags := CC="$(CCACHE)gcc" \
333 TARGET_CC="$(AARCH64_CROSS_COMPILE)gcc" \
334 TARGET_OBJCOPY="$(AARCH64_CROSS_COMPILE)objcopy" \
335 TARGET_NM="$(AARCH64_CROSS_COMPILE)nm" \
336 TARGET_RANLIB="$(AARCH64_CROSS_COMPILE)ranlib" \
337 TARGET_STRIP="$(AARCH64_CROSS_COMPILE)strip"
338
339.PHONY: grub
340grub: prepare
341 cd $(GRUB_PATH); \
342 ./autogen.sh; \
343 ./configure --target=aarch64 --enable-boot-time $(grub-flags); \
344 $(MAKE) -C $(GRUB_PATH); \
345 ./grub-mkimage \
346 --verbose \
347 --output=$(OUT_PATH)/grubaa64.efi \
348 --config=$(PATCHES_PATH)/grub/grub.configfile \
349 --format=arm64-efi \
350 --directory=grub-core \
351 --prefix=/boot/grub \
352 boot chain configfile efinet ext2 fat gettext help linux loadenv lsefi normal part_gpt part_msdos read search search_fs_file search_fs_uuid search_label terminal terminfo tftp time
353
354.PHONY: grub-clean
355grub-clean:
356 @if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) clean; fi
357 rm -f $(OUT_PATH)/grubaa64.efi
358
359.PHONY: grub-cleaner
360grub-cleaner: grub-clean
361 @if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) distclean; fi
362 rm -f $(GRUB_PATH)/configure
Joakim Bech427dd632015-05-04 15:52:33 +0200363
364################################################################################
365# Boot Image
366################################################################################
Victor Chong13cad772015-12-05 00:35:19 +0900367LINUX_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
368ifeq ($(LINUX_CONSOLE_UART),3)
369GRUBCFG = $(PATCHES_PATH)/grub/grub_uart3.cfg
370else
371GRUBCFG = $(PATCHES_PATH)/grub/grub_uart0.cfg
372endif
373
Victor Chong24475982015-12-02 07:18:13 +0000374boot-img: linux update_rootfs edk2 grub
Joakim Bech427dd632015-05-04 15:52:33 +0200375 sudo -p "[sudo] Password:" true
376 if [ -d .tmpbootimg ] ; then sudo rm -rf .tmpbootimg ; fi
377 mkdir -p .tmpbootimg
378 dd if=/dev/zero of=$(BOOT_IMG) bs=512 count=131072 status=none
Victor Chong24475982015-12-02 07:18:13 +0000379 sudo mkfs.vfat -n "BOOT IMG" $(BOOT_IMG) >/dev/null
Joakim Bech427dd632015-05-04 15:52:33 +0200380 sudo mount -o loop,rw,sync $(BOOT_IMG) .tmpbootimg
Victor Chong24475982015-12-02 07:18:13 +0000381 sudo cp $(LINUX_PATH)/arch/arm64/boot/Image $(DTB) .tmpbootimg/
382 sudo mkdir -p .tmpbootimg/EFI/BOOT
Victor Chong13cad772015-12-05 00:35:19 +0900383 sudo cp $(OUT_PATH)/grubaa64.efi .tmpbootimg/EFI/BOOT/
384 sudo cp $(GRUBCFG) .tmpbootimg/EFI/BOOT/grub.cfg
Joakim Bech427dd632015-05-04 15:52:33 +0200385 sudo cp $(GEN_ROOTFS_PATH)/filesystem.cpio.gz .tmpbootimg/initrd.img
Victor Chong24475982015-12-02 07:18:13 +0000386 sudo cp $(EDK2_PATH)/Build/HiKey/$(EDK2_BUILD)_GCC49/AARCH64/AndroidFastbootApp.efi .tmpbootimg/EFI/BOOT/fastboot.efi
Joakim Bech2a8ddf42015-11-12 14:12:43 +0100387 # We cannot figure out why we need the sleep here, but from time to time
388 # we can see that we get "device/resource busy" when trying to unmount
389 # .tmpbootimg below. A short sleep seems to solve the problem and has to
390 # be here until we figure out why this happens.
391 sleep 3
Joakim Bech427dd632015-05-04 15:52:33 +0200392 sudo umount .tmpbootimg
393 sudo rm -rf .tmpbootimg
394
Joakim Bech7f43b922015-10-01 07:24:00 -0700395.PHONY: boot-img-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200396boot-img-clean:
397 rm -f $(BOOT_IMG)
398
399################################################################################
400# l-loader
401################################################################################
402lloader: arm-tf
Victor Chong24475982015-12-02 07:18:13 +0000403 $(MAKE) -C $(LLOADER_PATH) BL1=$(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/bl1.bin CROSS_COMPILE="$(CCACHE)$(AARCH32_CROSS_COMPILE)" PTABLE_LST=linux-4g
Joakim Bech427dd632015-05-04 15:52:33 +0200404
Joakim Bech7f43b922015-10-01 07:24:00 -0700405.PHONY: lloader-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200406lloader-clean:
Victor Chong24475982015-12-02 07:18:13 +0000407 $(MAKE) -C $(LLOADER_PATH) clean
Joakim Bech7f43b922015-10-01 07:24:00 -0700408
409################################################################################
410# nvme image
411################################################################################
412.PHONY: nvme
Victor Chong24475982015-12-02 07:18:13 +0000413nvme: prepare
Joakim Bech7f43b922015-10-01 07:24:00 -0700414 wget https://builds.96boards.org/releases/hikey/linaro/binaries/latest/nvme.img -O $(NVME_IMG)
415
416.PHONY: nvme-cleaner
417nvme-cleaner:
418 rm -f $(NVME_IMG)
419
420################################################################################
421# Flash
422################################################################################
Joakim Bech4eaf9b22016-01-18 13:31:45 +0100423define flash_help
424 @read -r -p "1. Connect USB OTG cable, the micro USB cable (press any key)" dummy
425 @read -r -p "2. Connect HiKey to power up (press any key)" dummy
426endef
427
428.PHONY: recovery
429recovery:
430 @echo "Enter recovery mode to flash a new bootloader"
431 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
432 @echo " 3-4: Closed (Boot Select = Recovery: program eMMC from USB OTG)"
433 $(call flash_help)
434 sudo python $(ROOT)/burn-boot/hisi-idt.py --img1=$(LLOADER_PATH)/l-loader.bin
435 @$(MAKE) --no-print flash FROM_RECOVERY=1
436
Joakim Bech7f43b922015-10-01 07:24:00 -0700437.PHONY: flash
438flash:
Joakim Bech4eaf9b22016-01-18 13:31:45 +0100439ifneq ($(FROM_RECOVERY),1)
440 @echo "Flash binaries using fastboot"
441 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
442 @echo " 3-4: Open (Boot Select = Boot from eMMC)"
443 @echo " 5-6: Closed (GPIO3-1 = Low: UEFI runs Fastboot app)"
444 $(call flash_help)
445 @echo "3. Wait until you see the (UART) message"
446 @echo " \"Android Fastboot mode - version x.x Press any key to quit.\""
447 @read -r -p " Then press any key to continue flashing" dummy
448endif
Victor Chong24475982015-12-02 07:18:13 +0000449 fastboot flash ptable $(LLOADER_PATH)/ptable-linux-4g.img
450 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
Joakim Bech7f43b922015-10-01 07:24:00 -0700451 fastboot flash nvme $(NVME_IMG)
452 fastboot flash boot $(BOOT_IMG)