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