Skip to content

Create a generic Raspbian image with 6LoWPAN support

Sebastian Meiling edited this page Mar 4, 2016 · 4 revisions

Create a generic Raspbian image with 6LoWPAN support

+++UPDATE+++UPDATE+++UPDATE+++

The text below is outdated, please refer to these guides and its associated repo

+++UPDATE+++UPDATE+++UPDATE+++

##1. Objectives

This guide shows how to create a modified Raspbian Image that supports 6LoWPAN and runs on any variant of the Raspberry Pi, namely B, B+, and 2B. Step-by-step we will do the following:

  • prepare an initial Raspbian image for any Raspberry Pi
  • configure and build Linux Kernels for Pi B,B+, and 2B
  • install these WPAN capable Kernels into Raspbian
  • install WPAN tools and configure 6LoWPAN devices

##2 Prepare Raspbian Image

###2.1 Get and install Raspbian

  • First, we need the latest Raspbian Image, downlowd here
  • there are 2 variants, namely Raspbian Jessie and Raspbian Jessie Lite, choose wisely:
    • if your Pi will be a server and a shell is all you need, go for the lite version
    • if you need a full fledged desktop GUI, e.g. with web browser, take standard Raspian
  • under the hood they are basically the same, no worries here!
  • Second, we need to write the Image to a SDcard, OS specific guides are available here
  • for the impatient, it boils down to this:
# OSX, use diskutil to find right disk
sudo dd if=<path/to/raspbian.img> of=/dev/rdisk<N> bs=1m
# Linux, check 'ls /dev' for any new '/dev/sdX' 
sudo dd if=<path/to/raspbian.img> of=/dev/sdX bs=4M 
  • but a take a look at the guides!

###2.2 Preconfigure Raspbian

  • plug the SDcard into your Pi and boot
    • login into the Pi with user pi and password raspberry
    • Note: standard keyboard layout is english so beware y and z!
  • first some initial configurations, run sudo raspi-config, and:
    • expand filesystem
    • change default password
    • fix keyboard layout, locals and timezone
    • if you need help
  • if you have Internet connectivity:
    • update Raspbian sudo apt-get update && sudo apt-get upgrade
    • install your favorite editor, that is VIM: sudo apt-get install vim
  • done, unplug the Pi, eject the SD card and proceed

##3 New Linux Kernels for the Pi

###3.1 Download sources

  • create a base directory and change owner to your user:
sudo mkdir -p /opt/src/rpi_wpan
sudo chown <your-username> /opt/src/rpi_wpan
cd /opt/src/rpi_wpan
  • clone Raspberry Pi Linux-Kernel from Github
git clone --depth 1 https://github.com/raspberrypi/linux.git linux-rpi
  • we don't want to mix things between Pi B,B+ and Pi 2B, so just do it again
git clone --depth 1 https://github.com/raspberrypi/linux.git linux-rpi2
  • we also need latest firmware files
git clone --depth 1 https://github.com/raspberrypi/firmware.git firmware
  • now we should have 3 directories under /opt/src/rpi_wpan/ namely firmware, linux-rpi, and linux-rpi2

###3.2 Configure the Kernel

special steps for for Raspi B and B+

  • change directory to /opt/src/raspi-wpan/linux-rpi
  • initials Kernel configuration with:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2835_defconfig
  • edit arch/arm/boot/dts/bcm2835-rpi-b.dts, and append at the following spi0 configuration:
&spi0 {
  status="okay";
  spidev@0{
    status = "disabled";
  };
  spidev@1{
    status = "disabled";
  };
  at86rf233@0 {
    compatible = "atmel,at86rf233";
    reg = <0>;
    interrupts = <23 4>;
    interrupt-parent = <&gpio>;
    reset-gpio = <&gpio 24 1>;
    sleep-gpio = <&gpio 25 1>;
    spi-max-frequency = <6000000>;
    xtal-trim = /bits/ 8 <0x0F>;
  };
};
  • do the same for B+, in file arch/arm/boot/dts/bcm2835-rpi-b-plus.dts

special steps specific to Raspi 2B

  • change directory to /opt/src/raspi-wpan/linux-rpi2
  • initials Kernel configuration with:
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- bcm2709_defconfig
  • edit arch/arm/boot/dts/bcm2709-rpi-2-b.dts, and modify section spi0 as follows:
&spi0 {
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins>;
    status="okay";
    spidev@0{
        compatible = "spidev";
        reg = <0>;      /* CE0 */
        #address-cells = <1>;
       #size-cells = <0>;
       spi-max-frequency = <500000>;
       status = "disabled";
    };

    spidev@1{
        compatible = "spidev";
        reg = <1>;      /* CE1 */
        #address-cells = <1>;
        #size-cells = <0>;
        spi-max-frequency = <500000>;
        status = "disabled";
    };
    at86rf233@0 {
        compatible = "atmel,at86rf233";
        reg = <0>;
        interrupts = <23 4>;
        interrupt-parent = <&gpio>;
        reset-gpio = <&gpio 24 1>;
        sleep-gpio = <&gpio 25 1>;
        spi-max-frequency = <6000000>;
        xtal-trim = /bits/ 8 <0x0F>;
    };
};
  • Note: do not append this section, you have to modify it inline!!

Kernel menuconfig (all Pi variants)

With the previous steps we configured the SPI for the Atmel IEEE 802.15.4 transceiver, now we have add Kernel support for IEEE 802.15.4 and 6LoWPAN.

  • run Kernel configuration with
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
  • enable general support for 802.15.4 and 6LoWPAN, goto:
Networking support
  --> Networking options
    --> IEEE Std 802.15.4 Low-Rate Wireless Personal Area Networks support
  • check all boxes (submenu too) and set them to <M> to build the required Kernel module
  • go back to top menu using <EXIT> in the bottom menu
  • next we add the network driver support, i.e., for the Atmel transceiver; goto:
Device Drivers
  --> Network device support
    --> IEEE 802.15.4 drivers
  • again check all boxes with <M>, submenus too and go back to the top menu
  • finally we set some boot options, goto:
Boot options
  --> () Default kernel command string
  • in the popup box enter:
console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
  • go back to the top menu again and exit, saving the configuration with ```
  • do this for both Pi configurations

###3.3 build Kernel and modules (all Pi variants)

  • compile the modified Linux Kernels by running the following commands in both directories:
CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm make zImage modules dtbs -j4
  • you can modify parameter -j to match number of cpu cores of your system: the more, the better
  • afterwards compile and install all Kernel modules, running:
CROSS_COMPILE=arm-linux-gnueabihf- ARCH=arm INSTALL_MOD_PATH=.mods make modules_install

###3.4 release the Kraken ... aehm Kernels

  • plug the SD-card with the prepared Raspbian Image into a card reader of your Linux system
  • likely your system will automount the boot and root partition somewhere, check where
  • first we deploy the Kernel for Pi B and B+
cd /opt/src/rpi_wpan/linux-rpi
sudo cp arch/arm/boot/dts/*.dtb <path/to/boot-mount>/
sudo cp arch/arm/boot/dts/overlays/*.dtb* <path/to/boot-partition>/overlays
sudo scripts/mkknlimg arch/arm/boot/zImage <path/to/boot-partition>/kernel.img
  • next copy the Kernel modules to the root partition (not boot!):
sudo cp -r .mods/lib/* <path/to/root-mount>/lib
  • now, we copy the Kernel for Pi 2B:
cd /opt/src/rpi_wpan/linux-rpi2
sudo cp arch/arm/boot/dts/*.dtb <path/to/boot-mount>/
sudo cp arch/arm/boot/dts/overlays/*.dtb* <path/to/boot-partition>/overlays
sudo scripts/mkknlimg arch/arm/boot/zImage <path/to/boot-partition>/kernel7.img
  • Note: the Kernel image name is kernel7.img!
  • finally we copy the new firmware files to the root partition:
cd ..
cd /opt/src/rpi_wpan/firmware
sudo rm -rf <path/to/root-mount>/opt/vc
sudo cp -r hardfp/opt/* <path/to/root-mount>/opt
  • that's it, now unmount both partitions an eject the Raspbian SD-card

##4 Install WPAN tools and configure 6LoWPAN devices

Clone this wiki locally