blob: 16db4d7f049e1c32d8919c30ab580aaec3099ac3 [file] [log] [blame]
xiaobo gue6c46862018-01-10 18:58:09 +08001#!/bin/bash
2
Tao Zengff03b402020-12-09 15:01:44 +08003function get_branch() {
4 local oldifs="$IFS"
5 local find_base='0'
6 local base_branch=""
7 local tmp=""
8 IFS=$'\n'
9
10 tmp=`git branch`
11 # Eg: * (HEAD detached at firmware/projects/sc2)
12 if [[ "${tmp}" =~ "HEAD detached " ]]; then
13 base_branch=${tmp%)*}
14 base_branch=${base_branch##* }
15 CURRENT_BL2_BRANCH=${base_branch}
16 export CURRENT_BL2_BRANCH
17 return
18 fi
19
20 # No valid information from 'git branch' command
21 for line1 in `git show-branch --current --more=5`; do
22 logmsg=${line1#* }
23 for line2 in `git branch -l -v -a`; do
24 tmp=${line2# }
25 # Eg: * (HEAD detached from 65a3a6e)
26 if [[ "${tmp}" =~ "HEAD detached from" ]]; then
27 continue
28 fi
29 # Eg: remotes/firmware/master e1d4a6f Inital commit
30 if [[ "${tmp}" =~ "${logmsg}" ]]; then
31 base_branch=${tmp#* }
32 base_branch=${base_branch%% *}
33 find_base=1
34 break
35 fi
36 done
37 if [ ${find_base} == 1 ]; then
38 break
39 fi
40 done
41 IFS="$oldifs"
42 CURRENT_BL2_BRANCH=${base_branch}
43 export CURRENT_BL2_BRANCH
44 return
45}
46
47function check_branch() {
48 local dest_branch="projects/$1"
49 local str=`git branch --remote | grep ${dest_branch}`
50
51 if [ "" != "${BL2_BRANCH_ARG}" ]; then
52 echo ==== BL2 BRANCH ${BL2_BRANCH_ARG} SPECIFIED ====
53 dest_branch="projects/${BL2_BRANCH_ARG}"
54 fi
55 # 1, check if existed amlogic git branch name format
56 if [ "${str}" == "" ]; then
57 echo "can't find ${dest_branch}"
58 else
59 local cur_branch=''
60 local diff=`git diff`
61
62 # 2, check current branch is based on target soc?
63 get_branch
64 echo ==== current BL2 branch:${CURRENT_BL2_BRANCH} ====
65 if [[ "${CURRENT_BL2_BRANCH}" == *"${dest_branch}" ]]; then
66 echo ==== NO NEED TO SWITCH BRANCH ====
67 return
68 fi
69
70 # 3, if contains uncommited local changes, stop compile
71 # before branch switch, user must save their local
72 # change.
73 if [ "${diff}" == "" ]; then
74 echo ==== switch branch to ${dest_branch} ====
75 git checkout "remotes/firmware/$dest_branch"
76 else
77 echo ==== bl2/core/ code is not clean!!! ====
78 echo ==== Please save your change first! ====
79 exit -1
80 fi
81 fi
82}
83
xiaobo gue6c46862018-01-10 18:58:09 +080084function build_bl2() {
85 echo -n "Build bl2...Please wait..."
xiaobo gu3ce64072018-03-06 17:20:44 +080086 local target="$1/bl2.bin"
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +080087 local targetv3="$1/bl2.v3.bin"
xiaobo gue6c46862018-01-10 18:58:09 +080088 # $1: src_folder, $2: bin_folder, $3: soc
Bo Lv78837da2020-12-16 04:13:04 -050089
xiaobo gue6c46862018-01-10 18:58:09 +080090 cd $1
Zhongfu Luo019ee832020-11-13 15:56:33 +080091 if [ "$ADVANCED_BOOTLOADER" == "1" ]; then
Tao Zengff03b402020-12-09 15:01:44 +080092 check_branch $3
Zhongfu Luo019ee832020-11-13 15:56:33 +080093 /bin/bash mk $3 --ddrtype ${CONFIG_DDRFW_TYPE} --dsto
94 /bin/bash mk $3 --ddrtype ${CONFIG_DDRFW_TYPE} --dusb
95 target="$1/bl2.bin*"
Honglin Zhangb2eb33b2020-07-20 23:19:31 -040096 targetv3="$1/chip_acs.bin"
Honglin Zhang637c38b2020-06-28 02:16:39 -040097 else
98 /bin/bash mk $3
99 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800100 if [ $? != 0 ]; then
101 cd ${MAIN_FOLDER}
102 echo "Error: Build bl2 failed... abort"
103 exit -1
104 fi
105 cd ${MAIN_FOLDER}
106 cp ${target} $2 -f
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800107 if [ -e ${targetv3} ]; then
108 cp ${targetv3} $2 -f
109 fi
Honglin Zhang637c38b2020-06-28 02:16:39 -0400110 echo "...done"
xiaobo gue6c46862018-01-10 18:58:09 +0800111 return
Honglin Zhang637c38b2020-06-28 02:16:39 -0400112}
113
114function build_bl2e() {
115 echo -n "Build bl2e...Please wait..."
Zhongfu Luo019ee832020-11-13 15:56:33 +0800116 local target="$1/bl2e.bin*"
Honglin Zhang637c38b2020-06-28 02:16:39 -0400117
118 # $1: src_folder, $2: bin_folder, $3: soc
119 cd $1
Bo Lv78837da2020-12-16 04:13:04 -0500120 /bin/bash mk $3
Honglin Zhang6b455ce2020-09-07 22:59:54 -0400121
Honglin Zhang637c38b2020-06-28 02:16:39 -0400122 if [ $? != 0 ]; then
123 cd ${MAIN_FOLDER}
124 echo "Error: Build bl2 failed... abort"
125 exit -1
126 fi
127 cd ${MAIN_FOLDER}
128 cp ${target} $2 -f
129 echo "...done"
130 return
131}
132
133function build_bl2x() {
134 echo -n "Build bl2...Please wait..."
135 local target="$1/bl2x.bin"
136
137 # $1: src_folder, $2: bin_folder, $3: soc
138 cd $1
Bo Lv78837da2020-12-16 04:13:04 -0500139 /bin/bash mk $3
Honglin Zhang6b455ce2020-09-07 22:59:54 -0400140
Honglin Zhang637c38b2020-06-28 02:16:39 -0400141 if [ $? != 0 ]; then
142 cd ${MAIN_FOLDER}
143 echo "Error: Build bl2x failed... abort"
144 exit -1
145 fi
146 cd ${MAIN_FOLDER}
147 cp ${target} $2 -f
148 echo "...done"
149 return
150}