-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_rk_bootloader
executable file
·172 lines (153 loc) · 3.92 KB
/
generate_rk_bootloader
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
#!/bin/sh
# Usage function
function usage() {
cat >&2 <<EOF
${SH_FILE} is used to generate/burn official U-Boot firmware for Rockchip SoC
Usage: ${SH_FILE} -b board [-f dir] [-h] [-s] -u dir
Where:
-b board
-f firmware / pre-compiled binary blob directory
-h this help page
-s "burn" the generated U-Boot file on a sdcard
-u Rockchip tools directory
EOF
exit 0
}
# Error function
function error() {
echo -e "$@" >&2
exit 1
}
# Copy/Check function
function copy() {
typeset -r FILE=$1
typeset -r DEST=$2
cp ${FILE} ${DEST} >/dev/null 2>&1 \
|| error "Error while copying file ${FILE} to ${DEST}!"
}
# Variable(s)
typeset -r SH_FILE=${0##*/}
typeset -r U_BOOT_DIR=/dev/shm/u-boot-tmp
typeset -i BURN=0 ATF=0
typeset UBOOT_FILE=u-boot.bin
typeset UBOOT_IMG=u-boot.img
typeset IDBLOADER_FW=idbloader.img
typeset TRUST_FW=trust.img
typeset RK_TOOLS_DIR RK_FW_DIR BOARD CHIP DEV
typeset DDR_FW MINILOADER_FW LOADER_FW ATF_FW OPTEE_FW IDBLOADER_FW
typeset -x ATF_FW_FILE=$(ls ${PWD}/atf-bl31.* 2>/dev/null)
# Get options
while getopts "b:f:su:h" ARG; do
case ${ARG} in
b) BOARD=${OPTARG}
;;
f) RK_FW_DIR=${OPTARG}
;;
s) BURN=1
DEV=${MMC_DEV:=/dev/mmcblk0}
;;
u) RK_TOOLS_DIR=${OPTARG}
;;
h|*) usage
;;
esac
done
shift $((OPTIND-1))
# Board model must be filled!
[[ -z "${BOARD}" ]] \
&& error "Board model must be filled!"
if [[ -s "${ATF_FW_FILE}" ]]; then
echo "- ATF Firmware detected!"
IDBLOADER_FW=u-boot-rockchip.bin
ATF=1
else
# RK tools directory must be filled!
[[ -z "${RK_TOOLS_DIR}" ]] \
&& error "RK tools directory must be filled!"
# Set default FW directory if needed
[[ -z "${RK_FW_DIR}" ]] \
&& RK_FW_DIR=${RK_TOOLS_DIR}/bin/rk33
# Set variables based on the board
case ${BOARD} in
*rk3328*)
CHIP=rk3328
if [[ "${RK_FW_DIR}" == "bin/rk33" ]]; then
DDR_FW=${RK_FW_DIR}/rk3328_ddr_333MHz_v1.13.bin
MINILOADER_FW=${RK_FW_DIR}/rk3328_miniloader_v2.43.bin
ATF_FW=${RK_FW_DIR}/rk3328_bl31_v1.34.bin
LOADER_FW=${RK_FW_DIR}/rk3328_loader_ddr786_v1.06.243.bin
else
DDR_FW=${RK_FW_DIR}/rk3328_ddr_333MHz_v1.19.bin
MINILOADER_FW=${RK_FW_DIR}/rk322xh_miniloader_v2.50.bin
ATF_FW=${RK_FW_DIR}/rk322xh_bl31_v1.49.elf
OPTEE_FW=${RK_FW_DIR}/rk322xh_bl32_v2.01.bin
fi
;;
esac
fi
# Add Rockchip tools into PATH
typeset -x PATH=${RK_TOOLS_DIR}/bin/:${PATH}
# Create RK FW image if needed
if ! (( ATF )); then
cd ${U_BOOT_DIR}
${RK_TOOLS_DIR}/tools/loaderimage --pack --uboot ${UBOOT_FILE} ${UBOOT_IMG} 0x200000
tools/mkimage -n ${CHIP} -T rksd -d ${DDR_FW} ${IDBLOADER_FW}
cat ${MINILOADER_FW} >> ${IDBLOADER_FW}
cd ${OLDPWD}
fi
# Copy U-Boot files in the current directory
for FILE in ${U_BOOT_DIR}/${UBOOT_FILE} ${U_BOOT_DIR}/${UBOOT_IMG} ${U_BOOT_DIR}/${IDBLOADER_FW} ${DDR_FW} ${MINILOADER_FW} ${LOADER_FW} ${ATF_FW} ${OPTEE_FW}; do
if [[ -f ${FILE} ]]; then
echo "- Copy firmware file ${FILE##*/}..."
copy ${FILE} ${PWD}
fi
done
# Generate TRUST ini file if needed
if ! (( ATF )); then
cat >trust.ini <<EOF
[VERSION]
MAJOR=1
MINOR=2
[BL30_OPTION]
SEC=0
[BL31_OPTION]
SEC=1
PATH=${ATF_FW}
ADDR=0x10000
EOF
if [[ -z "${OPTEE_FW}" ]]; then
cat >>trust.ini <<EOF
[BL32_OPTION]
SEC=0
EOF
else
cat >>trust.ini <<EOF
[BL32_OPTION]
SEC=1
PATH=${OPTEE_FW}
ADDR=0x08400000
EOF
fi
cat >>trust.ini <<EOF
[BL33_OPTION]
SEC=0
[OUTPUT]
PATH=trust.img
EOF
# Generate TRUST FW
${RK_TOOLS_DIR}/tools/trust_merger trust.ini
fi
# Write U-Boot to sd-card
if (( BURN )); then
echo "- Burning ${IDBLOADER_FW}..."
dd if=${IDBLOADER_FW} of=${DEV} conv=fsync,notrunc seek=64
if ! (( ATF )); then
echo "- Burning ${UBOOT_IMG}..."
dd if=${UBOOT_IMG} of=${DEV} conv=fsync,notrunc seek=16384
echo "- Burning ${TRUST_FW}..."
dd if=${TRUST_FW} of=${DEV} conv=fsync,notrunc seek=24576
fi
sync ${DEV}
fi
# Clean exit
exit 0