build : add iw to build
[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
334 function build_iw()
336         cd_repo iw
337         [ -z $NO_CLEAN ] && make clean
338         [ -z $NO_CLEAN ] && assert_no_error
339         CC=${CROSS_COMPILE}gcc LIBS+=" -lpthread -lm" make V=1
340         assert_no_error
341         DESTDIR=`path filesystem` make install
342         assert_no_error
343         cd_back
345 function build_libnl()
347         cd_repo libnl
348         [ -z $NO_CONFIG ] && ./autogen.sh
349         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
350         ([ -z $NO_CONFIG ] || [ -z $NO_CLEAN ]) && make clean
351         [ -z $NO_CLEAN ] && assert_no_error
352         make
353         assert_no_error
354         make install
355         assert_no_error
356         cd_back
359 function build_wpa_supplicant()
361         cd `repo_path hostap`/wpa_supplicant
362         [ -z $NO_CONFIG ] && cp android.config .config
363         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
364         assert_no_error
365         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
366         assert_no_error
367         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
368         assert_no_error
369         cd_back    
370     cp `repo_path scripts_download`/conf/*_supplicant.conf  `path filesystem`/etc/
373 function build_hostapd()
374 {              
375     cd `repo_path hostap`/hostapd
376         [ -z $NO_CONFIG ] && cp android.config .config
377         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
378         assert_no_error
379         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
380         assert_no_error
381         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
382         assert_no_error
383         cd_back
384     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
387 function build_crda()
388 {       
389         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
390         cp `repo_path wireless_regdb`/linville.key.pub.pem `path filesystem`/etc/wireless-regdb/pubkeys/
391     cd_repo crda
392         
393         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
394         [ -z $NO_CLEAN ] && assert_no_error
395         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
396         assert_no_error
397         DESTDIR=`path filesystem` make install
398         assert_no_error
399         cd_back
402 function build_calibrator()
404         cd_repo ti_utils
405         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
406         [ -z $NO_CLEAN ] && assert_no_error
407         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
408         assert_no_error
409         NFSROOT=`path filesystem` make install
410         #assert_no_error
411         cd_back
414 function build_wlconf()
416         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
417         cd `repo_path ti_utils`/wlconf
418         if [ -z $NO_CLEAN ]; then
419                 NFSROOT=`path filesystem` make clean
420                 assert_no_error
421                 for file_to_copy in $files_to_copy; do
422                         rm -f `path filesstem`/usr/sbin/wlconf/$file_to_copy
423                 done
424                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
425         fi
426         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
427         assert_no_error
429         # install
430         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
431         chmod 755 `path filesystem`/usr/sbin/wlconf
432         for file_to_copy in $files_to_copy; do
433                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
434                 echo "echoying files $file_to_copy"
435         done
436         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
437         cd_back
440 function build_fw_download()
442         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
446 function build_scripts_download()
448         cd_repo scripts_download
449         echo "Copying scripts"
450         scripts_download_path=`repo_path scripts_download`
451         for script_dir in `ls $scripts_download_path`
452         do
453                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
454                 cp -rf `repo_path scripts_download`/${script_dir}/* `path filesystem`/usr/share/wl18xx
455         done
456         cd_back
459 function clean_kernel()
461         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
462         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
463         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
466 function clean_outputs()
468     if [[ "$ROOTFS" == "DEFAULT" ]]
469     then
470         echo "Cleaning outputs"
471         rm -rf `path filesystem`/*
472         rm -f `path outputs`/${tar_filesystem[0]}
473         rm -f `path outputs`/uImage
474    fi
477 function build_outputs()
479         if [[ "$ROOTFS" == "DEFAULT" ]]
480     then  
481         echo "Building outputs"    
482         cd_path filesystem
483         tar cpjf `path outputs`/${tar_filesystem[0]} .
484         cd_back
485                 
486         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
487         then
488             cp `path tftp`/uImage `path outputs`/uImage
489         else
490             if [ -z $NO_DTB ]
491             then
492                 cp `path tftp`/zImage `path outputs`/zImage
493                 cp `path tftp`/am335x-evm.dtb `path outputs`/am335x-evm.dtb
494             else
495                 cp `path tftp`/uImage `path outputs`/uImage
496             fi
497         fi              
498     fi
501 function install_outputs()
503     echo "Installing outputs"
504         tftp_path=${setup[2]}
505         sitara_left_path=${setup[5]}
506         sitara_right_path=${setup[8]}
508         cp `path outputs`/uImage ${tftp_path}
509         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
510         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
512         cd $sitara_left_path
513         tar xjf ${tar_filesystem[0]}
514         cd_back
516         cd $sitara_right_path
517         tar xjf ${tar_filesystem[0]}
518         cd_back
521 function set_files_to_verify()
523         files_to_verify=(
524         # skeleton path
525         # source path
526         # pattern in output of file
528         `path filesystem`/usr/local/sbin/wpa_supplicant
529         `repo_path hostap`/wpa_supplicant/wpa_supplicant
530         "ELF 32-bit LSB executable, ARM"
532         `path filesystem`/usr/local/bin/hostapd
533         `repo_path hostap`/hostapd/hostapd
534         "ELF 32-bit LSB executable, ARM"
536         `path filesystem`/sbin/crda
537         `repo_path crda`/crda
538         "ELF 32-bit LSB executable, ARM"
540         `path filesystem`/usr/lib/crda/regulatory.bin
541         `repo_path wireless_regdb`/regulatory.bin
542         "CRDA wireless regulatory database file"
544         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
545         `repo_path fw_download`/wl18xx-fw-4.bin
546         "data"
548         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
549         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
550         "ELF 32-bit LSB relocatable, ARM"
552         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
553         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
554         "ELF 32-bit LSB relocatable, ARM"
556         #`path filesystem`/usr/bin/calibrator
557         #`repo_path ti_utils`/calibrator
558         #"ELF 32-bit LSB executable, ARM"
560         `path filesystem`/usr/sbin/wlconf/wlconf
561         `repo_path ti_utils`/wlconf/wlconf
562         "ELF 32-bit LSB executable, ARM"
563         )
566 function get_tag()
568        i="0"
569        while [ $i -lt ${#repositories[@]} ]; do
570                name=${repositories[$i]}
571                url=${repositories[$i + 1]}
572         branch=${repositories[$i + 2]}
573         checkout_type="branch"
574         cd_repo $name
575         if [[ "$url" == *git.ti.com* ]]
576         then
577                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
578                 git describe
579         fi
580                cd_back
581                i=$[$i + 3]
582        done
587 function admin_tag()
589         i="0"    
590         while [ $i -lt ${#repositories[@]} ]; do
591                 name=${repositories[$i]}
592                 url=${repositories[$i + 1]}
593         branch=${repositories[$i + 2]}   
594         checkout_type="branch"              
595         cd_repo $name    
596         if [[ "$url" == *git.ti.com* ]]
597         then                                   
598                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
599                 git show --summary        
600                 read -p "Do you want to tag this commit ?" yn
601                 case $yn in
602                     [Yy]* )  git tag -a $1 -m "$1" ;
603                              git push --tags ;;
604                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
605                     
606                     * ) echo "Please answer yes or no.";;
607                 esac
608            
609         fi        
610                 cd_back
611                 i=$[$i + 3]
612         done
616 function verify_skeleton()
618         echo "Verifying filesystem skeleton..."
620         set_files_to_verify
622         i="0"
623         while [ $i -lt ${#files_to_verify[@]} ]; do
624                 skeleton_path=${files_to_verify[i]}
625                 source_path=${files_to_verify[i + 1]}
626                 file_pattern=${files_to_verify[i + 2]}
627                 file $skeleton_path | grep "${file_pattern}" >/dev/null
628         if [ $? -eq 1 ]; then
629         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
630         #exit
631         fi
633                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
634                 md5_source=$(md5sum $source_path     | awk '{print $1}')
635                 if [ $md5_skeleton != $md5_source ]; then
636                         echo "ERROR: file mismatch"
637                         echo $skeleton_path
638                         exit 1
639                 fi
640                 i=$[$i + 3]
641         done
643         which regdbdump > /dev/null
644         if [ $? -eq 0 ]; then
645                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
646                 assert_no_error
647         fi
650 function setup_workspace()
652         setup_directories       
653         setup_repositories
654         setup_branches
655     #Download toolchain only if it was not set
656     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
660 function build_all()
662     if [ -z $NO_EXTERNAL ] 
663     then        
664         [ $DEFAULT_KERNEL ] && build_uimage
665         build_openssl
666         build_libnl
667         build_crda
668     fi
669     
670     if [ -z $NO_TI ] 
671     then
672         build_modules
673         build_iw
674         build_wpa_supplicant
675         build_hostapd   
676         build_calibrator
677         build_wlconf
678         build_fw_download
679         build_scripts_download
680     fi
681     
682     [ -z $NO_VERIFY ] && verify_skeleton
685 function setup_and_build()
687     setup_workspace
688     build_all
691 function main()
693         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
694     check_for_build_updates
695     setup_environment
696     setup_directories
697     read_kernel_version
698     
699         case "$1" in
700                 'update')                
701         print_highlight " setting up workspace and building all "       
702                 if [  -n "$2" ]
703         then
704             print_highlight "Using tag $2 " 
705             USE_TAG=$2
706         else
707             print_highlight "Updating all to head (this will revert local changes)" 
708             RESET=1    
709         fi
710         clean_kernel
711         clean_outputs        
712         setup_workspace
713         read_kernel_version #####read kernel version again after update#####
714         build_all
715                 ;;
716         
717         'init')                
718         print_highlight " initializing workspace (w/o build) "       
719                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
720         NO_BUILD=1 
721         setup_workspace
722         read_kernel_version #####read kernel version again after init#####
723                 ;;
724               
725         'clean')        
726         print_highlight " cleaning & building all "       
727         clean_outputs
728         setup_directories
729         build_all        
730                 ;;
732                 'rebuild')
733         print_highlight " building all (w/o clean) "       
734                 NO_CLEAN=1 build_all
735                 ;;
736         
737                 'openlink')
738         print_highlight " building all (w/o clean) "       
739                 NO_EXTERNAL=1 setup_and_build
740                 ;;
741         #################### Building single components #############################
742                 'kernel')
743                 print_highlight " building only Kernel "
744                 clean_kernel
745                 build_uimage
746                 ;;
747                 
748                 'kernel_modules')
749         print_highlight " building only Driver modules "
750                 build_uimage
751                 build_modules
752                 ;;
753                 'modules')
754         print_highlight " building only Driver modules "
755                 build_modules
756                 ;;
758                 'wpa_supplicant')
759         print_highlight " building only wpa_supplicant "
760                 build_wpa_supplicant      
761                 ;;
763                 'hostapd')
764         print_highlight " building only hostapd "
765                 build_hostapd
766                 ;;
768                 'crda')
769         print_highlight " building only CRDA "
770                 build_crda
771                 ;;
772         
773                 'libnl')
774                 print_highlight " building only libnl"
775                 build_libnl
776                 ;;
778                 'iw')
779                 print_highlight " building only iw"
780                 build_iw
781                 ;;
783                 'openssl')
784                 print_highlight " building only openssl"
785                 build_openssl
786                 ;;
788         'scripts')
789         print_highlight " Copying scripts "
790                 build_scripts_download
791                 ;;
792                 
793         'utils')
794         print_highlight " building only ti-utils "
795         build_calibrator
796         build_wlconf            
797                 ;;        
798         ############################################################
799         'get_tag')
800         get_tag
801         exit
802         ;;
803                 
804         'admin_tag')        
805                 admin_tag $2
806                 ;;
807         
808         *)
809         print_highlight " building all (No clean & no source code update) "  
810                 #clean_outputs
811         NO_CLEAN=1 build_all
812                 ;;
813         esac
814         
815         [[ -z $NO_BUILD ]] && build_outputs
816         [[ -n $INSTALL_NFS ]] && install_outputs
818 main $@