1 export PATH__ROOT=`pwd`
2 . configuration.sh
3 . setup-env
4 # Pretty colors
5 GREEN="\033[01;32m"
6 YELLOW="\033[01;33m"
7 NORMAL="\033[00m"
8 BLUE="\033[34m"
9 RED="\033[31m"
10 PURPLE="\033[35m"
11 CYAN="\033[36m"
12 UNDERLINE="\033[02m"
14 function print_highlight()
15 {
16 echo -e " ${YELLOW}***** $1 ***** ${NORMAL} "
17 }
19 function usage ()
20 {
21 echo ""
22 echo "This script compiles one/all of the following utilities: kernel, libnl, openssl, hostapd, wpa_supplicant,wl18xx_modules,firmware,crda,calibrator"
23 echo "by calling specific utility name and action."
24 echo ""
25 echo " Usage: ./wl18xx_build.sh init <head|TAG> [ Update w/o build ] "
26 echo " update <head|TAG> [ Update & build ] "
27 echo " rebuild [ Build w/o update ] "
28 echo " clean [ Clean, Update & build ] "
29 echo " "
30 echo " Building a specific module usage "
31 echo " ./build.sh hostapd "
32 echo " wpa_supplicant "
33 echo " modules(driver) "
34 echo " firmware "
35 echo " scripts "
36 echo " calibrator "
37 echo " wlconf "
38 echo " uimage "
39 echo " openssl "
40 echo " libnl "
41 echo " crda "
43 exit 1
44 }
46 function assert_no_error()
47 {
48 if [ $? -ne 0 ]; then
49 echo "****** ERROR $? $@*******"
50 exit 1
51 fi
52 echo "****** $1 *******"
53 }
55 function repo_id()
56 {
57 i="0"
58 while [ $i -lt ${#repositories[@]} ]; do
59 [ $1 == "${repositories[i]}" ] && echo $i
60 i=$[$i + 3]
61 done
62 }
64 function repo_url()
65 {
66 echo "${repositories[`repo_id $1` + 1]}"
67 }
69 function repo_branch()
70 {
71 echo "${repositories[`repo_id $1` + 2]}"
72 }
74 function path()
75 {
76 i="0"
77 while [ $i -lt "${#paths[@]}" ]; do
78 [ $1 == "${paths[i]}" ] && echo "${paths[i + 1]}"
79 i=$[$i + 2]
80 done
81 }
83 function set_path()
84 {
85 i="0"
86 while [ $i -lt "${#paths[@]}" ]; do
87 [ $1 == "${paths[i]}" ] && paths[i+1]=$2
88 i=$[$i + 2]
89 done
90 }
92 function repo_path()
93 {
94 echo `path src`/$1
95 }
97 function cd_path()
98 {
99 cd `path $1`
100 }
102 function cd_repo()
103 {
104 cd `repo_path $1`
105 }
107 function cd_back()
108 {
109 cd - > /dev/null
110 }
112 #----------------------------------------------------------j
113 function setup_environment()
114 {
115 if [ ! -e setup-env ]
116 then
117 echo "No setup-env"
118 exit 1
119 fi
121 #if a rootfs path is set - replace the default.
122 if [[ "$ROOTFS" != "DEFAULT" ]]
123 then
124 echo " Changing ROOTFS path to $ROOTFS"
125 set_path filesystem $ROOTFS
126 [ ! -d $ROOTFS ] && echo "Error ROOTFS: $ROOTFS dir does not exist" && exit 1
127 fi
128 echo "!!!!!!!!!!!!! `path filesystem` "
129 #if no toolchain path is set - download it.
130 if [[ "$TOOLCHAIN_PATH" == "DEFAULT" ]]
131 then
132 echo " Setting TOOLCHAIN_PATH path to default"
133 export TOOLCHAIN_PATH=`path toolchain`/arm/bin
134 DEFAULT_TOOLCHAIN=1
135 fi
137 #if no kernel path is set - download it.
138 if [[ "$KERNEL_PATH" == "DEFAULT" ]]
139 then
140 echo " Setting KERNEL_PATH path to default"
141 export KERNEL_PATH=`repo_path kernel`
142 DEFAULT_KERNEL=1
143 else
144 echo " Using user defined kernel"
145 [ ! -d $KERNEL_PATH ] && echo "Error KERNEL_PATH: $KERNEL_PATH dir does not exist" && exit 1
146 fi
148 export PROCESSORS_NUMBER=$(egrep '^processor' /proc/cpuinfo | wc -l)
149 export PKG_CONFIG_PATH=`path filesystem`/lib/pkgconfig
150 export INSTALL_PREFIX=`path filesystem`
151 export LIBNL_PATH=`repo_path libnl`
152 export KLIB=${KERNEL_PATH}
153 export KLIB_BUILD=${KERNEL_PATH}
154 export PATH=$TOOLCHAIN_PATH:$PATH
156 }
158 function setup_filesystem_skeleton()
159 {
160 mkdir -p `path filesystem`/usr/bin
161 mkdir -p `path filesystem`/etc
162 mkdir -p `path filesystem`/usr/lib/crda
163 mkdir -p `path filesystem`/lib/firmware/ti-connectivity
164 mkdir -p `path filesystem`/usr/share/wl18xx
165 mkdir -p `path filesystem`/usr/sbin/wlconf
166 mkdir -p `path filesystem`/usr/sbin/wlconf/official_inis
167 mkdir -p `path filesystem`/etc/wireless-regdb/pubkeys
168 }
170 function setup_directories()
171 {
172 i="0"
173 while [ $i -lt ${#paths[@]} ]; do
174 mkdir -p ${paths[i + 1]}
175 i=$[$i + 2]
176 done
177 setup_filesystem_skeleton
179 }
181 function setup_repositories()
182 {
183 i="0"
184 while [ $i -lt ${#repositories[@]} ]; do
185 url=${repositories[$i + 1]}
186 name=${repositories[$i]}
187 echo -e "${NORMAL}Cloning into: ${GREEN} $name ${NORMAL}"
188 #Skip kernel clone if it was user defined
189 [ "$name" != "kernel" -o "$DEFAULT_KERNEL" ] && [ ! -d `repo_path $name` ] && git clone $url `repo_path $name`
190 i=$[$i + 3]
191 done
192 }
194 function setup_branches()
195 {
196 i="0"
197 while [ $i -lt ${#repositories[@]} ]; do
198 name=${repositories[$i]}
199 url=${repositories[$i + 1]}
200 branch=${repositories[$i + 2]}
201 checkout_type="branch"
202 #for all the openlink repo. we use a tag if provided.
203 [ "$name" == "kernel" ] && [ -z "$DEFAULT_KERNEL" ] && i=$[$i + 3] && continue
204 cd_repo $name
205 echo -e "\n${NORMAL}Checking out branch ${GREEN}$branch ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
206 git checkout $branch
207 git fetch origin
208 git fetch origin --tags
209 if [[ "$url" == *git.ti.com* ]]
210 then
211 [[ -n $RESET ]] && echo -e "${PURPLE}Reset to latest in repo ${GREEN}$name ${NORMAL} branch ${GREEN}$branch ${NORMAL}" && git reset --hard origin/$branch
212 [[ -n $USE_TAG ]] && git reset --hard $USE_TAG && echo -e "${NORMAL}Reset to tag ${GREEN}$USE_TAG ${NORMAL}in repo ${GREEN}$name ${NORMAL} "
213 fi
214 cd_back
215 i=$[$i + 3]
216 done
217 }
219 function setup_toolchain()
220 {
221 if [ ! -f `path downloads`/arm-toolchain.tar.bz2 ]; then
222 echo "Setting toolchain"
223 wget ${toolchain[0]} -O `path downloads`/arm-toolchain.tar.bz2
224 tar -xjf `path downloads`/arm-toolchain.tar.bz2 -C `path toolchain`
225 mv `path toolchain`/* `path toolchain`/arm
226 fi
227 }
229 function build_uimage()
230 {
231 cd_repo kernel
232 [ -z $NO_CONFIG ] && cp `path configuration`/kernel.config `repo_path kernel`/.config
233 [ -z $NO_CLEAN ] && make clean
234 [ -z $NO_CLEAN ] && assert_no_error
235 make -j${PROCESSORS_NUMBER} uImage
236 assert_no_error
237 #LOADADDR=0x80008000 make -j${PROCESSORS_NUMBER} uImage-dtb.am335x-evm
238 assert_no_error
239 cp `repo_path kernel`/arch/arm/boot/uImage `path tftp`/uImage
240 cd_back
241 }
243 function generate_compat()
244 {
245 cd_repo backports
246 python ./gentree.py --clean `repo_path driver` `path compat_wireless`
247 cd_back
248 }
250 function build_modules()
251 {
252 generate_compat
253 cd_repo compat_wireless
254 if [ -z $NO_CLEAN ]; then
255 make clean
256 fi
257 make defconfig-wl18xx
258 make -j${PROCESSORS_NUMBER}
259 assert_no_error
260 find . -name \*.ko -exec cp {} `path debugging`/ \;
261 find . -name \*.ko -exec ${CROSS_COMPILE}strip -g {} \;
263 make -C ${KERNEL_PATH} M=`pwd` "INSTALL_MOD_PATH=`path filesystem`" modules_install
264 assert_no_error
265 #chmod -R 0777 ${PATH__FILESYSTEM}/lib/modules/
266 cd_back
267 }
269 function build_openssl()
270 {
271 cd_repo openssl
272 [ -z $NO_CONFIG ] && ./Configure s/compiler:gcc
273 [ -z $NO_CLEAN ] && make clean
274 [ -z $NO_CLEAN ] && assert_no_error
275 make
276 assert_no_error
277 make install_sw
278 assert_no_error
279 cd_back
280 }
282 function build_libnl()
283 {
284 cd_repo libnl
285 [ -z $NO_CONFIG ] && ./autogen.sh
286 [ -z $NO_CONFIG ] && ./configure --prefix=`path filesystem` --host=${ARCH} CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar
287 [ -z $NO_CLEAN ] && make clean
288 [ -z $NO_CLEAN ] && assert_no_error
289 make
290 assert_no_error
291 make install
292 assert_no_error
293 cd_back
294 }
296 function build_wpa_supplicant()
297 {
298 cd `repo_path hostap`/wpa_supplicant
299 [ -z $NO_CONFIG ] && cp android.config .config
300 CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
301 assert_no_error
302 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
303 assert_no_error
304 CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
305 assert_no_error
306 cd_back
307 cp `repo_path scripts_download`/conf/*_supplicant.conf `path filesystem`/etc/
308 }
310 function build_hostapd()
311 {
312 cd `repo_path hostap`/hostapd
313 [ -z $NO_CONFIG ] && cp android.config .config
314 CONFIG_LIBNL32=y DESTDIR=`path filesystem` make clean
315 assert_no_error
316 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
317 assert_no_error
318 CONFIG_LIBNL32=y DESTDIR=`path filesystem` make install
319 assert_no_error
320 cd_back
321 cp `repo_path scripts_download`/conf/hostapd.conf `path filesystem`/etc/
322 }
324 function build_crda()
325 {
326 cp `repo_path wireless_regdb`/regulatory.bin `path filesystem`/usr/lib/crda/regulatory.bin
327 cp `repo_path wireless_regdb`/linville.key.pub.pem `path filesystem`/etc/wireless-regdb/pubkeys/
328 cd_repo crda
330 [ -z $NO_CLEAN ] && DESTDIR=`path filesystem` make clean
331 [ -z $NO_CLEAN ] && assert_no_error
332 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
333 assert_no_error
334 DESTDIR=`path filesystem` make install
335 assert_no_error
336 cd_back
337 }
339 function build_calibrator()
340 {
341 cd_repo ti_utils
342 [ -z $NO_CLEAN ] && NFSROOT=`path filesystem` make clean
343 [ -z $NO_CLEAN ] && assert_no_error
344 NLVER=3 NLROOT=`repo_path libnl`/include NFSROOT=`path filesystem` LIBS+=-lpthread make
345 assert_no_error
346 NFSROOT=`path filesystem` make install
347 #assert_no_error
348 cd_back
349 }
351 function build_wlconf()
352 {
353 files_to_copy="dictionary.txt struct.bin wl18xx-conf-default.bin README example.conf example.ini configure-device.sh"
354 cd `repo_path ti_utils`/wlconf
355 if [ -z $NO_CLEAN ]; then
356 NFSROOT=`path filesystem` make clean
357 assert_no_error
358 for file_to_copy in $files_to_copy; do
359 rm -f `path filesstem`/usr/sbin/wlconf/$file_to_copy
360 done
361 rm -f `path filesystem`/usr/sbin/wlconf/official_inis/*
362 fi
363 NFSROOT=`path filesystem` make CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld
364 assert_no_error
366 # install
367 cp -f `repo_path ti_utils`/wlconf/wlconf `path filesystem`/usr/sbin/wlconf
368 chmod 755 `path filesystem`/usr/sbin/wlconf
369 for file_to_copy in $files_to_copy; do
370 cp $file_to_copy `path filesystem`/usr/sbin/wlconf/$file_to_copy
371 done
372 cp official_inis/* `path filesystem`/usr/sbin/wlconf/official_inis/
373 cd_back
374 }
376 function build_fw_download()
377 {
378 cp `repo_path fw_download`/*.bin `path filesystem`/lib/firmware/ti-connectivity
379 }
382 function build_scripts_download()
383 {
384 cd_repo scripts_download
385 echo "Copying scripts"
386 scripts_download_path=`repo_path scripts_download`
387 for script_dir in `ls $scripts_download_path`
388 do
389 echo "Copying everything from ${script_dir} to `path filesystem`/usr/share/wl18xx directory"
390 cp -rf `repo_path scripts_download`/${script_dir}/* `path filesystem`/usr/share/wl18xx
391 done
392 cd_back
393 }
395 function clean_outputs()
396 {
397 echo "Cleaning outputs"
398 rm -rf `path filesystem`/*
399 rm -f `path outputs`/${tar_filesystem[0]}
400 rm -f `path outputs`/uImage
402 }
404 function build_outputs()
405 {
406 if [[ "$ROOTFS" == "DEFAULT" ]]
407 then
408 echo "Building outputs"
409 cd_path filesystem
410 tar cpjf `path outputs`/${tar_filesystem[0]} .
411 cd_back
412 cp `path tftp`/uImage `path outputs`/uImage
413 fi
414 }
416 function install_outputs()
417 {
418 echo "Installing outputs"
419 tftp_path=${setup[2]}
420 sitara_left_path=${setup[5]}
421 sitara_right_path=${setup[8]}
423 cp `path outputs`/uImage ${tftp_path}
424 cp `path outputs`/${tar_filesystem[0]} $sitara_left_path
425 cp `path outputs`/${tar_filesystem[0]} $sitara_right_path
427 cd $sitara_left_path
428 tar xjf ${tar_filesystem[0]}
429 cd_back
431 cd $sitara_right_path
432 tar xjf ${tar_filesystem[0]}
433 cd_back
434 }
436 files_to_verify=(
437 # skeleton path
438 # source path
439 # pattern in output of file
441 `path filesystem`/usr/local/sbin/wpa_supplicant
442 `repo_path hostap`/wpa_supplicant/wpa_supplicant
443 "ELF 32-bit LSB executable, ARM"
445 `path filesystem`/usr/local/bin/hostapd
446 `repo_path hostap`/hostapd/hostapd
447 "ELF 32-bit LSB executable, ARM"
449 `path filesystem`/sbin/crda
450 `repo_path crda`/crda
451 "ELF 32-bit LSB executable, ARM"
453 `path filesystem`/usr/lib/crda/regulatory.bin
454 `repo_path wireless_regdb`/regulatory.bin
455 "CRDA wireless regulatory database file"
457 `path filesystem`/lib/firmware/ti-connectivity/wl18xx-fw-4.bin
458 `repo_path fw_download`/wl18xx-fw-4.bin
459 "data"
461 `path filesystem`/lib/modules/3.2.*/extra/drivers/net/wireless/ti/wl18xx/wl18xx.ko
462 `path compat_wireless`/drivers/net/wireless/ti/wl18xx/wl18xx.ko
463 "ELF 32-bit LSB relocatable, ARM"
465 `path filesystem`/lib/modules/3.2.*/extra/drivers/net/wireless/ti/wlcore/wlcore.ko
466 `path compat_wireless`/drivers/net/wireless/ti/wlcore/wlcore.ko
467 "ELF 32-bit LSB relocatable, ARM"
469 #`path filesystem`/usr/bin/calibrator
470 #`repo_path ti_utils`/calibrator
471 #"ELF 32-bit LSB executable, ARM"
473 `path filesystem`/usr/sbin/wlconf/wlconf
474 `repo_path ti_utils`/wlconf/wlconf
475 "ELF 32-bit LSB executable, ARM"
476 )
478 function get_tag()
479 {
480 i="0"
481 while [ $i -lt ${#repositories[@]} ]; do
482 name=${repositories[$i]}
483 url=${repositories[$i + 1]}
484 branch=${repositories[$i + 2]}
485 checkout_type="branch"
486 cd_repo $name
487 if [[ "$url" == *git.ti.com* ]]
488 then
489 echo -e "${PURPLE}Describe of ${NORMAL} repo : ${GREEN}$name ${NORMAL} " ;
490 git describe
491 fi
492 cd_back
493 i=$[$i + 3]
494 done
495 }
499 function admin_tag()
500 {
501 i="0"
502 while [ $i -lt ${#repositories[@]} ]; do
503 name=${repositories[$i]}
504 url=${repositories[$i + 1]}
505 branch=${repositories[$i + 2]}
506 checkout_type="branch"
507 cd_repo $name
508 if [[ "$url" == *git.ti.com* ]]
509 then
510 echo -e "${PURPLE}Adding tag ${GREEN} $1 ${NORMAL} to repo : ${GREEN}$name ${NORMAL} " ;
511 git show --summary
512 read -p "Do you want to tag this commit ?" yn
513 case $yn in
514 [Yy]* ) git tag -a $1 -m "$1" ;
515 git push --tags ;;
516 [Nn]* ) echo -e "${PURPLE}Tag was not applied ${NORMAL} " ;;
518 * ) echo "Please answer yes or no.";;
519 esac
521 fi
522 cd_back
523 i=$[$i + 3]
524 done
525 }
528 function verify_skeleton()
529 {
530 echo "Verifying filesystem skeleton..."
532 i="0"
533 while [ $i -lt ${#files_to_verify[@]} ]; do
534 skeleton_path=${files_to_verify[i]}
535 source_path=${files_to_verify[i + 1]}
536 file_pattern=${files_to_verify[i + 2]}
537 file $skeleton_path | grep "${file_pattern}" >/dev/null
538 if [ $? -eq 1 ]; then
539 echo -e "${RED}ERROR " $skeleton_path " Not found ! ${NORMAL}"
540 #exit
541 fi
543 md5_skeleton=$(md5sum $skeleton_path | awk '{print $1}')
544 md5_source=$(md5sum $source_path | awk '{print $1}')
545 if [ $md5_skeleton != $md5_source ]; then
546 echo "ERROR: file mismatch"
547 echo $skeleton_path
548 exit 1
549 fi
550 i=$[$i + 3]
551 done
553 which regdbdump > /dev/null
554 if [ $? -eq 0 ]; then
555 regdbdump `path filesystem`/usr/lib/crda/regulatory.bin > /dev/null
556 assert_no_error
557 fi
558 }
560 function setup_workspace()
561 {
562 setup_directories
563 setup_repositories
564 setup_branches
565 #Download toolchain only if it was not set
566 [ DEFAULT_TOOLCHAIN ] && setup_toolchain
569 }
572 function build_all()
573 {
574 if [ -z $NO_EXTERNAL ]
575 then
576 [ $DEFAULT_KERNEL ] && build_uimage
577 build_openssl
578 build_libnl
579 build_crda
580 fi
582 if [ -z $NO_TI ]
583 then
584 build_modules
585 build_wpa_supplicant
586 build_hostapd
587 build_calibrator
588 build_wlconf
589 build_fw_download
590 build_scripts_download
591 fi
593 [ -z $NO_VERIFY ] && verify_skeleton
595 }
597 function setup_and_build()
598 {
599 setup_workspace
600 build_all
601 }
603 function main()
604 {
605 [[ "$1" == "-h" || "$1" == "--help" ]] && usage
607 setup_environment
608 setup_directories
612 case "$1" in
613 'update')
614 print_highlight " setting up workspace and building all "
615 if [ -n "$2" ]
616 then
617 print_highlight "Using tag $2 "
618 USE_TAG=$2
619 else
620 print_highlight "Updating all to head (this will revert local changes)"
621 RESET=1
622 fi
623 setup_workspace
624 build_all
625 ;;
627 'init')
628 print_highlight " initializing workspace (w/o build) "
629 [[ -n "$2" ]] && echo "Using tag $2 " && USE_TAG=$2
630 NO_BUILD=1
631 setup_workspace
632 ;;
635 'clean')
636 print_highlight " cleaning & building all "
637 #clean_outputs
638 setup_directories
639 build_all
640 ;;
642 'rebuild')
643 print_highlight " building all (w/o clean) "
644 NO_CLEAN=1 build_all
645 ;;
647 'openlink')
648 print_highlight " building all (w/o clean) "
649 NO_EXTERNAL=1 setup_and_build
650 ;;
651 #################### Building single components #############################
652 'kernel')
653 print_highlight " building only Kernel "
654 build_uimage
655 ;;
657 'modules')
658 print_highlight " building only Driver modules "
659 build_modules
660 ;;
662 'wpa_supplicant')
663 print_highlight " building only wpa_supplicant "
664 build_wpa_supplicant
666 ;;
668 'hostapd')
669 print_highlight " building only hostapd "
670 build_hostapd
671 ;;
673 'crda')
674 print_highlight " building only CRDA "
675 build_crda
676 ;;
678 'scripts')
679 print_highlight " Copying scripts "
680 build_scripts_download
681 ;;
682 'utils')
683 print_highlight " building only ti-utils "
684 build_calibrator
685 build_wlconf
686 ;;
687 ############################################################
688 'get_tag')
689 get_tag
690 exit
691 ;;
693 'admin_tag')
694 admin_tag $2
695 ;;
697 *)
698 print_highlight " building all (No clean & no source code update) "
699 #clean_outputs
700 NO_CLEAN=1 build_all
701 ;;
702 esac
704 [[ -z $NO_BUILD ]] && build_outputs
705 [[ -n $INSTALL_NFS ]] && install_outputs
706 }
707 main $@