-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfunctions
More file actions
executable file
·203 lines (163 loc) · 4.96 KB
/
Copy pathfunctions
File metadata and controls
executable file
·203 lines (163 loc) · 4.96 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# Copyright (C) 2023 Vicharak Computers LLP
# shellcheck disable=1090
source "${SCRIPT_DIR}"/utils
function check_image_build() {
local uboot_img, trust_img, loader_img
uboot_img="${UBOOT_DIR}/uboot.img"
trust_img="${UBOOT_DIR}/trust.img"
loader_img="${UBOOT_DIR}/loader.bin"
if [ ! -f "${uboot_img}" ] || [ ! -f "${trust_img}" ] || [ ! -f "${loader_img}" ]; then
exit_with_error "U-Boot build failed!"
else
print "----------------------------------------------------------------"
print "Build successful!"
print "----------------------------------------------------------------"
fi
}
function source_toolchain {
if [ "$(uname -m)" != "aarch64" ]; then
case "${DEVICE_ARCH}" in
arm64)
command -v aarch64-linux-gnu-gcc >/dev/null 2>&1 \
|| exit_with_error "aarch64-linux-gnu-gcc not found!"
uboot_args="ARCH=arm CROSS_COMPILE=aarch64-linux-gnu- -j$(nproc --all)"
;;
arm)
command -v arm-linux-gnueabi-gcc >/dev/null 2>&1 \
|| exit_with_error "arm-linux-gnueabi-gcc not found!"
uboot_args="ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- -j$(nproc --all)"
;;
*)
exit_with_error "Unsupported DEVICE_ARCH: ${DEVICE_ARCH}"
;;
esac
else
uboot_args="ARCH=arm -j$(nproc --all)"
fi
export uboot_args
}
function cleanup() {
source_toolchain
# shellcheck disable=SC2086
make ${uboot_args} clean && make ${uboot_args} distclean
}
function build_config() {
if ! is_set "${uboot_args}"; then
source_toolchain
fi
cd "${UBOOT_DIR}" || exit
# shellcheck disable=SC2086
make ${uboot_args} "${DEVICE_DEFCONFIG}"
cd - || exit
}
function build_uboot_deb_package() {
dpkg-buildpackage -b -rfakeroot -us -uc -a "${DEVICE_ARCH}"
deb_files=$(find "${UBOOT_DIR}/.." -maxdepth 1 -name "u-boot-${DEVICE_NAME}*")
if is_set "${deb_files}"; then
for deb_file in ${deb_files}; do
mv "${deb_file}" "${UBOOT_DIR}/"
done
else
exit_with_error "Deb package build failed!"
fi
}
function build_ubootdeb() {
source_toolchain
build_config
build_uboot_deb_package
}
function make_bl31() {
if [ ! -d "${UBOOT_DIR}/trusted-firmware-a" ]; then
git clone --depth=1 https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/
fi
cd "${UBOOT_DIR}/trusted-firmware-a" || exit
make realclean -j$(nproc --all)
make CROSS_COMPILE=aarch64-linux-gnu- PLAT=rk3399 -j$(nproc --all)
cd "${UBOOT_DIR}" || exit
}
function build_uboot() {
source_toolchain
build_config
if ! is_enabled "${MAINLINE_BUILD}"; then
./make.sh "${DEVICE_NAME}"
else
make_bl31
# shellcheck disable=SC2086
BL31=${UBOOT_DIR}/trusted-firmware-a/build/rk3399/release/bl31/bl31.elf make ${uboot_args} all
fi
if is_enabled "${DEB_BUILD}"; then
build_uboot_deb_package
fi
}
function update_defconfig() {
source_toolchain
# shellcheck disable=SC2086
make ${uboot_args} "${DEVICE_DEFCONFIG}"
# shellcheck disable=SC2086
make ${uboot_args} savedefconfig
mv "${UBOOT_DIR}"/defconfig "${UBOOT_DIR}"/configs/"${DEVICE_DEFCONFIG}"
print "----------------------------------------------------------------"
print "Updated ${DEVICE_DEFCONFIG} with savedefconfig"
print "----------------------------------------------------------------"
}
function print_info() {
if [[ -f "${SCRIPT_DIR}/.device.mk" ]]; then
# shellcheck disable=SC1090
source "${SCRIPT_DIR}/.device.mk"
else
lunch_device
fi
print "----------------------------------------------------------------"
print "Device Information"
print "----------------------------------------------------------------"
if ! is_set "${DEVICE_DEFCONFIG}"; then
DEVICE_MAKEFILE="${DEVICE_NAME}.mk"
fi
print "Device Makefile: ${DEVICE_MAKEFILE}"
print "Device Name: ${DEVICE_NAME}"
print "Device Defconfig: ${DEVICE_DEFCONFIG}"
if is_set "${DEVICE_DTB_FILE}"; then
print "Device DTB: ${DEVICE_DTB_FILE}"
fi
if is_enabled "${DEB_BUILD}"; then
print "Build Debian package: Yes"
else
print "Build Debian package: No"
fi
if is_enabled "${MAINLINE_BUILD}"; then
print "Build Mainline U-Boot: Yes"
else
print "Build Mainline U-Boot: No"
fi
usage
}
function set_device_config() {
print "----------------------------------------------------------------"
cd "${SCRIPT_DIR}" || exit 1
printf "\e[1;32m"
select device in *.mk; do
DEVICE_MAKEFILE="${device}"
break
done
cd "${SCRIPT_DIR}" || exit 1
printf "\e[0m"
print "----------------------------------------------------------------"
}
function check_lunch_device() {
if [[ ! -f "${SCRIPT_DIR}/.device.mk" ]]; then
lunch_device
fi
}
function lunch_device() {
delete_file "${SCRIPT_DIR}/.device.mk"
set_device_config
cp "${SCRIPT_DIR}/${DEVICE_MAKEFILE}" "${SCRIPT_DIR}/.device.mk"
source "${SCRIPT_DIR}/.device.mk"
if ! is_set "${DEVICE_DEFCONFIG}"; then
exit_with_error "Device defconfig not set!"
fi
source_toolchain
build_config
}