blob: 35f46d198ff69d709f5310ec91cb65275633aedc [file] [log] [blame]
Victor Chongbadc7922015-12-08 17:23:20 +00001################################################################################
Pascal Brandefe56592016-03-03 10:46:52 +01002# Following variables defines how the NS_USER (Non Secure User - Client
3# Application), NS_KERNEL (Non Secure Kernel), S_KERNEL (Secure Kernel) and
4# S_USER (Secure User - TA) are compiled
Victor Chongbadc7922015-12-08 17:23:20 +00005################################################################################
Pascal Brandefe56592016-03-03 10:46:52 +01006COMPILE_NS_USER ?= 64
7override COMPILE_NS_KERNEL := 64
8COMPILE_S_USER ?= 32
9COMPILE_S_KERNEL ?= 64
Victor Chong24475982015-12-02 07:18:13 +000010
Victor Chong13cad772015-12-05 00:35:19 +090011# Normal/secure world console UARTs: 3 or 0 [default 3]
12CFG_NW_CONSOLE_UART ?= 3
13CFG_SW_CONSOLE_UART ?= 3
14
Victor Chongbadc7922015-12-08 17:23:20 +000015################################################################################
16# Includes
17################################################################################
Pascal Brandd6536da2015-09-01 10:38:43 +020018-include common.mk
19
20################################################################################
21# Mandatory definition to use common.mk
22################################################################################
Pascal Brandefe56592016-03-03 10:46:52 +010023ifeq ($(COMPILE_NS_USER),64)
Victor Chong24475982015-12-02 07:18:13 +000024MULTIARCH := aarch64-linux-gnu
25else
Victor Chong24475982015-12-02 07:18:13 +000026MULTIARCH := arm-linux-gnueabihf
27endif
Pascal Brandd6536da2015-09-01 10:38:43 +020028
Joakim Bech427dd632015-05-04 15:52:33 +020029################################################################################
30# Paths to git projects and various binaries
31################################################################################
32ARM_TF_PATH ?= $(ROOT)/arm-trusted-firmware
33ifeq ($(DEBUG),1)
34ARM_TF_BUILD ?= debug
35else
36ARM_TF_BUILD ?= release
Joakim Bech427dd632015-05-04 15:52:33 +020037endif
38
39EDK2_PATH ?= $(ROOT)/edk2
40ifeq ($(DEBUG),1)
41EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey/DEBUG_GCC49/FV/BL33_AP_UEFI.fd
42EDK2_BUILD ?= DEBUG
43else
44EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey/RELEASE_GCC49/FV/BL33_AP_UEFI.fd
45EDK2_BUILD ?= RELEASE
46endif
47
Victor Chong24475982015-12-02 07:18:13 +000048MCUIMAGE_BIN ?=$(EDK2_PATH)/HisiPkg/HiKeyPkg/NonFree/mcuimage.bin
Joakim Bech427dd632015-05-04 15:52:33 +020049STRACE_PATH ?=$(ROOT)/strace
50BOOT_IMG ?=$(ROOT)/out/boot-fat.uefi.img
51LLOADER_PATH ?=$(ROOT)/l-loader
Joakim Bech7f43b922015-10-01 07:24:00 -070052NVME_IMG ?=$(ROOT)/out/nvme.img
Victor Chong24475982015-12-02 07:18:13 +000053OUT_PATH ?=$(ROOT)/out
54GRUB_PATH ?=$(ROOT)/grub
55PATCHES_PATH ?=$(ROOT)/patches_hikey
56AESPERF_PATH ?=$(ROOT)/aes-perf
57SHAPERF_PATH ?=$(ROOT)/sha-perf
Joakim Bech427dd632015-05-04 15:52:33 +020058
59################################################################################
Joakim Bech427dd632015-05-04 15:52:33 +020060# Targets
61################################################################################
Victor Chong24475982015-12-02 07:18:13 +000062all: prepare arm-tf boot-img lloader nvme
Joakim Bech427dd632015-05-04 15:52:33 +020063
Victor Chong24475982015-12-02 07:18:13 +000064clean: 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 +020065
Victor Chong24475982015-12-02 07:18:13 +000066cleaner: clean prepare-cleaner busybox-cleaner linux-cleaner strace-cleaner nvme-cleaner grub-cleaner
Joakim Bech427dd632015-05-04 15:52:33 +020067
68-include toolchain.mk
69
Victor Chong24475982015-12-02 07:18:13 +000070prepare:
71 @if [ ! -d $(ROOT)/out ]; then mkdir $(ROOT)/out; fi
Joakim Bech427dd632015-05-04 15:52:33 +020072
Victor Chong24475982015-12-02 07:18:13 +000073.PHONY: prepare-cleaner
74prepare-cleaner:
75 rm -rf $(ROOT)/out
Joakim Bech427dd632015-05-04 15:52:33 +020076
77################################################################################
78# ARM Trusted Firmware
79################################################################################
Pascal Brandb130ea22015-10-13 13:18:36 +020080ARM_TF_EXPORTS ?= \
Joakim Bech427dd632015-05-04 15:52:33 +020081 CFLAGS="-O0 -gdwarf-2" \
Pascal Brandb130ea22015-10-13 13:18:36 +020082 CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
83
84ARM_TF_FLAGS ?= \
Joakim Bech427dd632015-05-04 15:52:33 +020085 BL32=$(OPTEE_OS_BIN) \
86 BL33=$(EDK2_BIN) \
Joakim Bech427dd632015-05-04 15:52:33 +020087 BL30=$(MCUIMAGE_BIN) \
Pascal Brandb130ea22015-10-13 13:18:36 +020088 DEBUG=$(DEBUG) \
89 PLAT=hikey \
90 SPD=opteed
Joakim Bech427dd632015-05-04 15:52:33 +020091
Victor Chong13cad772015-12-05 00:35:19 +090092ARM_TF_CONSOLE_UART ?= $(CFG_SW_CONSOLE_UART)
93ifeq ($(ARM_TF_CONSOLE_UART),0)
94 ARM_TF_FLAGS += CONSOLE_BASE=PL011_UART0_BASE \
95 CRASH_CONSOLE_BASE=PL011_UART0_BASE
96endif
97
Victor Chong24475982015-12-02 07:18:13 +000098arm-tf: optee-os edk2
Pascal Brandb130ea22015-10-13 13:18:36 +020099 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) all fip
100
Victor Chong24475982015-12-02 07:18:13 +0000101.PHONY: arm-tf-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200102arm-tf-clean:
Pascal Brandb130ea22015-10-13 13:18:36 +0200103 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) clean
Joakim Bech427dd632015-05-04 15:52:33 +0200104
105################################################################################
106# Busybox
Victor Chong24475982015-12-02 07:18:13 +0000107################################################################################
Pascal Brand440ef9c2015-09-08 16:01:58 +0200108BUSYBOX_COMMON_TARGET = hikey nocpio
109BUSYBOX_CLEAN_COMMON_TARGET = hikey clean
Joakim Bech427dd632015-05-04 15:52:33 +0200110
Pascal Brand440ef9c2015-09-08 16:01:58 +0200111busybox: busybox-common
Joakim Bech427dd632015-05-04 15:52:33 +0200112
Joakim Bech7f43b922015-10-01 07:24:00 -0700113.PHONY: busybox-clean
Pascal Brand440ef9c2015-09-08 16:01:58 +0200114busybox-clean: busybox-clean-common
115
Joakim Bech7f43b922015-10-01 07:24:00 -0700116.PHONY: busybox-cleaner
Victor Chong24475982015-12-02 07:18:13 +0000117busybox-cleaner: busybox-clean-common busybox-cleaner-common
Joakim Bech427dd632015-05-04 15:52:33 +0200118
119################################################################################
120# EDK2 / Tianocore
121################################################################################
Victor Chong13cad772015-12-05 00:35:19 +0900122EDK2_VARS ?= EDK2_ARCH=AARCH64 \
123 EDK2_DSC=HisiPkg/HiKeyPkg/HiKey.dsc \
124 EDK2_TOOLCHAIN=GCC49 \
125 EDK2_BUILD=$(EDK2_BUILD)
126
127EDK2_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
128ifeq ($(EDK2_CONSOLE_UART),0)
129 EDK2_VARS += EDK2_MACROS="-DSERIAL_BASE=0xF8015000"
130endif
131
Pascal Brand9a0f50f2015-09-08 15:34:17 +0200132define edk2-call
Joakim Bech427dd632015-05-04 15:52:33 +0200133 GCC49_AARCH64_PREFIX=$(AARCH64_CROSS_COMPILE) \
Pascal Brand9a0f50f2015-09-08 15:34:17 +0200134 $(MAKE) -j1 -C $(EDK2_PATH) \
Victor Chong13cad772015-12-05 00:35:19 +0900135 -f HisiPkg/HiKeyPkg/Makefile $(EDK2_VARS)
Joakim Bech427dd632015-05-04 15:52:33 +0200136endef
137
Pascal Brand9a0f50f2015-09-08 15:34:17 +0200138edk2: edk2-common
Joakim Bech427dd632015-05-04 15:52:33 +0200139
Joakim Bech7f43b922015-10-01 07:24:00 -0700140.PHONY: edk2-clean
Pascal Brand9a0f50f2015-09-08 15:34:17 +0200141edk2-clean: edk2-clean-common
Joakim Bech427dd632015-05-04 15:52:33 +0200142
143################################################################################
144# Linux kernel
145################################################################################
Jerome Forissiere1002382015-11-26 11:36:00 +0100146LINUX_DEFCONFIG_COMMON_ARCH ?= arm64
147LINUX_DEFCONFIG_COMMON_FILES ?= $(LINUX_PATH)/arch/arm64/configs/defconfig \
Victor Chong24475982015-12-02 07:18:13 +0000148 $(CURDIR)/kconfigs/hikey.conf \
149 $(PATCHES_PATH)/kernel_config/usb_net_dm9601.conf \
150 $(PATCHES_PATH)/kernel_config/ftrace.conf
Joakim Bech427dd632015-05-04 15:52:33 +0200151
152linux-defconfig: $(LINUX_PATH)/.config
153
154linux-gen_init_cpio: linux-defconfig
Victor Chong24475982015-12-02 07:18:13 +0000155 $(MAKE) -C $(LINUX_PATH)/usr \
Pascal Brande3d85982015-09-10 17:20:42 +0200156 CROSS_COMPILE=$(CROSS_COMPILE_NS_KERNEL) \
Joakim Bech427dd632015-05-04 15:52:33 +0200157 ARCH=arm64 \
158 LOCALVERSION= \
159 gen_init_cpio
160
Victor Chong24475982015-12-02 07:18:13 +0000161LINUX_COMMON_FLAGS += ARCH=arm64 Image modules
162UPSTREAM_KERNEL := $(if $(wildcard $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts),1,0)
163ifeq ($(UPSTREAM_KERNEL),0)
164LINUX_COMMON_FLAGS += hi6220-hikey.dtb
165DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hi6220-hikey.dtb
166else
167LINUX_COMMON_FLAGS += hisilicon/hi6220-hikey.dtb
168DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb
169endif
Joakim Bech427dd632015-05-04 15:52:33 +0200170
Pascal Brande3d85982015-09-10 17:20:42 +0200171linux: linux-common
172
Joakim Bech7f43b922015-10-01 07:24:00 -0700173.PHONY: linux-defconfig-clean
Pascal Brande3d85982015-09-10 17:20:42 +0200174linux-defconfig-clean: linux-defconfig-clean-common
Joakim Bech427dd632015-05-04 15:52:33 +0200175
Pascal Brande3d85982015-09-10 17:20:42 +0200176LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
Joakim Bech427dd632015-05-04 15:52:33 +0200177
Joakim Bech7f43b922015-10-01 07:24:00 -0700178.PHONY: linux-clean
Pascal Brande3d85982015-09-10 17:20:42 +0200179linux-clean: linux-clean-common
180
181LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
182
Joakim Bech7f43b922015-10-01 07:24:00 -0700183.PHONY: linux-cleaner
Pascal Brande3d85982015-09-10 17:20:42 +0200184linux-cleaner: linux-cleaner-common
Joakim Bech427dd632015-05-04 15:52:33 +0200185
186################################################################################
187# OP-TEE
188################################################################################
Victor Chong13cad772015-12-05 00:35:19 +0900189OPTEE_OS_COMMON_FLAGS += PLATFORM=hikey CFG_TEE_TA_LOG_LEVEL=3 CFG_CONSOLE_UART=$(CFG_SW_CONSOLE_UART)
190OPTEE_OS_CLEAN_COMMON_FLAGS += PLATFORM=hikey
191
Jerome Forissierae45fbf2015-09-04 09:40:17 +0200192optee-os: optee-os-common
Joakim Bech427dd632015-05-04 15:52:33 +0200193
Joakim Bech7f43b922015-10-01 07:24:00 -0700194.PHONY: optee-os-clean
Jerome Forissierae45fbf2015-09-04 09:40:17 +0200195optee-os-clean: optee-os-clean-common
Joakim Bech427dd632015-05-04 15:52:33 +0200196
Pascal Brand070d9552015-09-01 15:33:22 +0200197optee-client: optee-client-common
Jerome Forissierae45fbf2015-09-04 09:40:17 +0200198
Joakim Bech7f43b922015-10-01 07:24:00 -0700199.PHONY: optee-client-clean
Pascal Brand070d9552015-09-01 15:33:22 +0200200optee-client-clean: optee-client-clean-common
Jerome Forissierae45fbf2015-09-04 09:40:17 +0200201
202OPTEE_LINUXDRIVER_COMMON_FLAGS += ARCH=arm64
203optee-linuxdriver: optee-linuxdriver-common
204
205OPTEE_LINUXDRIVER_CLEAN_COMMON_FLAGS += ARCH=arm64
Joakim Bech7f43b922015-10-01 07:24:00 -0700206.PHONY: optee-linuxdriver-clean
Pascal Brand070d9552015-09-01 15:33:22 +0200207optee-linuxdriver-clean: optee-linuxdriver-clean-common
Joakim Bech427dd632015-05-04 15:52:33 +0200208
209################################################################################
210# xtest / optee_test
211################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000212
Pascal Brandd6536da2015-09-01 10:38:43 +0200213xtest: xtest-common
Joakim Bech7f43b922015-10-01 07:24:00 -0700214
Victor Chong24475982015-12-02 07:18:13 +0000215# FIXME:
216# "make clean" in xtest: fails if optee_os has been cleaned previously
Joakim Bech7f43b922015-10-01 07:24:00 -0700217.PHONY: xtest-clean
Pascal Brandd6536da2015-09-01 10:38:43 +0200218xtest-clean: xtest-clean-common
Victor Chong24475982015-12-02 07:18:13 +0000219 rm -rf $(OPTEE_TEST_OUT_PATH)
Joakim Bech7f43b922015-10-01 07:24:00 -0700220
221.PHONY: xtest-patch
Pascal Brandd6536da2015-09-01 10:38:43 +0200222xtest-patch: xtest-patch-common
Pascal Brand294bfdf2015-08-25 09:27:13 +0200223
Joakim Bech427dd632015-05-04 15:52:33 +0200224################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000225# aes-pef
226################################################################################
227PERF_FLAGS := CROSS_COMPILE_HOST=$(CROSS_COMPILE_NS_USER) \
228 CROSS_COMPILE_TA=$(CROSS_COMPILE_S_USER) \
229 TA_DEV_KIT_DIR=$(OPTEE_OS_TA_DEV_KIT_DIR)
230
231aes-perf: optee-os optee-client
232 $(MAKE) -C $(AESPERF_PATH) $(PERF_FLAGS)
233
234.PHONY: aes-perf-clean
235aes-perf-clean:
236 rm -rf $(AESPERF_PATH)/out
237
238################################################################################
239# sha-perf
240################################################################################
241sha-perf: optee-os optee-client
242 $(MAKE) -C $(SHAPERF_PATH) $(PERF_FLAGS)
243
244.PHONY: sha-perf-clean
245sha-perf-clean:
246 rm -rf $(SHAPERF_PATH)/out
247
248################################################################################
Joakim Bech427dd632015-05-04 15:52:33 +0200249# strace
250################################################################################
251strace:
Victor Chong24475982015-12-02 07:18:13 +0000252 cd $(STRACE_PATH); \
253 ./bootstrap; \
254 set -e; \
Pascal Brandefe56592016-03-03 10:46:52 +0100255 ./configure --host=$(MULTIARCH) CC="$(CCACHE)$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)gcc" LD=$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)ld; \
256 CC="$(CCACHE)$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)gcc" LD=$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)ld $(MAKE) -C $(STRACE_PATH)
Joakim Bech427dd632015-05-04 15:52:33 +0200257
Joakim Bech7f43b922015-10-01 07:24:00 -0700258.PHONY: strace-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200259strace-clean:
Victor Chong24475982015-12-02 07:18:13 +0000260 @if [ -e $(STRACE_PATH)/Makefile ]; then $(MAKE) -C $(STRACE_PATH) clean; fi
Joakim Bech427dd632015-05-04 15:52:33 +0200261
Joakim Bech7f43b922015-10-01 07:24:00 -0700262.PHONY: strace-cleaner
Victor Chong24475982015-12-02 07:18:13 +0000263strace-cleaner: strace-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200264 rm -f $(STRACE_PATH)/Makefile $(STRACE_PATH)/configure
265
266################################################################################
267# Root FS
268################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000269# Read stdin, expand ${VAR} environment variables, output to stdout
270# http://superuser.com/a/302847
271define expand-env-var
272awk '{while(match($$0,"[$$]{[^}]*}")) {var=substr($$0,RSTART+2,RLENGTH -3);gsub("[$$]{"var"}",ENVIRON[var])}}1'
273endef
Joakim Bech427dd632015-05-04 15:52:33 +0200274
Victor Chong24475982015-12-02 07:18:13 +0000275filelist-all: busybox
Joakim Bech427dd632015-05-04 15:52:33 +0200276 cat $(GEN_ROOTFS_PATH)/filelist-final.txt | sed '/fbtest/d' > $(GEN_ROOTFS_PATH)/filelist-all.txt
Victor Chong24475982015-12-02 07:18:13 +0000277 export KERNEL_VERSION=$(call KERNEL_VERSION); \
278 export TOP=$(ROOT); export MULTIARCH=$(MULTIARCH); \
279 $(expand-env-var) <$(PATCHES_PATH)/rootfs/initramfs-add-files.txt >> $(GEN_ROOTFS_PATH)/filelist-all.txt; \
280 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; \
281 find $(OPTEE_TEST_OUT_PATH) -name "*.ta" | \
282 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 +0200283
Victor Chong24475982015-12-02 07:18:13 +0000284update_rootfs: optee-client optee-linuxdriver xtest aes-perf sha-perf strace filelist-all linux-gen_init_cpio
Joakim Bech427dd632015-05-04 15:52:33 +0200285 cd $(GEN_ROOTFS_PATH); \
Victor Chong24475982015-12-02 07:18:13 +0000286 $(LINUX_PATH)/usr/gen_init_cpio $(GEN_ROOTFS_PATH)/filelist-all.txt | gzip > $(GEN_ROOTFS_PATH)/filesystem.cpio.gz
287
288.PHONY: update_rootfs-clean
289update_rootfs-clean:
290 rm -f $(GEN_ROOTFS_PATH)/filesystem.cpio.gz $(GEN_ROOTFS_PATH)/filelist-all.txt $(GEN_ROOTFS_PATH)/filelist-tmp.txt
291
292################################################################################
293# grub
294################################################################################
295grub-flags := CC="$(CCACHE)gcc" \
296 TARGET_CC="$(AARCH64_CROSS_COMPILE)gcc" \
297 TARGET_OBJCOPY="$(AARCH64_CROSS_COMPILE)objcopy" \
298 TARGET_NM="$(AARCH64_CROSS_COMPILE)nm" \
299 TARGET_RANLIB="$(AARCH64_CROSS_COMPILE)ranlib" \
300 TARGET_STRIP="$(AARCH64_CROSS_COMPILE)strip"
301
302.PHONY: grub
303grub: prepare
304 cd $(GRUB_PATH); \
305 ./autogen.sh; \
306 ./configure --target=aarch64 --enable-boot-time $(grub-flags); \
307 $(MAKE) -C $(GRUB_PATH); \
308 ./grub-mkimage \
309 --verbose \
310 --output=$(OUT_PATH)/grubaa64.efi \
311 --config=$(PATCHES_PATH)/grub/grub.configfile \
312 --format=arm64-efi \
313 --directory=grub-core \
314 --prefix=/boot/grub \
315 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
316
317.PHONY: grub-clean
318grub-clean:
319 @if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) clean; fi
320 rm -f $(OUT_PATH)/grubaa64.efi
321
322.PHONY: grub-cleaner
323grub-cleaner: grub-clean
324 @if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) distclean; fi
325 rm -f $(GRUB_PATH)/configure
Joakim Bech427dd632015-05-04 15:52:33 +0200326
327################################################################################
328# Boot Image
329################################################################################
Victor Chong13cad772015-12-05 00:35:19 +0900330LINUX_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
331ifeq ($(LINUX_CONSOLE_UART),3)
332GRUBCFG = $(PATCHES_PATH)/grub/grub_uart3.cfg
333else
334GRUBCFG = $(PATCHES_PATH)/grub/grub_uart0.cfg
335endif
336
Victor Chong24475982015-12-02 07:18:13 +0000337boot-img: linux update_rootfs edk2 grub
Joakim Bech427dd632015-05-04 15:52:33 +0200338 sudo -p "[sudo] Password:" true
339 if [ -d .tmpbootimg ] ; then sudo rm -rf .tmpbootimg ; fi
340 mkdir -p .tmpbootimg
341 dd if=/dev/zero of=$(BOOT_IMG) bs=512 count=131072 status=none
Victor Chong24475982015-12-02 07:18:13 +0000342 sudo mkfs.vfat -n "BOOT IMG" $(BOOT_IMG) >/dev/null
Joakim Bech427dd632015-05-04 15:52:33 +0200343 sudo mount -o loop,rw,sync $(BOOT_IMG) .tmpbootimg
Victor Chong24475982015-12-02 07:18:13 +0000344 sudo cp $(LINUX_PATH)/arch/arm64/boot/Image $(DTB) .tmpbootimg/
345 sudo mkdir -p .tmpbootimg/EFI/BOOT
Victor Chong13cad772015-12-05 00:35:19 +0900346 sudo cp $(OUT_PATH)/grubaa64.efi .tmpbootimg/EFI/BOOT/
347 sudo cp $(GRUBCFG) .tmpbootimg/EFI/BOOT/grub.cfg
Joakim Bech427dd632015-05-04 15:52:33 +0200348 sudo cp $(GEN_ROOTFS_PATH)/filesystem.cpio.gz .tmpbootimg/initrd.img
Victor Chong24475982015-12-02 07:18:13 +0000349 sudo cp $(EDK2_PATH)/Build/HiKey/$(EDK2_BUILD)_GCC49/AARCH64/AndroidFastbootApp.efi .tmpbootimg/EFI/BOOT/fastboot.efi
Joakim Bech2a8ddf42015-11-12 14:12:43 +0100350 # We cannot figure out why we need the sleep here, but from time to time
351 # we can see that we get "device/resource busy" when trying to unmount
352 # .tmpbootimg below. A short sleep seems to solve the problem and has to
353 # be here until we figure out why this happens.
354 sleep 3
Joakim Bech427dd632015-05-04 15:52:33 +0200355 sudo umount .tmpbootimg
356 sudo rm -rf .tmpbootimg
357
Joakim Bech7f43b922015-10-01 07:24:00 -0700358.PHONY: boot-img-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200359boot-img-clean:
360 rm -f $(BOOT_IMG)
361
362################################################################################
363# l-loader
364################################################################################
365lloader: arm-tf
Victor Chong24475982015-12-02 07:18:13 +0000366 $(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 +0200367
Joakim Bech7f43b922015-10-01 07:24:00 -0700368.PHONY: lloader-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200369lloader-clean:
Victor Chong24475982015-12-02 07:18:13 +0000370 $(MAKE) -C $(LLOADER_PATH) clean
Joakim Bech7f43b922015-10-01 07:24:00 -0700371
372################################################################################
373# nvme image
374################################################################################
375.PHONY: nvme
Victor Chong24475982015-12-02 07:18:13 +0000376nvme: prepare
Joakim Bech7f43b922015-10-01 07:24:00 -0700377 wget https://builds.96boards.org/releases/hikey/linaro/binaries/latest/nvme.img -O $(NVME_IMG)
378
379.PHONY: nvme-cleaner
380nvme-cleaner:
381 rm -f $(NVME_IMG)
382
383################################################################################
384# Flash
385################################################################################
Joakim Bech4eaf9b22016-01-18 13:31:45 +0100386define flash_help
387 @read -r -p "1. Connect USB OTG cable, the micro USB cable (press any key)" dummy
388 @read -r -p "2. Connect HiKey to power up (press any key)" dummy
389endef
390
391.PHONY: recovery
392recovery:
393 @echo "Enter recovery mode to flash a new bootloader"
394 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
395 @echo " 3-4: Closed (Boot Select = Recovery: program eMMC from USB OTG)"
396 $(call flash_help)
397 sudo python $(ROOT)/burn-boot/hisi-idt.py --img1=$(LLOADER_PATH)/l-loader.bin
398 @$(MAKE) --no-print flash FROM_RECOVERY=1
399
Joakim Bech7f43b922015-10-01 07:24:00 -0700400.PHONY: flash
401flash:
Joakim Bech4eaf9b22016-01-18 13:31:45 +0100402ifneq ($(FROM_RECOVERY),1)
403 @echo "Flash binaries using fastboot"
404 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
405 @echo " 3-4: Open (Boot Select = Boot from eMMC)"
406 @echo " 5-6: Closed (GPIO3-1 = Low: UEFI runs Fastboot app)"
407 $(call flash_help)
408 @echo "3. Wait until you see the (UART) message"
409 @echo " \"Android Fastboot mode - version x.x Press any key to quit.\""
410 @read -r -p " Then press any key to continue flashing" dummy
411endif
Victor Chong24475982015-12-02 07:18:13 +0000412 fastboot flash ptable $(LLOADER_PATH)/ptable-linux-4g.img
413 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
Joakim Bech7f43b922015-10-01 07:24:00 -0700414 fastboot flash nvme $(NVME_IMG)
415 fastboot flash boot $(BOOT_IMG)