d2fd338835a81414e2cd6422be3312b17492a7d1
[wilink8-wlan/build-utilites.git] / build_wl18xx.sh
1 export PATH__ROOT=`pwd`    
2 . configuration.sh    
3 . setup-env
4 # Pretty colors
5 GREEN="\033[01;32m"
6 YELLOW="\033[01;33m"
7 NORMAL="\033[00m"
8 BLUE="\033[34m"
9 RED="\033[31m"
10 PURPLE="\033[35m"
11 CYAN="\033[36m"
12 UNDERLINE="\033[02m"
14 function print_highlight()
15 {      
16     echo -e "   ${YELLOW}***** $1 ***** ${NORMAL} "
17 }
19 function usage ()
20 {
21     echo ""
22     echo "This script compiles one/all of the following utilities: kernel, libnl, openssl, hostapd, wpa_supplicant,wl18xx_modules,firmware,crda,calibrator"
23     echo "by calling specific utility name and action."
24     echo ""
25     echo " Usage: ./wl18xx_build.sh init         <head|TAG>  [ Update w/o build        ] "
26     echo "                          update       <head|TAG>  [ Update & build          ] "
27     echo "                          rebuild                  [ Build w/o update        ] "
28     echo "                          clean                    [ Clean, Update & build   ] "
29     echo "                              "
30     echo " Building a specific module usage "
31     echo "       ./build.sh    hostapd "
32     echo "                     wpa_supplicant "
33     echo "                     modules(driver) "
34     echo "                     firmware "
35     echo "                     scripts "
36     echo "                     calibrator "
37     echo "                     wlconf "
38     echo "                     uimage "
39     echo "                     openssl "
40     echo "                     libnl "
41     echo "                     crda "
43     exit 1
44 }
46 function assert_no_error()
47 {
48         if [ $? -ne 0 ]; then
49                 echo "****** ERROR $? $@*******"
50                 exit 1
51         fi
52         echo "****** $1 *******"
53 }
55 function repo_id()
56 {
57         i="0"
58         while [ $i -lt ${#repositories[@]} ]; do
59                 [ $1 == "${repositories[i]}" ] && echo $i
60                 i=$[$i + 3]
61         done
62 }
64 function repo_url()
65 {
66         echo "${repositories[`repo_id $1` + 1]}"
67 }
69 function repo_branch()
70 {
71         echo "${repositories[`repo_id $1` + 2]}"
72 }
74 function path()
75 {
76         i="0"
77         while [ $i -lt "${#paths[@]}" ]; do
78                 [ $1 == "${paths[i]}" ] && echo "${paths[i + 1]}"
79                 i=$[$i + 2]
80         done
81 }
83 function set_path()
84 {
85         i="0"    
86         while [ $i -lt "${#paths[@]}" ]; do
87                 [ $1 == "${paths[i]}" ] && paths[i+1]=$2    
88                 i=$[$i + 2]
89         done
90 }
92 function repo_path()
93 {
94         echo `path src`/$1
95 }
97 function cd_path()
98 {
99         cd `path $1`
102 function cd_repo()
104         cd `repo_path $1`
107 function cd_back()
109         cd - > /dev/null
112 function check_for_build_updates()
114         count=`git status -uno | grep behind | wc -l`
115         if [ $count -ne 0 ]
116         then
117                 echo ""
118                 echo "*** Please note, there is an updated build script avilalable ***"
119                 echo "*** Use 'git pull' to get the latest update. ***" 
120                 echo ""
121                 sleep 5
122         fi
125 function read_kernel_version()
127         filename=$KERNEL_PATH/Makefile
129         if [ ! -f $filename ]
130         then
131             KERNEL_VERSION=0
132             KERNEL_PATCHLEVEL=0
133             KERNEL_SUBLEVEL=0
134             echo "No Makefile was found. Kernel version was set to default." 
135         else 
136             exec 6< $filename
137             read version <&6
138             read patchlevel <&6
139             read sublevel <&6
140             exec 6<&-
142             KERNEL_VERSION=$(echo $version|sed 's/[^0-9]//g')
143             KERNEL_PATCHLEVEL=$(echo $patchlevel|sed 's/[^0-9]//g')
144             KERNEL_SUBLEVEL=$(echo $sublevel|sed 's/[^0-9]//g')
145             echo "Makefile was found. Kernel version was set to $KERNEL_VERSION.$KERNEL_PATCHLEVEL.$KERNEL_SUBLEVEL." 
146         fi
149 #----------------------------------------------------------j
150 function setup_environment()
152     if [ ! -e setup-env ]
153     then
154         echo "No setup-env"
155         exit 1
156     fi
157     
158     #if a rootfs path is set - replace the default.
159     if [[ "$ROOTFS" != "DEFAULT" ]]
160     then            
161         echo " Changing ROOTFS path to $ROOTFS"
162         set_path filesystem $ROOTFS
163         [ ! -d $ROOTFS ] && echo "Error ROOTFS: $ROOTFS dir does not exist" && exit 1
164     fi   
165     #if no toolchain path is set - download it.
166     if [[ "$TOOLCHAIN_PATH" == "DEFAULT" ]]
167     then            
168         echo " Setting TOOLCHAIN_PATH path to default"
169         export TOOLCHAIN_PATH=`path toolchain`/arm/bin
170         DEFAULT_TOOLCHAIN=1
171     fi   
173     #if no kernel path is set - download it.
174     if [[ "$KERNEL_PATH" == "DEFAULT" ]]
175     then            
176         echo " Setting KERNEL_PATH path to default"
177         export KERNEL_PATH=`repo_path kernel`
178         DEFAULT_KERNEL=1
179     else 
180         echo " Using user defined kernel"                        
181         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
182     fi  
183     
184         export PROCESSORS_NUMBER=$(egrep '^processor' /proc/cpuinfo | wc -l)
185         export PKG_CONFIG_PATH=`path filesystem`/lib/pkgconfig
186         export INSTALL_PREFIX=`path filesystem`
187         export LIBNL_PATH=`repo_path libnl`     
188         export KLIB=`path filesystem`
189         export KLIB_BUILD=${KERNEL_PATH}
190         export GIT_TREE=`repo_path driver`
191         export PATH=$TOOLCHAIN_PATH:$PATH
192     
195 function setup_filesystem_skeleton()
197         mkdir -p `path filesystem`/usr/bin
198         mkdir -p `path filesystem`/etc
199         mkdir -p `path filesystem`/usr/lib/crda
200         mkdir -p `path filesystem`/lib/firmware/ti-connectivity
201         mkdir -p `path filesystem`/usr/share/wl18xx
202         mkdir -p `path filesystem`/usr/sbin/wlconf
203         mkdir -p `path filesystem`/usr/sbin/wlconf/official_inis
204         mkdir -p `path filesystem`/etc/wireless-regdb/pubkeys
207 function setup_directories()
209         i="0"
210         while [ $i -lt ${#paths[@]} ]; do
211                 mkdir -p ${paths[i + 1]}
212                 i=$[$i + 2]
213         done
214         setup_filesystem_skeleton
218 function setup_repositories()
220         i="0"
221         while [ $i -lt ${#repositories[@]} ]; do
222                 url=${repositories[$i + 1]}
223                 name=${repositories[$i]}
224         echo -e "${NORMAL}Cloning into: ${GREEN} $name ${NORMAL}"        
225         #Skip kernel clone if it was user defined 
226                 [ "$name" != "kernel" -o "$DEFAULT_KERNEL" ] && [ ! -d `repo_path $name` ] && git clone $url `repo_path $name`
227                 i=$[$i + 3]
228         done        
231 function setup_branches()
233         i="0"    
234         while [ $i -lt ${#repositories[@]} ]; do
235                 name=${repositories[$i]}
236                 url=${repositories[$i + 1]}
237         branch=${repositories[$i + 2]}   
238         checkout_type="branch"       
239         #for all the openlink repo. we use a tag if provided.               
240         [ "$name" == "kernel" ] && [ -z "$DEFAULT_KERNEL" ] && i=$[$i + 3] && continue
241         cd_repo $name   
242         echo -e "\n${NORMAL}Checking out branch ${GREEN}$branch  ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
243                 git checkout $branch        
244         git fetch origin
245         git fetch origin --tags  
246         if [[ "$url" == *git.ti.com* ]]
247         then            
248            [[ -n $RESET ]] && echo -e "${PURPLE}Reset to latest in repo ${GREEN}$name ${NORMAL} branch  ${GREEN}$branch ${NORMAL}"  && git reset --hard origin/$branch
249            [[ -n $USE_TAG ]] && git reset --hard $USE_TAG  && echo -e "${NORMAL}Reset to tag ${GREEN}$USE_TAG   ${NORMAL}in repo ${GREEN}$name ${NORMAL} "            
250         fi        
251                 cd_back
252                 i=$[$i + 3]
253         done
256 function setup_toolchain()
258         if [ ! -f `path downloads`/arm-toolchain.tar.bz2 ]; then
259         echo "Setting toolchain"
260                 wget ${toolchain[0]} -O `path downloads`/arm-toolchain.tar.bz2
261                 tar -xjf `path downloads`/arm-toolchain.tar.bz2 -C `path toolchain`
262                 mv `path toolchain`/* `path toolchain`/arm
263         fi
266 function build_uimage()
268     cd_repo kernel
269         [ -z $NO_CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path kernel`/.config
270         [ -z $NO_CLEAN ] && make clean
271         [ -z $NO_CLEAN ] && assert_no_error
272        
273     if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
274     then
275         make -j${PROCESSORS_NUMBER} uImage
276         cp `repo_path kernel`/arch/arm/boot/uImage `path tftp`/uImage
277     else
278         if [ -z $NO_DTB ] 
279         then
280             make -j${PROCESSORS_NUMBER} uImage
281             make -j${PROCESSORS_NUMBER} am335x-evm.dtb
282             cp `repo_path kernel`/arch/arm/boot/zImage `path tftp`/zImage
283             cp `repo_path kernel`/arch/arm/boot/dts/am335x-evm.dtb `path tftp`/am335x-evm.dtb
284         else
285             LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage.am335x-evm 
286             cp `repo_path kernel`/arch/arm/boot/uImage.am335x-evm `path tftp`/uImage
287         fi
288     fi
289         assert_no_error
290         cd_back
293 function generate_compat()
295         cd_repo backports
296         python ./gentree.py --clean `repo_path driver` `path compat_wireless`
297         cd_back
300 function build_modules()
302         generate_compat
303         cd_repo compat_wireless
304         if [ -z $NO_CLEAN ]; then
305                 make clean
306         fi
307         make defconfig-wl18xx
308         make -j${PROCESSORS_NUMBER}
309         assert_no_error
310         find . -name \*.ko -exec cp {} `path debugging`/ \;
311         find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
312     
313 #       make -C ${KERNEL_PATH} M=`pwd` "INSTALL_MOD_PATH=`path filesystem`" modules_install
314         make  modules_install
315         assert_no_error
316         #chmod -R 0777 ${PATH__FILESYSTEM}/lib/modules/
317         cd_back
320 function build_openssl()
322         cd_repo openssl
323         [ -z $NO_CONFIG ] && ./Configure linux-generic32
324         [ -z $NO_CLEAN ] && make clean
325         [ -z $NO_CLEAN ] && assert_no_error
326         make
327         assert_no_error
328         make install_sw
329         assert_no_error
330         cd_back
333 function build_libnl()
335         cd_repo libnl
336         [ -z $NO_CONFIG ] && ./autogen.sh
337         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
338         ([ -z $NO_CONFIG ] || [ -z $NO_CLEAN ]) && make clean
339         [ -z $NO_CLEAN ] && assert_no_error
340         make
341         assert_no_error
342         make install
343         assert_no_error
344         cd_back
347 function build_wpa_supplicant()
349         cd `repo_path hostap`/wpa_supplicant
350         [ -z $NO_CONFIG ] && cp android.config .config
351         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
352         assert_no_error
353         CONFIG_LIBNL32=y DESTDIR=`path filesystem` CFLAGS+="-I`path filesystem`/usr/local/ssl/include -I`repo_path libnl`/include" LIBS+="-L`path filesystem`/lib -L`path filesystem`/usr/local/ssl/lib -lssl -lcrypto -lm -ldl -lpthread" LIBS_p+="-L`path filesystem`/lib -L`path filesystem`/usr/local/ssl/lib -lssl -lcrypto -lm -ldl -lpthread" make -j${PROCESSORS_NUMBER} CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld AR=${CROSS_COMPILE}ar
354         assert_no_error
355         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
356         assert_no_error
357         cd_back    
358     cp `repo_path scripts_download`/conf/*_supplicant.conf  `path filesystem`/etc/
361 function build_hostapd()
362 {              
363     cd `repo_path hostap`/hostapd
364         [ -z $NO_CONFIG ] && cp android.config .config
365         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
366         assert_no_error
367         CONFIG_LIBNL32=y DESTDIR=`path filesystem` CFLAGS+="-I`path filesystem`/usr/local/ssl/include -I`repo_path libnl`/include" LIBS+="-L`path filesystem`/lib -L`path filesystem`/usr/local/ssl/lib -lssl -lcrypto -lm -ldl -lpthread" LIBS_p+="-L`path filesystem`/lib -L`path filesystem`/usr/local/ssl/lib -lssl -lcrypto -lm -ldl -lpthread" make -j${PROCESSORS_NUMBER} CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld AR=${CROSS_COMPILE}ar
368         assert_no_error
369         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
370         assert_no_error
371         cd_back
372     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
375 function build_crda()
376 {       
377         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
378         cp `repo_path wireless_regdb`/linville.key.pub.pem `path filesystem`/etc/wireless-regdb/pubkeys/
379     cd_repo crda
380         
381         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
382         [ -z $NO_CLEAN ] && assert_no_error
383         PKG_CONFIG_LIBDIR="`path filesystem`/lib/pkgconfig" PKG_CONFIG_PATH="`path filesystem`/usr/local/ssl/lib/pkgconfig" DESTDIR=`path filesystem` CFLAGS+="-I`path filesystem`/usr/local/ssl/include -I`path filesystem`/include -L`path filesystem`/usr/local/ssl/lib -L`path filesystem`/lib" LDLIBS+=-lpthread V=1 USE_OPENSSL=1 make -j${PROCESSORS_NUMBER} all_noverify CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld AR=${CROSS_COMPILE}ar
384         assert_no_error
385         DESTDIR=`path filesystem` make install
386         assert_no_error
387         cd_back
390 function build_calibrator()
392         cd_repo ti_utils
393         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
394         [ -z $NO_CLEAN ] && assert_no_error
395         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
396         assert_no_error
397         NFSROOT=`path filesystem` make install
398         #assert_no_error
399         cd_back
402 function build_wlconf()
404         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
405         cd `repo_path ti_utils`/wlconf
406         if [ -z $NO_CLEAN ]; then
407                 NFSROOT=`path filesystem` make clean
408                 assert_no_error
409                 for file_to_copy in $files_to_copy; do
410                         rm -f `path filesstem`/usr/sbin/wlconf/$file_to_copy
411                 done
412                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
413         fi
414         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
415         assert_no_error
417         # install
418         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
419         chmod 755 `path filesystem`/usr/sbin/wlconf
420         for file_to_copy in $files_to_copy; do
421                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
422                 echo "echoying files $file_to_copy"
423         done
424         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
425         cd_back
428 function build_fw_download()
430         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
434 function build_scripts_download()
436         cd_repo scripts_download
437         echo "Copying scripts"
438         scripts_download_path=`repo_path scripts_download`
439         for script_dir in `ls $scripts_download_path`
440         do
441                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
442                 cp -rf `repo_path scripts_download`/${script_dir}/* `path filesystem`/usr/share/wl18xx
443         done
444         cd_back
447 function clean_kernel()
449         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
450         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
451         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
454 function clean_outputs()
456     if [[ "$ROOTFS" == "DEFAULT" ]]
457     then
458         echo "Cleaning outputs"
459         rm -rf `path filesystem`/*
460         rm -f `path outputs`/${tar_filesystem[0]}
461         rm -f `path outputs`/uImage
462    fi
465 function build_outputs()
467         if [[ "$ROOTFS" == "DEFAULT" ]]
468     then  
469         echo "Building outputs"    
470         cd_path filesystem
471         tar cpjf `path outputs`/${tar_filesystem[0]} .
472         cd_back
473                 
474         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
475         then
476             cp `path tftp`/uImage `path outputs`/uImage
477         else
478             if [ -z $NO_DTB ]
479             then
480                 cp `path tftp`/zImage `path outputs`/zImage
481                 cp `path tftp`/am335x-evm.dtb `path outputs`/am335x-evm.dtb
482             else
483                 cp `path tftp`/uImage `path outputs`/uImage
484             fi
485         fi              
486     fi
489 function install_outputs()
491     echo "Installing outputs"
492         tftp_path=${setup[2]}
493         sitara_left_path=${setup[5]}
494         sitara_right_path=${setup[8]}
496         cp `path outputs`/uImage ${tftp_path}
497         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
498         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
500         cd $sitara_left_path
501         tar xjf ${tar_filesystem[0]}
502         cd_back
504         cd $sitara_right_path
505         tar xjf ${tar_filesystem[0]}
506         cd_back
509 function set_files_to_verify()
511         files_to_verify=(
512         # skeleton path
513         # source path
514         # pattern in output of file
516         `path filesystem`/usr/local/sbin/wpa_supplicant
517         `repo_path hostap`/wpa_supplicant/wpa_supplicant
518         "ELF 32-bit LSB executable, ARM"
520         `path filesystem`/usr/local/bin/hostapd
521         `repo_path hostap`/hostapd/hostapd
522         "ELF 32-bit LSB executable, ARM"
524         `path filesystem`/sbin/crda
525         `repo_path crda`/crda
526         "ELF 32-bit LSB executable, ARM"
528         `path filesystem`/usr/lib/crda/regulatory.bin
529         `repo_path wireless_regdb`/regulatory.bin
530         "CRDA wireless regulatory database file"
532         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
533         `repo_path fw_download`/wl18xx-fw-4.bin
534         "data"
536         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
537         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
538         "ELF 32-bit LSB relocatable, ARM"
540         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
541         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
542         "ELF 32-bit LSB relocatable, ARM"
544         #`path filesystem`/usr/bin/calibrator
545         #`repo_path ti_utils`/calibrator
546         #"ELF 32-bit LSB executable, ARM"
548         `path filesystem`/usr/sbin/wlconf/wlconf
549         `repo_path ti_utils`/wlconf/wlconf
550         "ELF 32-bit LSB executable, ARM"
551         )
554 function get_tag()
556        i="0"
557        while [ $i -lt ${#repositories[@]} ]; do
558                name=${repositories[$i]}
559                url=${repositories[$i + 1]}
560         branch=${repositories[$i + 2]}
561         checkout_type="branch"
562         cd_repo $name
563         if [[ "$url" == *git.ti.com* ]]
564         then
565                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
566                 git describe
567         fi
568                cd_back
569                i=$[$i + 3]
570        done
575 function admin_tag()
577         i="0"    
578         while [ $i -lt ${#repositories[@]} ]; do
579                 name=${repositories[$i]}
580                 url=${repositories[$i + 1]}
581         branch=${repositories[$i + 2]}   
582         checkout_type="branch"              
583         cd_repo $name    
584         if [[ "$url" == *git.ti.com* ]]
585         then                                   
586                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
587                 git show --summary        
588                 read -p "Do you want to tag this commit ?" yn
589                 case $yn in
590                     [Yy]* )  git tag -a $1 -m "$1" ;
591                              git push --tags ;;
592                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
593                     
594                     * ) echo "Please answer yes or no.";;
595                 esac
596            
597         fi        
598                 cd_back
599                 i=$[$i + 3]
600         done
604 function verify_skeleton()
606         echo "Verifying filesystem skeleton..."
608         set_files_to_verify
610         i="0"
611         while [ $i -lt ${#files_to_verify[@]} ]; do
612                 skeleton_path=${files_to_verify[i]}
613                 source_path=${files_to_verify[i + 1]}
614                 file_pattern=${files_to_verify[i + 2]}
615                 file $skeleton_path | grep "${file_pattern}" >/dev/null
616         if [ $? -eq 1 ]; then
617         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
618         #exit
619         fi
621                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
622                 md5_source=$(md5sum $source_path     | awk '{print $1}')
623                 if [ $md5_skeleton != $md5_source ]; then
624                         echo "ERROR: file mismatch"
625                         echo $skeleton_path
626                         exit 1
627                 fi
628                 i=$[$i + 3]
629         done
631         which regdbdump > /dev/null
632         if [ $? -eq 0 ]; then
633                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
634                 assert_no_error
635         fi
638 function setup_workspace()
640         setup_directories       
641         setup_repositories
642         setup_branches
643     #Download toolchain only if it was not set
644     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
648 function build_all()
650     if [ -z $NO_EXTERNAL ] 
651     then        
652         [ $DEFAULT_KERNEL ] && build_uimage
653         build_openssl
654         build_libnl
655         build_crda
656     fi
657     
658     if [ -z $NO_TI ] 
659     then
660         build_modules
661         build_wpa_supplicant
662         build_hostapd   
663         build_calibrator
664         build_wlconf
665         build_fw_download
666         build_scripts_download
667     fi
668     
669     [ -z $NO_VERIFY ] && verify_skeleton
672 function setup_and_build()
674     setup_workspace
675     build_all
678 function main()
680         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
681     check_for_build_updates
682     setup_environment
683     setup_directories
684     read_kernel_version
685     
686         case "$1" in
687                 'update')                
688         print_highlight " setting up workspace and building all "       
689                 if [  -n "$2" ]
690         then
691             print_highlight "Using tag $2 " 
692             USE_TAG=$2
693         else
694             print_highlight "Updating all to head (this will revert local changes)" 
695             RESET=1    
696         fi
697         clean_kernel
698         clean_outputs        
699         setup_workspace
700         read_kernel_version #####read kernel version again after update#####
701         build_all
702                 ;;
703         
704         'init')                
705         print_highlight " initializing workspace (w/o build) "       
706                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
707         NO_BUILD=1 
708         setup_workspace
709         read_kernel_version #####read kernel version again after init#####
710                 ;;
711               
712         'clean')        
713         print_highlight " cleaning & building all "       
714         clean_outputs
715         setup_directories
716         build_all        
717                 ;;
719                 'rebuild')
720         print_highlight " building all (w/o clean) "       
721                 NO_CLEAN=1 build_all
722                 ;;
723         
724                 'openlink')
725         print_highlight " building all (w/o clean) "       
726                 NO_EXTERNAL=1 setup_and_build
727                 ;;
728         #################### Building single components #############################
729                 'kernel')
730                 print_highlight " building only Kernel "
731                 clean_kernel
732                 build_uimage
733                 ;;
734                 
735                 'kernel_modules')
736         print_highlight " building only Driver modules "
737                 build_uimage
738                 build_modules
739                 ;;
740                 'modules')
741         print_highlight " building only Driver modules "
742                 build_modules
743                 ;;
745                 'wpa_supplicant')
746         print_highlight " building only wpa_supplicant "
747                 build_wpa_supplicant      
748                 ;;
750                 'hostapd')
751         print_highlight " building only hostapd "
752                 build_hostapd
753                 ;;
755                 'crda')
756         print_highlight " building only CRDA "
757                 build_crda
758                 ;;
759         
760                 'libnl')
761                 print_highlight " building only libnl"
762                 build_libnl
763                 ;;
765                 'openssl')
766                 print_highlight " building only openssl"
767                 build_openssl
768                 ;;
770         'scripts')
771         print_highlight " Copying scripts "
772                 build_scripts_download
773                 ;;
774                 
775         'utils')
776         print_highlight " building only ti-utils "
777         build_calibrator
778         build_wlconf            
779                 ;;        
780         ############################################################
781         'get_tag')
782         get_tag
783         exit
784         ;;
785                 
786         'admin_tag')        
787                 admin_tag $2
788                 ;;
789         
790         *)
791         print_highlight " building all (No clean & no source code update) "  
792                 #clean_outputs
793         NO_CLEAN=1 build_all
794                 ;;
795         esac
796         
797         [[ -z $NO_BUILD ]] && build_outputs
798         [[ -n $INSTALL_NFS ]] && install_outputs
800 main $@