Building a Kernel driver on imx6 sabre target.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Building a Kernel driver on imx6 sabre target.

5,675 Views
chrishossack
Contributor III

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

Labels (3)
0 Kudos
4 Replies

1,590 Views
Yuri
NXP Employee
NXP Employee

Hello,

You may try using the SDK, which contains set of libraries and headers.

$ bitbake core-image-minimal –c populate-sdk

http://www.yoctoproject.org/bulk/devday-eu-2014/ypdd14-hudson-sdk.pdf

http://www.yoctoproject.org/docs/1.8/ref-manual/ref-manual.html#sdk-dev-environment

  As for kernel headers :

http://stackoverflow.com/questions/31256770/using-populate-sdk-to-include-kernel-headers


Have a great day,
Yuri

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,590 Views
chrishossack
Contributor III

Hi,

I've created my own layer (see Re: Changing the Kernel configuration for i.MX6 SABRE ) and added the following two lines to my linux-imx_3.10.53.bbappend.

$ cat ../sources/meta-fsl-pci/recipes-kernel/linux/linux-imx_3.10.53.bbappend

:

IMAGE_INSTALL_append = " kernel-devsrc"

TOOLCHAIN_TARGET_TASK_append = " kernel-devsrc"

:

Then I perform a build

$ bitbake core-image-base -f -c populate_sdk

And then extract the core-image-base-imx6qsabresd.tar.bz2 file system

sudo tar xvf ./tmp/deploy/images/imx6qsabresd/core-image-base-imx6qsabresd.tar.bz2 -C rfs

But I'm not see any build directory under rfs/lib/modules/3.10.53-1.1.0_ga+g496fbe0

What am I doing wrong?

cheers

Chris

0 Kudos

1,590 Views
Yuri
NXP Employee
NXP Employee

Hello,

  please use the recent Linux BSP

i.MX 6 Series Software and Development Tool|NXP

Regards,

Yuri.

0 Kudos

1,590 Views
chrishossack
Contributor III

Hi Yuri,

thank you, that looks very interesting. It will take me a couple of days to go through it. To help me get started I know I need to create a new branch for my work, but I'm not sure how to start. At the moment I use the following line to get the imx-3.14.38-6UL_ga code

repo init -u git://git.freescale.com/imx/fsl-arm-yocto-bsp.git -b imx-3.14.38-6UL_ga

But looking at this example (https://community.freescale.com/servlet/JiveServlet/previewBody/95096-102-10-7847/yocto_tutorial.pdf ) I need to create my own branch like this

repo init -u git://git.freescale.com/imx/fsl-arm-yocto-bsp.git -b my_branch

How do I know what code I'm going to be working on, eg 3.14.38, or 3.10.53, etc

cheers

Chris

0 Kudos