blob: dcc81e841539de4aacbe540be75a80ca9421ae13 [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
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800131 # loop bin folder. (this will overwrite src version if both exist)
xiaobo gude8a46a2018-03-05 21:41:54 +0800132 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
133 git_msg=${GIT_OPERATE_INFO}
134 IFS=' ' read -ra DATA <<< "$git_msg"
135 CUR_REV[$loop]=${DATA[2]}
136 echo -n "revL:${CUR_REV[$loop]} "
137 echo "@ ${BLX_BIN_FOLDER[$loop]}"
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800138 elif [ -d ${BLX_SRC_FOLDER[$loop]} ]; then
139 # merge into android/buildroot, can not get manifest.xml, get version by folder
140 # loop src folder
141 echo "No-Manifest: Src code only. build with --update-${BLX_NAME[$loop]}"
Honglin Zhang9dd03082020-07-22 07:24:44 -0400142 #update_bin_path $loop "source"
143 BIN_PATH[$loop]="source"
144 if [ BLX_NAME[$loop] == ${BLX_NAME_GLB[0]} ]; then
145 CONFIG_DDR_FW=1
146 export CONFIG_DDR_FW
147 fi
xiaobo gude8a46a2018-03-05 21:41:54 +0800148 fi
149 done
150 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800151}
152
153function git_operate() {
154 # $1: path, $2: other parameters
155 GIT_OPERATE_INFO=`git --git-dir $1/.git --work-tree=$1 ${@:2}`
156 dbg "${GIT_OPERATE_INFO}"
157}
158
159function git_operate2() {
160 # use -C. for pull use. don't know why [git_operate pull] doesn't work, server git update?
161 # $1: path, $2: other parameters
162 GIT_OPERATE_INFO="`git -C \"$1\" ${@:2}`"
163 #echo "${GIT_OPERATE_INFO}"
164}
165
166function get_blx_bin() {
167 # $1: current blx index
168 index=$1
Honglin Zhang9e062c92020-02-26 12:31:08 +0800169
170 # check for bl40, while only get bl40 from external path
171 if [ "${BLX_NAME[$index]}" == "bl40" ]; then
172 echo "skip to get bl40 from xml git"
173 return 0
174 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800175 git_operate ${BLX_BIN_FOLDER[index]} log --pretty=oneline
176
177 git_msg=${GIT_OPERATE_INFO}
178 BLX_READY[${index}]="false"
179 mkdir -p ${FIP_BUILD_FOLDER}
180
181 # get version log line by line, compare with target version
182 line_num=0
183 while read line;
184 do
185 IFS=' ' read -ra DATA <<< "$line"
186 # v1-fix support short-id
xiaobo gude8a46a2018-03-05 21:41:54 +0800187 dbg "${CUR_REV[$index]:0:7} - ${DATA[2]:0:7}"
xiaobo gue6c46862018-01-10 18:58:09 +0800188 if [ "${CUR_REV[$index]:0:7}" == "${DATA[2]:0:7}" ]; then
189 BLX_READY[${index}]="true"
190 dbg "blxbin:${DATA[0]} blxsrc: ${DATA[2]}"
191 dbg "blxbin:${DATA[0]} blxsrc-s:${DATA[2]:0:7}"
192 # reset to history version
193 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
194 git_operate2 ${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
195 # copy binary file
196 if [ "bl32" == "${BLX_NAME[$index]}" ]; then
197 # bl32 is optional
198 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
Zhongfu Luoa1e540c2020-07-17 15:44:37 +0800199 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_SUB_FOLDER}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
xiaobo gue6c46862018-01-10 18:58:09 +0800200 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
201 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
202 fi
203 fi
204 else
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800205 if [ "${CONFIG_CAS}" == "irdeto" ]; then
Honglin Zhanga5041212020-03-05 21:11:31 +0800206 if [ "${BLX_BIN_NAME_IRDETO[index]}" != "NULL" ]; then
207 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME_IRDETO[index]} \
208 ${FIP_BUILD_FOLDER}/${BLX_BIN_NAME[index]} -f || \
209 BLX_READY[${index}]="false"
210 fi
211 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ] && \
212 [ "${BLX_IMG_NAME_IRDETO[index]}" != "NULL" ]; then
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800213 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME_IRDETO[index]} \
Honglin Zhanga5041212020-03-05 21:11:31 +0800214 ${FIP_BUILD_FOLDER}/${BLX_IMG_NAME[index]} || \
215 BLX_READY[${index}]="false"
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800216 fi
Lawrence Mok048be0f2020-02-24 18:03:43 -0800217 elif [ "${CONFIG_CAS}" == "vmx" ]; then
218 if [ "${BLX_BIN_NAME_VMX[index]}" != "NULL" ]; then
219 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME_VMX[index]} \
220 ${FIP_BUILD_FOLDER}/${BLX_BIN_NAME[index]} -f || \
221 BLX_READY[${index}]="false"
222 fi
223 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
224 if [ "${BLX_IMG_NAME_VMX[index]}" != "NULL" ]; then
225 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME_VMX[index]} \
226 ${FIP_BUILD_FOLDER}/${BLX_IMG_NAME[index]} || \
227 BLX_READY[${index}]="false"
228 fi
229 fi
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800230 else
Zhongfu Luoa1e540c2020-07-17 15:44:37 +0800231 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_SUB_FOLDER}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800232 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
233 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
234 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800235 fi
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800236 if [ -e ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ]; then
237 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ${FIP_BUILD_FOLDER} -f
238 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800239 fi
240 # undo reset
241 if [ 0 -ne ${line_num} ]; then
242 # this is not latest version, can do reset. latest version doesn't have 'git reflog'
243 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
244 git_operate2 ${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
245 fi
246 break
247 fi
248 line_num=$((line_num+1))
249 done <<< "${git_msg}"
250 if [ "true" == ${BLX_READY[${index}]} ]; then
251 echo "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... done"
252 else
253 echo -n "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... failed"
254 if [ "true" == ${BLX_NEEDFUL[$index]} ]; then
255 echo "... abort"
256 exit -1
257 else
258 echo ""
259 fi
260 fi
261 return 0;
xiaobo gu8a3907e2019-05-22 11:46:49 +0800262}
Honglin Zhang694f5342019-12-09 14:54:40 +0800263
264function prepare_tools() {
265 echo "*****Compile tools*****"
266
267 mkdir -p ${FIP_BUILD_FOLDER}
268
269 if [ "${CONFIG_DDR_PARSE}" == "1" ]; then
270 if [ -d ${FIP_DDR_PARSE} ]; then
271 cd ${FIP_DDR_PARSE}
272 make clean; make
273 cd ${MAIN_FOLDER}
274
275 mv -f ${FIP_DDR_PARSE}/parse ${FIP_BUILD_FOLDER}
276 fi
277
278 if [ ! -x ${FIP_BUILD_FOLDER}/parse ]; then
279 echo "Error: no ddr_parse... abort"
280 exit -1
281 fi
282 fi
283
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800284}