-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tinker_Board_2.mk
150 lines (121 loc) · 4.74 KB
/
Tinker_Board_2.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
################################################################################
# Following variables defines how the NS_USER (Non Secure User - Client
# Application), NS_KERNEL (Non Secure Kernel), S_KERNEL (Secure Kernel) and
# S_USER (Secure User - TA) are compiled
################################################################################
override COMPILE_NS_USER := 32
override COMPILE_NS_KERNEL := 32
override COMPILE_S_USER := 32
override COMPILE_S_KERNEL := 32
OPTEE_OS_PLATFORM = rockchip
LOOP_DEVICE := $(shell losetup -f)
include common.mk
################################################################################
# Paths to git projects and various binaries
################################################################################
TF_A_PATH ?= $(ROOT)/atf
BINARIES_PATH ?= $(ROOT)/out/bin
U-BOOT_PATH ?= $(ROOT)/u-boot
DEBUG = 0
################################################################################
# Targets
################################################################################
all: arm-tf u-boot
clean: arm-tf-clean u-boot-clean
include toolchain.mk
################################################################################
# ARM Trusted Firmware
################################################################################
TF_A_EXPORTS ?= CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"
TF_A_DEBUG ?= $(DEBUG)
ifeq ($(TF_A_DEBUG),0)
TF_A_LOGLVL ?= 30
TF_A_OUT = $(TF_A_PATH)/build/rk3399/release
else
TF_A_LOGLVL ?= 50
TF_A_OUT = $(TF_A_PATH)/build/rk3399/debug
endif
TF_A_FLAGS ?= \
PLAT=rk3399 \
DEBUG=$(TF_A_DEBUG) \
LOG_LEVEL=$(TF_A_LOGLVL)
#BL32=$(OPTEE_OS_HEADER_V2_BIN) \
#BL32_EXTRA1=$(OPTEE_OS_PAGER_V2_BIN) \
#BL32_EXTRA2=$(OPTEE_OS_PAGEABLE_V2_BIN) \
#ARM_ARCH_MAJOR=8 \
#ARM_TSP_RAM_LOCATION=tdram \
#BL32_RAM_LOCATION=tdram \
#AARCH64_SP=optee \
#BL31=${TF_A_OUT}/bl31/bl31.elf \
#BL33=$(ROOT)/u-boot/u-boot.bin \
#ARCH=aarch64 \
arm-tf:
cd $(TF_A_PATH) && \
git reset --hard refs/tags/v2.4 && \
git clean -fdx
$(TF_A_EXPORTS) $(MAKE) -C $(TF_A_PATH) $(TF_A_FLAGS) bl31
arm-tf-clean:
$(TF_A_EXPORTS) $(MAKE) -C $(TF_A_PATH) $(TF_A_FLAGS) realclean
################################################################################
# U-boot
################################################################################
U-BOOT_EXPORTS ?= \
CROSS_COMPILE="$(CCACHE)$(AARCH64_CROSS_COMPILE)"\
BL31=${TF_A_OUT}/bl31/bl31.elf \
ARCH=arm64
U-BOOT_DEFCONFIG_FILES := \
$(U-BOOT_PATH)/configs/tinker-board-2_defconfig \
$(ROOT)/build/kconfig/Tinker_Board_2.config
U-BOOT_PATCHES := \
$(ROOT)/build/0001-CapsuleCommon.patch \
$(ROOT)/build/0002-Add-DFU-alternative-function-for-evb-rk3399.patch \
$(ROOT)/build/0003-Add-dts-and-defconfig-for-Tinker-Board-2.patch \
$(ROOT)/build/0004-Test-mmc-before-setting-up-env-device.patch
.PHONY: u-boot
u-boot: arm-tf
cd $(U-BOOT_PATH) && \
git reset --hard refs/tags/v2021.07 && \
git clean -fdx
cd $(U-BOOT_PATH) && \
git apply $(U-BOOT_PATCHES)
#rm -rf $(BINARIES_PATH)/u-boot
mkdir -p $(BINARIES_PATH)/u-boot
cd $(U-BOOT_PATH) && \
scripts/kconfig/merge_config.sh -O $(BINARIES_PATH)/u-boot $(U-BOOT_DEFCONFIG_FILES)
$(U-BOOT_EXPORTS) $(MAKE) -C $(U-BOOT_PATH) O=$(BINARIES_PATH)/u-boot all
dd if=/dev/zero of=$(BINARIES_PATH)/u-boot/tb2-firmware-efi.img bs=1M count=128
parted $(BINARIES_PATH)/u-boot/tb2-firmware-efi.img mklabel gpt
parted $(BINARIES_PATH)/u-boot/tb2-firmware-efi.img mkpart ESP fat32 16MiB 100%
parted $(BINARIES_PATH)/u-boot/tb2-firmware-efi.img set 1 esp on
losetup -P $(LOOP_DEVICE) $(BINARIES_PATH)/u-boot/tb2-firmware-efi.img
mkfs.vfat -F 32 -n "EFI System" $(LOOP_DEVICE)p1
mkdir tmp
mount $(LOOP_DEVICE)p1 tmp
cp -r efi/ tmp/
umount tmp
rm -rf tmp/
losetup -d $(LOOP_DEVICE)
dd if=$(BINARIES_PATH)/u-boot/u-boot-rockchip.bin of=$(BINARIES_PATH)/u-boot/tb2-firmware-efi.img conv=notrunc seek=64
sync
.PHONY: capsule
capsule: arm-tf
cd $(U-BOOT_PATH) && \
git reset --hard refs/tags/v2021.07 && \
git clean -fdx
cd $(U-BOOT_PATH) && \
git apply $(U-BOOT_PATCHES)
#rm -rf $(BINARIES_PATH)/capsule
mkdir -p $(BINARIES_PATH)/capsule
cd $(U-BOOT_PATH) && \
scripts/kconfig/merge_config.sh -O $(BINARIES_PATH)/capsule $(U-BOOT_DEFCONFIG_FILES) $(ROOT)/build/kconfig/Capsule.config
$(U-BOOT_EXPORTS) $(MAKE) -C $(U-BOOT_PATH) O=$(BINARIES_PATH)/capsule all
cp $(ROOT)/build/acapsule.its $(BINARIES_PATH)/capsule/acapsule.its
cd $(BINARIES_PATH)/capsule && \
tools/mkimage -f $(BINARIES_PATH)/capsule/acapsule.its capsule.itb
cd $(BINARIES_PATH)/capsule && \
tools/mkeficapsule --fit $(BINARIES_PATH)/capsule/capsule.itb --index 1 capsule.bin
.PHONY: u-boot-clean
u-boot-clean:
rm -rf $(BINARIES_PATH)/u-boot
rm -rf $(BINARIES_PATH)/capsule
$(U-BOOT_EXPORTS) $(MAKE) -C $(U-BOOT_PATH) distclean