blob: 357b0a6b4ff7f0198fae9702e788220e0d0810a1 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/bash
2
3# script to setup work enviroment for linux developers on open WRT
4#Usage:
5# cd to <open wrt root>
6# source ./scripts/env_tools/env_setup.bash
7#
8# this script will setup git autocomplete. make sure phabricator client is in the PATH
9# and setup PS1 to show GIT status.
10
11function echo_blue()
12{
13 echo -e '\033[1;34m'"$@"'\033[0m'
14}
15
16function echo_red()
17{
18 echo -e '\033[1;31m'"$@"'\033[0m'
19}
20
21function echo_purple()
22{
23 echo -e '\033[1;35m'"$@"'\033[0m'
24}
25
26export OWRT_ROOT=`pwd -P`
27
28function git_set_openwrt_alias()
29{
30 alias r='cd ${OWRT_ROOT}'
31 alias l='cd ${OWRT_ROOT}/marvell/linux'
32 alias t='cd ${OWRT_ROOT}/marvell/lte-telephony'
33 alias w='cd ${OWRT_ROOT}/marvell/linux/drivers/marvell/sd8897'
34 alias f='cd ${OWRT_ROOT}/marvell/fastpath'
35 alias i='cd ${OWRT_ROOT}/marvell/ims'
36 alias s='cd ${OWRT_ROOT}/marvell/services'
37 alias u='cd ${OWRT_ROOT}/marvell/uboot'
38 alias obm='cd ${OWRT_ROOT}/marvell/obm'
39 alias out='cd ${OWRT_ROOT}/bin/'
40
41 # scripts aliases
42 alias mgit='${OWRT_ROOT}/mgit.sh'
43 alias sa_lindent='${OWRT_ROOT}/scripts/env_tools/sa_lindent.sh'
44
45}
46
47function set_openwrt_git()
48{
49 ENV_TOOLS_DIR=$OWRT_ROOT/scripts/env_tools
50
51 echo_blue "Environment setup script for NZ2/3 open wrt project"
52
53 echo "setting PS1 with Git info"
54 source ${ENV_TOOLS_DIR}/git_prompt.bash
55 setps1
56 echo "adding git auto compleate to shell"
57 source ${ENV_TOOLS_DIR}/git_completion.bash
58
59 # make sure /usr/local/bin/ to your PATH environment variable
60 if ( ! (echo $PATH | grep -c -q ":/usr/local/bin") ); then
61 export PATH=$PATH:/usr/local/bin
62 fi
63
64 echo_blue "Done !"
65}
66
67function set_p305_git()
68{
69 #clean previous device setup
70 if [ -n "${DEVICE+set}" ]; then
71 unset DEVICE
72 fi
73
74 echo_blue "Device setup for p305"
75 # insert saar specific configuration here
76 export DEVICE=pxa1826p305
77 export BOARD=pxa1826p305
78 cd ${OWRT_ROOT} && make defconfig_${DEVICE} && cd -
79 echo_blue "Done !"
80}
81
82function set_spinor_git()
83{
84 #clean previous device setup
85 if [ -n "${DEVICE+set}" ]; then
86 unset DEVICE
87 fi
88
89 echo_blue "Device setup for spinor"
90 # insert spinor specific configuration here
91 export DEVICE=pxa1826spinor
92 export BOARD=pxa1826
93 cd ${OWRT_ROOT} && make defconfig_${DEVICE} && cd -
94 echo_blue "Done !"
95}
96
97function set_pcie_git()
98{
99 #clean previous device setup
100 if [ -n "${DEVICE+set}" ]; then
101 unset DEVICE
102 fi
103
104 echo_blue "Device setup for pxa1826pcie"
105 # insert pcie specific configuration here
106 export DEVICE=pxa1826pcie
107 export BOARD=pxa1826pcie
108 cd ${OWRT_ROOT} && make defconfig_${DEVICE} && cd -
109 echo_blue "Done !"
110}
111
112function set_dkb_git()
113{
114 #clean previous device setup
115 if [ -n "${DEVICE+set}" ]; then
116 unset DEVICE
117 fi
118
119 echo_blue "Device setup for pxa1826DKB"
120 # insert DKB specific configuration here
121 export DEVICE=pxa1826
122 export BOARD=pxa1826
123 cd ${OWRT_ROOT} && make defconfig_${DEVICE} && cd -
124 echo_blue "Done !"
125}
126
127function mk()
128{
129 BIN_DIR=$OWRT_ROOT/bin
130 DEFAULT='-j4 V=s'
131
132 if [ -z "${DEVICE}" ]; then
133 export DEVICE=pxa1826
134 fi
135
136 if [ -z "${BOARD}" ]; then
137 export BOARD=pxa1826
138 fi
139
140 local rc
141 if [ "$1" != "I_am_respawned" ];then
142 # respawn myself with output redirection
143 mk I_am_respawned $* 2>&1 | mrvlfilter ${OWRT_ROOT}/buildall.log
144 return
145 fi
146 shift # removing "I_am_respawned" parameter
147
148 if [ -z "$1" ] ; then # no input parameter
149 echo_blue "what would you like to build?"
150 echo " 1. build all"
151 echo " 2. build Kernel"
152 echo " 3. build Telephony"
153 echo " 4. build uboot"
154 echo " 5. build Obm"
155 echo " 6. Clean previous builds"
156 echo " 7. build clean - Clean previous builds and build all"
157 echo "=========================="
158 echo "for debug mode add the flag: -j1"
159 read x_ANSWER_ALL; ANSWER_ALL=( $x_ANSWER_ALL );
160 ANSWER=${ANSWER_ALL[0]}
161 for ((i=1; i<${#ANSWER_ALL[@]}; i++));do
162 VAROPTS+="${ANSWER_ALL[$i]} "
163 done
164 else
165 echo $1
166 ANSWER=$1
167 shift
168 VAROPTS="$@"
169 fi
170
171 date
172 BUILD_START_TIME=$(date)
173 BUILD_START_TIME_S=$(date +%s)
174
175 case $ANSWER in
176 1)
177 echo_blue "build NZ open WRT $OWRT_ROOT"
178 rm -rf $BIN_DIR/*
179 echo_blue "build $DEVICE device"
180 echo MRVL_START_FILTER_ACTION_START
181 cd ${OWRT_ROOT} && make package/network/services/lte-telephony/clean && make $DEFAULT $VAROPTS
182 check_build_result $?
183 echo MRVL_START_FILTER_ACTION_END
184 ;;
185 2)
186 echo MRVL_START_FILTER_ACTION_START
187 cd ${OWRT_ROOT} && make target/linux/{compile,install} IB=y $DEFAULT $VAROPTS
188 check_build_result $?
189 echo MRVL_START_FILTER_ACTION_END
190 ;;
191 3)
192 echo MRVL_START_FILTER_ACTION_START
193 cd ${OWRT_ROOT} && make package/network/services/lte-telephony/{clean,configure,compile} $DEFAULT $VAROPTS
194 [ $? -eq 0 ] && make package/install $DEFAULT $VAROPTS
195 [ $? -eq 0 ] && make target/linux/install $DEFAULT $VAROPTS
196 check_build_result $?
197 echo MRVL_START_FILTER_ACTION_END
198 ;;
199 4)
200 echo MRVL_START_FILTER_ACTION_START
201 cd ${OWRT_ROOT} && make package/boot/uboot-mmp/{configure,compile} $DEFAULT $VAROPTS
202 mv -f ${BIN_DIR}/${BOARD}/*u-boot.bin ${BIN_DIR}/${BOARD}/swd/
203 check_build_result $?
204 echo MRVL_START_FILTER_ACTION_END
205 ;;
206 5)
207 echo MRVL_START_FILTER_ACTION_START
208 cd ${OWRT_ROOT} && make package/obm-mmp/compile $DEFAULT $VAROPTS
209 mv -f ${BIN_DIR}/${BOARD}/*NonTLoader_NAND_DDR.bin ${BIN_DIR}/${BOARD}/swd/
210 check_build_result $?
211 echo MRVL_START_FILTER_ACTION_END
212 ;;
213 6)
214 echo MRVL_START_FILTER_ACTION_START
215 echo_blue "Clean previous builds"
216 cd ${OWRT_ROOT} && make distclean V=s
217 ./scripts/feeds update -a
218 ./scripts/feeds install -a
219 make defconfig_${DEVICE}
220 echo MRVL_START_FILTER_ACTION_END
221 ;;
222 7)
223 echo MRVL_START_FILTER_ACTION_START
224 echo_blue "Clean previous builds"
225 cd ${OWRT_ROOT} && make distclean V=s
226 ./scripts/feeds update -a
227 ./scripts/feeds install -a
228 make defconfig_${DEVICE}
229 echo_blue "build NZ open WRT $OWRT_ROOT"
230 make $DEFAULT $VAROPTS
231 check_build_result $?
232 echo MRVL_START_FILTER_ACTION_END
233 ;;
234 *)
235 echo_red "This option isn't defined"
236 ;;
237 esac
238}
239
240function mrvlfilter()
241{
242 rm $1 2> /dev/null || true
243 awk -v logfile=$1 '
244 BEGIN{
245 c_pur = "\033[1;35m"; c_red = "\033[1;31m";c_end = "\033[0m";start=0;
246 }
247 /MRVL_START_FILTER_ACTION_START/{wrns=0;start=1;next;};
248 /MRVL_START_FILTER_ACTION_END/{start=0;
249 printf("%s@ ==================== @ %s\n",c_red, c_end);
250 printf("%s@ WARNINGS_COUNT %d %s\n",c_red, wrns, c_end);
251 printf("%s@ ==================== @ %s\n",c_red, c_end);
252 next;};
253
254 {print $0 >> logfile;};
255 start == 0 {print $0; next;};
256 /[Ww]arning[ \t]*:/||/[Ee]rror[ \t]*:/||/ERROR[ \t]*:/||/WARNING[ \t]*:/{
257 wrns += 1;
258 printf("%s%s%s\n",c_red, $0, c_end); next;};
259 /Removing unused section/{gsub(/([^[:space:]])*(linux-x86\/toolchain\/arm-eabi)([^[:space:]])*/,"");
260 printf("%s%s%s\n",c_pur, $0, c_end); next;}
261 {print $0;};
262 '
263}
264
265function copy_to_windows()
266{
267 if [ "${SYNC_PATH}" == "" ]; then
268 export SYNC_PATH=/nfs/pt/swdev/areas/projects/gr_platdev/${USER}/owrt_out
269 fi
270 echo_blue "copy open WRT build output to ${SYNC_PATH}"
271 mkdir -p ${SYNC_PATH}
272 rsync -L --chmod=Dgo+w,Fgo+w -avq ${OWRT_ROOT}/bin/ ${SYNC_PATH}/
273}
274
275function check_build_result() {
276 local result=${1:-$?}
277 if [ $result -ne 0 ] ; then
278 echo_red "build $DEVICE device"
279 echo_red "BUILD FAILS.\n"
280 else
281 echo_purple "build $DEVICE device"
282 echo_purple "BUILD SUCCESSFUL"
283 copy_to_windows
284 fi
285 BUILD_END_TIME=$(date)
286 BUILD_END_TIME_S=$(date +%s)
287
288 DIFF=$(($BUILD_END_TIME_S - $BUILD_START_TIME_S))
289 H1=$((DIFF / 3600))
290 M1=$((DIFF / 60 % 60))
291 S1=$((DIFF % 60))
292
293 echo ""
294 echo_purple "Build Start Time: $BUILD_START_TIME"
295 echo_purple "Build End Time: $BUILD_END_TIME"
296
297 if (($H1 > 0)); then
298 printf "Build Duration: %d seconds = %02dh%02dm%02ds\n" $DIFF $H1 $M1 $S1
299 else
300 printf "Build Duration: %d seconds = %02dm%02ds\n" $DIFF $M1 $S1
301 fi
302 echo_purple "log found in ${OWRT_ROOT}/buildall.log"
303}
304
305function arc_land()
306{
307 echo_blue "arc_land"
308 branch="$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')"
309 [ "$branch" == "master" ] && echo_red on branch master, abort. && return 1
310
311 # check if master branch exists
312 git show-ref --verify --quiet refs/heads/master
313 if [ $? -eq 0 ]; then
314 echo_red In order to land, need to create master branch. Delete current master branch?
315 select yn in "Yes" "No"; do
316 case $yn in
317 Yes ) git branch -D master; break;;
318 No ) echo_red abort.; return 1;;
319 esac
320 done
321 fi
322
323 # Create a temporary master branch for arc land command
324 git branch --track master origin/master
325 [ ! $? -eq 0 ] && echo_red failed to create master branch, abort. && return 1
326
327 if [ "$branch" == "(no branch)" ]; then
328 tmp_branch=$(date +tmp_%N)
329 git checkout -b $tmp_branch
330 fi
331
332 arc land
333 result=$?
334
335 repo sync -d .
336 git branch -D master
337 [ ! -z "$tmp_branch" ] && git branch -D $tmp_branch
338
339 if [ $result -eq 0 ]; then
340 echo_blue Done.
341 else
342 echo_red Failed.
343 fi
344
345 return $result
346}