繁体   English   中英

无法为BeagleBone Debian编译内核模块

[英]Can't compile kernel module for BeagleBone Debian

我正在遵循Derek Molloys的指南来构建可加载的内核模块,但是在某些时候会遇到困难。

我在.c文件中有内核代码: 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: 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:什么都做不了

我正在运行3.8.13-bone47 ,但无法在Derek建议的此链接上找到与之完全匹配的头文件,因此我改为下载3.8.13-bone71 这可能是问题吗? 直接在BeagleBone上编译时,是否必须下载标头? 我也尝试过将Makefile中的行更改为与我的(3.8.13-bone47)匹配的硬编码发行版名称,也不起作用。

非常感谢你们!

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

Makefile中缺少选项卡我用make语句在每行的开头添加了一个选项卡。 它必须是一个实际的选项卡,<\\ t>不适用于我。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM