Xenomai on the Beaglebone Black in 14 easy steps

EDIT: Mark wrote an updated guide here.

The BeagleBone Black is an amazingly cheap and powerful development platform that is being used by many people in a lot of projects. That was intentionally vague, because I know that if you ended up here you already know what a BeagleBone Black is.

In this post I’ll explain how I got Xenomai to run on my BeagleBone.

First of all I tried these instructions, but couldn’t get past the kernel compilation step. I believe that this is due to the instructions being six months old, which are like two and a half centuries in computer time. So I continued searching and found a post in a Japanese blog. Using my fluent Japanese Google Translator I could understand what was going on and could successfully reproduce the steps and get Xenomai up and running (big thanks to the author!). Here I’ll reproduce the steps. I’m assuming that you are on a computer running Ubuntu (like mine) and are familiar with the command line.

Getting the tools

Step 0: Get all the tools that will be needed (cross-compiler and dev libraries).

Building the Kernel

Step 1: First of all, make a directory to hold all of our development files. I’ll call mine bbb

Step 2: Get the Linux kernel for the BeagleBone and the Xenomai sources. This might take a while.

Step 3: Checkout kernel 3.8 version branch. Apply BeagleBone’s patches.

Note: In this step I revert to a specific commit because newer ones are known to cause problems.

Step 4: Get a firmware that the kernel config will need (I’m not sure whether this firmware is really needed).

Step 5: Copy the BeagleBone default config as the running config.

Step 6: Apply I-pipe patches to the BeagleBone kernel.

Step 7: Run the Xenomai prepare-kernel  script for the BeagleBone kernel.

Step 8: Configure the kernel to be built.

Under  CPU Power Management --->  CPU Frequency scaling, disable  [ ] CPU Frequency scaling . (Note: Don’t know if it’s better to leave it enabled, read the comments!)

Under  Real-time sub-system  ---> Drivers ---> Testing drivers, enable everything.

Step 9: Compile the kernel.

Note: I chose 16 to the -j  option, because my computer has 8 cores. Choose a value appropriate to your computer. I read somewhere that 2 times the number of cores is a good number.

Note: If there were errors in the compilation, the messages will probably be lost among all other output. To see them, simply run the command again.

Preparing an SD Card

Now let’s get an SD Card ready with the Angstrom distribution and our kernel. If you want to use this kernel with the distribution on the eMMC memory, just put it in the appropriate place.

Step 10: Download and copy the default Angstrom distribution to your SD Card. Replace /dev/sdX  with the path to your SD Card. sudo fdisk -l  is your friend. Note: I used a SanDisk 4GB SD Card.

CAUTION: YOU WILL LOSE ALL YOUR PREVIOUS DATA ON THE DEVICE /dev/sdX !

Step 11: Mount the Angstrom partition. Copy kernel and kernel modules (thanks for your comment, Jurg Lehni!), Xenomai modules and source folder to that partition. Replace  /dev/sdX2  with your actual path to the partition.

Testing

Now put the SD card on the BeagleBone, boot it, ssh into it and test Xenomai.

Step 12: Configure the date and compile Xenomai

Note: an example for the date command would be  date -s "21 May 2014 13:25 GMT-3" 

Step 13: Load the testing driver

Step 14: Run some tests!

User-mode latency:

In-kernel Latency:

Poke around:

Change parameters:

Great, huh? Now go develop something real time =)

  • joseph

    Hi Brunos,

    Your post was really helpful to me to get a kickstart with Xenomai on BBB. But I cannot go past beyonf make menuconfig. I get an error drivers/video/Kconfig:60:error: recursive dependency detected!

    I am not able to get past beyond this point. If you have any inputs/pointers for me it will be really helpful

    Regards,
    Joseph

    • http://brunosmartins.info Bruno Martins

      Hi Joseph,

      I didn’t get that error, but it looks like something is missing. Try:

      sudo apt-get install build-essential libncurses5 libncurses5-dev

      Bruno

  • Mouha

    Great post! anyway things have change now. How far is it to apply your procedure to the RcN linux-dev repo with the official Xenomai patches ? ( http://git.xenomai.org/xenomai-2.6.git/tree/ksrc/arch/arm/patches/beaglebone/ )

  • Jurg Lehni

    This has been extremely useful to me, thank you! But there is one information missing: How to install the modules. This is how I did it:


    cd beagle-kernel/kernel
    sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=$BBB/sd

    • http://brunosmartins.info Bruno Martins

      I’ve edited the post to add your input!

      Thanks!

      • Jurg Lehni

        Actually, that was wrong / incomplete. Here the correct command:

        sudo make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- INSTALL_MOD_PATH=../../sd modules_install

  • Jurg Lehni

    Also, this didn’t work for me:

    ./configure CFLAGS="-march-armv7-a -mfpu=vfp3" LDFLAGS="-march-armv7-a -mfpu=vfp3"

    But the version from the Japanese website worked. Note the – instead of = in CFLAGS.

    ./configure CFLAGS="-march=armv7-a -mfpu=vfp3" LDFLAGS="-march=armv7-a -mfpu=vfp3"

    • http://brunosmartins.info Bruno Martins

      Fixed =)

  • Jurg Lehni

    It seems that the system does not run at full clock speed when you turn CONFIG_CPU_FREQ off.
    I had around 600 BogoMIPS with it turned off, and 986 when it’s on.

    So I’ve turned it back on and am getting better latency even!

    • http://brunosmartins.info Bruno Martins

      Very interesting, I got the same result here. I thought that disabling the Frequency Scaling would set the CPU to the maximum frequency, but apparently I was wrong. Running cpufreq-info in this new kernel says that the CPU is at 1000 MHz. Running it in the old kernel wouldn’t give me any information.

      • Daniel

        When I turn frequency scaling on. There’s displayed a warning in the real-time sub-system menu:

        *** WARNING! You enabled APM, CPU Frequency scaling, ACPI ‘processor’ ***
        *** or Intel cpuidle option. These options are known to cause troubles ***
        *** with Xenomai, disable them. ***

        • http://brunosmartins.info Bruno Martins

          Daniel, I don’t specifically remember this warning… If you find problems with it enabled, please let me know!

          • Steve B

            Hello Bruno,
            Actually one of my team members asked me to make sure that we would be running at 1000 MHz, and I had originally disabled frequency scaling but noticed that it was showing something like 540 on the BogoMIPS in /proc/cpuinfo.

            My application I’ve been working on was very stable previously, but when I enabled CPU frequency scaling (with no other changes), I started to have problems. My application would stop working properly after a certain amount of run time and the whole OS would get very sluggish and require a reboot. Looking at cpufreq-info output after this occurred, the “ondemand” governor was selected even though I had set “performance” as the default at kernel build time, so I suspect strange things were happening with the frequency scaling and causing issues just like the warning foretold.
            My solution was to modify am335x-boneblack.dts and rebuild and install the .dtb in the /boot directory. The modification was to comment out all options for operating-points except the one I want to use, 1000000 kHz. Then, even though the CPU frequency scaling is “enabled,” you only have one possible frequency that can be selected. This fixed the issue with my application. I hope that may be helpful to you or somebody else!

  • http://www.camoveit.com Davide Faconti

    Thank you so much for sharing. I am going to test is as soon as possible 🙂

  • http://awesomebytes.com Sam Pfeiffer

    I wish I would have found this post before. I was adding Xenomai to my raspberry pi and I ended doing very similar commands to yours… took a while to figure out.
    This is my (incompleted) work: https://github.com/awesomebytes/xenorasp just in case

    I can’t wait to have a BBB and test it 🙂 Your avg and worst latencies are better than the ones I obtain on the raspberry pi.

    • Alexis

      Is it working for you ?

  • Drew

    Two typos in step 6? It says “beaqlebone”-pre/post patch.. with a Q instead of a G. beaQlebone? Not as easily noticed in lower case.

    • http://brunosmartins.info Bruno Martins

      Thanks!

  • Rolf Mennekes

    Thank you for this great description.
    A note to it.
    When installing on a virgin Xubuntu (12.04.4) following commands are missing:

    Step 8 before
    make ARCH=arm menuconfig
    doing
    sudo apt-get update
    sudo apt-get install libncurses5-dev

    and of course at the beginning “sudo apt-get install git”

    • Rolf Mennekes

      Sorry. I have not read your first answer. Please delete the comment.

      • http://brunosmartins.info Bruno Martins

        No, you are right, this should be in the post. I’ll update it soon!

  • Alexis

    Hi Bruno,

    Thanks for the tuto. I’m having one issue with step 10 and 11… Do I have to you use Gparted to create partition before? sdX should be sdb (this is what I see with fdisk -l)? And sdX2 should be sdb2?

    Could you give me advice for those parts?

    • http://brunosmartins.info Bruno Martins

      I believe that it is not necessary to create the partition. The xz -dkc Angstrom*img.xz > /dev/sdX line should take care of it. And, in your case, yes, sdX would be sdb (but it never hurts to double check :))

      • Alexis

        Does the decompression take a long time? When I do the command xz -dkc Angstrom*img.xz > /dev/sdX nothing happens on the terminal. Is it long ? Or hould I launch a new terminal and do sudo mount /dev/sdX2 sd?

        • Alexis

          Okay I think it is good now… Sorry for the inconvenience, and thanks for your answer 🙂

          Is it normal that I have a file beagle-kernel/kernel/arch/arm/boot/Image instead of beagle-kernel/kernel/arch/arm/boot/uImage ?

  • Alexis

    Hi Bruno, it is me again 🙂

    I can not flash the eMMc using my microSD card (EMTEC 4gb microSD HC class 4). The four LEDS USRX light on and stay lit up when I press the user/boot button after powering the board. Maybe it is a power issue? I will try with an external power supply 5V DC 1A.

    Is it normal that I have a file beagle-kernel/kernel/arch/arm/boot/Image instead of beagle-kernel/kernel/arch/arm/boot/uImage ?

    Thanks

    • http://brunosmartins.info Bruno Martins

      Alexis,

      I never tried to flash the eMMC, so I don’t know the cause if this hang…

      I also have never seen an “Image” instead of an “uImage”, but if your tarball came this way, it should work.

      • Alexis

        And now the Image file that I had is not in its directory anymore. Do you have any idea?

        • Alexis

          Plus the make in step 11 is not working and I don’t have the .ko files.

          Thanks for your help 🙂

          • Praveen Prabhu

            No uImage means your compilation failed. Run make again to see the error. In my case “lzop” and “mkimage” were not installed in my ubuntu. After installing them make worked and uImage was generated.

  • BiBo

    Hello i followed ur instruction but it dont work for me i’ve tried with debian instead of Angstrom…

    Maybe you can help me?

    If i type in step 11 the module has an invalid format.. and nothing happen

  • Lee

    Nice write-up. Appreciate it!

    I compiled the Xenomai on the BB and the test apps work ok. However, if I cross-compile Xenomai on a Ubuntu and copy the xenomai folder to the BB’s usr folder, the test apps run but don’t do anything.

    Any idea?

    • http://brunosmartins.info Bruno Martins

      Hmm, I did not test with a cross-compiler, but it should work. Maybe something from the host is leaking to the executables?

      It is possible that the test apps are exiting with Segmentation Fault or something, try executing them with gdb to see what is happening.

  • Alexis

    Bruno, maybe my latest problem is because of a new commit on https://github.com/beagleboard/kernel/tree/3.8 ?

    • http://brunosmartins.info Bruno Martins

      Alexis,

      I will check which specific commits I used in the entire process and update the post accordingly. I did this process only once, I have not checked for recent breaking changes.

      • Alexis

        Thanks a lot !

  • http://bbuyukguzel.com/ bbuyukguzel

    This post is really really good resource but i recommend try to install on new OS Bruno. There are a few missing part which is hard to find and fix (like install lzop, uBoot, make, gcc). I struggle 2 days and when i failed step 12, i just give up.

    If you update this post, it will be really great. But thank you anyway of course.

    • http://brunosmartins.info Bruno Martins

      Hi bbuyukguzel, thanks for your input!

      What do you mean by new OS? Debian, for instance, instead of Angstrom?

      • http://batuhan.buyukguzel.com Batuhan Büyükgüzel

        Sorry for late reply. I meant new installed OS. Fresh install Ubuntu(or whatever) on your computer and try these steps on that 🙂

  • Alexis

    Hi Bruno,

    Thanks for your update!
    I found where the errors come from, but I just don’t know how to fix them. I have all the sources installed (step 0), but I get this during the step 9 make :

    net/wireless/regdb.c:1551:1: error: expected expression before ‘const’
    make[2]: *** [net/wireless/regdb.o] Error 1
    make[1]: *** [net/wireless] Error 2

    make: *** [net] Error 2
    make: *** Waiting for unfinished jobs

    Then it continues a bit and stops without generating the uImage.

    So I checked this .c file and yes there is an obvious error…:

    //…
    static const struct ieee80211_regdomain regdom_ZW = { // Line 1547
    .alpha2 = “ZW”,
    .reg_rules = {
    REG_RULE(2402, 2482, 40, 0, 20, 0), // Line 1551
    const struct ieee80211_regdomain *reg_regdb[] = {
    // …

    I didn’t have any Hunks failed when I applied the patches.

    If it may help, here is my configuration:

    $ uname -a
    Linux ubuntu 3.2.0-61-generic-pae #93-Ubuntu SMP Fri May 2 21:46:08 UTC 2014 i686 i686 i386 GNU/Linux

    I’m running it on a virtual machine on my Macbook Pro using Parallel Desktop.

    BTW: perhaps you could add on step 12 before the ./configure … to set the date of the BBB (Year 2000 by default, so it fails while compiling)

    =>date -s “DD MMM YYYY HH:MM:SS”
    => Day / Month / Year / Hour / Minutes / Seconds

    Anyway, I found those prebuild microSD images with Xenomai included, so I could work on my BBB with xenomai: http://www.machinekit.net/deb/rootfs/wheezy/

    But I’m still interested to complete your tutorial 🙂

    Alexis

    • brunosmartins

      Alexis,

      I redone the steps and got the exact same error, but didn’t have time to find the fix. I think it has something to do with the newer commits on the Beaglebone Kernel repo. Maybe when I first wrote this I used the commit from January 15th 2014,so I’ll try to compile from that one.

      • Alexis

        Yeah that’s possible.
        And also when I run latency with the machinekit images (see the link in my comment) I got 50 uS worst case in user mode… Your results are pretty impressive!

      • Alexis

        Is it working for you?

        • brunosmartins

          I tried using the specific commit that I used at the time of the writing of this post. It did compile now, although I did not test it as I don’t have access to my Beaglebone at the moment. I am updating the post, changing Step 3 (and Step 12 per your suggestion). If you can, please try with the changes and let me know if it works.

          • Alexis

            I think it is working !! 😉 I did not get the errors that I had before, thank you so much. Latency and Klatency are running. I’m going to do more tests then.

            You could add some “sudo” before mkdir and cp in step 11, and “sudo umount sd” at the end.

            However, I didn’t have a result as good as yours for klatency (about 30 microseconds for my worst case).

      • Gregor Rößle

        I encountered the same error (I downloaded the kernel sources on May 19th 2014) and fixed it by manually correcting the net/wireless/regdb.c file. Marking it ro it survived the next make command and the kernel got built.

  • Gregor Rößle

    One hint for those who also fail to compile xenomai kernel modules:
    I cross compiled the kernel on my Ubuntu VM using my standard user. In Angstrom linux on the SD card I put everything in the root user’s home. I found that in several locations symlinks point to the xenomai sources. Those symlinks point to nowhere because user root != my Ubuntu user.
    So it will be best to use the same user name also in the Angstrom linux. I fixed this by creating the same home directory and placing a symlink to the kernel sources in my root home directory.

  • Amit

    Hi Bruno,

    For Step 4 I am getting this error;

    kernel/firmware/am335-pm-firmware.bin: No such file or directory

    How can I solve this ?
    Should the name of the directory you created (bbb) has to something with the scripts ? I have made with different name.

    • brunosmartins

      Did you do step 4?

      • Amit

        No I was not able to, since it failed with an error I posted above.

        • brunosmartins

          Try

          wget “http://arago-project.org/git/projects/?p=am33x-cm3.git;a=blob;f=bin/am335x-pm-firmware.bin;h=2d9e42dda3d4a3c32d2cdcf2584ec9f4a71f197c;hb=HEAD” -O kernel/firmware/am335x-pm-firmware.bin

          • Amit

            Hi I was able to complete the 4th step successfully.

            Also I have a question, if you have same kind of web page without cross compiler. I mean I want to compiler my code on the BBB ?

            It would be great if you could have it.

          • brunosmartins

            I don’t, but you can just copy the files to the BBB before the compilation steps and remove cross-compiler specific options. It will take much longer to compile, though…

          • Amit

            Hi Bruno,
            In step 11, I have problem in the following script
            sudo cp beagle-kernel/kernel/arch/arm/boot/uImage sd/boot/uImage-3.8.13

            the error I am getting is this

            cannot stat `beagle-kernel/kernel/arch/arm/boot/uImage’: No such file or directory

            Can you tell me how to solve this ?

            =====One more question=====

            Do your steps from 2 to 9 depend on this “export BBB=$(pwd)” ??
            (I am asking this because I have used another variable instead of BBB)

          • brunosmartins

            Hi Amit,

            Seems like a compilation problem, apparently uImage is not being generated. Check your logs for errors.

            I use “export BBB…” for convenience. If you see a command that has $BBB, then it is needed. You can replace $BBB with the path you chose.

  • http://elinux.org/Category:ECE597 Mark Yoder

    Bruno:

    Nice job. It was very helpful. I created a recipe[1] that updates the process for the 3.8.13 kernel compiled using Robert C. Nelson’s tools.
    I think it’s now 12 easy steps.

    –Mark

    [1] http://elinux.org/EBC_Xenomai

    • brunosmartins

      Cool!

  • Javier Camus

    when i run: ./configure CFLAGS=”-march=armv7-a -mfpu=vfp3″ LDFLAGS=”-march=armv7-a -mfpu=vfp3″
    i get the next errors:

    checking build system type… armv7l-unknown-linux-gnueabihf

    checking host system type… armv7l-unknown-linux-gnueabihf

    checking for a BSD-compatible install… /usr/bin/install -c

    checking for gcc… no

    checking for cc… no

    checking for cl.exe… no

    configure: error: in `/root/xenomai-2.6.3′:

    configure: error: no acceptable C compiler found in $PATH

    how can i solve this?

    • brunosmartins

      As your last message says, you probably don’t have a compiler installed. Try “sudo apt-get install build-essential” for Ubuntu

      • Javier Camus

        i have already installed build-essential

        • brunosmartins

          If you run
          gcc
          with no arguments, what happens?

          • Javier Camus

            when i run gcc with no arguments, i got this:
            gcc: fatal error: no input files
            compilation terminated.

            What should i do?

          • brunosmartins

            That’s weird. What cross-compiler you installed? Can you compile something with that cross-compiler? Did you install it using the package manager or by other means? If you did the latter, is your PATH right? These are the sort of things I would check.

          • Bitblit11

            build-essentials installs the host build tools, which won’t do much good when building ARM target code on an x86 host platform. Did you install the cross compiler?

      • Javier Camus

        i got exactly these errors:

        checking build system type… armv7l-unknown-linux-gnueabihf
        checking host system type… armv7l-unknown-linux-gnueabihf
        checking for a BSD-compatible install… /usr/bin/install -c
        checking for gcc… no
        checking for cc… no
        checking for cl.exe… no
        configure: error: in `/root/xenomai-2.6.3′:
        configure: error: no acceptable C compiler found in $PATH

      • Javier Camus

        i have already installed build-essential

  • Javier Camus

    when i run: ./configure CFLAGS=”-march=armv7-a -mfpu=vfp3″ LDFLAGS=”-march=armv7-a -mfpu=vfp3″
    i get the next errors:
    checking build system type… armv7l-unknown-linux-gnueabihf
    checking host system type… armv7l-unknown-linux-gnueabihf
    checking for a BSD-compatible install… /usr/bin/install -c
    checking for gcc… no
    checking for cc… no
    checking for cl.exe… no
    configure: error: in `/root/xenomai-2.6.3′:
    configure: error: no acceptable C compiler found in $PATH
    how can i solve this?
    i have already installed build-essential.

  • Guest

    Great Tutorial. How can I run my xenomai user space application in BBB!!!! Do I need to cross compile it !!!! How can I cross compile my application ??
    Thank You

  • Pingback: Installing Xenomai on Beaglebone using Debian distribution | Random Linux Hacks

  • Ankit Sanghvi

    trying ./patch.sh

    i got the error
    error: RPC failed; result=52, HTTP code = 0
    fatal: The remote end hung up unexpectedly

  • Marcelo Gobetti

    hello! did you guys know that we can also install the xenomai kernel over the debian default one via apt-get? http://elinux.org/Beagleboard:BeagleBoneBlack_Debian#3.8.x_BBW.2FBBB_FULL_Cape_Support_.2B_Xenomai

    question is: is there any performance difference between that and the compiled one (like from the guide here)?

    for now, the difference I can tell is all the applications that come with xenomai, e.g. latency and klatency…

    I’ve tested using cyclictest though https://github.com/clrkwllms/rt-tests

    and there is a big difference on the latency got compared to that obtained by Debian’s kernel, the average latency is 16us vs. Debian’s 60us, however the max latency is around 800us for both…

  • Sean Machin

    Hi Bruno, this is a good post. Do you have any advice on how to get Xenomai working on an older custom system based on the BeagleBone white? We are still using the older 3.2 kernel from TI’s PSP download.

  • Peiyao Hu

    Hello! I successed to install xenomai on beagelbone black by this blog. Then I want to install RTnet on beaglebone black , but now I have some trouble on this . Here are some erro messages :

    checking for RT-extenxion target arch………… arm

    checking for RTnet target arch…………..arm

    checking for CROSS_COMPILE…………none

    checking for kernel modules extension…………… .ko

    checking for rtdm/rtdm_driver.h …………….result : no

    configure : erro : *** header not found or working , please check RT-extension installation

    But the rtdm/rtdm.h is really exsited in /usr/xenomai .
    Do you know what happened ?

    • Peiyao Hu

      Also when I check the config.log of /usr/src/RTnet-0.9.13 , I found one massege as follow :

      configure : 11485 : checking for rtdm/rtdm.h

      configure : 11505 : make -C /usr/xenomai ARCH=arm CROSS_COMPILE= V=1 M=/usr/src/rtent-0.9.13 SUBDIRS=/usr/src/rtnet-0/9/13 modules > /dev/null

      make : *** No rule to make target ‘modules’ . Stop .

      configure : 11513 : $? =2

      checking for rtdm/rtdm_driver.h …………….result : no

      configure : erro : *** header not found or working , please check RT-extension installation
      Are there Someone give me some advices?

      • Feng

        have you fixed this problem?

  • Mohamed Fawzy

    i followed documentation to get xenomai up and running on a udoo board

    but when i run the latency test i get this error message : Xenomai: native skin or CONFIG_XENO_OPT_PERVASIVE disabledwhen i check Troubleshooting guide i found that i should have /proc/xenomai/version but for me proc folder doesn’t contain (xenomai folder) so which step is wrong

    which step creates the cenomai folder in proc folder

  • Antoine

    Hello, do you know if it is possible to install xenomai 3 on the BBB? I cannot find any information on the internet, this is weird, no?