build : add firmware build only option
[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} zImage
281             make -j${PROCESSORS_NUMBER} am335x-evm.dtb
282             make -j${PROCESSORS_NUMBER} modules
283             INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} modules_install
284             cp `repo_path kernel`/arch/arm/boot/zImage `path tftp`/zImage
285             cp `repo_path kernel`/arch/arm/boot/dts/am335x-evm.dtb `path tftp`/am335x-evm.dtb
286         else
287             LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage.am335x-evm 
288             cp `repo_path kernel`/arch/arm/boot/uImage.am335x-evm `path tftp`/uImage
289         fi
290     fi
291         assert_no_error
292         cd_back
295 function generate_compat()
297         cd_repo backports
298         python ./gentree.py --clean `repo_path driver` `path compat_wireless`
299         cd_back
302 function build_modules()
304         generate_compat
305         cd_repo compat_wireless
306         if [ -z $NO_CLEAN ]; then
307                 make clean
308         fi
309         make defconfig-wl18xx
310         make -j${PROCESSORS_NUMBER}
311         assert_no_error
312         find . -name \*.ko -exec cp {} `path debugging`/ \;
313         find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
314     
315 #       make -C ${KERNEL_PATH} M=`pwd` "INSTALL_MOD_PATH=`path filesystem`" modules_install
316         make  modules_install
317         assert_no_error
318         #chmod -R 0777 ${PATH__FILESYSTEM}/lib/modules/
319         cd_back
322 function build_openssl()
324         cd_repo openssl
325         [ -z $NO_CONFIG ] && ./Configure linux-generic32
326         [ -z $NO_CLEAN ] && make clean
327         [ -z $NO_CLEAN ] && assert_no_error
328         make
329         assert_no_error
330         make install_sw
331         assert_no_error
332         cd_back
336 function build_iw()
338         cd_repo iw
339         [ -z $NO_CLEAN ] && make clean
340         [ -z $NO_CLEAN ] && assert_no_error
341         CC=${CROSS_COMPILE}gcc LIBS+=" -lpthread -lm" make V=1
342         assert_no_error
343         DESTDIR=`path filesystem` make install
344         assert_no_error
345         cd_back
347 function build_libnl()
349         cd_repo libnl
350         [ -z $NO_CONFIG ] && ./autogen.sh
351         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
352         ([ -z $NO_CONFIG ] || [ -z $NO_CLEAN ]) && make clean
353         [ -z $NO_CLEAN ] && assert_no_error
354         make
355         assert_no_error
356         make install
357         assert_no_error
358         cd_back
361 function build_wpa_supplicant()
363         cd `repo_path hostap`/wpa_supplicant
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/*_supplicant.conf  `path filesystem`/etc/
375 function build_hostapd()
376 {              
377     cd `repo_path hostap`/hostapd
378         [ -z $NO_CONFIG ] && cp android.config .config
379         [ -n "$UPNP_EN" ] && echo "Enable UPNP config" && sed -i "/#CONFIG_WPS_UPNP=y/ s/# *//" .config
380         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
381         assert_no_error
382         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
383         assert_no_error
384         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
385         assert_no_error
386         cd_back
387     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
390 function build_crda()
391 {       
392         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
393         cp `repo_path wireless_regdb`/linville.key.pub.pem `path filesystem`/etc/wireless-regdb/pubkeys/
394     cd_repo crda
395         
396         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
397         [ -z $NO_CLEAN ] && assert_no_error
398         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
399         assert_no_error
400         DESTDIR=`path filesystem` make install
401         assert_no_error
402         cd_back
405 function build_calibrator()
407         cd_repo ti_utils
408         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
409         [ -z $NO_CLEAN ] && assert_no_error
410         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
411         assert_no_error
412         NFSROOT=`path filesystem` make install
413         #assert_no_error
414         cd_back
417 function build_wlconf()
419         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
420         cd `repo_path ti_utils`/wlconf
421         if [ -z $NO_CLEAN ]; then
422                 NFSROOT=`path filesystem` make clean
423                 assert_no_error
424                 for file_to_copy in $files_to_copy; do
425                         rm -f `path filesstem`/usr/sbin/wlconf/$file_to_copy
426                 done
427                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
428         fi
429         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
430         assert_no_error
432         # install
433         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
434         chmod 755 `path filesystem`/usr/sbin/wlconf
435         for file_to_copy in $files_to_copy; do
436                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
437                 echo "echoying files $file_to_copy"
438         done
439         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
440         cd_back
443 function build_fw_download()
445         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
449 function build_scripts_download()
451         cd_repo scripts_download
452         echo "Copying scripts"
453         scripts_download_path=`repo_path scripts_download`
454         for script_dir in `ls $scripts_download_path`
455         do
456                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
457                 cp -rf `repo_path scripts_download`/${script_dir}/* `path filesystem`/usr/share/wl18xx
458         done
459         cd_back
462 function clean_kernel()
464         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
465         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
466         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
469 function clean_outputs()
471     if [[ "$ROOTFS" == "DEFAULT" ]]
472     then
473         echo "Cleaning outputs"
474         rm -rf `path filesystem`/*
475         rm -f `path outputs`/${tar_filesystem[0]}
476         rm -f `path outputs`/uImage
477    fi
480 function build_outputs()
482         if [[ "$ROOTFS" == "DEFAULT" ]]
483     then  
484         echo "Building outputs"    
485         cd_path filesystem
486         tar cpjf `path outputs`/${tar_filesystem[0]} .
487         cd_back
488                 
489         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
490         then
491             cp `path tftp`/uImage `path outputs`/uImage
492         else
493             if [ -z $NO_DTB ]
494             then
495                 cp `path tftp`/zImage `path outputs`/zImage
496                 cp `path tftp`/am335x-evm.dtb `path outputs`/am335x-evm.dtb
497             else
498                 cp `path tftp`/uImage `path outputs`/uImage
499             fi
500         fi              
501     fi
504 function install_outputs()
506     echo "Installing outputs"
507         tftp_path=${setup[2]}
508         sitara_left_path=${setup[5]}
509         sitara_right_path=${setup[8]}
511         cp `path outputs`/uImage ${tftp_path}
512         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
513         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
515         cd $sitara_left_path
516         tar xjf ${tar_filesystem[0]}
517         cd_back
519         cd $sitara_right_path
520         tar xjf ${tar_filesystem[0]}
521         cd_back
524 function set_files_to_verify()
526         files_to_verify=(
527         # skeleton path
528         # source path
529         # pattern in output of file
531         `path filesystem`/usr/local/sbin/wpa_supplicant
532         `repo_path hostap`/wpa_supplicant/wpa_supplicant
533         "ELF 32-bit LSB executable, ARM"
535         `path filesystem`/usr/local/bin/hostapd
536         `repo_path hostap`/hostapd/hostapd
537         "ELF 32-bit LSB executable, ARM"
539         `path filesystem`/sbin/crda
540         `repo_path crda`/crda
541         "ELF 32-bit LSB executable, ARM"
543         `path filesystem`/usr/lib/crda/regulatory.bin
544         `repo_path wireless_regdb`/regulatory.bin
545         "CRDA wireless regulatory database file"
547         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
548         `repo_path fw_download`/wl18xx-fw-4.bin
549         "data"
551         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
552         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
553         "ELF 32-bit LSB relocatable, ARM"
555         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
556         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
557         "ELF 32-bit LSB relocatable, ARM"
559         #`path filesystem`/usr/bin/calibrator
560         #`repo_path ti_utils`/calibrator
561         #"ELF 32-bit LSB executable, ARM"
563         `path filesystem`/usr/sbin/wlconf/wlconf
564         `repo_path ti_utils`/wlconf/wlconf
565         "ELF 32-bit LSB executable, ARM"
566         )
569 function get_tag()
571        i="0"
572        while [ $i -lt ${#repositories[@]} ]; do
573                name=${repositories[$i]}
574                url=${repositories[$i + 1]}
575         branch=${repositories[$i + 2]}
576         checkout_type="branch"
577         cd_repo $name
578         if [[ "$url" == *git.ti.com* ]]
579         then
580                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
581                 git describe
582         fi
583                cd_back
584                i=$[$i + 3]
585        done
590 function admin_tag()
592         i="0"    
593         while [ $i -lt ${#repositories[@]} ]; do
594                 name=${repositories[$i]}
595                 url=${repositories[$i + 1]}
596         branch=${repositories[$i + 2]}   
597         checkout_type="branch"              
598         cd_repo $name    
599         if [[ "$url" == *git.ti.com* ]]
600         then                                   
601                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
602                 git show --summary        
603                 read -p "Do you want to tag this commit ?" yn
604                 case $yn in
605                     [Yy]* )  git tag -a $1 -m "$1" ;
606                              git push --tags ;;
607                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
608                     
609                     * ) echo "Please answer yes or no.";;
610                 esac
611            
612         fi        
613                 cd_back
614                 i=$[$i + 3]
615         done
619 function verify_skeleton()
621         echo "Verifying filesystem skeleton..."
623         set_files_to_verify
625         i="0"
626         while [ $i -lt ${#files_to_verify[@]} ]; do
627                 skeleton_path=${files_to_verify[i]}
628                 source_path=${files_to_verify[i + 1]}
629                 file_pattern=${files_to_verify[i + 2]}
630                 file $skeleton_path | grep "${file_pattern}" >/dev/null
631         if [ $? -eq 1 ]; then
632         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
633         #exit
634         fi
636                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
637                 md5_source=$(md5sum $source_path     | awk '{print $1}')
638                 if [ $md5_skeleton != $md5_source ]; then
639                         echo "ERROR: file mismatch"
640                         echo $skeleton_path
641                         exit 1
642                 fi
643                 i=$[$i + 3]
644         done
646         which regdbdump > /dev/null
647         if [ $? -eq 0 ]; then
648                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
649                 assert_no_error
650         fi
653 function setup_workspace()
655         setup_directories       
656         setup_repositories
657         setup_branches
658     #Download toolchain only if it was not set
659     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
663 function build_all()
665     if [ -z $NO_EXTERNAL ] 
666     then        
667         [ $DEFAULT_KERNEL ] && build_uimage
668         build_openssl
669         build_libnl
670         build_crda
671     fi
672     
673     if [ -z $NO_TI ] 
674     then
675         build_modules
676         build_iw
677         build_wpa_supplicant
678         build_hostapd   
679         build_calibrator
680         build_wlconf
681         build_fw_download
682         build_scripts_download
683     fi
684     
685     [ -z $NO_VERIFY ] && verify_skeleton
688 function setup_and_build()
690     setup_workspace
691     build_all
694 function main()
696         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
697     check_for_build_updates
698     setup_environment
699     setup_directories
700     read_kernel_version
701     
702         case "$1" in
703                 'update')                
704         print_highlight " setting up workspace and building all "       
705                 if [  -n "$2" ]
706         then
707             print_highlight "Using tag $2 " 
708             USE_TAG=$2
709         else
710             print_highlight "Updating all to head (this will revert local changes)" 
711             RESET=1    
712         fi
713         #clean_kernel
714         clean_outputs        
715         setup_workspace
716         read_kernel_version #####read kernel version again after update#####
717         build_all
718                 ;;
719         
720         'init')                
721         print_highlight " initializing workspace (w/o build) "       
722                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
723         NO_BUILD=1 
724         setup_workspace
725         read_kernel_version #####read kernel version again after init#####
726                 ;;
727               
728         'clean')        
729         print_highlight " cleaning & building all "       
730         clean_outputs
731         setup_directories
732         build_all        
733                 ;;
735                 'rebuild')
736         print_highlight " building all (w/o clean) "       
737                 NO_CLEAN=1 build_all
738                 ;;
739         
740                 'openlink')
741         print_highlight " building all (w/o clean) "       
742                 NO_EXTERNAL=1 setup_and_build
743                 ;;
744         #################### Building single components #############################
745                 'kernel')
746                 print_highlight " building only Kernel "
747                 clean_kernel
748                 build_uimage
749                 ;;
750                 
751                 'kernel_modules')
752         print_highlight " building only Driver modules "
753                 build_uimage
754                 build_modules
755                 ;;
756                 'modules')
757         print_highlight " building only Driver modules "
758                 build_modules
759                 ;;
761                 'wpa_supplicant')
762         print_highlight " building only wpa_supplicant "
763                 build_wpa_supplicant      
764                 ;;
766                 'hostapd')
767         print_highlight " building only hostapd "
768                 build_hostapd
769                 ;;
771                 'crda')
772         print_highlight " building only CRDA "
773                 build_crda
774                 ;;
775         
776                 'libnl')
777                 print_highlight " building only libnl"
778                 build_libnl
779                 ;;
781                 'iw')
782                 print_highlight " building only iw"
783                 build_iw
784                 ;;
786                 'openssl')
787                 print_highlight " building only openssl"
788                 build_openssl
789                 ;;
791                 'scripts')
792                 print_highlight " Copying scripts "
793                 build_scripts_download
794                 ;;
795                 
796                 'utils')
797                 print_highlight " building only ti-utils "
798                 build_calibrator
799                 build_wlconf            
800                 ;;        
801                 'firmware')
802                 print_highlight " building only firmware"
803                 build_fw_download
804                 ;;
805         ############################################################
806         'get_tag')
807         get_tag
808         exit
809         ;;
810                 
811         'admin_tag')        
812                 admin_tag $2
813                 ;;
814         
815         *)
816         print_highlight " building all (No clean & no source code update) "  
817                 #clean_outputs
818         NO_CLEAN=1 build_all
819                 ;;
820         esac
821         
822         [[ -z $NO_BUILD ]] && build_outputs
823         [[ -n $INSTALL_NFS ]] && install_outputs
825 main $@