configuration.sh: update driver & hostap branches
[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         [ -n "$UPNP_EN" ] && echo "Enable UPNP config" && sed -i "/#CONFIG_WPS_UPNP=y/ s/# *//" .config
378         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
379         assert_no_error
380         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
381         assert_no_error
382         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
383         assert_no_error
384         cd_back
385     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
388 function build_crda()
389 {       
390         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
391         cp `repo_path wireless_regdb`/linville.key.pub.pem `path filesystem`/etc/wireless-regdb/pubkeys/
392     cd_repo crda
393         
394         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
395         [ -z $NO_CLEAN ] && assert_no_error
396         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
397         assert_no_error
398         DESTDIR=`path filesystem` make install
399         assert_no_error
400         cd_back
403 function build_calibrator()
405         cd_repo ti_utils
406         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
407         [ -z $NO_CLEAN ] && assert_no_error
408         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
409         assert_no_error
410         NFSROOT=`path filesystem` make install
411         #assert_no_error
412         cd_back
415 function build_wlconf()
417         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
418         cd `repo_path ti_utils`/wlconf
419         if [ -z $NO_CLEAN ]; then
420                 NFSROOT=`path filesystem` make clean
421                 assert_no_error
422                 for file_to_copy in $files_to_copy; do
423                         rm -f `path filesstem`/usr/sbin/wlconf/$file_to_copy
424                 done
425                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
426         fi
427         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
428         assert_no_error
430         # install
431         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
432         chmod 755 `path filesystem`/usr/sbin/wlconf
433         for file_to_copy in $files_to_copy; do
434                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
435                 echo "echoying files $file_to_copy"
436         done
437         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
438         cd_back
441 function build_fw_download()
443         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
447 function build_scripts_download()
449         cd_repo scripts_download
450         echo "Copying scripts"
451         scripts_download_path=`repo_path scripts_download`
452         for script_dir in `ls $scripts_download_path`
453         do
454                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
455                 cp -rf `repo_path scripts_download`/${script_dir}/* `path filesystem`/usr/share/wl18xx
456         done
457         cd_back
460 function clean_kernel()
462         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
463         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
464         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
467 function clean_outputs()
469     if [[ "$ROOTFS" == "DEFAULT" ]]
470     then
471         echo "Cleaning outputs"
472         rm -rf `path filesystem`/*
473         rm -f `path outputs`/${tar_filesystem[0]}
474         rm -f `path outputs`/uImage
475    fi
478 function build_outputs()
480         if [[ "$ROOTFS" == "DEFAULT" ]]
481     then  
482         echo "Building outputs"    
483         cd_path filesystem
484         tar cpjf `path outputs`/${tar_filesystem[0]} .
485         cd_back
486                 
487         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
488         then
489             cp `path tftp`/uImage `path outputs`/uImage
490         else
491             if [ -z $NO_DTB ]
492             then
493                 cp `path tftp`/zImage `path outputs`/zImage
494                 cp `path tftp`/am335x-evm.dtb `path outputs`/am335x-evm.dtb
495             else
496                 cp `path tftp`/uImage `path outputs`/uImage
497             fi
498         fi              
499     fi
502 function install_outputs()
504     echo "Installing outputs"
505         tftp_path=${setup[2]}
506         sitara_left_path=${setup[5]}
507         sitara_right_path=${setup[8]}
509         cp `path outputs`/uImage ${tftp_path}
510         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
511         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
513         cd $sitara_left_path
514         tar xjf ${tar_filesystem[0]}
515         cd_back
517         cd $sitara_right_path
518         tar xjf ${tar_filesystem[0]}
519         cd_back
522 function set_files_to_verify()
524         files_to_verify=(
525         # skeleton path
526         # source path
527         # pattern in output of file
529         `path filesystem`/usr/local/sbin/wpa_supplicant
530         `repo_path hostap`/wpa_supplicant/wpa_supplicant
531         "ELF 32-bit LSB executable, ARM"
533         `path filesystem`/usr/local/bin/hostapd
534         `repo_path hostap`/hostapd/hostapd
535         "ELF 32-bit LSB executable, ARM"
537         `path filesystem`/sbin/crda
538         `repo_path crda`/crda
539         "ELF 32-bit LSB executable, ARM"
541         `path filesystem`/usr/lib/crda/regulatory.bin
542         `repo_path wireless_regdb`/regulatory.bin
543         "CRDA wireless regulatory database file"
545         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
546         `repo_path fw_download`/wl18xx-fw-4.bin
547         "data"
549         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
550         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
551         "ELF 32-bit LSB relocatable, ARM"
553         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
554         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
555         "ELF 32-bit LSB relocatable, ARM"
557         #`path filesystem`/usr/bin/calibrator
558         #`repo_path ti_utils`/calibrator
559         #"ELF 32-bit LSB executable, ARM"
561         `path filesystem`/usr/sbin/wlconf/wlconf
562         `repo_path ti_utils`/wlconf/wlconf
563         "ELF 32-bit LSB executable, ARM"
564         )
567 function get_tag()
569        i="0"
570        while [ $i -lt ${#repositories[@]} ]; do
571                name=${repositories[$i]}
572                url=${repositories[$i + 1]}
573         branch=${repositories[$i + 2]}
574         checkout_type="branch"
575         cd_repo $name
576         if [[ "$url" == *git.ti.com* ]]
577         then
578                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
579                 git describe
580         fi
581                cd_back
582                i=$[$i + 3]
583        done
588 function admin_tag()
590         i="0"    
591         while [ $i -lt ${#repositories[@]} ]; do
592                 name=${repositories[$i]}
593                 url=${repositories[$i + 1]}
594         branch=${repositories[$i + 2]}   
595         checkout_type="branch"              
596         cd_repo $name    
597         if [[ "$url" == *git.ti.com* ]]
598         then                                   
599                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
600                 git show --summary        
601                 read -p "Do you want to tag this commit ?" yn
602                 case $yn in
603                     [Yy]* )  git tag -a $1 -m "$1" ;
604                              git push --tags ;;
605                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
606                     
607                     * ) echo "Please answer yes or no.";;
608                 esac
609            
610         fi        
611                 cd_back
612                 i=$[$i + 3]
613         done
617 function verify_skeleton()
619         echo "Verifying filesystem skeleton..."
621         set_files_to_verify
623         i="0"
624         while [ $i -lt ${#files_to_verify[@]} ]; do
625                 skeleton_path=${files_to_verify[i]}
626                 source_path=${files_to_verify[i + 1]}
627                 file_pattern=${files_to_verify[i + 2]}
628                 file $skeleton_path | grep "${file_pattern}" >/dev/null
629         if [ $? -eq 1 ]; then
630         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
631         #exit
632         fi
634                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
635                 md5_source=$(md5sum $source_path     | awk '{print $1}')
636                 if [ $md5_skeleton != $md5_source ]; then
637                         echo "ERROR: file mismatch"
638                         echo $skeleton_path
639                         exit 1
640                 fi
641                 i=$[$i + 3]
642         done
644         which regdbdump > /dev/null
645         if [ $? -eq 0 ]; then
646                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
647                 assert_no_error
648         fi
651 function setup_workspace()
653         setup_directories       
654         setup_repositories
655         setup_branches
656     #Download toolchain only if it was not set
657     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
661 function build_all()
663     if [ -z $NO_EXTERNAL ] 
664     then        
665         [ $DEFAULT_KERNEL ] && build_uimage
666         build_openssl
667         build_libnl
668         build_crda
669     fi
670     
671     if [ -z $NO_TI ] 
672     then
673         build_modules
674         build_iw
675         build_wpa_supplicant
676         build_hostapd   
677         build_calibrator
678         build_wlconf
679         build_fw_download
680         build_scripts_download
681     fi
682     
683     [ -z $NO_VERIFY ] && verify_skeleton
686 function setup_and_build()
688     setup_workspace
689     build_all
692 function main()
694         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
695     check_for_build_updates
696     setup_environment
697     setup_directories
698     read_kernel_version
699     
700         case "$1" in
701                 'update')                
702         print_highlight " setting up workspace and building all "       
703                 if [  -n "$2" ]
704         then
705             print_highlight "Using tag $2 " 
706             USE_TAG=$2
707         else
708             print_highlight "Updating all to head (this will revert local changes)" 
709             RESET=1    
710         fi
711         clean_kernel
712         clean_outputs        
713         setup_workspace
714         read_kernel_version #####read kernel version again after update#####
715         build_all
716                 ;;
717         
718         'init')                
719         print_highlight " initializing workspace (w/o build) "       
720                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
721         NO_BUILD=1 
722         setup_workspace
723         read_kernel_version #####read kernel version again after init#####
724                 ;;
725               
726         'clean')        
727         print_highlight " cleaning & building all "       
728         clean_outputs
729         setup_directories
730         build_all        
731                 ;;
733                 'rebuild')
734         print_highlight " building all (w/o clean) "       
735                 NO_CLEAN=1 build_all
736                 ;;
737         
738                 'openlink')
739         print_highlight " building all (w/o clean) "       
740                 NO_EXTERNAL=1 setup_and_build
741                 ;;
742         #################### Building single components #############################
743                 'kernel')
744                 print_highlight " building only Kernel "
745                 clean_kernel
746                 build_uimage
747                 ;;
748                 
749                 'kernel_modules')
750         print_highlight " building only Driver modules "
751                 build_uimage
752                 build_modules
753                 ;;
754                 'modules')
755         print_highlight " building only Driver modules "
756                 build_modules
757                 ;;
759                 'wpa_supplicant')
760         print_highlight " building only wpa_supplicant "
761                 build_wpa_supplicant      
762                 ;;
764                 'hostapd')
765         print_highlight " building only hostapd "
766                 build_hostapd
767                 ;;
769                 'crda')
770         print_highlight " building only CRDA "
771                 build_crda
772                 ;;
773         
774                 'libnl')
775                 print_highlight " building only libnl"
776                 build_libnl
777                 ;;
779                 'iw')
780                 print_highlight " building only iw"
781                 build_iw
782                 ;;
784                 'openssl')
785                 print_highlight " building only openssl"
786                 build_openssl
787                 ;;
789         'scripts')
790         print_highlight " Copying scripts "
791                 build_scripts_download
792                 ;;
793                 
794         'utils')
795         print_highlight " building only ti-utils "
796         build_calibrator
797         build_wlconf            
798                 ;;        
799         ############################################################
800         'get_tag')
801         get_tag
802         exit
803         ;;
804                 
805         'admin_tag')        
806                 admin_tag $2
807                 ;;
808         
809         *)
810         print_highlight " building all (No clean & no source code update) "  
811                 #clean_outputs
812         NO_CLEAN=1 build_all
813                 ;;
814         esac
815         
816         [[ -z $NO_BUILD ]] && build_outputs
817         [[ -n $INSTALL_NFS ]] && install_outputs
819 main $@