Compiling LIRC_BBB for IR control on a Beagle Bone Black

One of my favorite hobbies is doing home automation. This includes a near complete Z-Wave enabled house and a Vera Lite home automation controller

This is great for smartphone control but I still use a traditional IR remote for controlling my home theater system. In order to integrate I had been using a RaspberryPI (RPI) with LIRC, the RPI_LIRC driver, and some custom Perl CURL Scripts to control my lights.

I recently had to give up the RPI for another project and decided to integrate this with a beagle bone black I have been testing with.  Fortunately support with the Beagle Bone Black and IR is available with LIRC_BBB (a modified LIRC_RPI) thanks to user Hani93 and  their Github contribution. All credit to that user for making this guide possible.

Installation is certainly not as easy as a RPI. Unlike LIRC_RPI, there is no APT-GET INSTALL package for LIRC_BBB. A lack of instructions anywhere on the net prompted me to write this guide.

The basic steps involve:

  1. Downloading the BBB Kernel.
  2. Patching the Kernel with the standard BBB Patches.
  3. Downloading the LIRC_BBB driver (modified from LIRC_RPI).
  4. Patching the Kernel with the LIRC_BBB driver.
  5. Configuring the kernel with support for LIRC_BBB.
  6. Compiling the kernel.
  7. Booting the kernel and testing!

This guide will walk you through the above and doing a compile directly on the BBB. I know you can get things done faster with a cross-compile on a desktop computer but I didn’t feel like setting up a whole build environment just for a single compile on ARM!

Step 1: Kernel preparation

I’m going to assume that you have a BBB and are running a current version of Debian. you should also have sufficient space available (at least 1gb). For this guide I was running linux-3.8.13-bone50. You can verify with “uname -a” but I believe any version of linux-3.8.13 on Debian should work.

Lets start by following this guide here describing how to do this on a BBB:

http://dumb-looks-free.blogspot.com/2014/06/beaglebone-black-bbb-compile-kernel.html

I am going to roughly follow that guide with slight deviation. We will start by installing some basic dependencies:

root@beaglebone:~/# apt-get install linux-source screen
root@beaglebone:~/# apt-get install build-essential fakeroot
root@beaglebone:~/# apt-get install gcc make bc screen ncurses-dev

If you are doing this via SSH, I highly recommend doing the remainder during a SCREEN session. This will make it so during the 8 hour compile on the BBB, a disconnect of the SSH session does not kill the compile. Read up on the basic usage HERE
Now lets download the kernel source. There are two options. You can either do a GIT clone from the BBB team and patch it yourself or use a great automated script to do this all for you. Your file paths will differ depending on which option you choose.

OPTION #1: GIT Clone direct from the official BBB Team

root@beaglebone:/somepath/# git clone git://github.com/beagleboard/kernel.git
root@beaglebone:/somepath/# cd kernel
root@beaglebone:/somepath/kernel/# git checkout 3.8
root@beaglebone:/somepath/kernel/# ./patch.sh

You are going to need to remember where you put the kernel and adjust this guide from there.

OPTION #2: Use the automated script to get the source for you

root@beaglebone:~/# wget https://raw.github.com/gkaindl/beaglebone-ubuntu-scripts/master/bb-get-rcn-kernel-source.sh
root@beaglebone:~/# chmod +x bb-get-rcn-kernel-source.sh
root@beaglebone:~/# ./bb-get-rcn-kernel-source.sh

This puts the Kernel source and patch in /usr/src/linux-3.8.13-bone50/

I personally chose option #2 and roughly followed the guide posted above.

Step 2:  LIRC_BBB Patching

Lets start by grabbing the patch from its creator Hani93 (Once again, ALL Credit to him as this would not be possible without him)

First CD into the directory of your kernel source. If you picked Option #2 it will be in /usr/src/linux-3.8.13-bone50/. If you picked option #1, it will be a subfolder of kernel in whatever directory you ran the commands in.

Run the following

root@beaglebone:/usr/src/linux-3.8.13-bone50/# wget https://raw.githubusercontent.com/hani93/lirc_bbb/master/0001-LIRC_BBB.patch

root@beaglebone:/usr/src/linux-3.8.13-bone50/# patch -p1 < 0001-LIRC_BBB.patch

patching file drivers/staging/media/lirc/Kconfig
patching file drivers/staging/media/lirc/Makefile
patching file drivers/staging/media/lirc/lirc_bbb.c

If everything went well, congrats! you have just patched the kernel source with the LIRC_BBB Patch! Yes it really was that easy.

Step 3: Kernel Configuration and Firmware

Once again, ensure you are in the root folder of you kernel source.

The BBB needs firmware in order for the kernel compile to success. Lets get the firmware in the kernel source:

root@beaglebone:/usr/src/linux-3.8.13-bone50/#  cp /lib/firmware/am335x-pm-firmware.bin ./firmware/

Next, Import your current kernel config into the proposed kernel config

root@beaglebone:/usr/src/linux-3.8.13-bone50/# make mrproper

root@beaglebone:/usr/src/linux-3.8.13-bone50/# zcat /proc/config.gz > .config

root@beaglebone:/usr/src/linux-3.8.13-bone50/# make oldconfig

Now we need to configure the kernel to include the LIRC_BBB driver when we compile it. To do this, we use the command:

root@beaglebone:/usr/src/linux-3.8.13-bone50/# make menuconfig

In the Text GUI, do the following to enable the BBB_LIRC Driver:

  1. Open (D)evice Drivers -> (S)taging Drivers
  2. Enable M(e)dia staging drivers
  3. Open Media staging drivers
  4. Enable Linux Infrared Remote Control IR receiver/transmitter drivers
  5. Open Linux Infrared Remote Control IR receiver/transmitter drivers
  6. Enable Homebrew GPIO Port Receiver/Transmitter for the BeagleBone Black

Now exit and SAVE changes.

Finally, I think we need to do this. It was in the guide posted above but i’m not 100% certain as to its purpose.
Modify the file .config to specify a LOCALVERSION for the build

root@beaglebone:/usr/src/linux-3.8.13-bone50/# nano .config

Adjust the parameter CONFIG_LOCALVERSION=”-bone50-GL”

Save and quit.

NOTE!

I’m not sure why but modify the Kernel license is not compatible with the license of LIRC_BBB. I don’t know much about this and this is probably the correct solution but I modified the file ./drivers/staging/media/lirc/lirc_bbb.c with NANO

and changed the line:

MODULE_LICENSE(“GPLv2”);

TO

MODULE_LICENSE(“GPL”);

If there is a better way to overcome this please let me know. I’m a hobbyist, not a kernel ‘hacker’. I only know that I was getting the following error when compiling the kernel:

FATAL: modpost: GPL-incompatible module lirc_bbb.ko uses GPL-only symbol ‘gpio_direction_output’

This was the only workaround I could come up with.

Step 4: Compilation of the Kernel

Nearly complete! Lets make our Kernel, Modules, and install the modules.

This step will take about 8 hours so just be patient! I left mine running overnight.

root@beaglebone:/usr/src/linux-3.8.13-bone50/# make -j1 zImage modules
root@beaglebone:/usr/src/linux-3.8.13-bone50/# make modules_install

Check in on the compile every once in a while. If everything turned out good and you got NO Errors. CONGRATULATIONS, you completed all of the difficult portions.

We now need to activate the new kernel. We start by copying it to the boot partition. I called the new kernel “zImage-lirc

root@beaglebone:/usr/src/linux-3.8.13-bone50/# cp arch/arm/boot/zImage /boot/uboot/zImage-lirc

Finally adjust the bootloader to use out new kernel

root@beaglebone:/usr/src/linux-3.8.13-bone50/# nano /boot/uboot/uEnv.txt

Change

kernel_file=zImage

TO

kernel_file=zImage-lirc

Save and quit nano. Now, cross your fingers and reboot!

After the reboot, login and check your kernel version. If it looks newer, you are done:

root@beaglebone:~# uname -a
Linux beaglebone 3.8.13-bone50-GL #1 SMP Wed Oct 8 00:14:02 UTC 2014 armv7l GNU/Linux

You will notice that my kernel compile date is “Wed Oct 17 00:14:02”.

Great thats the right kernel!

Now test loading LIRC_BBB with:

root@beaglebone:~# modprobe lirc_bbb

Assuming no errors, you should see it listed in lsmod:

root@beaglebone:~# lsmod

Module Size Used by
lirc_bbb 5699 0
lirc_dev 9057 1 lirc_bbb
g_multi 50407 2
libcomposite 15028 1 g_multi

if lirc_bbb is there, you are done!

From here you can test LIRC and follow the basic RPI configuration. Sending is done on pin “P9_14” and receiving on pin “P9_12“.

I personally just followed the guide here:

http://www.instructables.com/id/Raspberry-Pi-Universal-Remote/

Advertisements

Thoughts? Comments? Reply here!

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: