samad52-xplained: add wilink8 wlan support for k4.1
[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 "                         all_intree               [ Build driver and kernel intree ] " 
33     echo "                          check_updates            [ Check for build script updates ] "
34     echo ""
35     echo "Building specific component :"
36     echo "                          hostapd                  [ Clean & Build hostapd          ] "
37     echo "                          wpa_supplicant           [ Clean & Build wpa_supplicant   ] "
38     echo "                          modules                  [ Clean & Build driver modules   ] "
39     echo "                          firmware                 [ Install firmware file          ] "
40     echo "                          scripts                  [ Install scripts                ] "
41     echo "                          utils                    [ Clean & Build scripts          ] "
42     echo "                          iw                       [ Clean & Build iw               ] "
43     echo "                          openssl                  [ Clean & Build openssll         ] "
44     echo "                          libnl                    [ Clean & Build libnl            ] "
45     echo "                          crda                     [ Clean & Build crda             ] "
46     echo "                          patch_kernel             [ Apply provided kernel patches  ] "
47     echo "                          uim                      [ Clean & Build uim              ] "
48     echo "                          bt-firmware              [ Install Bluetooth init scripts ] "
49     exit 1
50 }
52 function assert_no_error()
53 {
54         if [ $? -ne 0 ]; then
55                 echo "****** ERROR $? $@*******"
56                 exit 1
57         fi
58         echo "****** $1 *******"
59 }
61 function repo_id()
62 {
63         i="0"
64         while [ $i -lt ${#repositories[@]} ]; do
65                 [ $1 == "${repositories[i]}" ] && echo $i
66                 i=$[$i + 3]
67         done
68 }
70 function repo_url()
71 {
72         echo "${repositories[`repo_id $1` + 1]}"
73 }
75 function repo_branch()
76 {
77         echo "${repositories[`repo_id $1` + 2]}"
78 }
80 function path()
81 {
82         i="0"
83         while [ $i -lt "${#paths[@]}" ]; do
84                 [ $1 == "${paths[i]}" ] && echo "${paths[i + 1]}"
85                 i=$[$i + 2]
86         done
87 }
89 function set_path()
90 {
91         i="0"    
92         while [ $i -lt "${#paths[@]}" ]; do
93                 [ $1 == "${paths[i]}" ] && paths[i+1]=$2    
94                 i=$[$i + 2]
95         done
96 }
98 function repo_path()
99 {
100         echo `path src`/$1
103 function cd_path()
105         cd `path $1`
108 function cd_repo()
110         cd `repo_path $1`
113 function cd_back()
115         cd - > /dev/null
118 function check_for_build_updates()
120         git fetch
121         count=`git status -uno | grep behind | wc -l`
122         if [ $count -ne 0 ]
123         then
124                 echo ""
125                 echo "*** Please note, there is an updated build script avilalable ***"
126                 echo "*** Use 'git pull' to get the latest update. ***" 
127                 echo ""
128                 sleep 5
129         fi
132 function read_kernel_version()
134         filename=$KERNEL_PATH/Makefile
136         if [ ! -f $filename ]
137         then
138             KERNEL_VERSION=0
139             KERNEL_PATCHLEVEL=0
140             KERNEL_SUBLEVEL=0
141             echo "No Makefile was found. Kernel version was set to default." 
142         else 
143             exec 6< $filename
144             read version <&6
145             read patchlevel <&6
146             read sublevel <&6
147             exec 6<&-
149             KERNEL_VERSION=$(echo $version|sed 's/[^0-9]//g')
150             KERNEL_PATCHLEVEL=$(echo $patchlevel|sed 's/[^0-9]//g')
151             KERNEL_SUBLEVEL=$(echo $sublevel|sed 's/[^0-9]//g')
152             echo "Makefile was found. Kernel version was set to $KERNEL_VERSION.$KERNEL_PATCHLEVEL.$KERNEL_SUBLEVEL." 
153         fi
154         [ $VERIFY_CONFIG ] && ./verify_kernel_config.sh $KERNEL_PATH/.config
157 #----------------------------------------------------------j
158 function setup_environment()
160     if [ ! -e setup-env ]
161     then
162         echo "No setup-env"
163         exit 1
164     fi
165     
166     #if a rootfs path is set - replace the default.
167     if [[ "$ROOTFS" != "DEFAULT" ]]
168     then            
169         echo " Changing ROOTFS path to $ROOTFS"
170         set_path filesystem $ROOTFS
171         [ ! -d $ROOTFS ] && echo "Error ROOTFS: $ROOTFS dir does not exist" && exit 1
172     fi   
173     #if no toolchain path is set - download it.
174     if [[ "$TOOLCHAIN_PATH" == "DEFAULT" ]]
175     then            
176         echo " Setting TOOLCHAIN_PATH path to default"
177         export TOOLCHAIN_PATH=`path toolchain`/arm/bin
178         DEFAULT_TOOLCHAIN=1
179     fi   
181     #if no kernel path is set - download it.
182     if [[ "$KERNEL_PATH" == "DEFAULT" ]]
183     then            
184         echo " Setting KERNEL_PATH path to default"
185         export KERNEL_PATH=`repo_path kernel`
186         DEFAULT_KERNEL=1
187     else 
188         echo " Using user defined kernel"                        
189         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
190     fi  
191     
192         export PROCESSORS_NUMBER=$(egrep '^processor' /proc/cpuinfo | wc -l)
193         export PKG_CONFIG_PATH=`path filesystem`/lib/pkgconfig
194         export INSTALL_PREFIX=`path filesystem`
195         export LIBNL_PATH=`repo_path libnl`     
196         export KLIB=`path filesystem`
197         export KLIB_BUILD=${KERNEL_PATH}
198         export GIT_TREE=`repo_path driver`
199         export PATH=$TOOLCHAIN_PATH:$PATH
200     
203 function setup_filesystem_skeleton()
205         mkdir -p `path filesystem`/usr/bin
206         mkdir -p `path filesystem`/etc
207         mkdir -p `path filesystem`/etc/init.d
208         mkdir -p `path filesystem`/etc/rcS.d
209         mkdir -p `path filesystem`/usr/lib/crda
210         mkdir -p `path filesystem`/lib/firmware/ti-connectivity
211         mkdir -p `path filesystem`/usr/share/wl18xx
212         mkdir -p `path filesystem`/usr/sbin/wlconf
213         mkdir -p `path filesystem`/usr/sbin/wlconf/official_inis
214         mkdir -p `path filesystem`/etc/wireless-regdb/pubkeys
217 function setup_directories()
219         i="0"
220         while [ $i -lt ${#paths[@]} ]; do
221                 mkdir -p ${paths[i + 1]}
222                 i=$[$i + 2]
223         done
224         setup_filesystem_skeleton
228 function setup_repositories()
230         i="0"
231         while [ $i -lt ${#repositories[@]} ]; do
232                 url=${repositories[$i + 1]}
233                 name=${repositories[$i]}
234         echo -e "${NORMAL}Cloning into: ${GREEN} $name ${NORMAL}"        
235         #Skip kernel clone if it was user defined 
236                 [ "$name" != "kernel" -o "$DEFAULT_KERNEL" ] && [ ! -d `repo_path $name` ] && git clone $url `repo_path $name`
237                 i=$[$i + 3]
238         done        
241 function setup_branches()
243         i="0"    
244         while [ $i -lt ${#repositories[@]} ]; do
245                 name=${repositories[$i]}
246                 url=${repositories[$i + 1]}
247         branch=${repositories[$i + 2]}   
248         checkout_type="branch"       
249         #for all the openlink repo. we use a tag if provided.               
250         [ "$name" == "kernel" ] && [ -z "$DEFAULT_KERNEL" ] && i=$[$i + 3] && continue
251         cd_repo $name   
252         echo -e "\n${NORMAL}Checking out branch ${GREEN}$branch  ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
253                 git checkout $branch        
254         git fetch origin
255         git fetch origin --tags  
256         if [[ "$url" == *git.ti.com* ]]
257         then            
258            [[ -n $RESET ]] && echo -e "${PURPLE}Reset to latest in repo ${GREEN}$name ${NORMAL} branch  ${GREEN}$branch ${NORMAL}"  && git reset --hard origin/$branch
259            [[ -n $USE_TAG ]] && git checkout $USE_TAG  && echo -e "${NORMAL}Reset to tag ${GREEN}$USE_TAG   ${NORMAL}in repo ${GREEN}$name ${NORMAL} "            
260         fi        
261                 cd_back
262                 i=$[$i + 3]
263         done
266 function setup_toolchain()
268         if [ ! -f `path downloads`/arm-toolchain.tar.bz2 ]; then
269         echo "Setting toolchain"
270                 wget ${toolchain[0]} -O `path downloads`/arm-toolchain.tar.bz2
271                 tar -xjf `path downloads`/arm-toolchain.tar.bz2 -C `path toolchain`
272                 mv `path toolchain`/* `path toolchain`/arm
273         fi
276 function build_intree()
278     cd_repo driver
279         export KERNEL_PATH=`repo_path driver`
280         read_kernel_version
281         [ $CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path driver`/.config
282         [ $CLEAN ] && make clean
283         [ $CLEAN ] && assert_no_error
285         make -j${PROCESSORS_NUMBER} zImage
286         make -j${PROCESSORS_NUMBER} am335x-evm.dtb
287         make -j${PROCESSORS_NUMBER} am335x-bone.dtb
288         make -j${PROCESSORS_NUMBER} am335x-boneblack.dtb
289         make -j${PROCESSORS_NUMBER} am335x-boneblack-e14-wl1837.dtb
290         make -j${PROCESSORS_NUMBER} am335x-boneblack-su-audio.dtb
291         make -j${PROCESSORS_NUMBER} am335x-boneblack-wl1835.dtb
292         make -j${PROCESSORS_NUMBER} modules
293         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} modules_install
294         cp `repo_path driver`/arch/arm/boot/zImage `path tftp`/zImage
295         cp `repo_path driver`/arch/arm/boot/dts/am335x-*.dtb `path tftp`/
297         assert_no_error
298         cd_back
301 function build_uimage()
303     cd_repo kernel
304         [ -z $NO_CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path kernel`/.config
305         [ -z $NO_CLEAN ] && make clean
306         [ -z $NO_CLEAN ] && assert_no_error
308     if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
309     then
310         make -j${PROCESSORS_NUMBER} uImage
311         cp `repo_path kernel`/arch/arm/boot/uImage `path tftp`/uImage
312     else
313         if [ -z $NO_DTB ] 
314         then
315             make -j${PROCESSORS_NUMBER} zImage
316             make -j${PROCESSORS_NUMBER} am335x-evm.dtb
317             make -j${PROCESSORS_NUMBER} am335x-bone.dtb
318             make -j${PROCESSORS_NUMBER} am335x-boneblack.dtb
319             make -j${PROCESSORS_NUMBER} modules
320             INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} modules_install
321             cp `repo_path kernel`/arch/arm/boot/zImage `path tftp`/zImage
322             cp `repo_path kernel`/arch/arm/boot/dts/am335x-*.dtb `path tftp`/
323         else
324             LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage.am335x-evm 
325             cp `repo_path kernel`/arch/arm/boot/uImage.am335x-evm `path tftp`/uImage
326         fi
327     fi
328         assert_no_error
329         cd_back
332 function generate_compat()
334         cd_repo backports
335         python ./gentree.py --clean `repo_path driver` `path compat_wireless`
336         cd_back
339 function build_modules()
341         generate_compat
342         cd_repo compat_wireless
343         if [ -n "$KERNEL_VARIANT" ] && [ -d "$PATH__ROOT/patches/driver_patches/$KERNEL_VARIANT" ]; then
344                 for i in $PATH__ROOT/patches/driver_patches/$KERNEL_VARIANT/*.patch; do
345                         print_highlight "Applying driver patch: $i"
346                         patch -p1 < $i;
347                         assert_no_error
348                 done
349         fi
350         if [ -z $NO_CLEAN ]; then
351                 make clean
352         fi
353         make defconfig-wl18xx
354         make -j${PROCESSORS_NUMBER}
355         assert_no_error
356         #find . -name \*.ko -exec cp {} `path debugging`/ \;
357         find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
358     
359         make  modules_install
360         assert_no_error
361         cd_back
364 function build_openssl()
366         cd_repo openssl
367         [ -z $NO_CONFIG ] && ./Configure linux-generic32
368         [ -z $NO_CLEAN ] && make clean
369         [ -z $NO_CLEAN ] && assert_no_error
370         make
371         assert_no_error
372         make install_sw
373         assert_no_error
374         cd_back
378 function build_iw()
380         cd_repo iw
381         [ -z $NO_CLEAN ] && make clean
382         [ -z $NO_CLEAN ] && assert_no_error
383         CC=${CROSS_COMPILE}gcc LIBS+=" -lpthread -lm" make V=1
384         assert_no_error
385         DESTDIR=`path filesystem` make install
386         assert_no_error
387         cd_back
389 function build_libnl()
391         cd_repo libnl
392         [ -z $NO_CONFIG ] && ./autogen.sh
393         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
394         ([ -z $NO_CONFIG ] || [ -z $NO_CLEAN ]) && make clean
395         [ -z $NO_CLEAN ] && assert_no_error
396         make
397         assert_no_error
398         make install
399         assert_no_error
400         cd_back
403 function build_wpa_supplicant()
405         cd `repo_path hostap`/wpa_supplicant
406         [ -z $NO_CONFIG ] && cp android.config .config
407     [ -n "$SYSLOG_EN" ] && echo "Enable DEBUG_SYSLOG config" && sed -i "/#CONFIG_DEBUG_SYSLOG=y/ s/# *//" .config
408         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
409         assert_no_error
410         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
411         assert_no_error
412         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
413         assert_no_error
414         cd_back    
415     cp `repo_path scripts_download`/conf/*_supplicant.conf  `path filesystem`/etc/
418 function build_hostapd()
420     cd `repo_path hostap`/hostapd
421         [ -z $NO_CONFIG ] && cp android.config .config
422         [ -z $NO_UPNP ] && echo "Enable UPNP config" && sed -i "/#CONFIG_WPS_UPNP=y/ s/# *//" .config
423         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
424         assert_no_error
425         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
426         assert_no_error
427         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
428         assert_no_error
429         cd_back
430     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
433 function build_crda()
434 {       
435         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
436         cp `repo_path crda`/pubkeys/* `path filesystem`/etc/wireless-regdb/pubkeys/
437     cd_repo crda
438         
439         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
440         [ -z $NO_CLEAN ] && assert_no_error
441         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
442         assert_no_error
443         DESTDIR=`path filesystem` make install
444         assert_no_error
445         cd_back
448 function build_wl_logger()
450         if [ -d "`repo_path ti_utils`/wl_logproxy" ]; then
451                 cd `repo_path ti_utils`/wl_logproxy
452                 [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
453                 [ -z $NO_CLEAN ] && assert_no_error
454                 NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
455                 assert_no_error
456                 NFSROOT=`path filesystem` make install
457                 cd_back
458         fi
461 function build_calibrator()
463         cd_repo ti_utils
464         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
465         [ -z $NO_CLEAN ] && assert_no_error
466         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
467         assert_no_error
468         NFSROOT=`path filesystem` make install
469         #assert_no_error
470         cp -f `repo_path ti_utils`/hw/firmware/wl1271-nvs.bin `path filesystem`/lib/firmware/ti-connectivity
471         cd_back
474 function build_wlconf()
476         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
477         cd `repo_path ti_utils`/wlconf
478         if [ -z $NO_CLEAN ]; then
479                 NFSROOT=`path filesystem` make clean
480                 assert_no_error
481                 for file_to_copy in $files_to_copy; do
482                         rm -f `path filesystem`/usr/sbin/wlconf/$file_to_copy
483                 done
484                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
485         fi
486         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
487         assert_no_error
489         # install
490         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
491         chmod 755 `path filesystem`/usr/sbin/wlconf
492         for file_to_copy in $files_to_copy; do
493                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
494                 echo "echoying files $file_to_copy"
495         done
496         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
497         cd_back
500 function build_fw_download()
502         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
505 function patch_kernel()
507         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
508         cd $KERNEL_PATH
509         echo "using kernel: $KERNEL_PATH"
510         if [ -d "$PATH__ROOT/patches/kernel_patches/$KERNEL_VARIANT" ]; then
511                 read -p "Branch name to use? (will be created if doesn't exist)" -e branchname
512                 if git show-ref --verify --quiet "refs/heads/$branchname"; then
513                         echo "Branch name $branchname already exists, trying to use it..."
514                         git checkout $branchname
515                 else
516                         echo "Creating branch $branchname and switching to it"
517                         git checkout -b $branchname
518                 fi
519                 assert_no_error
520                 for i in $PATH__ROOT/patches/kernel_patches/$KERNEL_VARIANT/*.patch; do
521                         git am $i;
522                         assert_no_error
523                 done
524         fi
525         assert_no_error
526         cd_back
529 function build_uim()
531         cd_repo uim
532         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
533         [ -z $NO_CLEAN ] && assert_no_error
534         make CC=${CROSS_COMPILE}gcc
535         assert_no_error
536         install -m 0755 uim `path filesystem`/usr/bin
537         install -m 0755 `repo_path uim`/scripts/uim-sysfs `path filesystem`/etc/init.d/
538         cd `path filesystem`/etc/rcS.d/
539         ln -sf  ../init.d/uim-sysfs S03uim-sysfs
540         assert_no_error
541         cd_back
544 function build_bt_firmware()
546         cd_repo bt-firmware
547         for i in `repo_path bt-firmware`/initscripts/*.bts; do
548                 echo "Installing bluetooth init script: $i"
549                 install -m 0755 $i `path filesystem`/lib/firmware/
550                 assert_no_error
551         done
554 function build_scripts_download()
556         cd_repo scripts_download
557         echo "Copying scripts"
558         scripts_download_path=`repo_path scripts_download`
559         for script_dir in `ls -d $scripts_download_path`/*/
560         do
561                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
562                 cp -rf ${script_dir}/* `path filesystem`/usr/share/wl18xx
563         done
564         cd_back
567 function clean_kernel()
569         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
570         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
571         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
574 function clean_outputs()
576     if [[ "$ROOTFS" == "DEFAULT" ]]
577     then
578         echo "Cleaning outputs"
579         rm -rf `path filesystem`/*
580         rm -f `path outputs`/*
581    fi
584 function build_outputs()
586         if [[ "$ROOTFS" == "DEFAULT" ]]
587     then  
588         echo "Building outputs"
589         cd_path filesystem
590         tar cpjf `path outputs`/${tar_filesystem[0]} .
591         cd_back
592                 
593                 # Copy kernel files only if default kernel is used(for now)
594                 if [[ $DEFAULT_KERNEL -eq 1 ]]
595                 then
596                         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
597                         then
598                                 cp `path tftp`/uImage `path outputs`/uImage
599                         else
600                                 if [ -z $NO_DTB ]
601                                 then
602                                         cp `path tftp`/zImage `path outputs`/zImage
603                                         cp `path tftp`/*.dtb `path outputs`/
604                                 else
605                                         cp `path tftp`/uImage `path outputs`/uImage
606                                 fi
607                         fi
608                 fi
609     fi
612 function install_outputs()
614     echo "Installing outputs"
615         tftp_path=${setup[2]}
616         sitara_left_path=${setup[5]}
617         sitara_right_path=${setup[8]}
619         cp `path outputs`/uImage ${tftp_path}
620         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
621         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
623         cd $sitara_left_path
624         tar xjf ${tar_filesystem[0]}
625         cd_back
627         cd $sitara_right_path
628         tar xjf ${tar_filesystem[0]}
629         cd_back
632 function set_files_to_verify()
634         files_to_verify=(
635         # skeleton path
636         # source path
637         # pattern in output of file
639         `path filesystem`/usr/local/sbin/wpa_supplicant
640         `repo_path hostap`/wpa_supplicant/wpa_supplicant
641         "ELF 32-bit LSB[ ]*executable, ARM"
643         `path filesystem`/usr/local/bin/hostapd
644         `repo_path hostap`/hostapd/hostapd
645         "ELF 32-bit LSB[ ]*executable, ARM"
647         `path filesystem`/sbin/crda
648         `repo_path crda`/crda
649         "ELF 32-bit LSB[ ]*executable, ARM"
651         `path filesystem`/usr/lib/crda/regulatory.bin
652         `repo_path wireless_regdb`/regulatory.bin
653         "CRDA wireless regulatory database file"
655         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
656         `repo_path fw_download`/wl18xx-fw-4.bin
657         "data"
659         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
660         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
661         "ELF 32-bit LSB[ ]*relocatable, ARM"
663         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
664         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
665         "ELF 32-bit LSB[ ]*relocatable, ARM"
667         #`path filesystem`/usr/bin/calibrator
668         #`repo_path ti_utils`/calibrator
669         #"ELF 32-bit LSB[ ]*executable, ARM"
671         `path filesystem`/usr/sbin/wlconf/wlconf
672         `repo_path ti_utils`/wlconf/wlconf
673         "ELF 32-bit LSB[ ]*executable, ARM"
674         )
676                 [ $INTREE ] && files_to_verify=(
677         # skeleton path
678         # source path
679         # pattern in output of file
681         `path filesystem`/usr/local/sbin/wpa_supplicant
682         `repo_path hostap`/wpa_supplicant/wpa_supplicant
683         "ELF 32-bit LSB[ ]*executable, ARM"
685         `path filesystem`/usr/local/bin/hostapd
686         `repo_path hostap`/hostapd/hostapd
687         "ELF 32-bit LSB[ ]*executable, ARM"
689         `path filesystem`/sbin/crda
690         `repo_path crda`/crda
691         "ELF 32-bit LSB[ ]*executable, ARM"
693         `path filesystem`/usr/lib/crda/regulatory.bin
694         `repo_path wireless_regdb`/regulatory.bin
695         "CRDA wireless regulatory database file"
697         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
698         `repo_path fw_download`/wl18xx-fw-4.bin
699         "data"
701         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/kernel/drivers/net/wireless/ti/wl18xx/wl18xx.ko
702         `repo_path driver`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
703         "ELF 32-bit LSB[ ]*relocatable, ARM"
705         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/kernel/drivers/net/wireless/ti/wlcore/wlcore.ko
706         `repo_path driver`/drivers/net/wireless/ti/wlcore/wlcore.ko
707         "ELF 32-bit LSB[ ]*relocatable, ARM"
709         #`path filesystem`/usr/bin/calibrator
710         #`repo_path ti_utils`/calibrator
711         #"ELF 32-bit LSB[ ]*executable, ARM"
713         `path filesystem`/usr/sbin/wlconf/wlconf
714         `repo_path ti_utils`/wlconf/wlconf
715         "ELF 32-bit LSB[ ]*executable, ARM"
716         ) 
720 function get_tag()
722        i="0"
723        while [ $i -lt ${#repositories[@]} ]; do
724                name=${repositories[$i]}
725                url=${repositories[$i + 1]}
726         branch=${repositories[$i + 2]}
727         checkout_type="branch"
728         cd_repo $name
729         if [[ "$url" == *git.ti.com* ]]
730         then
731                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
732                 git describe
733         fi
734                cd_back
735                i=$[$i + 3]
736        done
741 function admin_tag()
743         i="0"    
744         while [ $i -lt ${#repositories[@]} ]; do
745                 name=${repositories[$i]}
746                 url=${repositories[$i + 1]}
747         branch=${repositories[$i + 2]}   
748         checkout_type="branch"              
749         cd_repo $name    
750         if [[ "$url" == *git.ti.com* ]]
751         then                                   
752                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
753                 git show --summary        
754                 read -p "Do you want to tag this commit ?" yn
755                 case $yn in
756                     [Yy]* )  git tag -a $1 -m "$1" ;
757                              git push --tags ;;
758                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
759                     
760                     * ) echo "Please answer yes or no.";;
761                 esac
762            
763         fi        
764                 cd_back
765                 i=$[$i + 3]
766         done
770 function verify_skeleton()
772         echo "Verifying filesystem skeleton..."
774         set_files_to_verify
776         i="0"
777         while [ $i -lt ${#files_to_verify[@]} ]; do
778                 skeleton_path=${files_to_verify[i]}
779                 source_path=${files_to_verify[i + 1]}
780                 file_pattern=${files_to_verify[i + 2]}
781                 file $skeleton_path | grep "${file_pattern}" >/dev/null
782         if [ $? -eq 1 ]; then
783         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
784         #exit
785         fi
787                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
788                 md5_source=$(md5sum $source_path     | awk '{print $1}')
789                 if [ $md5_skeleton != $md5_source ]; then
790                         echo "ERROR: file mismatch"
791                         echo $skeleton_path
792                         exit 1
793                 fi
794                 i=$[$i + 3]
795         done
797         which regdbdump > /dev/null
798         if [ $? -eq 0 ]; then
799                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
800                 if [ $? -ne 0 ]; then
801                         echo "Please update your public key used to verify the DB"
802                 fi
803         fi
806 function verify_installs()
808     apps_to_verify=(
809      libtool     
810      python-m2crypto
811      bison
812      flex
813     )
815     i="0"
816         while [ $i -lt ${#apps_to_verify[@]} ]; do
817         if !( dpkg-query -s ${apps_to_verify[i]} 2>/dev/null | grep -q ^"Status: install ok installed"$ )then
818             echo  "${apps_to_verify[i]} is missing"
819             echo  "Please use 'sudo apt-get install ${apps_to_verify[i]}'"
820             read -p "Do you want to install it now [y/n] ? (requires sudo) " yn
821             case $yn in
822                 [Yy]* )  sudo apt-get install ${apps_to_verify[i]} ;;
823                 [Nn]* ) echo -e "${PURPLE}${apps_to_verify[i]} was not installed. leaving build. ${NORMAL} " ; exit 0 ;;
824                 * ) echo "Please answer y or n.";;
825             esac
826         fi
827         i=$[$i + 1]
828     done
831 function setup_workspace()
833         setup_directories       
834         setup_repositories
835         setup_branches
836     verify_installs
837     #Download toolchain only if it was not set
838     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
842 function build_all()
844     if [ -z $NO_EXTERNAL ] 
845     then        
846         [ -z $INTREE ] && [ $DEFAULT_KERNEL ] && build_uimage
847         build_openssl
848         build_libnl
849         build_crda
850     fi
851     
852     if [ -z $NO_TI ] 
853     then
854         [ -z $INTREE ] && build_modules
855                 [ $INTREE ] && build_intree
856         build_iw
857         build_wpa_supplicant
858         build_hostapd   
859         build_calibrator
860         build_wl_logger
861         build_wlconf
862         build_fw_download
863         build_scripts_download
864         build_uim
865         build_bt_firmware
866     fi
867     
868     [ -z $NO_VERIFY ] && verify_skeleton
871 function setup_and_build()
873     setup_workspace
874     build_all
877 function main()
879         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
880     setup_environment
881     setup_directories
882     read_kernel_version
883     
884         case "$1" in
885         'init')                
886         print_highlight " initializing workspace (w/o build) "       
887                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
888         NO_BUILD=1 
889         setup_workspace
890         read_kernel_version #####read kernel version again after init#####
891                 ;;
892               
893         'clean')        
894         print_highlight " cleaning & building all "       
895         clean_outputs
896         setup_directories
897         build_all        
898                 ;;
900         'update')
901         print_highlight " setting up workspace and building all "
902                 if [  -n "$2" ]
903         then
904             print_highlight "Using tag $2 "
905             USE_TAG=$2
906         else
907             print_highlight "Updating all to head (this will revert local changes)"
908             RESET=1
909         fi
910         #clean_kernel
911         clean_outputs
912         setup_workspace
913         read_kernel_version #####read kernel version again after update#####
914         build_all
915                 ;;
916         
917                 'openlink')
918         print_highlight " building all (w/o clean) "       
919                 NO_EXTERNAL=1 setup_and_build
920                 ;;
922         #################### Building single components #############################
923                 'kernel')
924                 print_highlight " building only Kernel "
925                 #clean_kernel
926                 build_uimage
927                 ;;
929                 'intree')
930                 print_highlight " building modules intree"
931                 #clean_kernel
932                 build_intree
933                 ;;
934                 
935         'kernel_modules')
936         print_highlight " building kernel and driver modules"
937         build_uimage
938                 build_modules
939                 ;;
941                 'modules')
942         print_highlight " building only Driver modules "
943                 build_modules
944                 ;;
946                 'wpa_supplicant')
947         print_highlight " building only wpa_supplicant "
948                 build_wpa_supplicant      
949                 ;;
951                 'hostapd')
952         print_highlight " building only hostapd "
953                 build_hostapd
954                 ;;
956                 'crda')
957                 print_highlight " building only CRDA "
958                 build_crda
959                 ;;
960         
961                 'libnl')
962                 print_highlight " building only libnl"
963                 build_libnl
964                 ;;
966                 'iw')
967                 print_highlight " building only iw"
968                 build_iw
969                 ;;
971                 'openssl')
972                 print_highlight " building only openssl"
973                 build_openssl
974                 ;;
976                 'scripts')
977                 print_highlight " Copying scripts "
978                 build_scripts_download
979                 ;;
981                 'utils')
982                 print_highlight " building only ti-utils "
983                 build_calibrator
984                 build_wl_logger
985                 build_wlconf            
986                 ;;
988                 'firmware')
989                 print_highlight " building only firmware"
990                 build_fw_download
991                 ;;
993                 'patch_kernel')
994                 print_highlight " only patching kernel $2 without performing an actual build!"
995                 NO_BUILD=1
996                 patch_kernel
997                 ;;
999                 'uim')
1000                 print_highlight " building only uim "
1001                 build_uim
1002                 ;;
1004                 'bt-firmware')
1005                 print_highlight " Only installing bluetooth init scripts "
1006                 build_bt_firmware
1007                 ;;
1008         ############################################################
1009         'get_tag')
1010         get_tag
1011         exit
1012         ;;
1013                 
1014         'admin_tag')        
1015                 admin_tag $2
1016                 ;;
1018         'check_updates')
1019                 check_for_build_updates
1020                 ;;
1022         '')
1023         print_highlight " building all (No clean & no source code update) "  
1024                 #clean_outputs
1025         NO_CLEAN=1 build_all
1026                 ;;
1028                 'all_intree')
1029         print_highlight " building all (in-tree) (No clean & no source code update) "
1030                 #clean_outputs
1031         INTREE=1 build_all
1032                 ;;
1033         *)
1034         echo " "
1035         echo "**** Unknown parameter - please see usage below **** "
1036         usage
1037         ;;
1038         esac
1039         
1040         [[ -z $NO_BUILD ]] && build_outputs
1041         [[ -n $INSTALL_NFS ]] && install_outputs
1042         echo "Wifi Package Build Successful"
1044 main $@