200636807b4a1456380cdaec100648764854ba52
[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 build all/one of the relevent wl18xx software package."
23     echo "A web guide can be found here : http://processors.wiki.ti.com/index.php/WL18xx_System_Build_Scripts"
24     echo ""
25     echo "Usage : "
26     echo ""
27     echo "Building full package : "
28     echo "        ./build_wl18xx.sh init         <head|TAG>  [ Download and Update w/o build  ] "
29     echo "                          update       <head|TAG>  [ Update to specific TAG & Build ] "
30     echo "                          clean                    [ Clean & Build                  ] "
31     echo "                          <empty>                  [ Build w/o update               ] "
32     echo "                          check_updates            [ Check for build script updates ] "
33     echo ""
34     echo "Building specific component :"
35     echo "                          hostapd                  [ Clean & Build hostapd          ] "
36     echo "                          wpa_supplicant           [ Clean & Build wpa_supplicant   ] "
37     echo "                          modules                  [ Clean & Build driver modules   ] "
38     echo "                          firmware                 [ Install firmware file          ] "
39     echo "                          scripts                  [ Install scripts                ] "
40     echo "                          utils                    [ Clean & Build scripts          ] "
41     echo "                          iw                       [ Clean & Build iw               ] "
42     echo "                          openssl                  [ Clean & Build openssll         ] "
43     echo "                          libnl                    [ Clean & Build libnl            ] "
44     echo "                          crda                     [ Clean & Build crda             ] "
46     exit 1
47 }
49 function assert_no_error()
50 {
51         if [ $? -ne 0 ]; then
52                 echo "****** ERROR $? $@*******"
53                 exit 1
54         fi
55         echo "****** $1 *******"
56 }
58 function repo_id()
59 {
60         i="0"
61         while [ $i -lt ${#repositories[@]} ]; do
62                 [ $1 == "${repositories[i]}" ] && echo $i
63                 i=$[$i + 3]
64         done
65 }
67 function repo_url()
68 {
69         echo "${repositories[`repo_id $1` + 1]}"
70 }
72 function repo_branch()
73 {
74         echo "${repositories[`repo_id $1` + 2]}"
75 }
77 function path()
78 {
79         i="0"
80         while [ $i -lt "${#paths[@]}" ]; do
81                 [ $1 == "${paths[i]}" ] && echo "${paths[i + 1]}"
82                 i=$[$i + 2]
83         done
84 }
86 function set_path()
87 {
88         i="0"    
89         while [ $i -lt "${#paths[@]}" ]; do
90                 [ $1 == "${paths[i]}" ] && paths[i+1]=$2    
91                 i=$[$i + 2]
92         done
93 }
95 function repo_path()
96 {
97         echo `path src`/$1
98 }
100 function cd_path()
102         cd `path $1`
105 function cd_repo()
107         cd `repo_path $1`
110 function cd_back()
112         cd - > /dev/null
115 function check_for_build_updates()
117         git fetch
118         count=`git status -uno | grep behind | wc -l`
119         if [ $count -ne 0 ]
120         then
121                 echo ""
122                 echo "*** Please note, there is an updated build script avilalable ***"
123                 echo "*** Use 'git pull' to get the latest update. ***" 
124                 echo ""
125                 sleep 5
126         fi
129 function read_kernel_version()
131         filename=$KERNEL_PATH/Makefile
133         if [ ! -f $filename ]
134         then
135             KERNEL_VERSION=0
136             KERNEL_PATCHLEVEL=0
137             KERNEL_SUBLEVEL=0
138             echo "No Makefile was found. Kernel version was set to default." 
139         else 
140             exec 6< $filename
141             read version <&6
142             read patchlevel <&6
143             read sublevel <&6
144             exec 6<&-
146             KERNEL_VERSION=$(echo $version|sed 's/[^0-9]//g')
147             KERNEL_PATCHLEVEL=$(echo $patchlevel|sed 's/[^0-9]//g')
148             KERNEL_SUBLEVEL=$(echo $sublevel|sed 's/[^0-9]//g')
149             echo "Makefile was found. Kernel version was set to $KERNEL_VERSION.$KERNEL_PATCHLEVEL.$KERNEL_SUBLEVEL." 
150         fi
151         [ $VERIFY_CONFIG ] && ./verify_kernel_config.sh $KERNEL_PATH/.config
154 #----------------------------------------------------------j
155 function setup_environment()
157     if [ ! -e setup-env ]
158     then
159         echo "No setup-env"
160         exit 1
161     fi
162     
163     #if a rootfs path is set - replace the default.
164     if [[ "$ROOTFS" != "DEFAULT" ]]
165     then            
166         echo " Changing ROOTFS path to $ROOTFS"
167         set_path filesystem $ROOTFS
168         [ ! -d $ROOTFS ] && echo "Error ROOTFS: $ROOTFS dir does not exist" && exit 1
169     fi   
170     #if no toolchain path is set - download it.
171     if [[ "$TOOLCHAIN_PATH" == "DEFAULT" ]]
172     then            
173         echo " Setting TOOLCHAIN_PATH path to default"
174         export TOOLCHAIN_PATH=`path toolchain`/arm/bin
175         DEFAULT_TOOLCHAIN=1
176     fi   
178     #if no kernel path is set - download it.
179     if [[ "$KERNEL_PATH" == "DEFAULT" ]]
180     then            
181         echo " Setting KERNEL_PATH path to default"
182         export KERNEL_PATH=`repo_path kernel`
183         DEFAULT_KERNEL=1
184     else 
185         echo " Using user defined kernel"                        
186         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
187     fi  
188     
189         export PROCESSORS_NUMBER=$(egrep '^processor' /proc/cpuinfo | wc -l)
190         export PKG_CONFIG_PATH=`path filesystem`/lib/pkgconfig
191         export INSTALL_PREFIX=`path filesystem`
192         export LIBNL_PATH=`repo_path libnl`     
193         export KLIB=`path filesystem`
194         export KLIB_BUILD=${KERNEL_PATH}
195         export GIT_TREE=`repo_path driver`
196         export PATH=$TOOLCHAIN_PATH:$PATH
197     
200 function setup_filesystem_skeleton()
202         mkdir -p `path filesystem`/usr/bin
203         mkdir -p `path filesystem`/etc
204         mkdir -p `path filesystem`/usr/lib/crda
205         mkdir -p `path filesystem`/lib/firmware/ti-connectivity
206         mkdir -p `path filesystem`/usr/share/wl18xx
207         mkdir -p `path filesystem`/usr/sbin/wlconf
208         mkdir -p `path filesystem`/usr/sbin/wlconf/official_inis
209         mkdir -p `path filesystem`/etc/wireless-regdb/pubkeys
212 function setup_directories()
214         i="0"
215         while [ $i -lt ${#paths[@]} ]; do
216                 mkdir -p ${paths[i + 1]}
217                 i=$[$i + 2]
218         done
219         setup_filesystem_skeleton
223 function setup_repositories()
225         i="0"
226         while [ $i -lt ${#repositories[@]} ]; do
227                 url=${repositories[$i + 1]}
228                 name=${repositories[$i]}
229         echo -e "${NORMAL}Cloning into: ${GREEN} $name ${NORMAL}"        
230         #Skip kernel clone if it was user defined 
231                 [ "$name" != "kernel" -o "$DEFAULT_KERNEL" ] && [ ! -d `repo_path $name` ] && git clone $url `repo_path $name`
232                 i=$[$i + 3]
233         done        
236 function setup_branches()
238         i="0"    
239         while [ $i -lt ${#repositories[@]} ]; do
240                 name=${repositories[$i]}
241                 url=${repositories[$i + 1]}
242         branch=${repositories[$i + 2]}   
243         checkout_type="branch"       
244         #for all the openlink repo. we use a tag if provided.               
245         [ "$name" == "kernel" ] && [ -z "$DEFAULT_KERNEL" ] && i=$[$i + 3] && continue
246         cd_repo $name   
247         echo -e "\n${NORMAL}Checking out branch ${GREEN}$branch  ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
248                 git checkout $branch        
249         git fetch origin
250         git fetch origin --tags  
251         if [[ "$url" == *git.ti.com* ]]
252         then            
253            [[ -n $RESET ]] && echo -e "${PURPLE}Reset to latest in repo ${GREEN}$name ${NORMAL} branch  ${GREEN}$branch ${NORMAL}"  && git reset --hard origin/$branch
254            [[ -n $USE_TAG ]] && git reset --hard $USE_TAG  && echo -e "${NORMAL}Reset to tag ${GREEN}$USE_TAG   ${NORMAL}in repo ${GREEN}$name ${NORMAL} "            
255         fi        
256                 cd_back
257                 i=$[$i + 3]
258         done
261 function setup_toolchain()
263         if [ ! -f `path downloads`/arm-toolchain.tar.bz2 ]; then
264         echo "Setting toolchain"
265                 wget ${toolchain[0]} -O `path downloads`/arm-toolchain.tar.bz2
266                 tar -xjf `path downloads`/arm-toolchain.tar.bz2 -C `path toolchain`
267                 mv `path toolchain`/* `path toolchain`/arm
268         fi
271 function build_uimage()
273     cd_repo kernel
274         [ -z $NO_CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path kernel`/.config
275         [ -z $NO_CLEAN ] && make clean
276         [ -z $NO_CLEAN ] && assert_no_error
278     if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
279     then
280         make -j${PROCESSORS_NUMBER} uImage
281         cp `repo_path kernel`/arch/arm/boot/uImage `path tftp`/uImage
282     else
283         if [ -z $NO_DTB ] 
284         then
285             make -j${PROCESSORS_NUMBER} zImage
286             make -j${PROCESSORS_NUMBER} am335x-evm.dtb
287             make -j${PROCESSORS_NUMBER} am335x-bone.dtb
288             make -j${PROCESSORS_NUMBER} am335x-boneblack.dtb
289             make -j${PROCESSORS_NUMBER} modules
290             INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} modules_install
291             cp `repo_path kernel`/arch/arm/boot/zImage `path tftp`/zImage
292             cp `repo_path kernel`/arch/arm/boot/dts/am335x-*.dtb `path tftp`/
293         else
294             LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage.am335x-evm 
295             cp `repo_path kernel`/arch/arm/boot/uImage.am335x-evm `path tftp`/uImage
296         fi
297     fi
298         assert_no_error
299         cd_back
302 function generate_compat()
304         cd_repo backports
305         python ./gentree.py --clean `repo_path driver` `path compat_wireless`
306         cd_back
309 function build_modules()
311         generate_compat
312         cd_repo compat_wireless
313         if [ -z $NO_CLEAN ]; then
314                 make clean
315         fi
316         make defconfig-wl18xx
317         make -j${PROCESSORS_NUMBER}
318         assert_no_error
319         #find . -name \*.ko -exec cp {} `path debugging`/ \;
320         find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
321     
322         make  modules_install
323         assert_no_error
324         cd_back
327 function build_openssl()
329         cd_repo openssl
330         [ -z $NO_CONFIG ] && ./Configure linux-generic32
331         [ -z $NO_CLEAN ] && make clean
332         [ -z $NO_CLEAN ] && assert_no_error
333         make
334         assert_no_error
335         make install_sw
336         assert_no_error
337         cd_back
341 function build_iw()
343         cd_repo iw
344         [ -z $NO_CLEAN ] && make clean
345         [ -z $NO_CLEAN ] && assert_no_error
346         CC=${CROSS_COMPILE}gcc LIBS+=" -lpthread -lm" make V=1
347         assert_no_error
348         DESTDIR=`path filesystem` make install
349         assert_no_error
350         cd_back
352 function build_libnl()
354         cd_repo libnl
355         [ -z $NO_CONFIG ] && ./autogen.sh
356         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
357         ([ -z $NO_CONFIG ] || [ -z $NO_CLEAN ]) && make clean
358         [ -z $NO_CLEAN ] && assert_no_error
359         make
360         assert_no_error
361         make install
362         assert_no_error
363         cd_back
366 function build_wpa_supplicant()
368         cd `repo_path hostap`/wpa_supplicant
369         [ -z $NO_CONFIG ] && cp android.config .config
370     [ -n "$SYSLOG_EN" ] && echo "Enable DEBUG_SYSLOG config" && sed -i "/#CONFIG_DEBUG_SYSLOG=y/ s/# *//" .config
371         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
372         assert_no_error
373         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
374         assert_no_error
375         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
376         assert_no_error
377         cd_back    
378     cp `repo_path scripts_download`/conf/*_supplicant.conf  `path filesystem`/etc/
381 function build_hostapd()
383     cd `repo_path hostap`/hostapd
384         [ -z $NO_CONFIG ] && cp android.config .config
385         [ -n "$UPNP_EN" ] && echo "Enable UPNP config" && sed -i "/#CONFIG_WPS_UPNP=y/ s/# *//" .config
386         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
387         assert_no_error
388         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
389         assert_no_error
390         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
391         assert_no_error
392         cd_back
393     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
396 function build_crda()
397 {       
398         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
399         cp `repo_path wireless_regdb`/sforshee.key.pub.pem `path filesystem`/etc/wireless-regdb/pubkeys/
400     cd_repo crda
401         
402         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
403         [ -z $NO_CLEAN ] && assert_no_error
404         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
405         assert_no_error
406         DESTDIR=`path filesystem` make install
407         assert_no_error
408         cd_back
411 function build_calibrator()
413         cd_repo ti_utils
414         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
415         [ -z $NO_CLEAN ] && assert_no_error
416         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
417         assert_no_error
418         NFSROOT=`path filesystem` make install
419         #assert_no_error
420         cp -f `repo_path ti_utils`/hw/firmware/wl1271-nvs.bin `path filesystem`/lib/firmware/ti-connectivity
421         cd_back
424 function build_wlconf()
426         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
427         cd `repo_path ti_utils`/wlconf
428         if [ -z $NO_CLEAN ]; then
429                 NFSROOT=`path filesystem` make clean
430                 assert_no_error
431                 for file_to_copy in $files_to_copy; do
432                         rm -f `path filesystem`/usr/sbin/wlconf/$file_to_copy
433                 done
434                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
435         fi
436         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
437         assert_no_error
439         # install
440         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
441         chmod 755 `path filesystem`/usr/sbin/wlconf
442         for file_to_copy in $files_to_copy; do
443                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
444                 echo "echoying files $file_to_copy"
445         done
446         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
447         cd_back
450 function build_fw_download()
452         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
456 function build_scripts_download()
458         cd_repo scripts_download
459         echo "Copying scripts"
460         scripts_download_path=`repo_path scripts_download`
461         for script_dir in `ls -d $scripts_download_path`/*/
462         do
463                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
464                 cp -rf ${script_dir}/* `path filesystem`/usr/share/wl18xx
465         done
466         cd_back
469 function clean_kernel()
471         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
472         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
473         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
476 function clean_outputs()
478     if [[ "$ROOTFS" == "DEFAULT" ]]
479     then
480         echo "Cleaning outputs"
481         rm -rf `path filesystem`/*
482         rm -f `path outputs`/*
483    fi
486 function build_outputs()
488         if [[ "$ROOTFS" == "DEFAULT" ]]
489     then  
490         echo "Building outputs"    
491         cd_path filesystem
492         tar cpjf `path outputs`/${tar_filesystem[0]} .
493         cd_back
494                 
495                 # Copy kernel files only if default kernel is used(for now)
496                 if [ "$DEFAULT_KERNEL" -eq 1 ]
497                 then
498                         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
499                         then
500                                 cp `path tftp`/uImage `path outputs`/uImage
501                         else
502                                 if [ -z $NO_DTB ]
503                                 then
504                                         cp `path tftp`/zImage `path outputs`/zImage
505                                         cp `path tftp`/*.dtb `path outputs`/
506                                 else
507                                         cp `path tftp`/uImage `path outputs`/uImage
508                                 fi
509                         fi
510                 fi
511     fi
514 function install_outputs()
516     echo "Installing outputs"
517         tftp_path=${setup[2]}
518         sitara_left_path=${setup[5]}
519         sitara_right_path=${setup[8]}
521         cp `path outputs`/uImage ${tftp_path}
522         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
523         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
525         cd $sitara_left_path
526         tar xjf ${tar_filesystem[0]}
527         cd_back
529         cd $sitara_right_path
530         tar xjf ${tar_filesystem[0]}
531         cd_back
534 function set_files_to_verify()
536         files_to_verify=(
537         # skeleton path
538         # source path
539         # pattern in output of file
541         `path filesystem`/usr/local/sbin/wpa_supplicant
542         `repo_path hostap`/wpa_supplicant/wpa_supplicant
543         "ELF 32-bit LSB executable, ARM"
545         `path filesystem`/usr/local/bin/hostapd
546         `repo_path hostap`/hostapd/hostapd
547         "ELF 32-bit LSB executable, ARM"
549         `path filesystem`/sbin/crda
550         `repo_path crda`/crda
551         "ELF 32-bit LSB executable, ARM"
553         `path filesystem`/usr/lib/crda/regulatory.bin
554         `repo_path wireless_regdb`/regulatory.bin
555         "CRDA wireless regulatory database file"
557         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
558         `repo_path fw_download`/wl18xx-fw-4.bin
559         "data"
561         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
562         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
563         "ELF 32-bit LSB relocatable, ARM"
565         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
566         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
567         "ELF 32-bit LSB relocatable, ARM"
569         #`path filesystem`/usr/bin/calibrator
570         #`repo_path ti_utils`/calibrator
571         #"ELF 32-bit LSB executable, ARM"
573         `path filesystem`/usr/sbin/wlconf/wlconf
574         `repo_path ti_utils`/wlconf/wlconf
575         "ELF 32-bit LSB executable, ARM"
576         )
579 function get_tag()
581        i="0"
582        while [ $i -lt ${#repositories[@]} ]; do
583                name=${repositories[$i]}
584                url=${repositories[$i + 1]}
585         branch=${repositories[$i + 2]}
586         checkout_type="branch"
587         cd_repo $name
588         if [[ "$url" == *git.ti.com* ]]
589         then
590                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
591                 git describe
592         fi
593                cd_back
594                i=$[$i + 3]
595        done
600 function admin_tag()
602         i="0"    
603         while [ $i -lt ${#repositories[@]} ]; do
604                 name=${repositories[$i]}
605                 url=${repositories[$i + 1]}
606         branch=${repositories[$i + 2]}   
607         checkout_type="branch"              
608         cd_repo $name    
609         if [[ "$url" == *git.ti.com* ]]
610         then                                   
611                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
612                 git show --summary        
613                 read -p "Do you want to tag this commit ?" yn
614                 case $yn in
615                     [Yy]* )  git tag -a $1 -m "$1" ;
616                              git push --tags ;;
617                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
618                     
619                     * ) echo "Please answer yes or no.";;
620                 esac
621            
622         fi        
623                 cd_back
624                 i=$[$i + 3]
625         done
629 function verify_skeleton()
631         echo "Verifying filesystem skeleton..."
633         set_files_to_verify
635         i="0"
636         while [ $i -lt ${#files_to_verify[@]} ]; do
637                 skeleton_path=${files_to_verify[i]}
638                 source_path=${files_to_verify[i + 1]}
639                 file_pattern=${files_to_verify[i + 2]}
640                 file $skeleton_path | grep "${file_pattern}" >/dev/null
641         if [ $? -eq 1 ]; then
642         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
643         #exit
644         fi
646                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
647                 md5_source=$(md5sum $source_path     | awk '{print $1}')
648                 if [ $md5_skeleton != $md5_source ]; then
649                         echo "ERROR: file mismatch"
650                         echo $skeleton_path
651                         exit 1
652                 fi
653                 i=$[$i + 3]
654         done
656         which regdbdump > /dev/null
657         if [ $? -eq 0 ]; then
658                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
659                 if [ $? -ne 0 ]; then
660                         echo "Please update your public key used to verify the DB"
661                 fi
662         fi
665 function verify_installs()
667     apps_to_verify=(
668      libtool     
669      python-m2crypto
670      bison
671      flex
672     )
674     i="0"
675         while [ $i -lt ${#apps_to_verify[@]} ]; do
676         if !( dpkg-query -s ${apps_to_verify[i]} 2>/dev/null | grep -q ^"Status: install ok installed"$ )then
677             echo  "${apps_to_verify[i]} is missing"
678             echo  "Please use 'sudo apt-get install ${apps_to_verify[i]}'"
679             read -p "Do you want to install it now [y/n] ? (requires sudo) " yn
680             case $yn in
681                 [Yy]* )  sudo apt-get install ${apps_to_verify[i]} ;;
682                 [Nn]* ) echo -e "${PURPLE}${apps_to_verify[i]} was not installed. leaving build. ${NORMAL} " ; exit 0 ;;
683                 * ) echo "Please answer y or n.";;
684             esac
685         fi
686         i=$[$i + 1]
687     done
690 function setup_workspace()
692         setup_directories       
693         setup_repositories
694         setup_branches
695     verify_installs
696     #Download toolchain only if it was not set
697     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
701 function build_all()
703     if [ -z $NO_EXTERNAL ] 
704     then        
705         [ $DEFAULT_KERNEL ] && build_uimage
706         build_openssl
707         build_libnl
708         build_crda
709     fi
710     
711     if [ -z $NO_TI ] 
712     then
713         build_modules
714         build_iw
715         build_wpa_supplicant
716         build_hostapd   
717         build_calibrator
718         build_wlconf
719         build_fw_download
720         build_scripts_download
721     fi
722     
723     [ -z $NO_VERIFY ] && verify_skeleton
726 function setup_and_build()
728     setup_workspace
729     build_all
732 function main()
734         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
735     setup_environment
736     setup_directories
737     read_kernel_version
738     
739         case "$1" in
740         'init')                
741         print_highlight " initializing workspace (w/o build) "       
742                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
743         NO_BUILD=1 
744         setup_workspace
745         read_kernel_version #####read kernel version again after init#####
746                 ;;
747               
748         'clean')        
749         print_highlight " cleaning & building all "       
750         clean_outputs
751         setup_directories
752         build_all        
753                 ;;
755         'update')
756         print_highlight " setting up workspace and building all "
757                 if [  -n "$2" ]
758         then
759             print_highlight "Using tag $2 "
760             USE_TAG=$2
761         else
762             print_highlight "Updating all to head (this will revert local changes)"
763             RESET=1
764         fi
765         #clean_kernel
766         clean_outputs
767         setup_workspace
768         read_kernel_version #####read kernel version again after update#####
769         build_all
770                 ;;
771         
772                 'openlink')
773         print_highlight " building all (w/o clean) "       
774                 NO_EXTERNAL=1 setup_and_build
775                 ;;
777         #################### Building single components #############################
778                 'kernel')
779                 print_highlight " building only Kernel "
780                 #clean_kernel
781                 build_uimage
782                 ;;
783                 
784                 'kernel_modules')
785         print_highlight " building only Driver modules "
786                 build_uimage
787                 build_modules
788                 ;;
789                 'modules')
790         print_highlight " building only Driver modules "
791                 build_modules
792                 ;;
794                 'wpa_supplicant')
795         print_highlight " building only wpa_supplicant "
796                 build_wpa_supplicant      
797                 ;;
799                 'hostapd')
800         print_highlight " building only hostapd "
801                 build_hostapd
802                 ;;
804                 'crda')
805         print_highlight " building only CRDA "
806                 build_crda
807                 ;;
808         
809                 'libnl')
810                 print_highlight " building only libnl"
811                 build_libnl
812                 ;;
814                 'iw')
815                 print_highlight " building only iw"
816                 build_iw
817                 ;;
819                 'openssl')
820                 print_highlight " building only openssl"
821                 build_openssl
822                 ;;
824                 'scripts')
825                 print_highlight " Copying scripts "
826                 build_scripts_download
827                 ;;
828                 
829                 'utils')
830                 print_highlight " building only ti-utils "
831                 build_calibrator
832                 build_wlconf            
833                 ;;        
834                 'firmware')
835                 print_highlight " building only firmware"
836                 build_fw_download
837                 ;;
838         ############################################################
839         'get_tag')
840         get_tag
841         exit
842         ;;
843                 
844         'admin_tag')        
845                 admin_tag $2
846                 ;;
848         'check_updates')
849                 check_for_build_updates
850                 ;;
852         '')
853         print_highlight " building all (No clean & no source code update) "  
854                 #clean_outputs
855         NO_CLEAN=1 build_all
856                 ;;
858         *)
859         echo " "
860         echo "**** Unknown parameter - please see usage below **** "
861         usage
862         ;;
863         esac
864         
865         [[ -z $NO_BUILD ]] && build_outputs
866         [[ -n $INSTALL_NFS ]] && install_outputs
868 main $@