Showing posts with label firmware. Show all posts
Showing posts with label firmware. Show all posts

Saturday, 5 September 2009

Wireless Firmware Through a Virtual Machine

Herein I present yet another way of getting a hold of the firmware you need to have a functioning wireless connection on a Linux Live CD, which you may wish to use because:

a) you do not already have a working wireless connection on a Linux machine otherwise you wouldn't be reading this crap; or
b) you do not have a 50m CAT5 network cable to connect to your router; or
c) ndiswrapper won't work - staggering I know.
d) life is too damn short to read the instructions on how to make ndiswrapper work.

For this method you will need:

A computer with a working internet connection (wired, wireless, doesn't matter) capable of running some sort of virtualisation software, such as Virtual PC, VMWare Player, or VirtualBox.
An Ubuntu Live CD image.
A USB Key

Step One.
Setup your virtual machine so that it boots from your Live CD image, and shares your Host machine's internet connection. The exact method will vary depending on which of the virtualisation software options you choose. You will need a sensible amount of RAM dedicated to the virtual machine - say 512Mb, and you do not need to bother with a Hard Disk image, we will not be installing.

Step Two.
Boot the Live CD in the Virtual environment.

Step Three.
Check the internet connection is working, by opening a web browser. If not working, go back to Step One and fix it.

Step Four.
Install b43-fwcutter.
Open a terminal window and type:
sudo apt-get install b43-fwcutter
'apt-get' is an ubuntu command to download a piece of software from the ubuntu servers. The install option installs the software once it has been downloaded. The 'b43-fwcutter' program is a utility to get the firmware that is the holy grail of this post. As part of the installation procedure you will be asked to agree to download and install the firmware. Say yes. If you panic and say no, then rerunning the above command will not work. Instead you have to run:
sudo dpkg-reconfigure b43-fwcutter
Step Five.
If you now look in /lib/firmware/ you will find the b43 folder referred to in my first post. You can just copy the contents of that folder onto your usb key and use them in the way described in said post. If your virtualisation software will not let you use a USB key (I don't think that the free version of virtualbox will) then archive the b43 folder (down to a massive 40k) and gmail or hotmail it to yourself. Exit to your host operating system, get your email attachment, open it and save to your USB key.

Step Six.
Proceed as per the first post, Step Three.

Friday, 4 September 2009

Wireless Firmware Through Ndiswrapper

In my previous post, I set out a way to load broadcom firmware into a running Live CD distribution.

I said you had to firstly copy the firmware from an installation with wireless up and running which some what defeated the point. In order to avoid turning the last post into War and fucking Peace I avoided getting bogged down in the alternative ways to get a hold of the broadcom firmware files. I present hereunder the ndiswrapper method. You will need:

An Ubuntu Live CD
A USB Key
The Windows drivers for the card
Ndiswrapper deb files.

Step One.
Download the latest ubuntu live cd, and burn or use unetbootin to install it to a usb stick.

Step Two.
Download the windows wireless drivers for your card. Extract the file and find the 'Drivers' folder. It should contain three files, *.sys, *.inf, and *.cat. Those three are all you need. Copy them to a folder on the USB Key called 'drivers'.

Step Three.
Download the ndiswrapper deb files.
Ndiswrapper is a linux utility to wrap windows drivers up in linux code so they can be used on linux. It may be installed already on your Live CD. Best to get the .deb files (ubuntu install files) just in case.
You will need to download ndiswrapper-common, ndiswrapper-utils, and ndisgtk. Copy the .deb files into the 'drivers' folder on your USB Key.

Step Four.
Boot the Live CD. Mount your USB key.

Step Five.
Make sure that no ndiswrapper installation is hanging about already by running these commands in a terminal window:
sudo modprobe -r ndiswrapper
sudo ndiswrapper -r bcmwl5
sudo apt-get remove ndiswrapper-utils-1.9
sudo rm -r /etc/ndiswrapper/
sudo rm -r /etc/modprobe.d/ndiswrapper
Step Six.
Install ndiswrapper.
Open a terminal window, and navigate to your usb key 'drivers' directory. For instance:
cd /media/disk/drivers
Then run these commands [WARNING make sure the file names match up. So, if you have downloaded a more up to date version of these, change the file names. Run the 'ls' command to check the full filenames]:
sudo dpkg -i ./ndiswrapper-common_1.50-1ubuntu1_all.deb
sudo dpkg -i ./ndiswrapper-utils-1.9_1.50-1ubuntu1_i386.deb
sudo dpkg -i ./ndisgtk_0.8.3-1_i386.deb
The './' before the filename just tells linux that the file that comes next is in the current folder.

Step Seven.
Run ndiswrapper from the terminal using this command:
sudo ndisgtk
You then use the gui that pops up to locate the *.inf file for the appropriate driver. This is the file you copied in Step Two above.

Step Eight.
At this stage you may think you have managed to get wireless functioning, after all there is a nice box on the screen saying 'Hardware Detected: Yes'. Oh, you poor naive fool. The chances are that the b43 driver module is still hogging the wireless card. To check this run in a terminal:
sudo lshw -C network 
and check for driver=b43... instead of driver=ndis...
If that is the case run these commands in terminal:
sudo rmmod b43
sudo rmmod b44
sudo rmmod b43legacy
sudo rmmod wl
sudo rmmod ssb
sudo rmmod ndiswrapper
sudo modprobe ndiswrapper
sudo modprobe ssb
sudo modprobe b44 
You then run the:
sudo lshw -C network 
command again, and the b43 should have changed to ndis...

Step Nine.
Log onto your wireless network using network manager.

Step Ten.
Install b43-fwcutter.
Open a terminal window and type:
sudo apt-get install b43-fwcutter
'apt-get' is an ubuntu command to download a piece of software from the ubuntu servers. The install option installs the software once it has been downloaded. The 'b43-fwcutter' program is a utility to get the firmware that is the holy grail of this post. As part of the installation procedure you will be asked to agree to download and install the firmware. Say yes. If you panic and say no, then rerunning the above command will not work. Instead you have to run:
sudo dpkg-reconfigure b43-fwcutter
Step Eleven.
If you now look in /lib/firmware/ you will find the b43 folder referred to in my previous post. You can just copy the contents of that folder onto your usb stick and use them in the way described in said post.

Step Twelve.
(This is the important bit)
Save the b43 folder and it's contents somewhere safe. You will reuse this everytime you want to install linux or boot a Live CD on your machine. It is really easy - it is a tiny directory. It p7zips to 40k. But remember - do not email to anyone that needs it and can't be arsed going through the previous eleven steps, because that would be wrong.

Broadcom Firmware on Live CD

I use linksys wmp54gs wireless cards on my desktop and server machines. I want to try a linux distribution. I download a Live CD and boot the machine. I get crap screen resolution and no internet connection. There is no obvious reason why this is the case.

It turns out, after much googling, that my wireless cards use a chipset made by broadcom. Linux is supposed to have the drivers for this chipset built in. So what gives?

Well, it turns out that it you need TWO pieces of software to get this card working. You need the driver which, as with more mainstream operating systems, sits between the OS and the hardware. There is indeed an open source version of this which is bundled into the linux OS (or kernel). However, you ALSO need the firmware. This is code which runs on the wireless card itself. There is no open source firmware bundled into the linux kernel.

If one is being charitible, one would say that modern network cards are actually mini computers in their own right, and therefore need their own software loaded onto them. If one was feeling cynical one would say that the manufacturers are a bunch of bastards who value obfuscation of function over ease of use. After all, if you try to reverse engineer a network card missing its firmware you are not going to get very far.

Still if you wanted to get a hold of broadcom firmware, it is not difficult. They give it away. They just do not allow anyone else to give it away. With Windows, for instance, all of this is transparent because the driver CD you got or the driver you downloaded comes with the firmware in it. With linux, however, it is a problem because Broadcom will not allow any linux distribution to put the firmware on the CD. Because they are gits.

The solution is to download the firmware once you have booted the CD. Which is a great idea. Oh, except for that rare situation were you do not have an internet connection because your fucking wireless connection is not working. Welcome to the chicken and egg dilemma. You can't get your internet connection working until you get your internet connection working.

With a Windows PC you would, at this point, slip in the driver CD and load up the necessary drivers/firmware from that. No linux drivers on the CD though. Bugger. The windows alternative to a driver CD would be to download the drivers from broadcom on some other machine and move them by USB (or whatever) to the wireless-less machine.

I should point out at this stage that there is a webpage which tries to explain all this. It is a master piece of how not to get across information to someone who just cannot get a god damned wireless card to work. The headline story - that firmware is independent of the drivers - is halfway down the fucking page. The first sentence of the whole page reads "The b43 drivers (bcm43xx in mainline kernels, b43 and b43legacy in wireless-2.6 and 2.6.24 and later) are drivers for the 802.11 B/G family of wireless chips Broadcom produces." In terms of communication, it just goes downhill from there. I expect more from the number two google search result for "linux wireless broadcom".

What I therefore now present is a way to load the firmware onto a running Live CD.

Step Zero.
You need the firmware files. You can get them one of four ways. You can use a PC which already has a working wireless connection in Linux. See above for the amusing catch-22-ness of this solution. Alternatively you can temporarily use windows drivers to at least get online and download them in Linux, or you could use a virtual machine running on a PC with some other OS connected to the internet, or you can use a wired connection. What you could NOT do is leave a comment here asking for a zip of the extracted firmware files, because I am not allowed to distribute them and could not email them to you in a helpful manner. I will deal with using windows drivers and virtual machines in another post, so lets just assume you have somehow got the firmware files installed on your running PC.

Step One.
Get a USB key. Make a directory on the key called, firmware.
I talk a lot about Live CD images above, but really I normally use unetbootin to put the Live CD on a USB key. There should be room on the key to put the firmware on afterwards, it is not that big. You could also partition the key and put the firmware in a different partition to the Live CD image, which would let you swap around Live CD images without having to redo the first few steps here. Partitioning is a whole other topic though.

Step Two.
Copy the folder /lib/firmware/b43 to the usb key firmware directory.
All the linux firmware is kept in the /lib/firmware directory. I understand that some distributions keep the firmware somewhere else. If you have one of those I would recommend trying to find out where your /lib/firmware directory is.

Step Three.
Boot the Live CD (or USB, you know what I mean).
Mount your USB key. If using a sensible distribution, this is as simple as plugging it in. If not you will have to acquaint yourself with the contents of the /dev/ and /media/ directories and the mount command.

Step Four.
On the assumption that your usb key has been mounted to /media/disk, which mine invariably is, you can then just run the following commands in a terminal window:

sudo mkdir /lib/firmware/b43

This [m]a[k]es a folder (or [dir]ectory) in your local /lib/firmware/ folder ready for the firmware. Because this command affects the system area of linux the [s]uper[u]ser (or root) needs to [do] this command.

Step Five.
sudo cp /media/disk/firmware/*.* /lib/firmware/b43/
This copies the firmware file from your USB key to the local system. Note the [/disk/] part of the command - if your USB key mounts to somewhere else you need to change that.

Step Six.
sudo rmmod b43
This shutsdown the wireless driver. Techically it [r]e[m]oves the broadcom driver [mod]ule 'b43'. For these purposes a module is something which deals with hardware and could be in the kernel, but is kept out. It can be loaded or shutdown at will - think of it as a running program.

Step Seven.
sudo modprobe b43
This runs the wireless driver again. This time it will find the b43 folder in /lib/firmware/ and load the files from it onto the card. Assuming this works, you can then configure your internet connection using your usual Live CD network manager.