blob: ffb292b65aced106d354509a49980cd49c294e17 [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
xiaobo gude8a46a2018-03-05 21:41:54 +080039 if [ -f $MANIFEST ]; then
40 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]}
120 update_bin_path $loop "source"
xiaobo gu38355222019-09-27 17:13:16 +0800121 CONFIG_DDR_FW=1
122 export CONFIG_DDR_FW
xiaobo gude8a46a2018-03-05 21:41:54 +0800123 done
124 fi
125 else
126 for loop in ${!BLX_NAME[@]}; do
xiaobo gude8a46a2018-03-05 21:41:54 +0800127 if [ -d ${BLX_BIN_FOLDER[$loop]} ]; then
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800128 # loop bin folder. (this will overwrite src version if both exist)
xiaobo gude8a46a2018-03-05 21:41:54 +0800129 git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1
130 git_msg=${GIT_OPERATE_INFO}
131 IFS=' ' read -ra DATA <<< "$git_msg"
132 CUR_REV[$loop]=${DATA[2]}
133 echo -n "revL:${CUR_REV[$loop]} "
134 echo "@ ${BLX_BIN_FOLDER[$loop]}"
Honglin Zhangcd8a9fc2019-11-22 17:52:55 +0800135 elif [ -d ${BLX_SRC_FOLDER[$loop]} ]; then
136 # merge into android/buildroot, can not get manifest.xml, get version by folder
137 # loop src folder
138 echo "No-Manifest: Src code only. build with --update-${BLX_NAME[$loop]}"
139 update_bin_path $loop "source"
140 CONFIG_DDR_FW=1
141 export CONFIG_DDR_FW
xiaobo gude8a46a2018-03-05 21:41:54 +0800142 fi
143 done
144 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800145}
146
147function git_operate() {
148 # $1: path, $2: other parameters
149 GIT_OPERATE_INFO=`git --git-dir $1/.git --work-tree=$1 ${@:2}`
150 dbg "${GIT_OPERATE_INFO}"
151}
152
153function git_operate2() {
154 # use -C. for pull use. don't know why [git_operate pull] doesn't work, server git update?
155 # $1: path, $2: other parameters
156 GIT_OPERATE_INFO="`git -C \"$1\" ${@:2}`"
157 #echo "${GIT_OPERATE_INFO}"
158}
159
160function get_blx_bin() {
161 # $1: current blx index
162 index=$1
163 git_operate ${BLX_BIN_FOLDER[index]} log --pretty=oneline
164
165 git_msg=${GIT_OPERATE_INFO}
166 BLX_READY[${index}]="false"
167 mkdir -p ${FIP_BUILD_FOLDER}
168
169 # get version log line by line, compare with target version
170 line_num=0
171 while read line;
172 do
173 IFS=' ' read -ra DATA <<< "$line"
174 # v1-fix support short-id
xiaobo gude8a46a2018-03-05 21:41:54 +0800175 dbg "${CUR_REV[$index]:0:7} - ${DATA[2]:0:7}"
xiaobo gue6c46862018-01-10 18:58:09 +0800176 if [ "${CUR_REV[$index]:0:7}" == "${DATA[2]:0:7}" ]; then
177 BLX_READY[${index}]="true"
178 dbg "blxbin:${DATA[0]} blxsrc: ${DATA[2]}"
179 dbg "blxbin:${DATA[0]} blxsrc-s:${DATA[2]:0:7}"
180 # reset to history version
181 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
182 git_operate2 ${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard
183 # copy binary file
184 if [ "bl32" == "${BLX_NAME[$index]}" ]; then
185 # bl32 is optional
186 if [ "y" == "${CONFIG_NEED_BL32}" ]; then
187 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
188 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
189 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
190 fi
191 fi
192 else
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800193 if [ "${CONFIG_CAS}" == "irdeto" ]; then
194 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME_IRDETO[index]} \
195 ${FIP_BUILD_FOLDER}/${BLX_BIN_NAME[index]} -f
196 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
197 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME_IRDETO[index]} \
198 ${FIP_BUILD_FOLDER}/${BLX_IMG_NAME[index]} 2>/dev/null
199 fi
200 else
201 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f
202 if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then
203 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null
204 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800205 fi
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800206 if [ -e ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ]; then
207 cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ${FIP_BUILD_FOLDER} -f
208 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800209 fi
210 # undo reset
211 if [ 0 -ne ${line_num} ]; then
212 # this is not latest version, can do reset. latest version doesn't have 'git reflog'
213 #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
214 git_operate2 ${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard
215 fi
216 break
217 fi
218 line_num=$((line_num+1))
219 done <<< "${git_msg}"
220 if [ "true" == ${BLX_READY[${index}]} ]; then
221 echo "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... done"
222 else
223 echo -n "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... failed"
224 if [ "true" == ${BLX_NEEDFUL[$index]} ]; then
225 echo "... abort"
226 exit -1
227 else
228 echo ""
229 fi
230 fi
231 return 0;
xiaobo gu8a3907e2019-05-22 11:46:49 +0800232}
Honglin Zhang694f5342019-12-09 14:54:40 +0800233
234function prepare_tools() {
235 echo "*****Compile tools*****"
236
237 mkdir -p ${FIP_BUILD_FOLDER}
238
239 if [ "${CONFIG_DDR_PARSE}" == "1" ]; then
240 if [ -d ${FIP_DDR_PARSE} ]; then
241 cd ${FIP_DDR_PARSE}
242 make clean; make
243 cd ${MAIN_FOLDER}
244
245 mv -f ${FIP_DDR_PARSE}/parse ${FIP_BUILD_FOLDER}
246 fi
247
248 if [ ! -x ${FIP_BUILD_FOLDER}/parse ]; then
249 echo "Error: no ddr_parse... abort"
250 exit -1
251 fi
252 fi
253
Honglin Zhang8fa9d152020-02-10 12:29:27 +0800254}