1#!/bin/sh 2# 3# Copyright (c) 2010 Haiku Inc. All rights reserved. 4# Distributed under the terms of the MIT License. 5# 6# Authors: 7# Matt Madia, mattmadia@gmail.com 8# 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. 12# 13# Supported chipsets: 14# Intel ipw2100 15# Intel ipw2200/2225/2915 16# Broadcom 43xx 17# Marvell 88W8335 18 19 20MESSAGE="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. 24 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." 30VIEW='View licenses' 31ABORT='Abort installation' 32OK='I agree to the licenses. Install firmwares.' 33 34firmwareDir=`finddir B_SYSTEM_DATA_DIRECTORY`/firmware 35tempDir=`finddir B_COMMON_TEMP_DIRECTORY`/wifi-firmwares 36driversDir=`finddir B_SYSTEM_ADDONS_DIRECTORY`/kernel/drivers 37intelLicense='/boot/system/data/licenses/Intel (2xxx firmware)' 38 39 40function DisplayAlert() 41{ 42 local result=`alert --stop "$MESSAGE" "$VIEW" "$ABORT" "$OK"` 43 case "${result}" in 44 "$VIEW") 45 ViewLicenses ; 46 DisplayAlert ; 47 ;; 48 "$ABORT") 49 exit 0 ;; 50 "$OK") 51 InstallAllFirmwares ; 52 exit 0 ; 53 ;; 54 esac 55} 56 57 58function ViewLicenses() 59{ 60 license="$tempDir/Wifi_Firmware_Licenses" 61 cat << EOF > $license 62 63+-----------------------------------------------------------------------------+ 64| | 65| Copyright and licensing information of the various wireless firmwares | 66| | 67| Firmware for broadcom43xx is under the Copyright of Broadcom Corporation(R) | 68| Firmware for marvell88w8335 is under the Copyright of Marvell Technology(R) | 69| ipw2100,iprowifi2200 firmware is covered by the following Intel(R) license: | 70| | 71+-----------------------------------------------------------------------------+ 72 73EOF 74 cat "$intelLicense" >> $license 75 76 open $license 77} 78 79 80function InstallAllFirmwares() 81{ 82 InstallIpw2100 83 InstallIprowifi2200 84 InstallBroadcom43xx 85 InstallMarvell88w8335 86} 87 88 89function UnlinkDriver() 90{ 91 # remove the driver's symlink 92 rm -f "${driversDir}/dev/net/${driver}" 93} 94 95 96function SymlinkDriver() 97{ 98 # restore the driver's symlink 99 cd "${driversDir}/dev/net/" 100 ln -sf "../../bin/${driver}" "${driver}" 101} 102 103 104function DownloadFileIfNotCached() 105{ 106 # DownloadFileIfNotCached <url> <filename> <destination dir> 107 local url=$1 108 local file=$2 109 local dir=$3 110 111 mkdir -p "$dir" 112 if [ ! -e $dir/$file ] ; then 113 echo "Downloading $url ..." 114 wget -nv -O $dir/$file $url 115 fi 116 result=$? 117 if [ $result -gt 0 ]; then 118 local error="Failed to download $url." 119 local msg="As a result, ${driver}'s firmware will not be installed." 120 alert --warning "$error $msg" 121 fi 122 123} 124 125 126function OpenIntelFirmwareWebpage() 127{ 128 # OpenIntelFirmwareWebpage <url> <file> 129 local url="$1" 130 local file="$2" 131 132 echo "Downloading $file ..." 133 alert --info "A webpage is going to open. Download and save $file in ${firmwareDir}/${driver}/" 134 135 open "$url" 136 137 alert --info "Click OK after the $file has been saved in ${firmwareDir}/${driver}/" 138} 139 140 141function SetFirmwarePermissions() 142{ 143 cd ${firmwareDir}/${driver}/ 144 for file in * ; do 145 if [ "$file" != "$driver" ] ; then 146 chmod a=r $file 147 fi 148 done 149} 150 151 152function CleanTemporaryFiles() 153{ 154 rm -rf "$tempDir" 155 mkdir -p "$tempDir" 156} 157 158 159function PreFirmwareInstallation() 160{ 161 mkdir -p "${firmwareDir}/${driver}" 162 UnlinkDriver 163} 164 165 166function PostFirmwareInstallation() 167{ 168 SetFirmwarePermissions 169 SymlinkDriver 170 CleanTemporaryFiles 171} 172 173 174function InstallIpw2100() 175{ 176 driver='ipw2100' 177 PreFirmwareInstallation 178 179 # Extract contents. 180 local file='ipw2100-fw-1.3.tgz' 181 182 # In case the file doesn's exist. 183 if [ ! -e ${firmwareDir}/${driver}/$file ] ; then 184 url='http://ipw2100.sourceforge.net/firmware.php?fid=4' 185 OpenIntelFirmwareWebpage $url $file 186 fi 187 # TODO: handle when $file hasn't been saved in ${firmwareDir}/${driver}/ 188 189 # Install the firmware & license file by extracting in place. 190 cd "${firmwareDir}/${driver}" 191 gunzip < "$file" | tar xf - 192 193 PostFirmwareInstallation 194} 195 196 197function InstallIprowifi2200() 198{ 199 driver='iprowifi2200' 200 PreFirmwareInstallation 201 202 # Extract contents. 203 local file='ipw2200-fw-3.1.tgz' 204 205 # In case the file doesn't exist. 206 if [ ! -e ${firmwareDir}/${driver}/$file ] ; then 207 url=http://ipw2200.sourceforge.net/firmware.php?fid=8 208 OpenIntelFirmwareWebpage $url $file 209 fi 210 # TODO: handle when $file hasn't been saved in ${firmwareDir}/${driver}/ 211 212 cd "$tempDir" 213 gunzip < "${firmwareDir}/${driver}/$file" | tar xf - 214 215 # Install the firmware & license file. 216 cd "${tempDir}/ipw2200-fw-3.1" 217 mv LICENSE.ipw2200-fw "${firmwareDir}/${driver}/" 218 mv ipw2200-ibss.fw "${firmwareDir}/${driver}/" 219 mv ipw2200-sniffer.fw "${firmwareDir}/${driver}/" 220 mv ipw2200-bss.fw "${firmwareDir}/${driver}/" 221 222 PostFirmwareInstallation 223} 224 225 226function InstallBroadcom43xx() 227{ 228 driver='broadcom43xx' 229 PreFirmwareInstallation 230 231 BuildBroadcomFWCutter 232 returnCode=$? 233 if [ $returnCode -gt 0 ] ; then 234 echo "...failed. ${driver}'s firmware will not be installed." 235 return $returnCode 236 fi 237 238 CutAndInstallBroadcomFirmware 239 returnCode=$? 240 if [ $returnCode -gt 0 ] ; then 241 echo "...failed. ${driver}'s firmware will not be installed." 242 return $returnCode 243 fi 244 245 PostFirmwareInstallation 246} 247 248 249function InstallMarvell88w8335() 250{ 251 driver='marvell88w8335' 252 PreFirmwareInstallation 253 254 # Download firmware archive. 255 local file="malo-firmware-1.4.tgz" 256 local url='http://www.nazgul.ch/malo/malo-firmware-1.4.tgz' 257 local dir="${firmwareDir}/${driver}" 258 DownloadFileIfNotCached $url $file "$dir" 259 if [ $result -gt 0 ]; then 260 echo "...failed. ${driver}'s firmware will not be installed." 261 return $result 262 fi 263 264 # Extract archive. 265 cd "$tempDir" 266 tar xf "${firmwareDir}/${driver}/$file" 267 268 # Move firmware files to destination. 269 local sourceDir="${tempDir}/share/examples/malo-firmware" 270 mv ${sourceDir}/malo8335-h "${firmwareDir}/${driver}" 271 mv ${sourceDir}/malo8335-m "${firmwareDir}/${driver}" 272 PostFirmwareInstallation 273} 274 275 276function BuildBroadcomFWCutter() 277{ 278 # Download & extract b43-fwcutter. 279 local file="b43-fwcutter-012.tar.bz2" 280 local dir="${firmwareDir}/${driver}/b43-fwcutter" 281 local url="http://bu3sch.de/b43/fwcutter/b43-fwcutter-012.tar.bz2" 282 DownloadFileIfNotCached $url $file $dir 283 if [ $result -gt 0 ]; then 284 return $result 285 fi 286 287 # Extract archive. 288 cd "$tempDir" 289 tar xjf "$dir/$file" 290 291 # Download additonal files for building b43-fwcutter. 292 cd b43-fwcutter-012 293 local baseURL='http://svn.haiku-os.org/haiku/haiku/trunk/src/system/libroot/posix/glibc' 294 DownloadFileIfNotCached ${baseURL}/string/byteswap.h byteswap.h $dir 295 if [ $result -gt 0 ]; then 296 return $result 297 fi 298 DownloadFileIfNotCached ${baseURL}/include/arch/x86/bits/byteswap.h byteswap.h $dir/bits 299 if [ $result -gt 0 ]; then 300 return $result 301 fi 302 303 # Copy those files to working directory. 304 mkdir -p bits 305 cp $dir/byteswap.h . 306 cp $dir/bits/byteswap.h bits/ 307 308 # Build b43-fwcutter. 309 echo "Compiling b43-fwcutter for installing Broadcom's firmware ..." 310 make PREFIX=/boot/common CFLAGS="-I. -Wall -D_BSD_SOURCE" > /dev/null 2>&1 311 if [ ! -e b43-fwcutter ] ; then 312 return 1 313 fi 314 mv b43-fwcutter "$tempDir" 315 316 return 0 317} 318 319 320function CutAndInstallBroadcomFirmware() 321{ 322 # Download firmware. 323 local file="wl_apsta-3.130.20.0.o" 324 local dir="${firmwareDir}/${driver}" 325 local url='http://downloads.openwrt.org/sources/wl_apsta-3.130.20.0.o' 326 DownloadFileIfNotCached $url $file $dir 327 if [ $result -gt 0 ]; then 328 return $result 329 fi 330 331 # Cut firmware in pieces. 332 cp "$dir/$file" "$tempDir" 333 cd "$tempDir" 334 b43-fwcutter $file > /dev/null 2>&1 335 336 # Rename the pieces. 337 cd b43legacy 338 for i in $(ls -1); do 339 newFileName=$(echo $i | sed "s/\(.*\)\.fw$/bwi_v3_\1/g") 340 mv $i $newFileName 341 done 342 touch bwi_v3_ucode 343 344 # Install files. 345 mv * ${firmwareDir}/${driver}/ 346 347 return 0 348} 349 350 351mkdir -p "$tempDir" 352DisplayAlert 353