a3dd9afd449f3d47c21217195bf9aa1f4e0a0a07
[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 "        ./wl18xx_build.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
153 #----------------------------------------------------------j
154 function setup_environment()
156     if [ ! -e setup-env ]
157     then
158         echo "No setup-env"
159         exit 1
160     fi
161     
162     #if a rootfs path is set - replace the default.
163     if [[ "$ROOTFS" != "DEFAULT" ]]
164     then            
165         echo " Changing ROOTFS path to $ROOTFS"
166         set_path filesystem $ROOTFS
167         [ ! -d $ROOTFS ] && echo "Error ROOTFS: $ROOTFS dir does not exist" && exit 1
168     fi   
169     #if no toolchain path is set - download it.
170     if [[ "$TOOLCHAIN_PATH" == "DEFAULT" ]]
171     then            
172         echo " Setting TOOLCHAIN_PATH path to default"
173         export TOOLCHAIN_PATH=`path toolchain`/arm/bin
174         DEFAULT_TOOLCHAIN=1
175     fi   
177     #if no kernel path is set - download it.
178     if [[ "$KERNEL_PATH" == "DEFAULT" ]]
179     then            
180         echo " Setting KERNEL_PATH path to default"
181         export KERNEL_PATH=`repo_path kernel`
182         DEFAULT_KERNEL=1
183     else 
184         echo " Using user defined kernel"                        
185         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
186     fi  
187     
188         export PROCESSORS_NUMBER=$(egrep '^processor' /proc/cpuinfo | wc -l)
189         export PKG_CONFIG_PATH=`path filesystem`/lib/pkgconfig
190         export INSTALL_PREFIX=`path filesystem`
191         export LIBNL_PATH=`repo_path libnl`     
192         export KLIB=`path filesystem`
193         export KLIB_BUILD=${KERNEL_PATH}
194         export GIT_TREE=`repo_path driver`
195         export PATH=$TOOLCHAIN_PATH:$PATH
196     
199 function setup_filesystem_skeleton()
201         mkdir -p `path filesystem`/usr/bin
202         mkdir -p `path filesystem`/etc
203         mkdir -p `path filesystem`/usr/lib/crda
204         mkdir -p `path filesystem`/lib/firmware/ti-connectivity
205         mkdir -p `path filesystem`/usr/share/wl18xx
206         mkdir -p `path filesystem`/usr/sbin/wlconf
207         mkdir -p `path filesystem`/usr/sbin/wlconf/official_inis
208         mkdir -p `path filesystem`/etc/wireless-regdb/pubkeys
211 function setup_directories()
213         i="0"
214         while [ $i -lt ${#paths[@]} ]; do
215                 mkdir -p ${paths[i + 1]}
216                 i=$[$i + 2]
217         done
218         setup_filesystem_skeleton
222 function setup_repositories()
224         i="0"
225         while [ $i -lt ${#repositories[@]} ]; do
226                 url=${repositories[$i + 1]}
227                 name=${repositories[$i]}
228         echo -e "${NORMAL}Cloning into: ${GREEN} $name ${NORMAL}"        
229         #Skip kernel clone if it was user defined 
230                 [ "$name" != "kernel" -o "$DEFAULT_KERNEL" ] && [ ! -d `repo_path $name` ] && git clone $url `repo_path $name`
231                 i=$[$i + 3]
232         done        
235 function setup_branches()
237         i="0"    
238         while [ $i -lt ${#repositories[@]} ]; do
239                 name=${repositories[$i]}
240                 url=${repositories[$i + 1]}
241         branch=${repositories[$i + 2]}   
242         checkout_type="branch"       
243         #for all the openlink repo. we use a tag if provided.               
244         [ "$name" == "kernel" ] && [ -z "$DEFAULT_KERNEL" ] && i=$[$i + 3] && continue
245         cd_repo $name   
246         echo -e "\n${NORMAL}Checking out branch ${GREEN}$branch  ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
247                 git checkout $branch        
248         git fetch origin
249         git fetch origin --tags  
250         if [[ "$url" == *git.ti.com* ]]
251         then            
252            [[ -n $RESET ]] && echo -e "${PURPLE}Reset to latest in repo ${GREEN}$name ${NORMAL} branch  ${GREEN}$branch ${NORMAL}"  && git reset --hard origin/$branch
253            [[ -n $USE_TAG ]] && git reset --hard $USE_TAG  && echo -e "${NORMAL}Reset to tag ${GREEN}$USE_TAG   ${NORMAL}in repo ${GREEN}$name ${NORMAL} "            
254         fi        
255                 cd_back
256                 i=$[$i + 3]
257         done
260 function setup_toolchain()
262         if [ ! -f `path downloads`/arm-toolchain.tar.bz2 ]; then
263         echo "Setting toolchain"
264                 wget ${toolchain[0]} -O `path downloads`/arm-toolchain.tar.bz2
265                 tar -xjf `path downloads`/arm-toolchain.tar.bz2 -C `path toolchain`
266                 mv `path toolchain`/* `path toolchain`/arm
267         fi
270 function build_uimage()
272     cd_repo kernel
273         [ -z $NO_CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path kernel`/.config
274         [ -z $NO_CLEAN ] && make clean
275         [ -z $NO_CLEAN ] && assert_no_error
276        
277     if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
278     then
279         make -j${PROCESSORS_NUMBER} uImage
280         cp `repo_path kernel`/arch/arm/boot/uImage `path tftp`/uImage
281     else
282         if [ -z $NO_DTB ] 
283         then
284             make -j${PROCESSORS_NUMBER} zImage
285             make -j${PROCESSORS_NUMBER} am335x-evm.dtb
286             make -j${PROCESSORS_NUMBER} am335x-bone.dtb
287             make -j${PROCESSORS_NUMBER} am335x-boneblack.dtb
288             make -j${PROCESSORS_NUMBER} modules
289             INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} modules_install
290             cp `repo_path kernel`/arch/arm/boot/zImage `path tftp`/zImage
291             cp `repo_path kernel`/arch/arm/boot/dts/am335x-*.dtb `path tftp`/
292         else
293             LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage.am335x-evm 
294             cp `repo_path kernel`/arch/arm/boot/uImage.am335x-evm `path tftp`/uImage
295         fi
296     fi
297         assert_no_error
298         cd_back
301 function generate_compat()
303         cd_repo backports
304         python ./gentree.py --clean `repo_path driver` `path compat_wireless`
305         cd_back
308 function build_modules()
310         generate_compat
311         cd_repo compat_wireless
312         if [ -z $NO_CLEAN ]; then
313                 make clean
314         fi
315         make defconfig-wl18xx
316         make -j${PROCESSORS_NUMBER}
317         assert_no_error
318         #find . -name \*.ko -exec cp {} `path debugging`/ \;
319         find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
320     
321         make  modules_install
322         assert_no_error
323         cd_back
326 function build_openssl()
328         cd_repo openssl
329         [ -z $NO_CONFIG ] && ./Configure linux-generic32
330         [ -z $NO_CLEAN ] && make clean
331         [ -z $NO_CLEAN ] && assert_no_error
332         make
333         assert_no_error
334         make install_sw
335         assert_no_error
336         cd_back
340 function build_iw()
342         cd_repo iw
343         [ -z $NO_CLEAN ] && make clean
344         [ -z $NO_CLEAN ] && assert_no_error
345         CC=${CROSS_COMPILE}gcc LIBS+=" -lpthread -lm" make V=1
346         assert_no_error
347         DESTDIR=`path filesystem` make install
348         assert_no_error
349         cd_back
351 function build_libnl()
353         cd_repo libnl
354         [ -z $NO_CONFIG ] && ./autogen.sh
355         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
356         ([ -z $NO_CONFIG ] || [ -z $NO_CLEAN ]) && make clean
357         [ -z $NO_CLEAN ] && assert_no_error
358         make
359         assert_no_error
360         make install
361         assert_no_error
362         cd_back
365 function build_wpa_supplicant()
367         cd `repo_path hostap`/wpa_supplicant
368         [ -z $NO_CONFIG ] && cp android.config .config
369     [ -n "$SYSLOG_EN" ] && echo "Enable DEBUG_SYSLOG config" && sed -i "/#CONFIG_DEBUG_SYSLOG=y/ s/# *//" .config
370         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
371         assert_no_error
372         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
373         assert_no_error
374         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
375         assert_no_error
376         cd_back    
377     cp `repo_path scripts_download`/conf/*_supplicant.conf  `path filesystem`/etc/
380 function build_hostapd()
382     cd `repo_path hostap`/hostapd
383         [ -z $NO_CONFIG ] && cp android.config .config
384         [ -n "$UPNP_EN" ] && echo "Enable UPNP config" && sed -i "/#CONFIG_WPS_UPNP=y/ s/# *//" .config
385         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
386         assert_no_error
387         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
388         assert_no_error
389         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
390         assert_no_error
391         cd_back
392     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
395 function build_crda()
396 {       
397         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
398         cp `repo_path wireless_regdb`/linville.key.pub.pem `path filesystem`/etc/wireless-regdb/pubkeys/
399     cd_repo crda
400         
401         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
402         [ -z $NO_CLEAN ] && assert_no_error
403         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
404         assert_no_error
405         DESTDIR=`path filesystem` make install
406         assert_no_error
407         cd_back
410 function build_calibrator()
412         cd_repo ti_utils
413         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
414         [ -z $NO_CLEAN ] && assert_no_error
415         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
416         assert_no_error
417         NFSROOT=`path filesystem` make install
418         #assert_no_error
419         cd_back
422 function build_wlconf()
424         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
425         cd `repo_path ti_utils`/wlconf
426         if [ -z $NO_CLEAN ]; then
427                 NFSROOT=`path filesystem` make clean
428                 assert_no_error
429                 for file_to_copy in $files_to_copy; do
430                         rm -f `path filesstem`/usr/sbin/wlconf/$file_to_copy
431                 done
432                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
433         fi
434         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
435         assert_no_error
437         # install
438         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
439         chmod 755 `path filesystem`/usr/sbin/wlconf
440         for file_to_copy in $files_to_copy; do
441                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
442                 echo "echoying files $file_to_copy"
443         done
444         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
445         cd_back
448 function build_fw_download()
450         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
454 function build_scripts_download()
456         cd_repo scripts_download
457         echo "Copying scripts"
458         scripts_download_path=`repo_path scripts_download`
459         for script_dir in `ls $scripts_download_path`
460         do
461                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
462                 cp -rf `repo_path scripts_download`/${script_dir}/* `path filesystem`/usr/share/wl18xx
463         done
464         cd_back
467 function clean_kernel()
469         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
470         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
471         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
474 function clean_outputs()
476     if [[ "$ROOTFS" == "DEFAULT" ]]
477     then
478         echo "Cleaning outputs"
479         rm -rf `path filesystem`/*
480         rm -f `path outputs`/*
481    fi
484 function build_outputs()
486         if [[ "$ROOTFS" == "DEFAULT" ]]
487     then  
488         echo "Building outputs"    
489         cd_path filesystem
490         tar cpjf `path outputs`/${tar_filesystem[0]} .
491         cd_back
492                 
493         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
494         then
495             cp `path tftp`/uImage `path outputs`/uImage
496         else
497             if [ -z $NO_DTB ]
498             then
499                 cp `path tftp`/zImage `path outputs`/zImage
500                 cp `path tftp`/*.dtb `path outputs`/*.dtb
501             else
502                 cp `path tftp`/uImage `path outputs`/uImage
503             fi
504         fi              
505     fi
508 function install_outputs()
510     echo "Installing outputs"
511         tftp_path=${setup[2]}
512         sitara_left_path=${setup[5]}
513         sitara_right_path=${setup[8]}
515         cp `path outputs`/uImage ${tftp_path}
516         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
517         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
519         cd $sitara_left_path
520         tar xjf ${tar_filesystem[0]}
521         cd_back
523         cd $sitara_right_path
524         tar xjf ${tar_filesystem[0]}
525         cd_back
528 function set_files_to_verify()
530         files_to_verify=(
531         # skeleton path
532         # source path
533         # pattern in output of file
535         `path filesystem`/usr/local/sbin/wpa_supplicant
536         `repo_path hostap`/wpa_supplicant/wpa_supplicant
537         "ELF 32-bit LSB executable, ARM"
539         `path filesystem`/usr/local/bin/hostapd
540         `repo_path hostap`/hostapd/hostapd
541         "ELF 32-bit LSB executable, ARM"
543         `path filesystem`/sbin/crda
544         `repo_path crda`/crda
545         "ELF 32-bit LSB executable, ARM"
547         `path filesystem`/usr/lib/crda/regulatory.bin
548         `repo_path wireless_regdb`/regulatory.bin
549         "CRDA wireless regulatory database file"
551         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
552         `repo_path fw_download`/wl18xx-fw-4.bin
553         "data"
555         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
556         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
557         "ELF 32-bit LSB relocatable, ARM"
559         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
560         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
561         "ELF 32-bit LSB relocatable, ARM"
563         #`path filesystem`/usr/bin/calibrator
564         #`repo_path ti_utils`/calibrator
565         #"ELF 32-bit LSB executable, ARM"
567         `path filesystem`/usr/sbin/wlconf/wlconf
568         `repo_path ti_utils`/wlconf/wlconf
569         "ELF 32-bit LSB executable, ARM"
570         )
573 function get_tag()
575        i="0"
576        while [ $i -lt ${#repositories[@]} ]; do
577                name=${repositories[$i]}
578                url=${repositories[$i + 1]}
579         branch=${repositories[$i + 2]}
580         checkout_type="branch"
581         cd_repo $name
582         if [[ "$url" == *git.ti.com* ]]
583         then
584                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
585                 git describe
586         fi
587                cd_back
588                i=$[$i + 3]
589        done
594 function admin_tag()
596         i="0"    
597         while [ $i -lt ${#repositories[@]} ]; do
598                 name=${repositories[$i]}
599                 url=${repositories[$i + 1]}
600         branch=${repositories[$i + 2]}   
601         checkout_type="branch"              
602         cd_repo $name    
603         if [[ "$url" == *git.ti.com* ]]
604         then                                   
605                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
606                 git show --summary        
607                 read -p "Do you want to tag this commit ?" yn
608                 case $yn in
609                     [Yy]* )  git tag -a $1 -m "$1" ;
610                              git push --tags ;;
611                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
612                     
613                     * ) echo "Please answer yes or no.";;
614                 esac
615            
616         fi        
617                 cd_back
618                 i=$[$i + 3]
619         done
623 function verify_skeleton()
625         echo "Verifying filesystem skeleton..."
627         set_files_to_verify
629         i="0"
630         while [ $i -lt ${#files_to_verify[@]} ]; do
631                 skeleton_path=${files_to_verify[i]}
632                 source_path=${files_to_verify[i + 1]}
633                 file_pattern=${files_to_verify[i + 2]}
634                 file $skeleton_path | grep "${file_pattern}" >/dev/null
635         if [ $? -eq 1 ]; then
636         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
637         #exit
638         fi
640                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
641                 md5_source=$(md5sum $source_path     | awk '{print $1}')
642                 if [ $md5_skeleton != $md5_source ]; then
643                         echo "ERROR: file mismatch"
644                         echo $skeleton_path
645                         exit 1
646                 fi
647                 i=$[$i + 3]
648         done
650         which regdbdump > /dev/null
651         if [ $? -eq 0 ]; then
652                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
653                 assert_no_error
654         fi
657 function verify_installs()
659     apps_to_verify=(
660      libtool     
661      python-m2crypto
662      bison
663      flex
664     )
666     i="0"
667         while [ $i -lt ${#apps_to_verify[@]} ]; do
668         if !( hash ${apps_to_verify[i]} 2>/dev/null; )then
669             echo  "${apps_to_verify[i]} is missing"
670             echo  "Please use 'sudo apt-get install ${apps_to_verify[i]}'"
671             read -p "Do you want to install it now [y/n] ? (requires sudo) " yn
672             case $yn in
673                 [Yy]* )  sudo apt-get install ${apps_to_verify[i]} ;;
674                 [Nn]* ) echo -e "${PURPLE}${apps_to_verify[i]} was not installed. leaving build. ${NORMAL} " ; exit 0 ;;
675                 * ) echo "Please answer y or n.";;
676             esac
677         fi
678         i=$[$i + 1]
679     done
682 function setup_workspace()
684         setup_directories       
685         setup_repositories
686         setup_branches
687     verify_installs
688     #Download toolchain only if it was not set
689     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
693 function build_all()
695     if [ -z $NO_EXTERNAL ] 
696     then        
697         [ $DEFAULT_KERNEL ] && build_uimage
698         build_openssl
699         build_libnl
700         build_crda
701     fi
702     
703     if [ -z $NO_TI ] 
704     then
705         build_modules
706         build_iw
707         build_wpa_supplicant
708         build_hostapd   
709         build_calibrator
710         build_wlconf
711         build_fw_download
712         build_scripts_download
713     fi
714     
715     [ -z $NO_VERIFY ] && verify_skeleton
718 function setup_and_build()
720     setup_workspace
721     build_all
724 function main()
726         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
727     setup_environment
728     setup_directories
729     read_kernel_version
730     
731         case "$1" in
732         'init')                
733         print_highlight " initializing workspace (w/o build) "       
734                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
735         NO_BUILD=1 
736         setup_workspace
737         read_kernel_version #####read kernel version again after init#####
738                 ;;
739               
740         'clean')        
741         print_highlight " cleaning & building all "       
742         clean_outputs
743         setup_directories
744         build_all        
745                 ;;
747         'update')
748         print_highlight " setting up workspace and building all "
749                 if [  -n "$2" ]
750         then
751             print_highlight "Using tag $2 "
752             USE_TAG=$2
753         else
754             print_highlight "Updating all to head (this will revert local changes)"
755             RESET=1
756         fi
757         #clean_kernel
758         clean_outputs
759         setup_workspace
760         read_kernel_version #####read kernel version again after update#####
761         build_all
762                 ;;
763         
764                 'openlink')
765         print_highlight " building all (w/o clean) "       
766                 NO_EXTERNAL=1 setup_and_build
767                 ;;
769         #################### Building single components #############################
770                 'kernel')
771                 print_highlight " building only Kernel "
772                 #clean_kernel
773                 build_uimage
774                 ;;
775                 
776                 'kernel_modules')
777         print_highlight " building only Driver modules "
778                 build_uimage
779                 build_modules
780                 ;;
781                 'modules')
782         print_highlight " building only Driver modules "
783                 build_modules
784                 ;;
786                 'wpa_supplicant')
787         print_highlight " building only wpa_supplicant "
788                 build_wpa_supplicant      
789                 ;;
791                 'hostapd')
792         print_highlight " building only hostapd "
793                 build_hostapd
794                 ;;
796                 'crda')
797         print_highlight " building only CRDA "
798                 build_crda
799                 ;;
800         
801                 'libnl')
802                 print_highlight " building only libnl"
803                 build_libnl
804                 ;;
806                 'iw')
807                 print_highlight " building only iw"
808                 build_iw
809                 ;;
811                 'openssl')
812                 print_highlight " building only openssl"
813                 build_openssl
814                 ;;
816                 'scripts')
817                 print_highlight " Copying scripts "
818                 build_scripts_download
819                 ;;
820                 
821                 'utils')
822                 print_highlight " building only ti-utils "
823                 build_calibrator
824                 build_wlconf            
825                 ;;        
826                 'firmware')
827                 print_highlight " building only firmware"
828                 build_fw_download
829                 ;;
830         ############################################################
831         'get_tag')
832         get_tag
833         exit
834         ;;
835                 
836         'admin_tag')        
837                 admin_tag $2
838                 ;;
840         'check_updates')
841                 check_for_build_updates
842                 ;;
844         '')
845         print_highlight " building all (No clean & no source code update) "  
846                 #clean_outputs
847         NO_CLEAN=1 build_all
848                 ;;
850         *)
851         echo " "
852         echo "**** Unknown parameter - please see usage below **** "
853         usage
854         ;;
855         esac
856         
857         [[ -z $NO_BUILD ]] && build_outputs
858         [[ -n $INSTALL_NFS ]] && install_outputs
860 main $@