blob: a403cdfe647e380f013ea129024fc7b2442f2b10 [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
Jens Wiklanderb17e11c2016-01-27 09:23:40 +010064clean: arm-tf-clean busybox-clean edk2-clean linux-clean optee-os-clean optee-client-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
Joakim Bech427dd632015-05-04 15:52:33 +0200202################################################################################
203# xtest / optee_test
204################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000205
Pascal Brandd6536da2015-09-01 10:38:43 +0200206xtest: xtest-common
Joakim Bech7f43b922015-10-01 07:24:00 -0700207
Victor Chong24475982015-12-02 07:18:13 +0000208# FIXME:
209# "make clean" in xtest: fails if optee_os has been cleaned previously
Joakim Bech7f43b922015-10-01 07:24:00 -0700210.PHONY: xtest-clean
Pascal Brandd6536da2015-09-01 10:38:43 +0200211xtest-clean: xtest-clean-common
Victor Chong24475982015-12-02 07:18:13 +0000212 rm -rf $(OPTEE_TEST_OUT_PATH)
Joakim Bech7f43b922015-10-01 07:24:00 -0700213
214.PHONY: xtest-patch
Pascal Brandd6536da2015-09-01 10:38:43 +0200215xtest-patch: xtest-patch-common
Pascal Brand294bfdf2015-08-25 09:27:13 +0200216
Joakim Bech427dd632015-05-04 15:52:33 +0200217################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000218# aes-pef
219################################################################################
220PERF_FLAGS := CROSS_COMPILE_HOST=$(CROSS_COMPILE_NS_USER) \
221 CROSS_COMPILE_TA=$(CROSS_COMPILE_S_USER) \
222 TA_DEV_KIT_DIR=$(OPTEE_OS_TA_DEV_KIT_DIR)
223
224aes-perf: optee-os optee-client
225 $(MAKE) -C $(AESPERF_PATH) $(PERF_FLAGS)
226
227.PHONY: aes-perf-clean
228aes-perf-clean:
229 rm -rf $(AESPERF_PATH)/out
230
231################################################################################
232# sha-perf
233################################################################################
234sha-perf: optee-os optee-client
235 $(MAKE) -C $(SHAPERF_PATH) $(PERF_FLAGS)
236
237.PHONY: sha-perf-clean
238sha-perf-clean:
239 rm -rf $(SHAPERF_PATH)/out
240
241################################################################################
Joakim Bech427dd632015-05-04 15:52:33 +0200242# strace
243################################################################################
244strace:
Victor Chong24475982015-12-02 07:18:13 +0000245 cd $(STRACE_PATH); \
246 ./bootstrap; \
247 set -e; \
Pascal Brandefe56592016-03-03 10:46:52 +0100248 ./configure --host=$(MULTIARCH) CC="$(CCACHE)$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)gcc" LD=$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)ld; \
249 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 +0200250
Joakim Bech7f43b922015-10-01 07:24:00 -0700251.PHONY: strace-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200252strace-clean:
Victor Chong24475982015-12-02 07:18:13 +0000253 @if [ -e $(STRACE_PATH)/Makefile ]; then $(MAKE) -C $(STRACE_PATH) clean; fi
Joakim Bech427dd632015-05-04 15:52:33 +0200254
Joakim Bech7f43b922015-10-01 07:24:00 -0700255.PHONY: strace-cleaner
Victor Chong24475982015-12-02 07:18:13 +0000256strace-cleaner: strace-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200257 rm -f $(STRACE_PATH)/Makefile $(STRACE_PATH)/configure
258
259################################################################################
260# Root FS
261################################################################################
Victor Chong24475982015-12-02 07:18:13 +0000262# Read stdin, expand ${VAR} environment variables, output to stdout
263# http://superuser.com/a/302847
264define expand-env-var
265awk '{while(match($$0,"[$$]{[^}]*}")) {var=substr($$0,RSTART+2,RLENGTH -3);gsub("[$$]{"var"}",ENVIRON[var])}}1'
266endef
Joakim Bech427dd632015-05-04 15:52:33 +0200267
Victor Chong24475982015-12-02 07:18:13 +0000268filelist-all: busybox
Joakim Bech427dd632015-05-04 15:52:33 +0200269 cat $(GEN_ROOTFS_PATH)/filelist-final.txt | sed '/fbtest/d' > $(GEN_ROOTFS_PATH)/filelist-all.txt
Victor Chong24475982015-12-02 07:18:13 +0000270 export KERNEL_VERSION=$(call KERNEL_VERSION); \
271 export TOP=$(ROOT); export MULTIARCH=$(MULTIARCH); \
272 $(expand-env-var) <$(PATCHES_PATH)/rootfs/initramfs-add-files.txt >> $(GEN_ROOTFS_PATH)/filelist-all.txt; \
273 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; \
274 find $(OPTEE_TEST_OUT_PATH) -name "*.ta" | \
275 sed 's/\(.*\)\/\(.*\)/file \/lib\/optee_armtz\/\2 \1\/\2 444 0 0/g' >> $(GEN_ROOTFS_PATH)/filelist-all.txt
Victor Chongcfb99cf2016-04-26 10:51:58 +0100276 @if [ -e $(OPTEE_GENDRV_MODULE) ]; then \
277 echo "# OP-TEE device" >> $(GEN_ROOTFS_PATH)/filelist-all.txt; \
278 echo "dir /lib/modules 755 0 0" >> $(GEN_ROOTFS_PATH)/filelist-all.txt; \
279 echo "dir /lib/modules/$(call KERNEL_VERSION) 755 0 0" >> $(GEN_ROOTFS_PATH)/filelist-all.txt; \
280 echo "file /lib/modules/$(call KERNEL_VERSION)/optee.ko $(OPTEE_GENDRV_MODULE) 755 0 0" >> $(GEN_ROOTFS_PATH)/filelist-all.txt; \
281 fi
Joakim Bech427dd632015-05-04 15:52:33 +0200282
Jens Wiklanderb17e11c2016-01-27 09:23:40 +0100283update_rootfs: optee-client xtest aes-perf sha-perf strace filelist-all linux-gen_init_cpio
Joakim Bech427dd632015-05-04 15:52:33 +0200284 cd $(GEN_ROOTFS_PATH); \
Victor Chong24475982015-12-02 07:18:13 +0000285 $(LINUX_PATH)/usr/gen_init_cpio $(GEN_ROOTFS_PATH)/filelist-all.txt | gzip > $(GEN_ROOTFS_PATH)/filesystem.cpio.gz
286
287.PHONY: update_rootfs-clean
288update_rootfs-clean:
289 rm -f $(GEN_ROOTFS_PATH)/filesystem.cpio.gz $(GEN_ROOTFS_PATH)/filelist-all.txt $(GEN_ROOTFS_PATH)/filelist-tmp.txt
290
291################################################################################
292# grub
293################################################################################
294grub-flags := CC="$(CCACHE)gcc" \
295 TARGET_CC="$(AARCH64_CROSS_COMPILE)gcc" \
296 TARGET_OBJCOPY="$(AARCH64_CROSS_COMPILE)objcopy" \
297 TARGET_NM="$(AARCH64_CROSS_COMPILE)nm" \
298 TARGET_RANLIB="$(AARCH64_CROSS_COMPILE)ranlib" \
299 TARGET_STRIP="$(AARCH64_CROSS_COMPILE)strip"
300
301.PHONY: grub
302grub: prepare
303 cd $(GRUB_PATH); \
304 ./autogen.sh; \
305 ./configure --target=aarch64 --enable-boot-time $(grub-flags); \
306 $(MAKE) -C $(GRUB_PATH); \
307 ./grub-mkimage \
308 --verbose \
309 --output=$(OUT_PATH)/grubaa64.efi \
310 --config=$(PATCHES_PATH)/grub/grub.configfile \
311 --format=arm64-efi \
312 --directory=grub-core \
313 --prefix=/boot/grub \
314 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
315
316.PHONY: grub-clean
317grub-clean:
318 @if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) clean; fi
319 rm -f $(OUT_PATH)/grubaa64.efi
320
321.PHONY: grub-cleaner
322grub-cleaner: grub-clean
323 @if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) distclean; fi
324 rm -f $(GRUB_PATH)/configure
Joakim Bech427dd632015-05-04 15:52:33 +0200325
326################################################################################
327# Boot Image
328################################################################################
Victor Chong13cad772015-12-05 00:35:19 +0900329LINUX_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
330ifeq ($(LINUX_CONSOLE_UART),3)
331GRUBCFG = $(PATCHES_PATH)/grub/grub_uart3.cfg
332else
333GRUBCFG = $(PATCHES_PATH)/grub/grub_uart0.cfg
334endif
335
Victor Chong24475982015-12-02 07:18:13 +0000336boot-img: linux update_rootfs edk2 grub
Joakim Bech427dd632015-05-04 15:52:33 +0200337 sudo -p "[sudo] Password:" true
338 if [ -d .tmpbootimg ] ; then sudo rm -rf .tmpbootimg ; fi
339 mkdir -p .tmpbootimg
340 dd if=/dev/zero of=$(BOOT_IMG) bs=512 count=131072 status=none
Victor Chong24475982015-12-02 07:18:13 +0000341 sudo mkfs.vfat -n "BOOT IMG" $(BOOT_IMG) >/dev/null
Joakim Bech427dd632015-05-04 15:52:33 +0200342 sudo mount -o loop,rw,sync $(BOOT_IMG) .tmpbootimg
Victor Chong24475982015-12-02 07:18:13 +0000343 sudo cp $(LINUX_PATH)/arch/arm64/boot/Image $(DTB) .tmpbootimg/
344 sudo mkdir -p .tmpbootimg/EFI/BOOT
Victor Chong13cad772015-12-05 00:35:19 +0900345 sudo cp $(OUT_PATH)/grubaa64.efi .tmpbootimg/EFI/BOOT/
346 sudo cp $(GRUBCFG) .tmpbootimg/EFI/BOOT/grub.cfg
Joakim Bech427dd632015-05-04 15:52:33 +0200347 sudo cp $(GEN_ROOTFS_PATH)/filesystem.cpio.gz .tmpbootimg/initrd.img
Victor Chong24475982015-12-02 07:18:13 +0000348 sudo cp $(EDK2_PATH)/Build/HiKey/$(EDK2_BUILD)_GCC49/AARCH64/AndroidFastbootApp.efi .tmpbootimg/EFI/BOOT/fastboot.efi
Joakim Bech2a8ddf42015-11-12 14:12:43 +0100349 # We cannot figure out why we need the sleep here, but from time to time
350 # we can see that we get "device/resource busy" when trying to unmount
351 # .tmpbootimg below. A short sleep seems to solve the problem and has to
352 # be here until we figure out why this happens.
353 sleep 3
Joakim Bech427dd632015-05-04 15:52:33 +0200354 sudo umount .tmpbootimg
355 sudo rm -rf .tmpbootimg
356
Joakim Bech7f43b922015-10-01 07:24:00 -0700357.PHONY: boot-img-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200358boot-img-clean:
359 rm -f $(BOOT_IMG)
360
361################################################################################
362# l-loader
363################################################################################
364lloader: arm-tf
Victor Chong24475982015-12-02 07:18:13 +0000365 $(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 +0200366
Joakim Bech7f43b922015-10-01 07:24:00 -0700367.PHONY: lloader-clean
Joakim Bech427dd632015-05-04 15:52:33 +0200368lloader-clean:
Victor Chong24475982015-12-02 07:18:13 +0000369 $(MAKE) -C $(LLOADER_PATH) clean
Joakim Bech7f43b922015-10-01 07:24:00 -0700370
371################################################################################
372# nvme image
373################################################################################
374.PHONY: nvme
Victor Chong24475982015-12-02 07:18:13 +0000375nvme: prepare
Joakim Bech7f43b922015-10-01 07:24:00 -0700376 wget https://builds.96boards.org/releases/hikey/linaro/binaries/latest/nvme.img -O $(NVME_IMG)
377
378.PHONY: nvme-cleaner
379nvme-cleaner:
380 rm -f $(NVME_IMG)
381
382################################################################################
383# Flash
384################################################################################
Joakim Bech4eaf9b22016-01-18 13:31:45 +0100385define flash_help
386 @read -r -p "1. Connect USB OTG cable, the micro USB cable (press any key)" dummy
387 @read -r -p "2. Connect HiKey to power up (press any key)" dummy
388endef
389
390.PHONY: recovery
391recovery:
392 @echo "Enter recovery mode to flash a new bootloader"
393 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
394 @echo " 3-4: Closed (Boot Select = Recovery: program eMMC from USB OTG)"
395 $(call flash_help)
396 sudo python $(ROOT)/burn-boot/hisi-idt.py --img1=$(LLOADER_PATH)/l-loader.bin
397 @$(MAKE) --no-print flash FROM_RECOVERY=1
398
Joakim Bech7f43b922015-10-01 07:24:00 -0700399.PHONY: flash
400flash:
Joakim Bech4eaf9b22016-01-18 13:31:45 +0100401ifneq ($(FROM_RECOVERY),1)
402 @echo "Flash binaries using fastboot"
403 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
404 @echo " 3-4: Open (Boot Select = Boot from eMMC)"
405 @echo " 5-6: Closed (GPIO3-1 = Low: UEFI runs Fastboot app)"
406 $(call flash_help)
407 @echo "3. Wait until you see the (UART) message"
408 @echo " \"Android Fastboot mode - version x.x Press any key to quit.\""
409 @read -r -p " Then press any key to continue flashing" dummy
410endif
Victor Chong24475982015-12-02 07:18:13 +0000411 fastboot flash ptable $(LLOADER_PATH)/ptable-linux-4g.img
412 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
Joakim Bech7f43b922015-10-01 07:24:00 -0700413 fastboot flash nvme $(NVME_IMG)
414 fastboot flash boot $(BOOT_IMG)