forked from edk2-porting/edk2-rk3588
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·207 lines (171 loc) · 6.16 KB
/
build.sh
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
204
205
206
207
#!/bin/bash
function _help(){
echo
echo "Build EDK2 for Rockchip RK3588 platforms."
echo
echo "Usage: build.sh [options]"
echo
echo "Options:"
echo " -d, --device DEV Build for DEV, or 'all'."
echo " -r, --release MODE Release mode for building, default is 'DEBUG', 'RELEASE' alternatively."
echo " -t, --toolchain TOOLCHAIN Set toolchain, default is 'GCC'."
echo " -C, --clean Clean workspace and output."
echo " -D, --distclean Clean up all files that are not in repo."
echo " --edk2-flags \"FLAGS\" Flags appended to the EDK2 build process."
echo " -h, --help Show this help."
echo
exit "${1}"
}
function _error() { echo "${@}" >&2; exit 1; }
function _build_idblock() {
echo " => Building idblock.bin"
pushd ${WORKSPACE}
FLASHFILES="FlashHead.bin FlashData.bin FlashBoot.bin"
rm -f rk35*_spl_loader_*.bin idblock.bin rk35*_ddr_*.bin rk35*_usbplug*.bin UsbHead.bin ${FLASHFILES}
DDRBIN=$(grep '^FlashData' ${ROOTDIR}/misc/rkbin/RKBOOT/${MINIALL_INI} | cut -d = -f 2-)
SPL=$(grep '^FlashBoot' ${ROOTDIR}/misc/rkbin/RKBOOT/${MINIALL_INI} | cut -d = -f 2-)
# Create idblock.bin
${ROOTDIR}/misc/tools/${MACHINE_TYPE}/mkimage -n rk3588 -T rksd -d ${ROOTDIR}/misc/rkbin/${DDRBIN}:${ROOTDIR}/misc/rkbin/${SPL} idblock.bin
popd
echo " => idblock.bin build done"
}
function _build_fit() {
echo " => Building FIT"
pushd ${WORKSPACE}
BL31=$(grep '^PATH=.*_bl31_' ${ROOTDIR}/misc/rkbin/RKTRUST/${TRUST_INI} | cut -d = -f 2-)
BL32=$(grep '^PATH=.*_bl32_' ${ROOTDIR}/misc/rkbin/RKTRUST/${TRUST_INI} | cut -d = -f 2-)
rm -f bl31_0x*.bin ${WORKSPACE}/BL33_AP_UEFI.Fv ${SOC_L}_${DEVICE}_EFI.its
${ROOTDIR}/misc/extractbl31.py ${ROOTDIR}/misc/rkbin/${BL31}
cp ${ROOTDIR}/misc/rkbin/${BL32} ${WORKSPACE}/bl32.bin
cp ${ROOTDIR}/misc/${SOC_L}_spl.dtb ${WORKSPACE}/${DEVICE}.dtb
cp ${WORKSPACE}/Build/${PLATFORM_NAME}/${RELEASE_TYPE}_${TOOLCHAIN}/FV/BL33_AP_UEFI.Fv ${WORKSPACE}/
cat ${ROOTDIR}/misc/uefi_${SOC_L}.its | sed "s,@DEVICE@,${DEVICE},g" > ${SOC_L}_${DEVICE}_EFI.its
${ROOTDIR}/misc/tools/${MACHINE_TYPE}/mkimage -f ${SOC_L}_${DEVICE}_EFI.its -E ${DEVICE}_EFI.itb
popd
echo " => FIT build done"
}
function _pack_image() {
_build_idblock
_build_fit
echo " => Building 8MB NOR FLASH IMAGE"
cp ${WORKSPACE}/Build/${PLATFORM_NAME}/${RELEASE_TYPE}_${TOOLCHAIN}/FV/NOR_FLASH_IMAGE.fd ${WORKSPACE}/RK3588_NOR_FLASH.img
# GPT at 0x0, size:0x4400
dd if=${ROOTDIR}/misc/rk3588_spi_nor_gpt.img of=${WORKSPACE}/RK3588_NOR_FLASH.img
# idblock at 0x8000
dd if=${WORKSPACE}/idblock.bin of=${WORKSPACE}/RK3588_NOR_FLASH.img bs=1K seek=32
# FIT Image at 0x100000
dd if=${WORKSPACE}/${DEVICE}_EFI.itb of=${WORKSPACE}/RK3588_NOR_FLASH.img bs=1K seek=1024
cp ${WORKSPACE}/RK3588_NOR_FLASH.img ${ROOTDIR}/
}
function _build(){
local DEVICE="${1}"; shift
#
# Grab platform parameters
#
if [ -f "configs/${DEVICE}.conf" ]
then source "configs/${DEVICE}.conf"
else _error "Device configuration not found"
fi
if [ -f "configs/${SOC}.conf" ]
then source "configs/${SOC}.conf"
else _error "SoC configuration not found"
fi
typeset -l SOC_L="$SOC"
rm -f "${OUTDIR}/RK35*_NOR_FLASH.img"
#
# Build EDK2
#
[ -d "${WORKSPACE}/Conf" ] || mkdir -p "${WORKSPACE}/Conf"
export GCC_AARCH64_PREFIX="${CROSS_COMPILE}"
export CLANG38_AARCH64_PREFIX="${CROSS_COMPILE}"
export PACKAGES_PATH="${ROOTDIR}/edk2:${ROOTDIR}/edk2-platforms:${ROOTDIR}/edk2-rockchip:${ROOTDIR}/edk2-rockchip-non-osi:${ROOTDIR}/edk2-non-osi:${ROOTDIR}"
make -C "${ROOTDIR}/edk2/BaseTools"
source "${ROOTDIR}/edk2/edksetup.sh"
build \
-s \
-n 0 \
-a AARCH64 \
-t "${TOOLCHAIN}" \
-p "${ROOTDIR}/${DSC_FILE}" \
-b "${RELEASE_TYPE}" \
-D FIRMWARE_VER="${GIT_COMMIT}" \
${EDK2_FLAGS}
#
# Compile final image
#
_pack_image
echo "Build done: RK3588_NOR_FLASH.img"
}
function _clean() { rm --one-file-system --recursive --force "${OUTDIR}"/workspace "${OUTDIR}"/RK3588_*.img; }
function _distclean() { if [ -d .git ]; then git clean -xdf; else _clean; fi; }
#
# Default variables
#
typeset -l DEVICE
typeset -u RELEASE_TYPE
DEVICE=""
RELEASE_TYPE=DEBUG
TOOLCHAIN=GCC
EDK2_FLAGS=""
CLEAN=false
DISTCLEAN=false
OUTDIR="${PWD}"
#
# Get options
#
OPTS=$(getopt -o "d:r:t:CDh" -l "device:,release:,toolchain:,edk2-flags:,clean,distclean,help" -n build.sh -- "${@}") || _help $?
eval set -- "${OPTS}"
while true; do
case "${1}" in
-d|--device) DEVICE="${2}"; shift 2 ;;
-r|--release) RELEASE_TYPE="${2}"; shift 2 ;;
-t|--toolchain) TOOLCHAIN="${2}"; shift 2 ;;
--edk2-flags) EDK2_FLAGS="${2}"; shift 2 ;;
-C|--clean) CLEAN=true; shift ;;
-D|--distclean) DISTCLEAN=true; shift ;;
-h|--help) _help 0; shift ;;
--) shift; break ;;
*) break ;;
esac
done
if [[ -n "${@}" ]]; then
echo "Invalid additional arguments '${@}'"
_help 1
fi
if "${DISTCLEAN}"; then _distclean; exit "$?"; fi
if "${CLEAN}"; then _clean; exit "$?"; fi
[ -z "${DEVICE}" ] && _help 1
[ -f "configs/${DEVICE}.conf" ] || [ "${DEVICE}" == "all" ] || _error "Device configuration not found"
#
# Get machine architecture
#
MACHINE_TYPE=$(uname -m)
# Fix-up possible differences in reported arch
if [ ${MACHINE_TYPE} == 'arm64' ]; then
MACHINE_TYPE='aarch64'
elif [ ${MACHINE_TYPE} == 'amd64' ]; then
MACHINE_TYPE='x86_64'
fi
if [ ${MACHINE_TYPE} != 'aarch64' ]; then
export CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
fi
GIT_COMMIT="$(git describe --tags --always)" || GIT_COMMIT="unknown"
export WORKSPACE="${OUTDIR}/workspace"
[ -d "${WORKSPACE}" ] || mkdir "${WORKSPACE}"
ROOTDIR="$(realpath "$(dirname "$0")")"
cd "${ROOTDIR}" || exit 1
# Exit on first error
set -e
if [ "${DEVICE}" == "all" ]
then
for i in configs/*.conf; do
DEV="$(basename "$i" .conf)"
if [ "${DEV}" != "RK3588" ]
then
echo "Building ${DEV}"
_build "${DEV}"
fi
done
else
_build "${DEVICE}"
fi