Tuesday, May 27. 2014
6LoWPAN support in the Linux kernel is sufficiently new right now that you can't just use any old kernel version - you have to ensure you're using a new enough kernel if you want to do anything useful. This presents a problem since the custom kernel normally used on the Raspberry Pi is forked from an older version of the kernel. Fortunately however, support for the RPi in the vanilla kernel has reached the point where we can now run a vanilla Linux kernel on the RPi rather than the custom RPi kernel.
Actually, even the mainline kernel does not currently have sufficiently complete 6LoWPAN and 802.15.4 code to interoperate well with other platforms like Contiki OS. Our task therefore is to get the net-next kernel running on an RPi.
Previously, development had been occurring on David Miller's net-next branch. Alexander Aring now maintains linux-wpan and linux-wpan-next branches based on bluetooth and bluetooth-next, as well as a fork of the userspace tools here. Fortunately this change between branches does not seem to have caused any problems with running on the RPi.
Substituting a vanilla Linux kernel for the forked RPi Linux kernel is simple enough, but there are some noteworthy obstacles. First is that booting a vanilla kernel will require us to use U-Boot *, which the RPi does not use by default. Second is that RPi support in the vanilla kernel is not 100% done yet. The complete list of omissions is unknown to me, but I believe HDMI is the main thing that's missing. Fortunately for us though, everything that we need to turn the RPi into a 6LoWPAN border router is working.
Aside from that, this won't be too different from compiling a kernel in any other case.
* Actually, this may not be true anymore. Looking at the configuration options for the (closed source) RPi bootloader and this discussion, it seems that the necessary functionality for loading a vanilla Linux kernel may have been present for some time already. I expect I'll try this some day, but I'd still rather have a proper configurable bootloader and I imagine most would agree. Thus, U-Boot stays
Compiling the Linux kernel on an RPi is an overnight process, so we're going to want to cross-compile on something quicker instead. You can skip the cross-compiling and proceed with the remaining steps on an RPi if you need to, but you can expect it to be quite slow.
To cross-compile, we'll need to fetch an
On Arch, we can do something like:
On a Debian-ish system, something like:
That will pull in what we need for cross-compiling, including the binaries like
Now we can prefix
building the Linux kernel
First we'll grab the kernel source:
This can take some time even on a good connection, so you might want to start it before doing anything else.
Once git finishes cloning the kernel source, we can go ahead and configure the kernel. The default bcm2835 config will be our starting point but we'll need to add some things to it for our purposes.
This will result in a kernel configuration which will run on the RPi, but it won't be very useful to us without support for 6LoWPAN, 802.15.4, or an 802.15.4 device driver - AT86RF233 in my case.
To configure the kernel the way we need it, we'll use
...to enable the following options:
Whether we enable them as modules or as built-ins doesn't much matter, but we'll have to be sure to copy the modules over to the RPi later if we choose to build any now.
These next options aren't required but they're pretty standard and may well be desirable. You should enable them if you don't otherwise know what to do. (the first one is required if you want to build anything as a module instead of built-in)
At this point, we can proceed to build the kernel (and modules, if applicable):
We now have
patching the device tree
The device tree is what recent ARM systems (among others) use to describe the hardware to the kernel at boottime. x86 systems have BIOS; embedded systems have device tree. It's needed for things which are sufficiently low-level that they that aren't capable of runtime enumeration, like SPI devices, I2C devices, and many others.
The 802.15.4 device I'm using (AT86RF233) is an SPI device, so it can't be auto-enumerated and needs to go into the device tree. Therefore, I've added the following to the bottom of
After patching a
With our kernel and device tree ready, we now need to get U-Boot compiled and set up. Stephen Warren maintains a U-Boot branch with some RPi-specific code that hasn't yet been moved into mainline U-Boot. That's the branch we're going to use.
We'll need to configure for rpi_b before we can compile:
I found it necessary to apply a small patch to U-Boot to make it work with some (all?) of my SD cards:
Presumably this patch isn't required for everyone, but as I haven't yet isolated the actual problem, it seems necessary that I include it here.
Now we can build:
This gives us
U-Boot needs to be told how to boot our new Linux kernel. Its configuration resides in
(As always, mind the line breaks. There are only two lines there -
This configuration will cause U-Boot to automatically load
installing and rebooting
Now that we've got everything compiled, we can copy it all over to the RPi:
(Don't forget to first back up your existing
At this point, we can reboot into the new kernel and try out the new functionality.
linux-zigbee userspace tools
The linux-zigbee userspace tools are what we use to manage 802.15.4 devices. We'll need them in order to do anything useful with our new 6LoWPAN Linux kernel. The source code is at
With the linux-zigbee userspace tools installed, we now have the
That should return something like this:
bringing up the 6LoWPAN network
Upon doing this, we now have a
And of course, with the proper network configuration, we could now just as easily ping the second RPi (or other 6LoWPAN node) from a device connected to the ethernet port of the first RPi. Thus, the RPi has become a 6LoWPAN border router for our ethernet network. This is left as an exercise for the reader until I have time for the next article.
In the mean time, I can vouch that the procedure I've described here does produce a setup which can function as a 6LoWPAN border router capable of interoperating with devices running Contiki OS. I use it several times a day to turn my lights on and off.
Display comments as (Linear | Threaded)
Hi, I am working on a demo for wireless sensor networks using 802.15.4 and ordered a few of the radio devices mentioned for my Pi, and followed this description. I got the thing working (replaced the kernel of a Raspbian image), however my eth0 and wlan0 interfaces disappeared (/etc/network/interfaces is unchanged). Any ideas why is this happening? I had some issues copying the kernel modules (simply cp-ing to the sd card) since it contained symlinks to the net-next library, which I resolved simply by not copying those (I had read somewhere it's OK to do), but I couldn't really find .o files anywhere else in the lib folder. Is this normal? Let me know if you need some details like dmesg, ifconfig or whatsoever, I would appreciate any help :) Thanks
I was able to reproduce this just now by updating to the latest net-next commit. These things do happen from time to time when working with a development branch. I'll spend some time with git-bisect tonight to track down which commit is responsible. At first glance, it looks like something has broken the dwc2 (DesignWare USB Controller) driver. This has the effect of knocking out not just the USB ports but also the ethernet chip since that's connected through USB as well. Obviously I should have specified which commit I was on as a known good reference when I wrote this. Oops. I'll be back soon with updates.
The commit that did it was 47a1685f139271de401212bd69d17374ca5a5270 (usb: dwc2/s3c-hsotg: move s3c-hsotg into dwc2 directory) Reverting this commit does fix the problem if you resolve the two conflicts, but it isn't necessary. Enabling CONFIG_USB_DWC2_HOST and CONFIG_USB_DWC2_PLATFORM fixed this for me. It may simply be that bcm2835_defconfig needs updating although I haven't looked any deeper. I'd be interested to know if this fixes it for you too, although I expect it will. There are probably only a tiny handful of people running a vanilla kernel on the RPi at the moment.
Hi, I tried the latter method and rebuilt the kernel with the new config and it indeed fixed the problem, now USB is working as it should, so I have Ethernet interface again. Thanks for the effort, it would have taken quite a lot of time to figure this out myself. By the way the radio works beautifully, though at the moment I am just sending raw 802.15.4 frames from an ATMEGA256RFR2 chip.
Hi Daniel, I'm very new to this, would you have or know where a guide to replacing the kernel of the Raspbian image would be? Thanks in advance. Craig.
Hello all, I'm having some troubles when I try to reboot the raspberry pi into the new kernel. Here is what it shows up: reading /uEnv.txt **Unable to read file /uEven.txt ** (...) ***Warning: no boot file name: using '0A0301E0.img' Using sms0 device TFTP from server 0.0.0.0: our IP address is 10.3.1.224; sending trough gateway 10.3.0.254 Filename '0A0301E0.img' Load Address: 0x20000 Loading: TFTP error: 'illegal (unrecongnized) tftp operation (4) It seems that my u-boot configurations are not able to read the uEnv.txt file. After that, the screen shows up a TFTP error and it starts running in an infinite loop. Can someone please help me? Thank you in advance.
Hello! I'm following your tutorial, but I'm having problems with U-Boot - it hangs on error: mbox: Response buffer mismatch bcm2835: Could not query ARM memory size ### ERROR ### Please RESET the board ### This seems rather rare (I haven't found any other reference on the Internet). Can you please tell me which U-Boot commit you used for your setup? Best Regards
Hey, I solved the problem - it was caused by old start.elf file. I used 2012 Raspbian image that contained old start.elf. I advise using new start.elf for testing U-Boot. Best Regards
Hi, I manage to get it working but i couldn't find the instruction to compile the Zigbee user tools, i tried this http://wiki.beyondlogic.org/index.php?title=Cross_Compiling_Linux-Zigbee_for_ARM somebody found a way to compile the zigbee user tools
The userspace tools have been updated and moved to here: https://github.com/linux-wpan/lowpan-tools There have also been some other changes since this blog post. See the updates in this post: http://openlabs.co/blog/archives/4-sniffing-802.15.4-packets-natively-with-Raspberry-Pi-and-Wireshark
Hi! This is a very good module to deploy a 6LoWPAN solution. It is possible to attach to Contiki-based solutions? (I'm thinking in 6LBR...) I'm trying but I don't have ping connectivity. Thanks in advance!
Yes, Contiki is what most of my devices are running and they communicate well enough. 6lbr should work just as well, but I haven't tried it. I decided instead to replace 6lbr with a more straightforward/native approach, which is why I made this module and got it running with Linux in the first place.
Thats nice! Now I'm trying to get ping connectivity between them but 6lbr detects at stale neighbor... I keep trying! Thanks!
I'm trying only building the kernel, and the graphic part doesnt work. i'm doing that with the rpi b+. Are the same procedures? Thank you in advance!
Do you mean the HDMI output? That still doesn't work on a vanilla kernel as far as I know. The RPi B+ should hopefully use the same procedures but I don't have one to play around with yet.
Could your 6LoWPAN adapter be made to work on Beagle Bone Black (BBB)?
Yes I'm sure it would work. The pinout won't match of course but it's just an SPI connection so there's no limit to what you can use it with. I've got a beaglebone on my wishlist this year so maybe I'll soon be doing a blog post on it if I'm lucky.
Hello, I am a novice, I bought two of your modules, I use a raspberry pi B+, and I am following this tutorial to get what you say. But, in the section of building U-BOOT, the oart of: "We'll need to configure for rpi_b before we can compile: make rpi_b_config" I get "HOSTCC scripts/basic/fixdep ** ** Can't find the default configuration "configs/rpi_defconfig"! ** make: ** [rpi_b_config] Error 1" Thanks in advance
It looks like uboot has changed a bit. According to the link below, you need to use `make rpi_b_defconfig` instead on recent versions of uboot. http://elinux.org/RPi_U-Boot#Compile_the_source
The problem is, that the branch 'rpi_dev' not contains the 'rpi_b_defconfig', only contains rpi_defconfig. But I have seen it on the branch 'tegra_dev', if that file exists! so, try this branch could have a correct result? branch rpi_dev: https://github.com/swarren/u-boot/tree/rpi_dev/configs branch tegra_dev: https://github.com/swarren/u-boot/tree/tegra_dev/configs
For Pi, are there any assumptions about what is already running on the sdcard? For example, I started with raspbain from http://www.raspberrypi.org/downloads/. That image doesn't have /boot/uEnv.txt (nor does the card that shipped with the Pi.) There doesn't seem to be /dev/mmcblk0p5 either, just: Device Boot Start End Blocks Id System /dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA) /dev/mmcblk0p2 122880 31275007 15576064 83 Linux Should I start with a different distro? Thanks
Raspbian is probably a great distro to use. /boot/uEnv.txt doesn't exist on a system where uboot isn't being used. You have to create it when installing uboot. /dev/mmcblk0p5 has to be customized. In your case you need /dev/mmcblk0p2 I think.
From my understanding, the wpan tools have changed quite a bit, so the instructions starting with "linux-zigbee userspace tools" do not work anymore. Here is a summary of what needs to be done for ping to work correctly: (Setup is two Raspberry Pis (A and B) with Rasbian but a self-compiled bluetooth-next kernel.) My Pi boots with wpan0 configured, but down. This depends on the contents of /etc/ifplugd, see http://www.spinics.net/lists/linux-wpan/msg01366.html. If iwpan dev does not list anything, create wpan0 with $ sudo iwpan phy wpan-phy0 interface add wpan0 type node) Anyway, do the following on both sides (both RPi in my case): Bring up wpan0: $ sudo ip link set wpan0 up Create lowpan Interface $ sudo ip link add link wpan0 name lowpan0 type lowpan Bring up lowpan0 $ sudo ip link set wpan0 up Check all interfaces $ ifconfig As ifconfig only lists interfaces that are up, this should list wpan0 and lowpan0. Make a note of the "inet6 addr" of Pi A. In Pi B, type $ ping6 -I lowpan0 Note that specification of the interface to use is mandatory as mentioned in the man page of ping!
Hello all, I ordered one of these interfaces (i.e., Atmel AT86RF233 based OpenLabs interface) some time back and today, I was able to bring the 802.15.4 enabled kernel up and running on an RPi with this interface. Though I followed the above procedure, I was stuck with a u-boot issue for some time and could not proceed. Basically it was not using the uEnv.txt I created. So, I had to use the procedure in http://elinux.org/RPi_U-Boot to get it working. During the process, I documented what I did. Here is a link to it, in case someone else is interested. http://www-user.uni-bremen.de/~koojana/HOWTO_RPi_802154_atmel_AT86RF233.txt Now, I have the following issue with the "iz set” which I am looking into. sudo iz add wpan-phy0 wpan0 00:00:00:00:00:00:00:01 Receive failed: Unspecific failure If anyone has any idea on this, I would be very glad to hear it. Thanks. Koojana
Hello, Thanks for this wonderfull and very usefull work. Trying to compile the kernel for the Raspberry Pi, I got the following error on lib/rhashtable.c file: lib/rhashtable.c:967:3: erreur: implicit declaration of function ‘ERR_PTR’ [-Werror=implicit-function-declaration] I had to add #include at the beginning of the file to get it compile without error. Hope this help...
While compiling, I've got the following error : #CROSS_COMPILE=arm-linux-gnueabi- ARCH=arm INSTALL_MOD_PATH=.mods make modules_install ln: la cible «.mods/lib/modules/3.19.0-rc7+/source» n'est pas un répertoire Makefile:1121: recipe for target 'modinst' failed make: *** [modinst] Error 1 Please could you help me to fix it ? The folder ".mods/lib/modules/3.19.0-rc7+/source" is missing, and ".mods/lib/modules/3.19.0-rc7+/" just has "kernel" in it... Maybee a mssing link ? Thanks in advance. Bernard
After all the process, finally I boot the kernel. BUT, when I use the lowpan tools, and put "./iz listphy" into the shell, I obtain this : "Could not get multicast group ID: No such file or directory" Do you know what to do? I use lib 3.2.24 and lowpan tools 0.3.1 [I don't know if GPIO detect your product, the 802.15.4 radio, or not]
NEED HELP TO COMPILE I compiled with success the "https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git" branch. Then I decided to move to the newer brnch in order to get the promixuity mode working with wireshark as described in "sniffing 802.15.4 packets natively with Raspberry Pi and Wireshark". But when tried to compile the "https://github.com/linux-wpan/linux-wpan-next.git" branch, I have the following error: $ ARCH=arm CROSS_COMPILE=arch-arm-gnueabi- make dtbs make: arch-arm-gnueabi-gcc: commande introuvable CHK include/config/kernel.release CHK include/generated/uapi/linux/version.h CHK include/generated/utsrelease.h make: 'include/generated/mach-types.h' is up to date. CC kernel/bounds.s /bin/sh: 1: arch-arm-gnueabi-gcc: not found Kbuild:35: recipe for target 'kernel/bounds.s' failed make: ** [kernel/bounds.s] Error 127 Makefile:972: recipe for target 'prepare0' failed make: ** [prepare0] Error 2 In addition, patching the kernel as described in "sniffing 802.15.4 packets natively with Raspberry Pi and Wireshark" also fail with the following error: Application : ieee802154: skip bad frame type warning for ack type Application : ieee802154: at86rf230: add support for promiscuous mode error: le patch a échoué : drivers/net/ieee802154/at86rf230.c:90 error: drivers/net/ieee802154/at86rf230.c : le patch ne s'applique pas Le patch a échoué à 0002 ieee802154: at86rf230: add support for promiscuous mode PLease could you help me to make it work ? Thanks in advance.