blob: 4fedd2a9bb2c75b3d7ea8003b6d62be109798a76 [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>
20OPTEE_PKG_VERSION ?= 2.0-1
21
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
27BOOT_IMG_URL=https://builds.96boards.org/releases/reference-platform/debian/hikey/16.03/hikey-boot-linux-20160301-68.uefi.img.gz
28NVME_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 \
154 $(LINUX_PATH)/arch/arm64/configs/distro.config \
155 $(CURDIR)/kconfigs/hikey_debian.conf
156
157linux-defconfig: $(LINUX_PATH)/.config
158
159LINUX_COMMON_FLAGS += ARCH=arm64 deb-pkg LOCALVERSION=-optee-rpb
160UPSTREAM_KERNEL := $(if $(wildcard $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts),1,0)
161ifeq ($(UPSTREAM_KERNEL),0)
162LINUX_COMMON_FLAGS += hi6220-hikey.dtb
163DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hi6220-hikey.dtb
164else
165LINUX_COMMON_FLAGS += hisilicon/hi6220-hikey.dtb
166DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb
167endif
168
169linux: linux-common
170
171.PHONY: linux-defconfig-clean
172linux-defconfig-clean: linux-defconfig-clean-common
173
174LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
175
176.PHONY: linux-clean
177linux-clean: linux-clean-common
178
179LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
180
181.PHONY: linux-cleaner
182linux-cleaner: linux-cleaner-common
183
184################################################################################
185# OP-TEE
186################################################################################
Etienne Carrierecc23f6b2016-10-21 10:16:00 +0200187OPTEE_OS_COMMON_FLAGS += PLATFORM=hikey CFG_CONSOLE_UART=$(CFG_SW_CONSOLE_UART)
Joakim Becha40320b2016-04-14 21:37:49 +0200188OPTEE_OS_CLEAN_COMMON_FLAGS += PLATFORM=hikey
189
190optee-os: optee-os-common
191
192.PHONY: optee-os-clean
193optee-os-clean: optee-os-clean-common
194
195optee-client: optee-client-common
196
197.PHONY: optee-client-clean
198optee-client-clean: optee-client-clean-common
199
200################################################################################
201# xtest / optee_test
202################################################################################
203
204xtest: xtest-common
205
206# FIXME:
207# "make clean" in xtest: fails if optee_os has been cleaned previously
208.PHONY: xtest-clean
209xtest-clean: xtest-clean-common
210 rm -rf $(OPTEE_TEST_OUT_PATH)
211
212.PHONY: xtest-patch
213xtest-patch: xtest-patch-common
214
215################################################################################
Victor Chong8519bcf2016-07-15 08:43:03 +0100216# hello_world
217################################################################################
218helloworld: helloworld-common
219
220helloworld-clean: helloworld-clean-common
221
222################################################################################
Joakim Becha40320b2016-04-14 21:37:49 +0200223# aes-pef
224################################################################################
225PERF_FLAGS := CROSS_COMPILE_HOST=$(CROSS_COMPILE_NS_USER) \
226 CROSS_COMPILE_TA=$(CROSS_COMPILE_S_USER) \
227 TA_DEV_KIT_DIR=$(OPTEE_OS_TA_DEV_KIT_DIR)
228
229aes-perf: optee-os optee-client
230 $(MAKE) -C -j$(NPROC) $(AESPERF_PATH) $(PERF_FLAGS)
231
232.PHONY: aes-perf-clean
233aes-perf-clean:
234 rm -rf $(AESPERF_PATH)/out
235
236################################################################################
237# sha-perf
238################################################################################
239sha-perf: optee-os optee-client
240 $(MAKE) -C -j$(NPROC) $(SHAPERF_PATH) $(PERF_FLAGS)
241
242.PHONY: sha-perf-clean
243sha-perf-clean:
244 rm -rf $(SHAPERF_PATH)/out
245
246################################################################################
247# Boot Image
248################################################################################
249.PHONY: boot-img
250boot-img:
251ifeq ("$(wildcard $(BOOT_IMG))","")
252 echo "Downloading Debian HiKey boot image ..."
253 wget $(BOOT_IMG_URL) -O $(BOOT_IMG).gz
254 gunzip $(BOOT_IMG).gz
255endif
256
257.PHONY: boot-img-clean
258boot-img-clean:
259 rm -f $(BOOT_IMG)
260
261################################################################################
262# system image
263################################################################################
264.PHONY: system-img
265system-img: prepare
266ifeq ("$(wildcard $(SYSTEM_IMG))","")
267 @echo "Downloading Debian root fs (730MB) ..."
268 wget $(SYSTEM_IMG_URL) -O $(SYSTEM_IMG).gz
269 gunzip $(SYSTEM_IMG).gz
270endif
271
272.PHONY: system-cleaner
273system-img-cleaner:
274 rm -f $(SYSTEM_IMG)
275
276################################################################################
277# l-loader
278################################################################################
279lloader: arm-tf
280 $(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
281
282.PHONY: lloader-clean
283lloader-clean:
284 $(MAKE) -C $(LLOADER_PATH) clean
285
286################################################################################
287# nvme image
288################################################################################
289.PHONY: nvme
290nvme: prepare
291ifeq ("$(wildcard $(NVME_IMG))","")
292 wget $(NVME_IMG_URL) -O $(NVME_IMG)
293endif
294
295.PHONY: nvme-cleaner
296nvme-cleaner:
297 rm -f $(NVME_IMG)
298
299################################################################################
300# Debian package
301################################################################################
302define CONTROL_TEXT
303Package: op-tee
304Version: $(OPTEE_PKG_VERSION)
305Section: base
306Priority: optional
307Architecture: arm64
308Depends:
309Maintainer: Joakim Bech <joakim.bech@linaro.org>
310Description: OP-TEE client binaries, test program and Trusted Applications
Victor Chong8519bcf2016-07-15 08:43:03 +0100311 Package contains tee-supplicant, libtee.so, xtest, hello_world and a set of
Joakim Becha40320b2016-04-14 21:37:49 +0200312 Trusted Applications.
313 NOTE! This package should only be used for testing and development.
314endef
315
316export CONTROL_TEXT
317
318.PHONY: deb
Victor Chong8519bcf2016-07-15 08:43:03 +0100319deb: xtest helloworld optee-client
Joakim Becha40320b2016-04-14 21:37:49 +0200320 @mkdir -p $(DEBPKG_BIN_PATH) && cd $(DEBPKG_BIN_PATH) && \
321 cp -f $(OPTEE_CLIENT_EXPORT)/bin/tee-supplicant . && \
Victor Chong8519bcf2016-07-15 08:43:03 +0100322 cp -f $(OPTEE_TEST_OUT_PATH)/xtest/xtest . && \
323 cp -f $(HELLOWORLD_PATH)/host/hello_world .
Joakim Becha40320b2016-04-14 21:37:49 +0200324
325 @mkdir -p $(DEBPKG_LIB_PATH) && cd $(DEBPKG_LIB_PATH) && \
326 cp $(OPTEE_CLIENT_EXPORT)/lib/libtee* .
327
328 @mkdir -p $(DEBPKG_TA_PATH) && cd $(DEBPKG_TA_PATH) && \
Victor Chong8519bcf2016-07-15 08:43:03 +0100329 cp $(HELLOWORLD_PATH)/ta/*.ta . && \
Joakim Becha40320b2016-04-14 21:37:49 +0200330 find $(OPTEE_TEST_OUT_PATH)/ta -name "*.ta" -exec cp {} . \;
331
332 @mkdir -p $(DEBPKG_CONTROL_PATH)
333 @echo "$$CONTROL_TEXT" > $(DEBPKG_CONTROL_PATH)/control
334 @cd $(OUT_PATH) && dpkg-deb --build optee_$(OPTEE_PKG_VERSION)
335
336################################################################################
337# Send built files to the host, note this require that the IP corresponds to
338# the device. One can run:
339# IP=111.222.333.444 make send
340# If you don't want to edit the makefile itself.
341################################################################################
342.PHONY: send
343send:
344 @tar czf - $(shell cd $(OUT_PATH) && echo $(OUT_PATH)/*.deb && echo $(ROOT)/linux-image-*.deb) | ssh linaro@$(IP) "cd /tmp; tar xvzf -"
345 @echo "Files has been sent to $$IP/tmp/ and $$IP/tmp/out"
346 @echo "On the device, run:"
347 @echo " dpkg --force-all -i /tmp/out/optee_$(OPTEE_PKG_VERSION).deb"
348 @echo " dpkg --force-all -i /tmp/linux-image-*.deb"
349
350################################################################################
351# Flash
352################################################################################
353define flash_help
354 @read -r -p "1. Connect USB OTG cable, the micro USB cable (press any key)" dummy
355 @read -r -p "2. Connect HiKey to power up (press any key)" dummy
356endef
357
358.PHONY: recovery
359recovery:
360 @echo "Enter recovery mode to flash a new bootloader"
361 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
362 @echo " 3-4: Closed (Boot Select = Recovery: program eMMC from USB OTG)"
363 $(call flash_help)
364 sudo python $(ROOT)/burn-boot/hisi-idt.py --img1=$(LLOADER_PATH)/l-loader.bin
365 @$(MAKE) --no-print flash FROM_RECOVERY=1
366
367.PHONY: flash
368flash:
369ifneq ($(FROM_RECOVERY),1)
370 @echo "Flash binaries using fastboot"
371 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
372 @echo " 3-4: Open (Boot Select = Boot from eMMC)"
373 @echo " 5-6: Closed (GPIO3-1 = Low: UEFI runs Fastboot app)"
374 $(call flash_help)
375 @echo "3. Wait until you see the (UART) message"
376 @echo " \"Android Fastboot mode - version x.x Press any key to quit.\""
377 @read -r -p " Then press any key to continue flashing" dummy
378endif
379 fastboot flash ptable $(LLOADER_PATH)/ptable-linux-4g.img
380 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
381 fastboot flash nvme $(NVME_IMG)
382 fastboot flash boot $(BOOT_IMG)
383 fastboot flash system $(SYSTEM_IMG)
384
385.PHONY: flash-fip
386flash-fip:
387 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
388
389.PHONY: flash-boot-img
390flash-boot-img: boot-img
391 fastboot flash boot $(BOOT_IMG)
392
393.PHONY: flash-system-img
394flash-system-img: system-img
395 fastboot flash system $(SYSTEM_IMG)
396
397.PHONY: help
398help:
399 @echo " 1. WiFi on HiKey debian"
400 @echo " ======================="
401 @echo " Open /etc/network/interfaces and add:"
402 @echo " allow-hotplug wlan0"
403 @echo " iface wlan0 inet dhcp"
404 @echo " wpa-ssid \"my-ssid\""
405 @echo " wpa-psk \"my-wifi-password\""
406 @echo " Reboot and you should have WiFi access"