xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | DEBUG_PRINT=0 |
| 4 | |
xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 5 | declare GIT_OPERATE_INFO="" |
| 6 | |
| 7 | function dbg() { |
| 8 | if [ 0 != ${DEBUG_PRINT} ]; then |
| 9 | echo "$1" |
| 10 | fi |
| 11 | } |
| 12 | |
| 13 | declare str_use="" |
| 14 | # filter means get useful information |
| 15 | function 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 |
| 20 | str_origin=${str_origin#*${str_filter}} # filter |
| 21 | IFS=${str_split} read -ra DATA <<< "$str_origin" |
| 22 | str_use=${DATA[$4]} |
| 23 | } |
| 24 | |
| 25 | function get_versions() { |
| 26 | echo "Get version info" |
xiaobo gu | de8a46a | 2018-03-05 21:41:54 +0800 | [diff] [blame] | 27 | declare -a SRC_REV |
| 28 | declare -a BIN_REV |
xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 29 | # read manifest, get each blx information |
xiaobo gu | de8a46a | 2018-03-05 21:41:54 +0800 | [diff] [blame] | 30 | if [ -f $MANIFEST ]; then |
| 31 | while read -r line || [[ -n $line ]]; do |
| 32 | string_filter "${line}" "dest-branch=" '"' 1 |
| 33 | GIT_INFO[0]=${str_use} |
| 34 | string_filter "${line}" "path=" '"' 1 |
| 35 | GIT_INFO[1]=${str_use} |
| 36 | string_filter "${line}" "revision=" '"' 1 |
| 37 | GIT_INFO[2]=${str_use} |
| 38 | string_filter "${line}" "name=" '"' 1 |
| 39 | GIT_INFO[3]=${str_use} |
| 40 | string_filter "${line}" "remote=" '"' 1 |
| 41 | GIT_INFO[4]=${str_use} |
| 42 | # if this line doesn't contain any info, skip it |
| 43 | if [ "${GIT_INFO[2]}" == "" ]; then |
| 44 | continue |
| 45 | fi |
| 46 | #echo "${GIT_INFO[0]} ${GIT_INFO[1]} ${GIT_INFO[2]} ${GIT_INFO[3]} ${GIT_INFO[4]}" |
| 47 | #echo ${BLX_NAME[@]} |
| 48 | #echo ${BLX_SRC_FOLDER[@]} |
| 49 | for loop in ${!BLX_NAME[@]}; do |
| 50 | if [ "${GIT_INFO[1]}" == "${BLX_SRC_FOLDER[$loop]}" ]; then |
| 51 | SRC_REV[$loop]=${GIT_INFO[2]} |
| 52 | #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]} |
| 53 | echo -n "name:${BLX_NAME[$loop]}, path:${BLX_SRC_FOLDER[$loop]}, " |
| 54 | if [ "${SRC_REV[$loop]}" == "${GIT_INFO[0]}" ]; then |
| 55 | # if only specify branch name, not version, use latest binaries under bin/ folders |
| 56 | # use bin.git revision, in case src code have local commits |
| 57 | if [ -d ${BLX_BIN_FOLDER[loop]} ]; then |
| 58 | git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1 |
| 59 | git_msg=${GIT_OPERATE_INFO} |
| 60 | else |
| 61 | git_msg="" |
| 62 | fi |
| 63 | IFS=' ' read -ra DATA <<< "$git_msg" |
| 64 | SRC_REV[$loop]=${DATA[2]} |
| 65 | echo -n "revL:${SRC_REV[$loop]} " |
| 66 | else |
| 67 | SRC_REV[$loop]=${GIT_INFO[2]} |
| 68 | echo -n "rev:${SRC_REV[$loop]} " |
| 69 | fi |
| 70 | echo "@ ${GIT_INFO[0]}" |
| 71 | fi |
| 72 | if [ "${GIT_INFO[1]}" == "${BLX_BIN_FOLDER[$loop]}" ]; then |
| 73 | BIN_REV[$loop]=${GIT_INFO[2]} |
| 74 | #CUR_BIN_BRANCH[$loop]=${GIT_INFO[0]} |
| 75 | echo -n "name:${BLX_NAME[$loop]}, path:${BLX_BIN_FOLDER[$loop]}, " |
| 76 | if [ "${BIN_REV[$loop]}" == "${GIT_INFO[0]}" ]; then |
| 77 | # if only specify branch name, not version, use latest binaries under bin/ folders |
| 78 | git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1 |
| 79 | else |
| 80 | # else get bin->src version |
| 81 | git_operate ${BLX_BIN_FOLDER[loop]} log ${BIN_REV[$loop]} --pretty=oneline -1 |
| 82 | fi |
xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 83 | git_msg=${GIT_OPERATE_INFO} |
| 84 | IFS=' ' read -ra DATA <<< "$git_msg" |
xiaobo gu | de8a46a | 2018-03-05 21:41:54 +0800 | [diff] [blame] | 85 | BIN_REV[$loop]=${DATA[2]} |
| 86 | echo -n "revL:${BIN_REV[$loop]} " |
| 87 | echo "@ ${GIT_INFO[0]}" |
xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 88 | fi |
xiaobo gu | de8a46a | 2018-03-05 21:41:54 +0800 | [diff] [blame] | 89 | done |
| 90 | done < "$MANIFEST" |
| 91 | # SRC_REV="" means this is a no-src repo, use bin.git |
| 92 | if [ "" == "${SRC_REV[0]}" ]; then |
| 93 | dbg "src_rev NULL" |
| 94 | for loop in ${!BIN_REV[@]}; do |
| 95 | echo "Manifest: Use bin.git version. ${BLX_BIN_FOLDER[$loop]} - ${BIN_REV[$loop]}" |
| 96 | CUR_REV[$loop]=${BIN_REV[$loop]} |
| 97 | done |
| 98 | else |
| 99 | dbg "src_rev not NULL" |
| 100 | for loop in ${!SRC_REV[@]}; do |
| 101 | dbg "Manifest: src.git version. ${BLX_SRC_FOLDER[$loop]} - ${SRC_REV[$loop]}" |
| 102 | CUR_REV[$loop]=${SRC_REV[$loop]} |
| 103 | done |
| 104 | fi |
| 105 | |
| 106 | # BIN_REV="" means this is a no-bin repo, use src.git |
| 107 | if [ "" == "${BIN_REV[0]}" ]; then |
| 108 | for loop in ${!SRC_REV[@]}; do |
| 109 | echo "Manifest: Src code only. build with --update-${BLX_NAME[$loop]}" |
| 110 | #CUR_REV[$loop]=${SRC_REV[$loop]} |
| 111 | update_bin_path $loop "source" |
xiaobo gu | 3835522 | 2019-09-27 17:13:16 +0800 | [diff] [blame^] | 112 | CONFIG_DDR_FW=1 |
| 113 | export CONFIG_DDR_FW |
xiaobo gu | de8a46a | 2018-03-05 21:41:54 +0800 | [diff] [blame] | 114 | done |
| 115 | fi |
| 116 | else |
| 117 | for loop in ${!BLX_NAME[@]}; do |
| 118 | # merge into android/buildroot, can not get manifest.xml, get version by folder |
| 119 | # loop src folder |
| 120 | if [ -d ${BLX_SRC_FOLDER[$loop]} ]; then |
| 121 | echo "No-Manifest: Src code only. build with --update-${BLX_NAME[$loop]}" |
| 122 | update_bin_path $loop "source" |
xiaobo gu | 3835522 | 2019-09-27 17:13:16 +0800 | [diff] [blame^] | 123 | CONFIG_DDR_FW=1 |
| 124 | export CONFIG_DDR_FW |
xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 125 | fi |
| 126 | done |
xiaobo gu | de8a46a | 2018-03-05 21:41:54 +0800 | [diff] [blame] | 127 | # loop bin folder. (this will overwrite src version if both exist) |
| 128 | for loop in ${!BLX_NAME[@]}; do |
| 129 | if [ -d ${BLX_BIN_FOLDER[$loop]} ]; then |
| 130 | git_operate ${BLX_BIN_FOLDER[loop]} log --pretty=oneline -1 |
| 131 | git_msg=${GIT_OPERATE_INFO} |
| 132 | IFS=' ' read -ra DATA <<< "$git_msg" |
| 133 | CUR_REV[$loop]=${DATA[2]} |
| 134 | echo -n "revL:${CUR_REV[$loop]} " |
| 135 | echo "@ ${BLX_BIN_FOLDER[$loop]}" |
| 136 | fi |
| 137 | done |
| 138 | fi |
xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | function git_operate() { |
| 142 | # $1: path, $2: other parameters |
| 143 | GIT_OPERATE_INFO=`git --git-dir $1/.git --work-tree=$1 ${@:2}` |
| 144 | dbg "${GIT_OPERATE_INFO}" |
| 145 | } |
| 146 | |
| 147 | function git_operate2() { |
| 148 | # use -C. for pull use. don't know why [git_operate pull] doesn't work, server git update? |
| 149 | # $1: path, $2: other parameters |
| 150 | GIT_OPERATE_INFO="`git -C \"$1\" ${@:2}`" |
| 151 | #echo "${GIT_OPERATE_INFO}" |
| 152 | } |
| 153 | |
| 154 | function get_blx_bin() { |
| 155 | # $1: current blx index |
| 156 | index=$1 |
| 157 | git_operate ${BLX_BIN_FOLDER[index]} log --pretty=oneline |
| 158 | |
| 159 | git_msg=${GIT_OPERATE_INFO} |
| 160 | BLX_READY[${index}]="false" |
| 161 | mkdir -p ${FIP_BUILD_FOLDER} |
| 162 | |
| 163 | # get version log line by line, compare with target version |
| 164 | line_num=0 |
| 165 | while read line; |
| 166 | do |
| 167 | IFS=' ' read -ra DATA <<< "$line" |
| 168 | # v1-fix support short-id |
xiaobo gu | de8a46a | 2018-03-05 21:41:54 +0800 | [diff] [blame] | 169 | dbg "${CUR_REV[$index]:0:7} - ${DATA[2]:0:7}" |
xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 170 | if [ "${CUR_REV[$index]:0:7}" == "${DATA[2]:0:7}" ]; then |
| 171 | BLX_READY[${index}]="true" |
| 172 | dbg "blxbin:${DATA[0]} blxsrc: ${DATA[2]}" |
| 173 | dbg "blxbin:${DATA[0]} blxsrc-s:${DATA[2]:0:7}" |
| 174 | # reset to history version |
| 175 | #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard |
| 176 | git_operate2 ${BLX_BIN_FOLDER[index]} reset ${DATA[0]} --hard |
| 177 | # copy binary file |
| 178 | if [ "bl32" == "${BLX_NAME[$index]}" ]; then |
| 179 | # bl32 is optional |
| 180 | if [ "y" == "${CONFIG_NEED_BL32}" ]; then |
| 181 | cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_BIN_NAME[index]} ${FIP_BUILD_FOLDER} -f |
| 182 | if [ "y" == "${CONFIG_FIP_IMG_SUPPORT}" ]; then |
| 183 | cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/${BLX_IMG_NAME[index]} ${FIP_BUILD_FOLDER} 2>/dev/null |
| 184 | fi |
| 185 | fi |
| 186 | else |
| 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 |
Zhongfu Luo | fd0ea3e | 2018-11-30 14:15:16 +0800 | [diff] [blame] | 191 | if [ -e ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ]; then |
| 192 | cp ${BLX_BIN_FOLDER[index]}/${CUR_SOC}/bl2.v3.bin ${FIP_BUILD_FOLDER} -f |
| 193 | fi |
xiaobo gu | e6c4686 | 2018-01-10 18:58:09 +0800 | [diff] [blame] | 194 | fi |
| 195 | # undo reset |
| 196 | if [ 0 -ne ${line_num} ]; then |
| 197 | # this is not latest version, can do reset. latest version doesn't have 'git reflog' |
| 198 | #git --git-dir ${BLX_BIN_FOLDER[index]}/.git --work-tree=${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard |
| 199 | git_operate2 ${BLX_BIN_FOLDER[index]} reset 'HEAD@{1}' --hard |
| 200 | fi |
| 201 | break |
| 202 | fi |
| 203 | line_num=$((line_num+1)) |
| 204 | done <<< "${git_msg}" |
| 205 | if [ "true" == ${BLX_READY[${index}]} ]; then |
| 206 | echo "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... done" |
| 207 | else |
| 208 | echo -n "Get ${BLX_NAME[$index]} from ${BLX_BIN_FOLDER[$index]}... failed" |
| 209 | if [ "true" == ${BLX_NEEDFUL[$index]} ]; then |
| 210 | echo "... abort" |
| 211 | exit -1 |
| 212 | else |
| 213 | echo "" |
| 214 | fi |
| 215 | fi |
| 216 | return 0; |
xiaobo gu | 8a3907e | 2019-05-22 11:46:49 +0800 | [diff] [blame] | 217 | } |