[yocto] Using standard SDK to build LKM

Alberto Spin a.spin at datawatt.nl
Thu Sep 7 07:09:36 PDT 2017


I've build a Standard SDK using yocto

      bitbake angstrom-lxde-image -c populate_sdk

I made sure that the kernel sources are included in the SDK

TOOLCHAIN_TARGET_TASK_append = "kernel-devsrc"

After installing the generated SDK at my workstation (separate machine from my build host), I verified that the kernel sources are present

In the directory where the SDK has been installed, the kernel subdirectory has been added.

datawatt at O-LINUX-1:~/toolchain/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/usr/src$ tree -L 1
.
├── backfire
├── debug
└── kernel

3 directories, 0 files

Next I'm trying to build a simple LKM


  *   First I source the environment setup script

*********
I'm using this c-source:

/**
* @file    hello.c
* @author  Derek Molloy
* @date    4 April 2015
* @version 0.1
* @brief  An introductory "Hello World!" loadable kernel module (LKM) that can display a message
* in the /var/log/kern.log file when the module is loaded and removed. The module can accept an
* argument when it is loaded -- the name, which appears in the kernel log files.
* @see http://www.derekmolloy.ie/ for a full description and follow-up descriptions.
*/

#include <linux/init.h>             // Macros used to mark up functions e.g., __init __exit
#include <linux/module.h>           // Core header for loading LKMs into the kernel
#include <linux/kernel.h>           // Contains types, macros, functions for the kernel

MODULE_LICENSE("GPL");              ///< The license type -- this affects runtime behavior
MODULE_AUTHOR("Derek Molloy");      ///< The author -- visible when you use modinfo
MODULE_DESCRIPTION("A simple Linux driver for the BBB.");  ///< The description -- see modinfo
MODULE_VERSION("0.1");              ///< The version of the module

static char *name = "world";        ///< An example LKM argument -- default value is "world"
module_param(name, charp, S_IRUGO); ///< Param desc. charp = char ptr, S_IRUGO can be read/not changed
MODULE_PARM_DESC(name, "The name to display in /var/log/kern.log");  ///< parameter description

/** @brief The LKM initialization function
*  The static keyword restricts the visibility of the function to within this C file. The __init
*  macro means that for a built-in driver (not a LKM) the function is only used at initialization
*  time and that it can be discarded and its memory freed up after that point.
*  @return returns 0 if successful
*/
static int __init helloBBB_init(void){
   printk(KERN_INFO "EBB: Hello %s from the BBB LKM!\n", name);
   return 0;
}

/** @brief The LKM cleanup function
*  Similar to the initialization function, it is static. The __exit macro notifies that if this
*  code is used for a built-in driver (not a LKM) that this function is not required.
*/
static void __exit helloBBB_exit(void){
   printk(KERN_INFO "EBB: Goodbye %s from the BBB LKM!\n", name);
}

/** @brief A module must use the module_init() module_exit() macros from linux/init.h, which
*  identify the initialization function at insertion time and the cleanup function (as
*  listed above)
*/
module_init(helloBBB_init);
module_exit(helloBBB_exit);

**********
And this makefile:

datawatt at O-LINUX-1:~/workspace-lkm/hello$ cat Makefile
obj-m+=hello.o

#KDIR := /lib/modules/$(shell uname -r)/build/

KDIR := $(SDKTARGETSYSROOT)/usr/src/kernel/

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


***********
Next I start the build process, by executing make and I get an error which I can't fix:


datawatt at O-LINUX-1:~/workspace-lkm/hello$ make
make -C /home/datawatt/toolchain/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/usr/src/kernel/ M=/home/datawatt/workspace-lkm/hello modules
make[1]: Entering directory '/home/datawatt/toolchain/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/usr/src/kernel'
  CC [M]  /home/datawatt/workspace-lkm/hello/hello.o
/bin/sh: scripts/basic/fixdep: No such file or directory
scripts/Makefile.build:264: recipe for target '/home/datawatt/workspace-lkm/hello/hello.o' failed
make[2]: *** [/home/datawatt/workspace-lkm/hello/hello.o] Error 1
Makefile:1387: recipe for target '_module_/home/datawatt/workspace-lkm/hello' failed
make[1]: *** [_module_/home/datawatt/workspace-lkm/hello] Error 2
make[1]: Leaving directory '/home/datawatt/toolchain/sysroots/armv7at2hf-neon-angstrom-linux-gnueabi/usr/src/kernel'
Makefile:8: recipe for target 'all' failed
make: *** [all] Error 2

Any help is appreciated.

Alberto Spin










-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.yoctoproject.org/pipermail/yocto/attachments/20170907/c9d978fa/attachment.html>


More information about the yocto mailing list