]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - wl12xx/build-utilites.git/blob - wl12xx_build.sh
setup-env: update setup-env files
[wl12xx/build-utilites.git] / wl12xx_build.sh
1 #!/bin/bash
3 declare -A gen_tag="ol_R5.SP8.01"
4 #### R5 SP8.01
5 declare -A wl12xx_download_target="git://git.ti.com/wl12xx/wl12xx.git"
6 declare -A wl12xx_tag=${gen_tag}
7 declare -A compatwireless_download_target="git://git.ti.com/wl12xx/compat-wireless.git"
8 declare -A compat_wireless_tag=${gen_tag}
9 declare -A compat_download_target="git://git.ti.com/wl12xx/compat.git"
10 declare -A compat_tag=${gen_tag}
11 declare -A iw_download_target="git://git.sipsolutions.net/iw.git"
12 declare -A iw_tag="0a236ef5f8e4ba7218aac7d0cdacf45673d5b35c"
14 declare -A ti_utils_download_target="git://git.ti.com/wl12xx/ti-utils.git"
15 declare -A ti_utils_commit_id=${gen_tag}
16 declare -A hostap_download_target="git://git.ti.com/wl12xx/hostap.git"
17 declare -A hostap_commit_id=${gen_tag}
21 if [ ! -e setup-env ]
22 then
23         echo "No setup-env"
24         exit 1
25 fi
26 source setup-env
27 unset PKG_CONFIG_SYSROOT_DIR
28 ME=$0
29 components="libnl openssl iw hostap wpa_supplicant crda ti-utils ti-utils-firmware compat-wireless"
30 export GIT_TREE=${WORK_SPACE}/wl12xx
31 export GIT_COMPAT_TREE=${WORK_SPACE}/compat
33 old_dir=`pwd`
35 function download ()
36 {
37         file="$2"
38         [ -e ${WORK_SPACE}/${file} ] && echo "File $file already exists. Skipping download." && return 0
39         wget "$1"
40         if [ $? -ne 0 ]
41         then 
42                 echo "Failed to download $file"
43                 exit 1
44         fi
45 }
47 function git_clone ()
48 {
49         file="$2"
50         if [ -e ${WORK_SPACE}/${file} ]
51         then
52                 echo "File $file alread exists. Skipping git clone."
53                 cd ${WORK_SPACE}/${file}
54                 git fetch || exit 1
55                 echo "git $file fetched."
56                 return 0
57         fi
58         git clone "$1"
59         if [ $? -ne 0 ]
60         then
61                 echo "Failed to download $2 git repository"
62                 exit 1
63         fi
64         echo "git $file cloned."
65 }
67 function compat-wireless()
68 {
69         stage=$1
72         if [ x"$stage" = "xdownload"  -o x"$stage" = "xall" ]
73         then
74                 cd ${WORK_SPACE}
75                 git_clone ${wl12xx_download_target} wl12xx
76                 cd ${WORK_SPACE}/wl12xx
77                 git reset --hard ${wl12xx_tag} || exit 1
78                 cd ${WORK_SPACE}
79                 git_clone ${compat_download_target} compat
80                 cd ${WORK_SPACE}/compat
81                 git reset --hard ${compat_tag} || exit 1
82                 cd ${WORK_SPACE}
83                 git_clone ${compatwireless_download_target} compat-wireless
84                 cd ${WORK_SPACE}/compat-wireless
85                 git reset --hard ${compat_wireless_tag} || exit 1
86         fi
87         if [ x"$stage" = "xbuild" -o x"$stage" = "xall" ]
88         then
89                 cd ${WORK_SPACE}/compat-wireless
90                 ./scripts/admin-update.sh
91                 ./scripts/driver-select wl12xx
92                 patch -p1 -i ${old_dir}/patches/0001-wl12xx-additional-two-members-for-wl12xx_platform_da.patch || exit 1
93                 make KLIB_BUILD=${KLIB_BUILD} KLIB=${ROOTFS} || exit 1
94         fi
95         if [ x"$stage" = "xinstall"  -o x"$stage" = "xall" ]
96         then
97                 cd ${WORK_SPACE}/compat-wireless
98                 make KLIB_BUILD=${KLIB_BUILD} KLIB=${ROOTFS} install-modules
99         fi
101         if [ x"$stage" = "xclean" ]
102         then
103                 cd $WORK_SPACE/compat-wireless
104                 #make KLIB=${ROOTFS} uninstall
105                 cd $WORK_SPACE && rm -rf compat-wireless
106         fi
108         cd $WORK_SPACE
110 function crda ()
112         stage=$1
113         if [ x"$stage" = "xdownload"  -o x"$stage" = "xall" ]
114         then
115                 download "http://linuxwireless.org/download/crda/crda-1.1.1.tar.bz2" "crda-1.1.1.tar.bz2"
116                 download "http://linuxwireless.org/download/wireless-regdb/regulatory.bins/2011.04.28-regulatory.bin" "2011.04.28-regulatory.bin"
117                 tar xjf crda-1.1.1.tar.bz2
118                 cd ${WORK_SPACE}/crda-1.1.1
119                 cp ${WORK_SPACE}/2011.04.28-regulatory.bin .
120         fi
121         if [ x"$stage" = "xbuild" -o x"$stage" = "xall" ]
122         then
123                 cd ${WORK_SPACE}/crda-1.1.1
124                 make USE_OPENSSL=1 all_noverify || exit 1
125         fi
126         if [ x"$stage" = "xinstall"  -o x"$stage" = "xall" ]
127         then
128                 cd ${WORK_SPACE}/crda-1.1.1
129                 DESTDIR=${ROOTFS} make USE_OPENSSL=1 UDEV_RULE_DIR="etc/udev/rules.d/" install || exit 1
130                 mkdir -p ${ROOTFS}/usr/lib/crda
131                 cp 2011.04.28-regulatory.bin ${ROOTFS}/usr/lib/crda/regulatory.bin
132         fi
133         if [ x"$stage" = "xclean" ]
134         then
135                 cd $WORK_SPACE/crda-1.1.1
136                 DESTDIR=${ROOTFS} make clean
137                 cd $WORK_SPACE && rm -rf crda-1.1.1
138         fi
139         cd $WORK_SPACE
142 function iw ()
144         stage=$1
145         if [ x"$stage" = "xdownload"  -o x"$stage" = "xall" ]
146         then
147                 git_clone "${iw_download_target}" iw
148                 cd ${WORK_SPACE}/iw
149                 git reset --hard ${iw_tag} || exit 1 
150         fi
151         if [ x"$stage" = "xbuild" -o x"$stage" = "xall" ]
152         then
153                 cd ${WORK_SPACE}/iw
154                 make || exit 1
155         fi
157         if [ x"$stage" = "xinstall"  -o x"$stage" = "xall" ]
158         then
159                 cd ${WORK_SPACE}/iw
160                 DESTDIR=${ROOTFS} make install || exit 1
161         fi
162         if [ x"$stage" = "xclean" ]
163         then
164                 cd $WORK_SPACE/iw
165                 make clean
166         fi
167         cd $WORK_SPACE
169 function libnl ()
171         stage=$1
172         if [ x"$stage" = x"download" -o x"$stage" = "xall" ]
173         then
174                 download http://www.infradead.org/~tgr/libnl/files/libnl-2.0.tar.gz libnl-2.0.tar.gz
175                 tar xzf libnl-2.0.tar.gz
176                 cd ${WORK_SPACE}/libnl-2.0
177                 ./configure --prefix=${ROOTFS} CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld RANLIB=${CROSS_COMPILE}ranlib --host=arm-linux
178                 if [ $? != 0 ]
179                 then
180                         echo "libnl failed to be configured"
181                         exit 1
182                 fi
183         fi
185         if [ x"$stage" = "xbuild" -o x"$stage" = "xall" ]
186         then
187                 cd ${WORK_SPACE}/libnl-2.0
188                 make || exit 1
189         fi
190         if [ x"$stage" = "xinstall" -o x"$stage" = "xall" ]
191         then
192                 cd ${WORK_SPACE}/libnl-2.0
193                 make install || exit 1
194         fi
195         if [ x"$stage" = "xclean" ]
196         then
197                 cd $WORK_SPACE/libnl-2.0
198                 make uninstall
199                 cd .. && rm -rf libnl-2.0
200         fi
201         cd $WORK_SPACE
204 function openssl ()
206         stage=$1
207         if [ x"$stage" = x"download" -o x"$stage" = "xall" ]
208         then
209                 cd ${WORK_SPACE}
210                 download "http://www.openssl.org/source/openssl-1.0.0d.tar.gz" "openssl-1.0.0d.tar.gz"
211                 tar xzf openssl-1.0.0d.tar.gz
212                 cd ${WORK_SPACE}/openssl-1.0.0d
213                 patch -p1 -i ${old_dir}/patches/0001-openssl-1.0.0d-new-target-os-for-configure.patch
214                 CROSS_COMPILE= perl ./Configure  shared --prefix=$ROOTFS/usr --openssldir=$ROOTFS/usr/lib/ssl linux-elf-arm
215         fi || exit 1
216         if [ x"$stage" = "xbuild" -o x"$stage" = "xall" ]
217         then
218                 cd ${WORK_SPACE}/openssl-1.0.0d
219                 make || exit 1
220         fi
221         if [ x"$stage" = "xinstall" -o x"$stage" = "xall" ]
222         then
223                 cd ${WORK_SPACE}/openssl-1.0.0d
224                 make install_sw || exit 1
225         fi
226         if [ x"$stage" = "xclean" ]
227         then
228                 cd ${WORK_SPACE}/openssl-1.0.0d
229                 rm -f ${ROOTFS}/usr/lib/*ssl* ${ROOTFS}/usr/lib/pkgconfig/*ssl*
230                 cd .. && rm -rf openssl-1.0.0d
231         fi
232         cd $WORK_SPACE
234 function ti-utils ()
236         stage=$1
238         if [ x"$stage" = x"download" -o x"$stage" = "xall" ]
239         then
240                 git_clone "${ti_utils_download_target}" ti-utils
241                 cd ${WORK_SPACE}/ti-utils
242                 git reset --hard "${ti_utils_commit_id}"
243         fi
245         if [ x"$stage" = "xbuild" -o x"$stage" = "xall" ]
246         then
247                 cd ${WORK_SPACE}/ti-utils
248                 NFSROOT=${ROOTFS} make || exit 1
249         fi
250         if [ x"$stage" = "xinstall" -o x"$stage" = "xall" ]
251         then
252                 cd ${WORK_SPACE}/ti-utils
253                 #NFSROOT=${ROOTFS} make install || exit 1
254                 if [ ! -x calibrator ]
255                 then
256                         echo "calibrator is not built, run 'make' first"
257                         exit 1
258                 fi
259                 cp -f ./calibrator ${ROOTFS}/home/root
260                 chmod 755 ${ROOTFS}/home/root/calibrator
261         fi
262         if [ x"$stage" = "xclean" ]
263         then
264                 cd ${WORK_SPACE}/ti-utils
265                 NFSROOT=${ROOTFS} make clean
266                 rm -f ${ROOTFS}/home/root/calibrator ${ROOTFS}/home/root/wl12xx-tool.sh
267         fi
268         cd $WORK_SPACE
270 function ti-utils-firmware()
272         stage=$1
273          
274         if [ x"$stage" = "xinstall" -o x"$stage" = "xall" ]
275         then
276                 mkdir -p $ROOTFS/lib/firmware/ti-connectivity
277                 cp ${WORK_SPACE}/ti-utils/hw/firmware/* $ROOTFS/lib/firmware/ti-connectivity
278                 rm -f $ROOTFS/lib/hw/firmware/ti-connectivity/Makefile
279                 cp -r ${WORK_SPACE}/ti-utils/hw/ini_files $ROOTFS/lib/firmware/ti-connectivity
280         fi
281         if [ x"$stage" = "xclean" ]
282         then
283                 rm -rf $ROOTFS/lib/firmware/ti-connectivity
284         fi
285         cd $WORK_SPACE
288 function make_hostapd_defconfig ()
290         cat > .config <<"hostapd_defconfig"
291 # Example hostapd build time configuration
293 # This file lists the configuration options that are used when building the
294 # hostapd binary. All lines starting with # are ignored. Configuration option
295 # lines must be commented out complete, if they are not to be included, i.e.,
296 # just setting VARIABLE=n is not disabling that variable.
298 # This file is included in Makefile, so variables like CFLAGS and LIBS can also
299 # be modified from here. In most cass, these lines should use += in order not
300 # to override previous values of the variables.
302 DESTDIR=$(ROOTFS)
303 # Driver interface for Host AP driver
304 CONFIG_DRIVER_HOSTAP=y
306 # Driver interface for wired authenticator
307 #CONFIG_DRIVER_WIRED=y
309 # Driver interface for drivers using the nl80211 kernel interface
310 CONFIG_DRIVER_NL80211=y
311 CONFIG_LIBNL20=y
312 # driver_nl80211.c requires a rather new libnl (version 1.1) which may not be
313 # shipped with your distribution yet. If that is the case, you need to build
314 # newer libnl version and point the hostapd build to use it.
315 #LIBNL=/usr/src/libnl
316 #CFLAGS += -I$(LIBNL)/include
317 #LIBS += -L$(LIBNL)/lib
319 # Driver interface for FreeBSD net80211 layer (e.g., Atheros driver)
320 #CONFIG_DRIVER_BSD=y
321 #CFLAGS += -I/usr/local/include
322 #LIBS += -L/usr/local/lib
323 #LIBS_p += -L/usr/local/lib
324 #LIBS_c += -L/usr/local/lib
326 # Driver interface for no driver (e.g., RADIUS server only)
327 #CONFIG_DRIVER_NONE=y
329 # IEEE 802.11F/IAPP
330 CONFIG_IAPP=y
332 # WPA2/IEEE 802.11i RSN pre-authentication
333 CONFIG_RSN_PREAUTH=y
335 # PeerKey handshake for Station to Station Link (IEEE 802.11e DLS)
336 CONFIG_PEERKEY=y
338 # IEEE 802.11w (management frame protection)
339 # This version is an experimental implementation based on IEEE 802.11w/D1.0
340 # draft and is subject to change since the standard has not yet been finalized.
341 # Driver support is also needed for IEEE 802.11w.
342 #CONFIG_IEEE80211W=y
344 # Integrated EAP server
345 CONFIG_EAP=y
347 # EAP-MD5 for the integrated EAP server
348 CONFIG_EAP_MD5=y
350 # EAP-TLS for the integrated EAP server
351 CONFIG_EAP_TLS=y
353 # EAP-MSCHAPv2 for the integrated EAP server
354 CONFIG_EAP_MSCHAPV2=y
356 # EAP-PEAP for the integrated EAP server
357 CONFIG_EAP_PEAP=y
359 # EAP-GTC for the integrated EAP server
360 CONFIG_EAP_GTC=y
362 # EAP-TTLS for the integrated EAP server
363 CONFIG_EAP_TTLS=y
365 # EAP-SIM for the integrated EAP server
366 #CONFIG_EAP_SIM=y
368 # EAP-AKA for the integrated EAP server
369 #CONFIG_EAP_AKA=y
371 # EAP-AKA' for the integrated EAP server
372 # This requires CONFIG_EAP_AKA to be enabled, too.
373 #CONFIG_EAP_AKA_PRIME=y
375 # EAP-PAX for the integrated EAP server
376 #CONFIG_EAP_PAX=y
378 # EAP-PSK for the integrated EAP server (this is _not_ needed for WPA-PSK)
379 #CONFIG_EAP_PSK=y
381 # EAP-SAKE for the integrated EAP server
382 #CONFIG_EAP_SAKE=y
384 # EAP-GPSK for the integrated EAP server
385 #CONFIG_EAP_GPSK=y
386 # Include support for optional SHA256 cipher suite in EAP-GPSK
387 #CONFIG_EAP_GPSK_SHA256=y
389 # EAP-FAST for the integrated EAP server
390 # Note: Default OpenSSL package does not include support for all the
391 # functionality needed for EAP-FAST. If EAP-FAST is enabled with OpenSSL,
392 # the OpenSSL library must be patched (openssl-0.9.9-session-ticket.patch)
393 # to add the needed functions.
394 #CONFIG_EAP_FAST=y
396 # Wi-Fi Protected Setup (WPS)
397 CONFIG_WPS=y
398 # Enable WSC 2.0 support
399 CONFIG_WPS2=y
400 # Enable UPnP support for external WPS Registrars
401 CONFIG_WPS_UPNP=y
403 # EAP-IKEv2
404 #CONFIG_EAP_IKEV2=y
406 # Trusted Network Connect (EAP-TNC)
407 #CONFIG_EAP_TNC=y
409 # PKCS#12 (PFX) support (used to read private key and certificate file from
410 # a file that usually has extension .p12 or .pfx)
411 CONFIG_PKCS12=y
413 # RADIUS authentication server. This provides access to the integrated EAP
414 # server from external hosts using RADIUS.
415 #CONFIG_RADIUS_SERVER=y
417 # Build IPv6 support for RADIUS operations
418 CONFIG_IPV6=y
420 # IEEE Std 802.11r-2008 (Fast BSS Transition)
421 #CONFIG_IEEE80211R=y
423 # Use the hostapd's IEEE 802.11 authentication (ACL), but without
424 # the IEEE 802.11 Management capability (e.g., madwifi or FreeBSD/net80211)
425 #CONFIG_DRIVER_RADIUS_ACL=y
427 # IEEE 802.11n (High Throughput) support
428 CONFIG_IEEE80211N=y
430 # Remove debugging code that is printing out debug messages to stdout.
431 # This can be used to reduce the size of the hostapd considerably if debugging
432 # code is not needed.
433 #CONFIG_NO_STDOUT_DEBUG=y
435 # Remove support for RADIUS accounting
436 #CONFIG_NO_ACCOUNTING=y
438 # Remove support for RADIUS
439 #CONFIG_NO_RADIUS=y
441 # Remove support for VLANs
442 #CONFIG_NO_VLAN=y
444 # Remove support for dumping state into a file on SIGUSR1 signal
445 # This can be used to reduce binary size at the cost of disabling a debugging
446 # option.
447 #CONFIG_NO_DUMP_STATE=y
449 CONFIG_NO_RANDOM_POOL=y
450 LIBNL=$(ROOTFS)
451 CFLAGS += -I$(LIBNL)/include -I$(ROOTFS)/usr/include/
452 LIBS += -L$(LIBNL)/lib -L$(LIBNL)/lib  -L$(ROOTFS)/usr/lib -lssl -lcrypto -ldl
453 LIBS_p += -L$(LIBNL)/lib -L$(LIBNL)/lib  -L$(ROOTFS)/usr/lib -lssl -lcrypto -ldl
454 hostapd_defconfig
457 function hostap()
459         stage=$1
460         if [ x"$stage" = x"download" -o x"$stage" = "xall" ]
461         then
462                 git_clone "${hostap_download_target}" hostap
463                 cd ${WORK_SPACE}/hostap
464                 git reset --hard "${hostap_commit_id}"
465         fi
466         if [ x"$stage" = "xbuild" -o x"$stage" = "xall" ]
467         then
468                 cd ${WORK_SPACE}/hostap/hostapd
469                 make_hostapd_defconfig
470                 make clean || exit 1
471                 make || exit 1
472         fi
473         if [ x"$stage" = "xinstall" -o x"$stage" = "xall" ]
474         then
475                 cd ${WORK_SPACE}/hostap/hostapd
476                 make install || exit 1
477                 for i in hostapd hostapd_cli; do cp -f $i ${ROOTFS}/usr/sbin/$i || exit 1; done
478         fi
479         if [ x"$stage" = "xclean" ]
480         then
481                 cd ${WORK_SPACE}/hostap/hostapd
482                 make clean
483                 cd ../wpa_supplicant
484                 make clean
485         fi
486         cd $WORK_SPACE
490 function make_wpa_sup_defconfig ()
492         cat > .config <<"wpa_sup_defconfig"
493 # Example wpa_supplicant build time configuration
494 DESTDIR=$(ROOTFS)
495 CFLAGS += -I$(ROOTFS)/usr/include/
496 LIBS += -L$(ROOTFS)/usr/lib
497 LIBS_p += -L$(ROOTFS)/usr/lib
498 CONFIG_WAPI=y
499 CONFIG_LIBNL20=y
500 NEED_BGSCAN=y
501 CONFIG_BGSCAN_LEARN=y
502 # Driver interface for generic Linux wireless extensions
503 CONFIG_DRIVER_WEXT=y
504 # Driver interface for Linux drivers using the nl80211 kernel interface
505 CONFIG_DRIVER_NL80211=y
506 # Driver interface for wired Ethernet drivers
507 CONFIG_DRIVER_WIRED=y
508 # Enable IEEE 802.1X Supplicant (automatically included if any EAP method is
509 # included)
510 CONFIG_IEEE8021X_EAPOL=y
511 # EAP-MD5
512 CONFIG_EAP_MD5=y
513 # EAP-MSCHAPv2
514 CONFIG_EAP_MSCHAPV2=y
515 # EAP-TLS
516 CONFIG_EAP_TLS=y
517 # EAL-PEAP
518 CONFIG_EAP_PEAP=y
519 # EAP-TTLS
520 CONFIG_EAP_TTLS=y
521 # EAP-GTC
522 CONFIG_EAP_GTC=y
523 # EAP-OTP
524 CONFIG_EAP_OTP=y
525 # LEAP
526 CONFIG_EAP_LEAP=y
527 # Wi-Fi Protected Setup (WPS)
528 CONFIG_WPS=y
529 # Enable WSC 2.0 support
530 CONFIG_WPS2=y
531 # PKCS#12 (PFX) support (used to read private key and certificate file from
532 # a file that usually has extension .p12 or .pfx)
533 CONFIG_PKCS12=y
534 # Smartcard support (i.e., private key on a smartcard), e.g., with openssl
535 # engine.
536 CONFIG_SMARTCARD=y
537 # Select control interface backend for external programs, e.g, wpa_cli:
538 # unix = UNIX domain sockets (default for Linux/*BSD)
539 # udp = UDP sockets using localhost (127.0.0.1)
540 # named_pipe = Windows Named Pipe (default for Windows)
541 # y = use default (backwards compatibility)
542 # If this option is commented out, control interface is not included in the
543 # build.
544 CONFIG_CTRL_IFACE=y
545 # Select configuration backend:
546 # file = text file (e.g., wpa_supplicant.conf; note: the configuration file
547 #       path is given on command line, not here; this option is just used to
548 #       select the backend that allows configuration files to be used)
549 # winreg = Windows registry (see win_example.reg for an example)
550 CONFIG_BACKEND=file
551 # PeerKey handshake for Station to Station Link (IEEE 802.11e DLS)
552 CONFIG_PEERKEY=y
553 # Add support for writing debug log to a file (/tmp/wpa_supplicant-log-#.txt)
554 CONFIG_DEBUG_FILE=y
555 LIBNL=$(ROOTFS)
556 CFLAGS += -I$(LIBNL)/include
557 LIBS += -L$(LIBNL)/lib  -lssl -lcrypto -ldl
558 LIBS_p += -L$(LIBNL)/lib  -lssl -lcrypto -ldl
559 # for p2p
560 CONFIG_P2P=y
561 CONFIG_AP=y
562 wpa_sup_defconfig
565 function wpa_supplicant ()
567         stage=$1
568         if [ x"$stage" = x"build" -o x"$stage" = "xall" ]
569         then
570                 cd ${WORK_SPACE}/hostap/wpa_supplicant
571                 make clean
572                 make_wpa_sup_defconfig
573                 make || exit 1
574         fi
575         if [ x"$stage" = x"install" -o x"$stage" = "xall" ]
576         then
577                 cd ${WORK_SPACE}/hostap/wpa_supplicant
578                 make install || exit 1
579                 for i in wpa_supplicant wpa_cli wpa_passphrase; do cp $i ${ROOTFS}/usr/sbin//$i || exit 1; done
580         fi
581         cd $WORK_SPACE
584 function bridge ()
586         stage=$1
587         if [ x"$stage" = x"download" -o x"$stage" = "xall" ]
588         then
589                 download "http://downloads.sourceforge.net/project/bridge/bridge/bridge-utils-1.5.tar.gz" "bridge-utils-1.5.tar.gz"
590                 tar -xvzf bridge-utils-1.5.tar.gz
591                 cd ${WORK_SPACE}/bridge-utils-1.5
592                 autoconf
593                 ./configure --prefix=${ROOTFS} CC=${CROSS_COMPILE}gcc LD=${CROSS_COMPILE}ld RANLIB=${CROSS_COMPILE}ranlib --host=arm-linux
594                 if [ $? != 0 ]
595                         then
596                         echo "bridge failed to be configured"
597                         exit 1
598                 fi
599         fi
600         if [ x"$stage" = "xbuild" -o x"$stage" = "xall" ]
601         then
602                 cd ${WORK_SPACE}/bridge-utils-1.5
603                 make || exit 1
604         fi
605         if [ x"$stage" = "xinstall" -o x"$stage" = "xall" ]
606         then
607                 cd ${WORK_SPACE}/bridge-utils-1.5
608                 make install
609                 cp ./brctl/brctl ${ROOTFS}/usr/sbin/ || exit 1
610         fi
611         if [ x"$stage" = "xclean" ]
612         then
613         cd $WORK_SPACE/bridge-utils-1.5
614 #               make uninstall
615                 cd .. && rm -rf bridge-utils-1.5
616         fi
617         cd $WORK_SPACE
622 function usage ()
624         echo "This script compiles one of following utilities: libnl, openssl, hostapd, wpa_supplicant,wl12xx_modules,firmware,crda,calibrator"
625         echo "by calling specific utility name and action."
626         echo "In case the options is 'all' all utilities will be downloaded and installed on root file system."
627         echo "File setup-env contains all required environment variables, for example:"
628         echo "  ROOTFS=<path to target root file system>."
629         echo "Part of operations requires root access."
630         echo "Usage: `basename $ME` target <libnl"
631         echo "                              openssl"
632         echo "                              hostapd"
633         echo "                              wpa_supplicant"
634         echo "                              wl12xx_modules"
635         echo "                              firmware"
636         echo "                              crda"
637         echo "                              bridge"
638         echo "                              calibrator>  action <download|build|install>"
639         echo "                      all"
640         echo "                      clean-all"
643 function check_libs()
645         local openssl=`pkg-config --exists openssl`
646         local libnl=`pkg-config --exists libnl-2.0`
647         package=$1
649         if [ $openssl -ne 0 -o $libnl -ne 0 ]
650         then
651                 echo "Cannot build $1: openssl and libnl should be installed first."
652                 exit 1
653         fi
655 function package_dir_exists()
657         if [ -d "$1" ]
658         then
659                 echo "Package $2 already downloaded at: $1"
660                 return 1
661         fi
662         return 0
664 function check_env()
666         [ -e ${WORK_SPACE}/.check_env.stamp ] && return 0
667         which dpkg 2>&1>/dev/null || return 0
668         err=0
669         ret=0
670         packages="python python-m2crypto bash bison flex perl bc corkscrew"
671         for p in ${packages}
672         do
673                 echo -n "Checking ${p}..."
674                 present=`dpkg --get-selections ${p} 2>/dev/null | awk '{print $1}'`
675                 [ x"${present}" != x"${p}" ] && echo "Package ${p} is not found. Please run 'apt-get install ${p}' to install it." && err=1 && ret=1
676                 [ ${err} -ne 1 ] && echo "OK"
677                 err=0
678         done
679         return ${ret}
682 ############################# MAIN ##############################################
683 # First building environment should be checked
684 check_env || exit 1
685 if [ -z $CROSS_COMPILE ]
686 then
687         #lets find some
688         tool_path=`which arm-none-linux-gnueabi-gcc`
689         if [ $? -ne 0 ]
690         then
691                 echo "No tool chain is found"
692                 exit 1
693         fi      
694         export CROSS_COMPILE=`dirname $tool_path`/arm-none-linux-gnueabi-
695 fi
697 if [ -z $KLIB_BUILD ]
698 then
699         echo "Path to kernel sources has to be defined"
700         exit 1
701 fi
703 if [ -z $ROOTFS ]
704 then
705         echo "No path to root file system"
706         exit 1
707 fi
708 argc=$#
709 if [ $argc -lt 1 ]
710 then
711         usage
712         exit 1
713 elif [ $argc -eq 1 ]
714 then
715         if [ x"$1" != x"all" -a x"$1" != x"clean-all" ]
716         then
717                 usage
718                 exit 1
719         else
720                 package="$1"
721         fi
722 fi
724 if [ $argc -eq 2 ]
725 then
726         package=$1
727         stage=$2
728 fi
729 if [ ! -d $WORK_SPACE ]
730 then
731         mkdir -p $WORK_SPACE
732         touch ${WORK_SPACE}/.check_env.stamp
733 fi
734 cd $WORK_SPACE
736 case $package in
737         libnl)
738                 case $stage in
739                         download )
740                                 package_dir_exists ${WORK_SPACE}/libnl-2.0 libnl-2 && libnl "download"
741                                 ;;
742                         build)
743                                 package_dir_exists ${WORK_SPACE}/libnl-2.0 libnl-2
744                                 if [ ! $? ]
745                                 then
746                                         libnl "download"
747                                 fi
748                                 cd ${WORK_SPACE}/libnl-2.0
749                                 libnl "build"
750                                 ;;
751                         install)
752                                 package_dir_exists ${WORK_SPACE}/libnl-2.0 libnl-2
753                                 if [ ! $? ]
754                                 then
755                                         libnl "all" && exit
756                                 else
757                                         cd ${WORK_SPACE}/libnl-2.0
758                                         libnl "install"
759                                 fi
760                                 ;;
761                         all)
762                                 package_dir_exists ${WORK_SPACE}/libnl-2.0 libnl-2 || rm -rf libnl-2.0
763                                 libnl "all"
764                                 ;;
765                         *)
766                                 echo "Error: illegal action for libnl"
767                                 exit 1
768                 esac
769                 ;;
770         openssl)
771                 case $stage in
772                         download )
773                                 package_dir_exists ${WORK_SPACE}/openssl-1.0.0d openssl || exit 1
774                                 openssl "download"
775                                 ;;
776                         build)
777                                 package_dir_exists ${WORK_SPACE}/openssl-1.0.0d openssl
778                                 if [ ! $? ]
779                                 then
780                                         openssl "download"
781                                 fi
782                                 cd ${WORK_SPACE}/openssl-1.0.0d
783                                 openssl "build"
784                                 ;;
785                         install)
786                                 package_dir_exists ${WORK_SPACE}/openssl-1.0.0d openssl
787                                 test [ ! $? ] && openssl "all" && exit 0
788                                 cd ${WORK_SPACE}/openssl-1.0.0d
789                                 openssl "install"
790                                 ;;
791                         all)
792                                 package_dir_exists ${WORK_SPACE}/openssl-1.0.0d openssl || rm -rf openssl-1.0.0d
793                                 openssl "all"
794                                 ;;
795                 esac
796                 ;;
797         iw)
798                 case $stage in
799                         download )
800                                 package_dir_exists ${WORK_SPACE}/iw iw || exit 1
801                                 iw "download"
802                                 ;;
803                         build)
804                                 package_dir_exists ${WORK_SPACE}/iw iw
805                                 [ ! $? ] && iw "download"
806                                 check_libs iw
807                                 iw "build"
808                                 ;;
809                         install)
810                                 package_dir_exists ${WORK_SPACE}/iw iw
811                                 [ ! $? ] && iw "donwload"
812                                 [ ! -x ${WORK_SPACE}/iw/iw ] && iw "build"
813                                 iw "install"
814                                 ;;
815                         all)
817                                 package_dir_exists ${WORK_SPACE}/iw iw || rm -rf ${WORK_SPACE}/iw
818                                 iw "all"
819                                 ;;
820                         *)
821                                 echo "Error: illegal action for iw"
822                                 exit 1
823                                 ;;
824                 esac
825                 ;;
826         hostapd)
827                 case $stage in
828                         download)
829                                 package_dir_exists ${WORK_SPACE}/hostap hostapd || exit 1
830                                 hostap "download"
831                                 ;;
832                         build)
833                                 if [ ! -d ${WORK_SPACE}/hostap ]
834                                 then
835                                         hostap "download"
836                                 fi
837                                 cd ${WORK_SPACE}/hostap
838                                 hostap "build"
839                                 ;;
840                         install)
841                                 if [ ! -d ${WORK_SPACE}/hostap ]
842                                 then
843                                         hostap "download"
844                                 fi
845                                 if [ ! -e ${WORK_SPACE}/hostap/hostapd/hostapd ]
846                                 then
847                                         hostap "build"
848                                 fi
849                                 hostap "install"
850                                 ;;
851                         all)
852                                 package_dir_exists ${WORK_SPACE}/hostap hostapd || rm -rf ${WORK_SPACE}/hostap
853                                 hostap "all"
854                                 ;;
855                         *)
856                                 echo "Error: illegal action for hostapd"
857                                 exit 1
858                                 ;;
859                 esac
860                 
861                 ;;
862         wpa_supplicant)
863                 case $stage in
864                         download)
865                                 package_dir_exists ${WORK_SPACE}/hostap wpa_supplicant || exit 1
866                                 hostap "download"
867                                 ;;
868                         build)
869                                 if [ ! -e ${WORK_SPACE}/hostap ]
870                                 then
871                                         hostap "download"
872                                 fi
873                                 wpa_supplicant "build"
874                                 ;;
875                         install)
876                                 if [ ! -e ${WORK_SPACE}/hostap ]
877                                 then
878                                         hostap "download"
879                                 fi
880                                 if [ ! -e ${WORK_SPACE}/hostap/wpa_supplicant/wpa_supplicant ]
881                                 then
882                                         wpa_supplicant "build"
883                                 fi
884                                 wpa_supplicant "install"
885                                 ;;
886                         *)
887                                 echo "Error: illegal action for hostapd"
888                                 exit 1
889                                 ;;
890                 esac
891                 ;;
892         wl12xx_modules)
893                 case $stage in
894                         download)
895                                 package_dir_exists ${WORK_SPACE}/compat-wireless compat-wireless || exit 1
896                                 compat-wireless "download"
897                                 ;;
898                         build)
899                                 if [ ! -d ${WORK_SPACE}/compat-wireless ]
900                                 then
901                                         compat-wireless "download"
902                                 fi
903                                 cd ${WORK_SPACE}/compat-wireless
904                                 compat-wireless "build"
905                                 ;;
906                         install)
907                                 if [ ! -d ${WORK_SPACE}/compat-wireless ]
908                                 then
909                                         compat-wireless "all"
910                                 else
911                                         cd ${WORK_SPACE}/compat-wireless
912                                         compat-wireless "install"
913                                 fi
914                                 ;;
915                         all)
916                                 package_dir_exists ${WORK_SPACE}/compat-wireless compat-wireless || rm -rf ${WORK_SPACE}/compat-wireless
917                                 compat-wireless "all"
918                                 ;;
919                         *)
920                                 echo "Error: illegal action for wl12xx_modules"
921                                 exit 1
922                                 ;;
923                 esac
925                 ;;
926         calibrator)
927                 case $stage in
928                         download)
929                                 if [ -d ${WORK_SPACE}/ti-utils ]
930                                 then
931                                         echo "Calibrator is part of ti-utils package that already exists at: ${WORK_SPACE}/ti-utils"
932                                         exit 0
933                                 fi
934                                 ti-utils "download"
935                                 ;;
936                         build)
937                                 if [ ! -d ${WORK_SPACE}/ti-utils ]
938                                 then
939                                         ti-utils "download"
940                                 fi
941                                 cd ${WORK_SPACE}/ti-utils
942                                 ti-utils "build"
943                                 ;;
944                         install)
945                                 if [ ! -d ${WORK_SPACE}/ti-utils ]
946                                 then
947                                         ti-utils "all"
948                                 else
949                                         if [ ! -e ${WORK_SPACE}/ti-utils/calibrator ]
950                                         then
951                                                 ti-utils "build"
952                                         fi
953                                         ti-utils "install"
954                                 fi
955                                 ;;
956                         all)
957                                 ti-utils "all"
958                                 ;;
959                         *)
960                                 echo "Error: illegal action for calibrator"
961                                 exit 1
962                                 ;;
963                 esac
964                 ;;
965         firmware)
966                 if [  x$stage = "xclean" -o x$stage = "xinstall"  -o x$stage = "xall"   ]
967                 then
969                         if [ ! -d ti-utils/ ]
970                         then
971                                 ti-utils "download"
972                         fi
974                         ti-utils-firmware $2 
975                 else
976                         echo "illegal action for firmware"
977                         exit 1
978                 fi
979                 ;;
980         crda)
981                 case $stage in
982                         download)
983                                 package_dir_exists ${WORK_SPACE}/crda-1.1.1 crda || exit 1
984                                 crda "download"
985                                 ;;
986                         build)
987                                 if [ ! -d ${WORK_SPACE}/crda-1.1.1 ]
988                                 then
989                                         crda "download"
990                                 fi
991                                 cd ${WORK_SPACE}/crda-1.1.1
992                                 crda "build"
993                                 ;;
994                         install)
995                                 if [ ! -d ${WORK_SPACE}/crda-1.1.1 ]
996                                 then
997                                         crda "all"
998                                 else
999                                         cd ${WORK_SPACE}/crda-1.1.1
1000                                         crda "install"
1001                                 fi
1002                                 ;;
1003                         all)
1004                                 package_dir_exists ${WORK_SPACE}/crda-1.1.1 crda || rm -rf ${WORK_SPACE}/crda-1.1.1
1005                                 crda "all"
1006                                 ;;
1007                         *)
1008                                 echo "Error: illegal action for crda"
1009                                 exit 1
1010                                 ;;
1011                 esac
1012                 ;;
1013         bridge)
1014                 case $stage in
1015                         download)
1016                                 package_dir_exists ${WORK_SPACE}/bridge-utils-1.5 bridge || exit 1
1017                                 bridge "download"
1018                                 ;;
1019                         build)
1020                                 if [ ! -d ${WORK_SPACE}/bridge-utils-1.5 ]
1021                                 then
1022                                         bridge "download"
1023                                 fi
1024                                 cd ${WORK_SPACE}/bridge-utils-1.5
1025                                         bridge "build"
1026                                 ;;
1027                         install)
1028                                 if [ ! -d ${WORK_SPACE}/bridge-utils-1.5 ]
1029                                 then
1030                                         bridge "all"
1031                                 else
1032                                         cd ${WORK_SPACE}/bridge-utils-1.5
1033                                         bridge "install"
1034                                 fi
1035                                 ;;
1036                         all)
1037                                 package_dir_exists ${WORK_SPACE}/bridge-utils-1.5 bridge || rm -rf ${WORK_SPACE}/bridge-utils-1.5
1038                                 bridge "all"
1039                                 ;;
1040                         *)
1041                                 echo "Error: illegal action for bridge"
1042                                 exit 1
1043                                 ;;
1044                 esac
1045                 ;;
1046         all)
1047                 echo "bridge ***********************************************************************************"
1048                 bridge "all"
1049                 echo "libnl ***********************************************************************************"
1050                 libnl "all"
1051                 echo "openssl ***********************************************************************************"
1052                 openssl "all"
1053                 echo "iw ***********************************************************************************"
1054                 iw "all"
1055                 echo "hostap ***********************************************************************************"
1056                 hostap "all"
1057                 echo "wpa_supplicant ***********************************************************************************"
1058                 wpa_supplicant "all"
1059                 echo "crda ***********************************************************************************"
1060                 crda "all"
1061                 echo "ti-utils ***********************************************************************************"
1062                 ti-utils "all"
1063                 echo "ti-utils-firmware ***********************************************************************************"
1064                 ti-utils-firmware "all"
1065                 echo "compat-wireless ***********************************************************************************"
1066                 compat-wireless "all"
1067                 ;;
1068         clean-all)
1069                 bridge "clean"
1070                 compat-wireless "clean"
1071                 ti-utils "clean"
1072                 crda "clean"
1073                 hostap "clean"
1074                 iw "clean"
1075                 openssl "clean"
1076                 libnl "clean"
1077                 ti-utils-firmware "clean"
1078                 ;;
1079         *)
1080                 usage
1081                 exit 1
1082 esac