Skip to content

How to install 6LoWPAN Linux Kernel on Raspberry Pi

BytesGalore edited this page Jun 12, 2015 · 34 revisions

This is work in progress and just hacked together for now...

Objective

Install a fairly new (next) Linux kernel on a raspberry pi, which is able to run IEEE802.15.4 devices (i.e. the Atmel AT86RF233) and 6LoWPAN.

These are the results of a long night:

NOTE There is much room for improvement here, so follow the steps with caution :-)

Flash the current of-the-shelf raspian image

Get a toolchain that supports arm-linux-gnueabihf- (with hard fp)

For debugging, connect a UART adapter to the Pi, see for pinout:

http://elinux.org/RPi_Low-level_peripherals

Take the official raspberry pi kernel (branch rpi-4.0.y):

git clone git@github.com:raspberrypi/linux.git linux-rpi
cd linux rpi
git checkout rpi-4.0.y

On top get the newest raspberry firmware (branch: next):

git clone git@github.com:raspberrypi/firmware.git firmware
cd firmware
git checkout next

Activate modules and patch the device tree as described in

http://openlabs.co/blog/archives/1-6LoWPAN-kernel-on-a-Raspberry-Pi Don't forget the lib dir

Follow these sections:

  • cross-compiling
  • building the Linux kernel
  • patching the device tree

But also add the option:

 Boot options -> Use appended device tree blob to zImage

-- is this needed? --

Build the kernel as described in

http://elinux.org/Raspberry_Pi_Kernel_Compilation

Copy Kernel and Modules and Firmware to the boot dir of the Pi as described in

http://elinux.org/Raspberry_Pi_Kernel_Compilation

Also copy over the vp dir in the hf version (whatever it does), see also

http://elinux.org/Raspberry_Pi_Kernel_Compilation

Add a config.txt file with options from

https://github.com/raspberrypi/linux/wiki/How-to-boot-using-device-tree (but remove the option init_emmc_clock)

reboot and hope!

Now, on the Pi, install the userspace tools:

install some needed packets on the Pi:

sudo apt-get install libnl-3-dev libnl-genl-3-dev

####get them from here: https://github.com/linux-wpan/wpan-tools

The current master seems to fail while configuring...

run autoconf and make the thing

cd wpan-tools
./autogen.sh
./configure 

get them frome here, then:

http://wpan.cakelab.org/releases/wpan-tools-0.4.tar.gz

unzip and build them

tar xfvz wpan-tools-0.4.tar.gz
cd wpan-tools-0.4.tar.gz
./configure
make
sudo make install

Now it should work?

For testing, follow some of the instructions at http://wpan.cakelab.org/#_how_to_8217_s

How-to install and use 6LoWPAN on a Raspberry Pi with Linux Kernel 4.0.5+

Objective

This how-to will guide you to:

  • configure the Raspberry Pi Kernel for 802.15.4 and 6LoWPAN
  • patch in support for the openlabs Raspberry-Pi-802.15.4-radio device
  • compile a recent Linux kernel (rpi-4.0.y) for the Raspberry Pi
  • and use the new built Kernel on your Raspberry Pi

Preparing the Raspberry Pi

To start off, we obtain the latest Raspbian image and flash it on our SDCard.

  • We download the official image from the Raspbian download site (scroll down a bit there),
  • and follow their provided guides to flash the downloaded Raspbian image to our SDCard.
  • Then we Plug the SDCard and boot our Raspberry Pi.
  • Note, if you login the first time, the username is pi and the password is raspberry
  • Additional note, watch out if you have a german keyboard layout, the keys y and z are switched.
  • In the first run of our Raspberry, we set the filesystem to be expanded and set additional options for the system using the raspi-config tool. Then we let the Raspberry Pi reboot to finish the installation.
  • After the reboot we login and update the system by entering sudo apt-get update followed by sudo apt-get upgrade.

Get a new Raspberry Pi kernel (on a Linux Host)

We focus on cross compilation here, since we don't want to spend a night watching the build process ;).
To start, we need an appropriate and recent cross compiler (GCC for ARM) to build a new Raspbian kernel.
The Raspberry Pi requires a GCC for cortex a7 processors with hard fp (arm-gnueabihf) support.
So, our choice for a suiting GCC here is the Linaro GCC 4.9, which fulfills the requirements.
Note, you can use any other suiting GCC for the build process.
We download the appropriate tar.xz file and decompress it, e.g. directly in directory where we downloaded the file to.
To make the cross GCC ready to build things, we open a terminal and export the PATH to the newly decompressed GCC bin directory.
We enter:

export PATH=$PATH:/home/<myusername>/Downloads/gcc-linaro-4.9-2014.11-x86_64_arm-linux-gnueabihf/bin

Doing so we tell the environment (of the current terminal) the location of the cross GCC executables. (Please note, this may differ for your system).
To test if the export succeeded, we type arm-linux-gnueabihf-gcc --version, which should provides us with the version information of our cross GCC.
If not, the path export seems to be failed. You can check the export by entering $PATH in the terminal, which shows the content of the exported variable.
Please note, if you use a 64 bit Linux you may also need to install multilib support, i.e. i386 support.

Now we download the latest Raspberry Pi kernel sources from their Git repository.
We enter:

git clone https://github.com/raspberrypi/linux.git linux-rpi
cd linux rpi
git checkout rpi-4.0.y
cd ..

Additionally we also obtain the latest firmware files.
We enter:

git clone https://github.com/raspberrypi/firmware.git firmware
cd firmware
git checkout next
cd ..

Now we have everything prepared to start configuring and building our new kernel.

Configure the new kernel

First we configure the sources with an appropriate configuration for the Raspberry Pi.
We switch in the kernel source folder, by entering cd linux-rpi followed by:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2835_defconfig

This provides us with an initial and basically complete configuration for the new kernel. In addition, we need to enable 802.15.4, 6LoWPAN and our specific transmission devices in the kernel, since its not provided in the default configuration.

We basically follow the openlabs guide, which instructs to setup an appropriate configuration for 802.15.4 and 6LoWPAN using an AT86RF233 SPI transceiver for a net-next kernel on a Raspberry Pi.
Contrary to the guide, we first patch the device tree, to enable support for the AT86RF233 SPI transceiver.
We load the arch/arm/boot/dts/bcm2835-rpi-b.dts file in our favorite editor and append the following part at the end:

&spi0 {
	status="okay";
	spidev@0{
		status = "disabled";
	};
	spidev@1{
		status = "disabled";
	};
	at86rf233@0 {
		compatible = "atmel,at86rf233";
		reg = <0>;
		interrupts = <23 1>;
		interrupt-parent = <&gpio>;
		reset-gpio = <&gpio 24 1>;
		sleep-tpio = <&gpio 25 1>;
		spi-max-frequency = <500000>;
	};
};

This enables SPI on the Raspberry Pi and tells the kernel that our AT86RF233 SPI transceiver may be plugged over SPI (Pins 15-26) to it.

Now that we set-up the SPI connection for our AT86RF233 transceiver, we move on to configure our kernel for providing 802.15.4, 6LoWPAN and the transceiver device drivers.
We enter:

make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig

which provides us with the kernel configuration menu to configure/enable the above named features.

  • First we enable 802.15.4 and 6LoWPAN support in our kernel.
    We traverse the menu to:
Networking support
  --> Networking options
    --> IEEE Std 802.15.4 Low-Rate Wireless Personal Area Networks support

enable the item if not already enabled, and enter the sub-menu of this item.
There we set all options either to be loaded as module <M> or as direct part of the kernel <*>.
We < Exit > back to Networking options and set 6LoWPAN Support if not already set.
Then traverse back to root menu.

  • Now we enable the drivers for our 802.15.4 devices (e.g. our AT86RF233 SPI transceiver).
    We traverse to:
Device Drivers
  --> Network device support
    --> IEEE 802.15.4 drivers

enable it if not already enabled, and enter the sub-menu.
There we set our driver(s) either to be loaded as module <M> or as direct part of the kernel <*>, e.g. <M> AT86RF230/231/233/212 transceiver driver.
Then we traverse back to root menu.

  • Finally we put in some default Boot options We traverse to:
Boot options
  --> () Default kernel command string

hit the enter key and type

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait

in the "popped-up" input field.
Then we hit < Ok > and got back to the root menu.

There we hit < Save > and store the configuration in the proposed file (.config) followed by < Exit > to leave the kernel configuration menu.

Build our new kernel

After we finished our configuration, we fire the build process of our new kernel.
We enter:

CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm make zImage modules dtbs -j8

and have break.
When all is finished, we collect all built modules together in a .mods folder.
We enter:

CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm INSTALL_MOD_PATH=.mods make modules_install

which copies all *.ko files to the provided directory, i.e. .mods.

Use the new kernel

Now that we built a recent kernel we need to copy with the modules and the firmware to our SDCard.
First the kernel:

sudo cp arch/arm/boot/dts/*.dtb /media/<myusername>/boot/
sudo cp arch/arm/boot/dts/overlays/*.dtb* /media/<myusername>/boot/overlays
sudo scripts/mkknlimg arch/arm/boot/zImage /media/<myusername>/boot/kernel.img

After this, we copy the modules:

sudo cp -r .mods/lib/* /media/<myusername>/<SDCardpatitionname>/lib

and the prebuilt firmware files for hard fp:

cd ..
cd firmware
sudo rm -rf /media/<myusername>/<SDCardpatitionname>/opt/vc
sudo cp -r hardfp/opt/* /media/<myusername>/<SDCardpatitionname>/opt

As last step we need to tell the bootloader which device configuration it should use, i.e. bcm2835-rpi-b.dtb. We fire our favorite editor open the /media/<myusername>/boot/config.txt file, append

device_tree=bcm2835-rpi-b.dtb
device_tree_address=0x100

at the end and save it.
That's it :D our SDCard is prepared to run the new kernel.

So, we unmount the SDCard, plug it in the Raspberry Pi and let it boot. If everything went fine, we should see the usual boot process. If you see a colored screen permanently (in case you plugged a monitor to your Raspberry Pi) something went wrong.

Build and install the WPAN tools

After logging in, we need the WPAN tools to setup and use one of our 802.15.14 devices. First we need to install the dh-autoreconf package to be able to build the recent WPAN tools. We type

sudo apt-get install dh-autoreconf

Then we clone the latest wpan-tools sources

git clone https://github.com/linux-wpan/wpan-tools
cd wpan-tools

build them

./autogen.sh
./configure CFLAGS='-g -O0' --prefix=/usr --sysconfdir=/etc --libdir=/usr/lib
make

and finally install them

sudo make install

For testing, follow some of the instructions at http://wpan.cakelab.org/#_how_to_8217_s

Clone this wiki locally