Currently, Raspbian OS does not come with the bluetooth_6lowpan kernel module precompiled. Therefore, you must replace the kernel with a version that has a precompiled 6LoWPAN module, and you must install additional packages that provide Bluetooth low energy and router capabilities.
Downloading the required packages
Install the following packages:
If your Raspberry Pi has a direct connection to the internet, log into the Raspberry Pi and install the required packages directly to the Raspberry Pi.
sudo apt-get install bluez radvd libcap-ng0
If your Raspberry Pi has no direct connection to the internet, download the packages to your computer, make sure that the Raspberry Pi is running and that you know its IP address, and use scp (or pscp on Windows) to copy the packages to the Raspberry Pi. You can download these modules from the Raspbian (wheezy) APT repository.
Then copy the files over to the Raspberry Pi:
scp *.deb pi:raspberry\@<IP_address>:~
Next, log into the Raspberry Pi and install the required packages on to the Raspberry Pi.
sudo dpkg -i bluez_4.99-2_armhf.deb libcap-ng0_0.6.6-2_armhf.deb radvd_1.8.5-1_armhf.deb
Building Raspbian Kernel with bluetooth_6lowpan module
In this guide, you will have two choices:
Choose the one that fits your needs. Cross-compilation is the fastest choice.
Dependencies:
In addition to the already installed tools in Raspbian, you will need:
You can install these using apt:
sudo apt-get install git kernel-package -y
“kernel-package” is needed for generating the .deb package, and git is used to fetch the repository from Raspberry Pi’s github account. Fetch the default branch, which holds 3.18.11, for example.
Obtaining the kernel
- Open a terminal and maneuver to a clean directory, for example by creating a directory named ~/raspbian.
- Clone the kernel: Note: This will take some time.
Option 1: Cross-compilation on x86/x64
The easiest option is to grab the tool chain from RaspberryPi.
- Go into a clean directory and clone: Define this path for easier building.
- a) For building on x86 (32-bit) environment, enter:
export CCPREFIX=/path/to/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
b) For building on x64 (64-bit) environment, enter: export CCPREFIX=/path/to/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-
- Go to the kernel directory you just cloned. Ensure that the directory is cleaned:
hkn@desktop:~/raspbian/kernel/linux$ make mrproper
- Set the default kernel configuration for your Raspberry Pi platform.
# If Raspberry Pi 1.
pi@raspberry:~/raspbian/kernel/linux$ ARCH=arm CROSS_COMPILE=${CCPREFIX} make bcmrpi_defconfig
# If Raspberry Pi 2.
pi@raspberry:~/raspbian/kernel/linux$ ARCH=arm CROSS_COMPILE=${CCPREFIX} make bcm2709_defconfig
- Start compiling.
hkn@desktop:~/raspbian/kernel/linux$ ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} make –j5
hkn@desktop:~/raspbian/kernel/linux$ ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MODULES_TEMP} make –j5 modules
On multi-core CPUs, you can utilize the cores via the “-j” operation. For example, if there are 4 cores, add “-j 5” to the above command to speed things up. You should set the number to “NUM_OF_CPU_CORES + 1” to ensure that your cores are working full-time.
- Generate .deb packages
hkn@desktop:~/raspbian/kernel/linux$ CONCURRENCY_LEVEL=5 DEB_HOST_ARCH=armhf fakeroot make-kpkg --append-to-version –name_of_your_choice --revision `date +%Y%m%d%H%M%S` --ARCH=arm --cross-compile ${CCPREFIX} kernel_image kernel_headers
CONCURRENCY_LEVEL sets the number of jobs. In this example 5 are used assuming there are four CPU cores. You will see warnings similar to the following when generating the .deb files: dpkg-architecture: warning: specified GNU system type arm-linux-gnu does not match gcc system type x86_64-linux-gnu, try setting a correct CC environment variable
Note: This is normal when cross-compiling, and actually reassures that the compilation of the kernel for ARM architecture really took place.
Option 2: Native build
It is recommended to have 10 GB free space on your Raspberry for kernel compilation.
The procedure is very similar to the section about cross-compilation, only that a couple of defines are missing.
- Ensure that you have your build essentials in order:
pi@raspberry:~/$ sudo apt-get install build-essential –y
- Set the default kernel configuration for your Raspberry Pi platform.
# If Raspberry Pi 1.
pi@raspberry:~/raspbian/kernel/linux$ make bcmrpi_defconfig
# If Raspberry Pi 2.
pi@raspberry:~/raspbian/kernel/linux$ make bcm2709_defconfig
- Start compiling.
pi@raspberry:~/raspbian/kernel/linux$ make –j5 && make –j5 modules
- Generate .deb packages.
pi@raspberry:~/raspbian/kernel/linux$ CONCURRENCY_LEVEL=5 DEB_HOST_ARCH=armhf fakeroot make-kpkg --append-to-version –name_of_your_choice --revision `date +%Y%m%d%H%M%S` --initrd kernel_image kernel_headers
The .deb files will be placed in the parent directory. Type: As a result you should have two files: ../linux-headers-*.deb
../linux-image-*.deb
Installing the kernel on your Raspberry Pi
- If you cross-compiled, you will need to transfer your kernel header and kernel image to the Pi. You can do this via scp, for instance.
scp linux-header*.deb linux-image*.deb pi:raspberry\@<IP_address>:~
This will transfer the files to your home directory.
- Log into the Raspberry Pi and install the new kernel:
sudo dpkg –i linux-header*.deb linux-image*.deb
The kernel is now installed.
- Specify in the boot settings that this new kernel is used.
pi@raspberry ~ $ cd /boot
pi@raspberry /boot $ ls | grep vmlinuz
vmlinuz-3.18.11-rpi2-v7+
- Specify the kernel and append the resolved name to config.txt:
pi@raspberry /boot $ sudo sh –c ‘echo “kernel=vmlinuz-3.18.11-rpi2-v7+” >> config.txt’
- Reboot, and you will have a new kernel with the bluetooth_6lowpan module.