blob: 832e3a083b4c207d8112a18c6e8846c259060850 [file] [log] [blame]
Joakim Becha40320b2016-04-14 21:37:49 +02001################################################################################
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/secure world console UARTs: 3 or 0 [default 3]
12# NOTE: For Debian build only UART 3 works until we have sorted out how to build
13# UEFI correcly.
14CFG_NW_CONSOLE_UART ?= 3
15CFG_SW_CONSOLE_UART ?= 3
16
17# TODO: Figure out how to handle this in a better way, but we need a version
18# number with major and minor for the debian packages.
19# <major version>.<minor version>-<package revision>
Joakim Bech6f7c87a2017-01-10 10:20:37 +010020OPTEE_PKG_VERSION ?= 2.3-0
Joakim Becha40320b2016-04-14 21:37:49 +020021
22# IP-address to the HiKey device
23IP ?= 127.0.0.1
24
25# URL to images
26SYSTEM_IMG_URL=https://builds.96boards.org/releases/reference-platform/debian/hikey/16.03/hikey-rootfs-debian-jessie-alip-20160301-68.emmc.img.gz
Joakim Bech6f7c87a2017-01-10 10:20:37 +010027BOOT_IMG_URL=https://builds.96boards.org/releases/reference-platform/debian/hikey/16.06/hikey-boot-linux-20160629-120.uefi.img.gz
Joakim Becha40320b2016-04-14 21:37:49 +020028NVME_IMG_URL=https://builds.96boards.org/releases/hikey/linaro/binaries/latest/nvme.img
29
30################################################################################
31# Includes
32################################################################################
33-include common.mk
34
35################################################################################
36# Mandatory definition to use common.mk
37################################################################################
38ifeq ($(COMPILE_NS_USER),64)
39MULTIARCH := aarch64-linux-gnu
40else
41MULTIARCH := arm-linux-gnueabihf
42endif
43
44################################################################################
45# Paths to git projects and various binaries
46################################################################################
47ARM_TF_PATH ?= $(ROOT)/arm-trusted-firmware
48ifeq ($(DEBUG),1)
49ARM_TF_BUILD ?= debug
50else
51ARM_TF_BUILD ?= release
52endif
53
54EDK2_PATH ?= $(ROOT)/edk2
55ifeq ($(DEBUG),1)
56EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey/DEBUG_GCC49/FV/BL33_AP_UEFI.fd
57EDK2_BUILD ?= DEBUG
58else
59EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey/RELEASE_GCC49/FV/BL33_AP_UEFI.fd
60EDK2_BUILD ?= RELEASE
61endif
62
63OUT_PATH ?= $(ROOT)/out
64MCUIMAGE_BIN ?= $(EDK2_PATH)/HisiPkg/HiKeyPkg/NonFree/mcuimage.bin
65BOOT_IMG ?= $(OUT_PATH)/boot-fat.uefi.img
66NVME_IMG ?= $(OUT_PATH)/nvme.img
67SYSTEM_IMG ?= $(OUT_PATH)/debian_system.img
68ROOTFS_PATH ?= $(OUT_PATH)/rootfs
69LLOADER_PATH ?= $(ROOT)/l-loader
70PATCHES_PATH ?= $(ROOT)/patches_hikey
71AESPERF_PATH ?= $(ROOT)/aes-perf
72SHAPERF_PATH ?= $(ROOT)/sha-perf
73DEBPKG_PATH ?= $(OUT_PATH)/optee_$(OPTEE_PKG_VERSION)
74DEBPKG_BIN_PATH ?= $(DEBPKG_PATH)/usr/bin
75DEBPKG_LIB_PATH ?= $(DEBPKG_PATH)/usr/lib/$(MULTIARCH)
76DEBPKG_TA_PATH ?= $(DEBPKG_PATH)/lib/optee_armtz
77DEBPKG_CONTROL_PATH ?= $(DEBPKG_PATH)/DEBIAN
78
79################################################################################
80# Targets
81################################################################################
82all: prepare arm-tf linux boot-img lloader system-img nvme deb
83
Victor Chong8519bcf2016-07-15 08:43:03 +010084clean: arm-tf-clean edk2-clean linux-clean optee-os-clean optee-client-clean xtest-clean helloworld-clean boot-img-clean lloader-clean aes-perf-clean sha-perf-clean
Joakim Becha40320b2016-04-14 21:37:49 +020085
86cleaner: clean prepare-cleaner linux-cleaner nvme-cleaner system-img-cleaner
87
88-include toolchain.mk
89
90prepare:
91 @mkdir -p $(ROOT)/out
92
93.PHONY: prepare-cleaner
94prepare-cleaner:
95 rm -rf $(ROOT)/out
96
97################################################################################
98# ARM Trusted Firmware
99################################################################################
100ARM_TF_EXPORTS ?= \
101 CFLAGS="-O0 -gdwarf-2" \
102 CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
103
104ARM_TF_FLAGS ?= \
105 BL32=$(OPTEE_OS_BIN) \
106 BL33=$(EDK2_BIN) \
107 BL30=$(MCUIMAGE_BIN) \
108 DEBUG=$(DEBUG) \
109 PLAT=hikey \
110 SPD=opteed
111
112ARM_TF_CONSOLE_UART ?= $(CFG_SW_CONSOLE_UART)
113ifeq ($(ARM_TF_CONSOLE_UART),0)
114 ARM_TF_FLAGS += CONSOLE_BASE=PL011_UART0_BASE \
115 CRASH_CONSOLE_BASE=PL011_UART0_BASE
116endif
117
118arm-tf: optee-os edk2
119 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) all fip
120
121.PHONY: arm-tf-clean
122arm-tf-clean:
123 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) clean
124
125################################################################################
126# EDK2 / Tianocore
127################################################################################
128EDK2_VARS ?= EDK2_ARCH=AARCH64 \
129 EDK2_DSC=HisiPkg/HiKeyPkg/HiKey.dsc \
130 EDK2_TOOLCHAIN=GCC49 \
131 EDK2_BUILD=$(EDK2_BUILD)
132
133EDK2_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
134ifeq ($(EDK2_CONSOLE_UART),0)
135 EDK2_VARS += EDK2_MACROS="-DSERIAL_BASE=0xF8015000"
136endif
137
138define edk2-call
Joakim Bechf4543a72016-06-14 10:46:38 +0200139 GCC49_AARCH64_PREFIX=$(LEGACY_AARCH64_CROSS_COMPILE) \
Joakim Becha40320b2016-04-14 21:37:49 +0200140 $(MAKE) -j1 -C $(EDK2_PATH) \
141 -f HisiPkg/HiKeyPkg/Makefile $(EDK2_VARS)
142endef
143
144edk2: edk2-common
145
146.PHONY: edk2-clean
147edk2-clean: edk2-clean-common
148
149################################################################################
150# Linux kernel
151################################################################################
152LINUX_DEFCONFIG_COMMON_ARCH ?= arm64
153LINUX_DEFCONFIG_COMMON_FILES ?= $(LINUX_PATH)/arch/arm64/configs/defconfig \
Joakim Becha40320b2016-04-14 21:37:49 +0200154 $(CURDIR)/kconfigs/hikey_debian.conf
155
156linux-defconfig: $(LINUX_PATH)/.config
157
158LINUX_COMMON_FLAGS += ARCH=arm64 deb-pkg LOCALVERSION=-optee-rpb
159UPSTREAM_KERNEL := $(if $(wildcard $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts),1,0)
160ifeq ($(UPSTREAM_KERNEL),0)
161LINUX_COMMON_FLAGS += hi6220-hikey.dtb
162DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hi6220-hikey.dtb
163else
164LINUX_COMMON_FLAGS += hisilicon/hi6220-hikey.dtb
165DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb
166endif
167
168linux: linux-common
169
170.PHONY: linux-defconfig-clean
171linux-defconfig-clean: linux-defconfig-clean-common
172
173LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
174
175.PHONY: linux-clean
176linux-clean: linux-clean-common
177
178LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
179
180.PHONY: linux-cleaner
181linux-cleaner: linux-cleaner-common
182
183################################################################################
184# OP-TEE
185################################################################################
Etienne Carrierecc23f6b2016-10-21 10:16:00 +0200186OPTEE_OS_COMMON_FLAGS += PLATFORM=hikey CFG_CONSOLE_UART=$(CFG_SW_CONSOLE_UART)
Joakim Becha40320b2016-04-14 21:37:49 +0200187OPTEE_OS_CLEAN_COMMON_FLAGS += PLATFORM=hikey
188
189optee-os: optee-os-common
190
191.PHONY: optee-os-clean
192optee-os-clean: optee-os-clean-common
193
194optee-client: optee-client-common
195
196.PHONY: optee-client-clean
197optee-client-clean: optee-client-clean-common
198
199################################################################################
200# xtest / optee_test
201################################################################################
202
203xtest: xtest-common
204
205# FIXME:
206# "make clean" in xtest: fails if optee_os has been cleaned previously
207.PHONY: xtest-clean
208xtest-clean: xtest-clean-common
209 rm -rf $(OPTEE_TEST_OUT_PATH)
210
211.PHONY: xtest-patch
212xtest-patch: xtest-patch-common
213
214################################################################################
Victor Chong8519bcf2016-07-15 08:43:03 +0100215# hello_world
216################################################################################
217helloworld: helloworld-common
218
219helloworld-clean: helloworld-clean-common
220
221################################################################################
Joakim Becha40320b2016-04-14 21:37:49 +0200222# aes-pef
223################################################################################
224PERF_FLAGS := CROSS_COMPILE_HOST=$(CROSS_COMPILE_NS_USER) \
225 CROSS_COMPILE_TA=$(CROSS_COMPILE_S_USER) \
226 TA_DEV_KIT_DIR=$(OPTEE_OS_TA_DEV_KIT_DIR)
227
228aes-perf: optee-os optee-client
229 $(MAKE) -C -j$(NPROC) $(AESPERF_PATH) $(PERF_FLAGS)
230
231.PHONY: aes-perf-clean
232aes-perf-clean:
233 rm -rf $(AESPERF_PATH)/out
234
235################################################################################
236# sha-perf
237################################################################################
238sha-perf: optee-os optee-client
239 $(MAKE) -C -j$(NPROC) $(SHAPERF_PATH) $(PERF_FLAGS)
240
241.PHONY: sha-perf-clean
242sha-perf-clean:
243 rm -rf $(SHAPERF_PATH)/out
244
245################################################################################
246# Boot Image
247################################################################################
248.PHONY: boot-img
249boot-img:
250ifeq ("$(wildcard $(BOOT_IMG))","")
251 echo "Downloading Debian HiKey boot image ..."
252 wget $(BOOT_IMG_URL) -O $(BOOT_IMG).gz
253 gunzip $(BOOT_IMG).gz
254endif
255
256.PHONY: boot-img-clean
257boot-img-clean:
258 rm -f $(BOOT_IMG)
259
260################################################################################
261# system image
262################################################################################
263.PHONY: system-img
264system-img: prepare
265ifeq ("$(wildcard $(SYSTEM_IMG))","")
266 @echo "Downloading Debian root fs (730MB) ..."
267 wget $(SYSTEM_IMG_URL) -O $(SYSTEM_IMG).gz
268 gunzip $(SYSTEM_IMG).gz
269endif
270
271.PHONY: system-cleaner
272system-img-cleaner:
273 rm -f $(SYSTEM_IMG)
274
275################################################################################
276# l-loader
277################################################################################
278lloader: arm-tf
279 $(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
280
281.PHONY: lloader-clean
282lloader-clean:
283 $(MAKE) -C $(LLOADER_PATH) clean
284
285################################################################################
286# nvme image
287################################################################################
288.PHONY: nvme
289nvme: prepare
290ifeq ("$(wildcard $(NVME_IMG))","")
291 wget $(NVME_IMG_URL) -O $(NVME_IMG)
292endif
293
294.PHONY: nvme-cleaner
295nvme-cleaner:
296 rm -f $(NVME_IMG)
297
298################################################################################
299# Debian package
300################################################################################
301define CONTROL_TEXT
302Package: op-tee
303Version: $(OPTEE_PKG_VERSION)
304Section: base
305Priority: optional
306Architecture: arm64
307Depends:
308Maintainer: Joakim Bech <joakim.bech@linaro.org>
309Description: OP-TEE client binaries, test program and Trusted Applications
Victor Chong8519bcf2016-07-15 08:43:03 +0100310 Package contains tee-supplicant, libtee.so, xtest, hello_world and a set of
Joakim Becha40320b2016-04-14 21:37:49 +0200311 Trusted Applications.
312 NOTE! This package should only be used for testing and development.
313endef
314
315export CONTROL_TEXT
316
317.PHONY: deb
Victor Chong8519bcf2016-07-15 08:43:03 +0100318deb: xtest helloworld optee-client
Joakim Becha40320b2016-04-14 21:37:49 +0200319 @mkdir -p $(DEBPKG_BIN_PATH) && cd $(DEBPKG_BIN_PATH) && \
320 cp -f $(OPTEE_CLIENT_EXPORT)/bin/tee-supplicant . && \
Victor Chong8519bcf2016-07-15 08:43:03 +0100321 cp -f $(OPTEE_TEST_OUT_PATH)/xtest/xtest . && \
322 cp -f $(HELLOWORLD_PATH)/host/hello_world .
Joakim Becha40320b2016-04-14 21:37:49 +0200323
324 @mkdir -p $(DEBPKG_LIB_PATH) && cd $(DEBPKG_LIB_PATH) && \
325 cp $(OPTEE_CLIENT_EXPORT)/lib/libtee* .
326
327 @mkdir -p $(DEBPKG_TA_PATH) && cd $(DEBPKG_TA_PATH) && \
Victor Chong8519bcf2016-07-15 08:43:03 +0100328 cp $(HELLOWORLD_PATH)/ta/*.ta . && \
Joakim Becha40320b2016-04-14 21:37:49 +0200329 find $(OPTEE_TEST_OUT_PATH)/ta -name "*.ta" -exec cp {} . \;
330
331 @mkdir -p $(DEBPKG_CONTROL_PATH)
332 @echo "$$CONTROL_TEXT" > $(DEBPKG_CONTROL_PATH)/control
333 @cd $(OUT_PATH) && dpkg-deb --build optee_$(OPTEE_PKG_VERSION)
334
335################################################################################
336# Send built files to the host, note this require that the IP corresponds to
337# the device. One can run:
338# IP=111.222.333.444 make send
339# If you don't want to edit the makefile itself.
340################################################################################
341.PHONY: send
342send:
343 @tar czf - $(shell cd $(OUT_PATH) && echo $(OUT_PATH)/*.deb && echo $(ROOT)/linux-image-*.deb) | ssh linaro@$(IP) "cd /tmp; tar xvzf -"
344 @echo "Files has been sent to $$IP/tmp/ and $$IP/tmp/out"
345 @echo "On the device, run:"
346 @echo " dpkg --force-all -i /tmp/out/optee_$(OPTEE_PKG_VERSION).deb"
347 @echo " dpkg --force-all -i /tmp/linux-image-*.deb"
348
349################################################################################
350# Flash
351################################################################################
352define flash_help
353 @read -r -p "1. Connect USB OTG cable, the micro USB cable (press any key)" dummy
354 @read -r -p "2. Connect HiKey to power up (press any key)" dummy
355endef
356
357.PHONY: recovery
358recovery:
359 @echo "Enter recovery mode to flash a new bootloader"
Joakim Bech6f7c87a2017-01-10 10:20:37 +0100360 @echo
361 @echo "Make sure udev permissions are set appropriately:"
362 @echo " # /etc/udev/rules.d/hikey.rules"
363 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d00d", MODE="0666"'
364 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"'
365 @echo
Joakim Becha40320b2016-04-14 21:37:49 +0200366 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
367 @echo " 3-4: Closed (Boot Select = Recovery: program eMMC from USB OTG)"
368 $(call flash_help)
Joakim Bech6f7c87a2017-01-10 10:20:37 +0100369 python $(ROOT)/burn-boot/hisi-idt.py --img1=$(LLOADER_PATH)/l-loader.bin
Joakim Becha40320b2016-04-14 21:37:49 +0200370 @$(MAKE) --no-print flash FROM_RECOVERY=1
371
372.PHONY: flash
373flash:
374ifneq ($(FROM_RECOVERY),1)
375 @echo "Flash binaries using fastboot"
376 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
377 @echo " 3-4: Open (Boot Select = Boot from eMMC)"
378 @echo " 5-6: Closed (GPIO3-1 = Low: UEFI runs Fastboot app)"
379 $(call flash_help)
380 @echo "3. Wait until you see the (UART) message"
381 @echo " \"Android Fastboot mode - version x.x Press any key to quit.\""
382 @read -r -p " Then press any key to continue flashing" dummy
383endif
384 fastboot flash ptable $(LLOADER_PATH)/ptable-linux-4g.img
385 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
386 fastboot flash nvme $(NVME_IMG)
387 fastboot flash boot $(BOOT_IMG)
388 fastboot flash system $(SYSTEM_IMG)
389
390.PHONY: flash-fip
391flash-fip:
392 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
393
394.PHONY: flash-boot-img
395flash-boot-img: boot-img
396 fastboot flash boot $(BOOT_IMG)
397
398.PHONY: flash-system-img
399flash-system-img: system-img
400 fastboot flash system $(SYSTEM_IMG)
401
402.PHONY: help
403help:
404 @echo " 1. WiFi on HiKey debian"
405 @echo " ======================="
406 @echo " Open /etc/network/interfaces and add:"
407 @echo " allow-hotplug wlan0"
408 @echo " iface wlan0 inet dhcp"
409 @echo " wpa-ssid \"my-ssid\""
410 @echo " wpa-psk \"my-wifi-password\""
411 @echo " Reboot and you should have WiFi access"