block_cache: Implement cache_has_block_in_transaction function that will check the...
[haiku.git] / data / bin / install-wifi-firmwares.sh
blob62f3463686f653b37331defc5572c2360198de8e
1 #!/bin/sh
3 # Copyright (c) 2010-2012 Haiku, Inc.
4 # Distributed under the terms of the MIT License.
6 # Authors:
7 # Matt Madia, mattmadia@gmail.com
9 # Synopsis:
10 # Provide a mechanism for end-users to install various firmwares for wireless
11 # network cards in a manner that complies with their individual licenses.
13 # Supported chipsets:
14 # Intel ipw2100
15 # Intel ipw2200/2225/2915
16 # Broadcom 43xx
17 # Marvell 88W8335
20 MESSAGE="This script will install firmware for various wireless network cards.
21 The Broadcom 43xx and Marvell 88W8335 require an active network connection
22 to download additional files before installation. In the absence of internet
23 access, only Intel's ipw2100 and ipw2200 will be installed.
25 If you do not have internet access and need to install the other firmwares,
26 goto http://www.haiku-os.org/guides/dailytasks/wireless. This page has
27 instructions on which files to manually download and where to copy them into
28 this OS. It also has different script that can be run on another OS and will
29 prepare a zip archive for easy install. After that, re-run this script."
30 VIEW='View licenses'
31 ABORT='Abort installation'
32 OK='I agree to the licenses. Install firmwares.'
34 baseURL='http://www.haiku-files.org/files/wifi-firmwares'
35 firmwareDir=`finddir B_SYSTEM_DATA_DIRECTORY`/firmware
36 tempDir=`finddir B_SYSTEM_TEMP_DIRECTORY`/wifi-firmwares
37 driversDir=`finddir B_SYSTEM_ADDONS_DIRECTORY`/kernel/drivers
38 tempFirmwareDir=`finddir B_SYSTEM_TEMP_DIRECTORY`/package_me"$firmwareDir"
39 intelLicense='/boot/system/data/licenses/Intel (2xxx firmware)'
42 function DisplayAlert()
44 local result=`alert --stop "$MESSAGE" "$VIEW" "$ABORT" "$OK"`
45 case "${result}" in
46 "$VIEW")
47 ViewLicenses ;
48 DisplayAlert ;
50 "$ABORT")
51 exit 0 ;;
52 "$OK")
53 InstallAllFirmwares ;
54 exit 0 ;
56 esac
60 function ViewLicenses()
62 license="$tempDir/Wifi_Firmware_Licenses"
63 cat << EOF > $license
65 +-----------------------------------------------------------------------------+
66 | |
67 | Copyright and licensing information of the various wireless firmwares |
68 | |
69 | Firmware for broadcom43xx is under the Copyright of Broadcom Corporation(R) |
70 | Firmware for marvell88w8335 is under the Copyright of Marvell Technology(R) |
71 | ipw2100,iprowifi2200 firmware is covered by the following Intel(R) license: |
72 | |
73 +-----------------------------------------------------------------------------+
75 EOF
76 cat "$intelLicense" >> $license
78 open $license
82 function InstallAllFirmwares()
84 InstallIpw2100
85 InstallIprowifi2200
86 InstallBroadcom43xx
87 InstallMarvell88w8335
88 MakeHPKG
92 function UnlinkDriver()
94 # remove the driver's symlink
95 #rm -f "${driversDir}/dev/net/${driver}"
96 echo "TODO: UnlinkDriver"
100 function SymlinkDriver()
102 # restore the driver's symlink
103 #cd "${driversDir}/dev/net/"
104 #ln -sf "../../bin/${driver}" "${driver}"
105 echo "TODO: SymlinkDriver"
109 function DownloadFileIfNotCached()
111 # DownloadFileIfNotCached <url> <filename> <destination dir>
112 local url=$1
113 local file=$2
114 local dir=$3
116 mkdir -p "$dir"
117 if [ ! -e $dir/$file ] ; then
118 echo "Downloading $url ..."
119 wget -nv -O $dir/$file $url
121 result=$?
122 if [ $result -gt 0 ]; then
123 local error="Failed to download $url."
124 local msg="As a result, ${driver}'s firmware will not be installed."
125 alert --warning "$error $msg"
130 function SetFirmwarePermissions()
132 cd ${tempFirmwareDir}/${driver}/
133 for file in * ; do
134 if [ "$file" != "$driver" ] && [ -f "$file" ] ; then
135 chmod a=r $file
137 done
141 function CleanTemporaryFiles()
143 rm -rf "$tempDir"
144 mkdir -p "$tempDir"
148 function PreFirmwareInstallation()
150 echo "Acquiring firmware for ${driver} ..."
151 mkdir -p "${tempFirmwareDir}/${driver}"
152 UnlinkDriver
156 function PostFirmwareInstallation()
158 SetFirmwarePermissions
159 SymlinkDriver
160 CleanTemporaryFiles
161 echo "... firmware for ${driver} will be installed."
165 function InstallIpw2100()
167 driver='iprowifi2100'
168 PreFirmwareInstallation
170 # Prepare firmware archive for extraction.
171 local file='ipw2100-fw-1.3.tgz'
172 local url="${baseURL}/intel/${file}"
173 local dir="${tempFirmwareDir}/${driver}"
174 cp "${firmwareDir}/${driver}/${file}" "${dir}"
175 DownloadFileIfNotCached $url $file $dir
177 # Extract the firmware & license file in place.
178 cd "${tempFirmwareDir}/${driver}"
179 gunzip < "$file" | tar xf -
181 rm "${tempFirmwareDir}/${driver}/${file}"
182 PostFirmwareInstallation
186 function InstallIprowifi2200()
188 driver='iprowifi2200'
189 PreFirmwareInstallation
191 # Prepare firmware archive for extraction.
192 local file='ipw2200-fw-3.1.tgz'
193 local url="${baseURL}/intel/${file}"
194 local dir="${tempFirmwareDir}/${driver}"
195 cp "${firmwareDir}/${driver}/${file}" "${dir}"
196 DownloadFileIfNotCached $url $file $dir
198 # Extract the firmware & license file.
199 cd "$tempDir"
200 gunzip < "${tempFirmwareDir}/${driver}/$file" | tar xf -
201 cd "${tempDir}/ipw2200-fw-3.1"
202 mv LICENSE.ipw2200-fw "${tempFirmwareDir}/${driver}/"
203 mv ipw2200-ibss.fw "${tempFirmwareDir}/${driver}/"
204 mv ipw2200-sniffer.fw "${tempFirmwareDir}/${driver}/"
205 mv ipw2200-bss.fw "${tempFirmwareDir}/${driver}/"
207 rm "${tempFirmwareDir}/${driver}/${file}"
208 PostFirmwareInstallation
212 function InstallBroadcom43xx()
214 driver='broadcom43xx'
215 PreFirmwareInstallation
217 BuildBroadcomFWCutter
218 returnCode=$?
219 if [ $returnCode -gt 0 ] ; then
220 echo "...failed. ${driver}'s firmware will not be installed."
221 return $returnCode
224 CutAndInstallBroadcomFirmware
225 returnCode=$?
226 if [ $returnCode -gt 0 ] ; then
227 echo "...failed. ${driver}'s firmware will not be installed."
228 return $returnCode
231 PostFirmwareInstallation
235 function InstallMarvell88w8335()
237 driver='marvell88w8335'
238 PreFirmwareInstallation
240 # Download firmware archive.
241 local file="malo-firmware-1.4.tgz"
242 local url="${baseURL}/marvell/${file}"
243 local dir="${tempFirmwareDir}/${driver}"
244 DownloadFileIfNotCached $url $file "$dir"
245 if [ $result -gt 0 ]; then
246 echo "...failed. ${driver}'s firmware will not be installed."
247 return $result
250 # Extract archive.
251 cd "$tempDir"
252 tar xf "${tempFirmwareDir}/${driver}/$file"
254 # Move firmware files to destination.
255 local sourceDir="${tempDir}/share/examples/malo-firmware"
256 mv ${sourceDir}/malo8335-h "${tempFirmwareDir}/${driver}"
257 mv ${sourceDir}/malo8335-m "${tempFirmwareDir}/${driver}"
259 rm "${tempFirmwareDir}/${driver}/${file}"
260 PostFirmwareInstallation
264 function BuildBroadcomFWCutter()
266 # Download & extract b43-fwcutter.
267 local file="b43-fwcutter-012.tar.bz2"
268 local dir="${tempFirmwareDir}/${driver}/b43-fwcutter"
269 local url="${baseURL}/b43/fwcutter/${file}"
270 DownloadFileIfNotCached $url $file $dir
271 if [ $result -gt 0 ]; then
272 return $result
275 # Extract archive.
276 cd "$tempDir"
277 tar xjf "$dir/$file"
279 # Download additonal files for building b43-fwcutter.
280 cd b43-fwcutter-012
281 local baseURL='http://cgit.haiku-os.org/haiku/plain/src/system/libroot/posix/glibc'
282 DownloadFileIfNotCached ${baseURL}/string/byteswap.h byteswap.h $dir
283 if [ $result -gt 0 ]; then
284 return $result
286 DownloadFileIfNotCached ${baseURL}/include/arch/x86/bits/byteswap.h byteswap.h $dir/bits
287 if [ $result -gt 0 ]; then
288 return $result
291 # Copy those files to working directory.
292 mkdir -p bits
293 cp $dir/byteswap.h .
294 cp $dir/bits/byteswap.h bits/
296 # Build b43-fwcutter.
297 echo "Compiling b43-fwcutter for installing Broadcom's firmware ..."
298 make PREFIX=/boot/system CFLAGS="-I. -Wall -D_BSD_SOURCE" > /dev/null 2>&1
299 result=$?
300 if [ $result -gt 0 ]; then
301 echo "... failed to compile b43-fwcutter."
302 else
303 echo "... successfully compiled b43-fwcutter."
305 if [ ! -e b43-fwcutter ] ; then
306 return 1
308 mv b43-fwcutter "$tempDir"
310 cd "${tempFirmwareDir}/${driver}/b43-fwcutter"
311 rm b43-fwcutter-012.tar.bz2
312 rm byteswap.h
313 rm bits/byteswap.h
314 rmdir bits
315 cd ..
316 rmdir b43-fwcutter
318 return 0
322 function CutAndInstallBroadcomFirmware()
324 # Download firmware.
325 local file="wl_apsta-3.130.20.0.o"
326 local dir="${tempFirmwareDir}/${driver}"
327 local url="${baseURL}/b43/${file}"
328 DownloadFileIfNotCached $url $file $dir
329 if [ $result -gt 0 ]; then
330 return $result
333 # Cut firmware in pieces.
334 cp "$dir/$file" "$tempDir"
335 cd "$tempDir"
336 b43-fwcutter $file > /dev/null 2>&1
338 # Rename the pieces.
339 cd b43legacy
340 for i in $(ls -1); do
341 newFileName=$(echo $i | sed "s/\(.*\)\.fw$/bwi_v3_\1/g")
342 mv $i $newFileName
343 done
344 touch bwi_v3_ucode
346 # Install files.
347 mv * ${tempFirmwareDir}/${driver}/
349 rm "${tempFirmwareDir}/${driver}/$file"
350 return 0
354 function makePackageInfo()
356 cat << EOF > .PackageInfo
357 name wifi_firmwares
358 version 2013_10_06-1
359 architecture any
360 summary "Firmwares for various wireless network cards"
361 description "Installs firmwares for the following wireless network cards:
362 Broadcom 43xx, Intel ipw2100, Intel ipw2200, and Marvell 88W8335.
363 Firmware for broadcom43xx is under the Copyright of Broadcom Corporation(R).
364 Firmware for marvell88w8335 is under the Copyright of Marvell Technology(R).
365 ipw2100,iprowifi2200 firmware is covered by the Intel(R) license located in
366 /boot/system/data/licenses/Intel (2xxx firmware). The user is not granted a
367 license to use the package unless these terms are agreed to."
369 packager "me"
370 vendor "myself"
371 copyrights {
372 "Copyright of Broadcom Corporation(R)"
373 "Copyright of Intel(R) Corporation"
374 "Copyright of Marvell Technology(R)"
376 licenses "Intel (2xxx firmware)"
377 flags {
378 "approve_license"
379 "system_package"
381 provides {
382 wifi_firmwares = 2013_10_06
384 requires {
392 function MakeHPKG()
394 cd "$tempFirmwareDir/../../.."
395 makePackageInfo
396 package create -C system -i .PackageInfo wifi_firmwares-1-any.hpkg
397 mv wifi_firmwares-1-any.hpkg `finddir B_SYSTEM_PACKAGES_DIRECTORY`
398 rm -rf "`finddir B_SYSTEM_TEMP_DIRECTORY`/package_me"
399 rm -rf "$tempDir"
403 mkdir -p "$tempDir"
404 mkdir -p "$tempFirmwareDir"
405 DisplayAlert