]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - wilink8-wlan/build-utilites.git/blob - build_wl18xx.sh
Initial commit of build-utilities
[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         echo "Building outputs"    
406         cd_path filesystem
407         tar cpjf `path outputs`/${tar_filesystem[0]} .
408         cd_back
409         cp `path tftp`/uImage `path outputs`/uImage
412 function install_outputs()
414     echo "Installing outputs"
415         tftp_path=${setup[2]}
416         sitara_left_path=${setup[5]}
417         sitara_right_path=${setup[8]}
419         cp `path outputs`/uImage ${tftp_path}
420         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
421         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
423         cd $sitara_left_path
424         tar xjf ${tar_filesystem[0]}
425         cd_back
427         cd $sitara_right_path
428         tar xjf ${tar_filesystem[0]}
429         cd_back
432 files_to_verify=(
433 # skeleton path
434 # source path
435 # pattern in output of file
437 `path filesystem`/usr/local/sbin/wpa_supplicant
438 `repo_path hostap`/wpa_supplicant/wpa_supplicant
439 "ELF 32-bit LSB executable, ARM"
441 `path filesystem`/usr/local/bin/hostapd
442 `repo_path hostap`/hostapd/hostapd
443 "ELF 32-bit LSB executable, ARM"
445 `path filesystem`/sbin/crda
446 `repo_path crda`/crda
447 "ELF 32-bit LSB executable, ARM"
449 `path filesystem`/usr/lib/crda/regulatory.bin
450 `repo_path wireless_regdb`/regulatory.bin
451 "CRDA wireless regulatory database file"
453 `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
454 `repo_path fw_download`/wl18xx-fw-4.bin
455 "data"
457 `path filesystem`/lib/modules/3.2.*/extra/drivers/net/wireless/ti/wl18xx/wl18xx.ko
458 `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
459 "ELF 32-bit LSB relocatable, ARM"
461 `path filesystem`/lib/modules/3.2.*/extra/drivers/net/wireless/ti/wlcore/wlcore.ko
462 `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
463 "ELF 32-bit LSB relocatable, ARM"
465 #`path filesystem`/usr/bin/calibrator
466 #`repo_path ti_utils`/calibrator
467 #"ELF 32-bit LSB executable, ARM"
469 `path filesystem`/usr/sbin/wlconf/wlconf
470 `repo_path ti_utils`/wlconf/wlconf
471 "ELF 32-bit LSB executable, ARM"
474 function get_tag()
476        i="0"
477        while [ $i -lt ${#repositories[@]} ]; do
478                name=${repositories[$i]}
479                url=${repositories[$i + 1]}
480         branch=${repositories[$i + 2]}
481         checkout_type="branch"
482         cd_repo $name
483         if [[ "$url" == *git.ti.com* ]]
484         then
485                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
486                 git describe
487         fi
488                cd_back
489                i=$[$i + 3]
490        done
495 function admin_tag()
497         i="0"    
498         while [ $i -lt ${#repositories[@]} ]; do
499                 name=${repositories[$i]}
500                 url=${repositories[$i + 1]}
501         branch=${repositories[$i + 2]}   
502         checkout_type="branch"              
503         cd_repo $name    
504         if [[ "$url" == *git.ti.com* ]]
505         then                                   
506                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
507                 git show --summary        
508                 read -p "Do you want to tag this commit ?" yn
509                 case $yn in
510                     [Yy]* )  git tag -a $1 -m "$1" ;
511                              git push --tags ;;
512                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
513                     
514                     * ) echo "Please answer yes or no.";;
515                 esac
516            
517         fi        
518                 cd_back
519                 i=$[$i + 3]
520         done
524 function verify_skeleton()
526         echo "Verifying filesystem skeleton..."
528         i="0"
529         while [ $i -lt ${#files_to_verify[@]} ]; do
530                 skeleton_path=${files_to_verify[i]}
531                 source_path=${files_to_verify[i + 1]}
532                 file_pattern=${files_to_verify[i + 2]}
533                 file $skeleton_path | grep "${file_pattern}" >/dev/null
534         if [ $? -eq 1 ]; then
535         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
536         #exit
537         fi
539                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
540                 md5_source=$(md5sum $source_path     | awk '{print $1}')
541                 if [ $md5_skeleton != $md5_source ]; then
542                         echo "ERROR: file mismatch"
543                         echo $skeleton_path
544                         exit 1
545                 fi
546                 i=$[$i + 3]
547         done
549         which regdbdump > /dev/null
550         if [ $? -eq 0 ]; then
551                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
552                 assert_no_error
553         fi
556 function setup_workspace()
558         setup_directories       
559         setup_repositories
560         setup_branches
561     #Download toolchain only if it was not set
562     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
564     
568 function build_all()
570     if [ -z $NO_EXTERNAL ] 
571     then        
572         [ $DEFAULT_KERNEL ] && build_uimage
573         build_openssl
574         build_libnl
575         build_crda
576     fi
577     
578     if [ -z $NO_TI ] 
579     then
580         build_modules
581         build_wpa_supplicant
582         build_hostapd   
583         build_calibrator
584         build_wlconf
585         build_fw_download
586         build_scripts_download
587     fi
588     
589     [ -z $NO_VERIFY ] && verify_skeleton
590     
593 function setup_and_build()
595     setup_workspace
596     build_all
599 function main()
601         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
603     setup_environment
604     setup_directories
605     
606      
607     
608         case "$1" in
609                 'update')                
610         print_highlight " setting up workspace and building all "       
611                 if [  -n "$2" ]
612         then
613             print_highlight "Using tag $2 " 
614             USE_TAG=$2
615         else
616             print_highlight "Updating all to head (this will revert local changes)" 
617             RESET=1    
618         fi        
619         setup_workspace
620         build_all
621                 ;;
622         
623         'init')                
624         print_highlight " initializing workspace (w/o build) "       
625                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
626         NO_BUILD=1 
627         setup_workspace
628                 ;;
629         
630         
631         'clean')        
632         print_highlight " cleaning & building all "       
633                 clean_outputs
634         setup_directories
635         build_all        
636                 ;;
638                 'rebuild')
639         print_highlight " building all (w/o clean) "       
640                 NO_CLEAN=1 build_all
641                 ;;
642         
643                 'openlink')
644         print_highlight " building all (w/o clean) "       
645                 NO_EXTERNAL=1 setup_and_build
646                 ;;
647         #################### Building single components #############################
648                 'kernel')
649                 print_highlight " building only Kernel "
650                 build_uimage
651                 ;;
653                 'modules')
654         print_highlight " building only Driver modules "
655                 build_modules
656                 ;;
658                 'wpa_supplicant')
659         print_highlight " building only wpa_supplicant "
660                 build_wpa_supplicant
661         
662                 ;;
664                 'hostapd')
665         print_highlight " building only hostapd "
666                 build_hostapd
667                 ;;
669                 'crda')
670         print_highlight " building only CRDA "
671                 build_crda
672                 ;;
673         
674         'scripts')
675         print_highlight " Copying scripts "
676                 build_scripts_download
677                 ;;
678         'utils')
679         print_highlight " building only ti-utils "
680         build_calibrator
681         build_wlconf            
682                 ;;        
683         ############################################################
684         'get_tag')
685         get_tag
686         exit
687         ;;
688                 
689         'admin_tag')        
690                 admin_tag $2
691                 ;;
692         
693         *)
694         print_highlight " building all (No clean & no source code update) "  
695                 #clean_outputs
696         NO_CLEAN=1 build_all
697                 ;;
698         esac
699         
700         [[ -z $NO_BUILD ]] && build_outputs
701         [[ -n $INSTALL_NFS ]] && install_outputs
703 main $@