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