0

im on BSP v1.1 yocto is 1.6

I'm trying to set up the cross compile toolchain to compile character driver code but the output i get is

[mark@localhost ~]$ ${CC} first.c -o first

first.c:1:24: fatal error: linux/init.h: No such file or directory

.#include ^ compilation terminated.

I think the issue is that the header is not in the toolchain /opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/include/linux/~ there is no at this location

I think something has to be added as IMAGE_INSTALL or IMAGE_FEATURE but i dont know what

am I on the right track ? does anyone know what i have to add ? or am i completely off tracks altogether?

0andriy
  • 4,183
  • 1
  • 24
  • 37

1 Answers1

2

Well, first and foremost, you can never build a kernel module by just running ${CC} on it. You should always use a Makefile, which redirects most of its work to the kernel source Makefil.

Create a Makefile for you module, consisting of something similar to:

obj-m += hello-1.o

all:
    make -C  $(KERNEL_SRC M=$(PWD) modules

clean:
    make -C  $(KERNEL_SRC) M=$(PWD) clean

Example taken from The Linux Kernel Module Programming Guide (Note that the actual commands needs to have a tab character for indentation).

Then you'll have to define KERNEL_SRC to be /opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel/, either in the Makefile, or from your make call. (Using a variable like KERNEL_SRC will ensure that your module recipe automatically picks the right location when building using bitbake).

To manually build your kernel module:

  1. Source the environment-* file for your SDK.
  2. Go to you modules directory.
  3. KERNEL_SRC=/opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel LDFLAGS="" make However, this will fail, as fixdep can't be found. We'll fix this manually.
  4. cd /opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel
  5. make silentoldconfig scripts
  6. Go back to your modules directory.
  7. KERNEL_SRC=/opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel LDFLAGS="" make

This should now produce hello.ko which you should be able to insmod on the Galileo board.

Anders
  • 8,541
  • 1
  • 27
  • 34
  • When i do no 7. i get back CC [M] /home/mark/GalileoDriver/hello-1.o Building modules, stage 2. MODPOST 1 modules /bin/sh: scripts/mod/modpost: No such file or directory make[2]: *** [__modpost] Error 127 make[1]: *** [modules] Error 2 make[1]: Leaving directory `/opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel' make: *** [all] Error 2 ` Any suggestion? – Mark Sherlock Mar 26 '15 at 14:39
  • Did step 5 work out OK? `scripts/mod/modpost` should have been created at that point, together with e.g. `scripts/basic/fixdep`. – Anders Mar 26 '15 at 14:53
  • well to be honest i kept hitting enter will i run again ? – Mark Sherlock Mar 26 '15 at 15:20
  • I have another question up if you would be able to help me – Mark Sherlock Mar 30 '15 at 10:07
  • Sure, just ask. Though maybe it should be a new question? Another possibility is to take out on the Yocto Project mailing list. – Anders Mar 30 '15 at 20:27
  • I SCPed the file to the Galileo and insmod it my issue now is it's saying I have the wrong format. insmod: ERROR: could not insert module hello-1.ko: Invalid module format – Mark Sherlock Mar 31 '15 at 10:13
  • Well, look at the standard things... Double check the arch of the hell0-1.ko, run modinfo on the module and verify everything. Double check the .config file in /opt/iot-devkit/1.6.1/sysroots/i586-poky-linux/usr/src/kernel with the one belonging to the running kernel. Is CONFIG_MODVERSIONS (and friends) enabled or not? – Anders Apr 02 '15 at 13:31