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 echo "Installing firmware for ${driver} ..." 162 mkdir -p "${firmwareDir}/${driver}" 163 UnlinkDriver 164} 165 166 167function PostFirmwareInstallation() 168{ 169 SetFirmwarePermissions 170 SymlinkDriver 171 CleanTemporaryFiles 172 echo "... firmware for ${driver} has been installed." 173} 174 175 176function InstallIpw2100() 177{ 178 driver='ipw2100' 179 PreFirmwareInstallation 180 181 # Extract contents. 182 local file='ipw2100-fw-1.3.tgz' 183 184 # In case the file doesn's exist. 185 if [ ! -e ${firmwareDir}/${driver}/$file ] ; then 186 url='http://ipw2100.sourceforge.net/firmware.php?fid=4' 187 OpenIntelFirmwareWebpage $url $file 188 fi 189 # TODO: handle when $file hasn't been saved in ${firmwareDir}/${driver}/ 190 191 # Install the firmware & license file by extracting in place. 192 cd "${firmwareDir}/${driver}" 193 gunzip < "$file" | tar xf - 194 195 PostFirmwareInstallation 196} 197 198 199function InstallIprowifi2200() 200{ 201 driver='iprowifi2200' 202 PreFirmwareInstallation 203 204 # Extract contents. 205 local file='ipw2200-fw-3.1.tgz' 206 207 # In case the file doesn't exist. 208 if [ ! -e ${firmwareDir}/${driver}/$file ] ; then 209 url=http://ipw2200.sourceforge.net/firmware.php?fid=8 210 OpenIntelFirmwareWebpage $url $file 211 fi 212 # TODO: handle when $file hasn't been saved in ${firmwareDir}/${driver}/ 213 214 cd "$tempDir" 215 gunzip < "${firmwareDir}/${driver}/$file" | tar xf - 216 217 # Install the firmware & license file. 218 cd "${tempDir}/ipw2200-fw-3.1" 219 mv LICENSE.ipw2200-fw "${firmwareDir}/${driver}/" 220 mv ipw2200-ibss.fw "${firmwareDir}/${driver}/" 221 mv ipw2200-sniffer.fw "${firmwareDir}/${driver}/" 222 mv ipw2200-bss.fw "${firmwareDir}/${driver}/" 223 224 PostFirmwareInstallation 225} 226 227 228function InstallBroadcom43xx() 229{ 230 driver='broadcom43xx' 231 PreFirmwareInstallation 232 233 BuildBroadcomFWCutter 234 returnCode=$? 235 if [ $returnCode -gt 0 ] ; then 236 echo "...failed. ${driver}'s firmware will not be installed." 237 return $returnCode 238 fi 239 240 CutAndInstallBroadcomFirmware 241 returnCode=$? 242 if [ $returnCode -gt 0 ] ; then 243 echo "...failed. ${driver}'s firmware will not be installed." 244 return $returnCode 245 fi 246 247 PostFirmwareInstallation 248} 249 250 251function InstallMarvell88w8335() 252{ 253 driver='marvell88w8335' 254 PreFirmwareInstallation 255 256 # Download firmware archive. 257 local file="malo-firmware-1.4.tgz" 258 local url='http://www.nazgul.ch/malo/malo-firmware-1.4.tgz' 259 local dir="${firmwareDir}/${driver}" 260 DownloadFileIfNotCached $url $file "$dir" 261 if [ $result -gt 0 ]; then 262 echo "...failed. ${driver}'s firmware will not be installed." 263 return $result 264 fi 265 266 # Extract archive. 267 cd "$tempDir" 268 tar xf "${firmwareDir}/${driver}/$file" 269 270 # Move firmware files to destination. 271 local sourceDir="${tempDir}/share/examples/malo-firmware" 272 mv ${sourceDir}/malo8335-h "${firmwareDir}/${driver}" 273 mv ${sourceDir}/malo8335-m "${firmwareDir}/${driver}" 274 PostFirmwareInstallation 275} 276 277 278function BuildBroadcomFWCutter() 279{ 280 # Download & extract b43-fwcutter. 281 local file="b43-fwcutter-012.tar.bz2" 282 local dir="${firmwareDir}/${driver}/b43-fwcutter" 283 local url="http://bu3sch.de/b43/fwcutter/b43-fwcutter-012.tar.bz2" 284 DownloadFileIfNotCached $url $file $dir 285 if [ $result -gt 0 ]; then 286 return $result 287 fi 288 289 # Extract archive. 290 cd "$tempDir" 291 tar xjf "$dir/$file" 292 293 # Download additonal files for building b43-fwcutter. 294 cd b43-fwcutter-012 295 local baseURL='http://svn.haiku-os.org/haiku/haiku/trunk/src/system/libroot/posix/glibc' 296 DownloadFileIfNotCached ${baseURL}/string/byteswap.h byteswap.h $dir 297 if [ $result -gt 0 ]; then 298 return $result 299 fi 300 DownloadFileIfNotCached ${baseURL}/include/arch/x86/bits/byteswap.h byteswap.h $dir/bits 301 if [ $result -gt 0 ]; then 302 return $result 303 fi 304 305 # Copy those files to working directory. 306 mkdir -p bits 307 cp $dir/byteswap.h . 308 cp $dir/bits/byteswap.h bits/ 309 310 # Build b43-fwcutter. 311 echo "Compiling b43-fwcutter for installing Broadcom's firmware ..." 312 make PREFIX=/boot/common CFLAGS="-I. -Wall -D_BSD_SOURCE" > /dev/null 2>&1 313 result=$? 314 if [ $result -gt 0 ]; then 315 echo "... failed to compile b43-fwcutter." 316 else 317 echo "... successfully compiled b43-fwcutter." 318 fi 319 if [ ! -e b43-fwcutter ] ; then 320 return 1 321 fi 322 mv b43-fwcutter "$tempDir" 323 324 return 0 325} 326 327 328function CutAndInstallBroadcomFirmware() 329{ 330 # Download firmware. 331 local file="wl_apsta-3.130.20.0.o" 332 local dir="${firmwareDir}/${driver}" 333 local url='http://downloads.openwrt.org/sources/wl_apsta-3.130.20.0.o' 334 DownloadFileIfNotCached $url $file $dir 335 if [ $result -gt 0 ]; then 336 return $result 337 fi 338 339 # Cut firmware in pieces. 340 cp "$dir/$file" "$tempDir" 341 cd "$tempDir" 342 b43-fwcutter $file > /dev/null 2>&1 343 344 # Rename the pieces. 345 cd b43legacy 346 for i in $(ls -1); do 347 newFileName=$(echo $i | sed "s/\(.*\)\.fw$/bwi_v3_\1/g") 348 mv $i $newFileName 349 done 350 touch bwi_v3_ucode 351 352 # Install files. 353 mv * ${firmwareDir}/${driver}/ 354 355 return 0 356} 357 358 359mkdir -p "$tempDir" 360DisplayAlert 361