blob: f2a8a69a1f9e871112d3b55956951c34a92bd1be [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
dongqing.lie538ef82022-08-24 15:11:31 +080070 # 3, if contains uncommitted local changes, stop compile
Tao Zengff03b402020-12-09 15:01:44 +080071 # 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
wenbo.wang0d6dc302023-02-02 16:28:29 +080095 set +e
Zhongfu Luo019ee832020-11-13 15:56:33 +080096 target="$1/bl2.bin*"
Honglin Zhangb2eb33b2020-07-20 23:19:31 -040097 targetv3="$1/chip_acs.bin"
benlong.zhou0226bee2021-08-27 15:51:09 +080098 targetvd="$1/ddr_param.bin"
Honglin Zhang637c38b2020-06-28 02:16:39 -040099 else
100 /bin/bash mk $3
101 fi
xiaobo gue6c46862018-01-10 18:58:09 +0800102 if [ $? != 0 ]; then
103 cd ${MAIN_FOLDER}
104 echo "Error: Build bl2 failed... abort"
105 exit -1
106 fi
107 cd ${MAIN_FOLDER}
108 cp ${target} $2 -f
Zhongfu Luofd0ea3e2018-11-30 14:15:16 +0800109 if [ -e ${targetv3} ]; then
110 cp ${targetv3} $2 -f
111 fi
benlong.zhou0226bee2021-08-27 15:51:09 +0800112 if [ -e ${targetvd} ]; then
113 cp ${targetvd} $2 -f
114 fi
Tao Zenge60f5cd2022-10-18 19:19:00 +0800115 if [ -e ${1}/bl22/bl22.bin ]; then
116 cp ${1}/bl22/bl22.bin $2 -f
117 fi
Honglin Zhang637c38b2020-06-28 02:16:39 -0400118 echo "...done"
xiaobo gue6c46862018-01-10 18:58:09 +0800119 return
Honglin Zhang637c38b2020-06-28 02:16:39 -0400120}
121
122function build_bl2e() {
123 echo -n "Build bl2e...Please wait..."
Zhongfu Luo019ee832020-11-13 15:56:33 +0800124 local target="$1/bl2e.bin*"
Honglin Zhang637c38b2020-06-28 02:16:39 -0400125
126 # $1: src_folder, $2: bin_folder, $3: soc
127 cd $1
Bo Lv78837da2020-12-16 04:13:04 -0500128 /bin/bash mk $3
Honglin Zhang6b455ce2020-09-07 22:59:54 -0400129
Honglin Zhang637c38b2020-06-28 02:16:39 -0400130 if [ $? != 0 ]; then
131 cd ${MAIN_FOLDER}
132 echo "Error: Build bl2 failed... abort"
133 exit -1
134 fi
135 cd ${MAIN_FOLDER}
136 cp ${target} $2 -f
137 echo "...done"
138 return
139}
140
141function build_bl2x() {
142 echo -n "Build bl2...Please wait..."
143 local target="$1/bl2x.bin"
144
145 # $1: src_folder, $2: bin_folder, $3: soc
146 cd $1
Meng yuec57d862024-04-30 11:23:02 +0800147 if [ "$3" == "c3" ]; then
148 check_branch_bl2x_bl31
149 fi
Bo Lv78837da2020-12-16 04:13:04 -0500150 /bin/bash mk $3
Honglin Zhang6b455ce2020-09-07 22:59:54 -0400151
Honglin Zhang637c38b2020-06-28 02:16:39 -0400152 if [ $? != 0 ]; then
153 cd ${MAIN_FOLDER}
154 echo "Error: Build bl2x failed... abort"
155 exit -1
156 fi
157 cd ${MAIN_FOLDER}
158 cp ${target} $2 -f
159 echo "...done"
160 return
161}