blob: 19b58c52ee92d89a4f234fa99250c1c3610513b4 [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
Victor Chong310ca4d2017-01-22 07:00:19 +000017# eMMC flash size: 8 or 4 GB [default 8]
18CFG_FLASH_SIZE ?= 8
19
Joakim Becha40320b2016-04-14 21:37:49 +020020# TODO: Figure out how to handle this in a better way, but we need a version
21# number with major and minor for the debian packages.
22# <major version>.<minor version>-<package revision>
Joakim Bech6f7c87a2017-01-10 10:20:37 +010023OPTEE_PKG_VERSION ?= 2.3-0
Joakim Becha40320b2016-04-14 21:37:49 +020024
25# IP-address to the HiKey device
26IP ?= 127.0.0.1
27
28# URL to images
Victor Chong5f499892017-03-03 17:20:48 +000029SYSTEM_IMG_URL=https://builds.96boards.org/releases/reference-platform/debian/hikey/16.06/hikey-rootfs-debian-jessie-alip-20160629-120.emmc.img.gz
Joakim Bech6f7c87a2017-01-10 10:20:37 +010030BOOT_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 +020031NVME_IMG_URL=https://builds.96boards.org/releases/hikey/linaro/binaries/latest/nvme.img
32
33################################################################################
34# Includes
35################################################################################
36-include common.mk
37
38################################################################################
39# Mandatory definition to use common.mk
40################################################################################
41ifeq ($(COMPILE_NS_USER),64)
42MULTIARCH := aarch64-linux-gnu
43else
44MULTIARCH := arm-linux-gnueabihf
45endif
46
47################################################################################
48# Paths to git projects and various binaries
49################################################################################
50ARM_TF_PATH ?= $(ROOT)/arm-trusted-firmware
51ifeq ($(DEBUG),1)
52ARM_TF_BUILD ?= debug
53else
54ARM_TF_BUILD ?= release
55endif
56
57EDK2_PATH ?= $(ROOT)/edk2
58ifeq ($(DEBUG),1)
59EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey/DEBUG_GCC49/FV/BL33_AP_UEFI.fd
60EDK2_BUILD ?= DEBUG
61else
62EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey/RELEASE_GCC49/FV/BL33_AP_UEFI.fd
63EDK2_BUILD ?= RELEASE
64endif
65
66OUT_PATH ?= $(ROOT)/out
67MCUIMAGE_BIN ?= $(EDK2_PATH)/HisiPkg/HiKeyPkg/NonFree/mcuimage.bin
68BOOT_IMG ?= $(OUT_PATH)/boot-fat.uefi.img
69NVME_IMG ?= $(OUT_PATH)/nvme.img
70SYSTEM_IMG ?= $(OUT_PATH)/debian_system.img
71ROOTFS_PATH ?= $(OUT_PATH)/rootfs
72LLOADER_PATH ?= $(ROOT)/l-loader
73PATCHES_PATH ?= $(ROOT)/patches_hikey
Joakim Becha40320b2016-04-14 21:37:49 +020074DEBPKG_PATH ?= $(OUT_PATH)/optee_$(OPTEE_PKG_VERSION)
75DEBPKG_BIN_PATH ?= $(DEBPKG_PATH)/usr/bin
76DEBPKG_LIB_PATH ?= $(DEBPKG_PATH)/usr/lib/$(MULTIARCH)
77DEBPKG_TA_PATH ?= $(DEBPKG_PATH)/lib/optee_armtz
78DEBPKG_CONTROL_PATH ?= $(DEBPKG_PATH)/DEBIAN
79
80################################################################################
81# Targets
82################################################################################
83all: prepare arm-tf linux boot-img lloader system-img nvme deb
84
Sylvain Pelissier0fb23ea2017-01-11 10:48:53 +010085clean: 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 +020086
87cleaner: clean prepare-cleaner linux-cleaner nvme-cleaner system-img-cleaner
88
89-include toolchain.mk
90
91prepare:
92 @mkdir -p $(ROOT)/out
93
94.PHONY: prepare-cleaner
95prepare-cleaner:
96 rm -rf $(ROOT)/out
97
98################################################################################
99# ARM Trusted Firmware
100################################################################################
101ARM_TF_EXPORTS ?= \
102 CFLAGS="-O0 -gdwarf-2" \
103 CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
104
105ARM_TF_FLAGS ?= \
106 BL32=$(OPTEE_OS_BIN) \
107 BL33=$(EDK2_BIN) \
108 BL30=$(MCUIMAGE_BIN) \
109 DEBUG=$(DEBUG) \
110 PLAT=hikey \
111 SPD=opteed
112
113ARM_TF_CONSOLE_UART ?= $(CFG_SW_CONSOLE_UART)
114ifeq ($(ARM_TF_CONSOLE_UART),0)
115 ARM_TF_FLAGS += CONSOLE_BASE=PL011_UART0_BASE \
116 CRASH_CONSOLE_BASE=PL011_UART0_BASE
117endif
118
119arm-tf: optee-os edk2
120 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) all fip
121
122.PHONY: arm-tf-clean
123arm-tf-clean:
124 $(ARM_TF_EXPORTS) $(MAKE) -C $(ARM_TF_PATH) $(ARM_TF_FLAGS) clean
125
126################################################################################
127# EDK2 / Tianocore
128################################################################################
129EDK2_VARS ?= EDK2_ARCH=AARCH64 \
130 EDK2_DSC=HisiPkg/HiKeyPkg/HiKey.dsc \
131 EDK2_TOOLCHAIN=GCC49 \
132 EDK2_BUILD=$(EDK2_BUILD)
133
134EDK2_CONSOLE_UART ?= $(CFG_NW_CONSOLE_UART)
135ifeq ($(EDK2_CONSOLE_UART),0)
136 EDK2_VARS += EDK2_MACROS="-DSERIAL_BASE=0xF8015000"
137endif
138
139define edk2-call
Joakim Bechf4543a72016-06-14 10:46:38 +0200140 GCC49_AARCH64_PREFIX=$(LEGACY_AARCH64_CROSS_COMPILE) \
Joakim Becha40320b2016-04-14 21:37:49 +0200141 $(MAKE) -j1 -C $(EDK2_PATH) \
142 -f HisiPkg/HiKeyPkg/Makefile $(EDK2_VARS)
143endef
144
145edk2: edk2-common
146
147.PHONY: edk2-clean
148edk2-clean: edk2-clean-common
149
150################################################################################
151# Linux kernel
152################################################################################
153LINUX_DEFCONFIG_COMMON_ARCH ?= arm64
154LINUX_DEFCONFIG_COMMON_FILES ?= $(LINUX_PATH)/arch/arm64/configs/defconfig \
Joakim Becha40320b2016-04-14 21:37:49 +0200155 $(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# Boot Image
224################################################################################
225.PHONY: boot-img
226boot-img:
227ifeq ("$(wildcard $(BOOT_IMG))","")
228 echo "Downloading Debian HiKey boot image ..."
229 wget $(BOOT_IMG_URL) -O $(BOOT_IMG).gz
230 gunzip $(BOOT_IMG).gz
231endif
232
233.PHONY: boot-img-clean
234boot-img-clean:
235 rm -f $(BOOT_IMG)
236
237################################################################################
238# system image
239################################################################################
240.PHONY: system-img
241system-img: prepare
242ifeq ("$(wildcard $(SYSTEM_IMG))","")
243 @echo "Downloading Debian root fs (730MB) ..."
244 wget $(SYSTEM_IMG_URL) -O $(SYSTEM_IMG).gz
245 gunzip $(SYSTEM_IMG).gz
246endif
247
248.PHONY: system-cleaner
249system-img-cleaner:
250 rm -f $(SYSTEM_IMG)
251
252################################################################################
253# l-loader
254################################################################################
255lloader: arm-tf
Victor Chong310ca4d2017-01-22 07:00:19 +0000256 $(MAKE) -C $(LLOADER_PATH) BL1=$(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/bl1.bin CROSS_COMPILE="$(CCACHE)$(AARCH32_CROSS_COMPILE)" PTABLE_LST=linux-$(CFG_FLASH_SIZE)g
Joakim Becha40320b2016-04-14 21:37:49 +0200257
258.PHONY: lloader-clean
259lloader-clean:
260 $(MAKE) -C $(LLOADER_PATH) clean
261
262################################################################################
263# nvme image
264################################################################################
265.PHONY: nvme
266nvme: prepare
267ifeq ("$(wildcard $(NVME_IMG))","")
268 wget $(NVME_IMG_URL) -O $(NVME_IMG)
269endif
270
271.PHONY: nvme-cleaner
272nvme-cleaner:
273 rm -f $(NVME_IMG)
274
275################################################################################
276# Debian package
277################################################################################
278define CONTROL_TEXT
279Package: op-tee
280Version: $(OPTEE_PKG_VERSION)
281Section: base
282Priority: optional
283Architecture: arm64
284Depends:
285Maintainer: Joakim Bech <joakim.bech@linaro.org>
286Description: OP-TEE client binaries, test program and Trusted Applications
Victor Chong8519bcf2016-07-15 08:43:03 +0100287 Package contains tee-supplicant, libtee.so, xtest, hello_world and a set of
Joakim Becha40320b2016-04-14 21:37:49 +0200288 Trusted Applications.
289 NOTE! This package should only be used for testing and development.
290endef
291
292export CONTROL_TEXT
293
294.PHONY: deb
Victor Chong8519bcf2016-07-15 08:43:03 +0100295deb: xtest helloworld optee-client
Joakim Becha40320b2016-04-14 21:37:49 +0200296 @mkdir -p $(DEBPKG_BIN_PATH) && cd $(DEBPKG_BIN_PATH) && \
297 cp -f $(OPTEE_CLIENT_EXPORT)/bin/tee-supplicant . && \
Victor Chong8519bcf2016-07-15 08:43:03 +0100298 cp -f $(OPTEE_TEST_OUT_PATH)/xtest/xtest . && \
299 cp -f $(HELLOWORLD_PATH)/host/hello_world .
Joakim Becha40320b2016-04-14 21:37:49 +0200300
301 @mkdir -p $(DEBPKG_LIB_PATH) && cd $(DEBPKG_LIB_PATH) && \
302 cp $(OPTEE_CLIENT_EXPORT)/lib/libtee* .
303
304 @mkdir -p $(DEBPKG_TA_PATH) && cd $(DEBPKG_TA_PATH) && \
Victor Chong8519bcf2016-07-15 08:43:03 +0100305 cp $(HELLOWORLD_PATH)/ta/*.ta . && \
Joakim Becha40320b2016-04-14 21:37:49 +0200306 find $(OPTEE_TEST_OUT_PATH)/ta -name "*.ta" -exec cp {} . \;
307
308 @mkdir -p $(DEBPKG_CONTROL_PATH)
309 @echo "$$CONTROL_TEXT" > $(DEBPKG_CONTROL_PATH)/control
310 @cd $(OUT_PATH) && dpkg-deb --build optee_$(OPTEE_PKG_VERSION)
311
312################################################################################
313# Send built files to the host, note this require that the IP corresponds to
314# the device. One can run:
315# IP=111.222.333.444 make send
316# If you don't want to edit the makefile itself.
317################################################################################
318.PHONY: send
319send:
320 @tar czf - $(shell cd $(OUT_PATH) && echo $(OUT_PATH)/*.deb && echo $(ROOT)/linux-image-*.deb) | ssh linaro@$(IP) "cd /tmp; tar xvzf -"
321 @echo "Files has been sent to $$IP/tmp/ and $$IP/tmp/out"
322 @echo "On the device, run:"
323 @echo " dpkg --force-all -i /tmp/out/optee_$(OPTEE_PKG_VERSION).deb"
324 @echo " dpkg --force-all -i /tmp/linux-image-*.deb"
325
326################################################################################
327# Flash
328################################################################################
329define flash_help
330 @read -r -p "1. Connect USB OTG cable, the micro USB cable (press any key)" dummy
331 @read -r -p "2. Connect HiKey to power up (press any key)" dummy
332endef
333
334.PHONY: recovery
335recovery:
336 @echo "Enter recovery mode to flash a new bootloader"
Joakim Bech6f7c87a2017-01-10 10:20:37 +0100337 @echo
338 @echo "Make sure udev permissions are set appropriately:"
339 @echo " # /etc/udev/rules.d/hikey.rules"
340 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d00d", MODE="0666"'
341 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"'
342 @echo
Joakim Becha40320b2016-04-14 21:37:49 +0200343 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
344 @echo " 3-4: Closed (Boot Select = Recovery: program eMMC from USB OTG)"
345 $(call flash_help)
Joakim Bech6f7c87a2017-01-10 10:20:37 +0100346 python $(ROOT)/burn-boot/hisi-idt.py --img1=$(LLOADER_PATH)/l-loader.bin
Joakim Becha40320b2016-04-14 21:37:49 +0200347 @$(MAKE) --no-print flash FROM_RECOVERY=1
348
349.PHONY: flash
350flash:
351ifneq ($(FROM_RECOVERY),1)
352 @echo "Flash binaries using fastboot"
353 @echo "Jumper 1-2: Closed (Auto power up = Boot up when power is applied)"
354 @echo " 3-4: Open (Boot Select = Boot from eMMC)"
355 @echo " 5-6: Closed (GPIO3-1 = Low: UEFI runs Fastboot app)"
356 $(call flash_help)
357 @echo "3. Wait until you see the (UART) message"
358 @echo " \"Android Fastboot mode - version x.x Press any key to quit.\""
359 @read -r -p " Then press any key to continue flashing" dummy
360endif
Victor Chongd19dd752017-03-03 17:22:45 +0000361 @echo "If the board stalls while flashing $(SYSTEM_IMG),"
362 @echo "i.e. does not complete after more than 5 minutes,"
363 @echo "please try running 'make recovery' instead"
Victor Chong310ca4d2017-01-22 07:00:19 +0000364 fastboot flash ptable $(LLOADER_PATH)/ptable-linux-$(CFG_FLASH_SIZE)g.img
Joakim Becha40320b2016-04-14 21:37:49 +0200365 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
366 fastboot flash nvme $(NVME_IMG)
367 fastboot flash boot $(BOOT_IMG)
368 fastboot flash system $(SYSTEM_IMG)
369
370.PHONY: flash-fip
371flash-fip:
372 fastboot flash fastboot $(ARM_TF_PATH)/build/hikey/$(ARM_TF_BUILD)/fip.bin
373
374.PHONY: flash-boot-img
375flash-boot-img: boot-img
376 fastboot flash boot $(BOOT_IMG)
377
378.PHONY: flash-system-img
379flash-system-img: system-img
380 fastboot flash system $(SYSTEM_IMG)
381
382.PHONY: help
383help:
384 @echo " 1. WiFi on HiKey debian"
385 @echo " ======================="
386 @echo " Open /etc/network/interfaces and add:"
387 @echo " allow-hotplug wlan0"
388 @echo " iface wlan0 inet dhcp"
389 @echo " wpa-ssid \"my-ssid\""
390 @echo " wpa-psk \"my-wifi-password\""
391 @echo " Reboot and you should have WiFi access"