blob: 28ea15efcb39095ed48760897b62f256aae3136e [file] [log] [blame]
Igor Opaniukd496f982018-06-04 12:05:57 +03001################################################################################
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################################################################################
12# Includes
13################################################################################
14include common.mk
15
16################################################################################
17# Paths to git projects and various binaries
18################################################################################
19ifeq ($(DEBUG),1)
Victor Chong371d7c22019-08-08 17:17:14 +010020TF_A_BUILD ?= debug
Igor Opaniukd496f982018-06-04 12:05:57 +030021else
Victor Chong371d7c22019-08-08 17:17:14 +010022TF_A_BUILD ?= release
Igor Opaniukd496f982018-06-04 12:05:57 +030023endif
24
25OUT_PATH ?= $(ROOT)/out
Igor Opaniukb81fe042018-10-09 13:40:30 +030026ROOTFS_BIN ?= $(ROOT)/out-br/images/rootfs.tar
Victor Chongdf54b112019-08-11 15:58:12 +010027TF_A_PATH ?= $(ROOT)/trusted-firmware-a
Igor Opaniukd496f982018-06-04 12:05:57 +030028LLOADER_PATH ?= $(ROOT)/l-loader
29UBOOT_PATH ?= $(ROOT)/u-boot
Igor Opaniukd496f982018-06-04 12:05:57 +030030OPTEE_CLIENT_EXPORT ?= $(OPTEE_CLIENT_PATH)/out/export
Igor Opaniukb81fe042018-10-09 13:40:30 +030031OPTEE_PATH ?= $(ROOT)/optee_os
Igor Opaniukd496f982018-06-04 12:05:57 +030032LINUX_PATH ?= $(ROOT)/linux
33TOOLS_PATH ?= $(ROOT)/poplar-tools
34
Victor Chong371d7c22019-08-08 17:17:14 +010035BL1_BIN ?= $(TF_A_PATH)/build/poplar/$(TF_A_BUILD)/bl1.bin
36FIP_BIN ?= $(TF_A_PATH)/build/poplar/$(TF_A_BUILD)/fip.bin
Igor Opaniukd496f982018-06-04 12:05:57 +030037LLOADER_BIN ?= $(LLOADER_PATH)/l-loader.bin
38
39LINUX_DTB ?= $(LINUX_PATH)/arch/arm64/boot/dts/hisilicon/hi3798cv200-poplar.dtb
40
41UBOOT_BIN ?= $(UBOOT_PATH)/u-boot.bin
42OPTEE_BIN ?= $(OPTEE_PATH)/out/arm/core/tee-header_v2.bin
43OPTEE_BIN_EXTRA1 ?= $(OPTEE_PATH)/out/arm/core/tee-pager_v2.bin
44OPTEE_BIN_EXTRA2 ?= $(OPTEE_PATH)/out/arm/core/tee-pageable_v2.bin
45
Igor Opaniukd496f982018-06-04 12:05:57 +030046################################################################################
47# Targets
48################################################################################
49.PHONY: all
Igor Opaniukb81fe042018-10-09 13:40:30 +030050all: u-boot arm-tf buildroot l-loader linux prepare-images | toolchains
Igor Opaniukd496f982018-06-04 12:05:57 +030051
52.PHONY: clean
Igor Opaniukb81fe042018-10-09 13:40:30 +030053clean: u-boot-clean arm-tf-clean l-loader-clean linux-clean optee-os-clean \
54 buildroot-clean
Igor Opaniukd496f982018-06-04 12:05:57 +030055
56################################################################################
57# Toolchain
58################################################################################
59include toolchain.mk
60
61################################################################################
62# U-Boot
63################################################################################
64.PHONY: u-boot-config
65u-boot-config:
66ifeq ($(wildcard $(UBOOT_PATH)/.config),)
67 $(MAKE) -C $(UBOOT_PATH) \
68 CROSS_COMPILE=$(AARCH64_CROSS_COMPILE) poplar_defconfig
69endif
70
71.PHONY: u-boot-menuconfig
72u-boot-menuconfig: u-boot-config
73 $(MAKE) -C $(UBOOT_PATH) \
74 CROSS_COMPILE=$(AARCH64_CROSS_COMPILE) menuconfig
75
76.PHONY: u-boot
77u-boot: u-boot-config
78 $(MAKE) -C $(UBOOT_PATH) \
79 CROSS_COMPILE="$(AARCH64_CROSS_COMPILE)"
80
81.PHONY: u-boot-clean
82u-boot-clean:
83 cd $(UBOOT_PATH) && git clean -xdf
84
85################################################################################
Igor Opaniukd496f982018-06-04 12:05:57 +030086# ARM Trusted Firmware
87################################################################################
88.PHONY: arm-tf
89arm-tf: u-boot optee-os
Victor Chong371d7c22019-08-08 17:17:14 +010090 $(MAKE) -C $(TF_A_PATH) \
Igor Opaniukd496f982018-06-04 12:05:57 +030091 CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)" \
92 all fip \
93 DEBUG=$(DEBUG) \
94 PLAT=poplar \
95 SPD=opteed \
96 BL32=$(OPTEE_BIN) \
97 BL33=$(UBOOT_BIN) \
98 BL32_EXTRA1=$(OPTEE_BIN_EXTRA1) \
99 BL32_EXTRA2=$(OPTEE_BIN_EXTRA2)
100
101.PHONY: arm-tf-clean
102arm-tf-clean:
Victor Chong371d7c22019-08-08 17:17:14 +0100103 cd $(TF_A_PATH) && git clean -xdf
Igor Opaniukd496f982018-06-04 12:05:57 +0300104
105################################################################################
106# OP-TEE
107################################################################################
Igor Opaniuk9b359162018-10-17 13:42:17 +0300108OPTEE_OS_COMMON_FLAGS += PLATFORM=poplar CFG_ARM64_core=y CFG_DRAM_SIZE_GB=1
Igor Opaniukd496f982018-06-04 12:05:57 +0300109OPTEE_OS_CLEAN_COMMON_FLAGS += PLATFORM=poplar
110
111.PHONY: optee-os
112optee-os: optee-os-common
113
114.PHONY: optee-os-clean
115optee-os-clean: optee-os-clean-common
116
117################################################################################
118# l-loader
119################################################################################
120l-loader: arm-tf
121 cp $(BL1_BIN) $(LLOADER_PATH)/atf
122 cp $(FIP_BIN) $(LLOADER_PATH)/atf
Igor Opaniuk9545cf92019-10-09 15:22:31 +0300123 $(MAKE) -C $(LLOADER_PATH) CROSS_COMPILE="$(AARCH32_CROSS_COMPILE)" \
124 ARM_TRUSTED_FIRMWARE="$(TF_A_PATH)"
Igor Opaniukd496f982018-06-04 12:05:57 +0300125
126.PHONY: l-loader-clean
127l-loader-clean:
128 cd $(LLOADER_PATH) && git clean -xdf
129
130################################################################################
Igor Opaniukd496f982018-06-04 12:05:57 +0300131# Linux
132################################################################################
133LINUX_DEFCONFIG_COMMON_ARCH := arm64
134LINUX_DEFCONFIG_COMMON_FILES := \
135 $(LINUX_PATH)/arch/arm64/configs/poplar_defconfig \
Igor Opaniukd496f982018-06-04 12:05:57 +0300136
137linux-defconfig: $(LINUX_PATH)/.config
138
139LINUX_COMMON_FLAGS += ARCH=arm64
Jerome Forissier7fd8fc92018-08-13 09:36:17 +0200140# Avoid compile errors with GCC 8.x. These flags may be removed when
141# https://github.com/96boards-poplar/linux/pull/3 is merged.
142LINUX_COMMON_FLAGS += CFLAGS_drv_hifb_proc.o=-Wno-stringop-truncation \
143 CFLAGS_drv_pvr_intf.o=-Wno-sizeof-pointer-memaccess \
144 CFLAGS_drv_display.o=-Wno-array-bounds
Igor Opaniukd496f982018-06-04 12:05:57 +0300145
146linux: linux-common
147
148linux-defconfig-clean: linux-defconfig-clean-common
149
150LINUX_CLEAN_COMMON_FLAGS += ARCH=arm64
151
152linux-clean: linux-clean-common
153
154LINUX_CLEANER_COMMON_FLAGS += ARCH=arm64
155
156linux-cleaner: linux-cleaner-common
157
Igor Opaniukd496f982018-06-04 12:05:57 +0300158.PHONY: prepare-images
Igor Opaniukb81fe042018-10-09 13:40:30 +0300159prepare-images: linux l-loader buildroot
Igor Opaniuk9b359162018-10-17 13:42:17 +0300160 @mkdir -p $(OUT_PATH)
Igor Opaniukd496f982018-06-04 12:05:57 +0300161 @cp $(TOOLS_PATH)/poplar_recovery_builder.sh $(OUT_PATH)
162 @cp $(LLOADER_BIN) $(OUT_PATH)
163 @cp $(LINUX_PATH)/arch/arm64/boot/Image $(OUT_PATH)
164 @cp $(LINUX_DTB) $(OUT_PATH)
Igor Opaniukb81fe042018-10-09 13:40:30 +0300165 @cd $(OUT_PATH) && PATH=$(UBOOT_PATH)/tools:$$PATH \
166 bash ./poplar_recovery_builder.sh all "$(ROOTFS_BIN)"
167
168################################################################################
169# Buildroot/RootFS
170################################################################################
171.PHONY: update_rootfs
172update_rootfs: arm-tf u-boot
173
174.PHONY: buildroot
175buildroot: update_rootfs
Igor Opaniukd496f982018-06-04 12:05:57 +0300176
177################################################################################
178# Flash images
179################################################################################
180.PHONY: flash-help
181flash-help:
182 @echo "1. Install and configure TFTP server on your host PC:"
183 @echo ""
184 @echo " $$ sudo apt-get install atftpd # install atftpd server"
185 @echo " $$ sudo vim /etc/default/atftpd # edit atftpd server config"
186 @echo " $$ sudo service atftpd restart # restart atftpd server"
187 @echo ""
188 @echo "2. Proper configuration should look like:"
189 @echo ""
190 @echo " $$ cat /etc/default/atftpd"
191 @echo " USE_INETD=false"
192 @echo " OPTIONS=\"--tftpd-timeout 300 --retry-timeout 5 --mcast-port 1758 --mcast-addr 239.239.239.0-255 --mcast-ttl 1 --maxthread 100 --verbose=5 /path/to/rep/out/dir\""
193 @echo ""
194 @echo "3. Flash proper U-boot build to USB stick."
195 @echo " It should be flashed to the first FAT32 partition. Then boot"
196 @echo " from it by pressing USB_BOOT switch on the board"
197 @echo ""
198 @echo "4. Connect to Poplar board over serial console (run on host PC):"
199 @echo ""
200 @echo " $$ screen /dev/ttyUSB0 115200"
201 @echo ""
202 @echo "5. Configure network interface in Poplar U-boot shell. If you can't"
203 @echo "get into U-boot console, press and hold Ctrl+C while booting:"
204 @echo ""
205 @echo " => setenv ipaddr 192.168.0.2"
206 @echo " => setenv netmask 255.255.255.0"
207 @echo " => setenv serverip 192.168.0.3"
208 @echo " ETH1: PHY(phyaddr=3, rgmii) link UP: DUPLEX=FULL : SPEED=1000M"
209 @echo " MAC: 00-16-8E-62-66-84"
210 @echo " host 192.168.0.3 is alive"
211 @echo ""
212 @echo "6. Verify connection is working (run in U-boot shell):"
213 @echo ""
214 @echo " => ping 192.168.0.3"
215 @echo ""
216 @echo "7. Run installer (run in U-boot shell):"
217 @echo ""
218 @echo " => tftp 0x08000000 recovery_files/install.scr"
219 @echo " => source 0x08000000"
220 @echo ""
221 @echo "8. After successful flashing reboot your board (U-boot shell):"
222 @echo ""
223 @echo " => reset"
224 @echo ""