3 Replies Latest reply on Aug 26, 2015 8:44 AM by Sriranjan

    Unable to correctly include linux/i2c-dev.h

    njg

      I'm working on writing a kernel module for my Edison with Arduino board, and I'm having trouble including linux/i2c-dev.h. What is the proper way to include a linux kernel header when building a kernel module with Yocto? I'd appreciate any help because I'm pretty stumped. Here's what I've done:

       

      I successfully built the hello-mod example with bitbake and was able to insmod it correctly. When I added #include <linux/i2c-dev.h> to hello-mod.c and build it, it still built. Here's where my problem starts, when I try to test that the correct i2c-dev.h was included, bitbake complains that I2C_SMBUS_BLOCK_MAX is undefined. I checked in the copy of i2c-dev.h that is included in mraa and the one on my edison, and in both places they are defined as 32. I suspect that bitbake is using my local workstation's copy of i2c-dev.h which is why it compiles, but doesn't recognize I2C_SMBUS_BLOCK_MAX.

       

      #include <linux/module.h> 
      #include <linux/init.h>  
      #include <linux/kernel.h>   
      #include <linux/i2c-dev.h>
      int dev_init(void)  
      {
           printk("Hello world\n");
           printk("I2C_SMBUS_BLOCK_MAX: %d\n", I2C_SMBUS_BLOCK_MAX);
           return 0;
      }
      int dev_exit(void)
      {
          printk("Goodbye world\n");
          return 0;
      }
      module_init(dev_init);
      module_exit(dev_exit);
      

      Here's what I've done to try to solve my problem:

      • defined the KERNEL_SRC in the Makefile like this: KERNEL_SRC := /home/USER_NAME/intel_edison/edison_src/build/tmp/work/edison-poky-linux/linux-yocto/3.10.17+gitAUTOINC+6ad20f049a_c03195ed6e-r0/linux-edison-standard-build/
      • symlinking in the file into the hello-mod/file directory and then adding "file://i2c-dev.h \" to the SRC_URI in hello-mod_0.1.bb
      • adding to FILESEXTRAPATHS, FILES, and CFLAGS in hello-mod_0.1.bb like this:

      FILESEXTRAPATHS_prepend := "/home/USER_NAME/intel_edison/edison_src/build/tmp/work/core2-32-poky-linux/linux-libc-headers/3.14-r0/linux-3.14/include/linux:"

      FILES_${PN} += "/home/USER_NAME/intel_edison/edison_src/build/tmp/work/core2-32-poky-linux/linux-libc-headers/3.14-r0/linux-3.14/include/linux"  (also tried without _${PN} at the end of FILES)

      CFLAGS_prepend = "-I /home/USER_NAME/intel_edison/edison_src/build/tmp/work/core2-32-poky-linux/linux-libc-headers/3.14-r0/linux-3.14/include/linux/"

      • adding a do_install_append routine similar to the one used in mraa's bitbake recipe like:

      do_install_append() {

          install -d ${D}${includedir}/linux

          install -m 644 include/linux/i2c-dev.h

          rm -f ${D}${includedir}/linux/i2c-dev.h

      }

      In every case, bitbake gives the same error complaining that I2C_SMBUD_BLOCK_MAX isn't defined.

       

      I looked at how mraa includes linux/i2c-dev.h, and it looks like they made a copy of i2c-dev.h from an already built kernel and then included it in their package. My ideal solution to this problem would be to directly include i2c-dev.h from the kernel source, but it would be fine if I had to make a copy like mraa.

       

      I imagine the solution is pretty simple, but I'm new to yocto and bitbake and have more or less exhausted Google and StackOverflow. Thanks for any help!

        • 1. Re: Unable to correctly include linux/i2c-dev.h
          njg

          If anyone is interested, here's a copy of the output from "bitbake hello-mod"

           

          WARNING: Host distribution "Debian-8.1" has not been validated with this version of the build system; you may possibly experience unexpected failures. It is recommended that you use a tested distribution.
          Loading cache...done.
          Loaded 1289 entries from dependency cache.
          NOTE: Resolving any missing task queue dependencies
          
          Build Configuration:
          BB_VERSION        = "1.22.0"
          BUILD_SYS        = "x86_64-linux"
          NATIVELSBSTRING  = "Debian-8.1"
          TARGET_SYS        = "i586-poky-linux"
          MACHINE          = "edison"
          DISTRO            = "poky-edison"
          DISTRO_VERSION    = "1.6.1"
          TUNE_FEATURES    = "m32 core2"
          TARGET_FPU        = ""
          meta             
          meta-yocto       
          meta-yocto-bsp   
          meta-edison     
          meta-edison-distro
          meta-edison-middleware
          meta-edison-arduino
          meta-edison-devtools = "<unknown>:<unknown>"
          
          NOTE: Preparing runqueue
          NOTE: Executing SetScene Tasks
          NOTE: Executing RunQueue Tasks
          NOTE: Running task 411 of 432 (ID: 7, /home/nick/intel_edison/edison-src/poky/meta/recipes-kernel/hello-mod/hello-mod_0.1.bb, do_compile)
          NOTE: recipe hello-mod-0.1-r0: task do_compile: Started
          Log data follows:
          | DEBUG: Executing shell function do_compile
          | NOTE: make -j 4 -e MAKEFLAGS= KERNEL_PATH=/home/nick/intel_edison/edison-src/build/tmp/sysroots/edison/usr/src/kernel KERNEL_SRC=/home/nick/intel_edison/edison-src/build/tmp/sysroots/edison/usr/src/kernel KERNEL_VERSION=3.10.17-yocto-standard CC=i586-poky-linux-gcc  LD=i586-poky-linux-ld.bfd  AR=i586-poky-linux-ar
          | make -C  M=/home/nick/intel_edison/edison-src/build/tmp/work/edison-poky-linux/hello-mod/0.1-r0
          | make[1]: *** M=/home/nick/intel_edison/edison-src/build/tmp/work/edison-poky-linux/hello-mod/0.1-r0: No such file or directory.  Stop.
          | Makefile:11: recipe for target 'all' failed
          | make: *** [all] Error 2
          | ERROR: oe_runmake failed
          | WARNING: exit code 1 from a shell command.
          | ERROR: Function failed: do_compile (log file is located at /home/nick/intel_edison/edison-src/build/tmp/work/edison-poky-linux/hello-mod/0.1-r0/temp/log.do_compile.14999)
          NOTE: recipe hello-mod-0.1-r0: task do_compile: Failed
          NOTE: Tasks Summary: Attempted 426 tasks of which 425 didn't need to be rerun and 1 failed.
          
          Summary: 1 task failed:
            /home/nick/intel_edison/edison-src/poky/meta/recipes-kernel/hello-mod/hello-mod_0.1.bb, do_compile
          Summary: There was 1 WARNING message shown.
          Summary: There was 1 ERROR message shown, returning a non-zero exit code.
          
          • 2. Re: Unable to correctly include linux/i2c-dev.h
            PabloM_Intel

            Hi njg,

             

            We apologize for the late reply. We’re still working on your case to provide a useful response. Could you please provide us your hello-mod_0.1.bb recipe?

             

            Regards,

            PabloM_Intel

            • 3. Re: Unable to correctly include linux/i2c-dev.h
              Sriranjan

              Any reply on this guys from intel side?I am working on modifying the kernel to add some printk() statements to see changes in the dmesg output.