AnsweredAssumed Answered

Building a Kernel driver on imx6 sabre target.

Question asked by Chris Hossack on Sep 29, 2015
Latest reply on Jul 25, 2016 by Yuri Muhin

Hi,

I’m trying to build a kernel driver on my sabre platform. To do this I need the kernel headers. I’ve managed to hack together a root file system (RTF), but I’m hoping there’s an easier way.

 

At the moment my core_image_base is based on imx-3.14.38-6UL_ga and I’m using ubuntu-precise-12.04.3-armhf.com-20131129.tar.xz for the RTF. Here are the steps I use…

 

Create an sd card with fsl-image-base.sdcard. My sdcard is /dev/sdd

$ cd ~

$ sudo dd if=<Yocto>/tmp/deploy/images/imx6qsabresd/core-image-base-imx6qsabresd.sdcard of=/dev/sdd bs=1M && sync

 

After this the sdcard partitions are available under /media.

Remove all files on the sdcard rootfs (eg sdd2) and then untar the unbuntu core, eg

$ cd /media/<sdcard-rootfs>

$ sudo rm -rf *

$ sudo tar --numeric-owner -xf <downloads>/ubuntu-precise-12.04.3-armhf.com-20131129.tar.xz

 

Then mount a local copy of the core_image_base RFS so we can copy the fsl-image-base lib & boot over the ubuntu core rootfs.

$ cd ~

$ mkdir rootfs

$ sudo mount -o loop -t ext3 =<Yocto>/tmp/deploy/images/imx6qsabresd/core-image-base-imx6qsabresd.ext3 rootfs

$ sudo rsync -artv rootfs/lib/modules/ /media/<sdcard-rootfd>/lib/modules/

$ sudo rsync -artv rootfs/boot/ /media/<sdcard-rootfd>/boot/

 

We now need to copy the kernel/build files across. We use rsync -k so all symbolic links are expanded.

$ cd /media/<sdcard-rootfd>/lib/modules/3.14.28-1.0.0_ga+g91cf351

$ sudo rsync -arkt  <Yocto>/tmp/work/imx6qsabresd-poky-linux-gnueabi/linux-imx/3.14.28-r0/build/ build/

 

Note: on previous Yocto branches the kernel is built within the .git directory, so you will need this command instead (untested)

$ sudo rsync -arkt  <Yocto>/tmp/work/imx6qsabresd-poky-linux-gnueabi/linux-imx/<version>/.git/ build/

                                               

Then change ownership to root

$ cd build

$ sudo chown -R root:root *

 

To auto login to the root user via the serial USB lead.

$ sudo vi /media/<sdcard-rootfd>/etc/init/ttymcx0.conf

And copy the following text in to it.

start on stopped rc RUNLEVEL=[12345]

stop on runlevel [!12345]

 

respawn

exec /sbin/getty -a ubuntu -L ttymxc0 115200 vt102

 

We can now eject the sdcard and power on the SABRE platform. We now perform all following actions on the imx6 target.

 

Before we can compile kernel driver we need to prepare the modules and install any software we need.

$ sudo apt-get install build-essential module-assistant

$ cd /lib/modules/$(uname -r)/build

$ sudo make modules_prepare

 

This gives an error since it can’t find the kernel source, eg

make: *** /mnt/data/imx6/fsl-release-bsp-3-14-38/build-x11/tmp/work-shared/imx6qsabresd/kernel-source: No such file or directory.  Stop.

make: *** [all] Error 2

 

This is because it was built on my host PC at that location (e.g. <Yocto> = /mnt/data/imx6/fsl-release-bsp-3-14-38/build-x11) and this path is splattered all over the kernel code. So we need to add a fake directory and soft link to it, e.g.

sudo mkdir -p /mnt/data/imx6/fsl-release-bsp-3-14-38/build-x11/tmp/work-shared/imx6qsabresd

sudo ln -s /lib/modules/$(uname -r)/build/source /mnt/data/imx6/fsl-release-bsp-3-14-38/build-x11/tmp/work-shared/imx6qsabresd/kernel-source

 

Now we can compile our kernel modules.

sudo make modules_prepare

 

Now, at long last you can build your kernel driver, e.g.

$ cd <your driver source>

$ make

 

All of this seems very complicated and I would love to find an easier way to build kernel drivers on the target.

 

I’ve seen this thread https://communities.intel.com/message/280388 which seems to suggest that I can build .deb packages for my headers. It would be sooo much nicer if I could configure Yocto to generate a set of .deb packages that I could just install to allow kernel drivers to be compiled on the target.

Or some way to get all of the required kernel source files built and prepared in to the file system automatically.

 

Cheers

 

Chris

Outcomes