blob: 18cf8df01d870719595d7a28292cb27e6cc4ffa4 [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
Jens Wiklander5a098ec2018-04-26 09:54:42 +020013# Needed by buildroot
14CFG_NW_CONSOLE_UART ?= $(CFG_CONSOLE_UART)
Victor Chong05bb4ed2017-07-02 13:47:57 +010015
Jerome Forissier03b920b2019-10-01 18:53:23 +020016# To enable Wi-Fi on HiKey960:
17# 1. Set the network name (SSID) and password in
18# $(BR2_ROOTFS_OVERLAY)/etc/wpa_supplicant.conf before building
19# 2. Boot the board, login as root and run: ifup wlan0
20BR2_PACKAGE_LINUX_FIRMWARE = y
21BR2_PACKAGE_LINUX_FIRMWARE_TI_WL18XX = y
22BR2_PACKAGE_WPA_SUPPLICANT = y
23BR2_PACKAGE_WIRELESS_REGDB = y
24
25BR2_ROOTFS_OVERLAY = $(ROOT)/build/br-ext/board/hikey960/overlay
26
Etienne Carriere3768a2b2019-05-14 17:13:19 +020027OPTEE_OS_PLATFORM = hikey-hikey960
28
Victor Chong05bb4ed2017-07-02 13:47:57 +010029################################################################################
30# Includes
31################################################################################
Victor Chong7a716512017-09-11 15:18:44 +010032include common.mk
Victor Chong05bb4ed2017-07-02 13:47:57 +010033
34################################################################################
Victor Chong05bb4ed2017-07-02 13:47:57 +010035# Paths to git projects and various binaries
36################################################################################
Victor Chongdf54b112019-08-11 15:58:12 +010037TF_A_PATH ?= $(ROOT)/trusted-firmware-a
Victor Chong05bb4ed2017-07-02 13:47:57 +010038ifeq ($(DEBUG),1)
Victor Chong371d7c22019-08-08 17:17:14 +010039TF_A_BUILD ?= debug
Victor Chong05bb4ed2017-07-02 13:47:57 +010040else
Victor Chong371d7c22019-08-08 17:17:14 +010041TF_A_BUILD ?= release
Victor Chong05bb4ed2017-07-02 13:47:57 +010042endif
43
44EDK2_PATH ?= $(ROOT)/edk2
45ifeq ($(DEBUG),1)
46EDK2_BUILD ?= DEBUG
47else
48EDK2_BUILD ?= RELEASE
49endif
50EDK2_BIN ?= $(EDK2_PATH)/Build/HiKey960/$(EDK2_BUILD)_$(EDK2_TOOLCHAIN)/FV/BL33_AP_UEFI.fd
51OPENPLATPKG_PATH ?= $(ROOT)/OpenPlatformPkg
52
53OUT_PATH ?=$(ROOT)/out
54MCUIMAGE_BIN ?= $(OPENPLATPKG_PATH)/Platforms/Hisilicon/HiKey960/Binary/lpm3.img
55BOOT_IMG ?=$(ROOT)/out/boot-fat.uefi.img
56GRUB_PATH ?=$(ROOT)/grub
57LLOADER_PATH ?=$(ROOT)/l-loader
58IMAGE_TOOLS_PATH ?=$(ROOT)/tools-images-hikey960
59IMAGE_TOOLS_CONFIG ?=$(OUT_PATH)/config
60PATCHES_PATH ?=$(ROOT)/patches_hikey
Victor Chong05bb4ed2017-07-02 13:47:57 +010061
62################################################################################
63# Targets
64################################################################################
65.PHONY: all
Victor Chong86840a42017-10-28 13:01:33 +010066all: arm-tf boot-img lloader
Victor Chong05bb4ed2017-07-02 13:47:57 +010067
68.PHONY: clean
Jens Wiklander5a098ec2018-04-26 09:54:42 +020069clean: arm-tf-clean buildroot-clean edk2-clean linux-clean optee-os-clean \
70 boot-img-clean lloader-clean grub-clean
Victor Chong05bb4ed2017-07-02 13:47:57 +010071
72.PHONY: cleaner
Jens Wiklander5a098ec2018-04-26 09:54:42 +020073cleaner: clean prepare-cleaner buildroot-cleaner linux-cleaner grub-cleaner
Victor Chong05bb4ed2017-07-02 13:47:57 +010074
Victor Chong7a716512017-09-11 15:18:44 +010075include toolchain.mk
Victor Chong05bb4ed2017-07-02 13:47:57 +010076
77.PHONY: prepare
78prepare:
79 mkdir -p $(OUT_PATH)
80
81.PHONY: prepare-cleaner
82prepare-cleaner:
83 rm -rf $(ROOT)/out
84
85################################################################################
86# ARM Trusted Firmware
87################################################################################
Victor Chong371d7c22019-08-08 17:17:14 +010088TF_A_EXPORTS ?= \
Victor Chong05bb4ed2017-07-02 13:47:57 +010089 CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
90
Victor Chong371d7c22019-08-08 17:17:14 +010091TF_A_FLAGS ?= \
Victor Chong865d7752017-08-24 04:53:07 +010092 BL32=$(OPTEE_OS_HEADER_V2_BIN) \
93 BL32_EXTRA1=$(OPTEE_OS_PAGER_V2_BIN) \
94 BL32_EXTRA2=$(OPTEE_OS_PAGEABLE_V2_BIN) \
Victor Chong05bb4ed2017-07-02 13:47:57 +010095 BL33=$(EDK2_BIN) \
96 SCP_BL2=$(MCUIMAGE_BIN) \
97 DEBUG=$(DEBUG) \
98 PLAT=hikey960 \
99 SPD=opteed
100
101ifeq ($(CFG_CONSOLE_UART),5)
Victor Chong371d7c22019-08-08 17:17:14 +0100102 TF_A_FLAGS += CRASH_CONSOLE_BASE=PL011_UART5_BASE
Victor Chong05bb4ed2017-07-02 13:47:57 +0100103endif
104
105.PHONY: arm-tf
106arm-tf: optee-os edk2
Victor Chong371d7c22019-08-08 17:17:14 +0100107 $(TF_A_EXPORTS) $(MAKE) -C $(TF_A_PATH) $(TF_A_FLAGS) all fip
Victor Chong05bb4ed2017-07-02 13:47:57 +0100108
109.PHONY: arm-tf-clean
110arm-tf-clean:
Victor Chong371d7c22019-08-08 17:17:14 +0100111 $(TF_A_EXPORTS) $(MAKE) -C $(TF_A_PATH) $(TF_A_FLAGS) clean
Victor Chong05bb4ed2017-07-02 13:47:57 +0100112
113################################################################################
Victor Chong05bb4ed2017-07-02 13:47:57 +0100114# EDK2 / Tianocore
115################################################################################
116EDK2_ARCH ?= AARCH64
117EDK2_DSC ?= OpenPlatformPkg/Platforms/Hisilicon/HiKey960/HiKey960.dsc
118EDK2_TOOLCHAIN ?= GCC49
119
120ifeq ($(CFG_CONSOLE_UART),5)
121 EDK2_BUILDFLAGS += -DSERIAL_BASE=0xFDF05000
122endif
123
124define edk2-call
Joakim Bechd1a05e32018-05-23 08:36:52 +0200125 $(EDK2_TOOLCHAIN)_$(EDK2_ARCH)_PREFIX=$(AARCH64_CROSS_COMPILE) \
Victor Chong05bb4ed2017-07-02 13:47:57 +0100126 build -n `getconf _NPROCESSORS_ONLN` -a $(EDK2_ARCH) \
127 -t $(EDK2_TOOLCHAIN) -p $(EDK2_DSC) \
128 -b $(EDK2_BUILD) $(EDK2_BUILDFLAGS)
129endef
130
131.PHONY: edk2
132edk2:
Jerome Forissier064b4b02023-07-05 15:50:03 +0200133 sed -i 's/\(^DEFINE GCC_ALL_CC_FLAGS.*-Wno-array-bounds\) -include/\1 -Wno-stringop-overflow -include/' $(EDK2_PATH)/BaseTools/Conf/tools_def.template
Victor Chong05bb4ed2017-07-02 13:47:57 +0100134 cd $(EDK2_PATH) && rm -rf OpenPlatformPkg && \
135 ln -s $(OPENPLATPKG_PATH)
136 set -e && cd $(EDK2_PATH) && source edksetup.sh && \
Jerome Forissier46f7be22019-12-11 15:25:39 +0100137 $(MAKE) -j1 -C $(EDK2_PATH)/BaseTools \
Jerome Forissierf342db92020-01-07 18:19:46 +0100138 BUILD_CC="gcc $(call cc-option,gcc,-Wno-error=stringop-truncation,)" && \
Victor Chong05bb4ed2017-07-02 13:47:57 +0100139 $(call edk2-call)
140
141.PHONY: edk2-clean
142edk2-clean:
143 set -e && cd $(EDK2_PATH) && source edksetup.sh && \
144 $(call edk2-call) cleanall && \
145 $(MAKE) -j1 -C $(EDK2_PATH)/BaseTools clean
146 rm -rf $(EDK2_PATH)/Build
147 rm -rf $(EDK2_PATH)/Conf/.cache
148 rm -f $(EDK2_PATH)/Conf/build_rule.txt
149 rm -f $(EDK2_PATH)/Conf/target.txt
150 rm -f $(EDK2_PATH)/Conf/tools_def.txt
151
152################################################################################
153# Linux kernel
154################################################################################
155LINUX_DEFCONFIG_COMMON_ARCH ?= arm64
156LINUX_DEFCONFIG_COMMON_FILES ?= $(LINUX_PATH)/arch/arm64/configs/defconfig \
157 $(CURDIR)/kconfigs/hikey960.conf \
158 $(PATCHES_PATH)/kernel_config/usb_net_dm9601.conf \
159 $(PATCHES_PATH)/kernel_config/ftrace.conf
160
161.PHONY: linux-defconfig
162linux-defconfig: $(LINUX_PATH)/.config
163
164.PHONY: linux-gen_init_cpio
165linux-gen_init_cpio: linux-defconfig
166 $(MAKE) -C $(LINUX_PATH)/usr \
167 CROSS_COMPILE=$(CROSS_COMPILE_NS_KERNEL) \
168 ARCH=arm64 \
169 LOCALVERSION= \
170 gen_init_cpio
171
Jens Wiklander41207ba2024-01-30 16:58:47 +0100172LINUX_COMMON_FLAGS += ARCH=arm64
173LINUX_COMMON_TARGETS += Image hisilicon/hi3660-hikey960.dtb
Victor Chong05bb4ed2017-07-02 13:47:57 +0100174
175.PHONY: linux
176linux: linux-common
177
178.PHONY: linux-defconfig-clean
179linux-defconfig-clean: linux-defconfig-clean-common
180
181LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
182
183.PHONY: linux-clean
184linux-clean: linux-clean-common
185
186LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
187
188.PHONY: linux-cleaner
189linux-cleaner: linux-cleaner-common
190
191################################################################################
192# OP-TEE
193################################################################################
Etienne Carriere3768a2b2019-05-14 17:13:19 +0200194OPTEE_OS_COMMON_FLAGS += CFG_CONSOLE_UART=$(CFG_CONSOLE_UART)
Victor Chong05bb4ed2017-07-02 13:47:57 +0100195
196.PHONY: optee-os
197optee-os: optee-os-common
198
199.PHONY: optee-os-clean
200optee-os-clean: optee-os-clean-common
201
Victor Chong05bb4ed2017-07-02 13:47:57 +0100202################################################################################
203# grub
204################################################################################
205grub-flags := CC="$(CCACHE)gcc" \
206 TARGET_CC="$(AARCH64_CROSS_COMPILE)gcc" \
207 TARGET_OBJCOPY="$(AARCH64_CROSS_COMPILE)objcopy" \
208 TARGET_NM="$(AARCH64_CROSS_COMPILE)nm" \
209 TARGET_RANLIB="$(AARCH64_CROSS_COMPILE)ranlib" \
Jens Wiklander3b5d8f02018-06-27 09:16:24 +0200210 TARGET_STRIP="$(AARCH64_CROSS_COMPILE)strip" \
211 --disable-werror
Victor Chong05bb4ed2017-07-02 13:47:57 +0100212
213GRUB_MODULES += boot chain configfile echo efinet eval ext2 fat font gettext \
214 gfxterm gzio help linux loadenv lsefi normal part_gpt \
215 part_msdos read regexp search search_fs_file search_fs_uuid \
216 search_label terminal terminfo test tftp time
217
218$(GRUB_PATH)/configure: $(GRUB_PATH)/configure.ac
219 cd $(GRUB_PATH) && ./autogen.sh
220
221$(GRUB_PATH)/Makefile: $(GRUB_PATH)/configure
222 cd $(GRUB_PATH) && ./configure --target=aarch64 --enable-boot-time $(grub-flags)
223
224.PHONY: grub
225grub: prepare $(GRUB_PATH)/Makefile
226 $(MAKE) -C $(GRUB_PATH); \
227 cd $(GRUB_PATH) && ./grub-mkimage \
228 --verbose \
229 --output=$(OUT_PATH)/grubaa64.efi \
230 --config=$(PATCHES_PATH)/grub/grub.configfile \
231 --format=arm64-efi \
232 --directory=grub-core \
233 --prefix=/boot/grub \
234 $(GRUB_MODULES)
235
236.PHONY: grub-clean
237grub-clean:
238 if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) clean; fi
239 rm -f $(OUT_PATH)/grubaa64.efi
240
241.PHONY: grub-cleaner
242grub-cleaner: grub-clean
243 if [ -e $(GRUB_PATH)/Makefile ]; then $(MAKE) -C $(GRUB_PATH) distclean; fi
244 rm -f $(GRUB_PATH)/configure
245
246################################################################################
247# Boot Image
248################################################################################
249ifeq ($(CFG_CONSOLE_UART),6)
250GRUBCFG = $(PATCHES_PATH)/grub/grub_uart6.cfg
251else
252GRUBCFG = $(PATCHES_PATH)/grub/grub_uart5.cfg
253endif
254
255.PHONY: boot-img
Jens Wiklander5a098ec2018-04-26 09:54:42 +0200256boot-img: linux buildroot edk2 grub
Victor Chong05bb4ed2017-07-02 13:47:57 +0100257 rm -f $(BOOT_IMG)
258 mformat -i $(BOOT_IMG) -n 64 -h 255 -T 131072 -v "BOOT IMG" -C ::
259 mcopy -i $(BOOT_IMG) $(LINUX_PATH)/arch/arm64/boot/Image ::
260 mcopy -i $(BOOT_IMG) $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dtb ::
261 mmd -i $(BOOT_IMG) ::/EFI
262 mmd -i $(BOOT_IMG) ::/EFI/BOOT
263 mcopy -i $(BOOT_IMG) $(OUT_PATH)/grubaa64.efi ::/EFI/BOOT/
264 mcopy -i $(BOOT_IMG) $(GRUBCFG) ::/EFI/BOOT/grub.cfg
Jens Wiklander5a098ec2018-04-26 09:54:42 +0200265 mcopy -i $(BOOT_IMG) $(ROOT)/out-br/images/rootfs.cpio.gz ::/initrd.img
Victor Chong05bb4ed2017-07-02 13:47:57 +0100266 mcopy -i $(BOOT_IMG) $(EDK2_PATH)/Build/HiKey960/$(EDK2_BUILD)_$(EDK2_TOOLCHAIN)/$(EDK2_ARCH)/AndroidFastbootApp.efi ::/EFI/BOOT/fastboot.efi
267
268.PHONY: boot-img-clean
269boot-img-clean:
270 rm -f $(BOOT_IMG)
271
272################################################################################
273# l-loader
274################################################################################
Victor Chong9860c922017-09-29 18:25:37 +0100275.PHONY: lloader
Jens Wiklandera51a4042017-10-09 13:30:24 +0200276lloader: arm-tf edk2
Victor Chong05bb4ed2017-07-02 13:47:57 +0100277 cd $(LLOADER_PATH) && \
Victor Chong371d7c22019-08-08 17:17:14 +0100278 ln -sf $(TF_A_PATH)/build/hikey960/$(TF_A_BUILD)/bl1.bin && \
279 ln -sf $(TF_A_PATH)/build/hikey960/$(TF_A_BUILD)/bl2.bin && \
Victor Chong9860c922017-09-29 18:25:37 +0100280 ln -sf $(EDK2_BIN) && \
281 $(MAKE) hikey960 PTABLE_LST=linux-32g
Victor Chong05bb4ed2017-07-02 13:47:57 +0100282
283.PHONY: lloader-clean
Victor Chong9860c922017-09-29 18:25:37 +0100284lloader-clean:
285 $(MAKE) -C $(LLOADER_PATH) hikey960-clean
Victor Chong05bb4ed2017-07-02 13:47:57 +0100286
287################################################################################
288# Flash
289################################################################################
290define flash_help
291 @read -r -p "Connect HiKey960 to power up (press enter)" dummy
292 @read -r -p "Connect USB OTG cable, the micro USB cable (press enter)" dummy
293endef
294
295.PHONY: recov_cfg
296recov_cfg:
Jerome Forissiera4a52552018-06-21 15:31:22 +0200297 @echo "./hisi-sec_usb_xloader.img 0x00020000" > $(IMAGE_TOOLS_CONFIG)
298 @echo "./hisi-sec_uce_boot.img 0x6A908000" >> $(IMAGE_TOOLS_CONFIG)
Victor Chongf9f39122018-03-09 06:54:53 +0000299 @echo "./recovery.bin 0x1AC00000" >> $(IMAGE_TOOLS_CONFIG)
Victor Chong05bb4ed2017-07-02 13:47:57 +0100300
301.PHONY: recovery
302recovery: recov_cfg
303 @echo "Enter recovery mode to flash a new bootloader"
304 @echo
305 @echo "Make sure udev permissions are set appropriately:"
306 @echo " # /etc/udev/rules.d/hikey960.rules"
307 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d00d", MODE="0666"'
308 @echo ' SUBSYSTEM=="usb", ATTRS{idVendor}=="12d1", MODE="0666", ENV{ID_MM_DEVICE_IGNORE}="1"'
309 @echo
310 @echo "Set jumpers or switches as follows:"
311 @echo "Jumper 1-2: Closed or Switch 1: On"
312 @echo " 3-4: Closed or 2: On"
313 @echo " 5-6: Open or 3: Off"
314 @read -r -p "Press enter to continue" dummy
315 @echo
316 $(call flash_help)
317 @echo
318 @echo "Check the device node (/dev/ttyUSBx) of the micro USB connection"
319 @echo "Note the value x of the device node. Default is 1"
320 @read -r -p "Enter the device node. Press enter for /dev/ttyUSB1: " DEV && \
321 DEV=$${DEV:-/dev/ttyUSB1} && \
322 cd $(IMAGE_TOOLS_PATH) && \
Victor Chongf9f39122018-03-09 06:54:53 +0000323 ln -sf $(LLOADER_PATH)/recovery.bin && \
Victor Chong05bb4ed2017-07-02 13:47:57 +0100324 sudo ./hikey_idt -c $(IMAGE_TOOLS_CONFIG) -p $$DEV && \
325 rm -f $(IMAGE_TOOLS_CONFIG)
326 @echo
327 @echo "If you see dots starting to appear on the console,"
328 @echo "press f ON THE CONSOLE (NOT HERE!) to run fastboot."
329 @echo "You have 10 seconds! Go!"
330 @echo "If not, fastboot should load automatically."
331 @read -r -p "Press enter (HERE) to continue flashing" dummy
332 @$(MAKE) --no-print flash FROM_RECOVERY=1
333
334.PHONY: flash
335flash:
336ifneq ($(FROM_RECOVERY),1)
337 @echo "Flash binaries using fastboot"
338 @echo
339 @echo "Set jumpers or switches as follows:"
340 @echo "Jumper 1-2: Closed or Switch 1: On"
341 @echo " 3-4: Open or 2: Off"
342 @echo " 5-6: Closed or 3: On"
343 @read -r -p "Press enter to continue" dummy
344 @echo
345 $(call flash_help)
346endif
347 @echo "Wait until you see the (UART) message"
348 @echo " \"Android Fastboot mode - version x.x.\""
349 @echo " Press RETURN or SPACE key to quit.\""
Victor Chongf9f39122018-03-09 06:54:53 +0000350 @echo "It can take a while for the fastboot device to come up,"
351 @echo "so please wait ~10 seconds."
Victor Chong05bb4ed2017-07-02 13:47:57 +0100352 @read -r -p "Then press enter to continue flashing" dummy
353 @echo
354 fastboot flash ptable $(LLOADER_PATH)/prm_ptable.img
Jerome Forissierf4fe6622018-04-26 14:17:34 +0200355 fastboot flash xloader $(IMAGE_TOOLS_PATH)/hisi-sec_xloader.img
Victor Chong05bb4ed2017-07-02 13:47:57 +0100356 fastboot flash fastboot $(LLOADER_PATH)/l-loader.bin
Victor Chong371d7c22019-08-08 17:17:14 +0100357 fastboot flash fip $(TF_A_PATH)/build/hikey960/$(TF_A_BUILD)/fip.bin
Victor Chongf9f39122018-03-09 06:54:53 +0000358 fastboot flash nvme $(IMAGE_TOOLS_PATH)/hisi-nvme.img
Victor Chong05bb4ed2017-07-02 13:47:57 +0100359 fastboot flash boot $(BOOT_IMG)