blob: 9b42525cf3469c4c3b6fac0cf55e16bf582e5040 [file] [log] [blame]
Victor Chong05bb4ed2017-07-02 13:47:57 +01001################################################################################
2# 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
5################################################################################
6COMPILE_NS_USER ?= 64
7override COMPILE_NS_KERNEL := 64
8COMPILE_S_USER ?= 32
9COMPILE_S_KERNEL ?= 64
10
11# Normal and secure world console UART: 6 (v2 or newer board) or 5 (v1 board)
12CFG_CONSOLE_UART ?= 6
13
14################################################################################
15# Includes
16################################################################################
Victor Chong7a716512017-09-11 15:18:44 +010017include common.mk
Victor Chong05bb4ed2017-07-02 13:47:57 +010018
19################################################################################
Victor Chong05bb4ed2017-07-02 13:47:57 +010020# Paths to git projects and various binaries
21################################################################################
22ARM_TF_PATH ?= $(ROOT)/arm-trusted-firmware
23ifeq ($(DEBUG),1)
24ARM_TF_BUILD ?= debug
25else
26ARM_TF_BUILD ?= release
27endif
28
29EDK2_PATH ?= $(ROOT)/edk2
30ifeq ($(DEBUG),1)
31EDK2_BUILD ?= DEBUG
32else
33EDK2_BUILD ?= RELEASE
34endif
35EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey960/$(EDK2_BUILD)_$(EDK2_TOOLCHAIN)/FV/BL33_AP_UEFI.fd
36OPENPLATPKG_PATH ?= $(ROOT)/OpenPlatformPkg
37
38OUT_PATH ?=$(ROOT)/out
39MCUIMAGE_BIN ?= $(OPENPLATPKG_PATH)/Platforms/Hisilicon/HiKey960/Binary/lpm3.img
40BOOT_IMG ?=$(ROOT)/out/boot-fat.uefi.img
41GRUB_PATH ?=$(ROOT)/grub
42LLOADER_PATH ?=$(ROOT)/l-loader
43IMAGE_TOOLS_PATH ?=$(ROOT)/tools-images-hikey960
44IMAGE_TOOLS_CONFIG ?=$(OUT_PATH)/config
45PATCHES_PATH ?=$(ROOT)/patches_hikey
46STRACE_PATH ?=$(ROOT)/strace
47
48################################################################################
49# Targets
50################################################################################
51.PHONY: all
Victor Chong86840a42017-10-28 13:01:33 +010052all: arm-tf boot-img lloader
Victor Chong05bb4ed2017-07-02 13:47:57 +010053
54.PHONY: clean
Igor Opaniukd5034112017-09-04 23:46:42 +030055clean: arm-tf-clean busybox-clean edk2-clean linux-clean optee-os-clean \
56 optee-client-clean xtest-clean optee-examples-clean strace-clean \
57 update_rootfs-clean boot-img-clean lloader-clean grub-clean
Victor Chong05bb4ed2017-07-02 13:47:57 +010058
59.PHONY: cleaner
60cleaner: clean prepare-cleaner busybox-cleaner linux-cleaner strace-cleaner grub-cleaner
61
Victor Chong7a716512017-09-11 15:18:44 +010062include toolchain.mk
Victor Chong05bb4ed2017-07-02 13:47:57 +010063
64.PHONY: prepare
65prepare:
66 mkdir -p $(OUT_PATH)
67
68.PHONY: prepare-cleaner
69prepare-cleaner:
70 rm -rf $(ROOT)/out
71
72################################################################################
73# ARM Trusted Firmware
74################################################################################
75ARM_TF_EXPORTS ?= \
76 CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
77
78ARM_TF_FLAGS ?= \
Victor Chong865d7752017-08-24 04:53:07 +010079 BL32=$(OPTEE_OS_HEADER_V2_BIN) \
80 BL32_EXTRA1=$(OPTEE_OS_PAGER_V2_BIN) \
81 BL32_EXTRA2=$(OPTEE_OS_PAGEABLE_V2_BIN) \
Victor Chong05bb4ed2017-07-02 13:47:57 +010082 BL33=$(EDK2_BIN) \
83 SCP_BL2=$(MCUIMAGE_BIN) \
84 DEBUG=$(DEBUG) \
85 PLAT=hikey960 \
86 SPD=opteed
87
88ifeq ($(CFG_CONSOLE_UART),5)
89 ARM_TF_FLAGS += CRASH_CONSOLE_BASE=PL011_UART5_BASE
90endif
91
92.PHONY: arm-tf
93arm-tf: optee-os edk2
94 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) all fip
95
96.PHONY: arm-tf-clean
97arm-tf-clean:
98 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) clean
99
100################################################################################
101# Busybox
102################################################################################
103BUSYBOX_COMMON_TARGET = hikey960 nocpio
104BUSYBOX_CLEAN_COMMON_TARGET = hikey960 clean
105
106.PHONY: busybox
107busybox: busybox-common
108
109.PHONY: busybox-clean
110busybox-clean: busybox-clean-common
111
112.PHONY: busybox-cleaner
113busybox-cleaner: busybox-clean-common busybox-cleaner-common
114
115################################################################################
116# EDK2 / Tianocore
117################################################################################
118EDK2_ARCH ?= AARCH64
119EDK2_DSC ?= OpenPlatformPkg/Platforms/Hisilicon/HiKey960/HiKey960.dsc
120EDK2_TOOLCHAIN ?= GCC49
121
122ifeq ($(CFG_CONSOLE_UART),5)
123 EDK2_BUILDFLAGS += -DSERIAL_BASE=0xFDF05000
124endif
125
126define edk2-call
127 $(EDK2_TOOLCHAIN)_$(EDK2_ARCH)_PREFIX=$(LEGACY_AARCH64_CROSS_COMPILE) \
128 build -n `getconf _NPROCESSORS_ONLN` -a $(EDK2_ARCH) \
129 -t $(EDK2_TOOLCHAIN) -p $(EDK2_DSC) \
130 -b $(EDK2_BUILD) $(EDK2_BUILDFLAGS)
131endef
132
133.PHONY: edk2
134edk2:
135 cd $(EDK2_PATH) && rm -rf OpenPlatformPkg && \
136 ln -s $(OPENPLATPKG_PATH)
137 set -e && cd $(EDK2_PATH) && source edksetup.sh && \
138 $(MAKE) -j1 -C $(EDK2_PATH)/BaseTools && \
139 $(call edk2-call)
140
141.PHONY: edk2-clean
142edk2-clean:
143 set -e && cd $(EDK2_PATH) && source edksetup.sh && \
144 $(call edk2-call) cleanall && \
145 $(MAKE) -j1 -C $(EDK2_PATH)/BaseTools clean
146 rm -rf $(EDK2_PATH)/Build
147 rm -rf $(EDK2_PATH)/Conf/.cache
148 rm -f $(EDK2_PATH)/Conf/build_rule.txt
149 rm -f $(EDK2_PATH)/Conf/target.txt
150 rm -f $(EDK2_PATH)/Conf/tools_def.txt
151
152################################################################################
153# Linux kernel
154################################################################################
155LINUX_DEFCONFIG_COMMON_ARCH ?= arm64
156LINUX_DEFCONFIG_COMMON_FILES ?= $(LINUX_PATH)/arch/arm64/configs/defconfig \
157 $(CURDIR)/kconfigs/hikey960.conf \
158 $(PATCHES_PATH)/kernel_config/usb_net_dm9601.conf \
159 $(PATCHES_PATH)/kernel_config/ftrace.conf
160
161.PHONY: linux-defconfig
162linux-defconfig: $(LINUX_PATH)/.config
163
164.PHONY: linux-gen_init_cpio
165linux-gen_init_cpio: linux-defconfig
166 $(MAKE) -C $(LINUX_PATH)/usr \
167 CROSS_COMPILE=$(CROSS_COMPILE_NS_KERNEL) \
168 ARCH=arm64 \
169 LOCALVERSION= \
170 gen_init_cpio
171
172LINUX_COMMON_FLAGS += ARCH=arm64 Image modules hisilicon/hi3660-hikey960.dtb
173
174.PHONY: linux
175linux: linux-common
176
177.PHONY: linux-defconfig-clean
178linux-defconfig-clean: linux-defconfig-clean-common
179
180LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
181
182.PHONY: linux-clean
183linux-clean: linux-clean-common
184
185LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
186
187.PHONY: linux-cleaner
188linux-cleaner: linux-cleaner-common
189
190################################################################################
191# OP-TEE
192################################################################################
193OPTEE_OS_COMMON_FLAGS += PLATFORM=hikey-hikey960 \
194 CFG_CONSOLE_UART=$(CFG_CONSOLE_UART) \
195 CFG_SECURE_DATA_PATH=n
196OPTEE_OS_CLEAN_COMMON_FLAGS += PLATFORM=hikey-hikey960
197
198.PHONY: optee-os
199optee-os: optee-os-common
200
201.PHONY: optee-os-clean
202optee-os-clean: optee-os-clean-common
203
204.PHONY: optee-client
205optee-client: optee-client-common
206
207.PHONY: optee-client-clean
208optee-client-clean: optee-client-clean-common
209
210################################################################################
211# xtest / optee_test
212################################################################################
213.PHONY: xtest
214xtest: xtest-common
215
216# FIXME:
217# "make clean" in xtest: fails if optee_os has been cleaned previously
218.PHONY: xtest-clean
219xtest-clean: xtest-clean-common
220 rm -rf $(OPTEE_TEST_OUT_PATH)
221
222.PHONY: xtest-patch
223xtest-patch: xtest-patch-common
224
225################################################################################
Igor Opaniukd5034112017-09-04 23:46:42 +0300226# Sample applications / optee_examples
Victor Chong05bb4ed2017-07-02 13:47:57 +0100227################################################################################
Igor Opaniukd5034112017-09-04 23:46:42 +0300228.PHONY: optee-examples
229optee-examples: optee-examples-common
Victor Chong05bb4ed2017-07-02 13:47:57 +0100230
Igor Opaniukd5034112017-09-04 23:46:42 +0300231.PHONY: optee-examples-clean
232optee-examples-clean: optee-examples-clean-common
Victor Chong05bb4ed2017-07-02 13:47:57 +0100233
234################################################################################
235# strace
236################################################################################
237.PHONY: strace
238strace:
239 cd $(STRACE_PATH); \
240 ./bootstrap; \
241 set -e; \
Joakim Becheed6aa92018-01-16 10:02:23 +0100242 ./configure --host=$(MULTIARCH) --enable-mpers=no CC="$(CCACHE)$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)gcc" LD=$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)ld; \
Victor Chong05bb4ed2017-07-02 13:47:57 +0100243 CC="$(CCACHE)$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)gcc" LD=$(AARCH$(COMPILE_NS_USER)_CROSS_COMPILE)ld $(MAKE) -C $(STRACE_PATH)
244
245.PHONY: strace-clean
246strace-clean:
247 if [ -e $(STRACE_PATH)/Makefile ]; then $(MAKE) -C $(STRACE_PATH) clean; fi
248
249.PHONY: strace-cleaner
250strace-cleaner: strace-clean
251 rm -f $(STRACE_PATH)/Makefile $(STRACE_PATH)/configure
252
253################################################################################
254# Root FS
255################################################################################
Victor Chong05bb4ed2017-07-02 13:47:57 +0100256.PHONY: filelist-tee
Victor Chong86840a42017-10-28 13:01:33 +0100257filelist-tee: strace filelist-tee-common
Victor Chong05bb4ed2017-07-02 13:47:57 +0100258 env TOP=$(ROOT) $(expand-env-var) <$(PATCHES_PATH)/rootfs/initramfs-add-files.txt >> $(GEN_ROOTFS_FILELIST)
259
260.PHONY: update_rootfs
261update_rootfs: update_rootfs-common
262
263.PHONY: update_rootfs-clean
264update_rootfs-clean: update_rootfs-clean-common
265
266################################################################################
267# grub
268################################################################################
269grub-flags := CC="$(CCACHE)gcc" \
270 TARGET_CC="$(AARCH64_CROSS_COMPILE)gcc" \
271 TARGET_OBJCOPY="$(AARCH64_CROSS_COMPILE)objcopy" \
272 TARGET_NM="$(AARCH64_CROSS_COMPILE)nm" \
273 TARGET_RANLIB="$(AARCH64_CROSS_COMPILE)ranlib" \
274 TARGET_STRIP="$(AARCH64_CROSS_COMPILE)strip"
275
276GRUB_MODULES += boot chain configfile echo efinet eval ext2 fat font gettext \
277 gfxterm gzio help linux loadenv lsefi normal part_gpt \
278 part_msdos read regexp search search_fs_file search_fs_uuid \
279 search_label terminal terminfo test tftp time
280
281$(GRUB_PATH)/configure: $(GRUB_PATH)/configure.ac
282 cd $(GRUB_PATH) && ./autogen.sh
283
284$(GRUB_PATH)/Makefile: $(GRUB_PATH)/configure
285 cd $(GRUB_PATH) && ./configure --target=aarch64 --enable-boot-time $(grub-flags)
286
287.PHONY: grub
288grub: prepare $(GRUB_PATH)/Makefile
289 $(MAKE) -C $(GRUB_PATH); \
290 cd $(GRUB_PATH) && ./grub-mkimage \
291 --verbose \
292 --output=$(OUT_PATH)/grubaa64.efi \
293 --config=$(PATCHES_PATH)/grub/grub.configfile \
294 --format=arm64-efi \
295 --directory=grub-core \
296 --prefix=/boot/grub \
297 $(GRUB_MODULES)
298
299.PHONY: grub-clean
300grub-clean:
301 if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) clean; fi
302 rm -f $(OUT_PATH)/grubaa64.efi
303
304.PHONY: grub-cleaner
305grub-cleaner: grub-clean
306 if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) distclean; fi
307 rm -f $(GRUB_PATH)/configure
308
309################################################################################
310# Boot Image
311################################################################################
312ifeq ($(CFG_CONSOLE_UART),6)
313GRUBCFG = $(PATCHES_PATH)/grub/grub_uart6.cfg
314else
315GRUBCFG = $(PATCHES_PATH)/grub/grub_uart5.cfg
316endif
317
318.PHONY: boot-img
319boot-img: linux update_rootfs edk2 grub
320 rm -f $(BOOT_IMG)
321 mformat -i $(BOOT_IMG) -n 64 -h 255 -T 131072 -v "BOOT IMG" -C ::
322 mcopy -i $(BOOT_IMG) $(LINUX_PATH)/arch/arm64/boot/Image ::
323 mcopy -i $(BOOT_IMG) $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dtb ::
324 mmd -i $(BOOT_IMG) ::/EFI
325 mmd -i $(BOOT_IMG) ::/EFI/BOOT
326 mcopy -i $(BOOT_IMG) $(OUT_PATH)/grubaa64.efi ::/EFI/BOOT/
327 mcopy -i $(BOOT_IMG) $(GRUBCFG) ::/EFI/BOOT/grub.cfg
328 mcopy -i $(BOOT_IMG) $(GEN_ROOTFS_PATH)/filesystem.cpio.gz ::/initrd.img
329 mcopy -i $(BOOT_IMG) $(EDK2_PATH)/Build/HiKey960/$(EDK2_BUILD)_$(EDK2_TOOLCHAIN)/$(EDK2_ARCH)/AndroidFastbootApp.efi ::/EFI/BOOT/fastboot.efi
330
331.PHONY: boot-img-clean
332boot-img-clean:
333 rm -f $(BOOT_IMG)
334
335################################################################################
336# l-loader
337################################################################################
Victor Chong9860c922017-09-29 18:25:37 +0100338.PHONY: lloader
Jens Wiklandera51a4042017-10-09 13:30:24 +0200339lloader: arm-tf edk2
Victor Chong05bb4ed2017-07-02 13:47:57 +0100340 cd $(LLOADER_PATH) && \
341 ln -sf $(ARM_TF_PATH)/build/hikey960/$(ARM_TF_BUILD)/bl1.bin && \
Victor Chong9860c922017-09-29 18:25:37 +0100342 ln -sf $(EDK2_BIN) && \
343 $(MAKE) hikey960 PTABLE_LST=linux-32g
Victor Chong05bb4ed2017-07-02 13:47:57 +0100344
345.PHONY: lloader-clean
Victor Chong9860c922017-09-29 18:25:37 +0100346lloader-clean:
347 $(MAKE) -C $(LLOADER_PATH) hikey960-clean
Victor Chong05bb4ed2017-07-02 13:47:57 +0100348
349################################################################################
350# Flash
351################################################################################
352define flash_help
353 @read -r -p "Connect HiKey960 to power up (press enter)" dummy
354 @read -r -p "Connect USB OTG cable, the micro USB cable (press enter)" dummy
355endef
356
357.PHONY: recov_cfg
358recov_cfg:
359 @echo "./sec_usb_xloader.img 0x00020000" > $(IMAGE_TOOLS_CONFIG)
360 @echo "./sec_uce_boot.img 0x6A908000" >> $(IMAGE_TOOLS_CONFIG)
361 @echo "./l-loader.bin 0x1AC00000" >> $(IMAGE_TOOLS_CONFIG)
362
363.PHONY: recovery
364recovery: recov_cfg
365 @echo "Enter recovery mode to flash a new bootloader"
366 @echo
367 @echo "Make sure udev permissions are set appropriately:"
368 @echo " # /etc/udev/rules.d/hikey960.rules"
369 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d00d", MODE="0666"'
370 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"'
371 @echo
372 @echo "Set jumpers or switches as follows:"
373 @echo "Jumper 1-2: Closed or Switch 1: On"
374 @echo " 3-4: Closed or 2: On"
375 @echo " 5-6: Open or 3: Off"
376 @read -r -p "Press enter to continue" dummy
377 @echo
378 $(call flash_help)
379 @echo
380 @echo "Check the device node (/dev/ttyUSBx) of the micro USB connection"
381 @echo "Note the value x of the device node. Default is 1"
382 @read -r -p "Enter the device node. Press enter for /dev/ttyUSB1: " DEV && \
383 DEV=$${DEV:-/dev/ttyUSB1} && \
384 cd $(IMAGE_TOOLS_PATH) && \
Victor Chong73beda92017-08-14 08:26:26 +0100385 ln -sf $(LLOADER_PATH)/l-loader.bin && \
Victor Chong05bb4ed2017-07-02 13:47:57 +0100386 sudo ./hikey_idt -c $(IMAGE_TOOLS_CONFIG) -p $$DEV && \
387 rm -f $(IMAGE_TOOLS_CONFIG)
388 @echo
389 @echo "If you see dots starting to appear on the console,"
390 @echo "press f ON THE CONSOLE (NOT HERE!) to run fastboot."
391 @echo "You have 10 seconds! Go!"
392 @echo "If not, fastboot should load automatically."
393 @read -r -p "Press enter (HERE) to continue flashing" dummy
394 @$(MAKE) --no-print flash FROM_RECOVERY=1
395
396.PHONY: flash
397flash:
398ifneq ($(FROM_RECOVERY),1)
399 @echo "Flash binaries using fastboot"
400 @echo
401 @echo "Set jumpers or switches as follows:"
402 @echo "Jumper 1-2: Closed or Switch 1: On"
403 @echo " 3-4: Open or 2: Off"
404 @echo " 5-6: Closed or 3: On"
405 @read -r -p "Press enter to continue" dummy
406 @echo
407 $(call flash_help)
408endif
409 @echo "Wait until you see the (UART) message"
410 @echo " \"Android Fastboot mode - version x.x.\""
411 @echo " Press RETURN or SPACE key to quit.\""
412 @read -r -p "Then press enter to continue flashing" dummy
413 @echo
414 fastboot flash ptable $(LLOADER_PATH)/prm_ptable.img
415 fastboot flash xloader $(IMAGE_TOOLS_PATH)/sec_xloader.img
416 fastboot flash fastboot $(LLOADER_PATH)/l-loader.bin
417 fastboot flash fip $(ARM_TF_PATH)/build/hikey960/$(ARM_TF_BUILD)/fip.bin
418 fastboot flash nvme $(IMAGE_TOOLS_PATH)/nvme.img
419 fastboot flash boot $(BOOT_IMG)