]> git.wh0rd.org Git - home.git/blob - .profile.d/bfin-alias.sh
set perforce diff settings
[home.git] / .profile.d / bfin-alias.sh
1 bfin_path() {
2         (
3                 set -C
4                 rm -f /tmp/bfin-reset-PATH.$$
5                 echo "${PATH}" > /tmp/bfin-reset-PATH.$$
6         )
7         trap "rm -f /tmp/bfin-reset-PATH.$$" EXIT
8
9         eval $(
10         local p
11         local quiet=false use_ccache=true
12         [[ $1 == -q || $1 == --quiet ]] && quiet=true && shift
13         [[ $1 == -nc ]] && use_ccache=false && shift
14         if [[ -z $* ]] ; then
15                 if [[ -d /usr/local/src/blackfin/toolchains/current ]] ; then
16                         set -- $(eval echo /usr/local/src/blackfin/toolchains/current/{linux-uclibc,uclinux,elf})
17                 else
18                         for d in /opt/uClinux /opt/uClinux-svn ; do
19                                 [ -d "$d" ] && set -- $d
20                         done
21                 fi
22         fi
23         if [[ $# -eq 0 ]] ; then
24                 echo "bfin_path: unable to locate a good toolchain" 1>&2
25                 echo return 1
26                 exit 1
27         elif [[ $# -eq 1 ]] ; then
28                 p=""
29                 local pp ppp
30                 for pp in elf uclinux linux-uclibc ; do
31                         if [[ -e $1/out-${pp}/bin ]] ; then
32                                 p="out-"
33                         elif [[ -e $1/bfin-${pp}/bin ]] ; then
34                                 p="bfin-"
35                         else
36                                 continue
37                         fi
38                         ppp="${ppp},${pp}"
39                 done
40                 set -- $(eval echo $1/${p}{${ppp:1}}/bin)
41         fi
42         echo export _BFIN_PATH=\'$*\'
43         for p in "$@" ; do
44                 p=$(readlink -f ${p})
45                 pushd ${p} > /dev/null || return 1
46                 local ccache=$(type -P ccache)
47                 ${use_ccache} || ccache=""
48                 if [[ -n ${ccache} ]] && [[ ! -d ccache ]] ; then
49                         if ! mkdir -p ccache >& /dev/null ; then
50                                 (
51                                 echo ""
52                                 echo "FAIL: ccache creation with $p; please do:"
53                                 echo " sudo mkdir '${p}/ccache'"
54                                 echo " sudo chown ${USER}:users '${p}/ccache'"
55                                 ) 1>&2
56                         fi
57                 fi
58                 if [[ -n ${ccache} ]] && [[ -d ccache ]] ; then
59                         if [[ ! -d ccache/scripts ]] ; then
60                                 mkdir -p ccache/{output,scripts,symlinks}
61                                 cd ccache
62                                 local x xx
63
64                                 cat <<-EOF > scripts/.wrapper
65                                         #!/bin/bash
66                                         x=\${0##*/}
67                                         p=\${0%/*}
68                                         p=\${p%/ccache/scripts}
69                                         export CCACHE_DIR=\${p}/ccache/output
70                                         export PATH=\${p}:\${PATH}
71                                         exec \${p}/ccache/symlinks/\${x} "\$@"
72                                 EOF
73                                 chmod a+rx scripts/.wrapper
74
75                                 x=$(find .. -maxdepth 1 -name '*-gcc' -printf '%P')
76                                 xx=${x%-gcc}-ccache
77                                 cat <<-EOF > scripts/${xx}
78                                         #!/bin/bash
79                                         p=\${0%/*}
80                                         p=\${p%/ccache/scripts}
81                                         export CCACHE_DIR=\${p}/ccache/output
82                                         export PATH=\${p}:\${PATH}
83                                         exec ccache "\$@"
84                                 EOF
85                                 chmod a+rx scripts/${xx}
86
87                                 for x in gcc c++ g++ ; do
88                                         for xx in $(find .. -maxdepth 1 '(' -name "*-${x}" -o -name "*-${x}-*" ')' -printf '%P ') ; do
89                                                 ln scripts/.wrapper scripts/${xx}
90                                                 ln -fs ${ccache} symlinks/${xx}
91                                         done
92                                 done
93                         fi
94                         echo export UCLINUX_USE_CCACHE=no # we handle it ourself
95                         ${quiet} || echo "Adding ${p} (w/ccache)" 1>&2
96                         export PATH=${PATH}:${p}/ccache/scripts:${p}
97                         echo export PATH=\"${PATH}\"
98                 else
99                         ${quiet} || echo "Adding ${p} to PATH" 1>&2
100                         export PATH=${PATH}:${p}
101                         echo export PATH=\"${PATH}\"
102                 fi
103                 popd > /dev/null
104         done
105         )
106         unset -f bfin_path
107
108         local g
109         for g in bfin-{{linux-uclibc,uclinux,elf}-gdb{,tui},gdbproxy,jtag} ; do
110                 type -P ${g} >& /dev/null && alias ${g}="${g} --quiet"
111                 type -P ${g} >& /dev/null && alias ${g}="${g} --quiet"
112         done
113
114         bfin-reset() {
115                 export PATH=$(</tmp/bfin-reset-PATH.$$)
116                 rm -f /tmp/bfin-reset-PATH.$$
117                 local f
118                 for f in /usr/local/src/blackfin/git/toolchain/distribution/snapshots/bfin-alias ~/.profile.d/bfin-alias.sh ; do
119                         [[ -e ${f} ]] && source "${f}"
120                 done
121                 local g
122                 for g in $(alias 2>&1 | sed -n '/^alias bfin-/{s:^alias ::;s:=.*::;p}') ; do
123                         unalias ${g}
124                 done
125                 for g in $(declare 2>&1 | awk '$0 ~ /^bfin-/ { print $1 }') ; do
126                         unset -f ${g}
127                 done
128         }
129
130         bfin-set-gcc-ver() {
131                 local ver=$1
132                 if [[ -z ${ver} || -n $2 ]] ; then
133                         echo "Usage: bfin-set-gcc-ver <gcc ver>"
134                         return 1
135                 fi
136
137                 local b bb
138                 for b in ${_BFIN_PATH} ; do
139                         for bb in $(echo ${b}/*-${ver}) ; do
140                                 b=${bb%-${ver}}
141                                 if [[ ! -x ${bb} ]] ; then
142                                         echo "Not found: ${bb}"
143                                         continue
144                                 fi
145                                 rm -f "${b}"
146                                 cp -a "${b}-${ver}" "${b}"
147                                 echo "${b##*/} -> ${bb##*/}"
148                         done
149                 done
150         }
151
152         bfin-cpu-reset() {
153                 bfin-jtag <<-EOF
154                 cable probe
155                 detect
156                 bfin emulation enter
157                 bfin reset
158                 bfin emulation exit
159                 quit
160                 EOF
161         }
162
163         bfin-cpu-uboot() {
164                 local init=$1 elf=$2
165                 [[ -z $elf ]] && echo "Usage: bfin-cpu-uboot <init> <elf>" && return 1
166                 killall -q bfin-gdbproxy
167                 bfin-gdbproxy -q bfin --reset &
168                 local pid=$!
169                 sleep 3s
170                 bfin-elf-gdb -q -batch \
171                         --ex "target remote localhost:2000" \
172                         --ex "load $init" \
173                         --ex c \
174                         --ex load \
175                         --ex "call memset(&_bss_start, 0, &_bss_end - &_bss_start)" \
176                         --ex c \
177                         "$elf"
178                 kill ${pid}
179         }
180 }
181
182 switch_svn() {
183         local localserv=$(</usr/local/src/blackfin/.svn.local)
184         local remotserv="svn+ssh://${USER}@firewall-sources.blackfin.uclinux.org"
185         [[ -z ${localserv} ]] && return 1
186
187         normalize_svn_trail() {
188                 local var=$1
189                 local val=${!var}
190                 while [[ ${val} == */svn ]] || [[ ${val} == */ ]] ; do
191                         val=${val%/svn}
192                         val=${val%/}
193                 done
194                 eval ${var}="${val}"
195         }
196         normalize_svn_lead() {
197                 local var=$1
198                 local val=${!var}
199                 while [[ ${val} == svn/* ]] || [[ ${val} == /* ]] ; do
200                         val=${val#svn/}
201                         val=${val#/}
202                 done
203                 eval ${var}="${val}"
204         }
205
206         normalize_svn_trail localserv
207         normalize_svn_trail remotserv
208
209         local newurl url=$(svn info | grep ^URL:) oldurl
210         [[ -z ${url} ]] && return 1
211         url=${url#URL: }
212         oldurl=${url}
213         case ${url} in
214                 ${remotserv}*)
215                         url=${url#${remotserv}}
216                         normalize_svn_lead url
217                         newurl=${localserv}/svn/${url}
218                         ;;
219                 ${localserv}*)
220                         url=${url#${localserv}}
221                         normalize_svn_lead url
222                         newurl=${remotserv}/svn/${url}
223                         ;;
224                 *)
225                         echo "Unknown url: ${url}; switching to local"
226                         remotserv=${url##*//}
227                         remotserv=${remotserv#*/}
228                         newurl="${localserv}/svn/${remotserv##svn/}"
229                         ;;
230         esac
231         (set -x; svn switch --relocate ${oldurl} ${newurl} "$@")
232
233         unset normalize_svn_trail
234         unset normalize_svn_lead
235 }