]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - wilink8-wlan/build-utilites.git/blob - build_wl18xx.sh
verify-config : Typo in flag name
[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             ] "
45     echo "                          patch_kernel             [ Apply provided kernel patches  ] "
46     echo "                          uim                      [ Clean & Build uim              ] "
47     echo "                          bt-firmware              [ Install Bluetooth init scripts ] "
48     exit 1
49 }
51 function assert_no_error()
52 {
53         if [ $? -ne 0 ]; then
54                 echo "****** ERROR $? $@*******"
55                 exit 1
56         fi
57         echo "****** $1 *******"
58 }
60 function repo_id()
61 {
62         i="0"
63         while [ $i -lt ${#repositories[@]} ]; do
64                 [ $1 == "${repositories[i]}" ] && echo $i
65                 i=$[$i + 3]
66         done
67 }
69 function repo_url()
70 {
71         echo "${repositories[`repo_id $1` + 1]}"
72 }
74 function repo_branch()
75 {
76         echo "${repositories[`repo_id $1` + 2]}"
77 }
79 function path()
80 {
81         i="0"
82         while [ $i -lt "${#paths[@]}" ]; do
83                 [ $1 == "${paths[i]}" ] && echo "${paths[i + 1]}"
84                 i=$[$i + 2]
85         done
86 }
88 function set_path()
89 {
90         i="0"    
91         while [ $i -lt "${#paths[@]}" ]; do
92                 [ $1 == "${paths[i]}" ] && paths[i+1]=$2    
93                 i=$[$i + 2]
94         done
95 }
97 function repo_path()
98 {
99         echo `path src`/$1
102 function cd_path()
104         cd `path $1`
107 function cd_repo()
109         cd `repo_path $1`
112 function cd_back()
114         cd - > /dev/null
117 function check_for_build_updates()
119         git fetch
120         count=`git status -uno | grep behind | wc -l`
121         if [ $count -ne 0 ]
122         then
123                 echo ""
124                 echo "*** Please note, there is an updated build script avilalable ***"
125                 echo "*** Use 'git pull' to get the latest update. ***" 
126                 echo ""
127                 sleep 5
128         fi
131 function read_kernel_version()
133         filename=$KERNEL_PATH/Makefile
135         if [ ! -f $filename ]
136         then
137             KERNEL_VERSION=0
138             KERNEL_PATCHLEVEL=0
139             KERNEL_SUBLEVEL=0
140             echo "No Makefile was found. Kernel version was set to default." 
141         else 
142             exec 6< $filename
143             read version <&6
144             read patchlevel <&6
145             read sublevel <&6
146             exec 6<&-
148             KERNEL_VERSION=$(echo $version|sed 's/[^0-9]//g')
149             KERNEL_PATCHLEVEL=$(echo $patchlevel|sed 's/[^0-9]//g')
150             KERNEL_SUBLEVEL=$(echo $sublevel|sed 's/[^0-9]//g')
151             echo "Makefile was found. Kernel version was set to $KERNEL_VERSION.$KERNEL_PATCHLEVEL.$KERNEL_SUBLEVEL." 
152         fi
153         [ $VERIFY_CONFIG ] && ./verify_kernel_config.sh $KERNEL_PATH/.config
156 #----------------------------------------------------------j
157 function setup_environment()
159     if [ ! -e setup-env ]
160     then
161         echo "No setup-env"
162         exit 1
163     fi
164     
165     #if a rootfs path is set - replace the default.
166     if [[ "$ROOTFS" != "DEFAULT" ]]
167     then            
168         echo " Changing ROOTFS path to $ROOTFS"
169         set_path filesystem $ROOTFS
170         [ ! -d $ROOTFS ] && echo "Error ROOTFS: $ROOTFS dir does not exist" && exit 1
171     fi   
172     #if no toolchain path is set - download it.
173     if [[ "$TOOLCHAIN_PATH" == "DEFAULT" ]]
174     then            
175         echo " Setting TOOLCHAIN_PATH path to default"
176         export TOOLCHAIN_PATH=`path toolchain`/arm/bin
177         DEFAULT_TOOLCHAIN=1
178     fi   
180     #if no kernel path is set - download it.
181     if [[ "$KERNEL_PATH" == "DEFAULT" ]]
182     then            
183         echo " Setting KERNEL_PATH path to default"
184         export KERNEL_PATH=`repo_path kernel`
185         DEFAULT_KERNEL=1
186     else 
187         echo " Using user defined kernel"                        
188         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
189     fi  
190     
191         export PROCESSORS_NUMBER=$(egrep '^processor' /proc/cpuinfo | wc -l)
192         export PKG_CONFIG_PATH=`path filesystem`/lib/pkgconfig
193         export INSTALL_PREFIX=`path filesystem`
194         export LIBNL_PATH=`repo_path libnl`     
195         export KLIB=`path filesystem`
196         export KLIB_BUILD=${KERNEL_PATH}
197         export GIT_TREE=`repo_path driver`
198         export PATH=$TOOLCHAIN_PATH:$PATH
199     
202 function setup_filesystem_skeleton()
204         mkdir -p `path filesystem`/usr/bin
205         mkdir -p `path filesystem`/etc
206         mkdir -p `path filesystem`/etc/init.d
207         mkdir -p `path filesystem`/etc/rcS.d
208         mkdir -p `path filesystem`/usr/lib/crda
209         mkdir -p `path filesystem`/lib/firmware/ti-connectivity
210         mkdir -p `path filesystem`/usr/share/wl18xx
211         mkdir -p `path filesystem`/usr/sbin/wlconf
212         mkdir -p `path filesystem`/usr/sbin/wlconf/official_inis
213         mkdir -p `path filesystem`/etc/wireless-regdb/pubkeys
216 function setup_directories()
218         i="0"
219         while [ $i -lt ${#paths[@]} ]; do
220                 mkdir -p ${paths[i + 1]}
221                 i=$[$i + 2]
222         done
223         setup_filesystem_skeleton
227 function setup_repositories()
229         i="0"
230         while [ $i -lt ${#repositories[@]} ]; do
231                 url=${repositories[$i + 1]}
232                 name=${repositories[$i]}
233         echo -e "${NORMAL}Cloning into: ${GREEN} $name ${NORMAL}"        
234         #Skip kernel clone if it was user defined 
235                 [ "$name" != "kernel" -o "$DEFAULT_KERNEL" ] && [ ! -d `repo_path $name` ] && git clone $url `repo_path $name`
236                 i=$[$i + 3]
237         done        
240 function setup_branches()
242         i="0"    
243         while [ $i -lt ${#repositories[@]} ]; do
244                 name=${repositories[$i]}
245                 url=${repositories[$i + 1]}
246         branch=${repositories[$i + 2]}   
247         checkout_type="branch"       
248         #for all the openlink repo. we use a tag if provided.               
249         [ "$name" == "kernel" ] && [ -z "$DEFAULT_KERNEL" ] && i=$[$i + 3] && continue
250         cd_repo $name   
251         echo -e "\n${NORMAL}Checking out branch ${GREEN}$branch  ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
252                 git checkout $branch        
253         git fetch origin
254         git fetch origin --tags  
255         if [[ "$url" == *git.ti.com* ]]
256         then            
257            [[ -n $RESET ]] && echo -e "${PURPLE}Reset to latest in repo ${GREEN}$name ${NORMAL} branch  ${GREEN}$branch ${NORMAL}"  && git reset --hard origin/$branch
258            [[ -n $USE_TAG ]] && git reset --hard $USE_TAG  && echo -e "${NORMAL}Reset to tag ${GREEN}$USE_TAG   ${NORMAL}in repo ${GREEN}$name ${NORMAL} "            
259         fi        
260                 cd_back
261                 i=$[$i + 3]
262         done
265 function setup_toolchain()
267         if [ ! -f `path downloads`/arm-toolchain.tar.bz2 ]; then
268         echo "Setting toolchain"
269                 wget ${toolchain[0]} -O `path downloads`/arm-toolchain.tar.bz2
270                 tar -xjf `path downloads`/arm-toolchain.tar.bz2 -C `path toolchain`
271                 mv `path toolchain`/* `path toolchain`/arm
272         fi
275 function build_intree()
277     cd_repo driver
278         export KERNEL_PATH=`repo_path driver`
279         read_kernel_version
280         [ $CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path driver`/.config
281         [ $CLEAN ] && make clean
282         [ $CLEAN ] && assert_no_error
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 driver`/arch/arm/boot/zImage `path tftp`/zImage
291         cp `repo_path driver`/arch/arm/boot/dts/am335x-*.dtb `path tftp`/
293         assert_no_error
294         cd_back
297 function rebuild_intree()
299     cd_repo driver
300         export KERNEL_PATH=`repo_path driver`
302         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=net/wireless/ modules
303         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=net/wireless/ modules_install
305         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=net/mac80211/ modules
306         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=net/mac80211/ modules_install
308         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=drivers/net/wireless/ti/ modules
309         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=drivers/net/wireless/ti/ modules_install
311         assert_no_error
312         cd_back
315 function build_uimage()
317     cd_repo kernel
318         [ -z $NO_CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path kernel`/.config
319         [ -z $NO_CLEAN ] && make clean
320         [ -z $NO_CLEAN ] && assert_no_error
322     if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
323     then
324         make -j${PROCESSORS_NUMBER} uImage
325         cp `repo_path kernel`/arch/arm/boot/uImage `path tftp`/uImage
326     else
327         if [ -z $NO_DTB ] 
328         then
329             make -j${PROCESSORS_NUMBER} zImage
330             make -j${PROCESSORS_NUMBER} am335x-evm.dtb
331             make -j${PROCESSORS_NUMBER} am335x-bone.dtb
332             make -j${PROCESSORS_NUMBER} am335x-boneblack.dtb
333             make -j${PROCESSORS_NUMBER} modules
334             INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} modules_install
335             cp `repo_path kernel`/arch/arm/boot/zImage `path tftp`/zImage
336             cp `repo_path kernel`/arch/arm/boot/dts/am335x-*.dtb `path tftp`/
337         else
338             LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage.am335x-evm 
339             cp `repo_path kernel`/arch/arm/boot/uImage.am335x-evm `path tftp`/uImage
340         fi
341     fi
342         assert_no_error
343         cd_back
346 function generate_compat()
348         cd_repo backports
349         python ./gentree.py --clean `repo_path driver` `path compat_wireless`
350         cd_back
353 function build_modules()
355         generate_compat
356         cd_repo compat_wireless
357         if [ -n "$KERNEL_VARIANT" ] && [ -d "$PATH__ROOT/patches/driver_patches/$KERNEL_VARIANT" ]; then
358                 for i in $PATH__ROOT/patches/driver_patches/$KERNEL_VARIANT/*.patch; do
359                         print_highlight "Applying driver patch: $i"
360                         patch -p1 < $i;
361                         assert_no_error
362                 done
363         fi
364         if [ -z $NO_CLEAN ]; then
365                 make clean
366         fi
367         make defconfig-wl18xx
368         make -j${PROCESSORS_NUMBER}
369         assert_no_error
370         #find . -name \*.ko -exec cp {} `path debugging`/ \;
371         find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
372     
373         make  modules_install
374         assert_no_error
375         cd_back
378 function build_openssl()
380         cd_repo openssl
381         [ -z $NO_CONFIG ] && ./Configure linux-generic32
382         [ -z $NO_CLEAN ] && make clean
383         [ -z $NO_CLEAN ] && assert_no_error
384         make
385         assert_no_error
386         make install_sw
387         assert_no_error
388         cd_back
392 function build_iw()
394         cd_repo iw
395         [ -z $NO_CLEAN ] && make clean
396         [ -z $NO_CLEAN ] && assert_no_error
397         CC=${CROSS_COMPILE}gcc LIBS+=" -lpthread -lm" make V=1
398         assert_no_error
399         DESTDIR=`path filesystem` make install
400         assert_no_error
401         cd_back
403 function build_libnl()
405         cd_repo libnl
406         [ -z $NO_CONFIG ] && ./autogen.sh
407         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
408         ([ -z $NO_CONFIG ] || [ -z $NO_CLEAN ]) && make clean
409         [ -z $NO_CLEAN ] && assert_no_error
410         make
411         assert_no_error
412         make install
413         assert_no_error
414         cd_back
417 function build_wpa_supplicant()
419         cd `repo_path hostap`/wpa_supplicant
420         [ -z $NO_CONFIG ] && cp android.config .config
421     [ -n "$SYSLOG_EN" ] && echo "Enable DEBUG_SYSLOG config" && sed -i "/#CONFIG_DEBUG_SYSLOG=y/ s/# *//" .config
422         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
423         assert_no_error
424         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
425         assert_no_error
426         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
427         assert_no_error
428         cd_back    
429     cp `repo_path scripts_download`/conf/*_supplicant.conf  `path filesystem`/etc/
432 function build_hostapd()
434     cd `repo_path hostap`/hostapd
435         [ -z $NO_CONFIG ] && cp android.config .config
436         [ -z $NO_UPNP ] && echo "Enable UPNP config" && sed -i "/#CONFIG_WPS_UPNP=y/ s/# *//" .config
437         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
438         assert_no_error
439         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
440         assert_no_error
441         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
442         assert_no_error
443         cd_back
444     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
447 function build_crda()
448 {       
449         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
450         cp `repo_path crda`/pubkeys/* `path filesystem`/etc/wireless-regdb/pubkeys/
451     cd_repo crda
452         
453         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
454         [ -z $NO_CLEAN ] && assert_no_error
455         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
456         assert_no_error
457         DESTDIR=`path filesystem` make install
458         assert_no_error
459         cd_back
462 function build_calibrator()
464         cd_repo ti_utils
465         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
466         [ -z $NO_CLEAN ] && assert_no_error
467         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
468         assert_no_error
469         NFSROOT=`path filesystem` make install
470         #assert_no_error
471         cp -f `repo_path ti_utils`/hw/firmware/wl1271-nvs.bin `path filesystem`/lib/firmware/ti-connectivity
472         cd_back
475 function build_wlconf()
477         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
478         cd `repo_path ti_utils`/wlconf
479         if [ -z $NO_CLEAN ]; then
480                 NFSROOT=`path filesystem` make clean
481                 assert_no_error
482                 for file_to_copy in $files_to_copy; do
483                         rm -f `path filesystem`/usr/sbin/wlconf/$file_to_copy
484                 done
485                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
486         fi
487         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
488         assert_no_error
490         # install
491         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
492         chmod 755 `path filesystem`/usr/sbin/wlconf
493         for file_to_copy in $files_to_copy; do
494                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
495                 echo "echoying files $file_to_copy"
496         done
497         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
498         cd_back
501 function build_fw_download()
503         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
506 function build_fw()
508         cd `repo_path firmware-build`/victoria/firmware
509         [ -z $NO_CLEAN ] && ./build.sh clean
510         ./build.sh
511         cp `repo_path firmware-build`/victoria/firmware/out/Firmware18xx/wl18xx-fw-4.bin `path filesystem`/lib/firmware/ti-connectivity
512         cp `repo_path firmware-build`/victoria/firmware/out/Firmware18xx/wl18xx-fw-4.bin `path outputs`
513         cd_back
517 function patch_kernel()
519         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
520         cd $KERNEL_PATH
521         echo "using kernel: $KERNEL_PATH"
522         if [ -d "$PATH__ROOT/patches/kernel_patches/$KERNEL_VARIANT" ]; then
523                 read -p "Branch name to use? (will be created if doesn't exist)" -e branchname
524                 if git show-ref --verify --quiet "refs/heads/$branchname"; then
525                         echo "Branch name $branchname already exists, trying to use it..."
526                         git checkout $branchname
527                 else
528                         echo "Creating branch $branchname and switching to it"
529                         git checkout -b $branchname
530                 fi
531                 assert_no_error
532                 for i in $PATH__ROOT/patches/kernel_patches/$KERNEL_VARIANT/*.patch; do
533                         git am $i;
534                         assert_no_error
535                 done
536         fi
537         assert_no_error
538         cd_back
541 function build_uim()
543         cd_repo uim
544         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
545         [ -z $NO_CLEAN ] && assert_no_error
546         make CC=${CROSS_COMPILE}gcc
547         assert_no_error
548         install -m 0755 uim `path filesystem`/usr/bin
549         install -m 0755 `repo_path uim`/scripts/uim-sysfs `path filesystem`/etc/init.d/
550         cd `path filesystem`/etc/rcS.d/
551         ln -sf  ../init.d/uim-sysfs S03uim-sysfs
552         assert_no_error
553         cd_back
556 function build_bt_firmware()
558         cd_repo bt-firmware
559         for i in `repo_path bt-firmware`/initscripts/*.bts; do
560                 echo "Installing bluetooth init script: $i"
561                 install -m 0755 $i `path filesystem`/lib/firmware/
562                 assert_no_error
563         done
566 function build_scripts_download()
568         cd_repo scripts_download
569         echo "Copying scripts"
570         scripts_download_path=`repo_path scripts_download`
571         for script_dir in `ls -d $scripts_download_path`/*/
572         do
573                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
574                 cp -rf ${script_dir}/* `path filesystem`/usr/share/wl18xx
575         done
576         cd_back
579 function clean_kernel()
581         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
582         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
583         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
586 function clean_outputs()
588     if [[ "$ROOTFS" == "DEFAULT" ]]
589     then
590         echo "Cleaning outputs"
591         rm -rf `path filesystem`/*
592         rm -f `path outputs`/*
593    fi
596 function build_outputs()
598         if [[ "$ROOTFS" == "DEFAULT" ]]
599     then  
600         echo "Building outputs"
601         cd_path filesystem
602         tar cpjf `path outputs`/${tar_filesystem[0]} .
603         cd_back
604                 
605                 # Copy kernel files only if default kernel is used(for now)
606                 if [[ $DEFAULT_KERNEL -eq 1 ]]
607                 then
608                         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
609                         then
610                                 cp `path tftp`/uImage `path outputs`/uImage
611                         else
612                                 if [ -z $NO_DTB ]
613                                 then
614                                         cp `path tftp`/zImage `path outputs`/zImage
615                                         cp `path tftp`/*.dtb `path outputs`/
616                                 else
617                                         cp `path tftp`/uImage `path outputs`/uImage
618                                 fi
619                         fi
620                 fi
621     fi
624 function install_outputs()
626     echo "Installing outputs"
627         tftp_path=${setup[2]}
628         sitara_left_path=${setup[5]}
629         sitara_right_path=${setup[8]}
631         cp `path outputs`/uImage ${tftp_path}
632         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
633         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
635         cd $sitara_left_path
636         tar xjf ${tar_filesystem[0]}
637         cd_back
639         cd $sitara_right_path
640         tar xjf ${tar_filesystem[0]}
641         cd_back
644 function set_files_to_verify()
646         files_to_verify=(
647         # skeleton path
648         # source path
649         # pattern in output of file
651         `path filesystem`/usr/local/sbin/wpa_supplicant
652         `repo_path hostap`/wpa_supplicant/wpa_supplicant
653         "ELF 32-bit LSB[ ]*executable, ARM"
655         `path filesystem`/usr/local/bin/hostapd
656         `repo_path hostap`/hostapd/hostapd
657         "ELF 32-bit LSB[ ]*executable, ARM"
659         `path filesystem`/sbin/crda
660         `repo_path crda`/crda
661         "ELF 32-bit LSB[ ]*executable, ARM"
663         `path filesystem`/usr/lib/crda/regulatory.bin
664         `repo_path wireless_regdb`/regulatory.bin
665         "CRDA wireless regulatory database file"
667         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
668         `repo_path fw_download`/wl18xx-fw-4.bin
669         "data"
671         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
672         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
673         "ELF 32-bit LSB[ ]*relocatable, ARM"
675         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
676         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
677         "ELF 32-bit LSB[ ]*relocatable, ARM"
679         #`path filesystem`/usr/bin/calibrator
680         #`repo_path ti_utils`/calibrator
681         #"ELF 32-bit LSB[ ]*executable, ARM"
683         `path filesystem`/usr/sbin/wlconf/wlconf
684         `repo_path ti_utils`/wlconf/wlconf
685         "ELF 32-bit LSB[ ]*executable, ARM"
686         )
689 function get_tag()
691        i="0"
692        while [ $i -lt ${#repositories[@]} ]; do
693                name=${repositories[$i]}
694                url=${repositories[$i + 1]}
695         branch=${repositories[$i + 2]}
696         checkout_type="branch"
697         cd_repo $name
698         if [[ "$url" == *git.ti.com* ]]
699         then
700                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
701                 git describe
702         fi
703                cd_back
704                i=$[$i + 3]
705        done
710 function admin_tag()
712         i="0"    
713         while [ $i -lt ${#repositories[@]} ]; do
714                 name=${repositories[$i]}
715                 url=${repositories[$i + 1]}
716         branch=${repositories[$i + 2]}   
717         checkout_type="branch"              
718         cd_repo $name    
719         if [[ "$url" == *git.ti.com* ]]
720         then                                   
721                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
722                 git show --summary        
723                 read -p "Do you want to tag this commit ?" yn
724                 case $yn in
725                     [Yy]* )  git tag -a $1 -m "$1" ;
726                              git push --tags ;;
727                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
728                     
729                     * ) echo "Please answer yes or no.";;
730                 esac
731            
732         fi        
733                 cd_back
734                 i=$[$i + 3]
735         done
739 function verify_skeleton()
741         echo "Verifying filesystem skeleton..."
743         set_files_to_verify
745         i="0"
746         while [ $i -lt ${#files_to_verify[@]} ]; do
747                 skeleton_path=${files_to_verify[i]}
748                 source_path=${files_to_verify[i + 1]}
749                 file_pattern=${files_to_verify[i + 2]}
750                 file $skeleton_path | grep "${file_pattern}" >/dev/null
751         if [ $? -eq 1 ]; then
752         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
753         #exit
754         fi
756                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
757                 md5_source=$(md5sum $source_path     | awk '{print $1}')
758                 if [ $md5_skeleton != $md5_source ]; then
759                         echo "ERROR: file mismatch"
760                         echo $skeleton_path
761                         exit 1
762                 fi
763                 i=$[$i + 3]
764         done
766         which regdbdump > /dev/null
767         if [ $? -eq 0 ]; then
768                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
769                 if [ $? -ne 0 ]; then
770                         echo "Please update your public key used to verify the DB"
771                 fi
772         fi
775 function verify_installs()
777     apps_to_verify=(
778      libtool     
779      python-m2crypto
780      bison
781      flex
782     )
784     i="0"
785         while [ $i -lt ${#apps_to_verify[@]} ]; do
786         if !( dpkg-query -s ${apps_to_verify[i]} 2>/dev/null | grep -q ^"Status: install ok installed"$ )then
787             echo  "${apps_to_verify[i]} is missing"
788             echo  "Please use 'sudo apt-get install ${apps_to_verify[i]}'"
789             read -p "Do you want to install it now [y/n] ? (requires sudo) " yn
790             case $yn in
791                 [Yy]* )  sudo apt-get install ${apps_to_verify[i]} ;;
792                 [Nn]* ) echo -e "${PURPLE}${apps_to_verify[i]} was not installed. leaving build. ${NORMAL} " ; exit 0 ;;
793                 * ) echo "Please answer y or n.";;
794             esac
795         fi
796         i=$[$i + 1]
797     done
800 function setup_workspace()
802         setup_directories       
803         setup_repositories
804         setup_branches
805     verify_installs
806     #Download toolchain only if it was not set
807     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
811 function build_all()
813     if [ -z $NO_EXTERNAL ] 
814     then        
815         [ $DEFAULT_KERNEL ] && build_uimage
816         build_openssl
817         build_libnl
818         build_crda
819     fi
820     
821     if [ -z $NO_TI ] 
822     then
823         build_modules
824         build_iw
825         build_wpa_supplicant
826         build_hostapd   
827         build_calibrator
828         build_wlconf
829         build_fw_download
830         build_scripts_download
831         build_uim
832         build_bt_firmware
833     fi
834     
835     [ -z $NO_VERIFY ] && verify_skeleton
838 function setup_and_build()
840     setup_workspace
841     build_all
844 function main()
846         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
847     setup_environment
848     setup_directories
849     read_kernel_version
850     
851         case "$1" in
852         'init')                
853         print_highlight " initializing workspace (w/o build) "       
854                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
855         NO_BUILD=1 
856         setup_workspace
857         read_kernel_version #####read kernel version again after init#####
858                 ;;
859               
860         'clean')        
861         print_highlight " cleaning & building all "       
862         clean_outputs
863         setup_directories
864         build_all        
865                 ;;
867         'update')
868         print_highlight " setting up workspace and building all "
869                 if [  -n "$2" ]
870         then
871             print_highlight "Using tag $2 "
872             USE_TAG=$2
873         else
874             print_highlight "Updating all to head (this will revert local changes)"
875             RESET=1
876         fi
877         #clean_kernel
878         clean_outputs
879         setup_workspace
880         read_kernel_version #####read kernel version again after update#####
881         build_all
882                 ;;
883         
884                 'openlink')
885         print_highlight " building all (w/o clean) "       
886                 NO_EXTERNAL=1 setup_and_build
887                 ;;
889         #################### Building single components #############################
890                 'kernel')
891                 print_highlight " building only Kernel "
892         #clean_kernel
893                 build_uimage
894                 ;;
896                 'intree')
897                 print_highlight " building modules intree"
898                 build_intree
899                 ;;
900                 
901                 'intree_m')
902                 print_highlight " Building JUST wireless modules intree"
903                 rebuild_intree
904                 ;;
906         'kernel_modules')
907         print_highlight " building kernel and driver modules"
908         build_uimage
909                 build_modules
910                 ;;
912                 'modules')
913         print_highlight " building only Driver modules "
914                 build_modules
915                 ;;
917                 'wpa_supplicant')
918         print_highlight " building only wpa_supplicant "
919                 build_wpa_supplicant      
920                 ;;
922                 'hostapd')
923         print_highlight " building only hostapd "
924                 build_hostapd
925                 ;;
927                 'crda')
928                 print_highlight " building only CRDA "
929                 build_crda
930                 ;;
931         
932                 'libnl')
933                 print_highlight " building only libnl"
934                 build_libnl
935                 ;;
937                 'iw')
938                 print_highlight " building only iw"
939                 build_iw
940                 ;;
942                 'openssl')
943                 print_highlight " building only openssl"
944                 build_openssl
945                 ;;
947                 'scripts')
948                 print_highlight " Copying scripts "
949                 build_scripts_download
950                 ;;
952                 'utils')
953                 print_highlight " building only ti-utils "
954                 build_calibrator
955                 build_wlconf            
956                 ;;
958                 'firmware')
959                 print_highlight " building only firmware"
960                 build_fw_download
961                 ;;
963                 'fw')
964                 print_highlight " building only firmware"
965                 build_fw
966                 ;;
968                 'patch_kernel')
969                 print_highlight " only patching kernel $2 without performing an actual build!"
970                 NO_BUILD=1
971                 patch_kernel
972                 ;;
974                 'uim')
975                 print_highlight " building only uim "
976                 build_uim
977                 ;;
979                 'bt-firmware')
980                 print_highlight " Only installing bluetooth init scripts "
981                 build_bt_firmware
982                 ;;
983         ############################################################
984         'get_tag')
985         get_tag
986         exit
987         ;;
988                 
989         'admin_tag')        
990                 admin_tag $2
991                 ;;
993         'check_updates')
994                 check_for_build_updates
995                 ;;
997         '')
998         print_highlight " building all (No clean & no source code update) "  
999                 #clean_outputs
1000         NO_CLEAN=1 build_all
1001                 ;;
1003         *)
1004         echo " "
1005         echo "**** Unknown parameter - please see usage below **** "
1006         usage
1007         ;;
1008         esac
1009         
1010         [[ -z $NO_BUILD ]] && build_outputs
1011         [[ -n $INSTALL_NFS ]] && install_outputs
1012         echo "Wifi Package Build Successful"
1014 main $@