blob: a8f43f254b65fcab2d9ca67b5930dc5b14e6f62d [file] [log] [blame]
xiaobo gue6c46862018-01-10 18:58:09 +08001#!/bin/bash
2
3DEBUG_PRINT=0
4
xiaobo gue6c46862018-01-10 18:58:09 +08005declare GIT_OPERATE_INFO=""
6
7function dbg() {
8 if [ 0 != ${DEBUG_PRINT} ]; then
9 echo "$1"
10 fi
11}
12
13declare str_use=""
14# filter means get useful information
15function string_filter() {
16 # #1 origin str, #2 filter str, #3 split char, #4 which section
17 local str_origin=$1
18 local str_filter=$2
19 local str_split=$3
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080020
21 if [[ "$str_origin" =~ "$str_filter" ]]; then
22 str_origin=${str_origin#*${str_filter}} # filter
23 IFS=${str_split} read -ra DATA <<< "$str_origin"
24 str_use=${DATA[$4]}
25
26 if [ -z ${str_use} ]; then
27 str_use="null"
28 fi
29 else
30 str_use="null"
31 fi
xiaobo gue6c46862018-01-10 18:58:09 +080032}
33
34function get_versions() {
35 echo "Get version info"
xiaobo gude8a46a2018-03-05 21:41:54 +080036 declare -a SRC_REV
37 declare -a BIN_REV
xiaobo gue6c46862018-01-10 18:58:09 +080038 # read manifest, get each blx information
Bo Lv73e30072020-07-28 07:52:10 -040039 if [ -f $MANIFEST ] && [ -L $MANIFEST ]; then
xiaobo gude8a46a2018-03-05 21:41:54 +080040 while read -r line || [[ -n $line ]]; do
41 string_filter "${line}" "dest-branch=" '"' 1
42 GIT_INFO[0]=${str_use}
43 string_filter "${line}" "path=" '"' 1
44 GIT_INFO[1]=${str_use}
45 string_filter "${line}" "revision=" '"' 1
46 GIT_INFO[2]=${str_use}
47 string_filter "${line}" "name=" '"' 1
48 GIT_INFO[3]=${str_use}
49 string_filter "${line}" "remote=" '"' 1
50 GIT_INFO[4]=${str_use}
51 # if this line doesn't contain any info, skip it
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080052 if [ "${GIT_INFO[2]}" == "null" ]; then
xiaobo gude8a46a2018-03-05 21:41:54 +080053 continue
54 fi
55 #echo "${GIT_INFO[0]} ${GIT_INFO[1]} ${GIT_INFO[2]} ${GIT_INFO[3]} ${GIT_INFO[4]}"
56 #echo ${BLX_NAME[@]}
57 #echo ${BLX_SRC_FOLDER[@]}
58 for loop in ${!BLX_NAME[@]}; do
Meng yu22c55a52023-05-18 17:19:29 +080059 if [ ! -d ${BLX_BIN_FOLDER[loop]} ]; then
60 if [[ ${BLX_BIN_FOLDER[loop]:0:4} == "bl31" || ${BLX_BIN_FOLDER[loop]:0:4} == "bl32" ]]; then
61 echo "${BLX_BIN_FOLDER[loop]}"
62 BLX_BIN_FOLDER[loop]="${BLX_BIN_FOLDER[loop]:5}"
63 BLX_SRC_FOLDER[loop]="${BLX_SRC_FOLDER[loop]:5}"
64 if [ ! -d ${BLX_BIN_FOLDER[loop]} ]; then
65 echo "${BLX_BIN_FOLDER[loop]} need modify try to remove 1.0"
66 BLX_BIN_FOLDER[loop]="${BLX_BIN_FOLDER[loop]/"_1.0"}"
67 BLX_SRC_FOLDER[loop]="${BLX_SRC_FOLDER[loop]/"_1.0"}"
68 fi
69 if [ ! -d ${BLX_BIN_FOLDER[loop]} ]; then
70 echo "${BLX_BIN_FOLDER[loop]} need modify try to remove2.4"
71 BLX_BIN_FOLDER[loop]="${BLX_BIN_FOLDER[loop]/"_2.4"}"
72 BLX_SRC_FOLDER[loop]="${BLX_SRC_FOLDER[loop]/"_2.4"}"
73 fi
74 echo "${BLX_BIN_FOLDER[loop]}"
75 fi
76 fi
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080077 if [[ "${GIT_INFO[1]}" =~ "${BLX_SRC_FOLDER[$loop]}" && "${GIT_INFO[3]}" == "${BLX_SRC_GIT[$loop]}" ]]; then
xiaobo gude8a46a2018-03-05 21:41:54 +080078 SRC_REV[$loop]=${GIT_INFO[2]}
79 #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]}
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080080 echo -n "name:${BLX_NAME[$loop]}, path:${GIT_INFO[1]}, ${BLX_SRC_FOLDER[$loop]}, "
81 if [[ "${GIT_INFO[0]}" == "null" || "${SRC_REV[$loop]}" == "${GIT_INFO[0]}" ]]; then
xiaobo gude8a46a2018-03-05 21:41:54 +080082 # if only specify branch name, not version, use latest binaries under bin/ folders
83 # use bin.git revision, in case src code have local commits
84 if [ -d ${BLX_BIN_FOLDER[loop]} ]; then
85 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
86 git_msg=${GIT_OPERATE_INFO}
87 else
88 git_msg=""
89 fi
90 IFS=' ' read -ra DATA <<< "$git_msg"
91 SRC_REV[$loop]=${DATA[2]}
92 echo -n "revL:${SRC_REV[$loop]} "
93 else
94 SRC_REV[$loop]=${GIT_INFO[2]}
95 echo -n "rev:${SRC_REV[$loop]} "
96 fi
97 echo "@ ${GIT_INFO[0]}"
98 fi
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080099 if [[ "${GIT_INFO[1]}" =~ "${BLX_BIN_FOLDER[$loop]}" && "${GIT_INFO[3]}" == "${BLX_BIN_GIT[$loop]}" ]]; then
xiaobo gude8a46a2018-03-05 21:41:54 +0800100 BIN_REV[$loop]=${GIT_INFO[2]}
101 #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]}
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800102 echo -n "name:${BLX_NAME[$loop]}, path:${GIT_INFO[1]}, ${BLX_BIN_FOLDER[$loop]}, "
103 if [[ "${GIT_INFO[0]}" == "null" || "${BIN_REV[$loop]}" == "${GIT_INFO[0]}" ]]; then
xiaobo gude8a46a2018-03-05 21:41:54 +0800104 # if only specify branch name, not version, use latest binaries under bin/ folders
105 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
106 else
107 # else get bin->src version
108 git_operate ${BLX_BIN_FOLDER[loop]} log ${BIN_REV[$loop]} --pretty=oneline -1
109 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800110 git_msg=${GIT_OPERATE_INFO}
111 IFS=' ' read -ra DATA <<< "$git_msg"
xiaobo gude8a46a2018-03-05 21:41:54 +0800112 BIN_REV[$loop]=${DATA[2]}
113 echo -n "revL:${BIN_REV[$loop]} "
114 echo "@ ${GIT_INFO[0]}"
xiaobo gue6c46862018-01-10 18:58:09 +0800115 fi
xiaobo gude8a46a2018-03-05 21:41:54 +0800116 done
117 done < "$MANIFEST"
118 # SRC_REV="" means this is a no-src repo, use bin.git
119 if [ "" == "${SRC_REV[0]}" ]; then
120 dbg "src_rev NULL"
121 for loop in ${!BIN_REV[@]}; do
122 echo "Manifest: Use bin.git version. ${BLX_BIN_FOLDER[$loop]} - ${BIN_REV[$loop]}"
123 CUR_REV[$loop]=${BIN_REV[$loop]}
124 done
125 else
126 dbg "src_rev not NULL"
127 for loop in ${!SRC_REV[@]}; do
128 dbg "Manifest: src.git version. ${BLX_SRC_FOLDER[$loop]} - ${SRC_REV[$loop]}"
129 CUR_REV[$loop]=${SRC_REV[$loop]}
130 done
131 fi
132
133 # BIN_REV="" means this is a no-bin repo, use src.git
134 if [ "" == "${BIN_REV[0]}" ]; then
135 for loop in ${!SRC_REV[@]}; do
136 echo "Manifest: Src code only. build with --update-${BLX_NAME[$loop]}"
137 #CUR_REV[$loop]=${SRC_REV[$loop]}
Honglin Zhang9dd03082020-07-22 07:24:44 -0400138 #update_bin_path $loop "source"
139 BIN_PATH[$loop]="source"
140 if [ BLX_NAME[$loop] == ${BLX_NAME_GLB[0]} ]; then
141 CONFIG_DDR_FW=1
142 export CONFIG_DDR_FW
143 fi
xiaobo gude8a46a2018-03-05 21:41:54 +0800144 done
145 fi
146 else
147 for loop in ${!BLX_NAME[@]}; do
xiaobo gude8a46a2018-03-05 21:41:54 +0800148 if [ -d ${BLX_BIN_FOLDER[$loop]} ]; then
Bo Lvc8e2bee2022-09-28 12:48:45 +0800149 if [ "1" != "${CONFIG_WITHOUT_BIN_GIT}" ]; then
150 # loop bin folder. (this will overwrite src version if both exist)
151 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
152 git_msg=${GIT_OPERATE_INFO}
153 IFS=' ' read -ra DATA <<< "$git_msg"
154 CUR_REV[$loop]=${DATA[2]}
155 echo -n "revL:${CUR_REV[$loop]} "
156 fi
xiaobo gude8a46a2018-03-05 21:41:54 +0800157 echo "@ ${BLX_BIN_FOLDER[$loop]}"
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800158 elif [ -d ${BLX_SRC_FOLDER[$loop]} ]; then
159 # merge into android/buildroot, can not get manifest.xml, get version by folder
160 # loop src folder
161 echo "No-Manifest: Src code only. build with --update-${BLX_NAME[$loop]}"
Honglin Zhang9dd03082020-07-22 07:24:44 -0400162 #update_bin_path $loop "source"
163 BIN_PATH[$loop]="source"
164 if [ BLX_NAME[$loop] == ${BLX_NAME_GLB[0]} ]; then
165 CONFIG_DDR_FW=1
166 export CONFIG_DDR_FW
167 fi
xiaobo gude8a46a2018-03-05 21:41:54 +0800168 fi
169 done
170 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800171}
172
173function git_operate() {
174 # $1: path, $2: other parameters
175 GIT_OPERATE_INFO=`git --git-dir $1/.git --work-tree=$1 ${@:2}`
176 dbg "${GIT_OPERATE_INFO}"
177}
178
179function git_operate2() {
180 # use -C. for pull use. don't know why [git_operate pull] doesn't work, server git update?
181 # $1: path, $2: other parameters
182 GIT_OPERATE_INFO="`git -C \"$1\" ${@:2}`"
183 #echo "${GIT_OPERATE_INFO}"
184}
185
186function get_blx_bin() {
187 # $1: current blx index
188 index=$1
Honglin Zhang9e062c92020-02-26 12:31:08 +0800189
190 # check for bl40, while only get bl40 from external path
191 if [ "${BLX_NAME[$index]}" == "bl40" ]; then
192 echo "skip to get bl40 from xml git"
193 return 0
194 fi
Honglin Zhang143efbf2020-08-20 04:16:49 -0400195
196 # special case for SC2
Zhongfu Luo3a6e5342020-12-27 13:11:54 +0800197 if [ "$ADVANCED_BOOTLOADER" == "1" ]; then
Honglin Zhang143efbf2020-08-20 04:16:49 -0400198 if [ "${BLX_NAME[$index]}" == "bl2" ]; then
199 BLX_BIN_SUB_FOLDER="${BLX_BIN_SUB_CHIP}/${DDRFW_TYPE}"
200 else
201 BLX_BIN_SUB_FOLDER="${BLX_BIN_SUB_CHIP}"
202 fi
203 else
204 BLX_BIN_SUB_FOLDER=""
205 fi
206
Bo Lvc8e2bee2022-09-28 12:48:45 +0800207 # if uboot code without git for binary directory
208 if [ "1" == "${CONFIG_WITHOUT_BIN_GIT}" ]; then
209 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_SUB_FOLDER}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
Yingwen Wu20e58d72024-12-04 19:00:24 +0800210 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
211 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
212 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800213 else
214 git_operate ${BLX_BIN_FOLDER[index]} log --pretty=oneline
xiaobo gue6c46862018-01-10 18:58:09 +0800215
Bo Lvc8e2bee2022-09-28 12:48:45 +0800216 git_msg=${GIT_OPERATE_INFO}
217 BLX_READY[${index}]="false"
218 mkdir -p ${FIP_BUILD_FOLDER}
xiaobo gue6c46862018-01-10 18:58:09 +0800219
Bo Lvc8e2bee2022-09-28 12:48:45 +0800220 # get version log line by line, compare with target version
221 line_num=0
222 while read line;
223 do
224 IFS=' ' read -ra DATA <<< "$line"
225 # v1-fix support short-id
226 dbg "${CUR_REV[$index]:0:7} - ${DATA[2]:0:7}"
227 if [ "${CUR_REV[$index]:0:7}" == "${DATA[2]:0:7}" ]; then
228 BLX_READY[${index}]="true"
229 dbg "blxbin:${DATA[0]} blxsrc: ${DATA[2]}"
230 dbg "blxbin:${DATA[0]} blxsrc-s:${DATA[2]:0:7}"
231 # reset to history version
232 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
233 git_operate2 ${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
234 # copy binary file
235 if [ "bl32" == "${BLX_NAME[$index]}" ]; then
236 # bl32 is optional
237 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
238 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_SUB_FOLDER}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
239 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
240 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
Lawrence Mok048be0f2020-02-24 18:03:43 -0800241 fi
242 fi
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800243 else
Bo Lvc8e2bee2022-09-28 12:48:45 +0800244 if [ "${CONFIG_CAS}" == "irdeto" ]; then
245 if [ "${BLX_BIN_NAME_IRDETO[index]}" != "NULL" ]; then
246 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME_IRDETO[index]} \
247 ${FIP_BUILD_FOLDER}/${BLX_BIN_NAME[index]} -f || \
248 BLX_READY[${index}]="false"
249 fi
250 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ] && \
251 [ "${BLX_IMG_NAME_IRDETO[index]}" != "NULL" ]; then
252 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME_IRDETO[index]} \
253 ${FIP_BUILD_FOLDER}/${BLX_IMG_NAME[index]} || \
254 BLX_READY[${index}]="false"
255 fi
256 elif [ "${CONFIG_CAS}" == "vmx" ]; then
257 if [ "${BLX_BIN_NAME_VMX[index]}" != "NULL" ]; then
258 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME_VMX[index]} \
259 ${FIP_BUILD_FOLDER}/${BLX_BIN_NAME[index]} -f || \
260 BLX_READY[${index}]="false"
261 fi
262 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
263 if [ "${BLX_IMG_NAME_VMX[index]}" != "NULL" ]; then
264 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME_VMX[index]} \
265 ${FIP_BUILD_FOLDER}/${BLX_IMG_NAME[index]} || \
266 BLX_READY[${index}]="false"
267 fi
268 fi
269 else
270 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_SUB_FOLDER}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
271 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
272 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
273 fi
274 fi
275 if [ -e ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ]; then
276 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ${FIP_BUILD_FOLDER} -f
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800277 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800278 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800279 # undo reset
280 if [ 0 -ne ${line_num} ]; then
281 # this is not latest version, can do reset. latest version doesn't have 'git reflog'
282 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
283 git_operate2 ${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800284 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800285 break
xiaobo gue6c46862018-01-10 18:58:09 +0800286 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800287 line_num=$((line_num+1))
288 done <<< "${git_msg}"
289 if [ "true" == ${BLX_READY[${index}]} ]; then
290 echo "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... done"
xiaobo gue6c46862018-01-10 18:58:09 +0800291 else
Bo Lvc8e2bee2022-09-28 12:48:45 +0800292 echo -n "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... failed"
293 if [ "true" == ${BLX_NEEDFUL[$index]} ]; then
294 echo "... abort"
295 exit -1
296 else
297 echo ""
298 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800299 fi
300 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800301
xiaobo gue6c46862018-01-10 18:58:09 +0800302 return 0;
xiaobo gu8a3907e2019-05-22 11:46:49 +0800303}
Honglin Zhang694f5342019-12-09 14:54:40 +0800304
305function prepare_tools() {
306 echo "*****Compile tools*****"
307
308 mkdir -p ${FIP_BUILD_FOLDER}
309
310 if [ "${CONFIG_DDR_PARSE}" == "1" ]; then
311 if [ -d ${FIP_DDR_PARSE} ]; then
312 cd ${FIP_DDR_PARSE}
313 make clean; make
314 cd ${MAIN_FOLDER}
315
316 mv -f ${FIP_DDR_PARSE}/parse ${FIP_BUILD_FOLDER}
317 fi
318
319 if [ ! -x ${FIP_BUILD_FOLDER}/parse ]; then
320 echo "Error: no ddr_parse... abort"
321 exit -1
322 fi
323 fi
324
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800325}