Developers Club geek daily blog

3 years ago
Recently I was asked how to add support of batman-adv in Yocto. Correspondence which became basis for this post was as a result started. So, how to make it? Let's understand together.

Operation "B.A.T.M.A.N.": adding of modules of kernel in Yocto on Intel Edison

Way first: it is not necessary to invent the bicycle


Before to do something most, will not prevent to check, whether someone else has made already the same. It is worth walking on the existing repositories, for example, to glance here. I managed to find necessary libnl, but not B.A.T.M.A.N here. (now, however, it already there is, but me, nevertheless, there is a wish to continue the story). In such situation it is quite possible to address with polite request to the one who is engaged in repository, for example, in our case, to the user with AlexT nickname. The essence of request consists in adding of packets of "kernel-module-batman-adv" and "batctl" in opkg repository. If good luck is on your party, AlexT it will make, but it is necessary to consider that it does in the spare time this repository on voluntary basis. Packets can be set team of type of "opkg install".

Way second: compilation on the target device


This approach is a little more difficult, it demands rather empty seat in rootfs Intel Edison. At its application it is necessary to load and compile necessary code of the kernel level on the target device.

Way third: assembly in the environment of Yocto


In order that this way to use, it is required to you:

  • The computer host on which Linux x64 is set. For example – Ubuntu 12.04 (I happened to hear about problems with Yocto in Ubuntu 14.04, perhaps, now they are already solved), Fedora 20 and so on.
  • At least 50 Gb of empty seat on disk (it if you want to compile full image of Yocto).

Yocto setup


Load "Yocto complete image" from here. After loading execute such commands:

  • tar xvf edison-src*.tgz
  • cd edison-src
  • device-software/setup.sh
  • source poky/oe-init-build-env

Assembly of kernel-modules-batman-adv


Here the way to success lies through the following steps:

  • Execute the bitbake command - with menuconfig virtual/kernel. It will open new window in which configuring of kernel for Edison will be started means.

  • Configure B.A.T.M.A.N. For this purpose, in menuconfig session, set the B.A.T.M.A.N parameters., which you would like to see in the category Networking Support> Networking Options> BATMAN.

  • cp build/tmp/work/edison-poky-linux/linux-yocto/<your current kernel> / linux-edison-standard-build/.config device-software/meta-edison/recipes-kernel/linux/files/defconfig

  • bitbake - with compile_kernelmodules virtual/kernel

  • If you need full tarball modules, then the bitbake team - with deploy virtual/kernel is necessary. Tarball can be found to the address build/tmp/deploy/images/edison

  • Otherwise the following team on the target device is necessary: opkg install build/tmp/deploy/ipk/edison/kernel-module-batman-adv_<version>.ipk

I have changed the following configuration settings:

< # CONFIG_BATMAN_ADV не установлен
---
> CONFIG_BATMAN_ADV=m
> CONFIG_BATMAN_ADV_BLA=y
> CONFIG_BATMAN_ADV_DAT=y
> CONFIG_BATMAN_ADV_NC=y
> # CONFIG_BATMAN_ADV_DEBUG не установлен

Batctl installation


To use B.A.T.M.A.N., it is necessary to set also batctl. Suitable recipes for assembly system of BitBake can be found in the Internet. For example, I used this, having made to it some changes. Here is how that I did looks:

mkdir -p device-software/meta-edison-distro/recipes-support/batman/

cat > device-software/meta-edison-distro/recipes-support/batman/batctl_2014.4.0.bb <<EOF

DESCRIPTION = "Control application for B.A.T.M.A.N. routing protocol kernel module for multi-hop ad-hoc mesh networks."
HOMEPAGE = "http://www.open-mesh.net/"
SECTION = "console/network"
PRIORITY = "optional"

LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://../license-destdir/${PN}/generic_GPLv2;md5=801f80980d171dd6425610833a22dbe6"

RDEPENDS_${PN} = "kernel-module-batman-adv"
DEPENDS = "libnl"

SRC_URI = "http://downloads.open-mesh.net/batman/stable/sources/batctl/batctl-${PV}.tar.gz\
     file://patch.patch"
SRC_URI[md5sum] = "f3a14565699313258ee6ba3de783eb0a"
SRC_URI[sha256sum] = "77509ed70232ebc0b73e2fa9471ae13b12d6547d167dda0a82f7a7fad7252c36"

EXTRA_OEMAKE = 'STAGING_INC="${STAGING_INC}"'

do_compile() {
  oe_runmake
}

do_install() {
  install -d ${D}${bindir}
  install -m 0755 batctl ${D}${bindir}
}
EOF

As libnl has changed the way of installation entering it, I need to propatchit Makefile batctl. It becomes so:

mkdir -p device-software/meta-edison-distro/recipes-support/batman/files
cat > device-software/meta-edison-distro/recipes-support/batman/files/patch.patch <<EOF

--- a/Makefile  2015-02-27 09:10:45.768409932 +0100
+++ b/Makefile  2015-02-27 09:11:32.710554513 +0100
@@ -29,7 +29,7 @@
MANPAGE = man/batctl.8

 # batctl flags and options
-CFLAGS += -Wall -W -std=gnu99 -fno-strict-aliasing -MD -MP
+CFLAGS += -Wall -W -std=gnu99 -fno-strict-aliasing -MD -MP –I${STAGING_INC}/libnl3
CPPFLAGS += -D_GNU_SOURCE
LDLIBS += -lm
EOF

After all these manipulations for assembly of batctl by means of bitbake such team is necessary:

bitbake batctl

After completion of assembly the ready packet can be found to the address build/tmp/deploy/ipk/core2-32/batctl_2014.4.0-r0_core2-32.ipk. It can be set by means of "opkg install" on Intel Edison with the set Yocto Linux

Testing for Intel Edison after installation


root@edison:~/ # modprobe batman-adv

If you want that the module was loaded automatically probably to you it is worth turning on it in / etc/modules-load.d/

root@edison:~/ # modinfo batman-adv
filename:       /lib/modules/3.10.17-poky-edison+/kernel/net/batman-adv/batman-adv.ko
version:        2013.2.0
description:    B.A.T.M.A.N. advanced
author:         Marek Lindner <lindner_marek@yahoo.de>, Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
license:        GPL
srcversion:     66711903985B5CAAE0DAF30
depends:       
intree:         Y
vermagic:       3.10.17-poky-edison+ SMP preempt mod_unload ATOM

With use of the USB Ethernet-adapter:

root@edison:~/ # batctl if add enp0s17u1
root@edison:~/ # batctl if
enp0s17u1: active
root@edison:~/ # batctl s
     tx: 6
     tx_bytes: 468
     tx_dropped: 0
     rx: 1
     rx_bytes: 42
     forward: 0
     forward_bytes: 0
     mgmt_tx: 60
     mgmt_tx_bytes: 2428
     mgmt_rx: 0
     mgmt_rx_bytes: 0
     tt_request_tx: 0
     tt_request_rx: 0
     tt_response_tx: 0
     tt_response_rx: 0
     tt_roam_adv_tx: 0
     tt_roam_adv_rx: 0
     dat_get_tx: 0
     dat_get_rx: 0
     dat_put_tx: 0
     dat_put_rx: 0
     dat_cached_reply_tx: 0
     nc_code: 0
     nc_code_bytes: 0
     nc_recode: 0
     nc_recode_bytes: 0
     nc_buffer: 0
     nc_decode: 0
     nc_decode_bytes: 0
     nc_decode_failed: 0
     nc_sniffed: 0

# ifconfig bat0
bat0      Link encap:Ethernet  HWaddr 52:78:97:51:ba:9d  
          inet6 addr: fe80::5078:97ff:fe51:ba9d/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST DYNAMIC  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:42 (42.0 B)  TX bytes:468 (468.0 B)

Results


The considered approach allows to build in modules Yocto Linux kernel on Intel Edison. Using it, you can include in kernel that is necessary for you, and not to depend on repositories. If your purpose – B.A.T.M.A.N. Advanced, so your Intel Edison is ready to work in MESH network.

This article is a translation of the original post at habrahabr.ru/post/267817/
If you have any questions regarding the material covered in the article above, please, contact the original author of the post.
If you have any complaints about this article or you want this article to be deleted, please, drop an email here: sysmagazine.com@gmail.com.

We believe that the knowledge, which is available at the most popular Russian IT blog habrahabr.ru, should be accessed by everyone, even though it is poorly translated.
Shared knowledge makes the world better.
Best wishes.

comments powered by Disqus