cd221807c9b7a88cba466375454abec5375b0f84
[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 #----------------------------------------------------------j
113 function setup_environment()
115     if [ ! -e setup-env ]
116     then
117         echo "No setup-env"
118         exit 1
119     fi
120     
121     #if a rootfs path is set - replace the default.
122     if [[ "$ROOTFS" != "DEFAULT" ]]
123     then            
124         echo " Changing ROOTFS path to $ROOTFS"
125         set_path filesystem $ROOTFS
126         [ ! -d $ROOTFS ] && echo "Error ROOTFS: $ROOTFS dir does not exist" && exit 1
127     fi   
128     echo "!!!!!!!!!!!!!   `path filesystem`  "
129     #if no toolchain path is set - download it.
130     if [[ "$TOOLCHAIN_PATH" == "DEFAULT" ]]
131     then            
132         echo " Setting TOOLCHAIN_PATH path to default"
133         export TOOLCHAIN_PATH=`path toolchain`/arm/bin
134         DEFAULT_TOOLCHAIN=1
135     fi   
137     #if no kernel path is set - download it.
138     if [[ "$KERNEL_PATH" == "DEFAULT" ]]
139     then            
140         echo " Setting KERNEL_PATH path to default"
141         export KERNEL_PATH=`repo_path kernel`
142         DEFAULT_KERNEL=1
143     else 
144         echo " Using user defined kernel"                        
145         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
146     fi  
147     
148         export PROCESSORS_NUMBER=$(egrep '^processor' /proc/cpuinfo | wc -l)
149         export PKG_CONFIG_PATH=`path filesystem`/lib/pkgconfig
150         export INSTALL_PREFIX=`path filesystem`
151         export LIBNL_PATH=`repo_path libnl`     
152         export KLIB=${KERNEL_PATH}
153         export KLIB_BUILD=${KERNEL_PATH}
154     export PATH=$TOOLCHAIN_PATH:$PATH
155     
158 function setup_filesystem_skeleton()
160         mkdir -p `path filesystem`/usr/bin
161         mkdir -p `path filesystem`/etc
162         mkdir -p `path filesystem`/usr/lib/crda
163         mkdir -p `path filesystem`/lib/firmware/ti-connectivity
164         mkdir -p `path filesystem`/usr/share/wl18xx
165         mkdir -p `path filesystem`/usr/sbin/wlconf
166         mkdir -p `path filesystem`/usr/sbin/wlconf/official_inis
167         mkdir -p `path filesystem`/etc/wireless-regdb/pubkeys
170 function setup_directories()
172         i="0"
173         while [ $i -lt ${#paths[@]} ]; do
174                 mkdir -p ${paths[i + 1]}
175                 i=$[$i + 2]
176         done
177         setup_filesystem_skeleton
181 function setup_repositories()
183         i="0"
184         while [ $i -lt ${#repositories[@]} ]; do
185                 url=${repositories[$i + 1]}
186                 name=${repositories[$i]}
187         echo -e "${NORMAL}Cloning into: ${GREEN} $name ${NORMAL}"        
188         #Skip kernel clone if it was user defined 
189                 [ "$name" != "kernel" -o "$DEFAULT_KERNEL" ] && [ ! -d `repo_path $name` ] && git clone $url `repo_path $name`
190                 i=$[$i + 3]
191         done        
194 function setup_branches()
196         i="0"    
197         while [ $i -lt ${#repositories[@]} ]; do
198                 name=${repositories[$i]}
199                 url=${repositories[$i + 1]}
200         branch=${repositories[$i + 2]}   
201         checkout_type="branch"       
202         #for all the openlink repo. we use a tag if provided.
203         cd_repo $name    
204         echo -e "\n${NORMAL}Checking out branch ${GREEN}$branch  ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
205                 git checkout $branch        
206         git fetch origin
207         git fetch origin --tags  
208         if [[ "$url" == *git.ti.com* ]]
209         then            
210            [[ -n $RESET ]] && echo -e "${PURPLE}Reset to latest in repo ${GREEN}$name ${NORMAL} branch  ${GREEN}$branch ${NORMAL}"  && git reset --hard origin/$branch
211            [[ -n $USE_TAG ]] && git reset --hard $USE_TAG  && echo -e "${NORMAL}Reset to tag ${GREEN}$USE_TAG   ${NORMAL}in repo ${GREEN}$name ${NORMAL} "            
212         fi        
213                 cd_back
214                 i=$[$i + 3]
215         done
218 function setup_toolchain()
220         if [ ! -f `path downloads`/arm-toolchain.tar.bz2 ]; then
221         echo "Setting toolchain"
222                 wget ${toolchain[0]} -O `path downloads`/arm-toolchain.tar.bz2
223                 tar -xjf `path downloads`/arm-toolchain.tar.bz2 -C `path toolchain`
224                 mv `path toolchain`/* `path toolchain`/arm
225         fi
228 function build_uimage()
230         cd_repo kernel
231         [ -z $NO_CONFIG ] && cp `path configuration`/kernel.config `repo_path kernel`/.config
232         [ -z $NO_CLEAN ] && make clean
233         [ -z $NO_CLEAN ] && assert_no_error
234         make -j${PROCESSORS_NUMBER} uImage
235         assert_no_error
236         #LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage-dtb.am335x-evm
237         assert_no_error
238         cp `repo_path kernel`/arch/arm/boot/uImage `path tftp`/uImage
239         cd_back
242 function generate_compat()
244         cd_repo backports
245         python ./gentree.py --clean `repo_path driver` `path compat_wireless`
246         cd_back
249 function build_modules()
251     generate_compat
252         cd_repo compat_wireless
253         if [ -z $NO_CLEAN ]; then
254                 make clean
255         fi
256         make defconfig-wl18xx
257     make -j${PROCESSORS_NUMBER} 
258         assert_no_error
259         find . -name \*.ko -exec cp {} `path debugging`/ \;
260         find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
261     
262         make -C ${KERNEL_PATH} M=`pwd` "INSTALL_MOD_PATH=`path filesystem`" modules_install
263         assert_no_error
264         #chmod -R 0777 ${PATH__FILESYSTEM}/lib/modules/
265         cd_back
268 function build_openssl()
270         cd_repo openssl
271         [ -z $NO_CONFIG ] && ./Configure s/compiler:gcc
272         [ -z $NO_CLEAN ] && make clean
273         [ -z $NO_CLEAN ] && assert_no_error
274         make
275         assert_no_error
276         make install_sw
277         assert_no_error
278         cd_back
281 function build_libnl()
283         cd_repo libnl
284         [ -z $NO_CONFIG ] && ./autogen.sh
285         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
286         [ -z $NO_CLEAN ] && make clean
287         [ -z $NO_CLEAN ] && assert_no_error
288         make
289         assert_no_error
290         make install
291         assert_no_error
292         cd_back
295 function build_wpa_supplicant()
297         cd `repo_path hostap`/wpa_supplicant
298         [ -z $NO_CONFIG ] && cp android.config .config
299         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
300         assert_no_error
301         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
302         assert_no_error
303         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
304         assert_no_error
305         cd_back    
306     cp `repo_path scripts_download`/conf/*_supplicant.conf  `path filesystem`/etc/
309 function build_hostapd()
310 {              
311     cd `repo_path hostap`/hostapd
312         [ -z $NO_CONFIG ] && cp android.config .config
313         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
314         assert_no_error
315         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
316         assert_no_error
317         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
318         assert_no_error
319         cd_back
320     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
323 function build_crda()
324 {       
325         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
326         cp `repo_path wireless_regdb`/linville.key.pub.pem `path filesystem`/etc/wireless-regdb/pubkeys/
327     cd_repo crda
328         
329         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
330         [ -z $NO_CLEAN ] && assert_no_error
331         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
332         assert_no_error
333         DESTDIR=`path filesystem` make install
334         assert_no_error
335         cd_back
338 function build_calibrator()
340         cd_repo ti_utils
341         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
342         [ -z $NO_CLEAN ] && assert_no_error
343         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
344         assert_no_error
345         NFSROOT=`path filesystem` make install
346         #assert_no_error
347         cd_back
350 function build_wlconf()
352         files_to_copy="dictionary.txt struct.bin wl18xx-conf-default.bin README example.conf example.ini"
353         cd `repo_path ti_utils`/wlconf
354         if [ -z $NO_CLEAN ]; then
355                 NFSROOT=`path filesystem` make clean
356                 assert_no_error
357                 for file_to_copy in $files_to_copy; do
358                         rm -f `path filesstem`/usr/sbin/wlconf/$file_to_copy
359                 done
360                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
361         fi
362         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
363         assert_no_error
365         # install
366         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
367         chmod 755 `path filesystem`/usr/sbin/wlconf
368         for file_to_copy in $files_to_copy; do
369                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
370         done
371         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
372         cd_back
375 function build_fw_download()
377         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
381 function build_scripts_download()
383         cd_repo scripts_download
384         echo "Copying scripts"
385         scripts_download_path=`repo_path scripts_download`
386         for script_dir in `ls $scripts_download_path`
387         do
388                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
389                 cp -rf `repo_path scripts_download`/${script_dir}/* `path filesystem`/usr/share/wl18xx
390         done
391         cd_back
394 function clean_outputs()
396         echo "Cleaning outputs"    
397     rm -rf `path filesystem`/*
398     rm -f `path outputs`/${tar_filesystem[0]}
399         rm -f `path outputs`/uImage
400         
403 function build_outputs()
405         if [[ "$ROOTFS" == "DEFAULT" ]]
406     then  
407         echo "Building outputs"    
408         cd_path filesystem
409         tar cpjf `path outputs`/${tar_filesystem[0]} .
410         cd_back
411         cp `path tftp`/uImage `path outputs`/uImage
412     fi
415 function install_outputs()
417     echo "Installing outputs"
418         tftp_path=${setup[2]}
419         sitara_left_path=${setup[5]}
420         sitara_right_path=${setup[8]}
422         cp `path outputs`/uImage ${tftp_path}
423         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
424         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
426         cd $sitara_left_path
427         tar xjf ${tar_filesystem[0]}
428         cd_back
430         cd $sitara_right_path
431         tar xjf ${tar_filesystem[0]}
432         cd_back
435 files_to_verify=(
436 # skeleton path
437 # source path
438 # pattern in output of file
440 `path filesystem`/usr/local/sbin/wpa_supplicant
441 `repo_path hostap`/wpa_supplicant/wpa_supplicant
442 "ELF 32-bit LSB executable, ARM"
444 `path filesystem`/usr/local/bin/hostapd
445 `repo_path hostap`/hostapd/hostapd
446 "ELF 32-bit LSB executable, ARM"
448 `path filesystem`/sbin/crda
449 `repo_path crda`/crda
450 "ELF 32-bit LSB executable, ARM"
452 `path filesystem`/usr/lib/crda/regulatory.bin
453 `repo_path wireless_regdb`/regulatory.bin
454 "CRDA wireless regulatory database file"
456 `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
457 `repo_path fw_download`/wl18xx-fw-4.bin
458 "data"
460 `path filesystem`/lib/modules/3.2.*/extra/drivers/net/wireless/ti/wl18xx/wl18xx.ko
461 `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
462 "ELF 32-bit LSB relocatable, ARM"
464 `path filesystem`/lib/modules/3.2.*/extra/drivers/net/wireless/ti/wlcore/wlcore.ko
465 `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
466 "ELF 32-bit LSB relocatable, ARM"
468 #`path filesystem`/usr/bin/calibrator
469 #`repo_path ti_utils`/calibrator
470 #"ELF 32-bit LSB executable, ARM"
472 `path filesystem`/usr/sbin/wlconf/wlconf
473 `repo_path ti_utils`/wlconf/wlconf
474 "ELF 32-bit LSB executable, ARM"
477 function get_tag()
479        i="0"
480        while [ $i -lt ${#repositories[@]} ]; do
481                name=${repositories[$i]}
482                url=${repositories[$i + 1]}
483         branch=${repositories[$i + 2]}
484         checkout_type="branch"
485         cd_repo $name
486         if [[ "$url" == *git.ti.com* ]]
487         then
488                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
489                 git describe
490         fi
491                cd_back
492                i=$[$i + 3]
493        done
498 function admin_tag()
500         i="0"    
501         while [ $i -lt ${#repositories[@]} ]; do
502                 name=${repositories[$i]}
503                 url=${repositories[$i + 1]}
504         branch=${repositories[$i + 2]}   
505         checkout_type="branch"              
506         cd_repo $name    
507         if [[ "$url" == *git.ti.com* ]]
508         then                                   
509                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
510                 git show --summary        
511                 read -p "Do you want to tag this commit ?" yn
512                 case $yn in
513                     [Yy]* )  git tag -a $1 -m "$1" ;
514                              git push --tags ;;
515                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
516                     
517                     * ) echo "Please answer yes or no.";;
518                 esac
519            
520         fi        
521                 cd_back
522                 i=$[$i + 3]
523         done
527 function verify_skeleton()
529         echo "Verifying filesystem skeleton..."
531         i="0"
532         while [ $i -lt ${#files_to_verify[@]} ]; do
533                 skeleton_path=${files_to_verify[i]}
534                 source_path=${files_to_verify[i + 1]}
535                 file_pattern=${files_to_verify[i + 2]}
536                 file $skeleton_path | grep "${file_pattern}" >/dev/null
537         if [ $? -eq 1 ]; then
538         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
539         #exit
540         fi
542                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
543                 md5_source=$(md5sum $source_path     | awk '{print $1}')
544                 if [ $md5_skeleton != $md5_source ]; then
545                         echo "ERROR: file mismatch"
546                         echo $skeleton_path
547                         exit 1
548                 fi
549                 i=$[$i + 3]
550         done
552         which regdbdump > /dev/null
553         if [ $? -eq 0 ]; then
554                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
555                 assert_no_error
556         fi
559 function setup_workspace()
561         setup_directories       
562         setup_repositories
563         setup_branches
564     #Download toolchain only if it was not set
565     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
567     
571 function build_all()
573     if [ -z $NO_EXTERNAL ] 
574     then        
575         [ $DEFAULT_KERNEL ] && build_uimage
576         build_openssl
577         build_libnl
578         build_crda
579     fi
580     
581     if [ -z $NO_TI ] 
582     then
583         build_modules
584         build_wpa_supplicant
585         build_hostapd   
586         build_calibrator
587         build_wlconf
588         build_fw_download
589         build_scripts_download
590     fi
591     
592     [ -z $NO_VERIFY ] && verify_skeleton
593     
596 function setup_and_build()
598     setup_workspace
599     build_all
602 function main()
604         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
606     setup_environment
607     setup_directories
608     
609      
610     
611         case "$1" in
612                 'update')                
613         print_highlight " setting up workspace and building all "       
614                 if [  -n "$2" ]
615         then
616             print_highlight "Using tag $2 " 
617             USE_TAG=$2
618         else
619             print_highlight "Updating all to head (this will revert local changes)" 
620             RESET=1    
621         fi        
622         setup_workspace
623         build_all
624                 ;;
625         
626         'init')                
627         print_highlight " initializing workspace (w/o build) "       
628                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
629         NO_BUILD=1 
630         setup_workspace
631                 ;;
632         
633         
634         'clean')        
635         print_highlight " cleaning & building all "       
636                 #clean_outputs
637         setup_directories
638         build_all        
639                 ;;
641                 'rebuild')
642         print_highlight " building all (w/o clean) "       
643                 NO_CLEAN=1 build_all
644                 ;;
645         
646                 'openlink')
647         print_highlight " building all (w/o clean) "       
648                 NO_EXTERNAL=1 setup_and_build
649                 ;;
650         #################### Building single components #############################
651                 'kernel')
652                 print_highlight " building only Kernel "
653                 build_uimage
654                 ;;
656                 'modules')
657         print_highlight " building only Driver modules "
658                 build_modules
659                 ;;
661                 'wpa_supplicant')
662         print_highlight " building only wpa_supplicant "
663                 build_wpa_supplicant
664         
665                 ;;
667                 'hostapd')
668         print_highlight " building only hostapd "
669                 build_hostapd
670                 ;;
672                 'crda')
673         print_highlight " building only CRDA "
674                 build_crda
675                 ;;
676         
677         'scripts')
678         print_highlight " Copying scripts "
679                 build_scripts_download
680                 ;;
681         'utils')
682         print_highlight " building only ti-utils "
683         build_calibrator
684         build_wlconf            
685                 ;;        
686         ############################################################
687         'get_tag')
688         get_tag
689         exit
690         ;;
691                 
692         'admin_tag')        
693                 admin_tag $2
694                 ;;
695         
696         *)
697         print_highlight " building all (No clean & no source code update) "  
698                 #clean_outputs
699         NO_CLEAN=1 build_all
700                 ;;
701         esac
702         
703         [[ -z $NO_BUILD ]] && build_outputs
704         [[ -n $INSTALL_NFS ]] && install_outputs
706 main $@