I have a Raspberry Pi 2 "model B" (the only rpi2 model) and I wanted to get
this usb wifi driver,
compiled and installed for a linux kernel installed by the "rpi-update" tool.
Unlike a packaged kernel provided by a debian-based linux distro which you may
be using, for example "linux-image-raspi2" which is available in Ubuntu Mate
15.10 armhf (used by the Ubuntu Mate sdcard image for the rpi2) and for which there
is a corresponding "linux-headers-raspi2" which provides all the bits needed
to compile an out-of-tree module for use with that kernel, the situation for
kernels installed by rpi-update is a bit more complicated. It looks like this
process works for rpi-update installed kernels for all Raspberry Pi models,
so that's nice.

You'll need curl and build-essential installed.

$ sudo apt-get install curl build-essential

The rpi-update tool downloads (and checks and copies) updated firmware files
and compiled linux kernels into the /boot partition. The kernels are kernel.img
and kernel7.img - the "7" variant is for the Rasberry Pi 2, which has a processor
which supports the ARMv7 instruction set, whereas all other Raspberry Pi models
have a processor which supports the ARMv6 instruction set. The runtime-loadable
kernel modules which are installed along with the kernel are in folders in
/lib/modules. I currently have:

The kernel I'm currently running on this rpi2 is 4.1.18-v7+ (the "-v7" variant
is for the "7" kernel). Once you've rebooted to run the most recent kernel
installed by rpi-update, there's no point in keeping the old module dirs
(4.1.17+ and 4.1.17-v7+ in my case) as the old kernels they correspond to
are overwritten and gone. You can get the version of the currently running kernel
with "uname -r" (and you can also see it at the beginning of the kernel log
with "dmesg | head").

So we know the kernel that's running, and where its module dir is. We now need
the kernel source tree and some other outputs of the build that produced this
running kernel. The secret is the Hexxeh/rpi-firmware repo on github, and the
file /boot/.firmware_revision which contains a commit hash from that repo.
(The raspberrypi/firmware repo on github is very similar, but arranged a bit
differently and has different commit hashes. The rpi-update I have seems to
use the Hexxeh repo.)

We also need one other file, Module.symvers, which also has a "7" variant which
corresponds to the "7" version of the kernel, for the rpi2. (If you don't have a
rpi2, you should be using the non-"7" variants throughout these steps.)

That should be it, now I can build this out-of-tree module. (Well this
particular one also notes in the README that you have to edit the Makefile just
to toggle CONFIG_PLATFORM_I386_PC and CONFIG_PLATFORM_ARM_RPI.)