c8f125b63352166e1cbcdabf3c24e2555cac3d04
[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   
182     #if no kernel path is set - download it.
183     if [[ "$KERNEL_PATH" == "DEFAULT" ]]
184     then            
185         echo " Setting KERNEL_PATH path to default"
186         export KERNEL_PATH=`repo_path kernel`
187         DEFAULT_KERNEL=1
188     else 
189         echo " Using user defined kernel"                        
190         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
191     fi  
192     
193         export PROCESSORS_NUMBER=$(egrep '^processor' /proc/cpuinfo | wc -l)
194         export PKG_CONFIG_PATH=`path filesystem`/lib/pkgconfig
195         export INSTALL_PREFIX=`path filesystem`
196         export LIBNL_PATH=`repo_path libnl`     
197         export KLIB=`path filesystem`
198         export KLIB_BUILD=${KERNEL_PATH}
199         export GIT_TREE=`repo_path driver`
200         export PATH=$TOOLCHAIN_PATH:$PATH
201     
204 function setup_filesystem_skeleton()
206         mkdir -p `path filesystem`/usr/bin
207         mkdir -p `path filesystem`/etc
208         mkdir -p `path filesystem`/etc/init.d
209         mkdir -p `path filesystem`/etc/rcS.d
210         mkdir -p `path filesystem`/usr/lib/crda
211         mkdir -p `path filesystem`/lib/firmware/ti-connectivity
212         mkdir -p `path filesystem`/usr/share/wl18xx
213         mkdir -p `path filesystem`/usr/sbin/wlconf
214         mkdir -p `path filesystem`/usr/sbin/wlconf/official_inis
215         mkdir -p `path filesystem`/etc/wireless-regdb/pubkeys
218 function setup_directories()
220         i="0"
221         while [ $i -lt ${#paths[@]} ]; do
222                 mkdir -p ${paths[i + 1]}
223                 i=$[$i + 2]
224         done
225         setup_filesystem_skeleton
229 function setup_repositories()
231         i="0"
232         while [ $i -lt ${#repositories[@]} ]; do
233                 url=${repositories[$i + 1]}
234                 name=${repositories[$i]}
235         echo -e "${NORMAL}Cloning into: ${GREEN} $name ${NORMAL}"        
236         #Skip kernel clone if it was user defined 
237                 [ "$name" != "kernel" -o "$DEFAULT_KERNEL" ] && [ ! -d `repo_path $name` ] && git clone $url `repo_path $name`
238                 i=$[$i + 3]
239         done        
242 function setup_branches()
244         i="0"    
245         while [ $i -lt ${#repositories[@]} ]; do
246                 name=${repositories[$i]}
247                 url=${repositories[$i + 1]}
248         branch=${repositories[$i + 2]}   
249         checkout_type="branch"       
250         #for all the openlink repo. we use a tag if provided.               
251         [ "$name" == "kernel" ] && [ -z "$DEFAULT_KERNEL" ] && i=$[$i + 3] && continue
252         cd_repo $name   
253         echo -e "\n${NORMAL}Checking out branch ${GREEN}$branch  ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
254                 git checkout $branch        
255         git fetch origin
256         git fetch origin --tags  
257         if [[ "$url" == *git.ti.com* ]]
258         then            
259            [[ -n $RESET ]] && echo -e "${PURPLE}Reset to latest in repo ${GREEN}$name ${NORMAL} branch  ${GREEN}$branch ${NORMAL}"  && git reset --hard origin/$branch
260            [[ -n $USE_TAG ]] && git checkout $USE_TAG  && echo -e "${NORMAL}Reset to tag ${GREEN}$USE_TAG   ${NORMAL}in repo ${GREEN}$name ${NORMAL} "            
261         fi        
262                 cd_back
263                 i=$[$i + 3]
264         done
267 function setup_toolchain()
269         if [ ! -f `path downloads`/arm-toolchain.tar.bz2 ]; then
270         echo "Setting toolchain"
271                 wget ${toolchain[0]} -O `path downloads`/arm-toolchain.tar.bz2
272                 tar -xjf `path downloads`/arm-toolchain.tar.bz2 -C `path toolchain`
273                 mv `path toolchain`/* `path toolchain`/arm
274         fi
277 function build_intree()
279         cd_repo driver
280         export KERNEL_PATH=`repo_path driver`
281         read_kernel_version
282         [ $CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path driver`/.config
283         [ $CLEAN ] && make clean
284         [ $CLEAN ] && assert_no_error
286         make -j${PROCESSORS_NUMBER} zImage
287         make -j${PROCESSORS_NUMBER} am335x-evm.dtb
288         make -j${PROCESSORS_NUMBER} am335x-evm-wow.dtb
289         make -j${PROCESSORS_NUMBER} am335x-bone.dtb
290         make -j${PROCESSORS_NUMBER} am335x-boneblack.dtb
291         make -j${PROCESSORS_NUMBER} am335x-boneblack-e14-wl1837.dtb
292         make -j${PROCESSORS_NUMBER} am335x-boneblack-su-audio.dtb
293         make -j${PROCESSORS_NUMBER} am335x-boneblack-wl1835.dtb
294         make -j${PROCESSORS_NUMBER} modules
295         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} modules_install
296         cp `repo_path driver`/arch/arm/boot/zImage `path tftp`/zImage
297         cp `repo_path driver`/arch/arm/boot/dts/am335x-*.dtb `path tftp`/
299         assert_no_error
301         cd `path filesystem`
302         [ -f ../outputs/drv_skeleton.tar ] && rm ../outputs/drv_skeleton.tar
303         find ./ -name wl*.ko -exec tar rf ../outputs/drv_skeleton.tar {$1} \;
304         find ./ -name *80211*.ko -exec tar rf ../outputs/drv_skeleton.tar {$1} \;
306         cd_back
309 function rebuild_intree()
311     cd_repo driver
312         export KERNEL_PATH=`repo_path driver`
314         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=net/wireless/ modules
315         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=net/wireless/ modules_install
317         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=net/mac80211/ modules
318         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=net/mac80211/ modules_install
320         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=drivers/net/wireless/ti/ modules
321         INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} M=drivers/net/wireless/ti/ modules_install
323         assert_no_error
324         cd_back
327 function build_uimage()
329     cd_repo kernel
330         [ -z $NO_CONFIG ] && cp `path configuration`/kernel_$KERNEL_VERSION.$KERNEL_PATCHLEVEL.config `repo_path kernel`/.config
331         [ -z $NO_CLEAN ] && make clean
332         [ -z $NO_CLEAN ] && assert_no_error
334     if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
335     then
336         make -j${PROCESSORS_NUMBER} uImage
337         cp `repo_path kernel`/arch/arm/boot/uImage `path tftp`/uImage
338     else
339         if [ -z $NO_DTB ] 
340         then
341             make -j${PROCESSORS_NUMBER} zImage
342             make -j${PROCESSORS_NUMBER} am335x-evm.dtb
343             make -j${PROCESSORS_NUMBER} am335x-bone.dtb
344             make -j${PROCESSORS_NUMBER} am335x-boneblack.dtb
345             make -j${PROCESSORS_NUMBER} modules
346             INSTALL_MOD_PATH=`path filesystem` make -j${PROCESSORS_NUMBER} modules_install
347             cp `repo_path kernel`/arch/arm/boot/zImage `path tftp`/zImage
348             cp `repo_path kernel`/arch/arm/boot/dts/am335x-*.dtb `path tftp`/
349         else
350             LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage.am335x-evm 
351             cp `repo_path kernel`/arch/arm/boot/uImage.am335x-evm `path tftp`/uImage
352         fi
353     fi
354         assert_no_error
355         cd_back
358 function generate_compat()
360         cd_repo backports
361         python ./gentree.py --clean `repo_path driver` `path compat_wireless`
362         cd_back
365 function build_modules()
367         generate_compat
368         cd_repo compat_wireless
369         if [ -n "$KERNEL_VARIANT" ] && [ -d "$PATH__ROOT/patches/driver_patches/$KERNEL_VARIANT" ]; then
370                 for i in $PATH__ROOT/patches/driver_patches/$KERNEL_VARIANT/*.patch; do
371                         print_highlight "Applying driver patch: $i"
372                         patch -p1 < $i;
373                         assert_no_error
374                 done
375         fi
376         if [ -z $NO_CLEAN ]; then
377                 make clean
378         fi
379         make defconfig-wl18xx
380         make -j${PROCESSORS_NUMBER}
381         assert_no_error
382         #find . -name \*.ko -exec cp {} `path debugging`/ \;
383         find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
384     
385         make  modules_install
386         assert_no_error
387         cd_back
390 function build_openssl()
392         cd_repo openssl
393         [ -z $NO_CONFIG ] && ./Configure linux-generic32
394         [ -z $NO_CLEAN ] && make clean
395         [ -z $NO_CLEAN ] && assert_no_error
396         make
397         assert_no_error
398         make install_sw
399         assert_no_error
400         cd_back
404 function build_iw()
406         cd_repo iw
407         [ -z $NO_CLEAN ] && make clean
408         [ -z $NO_CLEAN ] && assert_no_error
409         CC=${CROSS_COMPILE}gcc LIBS+=" -lpthread -lm" make V=1
410         assert_no_error
411         DESTDIR=`path filesystem` make install
412         assert_no_error
413         cd_back
415 function build_libnl()
417         cd_repo libnl
418         [ -z $NO_CONFIG ] && ./autogen.sh
419         [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
420         ([ -z $NO_CONFIG ] || [ -z $NO_CLEAN ]) && make clean
421         [ -z $NO_CLEAN ] && assert_no_error
422         make
423         assert_no_error
424         make install
425         assert_no_error
426         cd_back
429 function build_wpa_supplicant()
431         cd `repo_path hostap`/wpa_supplicant
432         [ -z $NO_CONFIG ] && cp android.config .config
433     [ -n "$SYSLOG_EN" ] && echo "Enable DEBUG_SYSLOG config" && sed -i "/#CONFIG_DEBUG_SYSLOG=y/ s/# *//" .config
434         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
435         assert_no_error
436         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
437         assert_no_error
438         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
439         assert_no_error
440         cd_back    
441     cp `repo_path scripts_download`/conf/*_supplicant.conf  `path filesystem`/etc/
444 function build_hostapd()
446     cd `repo_path hostap`/hostapd
447         [ -z $NO_CONFIG ] && cp android.config .config
448         [ -z $NO_UPNP ] && echo "Enable UPNP config" && sed -i "/#CONFIG_WPS_UPNP=y/ s/# *//" .config
449         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
450         assert_no_error
451         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
452         assert_no_error
453         CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
454         assert_no_error
455         cd_back
456     cp `repo_path scripts_download`/conf/hostapd.conf  `path filesystem`/etc/    
459 function build_crda()
460 {       
461         cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
462         cp `repo_path crda`/pubkeys/* `path filesystem`/etc/wireless-regdb/pubkeys/
463     cd_repo crda
464         
465         [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
466         [ -z $NO_CLEAN ] && assert_no_error
467         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
468         assert_no_error
469         DESTDIR=`path filesystem` make install
470         assert_no_error
471         cd_back
474 function build_wl_logger()
476         if [ -d "`repo_path ti_utils`/wl_logproxy" ]; then
477                 cd `repo_path ti_utils`/wl_logproxy
478                 [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
479                 [ -z $NO_CLEAN ] && assert_no_error
480                 NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
481                 assert_no_error
482                 NFSROOT=`path filesystem` make install
483                 cd_back
484         fi
487 function build_calibrator()
489         cd_repo ti_utils
490         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
491         [ -z $NO_CLEAN ] && assert_no_error
492         NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
493         assert_no_error
494         NFSROOT=`path filesystem` make install
495         #assert_no_error
496         cp -f `repo_path ti_utils`/hw/firmware/wl1271-nvs.bin `path filesystem`/lib/firmware/ti-connectivity
497         cd_back
500 function build_wlconf()
502         files_to_copy="dictionary.txt struct.bin default.conf wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
503         cd `repo_path ti_utils`/wlconf
504         if [ -z $NO_CLEAN ]; then
505                 NFSROOT=`path filesystem` make clean
506                 assert_no_error
507                 for file_to_copy in $files_to_copy; do
508                         rm -f `path filesystem`/usr/sbin/wlconf/$file_to_copy
509                 done
510                 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
511         fi
512         NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
513         assert_no_error
515         # install
516         cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
517         chmod 755 `path filesystem`/usr/sbin/wlconf
518         for file_to_copy in $files_to_copy; do
519                 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
520                 echo "echoying files $file_to_copy"
521         done
522         cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
523         cd_back
526 function build_fw_download()
528         cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
531 function build_fw()
533         cd `repo_path firmware-build`/victoria/firmware
534         [ -z $NO_CLEAN ] && ./build.sh clean
535         ./build.sh
536         cp `repo_path firmware-build`/victoria/firmware/out/Firmware18xx/wl18xx-fw-4.bin `path filesystem`/lib/firmware/ti-connectivity
537         cp `repo_path firmware-build`/victoria/firmware/out/Firmware18xx/wl18xx-fw-4.bin `path outputs`
538         cd_back
542 function patch_kernel()
544         [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
545         cd $KERNEL_PATH
546         echo "using kernel: $KERNEL_PATH"
547         if [ -d "$PATH__ROOT/patches/kernel_patches/$KERNEL_VARIANT" ]; then
548                 read -p "Branch name to use? (will be created if doesn't exist)" -e branchname
549                 if git show-ref --verify --quiet "refs/heads/$branchname"; then
550                         echo "Branch name $branchname already exists, trying to use it..."
551                         git checkout $branchname
552                 else
553                         echo "Creating branch $branchname and switching to it"
554                         git checkout -b $branchname
555                 fi
556                 assert_no_error
557                 for i in $PATH__ROOT/patches/kernel_patches/$KERNEL_VARIANT/*.patch; do
558                         git am $i;
559                         assert_no_error
560                 done
561         fi
562         assert_no_error
563         cd_back
566 function build_uim()
568         cd_repo uim
569         [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
570         [ -z $NO_CLEAN ] && assert_no_error
571         make CC=${CROSS_COMPILE}gcc
572         assert_no_error
573         install -m 0755 uim `path filesystem`/usr/bin
574         install -m 0755 `repo_path uim`/scripts/uim-sysfs `path filesystem`/etc/init.d/
575         cd `path filesystem`/etc/rcS.d/
576         ln -sf  ../init.d/uim-sysfs S03uim-sysfs
577         assert_no_error
578         cd_back
581 function build_bt_firmware()
583         cd_repo bt-firmware
584         for i in `repo_path bt-firmware`/initscripts/*.bts; do
585                 echo "Installing bluetooth init script: $i"
586                 install -m 0755 $i `path filesystem`/lib/firmware/
587                 assert_no_error
588         done
591 function build_scripts_download()
593         cd_repo scripts_download
594         echo "Copying scripts"
595         scripts_download_path=`repo_path scripts_download`
596         for script_dir in `ls -d $scripts_download_path`/*/
597         do
598                 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
599                 cp -rf ${script_dir}/* `path filesystem`/usr/share/wl18xx
600         done
601         cd_back
604 function clean_kernel()
606         [ "$DEFAULT_KERNEL" ] && echo "Cleaning kernel folder"
607         [ "$DEFAULT_KERNEL" ] && cd_repo kernel
608         [ "$DEFAULT_KERNEL" ] && git clean -fdx > /dev/null
611 function clean_outputs()
613     if [[ "$ROOTFS" == "DEFAULT" ]]
614     then
615         echo "Cleaning outputs"
616         rm -rf `path filesystem`/*
617         rm -f `path outputs`/*
618    fi
621 function build_outputs()
623         if [[ "$ROOTFS" == "DEFAULT" ]]
624     then  
625         echo "Building outputs"
626         cd_path filesystem
627         tar cpjf `path outputs`/${tar_filesystem[0]} .
628         cd_back
629                 
630                 # Copy kernel files only if default kernel is used(for now)
631                 if [[ $DEFAULT_KERNEL -eq 1 ]]
632                 then
633                         if [ "$KERNEL_VERSION" -eq 3 ] && [ "$KERNEL_PATCHLEVEL" -eq 2 ]
634                         then
635                                 cp `path tftp`/uImage `path outputs`/uImage
636                         else
637                                 if [ -z $NO_DTB ]
638                                 then
639                                         cp `path tftp`/zImage `path outputs`/zImage
640                                         cp `path tftp`/*.dtb `path outputs`/
641                                 else
642                                         cp `path tftp`/uImage `path outputs`/uImage
643                                 fi
644                         fi
645                 fi
646     fi
649 function install_outputs()
651     echo "Installing outputs"
652         tftp_path=${setup[2]}
653         sitara_left_path=${setup[5]}
654         sitara_right_path=${setup[8]}
656         cp `path outputs`/uImage ${tftp_path}
657         cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
658         cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
660         cd $sitara_left_path
661         tar xjf ${tar_filesystem[0]}
662         cd_back
664         cd $sitara_right_path
665         tar xjf ${tar_filesystem[0]}
666         cd_back
669 function set_files_to_verify()
671         files_to_verify=(
672         # skeleton path
673         # source path
674         # pattern in output of file
676         `path filesystem`/usr/local/sbin/wpa_supplicant
677         `repo_path hostap`/wpa_supplicant/wpa_supplicant
678         "ELF 32-bit LSB[ ]*executable, ARM"
680         `path filesystem`/usr/local/bin/hostapd
681         `repo_path hostap`/hostapd/hostapd
682         "ELF 32-bit LSB[ ]*executable, ARM"
684         `path filesystem`/sbin/crda
685         `repo_path crda`/crda
686         "ELF 32-bit LSB[ ]*executable, ARM"
688         `path filesystem`/usr/lib/crda/regulatory.bin
689         `repo_path wireless_regdb`/regulatory.bin
690         "CRDA wireless regulatory database file"
692         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
693         `repo_path fw_download`/wl18xx-fw-4.bin
694         "data"
696         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wl18xx/wl18xx.ko
697         `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
698         "ELF 32-bit LSB[ ]*relocatable, ARM"
700         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/updates/drivers/net/wireless/ti/wlcore/wlcore.ko
701         `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
702         "ELF 32-bit LSB[ ]*relocatable, ARM"
704         #`path filesystem`/usr/bin/calibrator
705         #`repo_path ti_utils`/calibrator
706         #"ELF 32-bit LSB[ ]*executable, ARM"
708         `path filesystem`/usr/sbin/wlconf/wlconf
709         `repo_path ti_utils`/wlconf/wlconf
710         "ELF 32-bit LSB[ ]*executable, ARM"
711         )
713                 [ $INTREE ] && files_to_verify=(
714         # skeleton path
715         # source path
716         # pattern in output of file
718         `path filesystem`/usr/local/sbin/wpa_supplicant
719         `repo_path hostap`/wpa_supplicant/wpa_supplicant
720         "ELF 32-bit LSB[ ]*executable, ARM"
722         `path filesystem`/usr/local/bin/hostapd
723         `repo_path hostap`/hostapd/hostapd
724         "ELF 32-bit LSB[ ]*executable, ARM"
726         `path filesystem`/sbin/crda
727         `repo_path crda`/crda
728         "ELF 32-bit LSB[ ]*executable, ARM"
730         `path filesystem`/usr/lib/crda/regulatory.bin
731         `repo_path wireless_regdb`/regulatory.bin
732         "CRDA wireless regulatory database file"
734         `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
735         `repo_path fw_download`/wl18xx-fw-4.bin
736         "data"
738         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/kernel/drivers/net/wireless/ti/wl18xx/wl18xx.ko
739         `repo_path driver`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
740         "ELF 32-bit LSB[ ]*relocatable, ARM"
742         `path filesystem`/lib/modules/$KERNEL_VERSION.$KERNEL_PATCHLEVEL.*/kernel/drivers/net/wireless/ti/wlcore/wlcore.ko
743         `repo_path driver`/drivers/net/wireless/ti/wlcore/wlcore.ko
744         "ELF 32-bit LSB[ ]*relocatable, ARM"
746         #`path filesystem`/usr/bin/calibrator
747         #`repo_path ti_utils`/calibrator
748         #"ELF 32-bit LSB[ ]*executable, ARM"
750         `path filesystem`/usr/sbin/wlconf/wlconf
751         `repo_path ti_utils`/wlconf/wlconf
752         "ELF 32-bit LSB[ ]*executable, ARM"
753         ) 
757 function get_tag()
759        i="0"
760        while [ $i -lt ${#repositories[@]} ]; do
761                name=${repositories[$i]}
762                url=${repositories[$i + 1]}
763         branch=${repositories[$i + 2]}
764         checkout_type="branch"
765         cd_repo $name
766         if [[ "$url" == *git.ti.com* ]]
767         then
768                 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} "  ;
769                 git describe
770         fi
771                cd_back
772                i=$[$i + 3]
773        done
778 function admin_tag()
780         i="0"    
781         while [ $i -lt ${#repositories[@]} ]; do
782                 name=${repositories[$i]}
783                 url=${repositories[$i + 1]}
784         branch=${repositories[$i + 2]}   
785         checkout_type="branch"              
786         cd_repo $name    
787         if [[ "$url" == *git.ti.com* ]]
788         then                                   
789                 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} "  ;
790                 git show --summary        
791                 read -p "Do you want to tag this commit ?" yn
792                 case $yn in
793                     [Yy]* )  git tag -a $1 -m "$1" ;
794                              git push --tags ;;
795                     [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
796                     
797                     * ) echo "Please answer yes or no.";;
798                 esac
799            
800         fi        
801                 cd_back
802                 i=$[$i + 3]
803         done
807 function verify_skeleton()
809         echo "Verifying filesystem skeleton..."
811         set_files_to_verify
813         i="0"
814         while [ $i -lt ${#files_to_verify[@]} ]; do
815                 skeleton_path=${files_to_verify[i]}
816                 source_path=${files_to_verify[i + 1]}
817                 file_pattern=${files_to_verify[i + 2]}
818                 file $skeleton_path | grep "${file_pattern}" >/dev/null
819         if [ $? -eq 1 ]; then
820         echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
821         #exit
822         fi
824                 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
825                 md5_source=$(md5sum $source_path     | awk '{print $1}')
826                 if [ $md5_skeleton != $md5_source ]; then
827                         echo "ERROR: file mismatch"
828                         echo $skeleton_path
829                         exit 1
830                 fi
831                 i=$[$i + 3]
832         done
834         which regdbdump > /dev/null
835         if [ $? -eq 0 ]; then
836                 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
837                 if [ $? -ne 0 ]; then
838                         echo "Please update your public key used to verify the DB"
839                 fi
840         fi
843 function verify_installs()
845     apps_to_verify=(
846      libtool     
847      python-m2crypto
848      bison
849      flex
850     )
852     i="0"
853         while [ $i -lt ${#apps_to_verify[@]} ]; do
854         if !( dpkg-query -s ${apps_to_verify[i]} 2>/dev/null | grep -q ^"Status: install ok installed"$ )then
855             echo  "${apps_to_verify[i]} is missing"
856             echo  "Please use 'sudo apt-get install ${apps_to_verify[i]}'"
857             read -p "Do you want to install it now [y/n] ? (requires sudo) " yn
858             case $yn in
859                 [Yy]* )  sudo apt-get install ${apps_to_verify[i]} ;;
860                 [Nn]* ) echo -e "${PURPLE}${apps_to_verify[i]} was not installed. leaving build. ${NORMAL} " ; exit 0 ;;
861                 * ) echo "Please answer y or n.";;
862             esac
863         fi
864         i=$[$i + 1]
865     done
868 function setup_workspace()
870         setup_directories       
871         setup_repositories
872         setup_branches
873     verify_installs
874     #Download toolchain only if it was not set
875     [ DEFAULT_TOOLCHAIN ] && setup_toolchain   
879 function build_all()
881     if [ -z $NO_EXTERNAL ] 
882     then        
883         [ -z $INTREE ] && [ $DEFAULT_KERNEL ] && build_uimage
884         build_openssl
885         build_libnl
886         build_crda
887     fi
888     
889     if [ -z $NO_TI ] 
890     then
891         [ -z $INTREE ] && build_modules
892                 [ $INTREE ] && build_intree
893         build_iw
894         build_wpa_supplicant
895         build_hostapd   
896         build_calibrator
897         build_wl_logger
898         build_wlconf
899         build_fw_download
900         build_scripts_download
901         build_uim
902         build_bt_firmware
903     fi
904     
905     [ -z $NO_VERIFY ] && verify_skeleton
908 function setup_and_build()
910     setup_workspace
911     build_all
914 function main()
916         [[ "$1" == "-h" || "$1" == "--help"  ]] && usage
917     setup_environment
918     setup_directories
919     read_kernel_version
920     
921         case "$1" in
922         'init')                
923         print_highlight " initializing workspace (w/o build) "       
924                 [[  -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2                
925         NO_BUILD=1 
926         setup_workspace
927         read_kernel_version #####read kernel version again after init#####
928                 ;;
929               
930         'clean')        
931         print_highlight " cleaning & building all "       
932         clean_outputs
933         setup_directories
934         build_all        
935                 ;;
937         'update')
938         print_highlight " setting up workspace and building all "
939                 if [  -n "$2" ]
940         then
941             print_highlight "Using tag $2 "
942             USE_TAG=$2
943         else
944             print_highlight "Updating all to head (this will revert local changes)"
945             RESET=1
946         fi
947         #clean_kernel
948         clean_outputs
949         setup_workspace
950         read_kernel_version #####read kernel version again after update#####
951         [[ -z $NO_BUILD ]] && build_all
952                 ;;
953         
954                 'openlink')
955         print_highlight " building all (w/o clean) "       
956                 NO_EXTERNAL=1 setup_and_build
957                 ;;
959         #################### Building single components #############################
960                 'kernel')
961                 print_highlight " building only Kernel "
962         #clean_kernel
963                 build_uimage
964                 ;;
966                 'intree')
967                 print_highlight " building modules intree"
968                 build_intree
969                 ;;
970                 
971                 'intree_m')
972                 print_highlight " Building JUST wireless modules intree"
973                 rebuild_intree
974                 ;;
976         'kernel_modules')
977         print_highlight " building kernel and driver modules"
978         build_uimage
979                 build_modules
980                 ;;
982                 'modules')
983         print_highlight " building only Driver modules "
984                 build_modules
985                 ;;
987                 'wpa_supplicant')
988         print_highlight " building only wpa_supplicant "
989                 build_wpa_supplicant      
990                 ;;
992                 'hostapd')
993         print_highlight " building only hostapd "
994                 build_hostapd
995                 ;;
997                 'crda')
998                 print_highlight " building only CRDA "
999                 build_crda
1000                 ;;
1001         
1002                 'libnl')
1003                 print_highlight " building only libnl"
1004                 build_libnl
1005                 ;;
1007                 'iw')
1008                 print_highlight " building only iw"
1009                 build_iw
1010                 ;;
1012                 'openssl')
1013                 print_highlight " building only openssl"
1014                 build_openssl
1015                 ;;
1017                 'scripts')
1018                 print_highlight " Copying scripts "
1019                 build_scripts_download
1020                 ;;
1022                 'utils')
1023                 print_highlight " building only ti-utils "
1024                 build_calibrator
1025                 build_wl_logger
1026                 build_wlconf            
1027                 ;;
1029                 'all_hostap')
1030                 print_highlight " building hostap and dependencies "
1031                 build_libnl
1032                 build_openssl
1033                 build_wpa_supplicant
1034                 build_hostapd
1035                 ;; 
1037                 'firmware')
1038                 print_highlight " building only firmware"
1039                 build_fw_download
1040                 ;;
1042                 'fw')
1043                 print_highlight " building only firmware"
1044                 build_fw
1045                 ;;
1047                 'patch_kernel')
1048                 print_highlight " only patching kernel $2 without performing an actual build!"
1049                 NO_BUILD=1
1050                 patch_kernel
1051                 ;;
1053                 'uim')
1054                 print_highlight " building only uim "
1055                 build_uim
1056                 ;;
1058                 'bt-firmware')
1059                 print_highlight " Only installing bluetooth init scripts "
1060                 build_bt_firmware
1061                 ;;
1062         ############################################################
1063         'get_tag')
1064         get_tag
1065         exit
1066         ;;
1067                 
1068         'admin_tag')        
1069                 admin_tag $2
1070                 ;;
1072         'check_updates')
1073                 check_for_build_updates
1074                 ;;
1076         '')
1077         print_highlight " building all (No clean & no source code update) "  
1078                 #clean_outputs
1079         NO_CLEAN=1 build_all
1080                 ;;
1082                 'all_intree')
1083         print_highlight " building all (in-tree) (No clean & no source code update) "
1084                 #clean_outputs
1085         INTREE=1 build_all
1086                 ;;
1087         *)
1088         echo " "
1089         echo "**** Unknown parameter - please see usage below **** "
1090         usage
1091         ;;
1092         esac
1093         
1094         [[ -z $NO_BUILD ]] && build_outputs
1095         [[ -n $INSTALL_NFS ]] && install_outputs
1096         echo "Wifi Package Build Successful"
1098 main $@