1#!/bin/sh 2# 3# Copyright (c) 2010-2012 Haiku, Inc. 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 34baseURL='http://www.haiku-files.org/files/wifi-firmwares' 35firmwareDir=`finddir B_SYSTEM_DATA_DIRECTORY`/firmware 36tempDir=`finddir B_SYSTEM_TEMP_DIRECTORY`/wifi-firmwares 37driversDir=`finddir B_SYSTEM_ADDONS_DIRECTORY`/kernel/drivers 38tempFirmwareDir=`finddir B_SYSTEM_TEMP_DIRECTORY`/package_me"$firmwareDir" 39intelLicense='/boot/system/data/licenses/Intel (2xxx firmware)' 40 41 42function DisplayAlert() 43{ 44 local result=`alert --stop "$MESSAGE" "$VIEW" "$ABORT" "$OK"` 45 case "${result}" in 46 "$VIEW") 47 ViewLicenses ; 48 DisplayAlert ; 49 ;; 50 "$ABORT") 51 exit 0 ;; 52 "$OK") 53 InstallAllFirmwares ; 54 exit 0 ; 55 ;; 56 esac 57} 58 59 60function ViewLicenses() 61{ 62 license="$tempDir/Wifi_Firmware_Licenses" 63 cat << EOF > $license 64 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+-----------------------------------------------------------------------------+ 74 75EOF 76 cat "$intelLicense" >> $license 77 78 open $license 79} 80 81 82function InstallAllFirmwares() 83{ 84 InstallIpw2100 85 InstallIprowifi2200 86 InstallBroadcom43xx 87 InstallMarvell88w8335 88 MakeHPKG 89} 90 91 92function UnlinkDriver() 93{ 94 # remove the driver's symlink 95 #rm -f "${driversDir}/dev/net/${driver}" 96 echo "TODO: UnlinkDriver" 97} 98 99 100function SymlinkDriver() 101{ 102 # restore the driver's symlink 103 #cd "${driversDir}/dev/net/" 104 #ln -sf "../../bin/${driver}" "${driver}" 105 echo "TODO: SymlinkDriver" 106} 107 108 109function DownloadFileIfNotCached() 110{ 111 # DownloadFileIfNotCached <url> <filename> <destination dir> 112 local url=$1 113 local file=$2 114 local dir=$3 115 116 mkdir -p "$dir" 117 if [ ! -e $dir/$file ] ; then 118 echo "Downloading $url ..." 119 wget -nv -O $dir/$file $url 120 fi 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" 126 fi 127} 128 129 130function SetFirmwarePermissions() 131{ 132 cd ${tempFirmwareDir}/${driver}/ 133 for file in * ; do 134 if [ "$file" != "$driver" ] && [ -f "$file" ] ; then 135 chmod a=r $file 136 fi 137 done 138} 139 140 141function CleanTemporaryFiles() 142{ 143 rm -rf "$tempDir" 144 mkdir -p "$tempDir" 145} 146 147 148function PreFirmwareInstallation() 149{ 150 echo "Installing firmware for ${driver} ..." 151 mkdir -p "${tempFirmwareDir}/${driver}" 152 UnlinkDriver 153} 154 155 156function PostFirmwareInstallation() 157{ 158 SetFirmwarePermissions 159 SymlinkDriver 160 CleanTemporaryFiles 161 echo "... firmware for ${driver} has been installed." 162} 163 164 165function InstallIpw2100() 166{ 167 driver='iprowifi2100' 168 PreFirmwareInstallation 169 170 # Extract contents. 171 local file='ipw2100-fw-1.3.tgz' 172 local url="${baseURL}/intel/${file}" 173 local dir="${tempFirmwareDir}/${driver}" 174 DownloadFileIfNotCached $url $file $dir 175 176 # Install the firmware & license file by extracting in place. 177 cd "${tempFirmwareDir}/${driver}" 178 gunzip < "$file" | tar xf - 179 180 rm "${tempFirmwareDir}/${driver}/${file}" 181 PostFirmwareInstallation 182} 183 184 185function InstallIprowifi2200() 186{ 187 driver='iprowifi2200' 188 PreFirmwareInstallation 189 190 # Extract contents. 191 local file='ipw2200-fw-3.1.tgz' 192 local url="${baseURL}/intel/${file}" 193 local dir="${tempFirmwareDir}/${driver}" 194 DownloadFileIfNotCached $url $file $dir 195 196 cd "$tempDir" 197 gunzip < "${tempFirmwareDir}/${driver}/$file" | tar xf - 198 199 # Install the firmware & license file. 200 cd "${tempDir}/ipw2200-fw-3.1" 201 mv LICENSE.ipw2200-fw "${tempFirmwareDir}/${driver}/" 202 mv ipw2200-ibss.fw "${tempFirmwareDir}/${driver}/" 203 mv ipw2200-sniffer.fw "${tempFirmwareDir}/${driver}/" 204 mv ipw2200-bss.fw "${tempFirmwareDir}/${driver}/" 205 206 rm "${tempFirmwareDir}/${driver}/${file}" 207 PostFirmwareInstallation 208} 209 210 211function InstallBroadcom43xx() 212{ 213 driver='broadcom43xx' 214 PreFirmwareInstallation 215 216 BuildBroadcomFWCutter 217 returnCode=$? 218 if [ $returnCode -gt 0 ] ; then 219 echo "...failed. ${driver}'s firmware will not be installed." 220 return $returnCode 221 fi 222 223 CutAndInstallBroadcomFirmware 224 returnCode=$? 225 if [ $returnCode -gt 0 ] ; then 226 echo "...failed. ${driver}'s firmware will not be installed." 227 return $returnCode 228 fi 229 230 PostFirmwareInstallation 231} 232 233 234function InstallMarvell88w8335() 235{ 236 driver='marvell88w8335' 237 PreFirmwareInstallation 238 239 # Download firmware archive. 240 local file="malo-firmware-1.4.tgz" 241 local url="${baseURL}/marvell/${file}" 242 local dir="${tempFirmwareDir}/${driver}" 243 DownloadFileIfNotCached $url $file "$dir" 244 if [ $result -gt 0 ]; then 245 echo "...failed. ${driver}'s firmware will not be installed." 246 return $result 247 fi 248 249 # Extract archive. 250 cd "$tempDir" 251 tar xf "${tempFirmwareDir}/${driver}/$file" 252 253 # Move firmware files to destination. 254 local sourceDir="${tempDir}/share/examples/malo-firmware" 255 mv ${sourceDir}/malo8335-h "${tempFirmwareDir}/${driver}" 256 mv ${sourceDir}/malo8335-m "${tempFirmwareDir}/${driver}" 257 258 rm "${tempFirmwareDir}/${driver}/${file}" 259 PostFirmwareInstallation 260} 261 262 263function BuildBroadcomFWCutter() 264{ 265 # Download & extract b43-fwcutter. 266 local file="b43-fwcutter-012.tar.bz2" 267 local dir="${tempFirmwareDir}/${driver}/b43-fwcutter" 268 local url="${baseURL}/b43/fwcutter/${file}" 269 DownloadFileIfNotCached $url $file $dir 270 if [ $result -gt 0 ]; then 271 return $result 272 fi 273 274 # Extract archive. 275 cd "$tempDir" 276 tar xjf "$dir/$file" 277 278 # Download additonal files for building b43-fwcutter. 279 cd b43-fwcutter-012 280 local baseURL='http://cgit.haiku-os.org/haiku/plain/src/system/libroot/posix/glibc' 281 DownloadFileIfNotCached ${baseURL}/string/byteswap.h byteswap.h $dir 282 if [ $result -gt 0 ]; then 283 return $result 284 fi 285 DownloadFileIfNotCached ${baseURL}/include/arch/x86/bits/byteswap.h byteswap.h $dir/bits 286 if [ $result -gt 0 ]; then 287 return $result 288 fi 289 290 # Copy those files to working directory. 291 mkdir -p bits 292 cp $dir/byteswap.h . 293 cp $dir/bits/byteswap.h bits/ 294 295 # Build b43-fwcutter. 296 echo "Compiling b43-fwcutter for installing Broadcom's firmware ..." 297 make PREFIX=/boot/system CFLAGS="-I. -Wall -D_BSD_SOURCE" > /dev/null 2>&1 298 result=$? 299 if [ $result -gt 0 ]; then 300 echo "... failed to compile b43-fwcutter." 301 else 302 echo "... successfully compiled b43-fwcutter." 303 fi 304 if [ ! -e b43-fwcutter ] ; then 305 return 1 306 fi 307 mv b43-fwcutter "$tempDir" 308 309 cd "${tempFirmwareDir}/${driver}/b43-fwcutter" 310 rm b43-fwcutter-012.tar.bz2 311 rm byteswap.h 312 rm bits/byteswap.h 313 rmdir bits 314 cd .. 315 rmdir b43-fwcutter 316 317 return 0 318} 319 320 321function CutAndInstallBroadcomFirmware() 322{ 323 # Download firmware. 324 local file="wl_apsta-3.130.20.0.o" 325 local dir="${tempFirmwareDir}/${driver}" 326 local url="${baseURL}/b43/${file}" 327 DownloadFileIfNotCached $url $file $dir 328 if [ $result -gt 0 ]; then 329 return $result 330 fi 331 332 # Cut firmware in pieces. 333 cp "$dir/$file" "$tempDir" 334 cd "$tempDir" 335 b43-fwcutter $file > /dev/null 2>&1 336 337 # Rename the pieces. 338 cd b43legacy 339 for i in $(ls -1); do 340 newFileName=$(echo $i | sed "s/\(.*\)\.fw$/bwi_v3_\1/g") 341 mv $i $newFileName 342 done 343 touch bwi_v3_ucode 344 345 # Install files. 346 mv * ${tempFirmwareDir}/${driver}/ 347 348 rm "${tempFirmwareDir}/${driver}/$file" 349 return 0 350} 351 352 353function makePackageInfo() 354{ 355 cat << EOF > .PackageInfo 356name wifi_firmwares 357version 2013_10_06-1 358architecture any 359summary "Firmwares for various wireless network cards" 360description "Installs firmwares for the following wireless network cards: 361Broadcom 43xx, Intel ipw2100, Intel ipw2200, and Marvell 88W8335. 362Firmware for broadcom43xx is under the Copyright of Broadcom Corporation(R). 363Firmware for marvell88w8335 is under the Copyright of Marvell Technology(R). 364ipw2100,iprowifi2200 firmware is covered by the Intel(R) license located in 365/boot/system/data/licenses/Intel (2xxx firmware). The user is not granted a 366license to use the package unless these terms are agreed to." 367 368packager "me" 369vendor "myself" 370copyrights { 371 "Copyright of Broadcom Corporation(R)" 372 "Copyright of Intel(R) Corporation" 373 "Copyright of Marvell Technology(R)" 374} 375licenses "Intel (2xxx firmware)" 376flags { 377 "approve_license" 378 "system_package" 379} 380provides { 381 wifi_firmwares = 2013_10_06 382} 383requires { 384 haiku >= R1~alpha4 385} 386 387EOF 388 389} 390 391 392function MakeHPKG() 393{ 394 cd "$tempFirmwareDir/../.." 395 makePackageInfo 396 package create 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" 400} 401 402 403mkdir -p "$tempDir" 404mkdir -p "$tempFirmwareDir" 405DisplayAlert 406