无法为 BeagleBone Debian 编译内核模块

Can't compile kernel module for BeagleBone Debian

我正在按照 Derek Molloys guide 构建可加载内核模块,但在某些时候会遇到问题。

我在 .c-file 中有内核代码: hello.c

#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);

makefile 如下: 生成文件

obj-m+=hello.o

all:
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean

当我尝试 运行 make 在只有上述两个文件的目录中时,我得到

Make: Nothing to be done for all

我正在 运行ning 3.8.13-bone47,但我无法找到与此 header 匹配的确切 header 文件=15=] Derek 推荐的,所以我下载了 3.8.13-bone71。这可能是问题所在吗?当我直接在 BeagleBone 上编译时,是否必须下载 headers?我还尝试将 Makefile 中的行更改为与我的 (3.8.13-bone47) 匹配的硬编码分发名称,但也不起作用。

非常感谢你们!

我解决了我的问题。我有两个问题:

Makefile 中缺少制表符 我用 make 语句在每一行的开头添加了一个制表符。它必须是一个真正的标签,<\t> 对我不起作用。

错误的头文件 事实证明,头文件的正确版本非常重要 :) 我从 http://rcn-ee.net/deb/trusty-armhf/v3.8.13-bone47/ 获得了头文件并添加了 mach/timex.h 文件,并且从那时起就能够遵循 Derek 的指南。