blob: 6d76a2e01638d1230ba11b3d7f216b13b14a2560 [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
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080059 if [[ "${GIT_INFO[1]}" =~ "${BLX_SRC_FOLDER[$loop]}" && "${GIT_INFO[3]}" == "${BLX_SRC_GIT[$loop]}" ]]; then
xiaobo gude8a46a2018-03-05 21:41:54 +080060 SRC_REV[$loop]=${GIT_INFO[2]}
61 #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]}
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080062 echo -n "name:${BLX_NAME[$loop]}, path:${GIT_INFO[1]}, ${BLX_SRC_FOLDER[$loop]}, "
63 if [[ "${GIT_INFO[0]}" == "null" || "${SRC_REV[$loop]}" == "${GIT_INFO[0]}" ]]; then
xiaobo gude8a46a2018-03-05 21:41:54 +080064 # if only specify branch name, not version, use latest binaries under bin/ folders
65 # use bin.git revision, in case src code have local commits
66 if [ -d ${BLX_BIN_FOLDER[loop]} ]; then
67 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
68 git_msg=${GIT_OPERATE_INFO}
69 else
70 git_msg=""
71 fi
72 IFS=' ' read -ra DATA <<< "$git_msg"
73 SRC_REV[$loop]=${DATA[2]}
74 echo -n "revL:${SRC_REV[$loop]} "
75 else
76 SRC_REV[$loop]=${GIT_INFO[2]}
77 echo -n "rev:${SRC_REV[$loop]} "
78 fi
79 echo "@ ${GIT_INFO[0]}"
80 fi
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080081 if [[ "${GIT_INFO[1]}" =~ "${BLX_BIN_FOLDER[$loop]}" && "${GIT_INFO[3]}" == "${BLX_BIN_GIT[$loop]}" ]]; then
xiaobo gude8a46a2018-03-05 21:41:54 +080082 BIN_REV[$loop]=${GIT_INFO[2]}
83 #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]}
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +080084 echo -n "name:${BLX_NAME[$loop]}, path:${GIT_INFO[1]}, ${BLX_BIN_FOLDER[$loop]}, "
85 if [[ "${GIT_INFO[0]}" == "null" || "${BIN_REV[$loop]}" == "${GIT_INFO[0]}" ]]; then
xiaobo gude8a46a2018-03-05 21:41:54 +080086 # if only specify branch name, not version, use latest binaries under bin/ folders
87 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
88 else
89 # else get bin->src version
90 git_operate ${BLX_BIN_FOLDER[loop]} log ${BIN_REV[$loop]} --pretty=oneline -1
91 fi
xiaobo gue6c46862018-01-10 18:58:09 +080092 git_msg=${GIT_OPERATE_INFO}
93 IFS=' ' read -ra DATA <<< "$git_msg"
xiaobo gude8a46a2018-03-05 21:41:54 +080094 BIN_REV[$loop]=${DATA[2]}
95 echo -n "revL:${BIN_REV[$loop]} "
96 echo "@ ${GIT_INFO[0]}"
xiaobo gue6c46862018-01-10 18:58:09 +080097 fi
xiaobo gude8a46a2018-03-05 21:41:54 +080098 done
99 done < "$MANIFEST"
100 # SRC_REV="" means this is a no-src repo, use bin.git
101 if [ "" == "${SRC_REV[0]}" ]; then
102 dbg "src_rev NULL"
103 for loop in ${!BIN_REV[@]}; do
104 echo "Manifest: Use bin.git version. ${BLX_BIN_FOLDER[$loop]} - ${BIN_REV[$loop]}"
105 CUR_REV[$loop]=${BIN_REV[$loop]}
106 done
107 else
108 dbg "src_rev not NULL"
109 for loop in ${!SRC_REV[@]}; do
110 dbg "Manifest: src.git version. ${BLX_SRC_FOLDER[$loop]} - ${SRC_REV[$loop]}"
111 CUR_REV[$loop]=${SRC_REV[$loop]}
112 done
113 fi
114
115 # BIN_REV="" means this is a no-bin repo, use src.git
116 if [ "" == "${BIN_REV[0]}" ]; then
117 for loop in ${!SRC_REV[@]}; do
118 echo "Manifest: Src code only. build with --update-${BLX_NAME[$loop]}"
119 #CUR_REV[$loop]=${SRC_REV[$loop]}
Honglin Zhang9dd03082020-07-22 07:24:44 -0400120 #update_bin_path $loop "source"
121 BIN_PATH[$loop]="source"
122 if [ BLX_NAME[$loop] == ${BLX_NAME_GLB[0]} ]; then
123 CONFIG_DDR_FW=1
124 export CONFIG_DDR_FW
125 fi
xiaobo gude8a46a2018-03-05 21:41:54 +0800126 done
127 fi
128 else
129 for loop in ${!BLX_NAME[@]}; do
xiaobo gude8a46a2018-03-05 21:41:54 +0800130 if [ -d ${BLX_BIN_FOLDER[$loop]} ]; then
Bo Lvc8e2bee2022-09-28 12:48:45 +0800131 if [ "1" != "${CONFIG_WITHOUT_BIN_GIT}" ]; then
132 # loop bin folder. (this will overwrite src version if both exist)
133 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
134 git_msg=${GIT_OPERATE_INFO}
135 IFS=' ' read -ra DATA <<< "$git_msg"
136 CUR_REV[$loop]=${DATA[2]}
137 echo -n "revL:${CUR_REV[$loop]} "
138 fi
xiaobo gude8a46a2018-03-05 21:41:54 +0800139 echo "@ ${BLX_BIN_FOLDER[$loop]}"
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800140 elif [ -d ${BLX_SRC_FOLDER[$loop]} ]; then
141 # merge into android/buildroot, can not get manifest.xml, get version by folder
142 # loop src folder
143 echo "No-Manifest: Src code only. build with --update-${BLX_NAME[$loop]}"
Honglin Zhang9dd03082020-07-22 07:24:44 -0400144 #update_bin_path $loop "source"
145 BIN_PATH[$loop]="source"
146 if [ BLX_NAME[$loop] == ${BLX_NAME_GLB[0]} ]; then
147 CONFIG_DDR_FW=1
148 export CONFIG_DDR_FW
149 fi
xiaobo gude8a46a2018-03-05 21:41:54 +0800150 fi
151 done
152 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800153}
154
155function git_operate() {
156 # $1: path, $2: other parameters
157 GIT_OPERATE_INFO=`git --git-dir $1/.git --work-tree=$1 ${@:2}`
158 dbg "${GIT_OPERATE_INFO}"
159}
160
161function git_operate2() {
162 # use -C. for pull use. don't know why [git_operate pull] doesn't work, server git update?
163 # $1: path, $2: other parameters
164 GIT_OPERATE_INFO="`git -C \"$1\" ${@:2}`"
165 #echo "${GIT_OPERATE_INFO}"
166}
167
168function get_blx_bin() {
169 # $1: current blx index
170 index=$1
Honglin Zhang9e062c92020-02-26 12:31:08 +0800171
172 # check for bl40, while only get bl40 from external path
173 if [ "${BLX_NAME[$index]}" == "bl40" ]; then
174 echo "skip to get bl40 from xml git"
175 return 0
176 fi
Honglin Zhang143efbf2020-08-20 04:16:49 -0400177
178 # special case for SC2
Zhongfu Luo3a6e5342020-12-27 13:11:54 +0800179 if [ "$ADVANCED_BOOTLOADER" == "1" ]; then
Honglin Zhang143efbf2020-08-20 04:16:49 -0400180 if [ "${BLX_NAME[$index]}" == "bl2" ]; then
181 BLX_BIN_SUB_FOLDER="${BLX_BIN_SUB_CHIP}/${DDRFW_TYPE}"
182 else
183 BLX_BIN_SUB_FOLDER="${BLX_BIN_SUB_CHIP}"
184 fi
185 else
186 BLX_BIN_SUB_FOLDER=""
187 fi
188
Bo Lvc8e2bee2022-09-28 12:48:45 +0800189 # if uboot code without git for binary directory
190 if [ "1" == "${CONFIG_WITHOUT_BIN_GIT}" ]; then
191 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_SUB_FOLDER}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
192 else
193 git_operate ${BLX_BIN_FOLDER[index]} log --pretty=oneline
xiaobo gue6c46862018-01-10 18:58:09 +0800194
Bo Lvc8e2bee2022-09-28 12:48:45 +0800195 git_msg=${GIT_OPERATE_INFO}
196 BLX_READY[${index}]="false"
197 mkdir -p ${FIP_BUILD_FOLDER}
xiaobo gue6c46862018-01-10 18:58:09 +0800198
Bo Lvc8e2bee2022-09-28 12:48:45 +0800199 # get version log line by line, compare with target version
200 line_num=0
201 while read line;
202 do
203 IFS=' ' read -ra DATA <<< "$line"
204 # v1-fix support short-id
205 dbg "${CUR_REV[$index]:0:7} - ${DATA[2]:0:7}"
206 if [ "${CUR_REV[$index]:0:7}" == "${DATA[2]:0:7}" ]; then
207 BLX_READY[${index}]="true"
208 dbg "blxbin:${DATA[0]} blxsrc: ${DATA[2]}"
209 dbg "blxbin:${DATA[0]} blxsrc-s:${DATA[2]:0:7}"
210 # reset to history version
211 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
212 git_operate2 ${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
213 # copy binary file
214 if [ "bl32" == "${BLX_NAME[$index]}" ]; then
215 # bl32 is optional
216 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
217 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_SUB_FOLDER}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
218 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
219 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
Lawrence Mok048be0f2020-02-24 18:03:43 -0800220 fi
221 fi
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800222 else
Bo Lvc8e2bee2022-09-28 12:48:45 +0800223 if [ "${CONFIG_CAS}" == "irdeto" ]; then
224 if [ "${BLX_BIN_NAME_IRDETO[index]}" != "NULL" ]; then
225 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME_IRDETO[index]} \
226 ${FIP_BUILD_FOLDER}/${BLX_BIN_NAME[index]} -f || \
227 BLX_READY[${index}]="false"
228 fi
229 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ] && \
230 [ "${BLX_IMG_NAME_IRDETO[index]}" != "NULL" ]; then
231 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME_IRDETO[index]} \
232 ${FIP_BUILD_FOLDER}/${BLX_IMG_NAME[index]} || \
233 BLX_READY[${index}]="false"
234 fi
235 elif [ "${CONFIG_CAS}" == "vmx" ]; then
236 if [ "${BLX_BIN_NAME_VMX[index]}" != "NULL" ]; then
237 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME_VMX[index]} \
238 ${FIP_BUILD_FOLDER}/${BLX_BIN_NAME[index]} -f || \
239 BLX_READY[${index}]="false"
240 fi
241 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
242 if [ "${BLX_IMG_NAME_VMX[index]}" != "NULL" ]; then
243 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME_VMX[index]} \
244 ${FIP_BUILD_FOLDER}/${BLX_IMG_NAME[index]} || \
245 BLX_READY[${index}]="false"
246 fi
247 fi
248 else
249 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_SUB_FOLDER}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
250 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
251 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
252 fi
253 fi
254 if [ -e ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ]; then
255 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ${FIP_BUILD_FOLDER} -f
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800256 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800257 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800258 # undo reset
259 if [ 0 -ne ${line_num} ]; then
260 # this is not latest version, can do reset. latest version doesn't have 'git reflog'
261 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
262 git_operate2 ${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800263 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800264 break
xiaobo gue6c46862018-01-10 18:58:09 +0800265 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800266 line_num=$((line_num+1))
267 done <<< "${git_msg}"
268 if [ "true" == ${BLX_READY[${index}]} ]; then
269 echo "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... done"
xiaobo gue6c46862018-01-10 18:58:09 +0800270 else
Bo Lvc8e2bee2022-09-28 12:48:45 +0800271 echo -n "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... failed"
272 if [ "true" == ${BLX_NEEDFUL[$index]} ]; then
273 echo "... abort"
274 exit -1
275 else
276 echo ""
277 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800278 fi
279 fi
Bo Lvc8e2bee2022-09-28 12:48:45 +0800280
xiaobo gue6c46862018-01-10 18:58:09 +0800281 return 0;
xiaobo gu8a3907e2019-05-22 11:46:49 +0800282}
Honglin Zhang694f5342019-12-09 14:54:40 +0800283
284function prepare_tools() {
285 echo "*****Compile tools*****"
286
287 mkdir -p ${FIP_BUILD_FOLDER}
288
289 if [ "${CONFIG_DDR_PARSE}" == "1" ]; then
290 if [ -d ${FIP_DDR_PARSE} ]; then
291 cd ${FIP_DDR_PARSE}
292 make clean; make
293 cd ${MAIN_FOLDER}
294
295 mv -f ${FIP_DDR_PARSE}/parse ${FIP_BUILD_FOLDER}
296 fi
297
298 if [ ! -x ${FIP_BUILD_FOLDER}/parse ]; then
299 echo "Error: no ddr_parse... abort"
300 exit -1
301 fi
302 fi
303
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800304}