blob: 8ae7eb52f6f8c80ace740e5991eae9bae88da6ae [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
Joakim Becha40320b2016-04-14 21:37:49 +020071DEBPKG_PATH ?= $(OUT_PATH)/optee_$(OPTEE_PKG_VERSION)
72DEBPKG_BIN_PATH ?= $(DEBPKG_PATH)/usr/bin
73DEBPKG_LIB_PATH ?= $(DEBPKG_PATH)/usr/lib/$(MULTIARCH)
74DEBPKG_TA_PATH ?= $(DEBPKG_PATH)/lib/optee_armtz
75DEBPKG_CONTROL_PATH ?= $(DEBPKG_PATH)/DEBIAN
76
77################################################################################
78# Targets
79################################################################################
80all: prepare arm-tf linux boot-img lloader system-img nvme deb
81
Sylvain Pelissier0fb23ea2017-01-11 10:48:53 +010082clean: arm-tf-clean edk2-clean linux-clean optee-os-clean optee-client-clean xtest-clean helloworld-clean boot-img-clean lloader-clean
Joakim Becha40320b2016-04-14 21:37:49 +020083
84cleaner: clean prepare-cleaner linux-cleaner nvme-cleaner system-img-cleaner
85
86-include toolchain.mk
87
88prepare:
89 @mkdir -p $(ROOT)/out
90
91.PHONY: prepare-cleaner
92prepare-cleaner:
93 rm -rf $(ROOT)/out
94
95################################################################################
96# ARM Trusted Firmware
97################################################################################
98ARM_TF_EXPORTS ?= \
99 CFLAGS="-O0 -gdwarf-2" \
100 CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
101
102ARM_TF_FLAGS ?= \
103 BL32=$(OPTEE_OS_BIN) \
104 BL33=$(EDK2_BIN) \
105 BL30=$(MCUIMAGE_BIN) \
106 DEBUG=$(DEBUG) \
107 PLAT=hikey \
108 SPD=opteed
109
110ARM_TF_CONSOLE_UART ?= $(CFG_SW_CONSOLE_UART)
111ifeq ($(ARM_TF_CONSOLE_UART),0)
112 ARM_TF_FLAGS += CONSOLE_BASE=PL011_UART0_BASE \
113 CRASH_CONSOLE_BASE=PL011_UART0_BASE
114endif
115
116arm-tf: optee-os edk2
117 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) all fip
118
119.PHONY: arm-tf-clean
120arm-tf-clean:
121 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) clean
122
123################################################################################
124# EDK2 / Tianocore
125################################################################################
126EDK2_VARS ?= EDK2_ARCH=AARCH64 \
127 EDK2_DSC=HisiPkg/HiKeyPkg/HiKey.dsc \
128 EDK2_TOOLCHAIN=GCC49 \
129 EDK2_BUILD=$(EDK2_BUILD)
130
131EDK2_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
132ifeq ($(EDK2_CONSOLE_UART),0)
133 EDK2_VARS += EDK2_MACROS="-DSERIAL_BASE=0xF8015000"
134endif
135
136define edk2-call
Joakim Bechf4543a72016-06-14 10:46:38 +0200137 GCC49_AARCH64_PREFIX=$(LEGACY_AARCH64_CROSS_COMPILE) \
Joakim Becha40320b2016-04-14 21:37:49 +0200138 $(MAKE) -j1 -C $(EDK2_PATH) \
139 -f HisiPkg/HiKeyPkg/Makefile $(EDK2_VARS)
140endef
141
142edk2: edk2-common
143
144.PHONY: edk2-clean
145edk2-clean: edk2-clean-common
146
147################################################################################
148# Linux kernel
149################################################################################
150LINUX_DEFCONFIG_COMMON_ARCH ?= arm64
151LINUX_DEFCONFIG_COMMON_FILES ?= $(LINUX_PATH)/arch/arm64/configs/defconfig \
Joakim Becha40320b2016-04-14 21:37:49 +0200152 $(CURDIR)/kconfigs/hikey_debian.conf
153
154linux-defconfig: $(LINUX_PATH)/.config
155
156LINUX_COMMON_FLAGS += ARCH=arm64 deb-pkg LOCALVERSION=-optee-rpb
157UPSTREAM_KERNEL := $(if $(wildcard $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dts),1,0)
158ifeq ($(UPSTREAM_KERNEL),0)
159LINUX_COMMON_FLAGS += hi6220-hikey.dtb
160DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hi6220-hikey.dtb
161else
162LINUX_COMMON_FLAGS += hisilicon/hi6220-hikey.dtb
163DTB = $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi6220-hikey.dtb
164endif
165
166linux: linux-common
167
168.PHONY: linux-defconfig-clean
169linux-defconfig-clean: linux-defconfig-clean-common
170
171LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
172
173.PHONY: linux-clean
174linux-clean: linux-clean-common
175
176LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
177
178.PHONY: linux-cleaner
179linux-cleaner: linux-cleaner-common
180
181################################################################################
182# OP-TEE
183################################################################################
Etienne Carrierecc23f6b2016-10-21 10:16:00 +0200184OPTEE_OS_COMMON_FLAGS += PLATFORM=hikey CFG_CONSOLE_UART=$(CFG_SW_CONSOLE_UART)
Joakim Becha40320b2016-04-14 21:37:49 +0200185OPTEE_OS_CLEAN_COMMON_FLAGS += PLATFORM=hikey
186
187optee-os: optee-os-common
188
189.PHONY: optee-os-clean
190optee-os-clean: optee-os-clean-common
191
192optee-client: optee-client-common
193
194.PHONY: optee-client-clean
195optee-client-clean: optee-client-clean-common
196
197################################################################################
198# xtest / optee_test
199################################################################################
200
201xtest: xtest-common
202
203# FIXME:
204# "make clean" in xtest: fails if optee_os has been cleaned previously
205.PHONY: xtest-clean
206xtest-clean: xtest-clean-common
207 rm -rf $(OPTEE_TEST_OUT_PATH)
208
209.PHONY: xtest-patch
210xtest-patch: xtest-patch-common
211
212################################################################################
Victor Chong8519bcf2016-07-15 08:43:03 +0100213# hello_world
214################################################################################
215helloworld: helloworld-common
216
217helloworld-clean: helloworld-clean-common
218
219################################################################################
Joakim Becha40320b2016-04-14 21:37:49 +0200220# Boot Image
221################################################################################
222.PHONY: boot-img
223boot-img:
224ifeq ("$(wildcard $(BOOT_IMG))","")
225 echo "Downloading Debian HiKey boot image ..."
226 wget $(BOOT_IMG_URL) -O $(BOOT_IMG).gz
227 gunzip $(BOOT_IMG).gz
228endif
229
230.PHONY: boot-img-clean
231boot-img-clean:
232 rm -f $(BOOT_IMG)
233
234################################################################################
235# system image
236################################################################################
237.PHONY: system-img
238system-img: prepare
239ifeq ("$(wildcard $(SYSTEM_IMG))","")
240 @echo "Downloading Debian root fs (730MB) ..."
241 wget $(SYSTEM_IMG_URL) -O $(SYSTEM_IMG).gz
242 gunzip $(SYSTEM_IMG).gz
243endif
244
245.PHONY: system-cleaner
246system-img-cleaner:
247 rm -f $(SYSTEM_IMG)
248
249################################################################################
250# l-loader
251################################################################################
252lloader: arm-tf
253 $(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
254
255.PHONY: lloader-clean
256lloader-clean:
257 $(MAKE) -C $(LLOADER_PATH) clean
258
259################################################################################
260# nvme image
261################################################################################
262.PHONY: nvme
263nvme: prepare
264ifeq ("$(wildcard $(NVME_IMG))","")
265 wget $(NVME_IMG_URL) -O $(NVME_IMG)
266endif
267
268.PHONY: nvme-cleaner
269nvme-cleaner:
270 rm -f $(NVME_IMG)
271
272################################################################################
273# Debian package
274################################################################################
275define CONTROL_TEXT
276Package: op-tee
277Version: $(OPTEE_PKG_VERSION)
278Section: base
279Priority: optional
280Architecture: arm64
281Depends:
282Maintainer: Joakim Bech <joakim.bech@linaro.org>
283Description: OP-TEE client binaries, test program and Trusted Applications
Victor Chong8519bcf2016-07-15 08:43:03 +0100284 Package contains tee-supplicant, libtee.so, xtest, hello_world and a set of
Joakim Becha40320b2016-04-14 21:37:49 +0200285 Trusted Applications.
286 NOTE! This package should only be used for testing and development.
287endef
288
289export CONTROL_TEXT
290
291.PHONY: deb
Victor Chong8519bcf2016-07-15 08:43:03 +0100292deb: xtest helloworld optee-client
Joakim Becha40320b2016-04-14 21:37:49 +0200293 @mkdir -p $(DEBPKG_BIN_PATH) && cd $(DEBPKG_BIN_PATH) && \
294 cp -f $(OPTEE_CLIENT_EXPORT)/bin/tee-supplicant . && \
Victor Chong8519bcf2016-07-15 08:43:03 +0100295 cp -f $(OPTEE_TEST_OUT_PATH)/xtest/xtest . && \
296 cp -f $(HELLOWORLD_PATH)/host/hello_world .
Joakim Becha40320b2016-04-14 21:37:49 +0200297
298 @mkdir -p $(DEBPKG_LIB_PATH) && cd $(DEBPKG_LIB_PATH) && \
299 cp $(OPTEE_CLIENT_EXPORT)/lib/libtee* .
300
301 @mkdir -p $(DEBPKG_TA_PATH) && cd $(DEBPKG_TA_PATH) && \
Victor Chong8519bcf2016-07-15 08:43:03 +0100302 cp $(HELLOWORLD_PATH)/ta/*.ta . && \
Joakim Becha40320b2016-04-14 21:37:49 +0200303 find $(OPTEE_TEST_OUT_PATH)/ta -name "*.ta" -exec cp {} . \;
304
305 @mkdir -p $(DEBPKG_CONTROL_PATH)
306 @echo "$$CONTROL_TEXT" > $(DEBPKG_CONTROL_PATH)/control
307 @cd $(OUT_PATH) && dpkg-deb --build optee_$(OPTEE_PKG_VERSION)
308
309################################################################################
310# Send built files to the host, note this require that the IP corresponds to
311# the device. One can run:
312# IP=111.222.333.444 make send
313# If you don't want to edit the makefile itself.
314################################################################################
315.PHONY: send
316send:
317 @tar czf - $(shell cd $(OUT_PATH) && echo $(OUT_PATH)/*.deb && echo $(ROOT)/linux-image-*.deb) | ssh linaro@$(IP) "cd /tmp; tar xvzf -"
318 @echo "Files has been sent to $$IP/tmp/ and $$IP/tmp/out"
319 @echo "On the device, run:"
320 @echo " dpkg --force-all -i /tmp/out/optee_$(OPTEE_PKG_VERSION).deb"
321 @echo " dpkg --force-all -i /tmp/linux-image-*.deb"
322
323################################################################################
324# Flash
325################################################################################
326define flash_help
327 @read -r -p "1. Connect USB OTG cable, the micro USB cable (press any key)" dummy
328 @read -r -p "2. Connect HiKey to power up (press any key)" dummy
329endef
330
331.PHONY: recovery
332recovery:
333 @echo "Enter recovery mode to flash a new bootloader"
Joakim Bech6f7c87a2017-01-10 10:20:37 +0100334 @echo
335 @echo "Make sure udev permissions are set appropriately:"
336 @echo " # /etc/udev/rules.d/hikey.rules"
337 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d00d", MODE="0666"'
338 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"'
339 @echo
Joakim Becha40320b2016-04-14 21:37:49 +0200340 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
341 @echo " 3-4: Closed (Boot Select = Recovery: program eMMC from USB OTG)"
342 $(call flash_help)
Joakim Bech6f7c87a2017-01-10 10:20:37 +0100343 python $(ROOT)/burn-boot/hisi-idt.py --img1=$(LLOADER_PATH)/l-loader.bin
Joakim Becha40320b2016-04-14 21:37:49 +0200344 @$(MAKE) --no-print flash FROM_RECOVERY=1
345
346.PHONY: flash
347flash:
348ifneq ($(FROM_RECOVERY),1)
349 @echo "Flash binaries using fastboot"
350 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
351 @echo " 3-4: Open (Boot Select = Boot from eMMC)"
352 @echo " 5-6: Closed (GPIO3-1 = Low: UEFI runs Fastboot app)"
353 $(call flash_help)
354 @echo "3. Wait until you see the (UART) message"
355 @echo " \"Android Fastboot mode - version x.x Press any key to quit.\""
356 @read -r -p " Then press any key to continue flashing" dummy
357endif
358 fastboot flash ptable $(LLOADER_PATH)/ptable-linux-4g.img
359 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
360 fastboot flash nvme $(NVME_IMG)
361 fastboot flash boot $(BOOT_IMG)
362 fastboot flash system $(SYSTEM_IMG)
363
364.PHONY: flash-fip
365flash-fip:
366 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
367
368.PHONY: flash-boot-img
369flash-boot-img: boot-img
370 fastboot flash boot $(BOOT_IMG)
371
372.PHONY: flash-system-img
373flash-system-img: system-img
374 fastboot flash system $(SYSTEM_IMG)
375
376.PHONY: help
377help:
378 @echo " 1. WiFi on HiKey debian"
379 @echo " ======================="
380 @echo " Open /etc/network/interfaces and add:"
381 @echo " allow-hotplug wlan0"
382 @echo " iface wlan0 inet dhcp"
383 @echo " wpa-ssid \"my-ssid\""
384 @echo " wpa-psk \"my-wifi-password\""
385 @echo " Reboot and you should have WiFi access"