sipn_lockとmutex_lockのデッドロックを確認するための簡単なデモを作成する予定でした。
その結果、コードが書かれ、それをkoにコンパイルする方法を忘れました...
後で情報を見つけることができるように、手動で書き留めておくことをお勧めします。
(ブログの多くは実際には他の人のメインコンテンツです。次にそれを使用するのを防ぐために、もう一度やり直してから、すべての試行錯誤を記録しました)
ナンセンスではありません、ただそれに従ってください:
.cコードを書く
//以下はドライバーのソースコードです
#include <linux/init.h>
#include <linux/module.h>
static int hello_init(void)
{
printk("Hello, World !\n");
return 0;
}
static void hello_exit(void)
{
printk("Goodbye, World !\n");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("Dual BSD/GPL");
Makefileを書く
//以下はMakefileコードです
#!/bin/bash
#通知编译器我们要编译模块的哪些源码
#这里是编译 hello.c这个文件编译成中间文件 hello.o
obj-m := hello.o
#声明当前的架构,这里用户需要根据实际情况选择架构类型
export ARCH=arm
#声明交叉编译工具链,这里用户需要根据实际情况选择对应的工具链
export CROSS_COMPILE=arm-himix200-linux-
#源码目录变量,这里用户需要根据实际情况选择路径
#下面作者是将Linux的源码目录
KERDIR := /home1/zhugeyifan/source/K5/3519av100/packages/linux_lsp/kernel/linux-4.9.37/
#当前目录变量
CURDIR := $(shell pwd)
#make命名默认寻找第一个目标
#make -C就是指调用执行的路径
#$(KERDIR)Linux源码目录,作者这里指的是.../linux-4.9.37/
#$(CURDIR)当前目录变量
#modules要执行的操作
#注意!假如复制到Makefile后,下行提示红色,把 all:下面一行的make前面的空格删除后添加(Tab)制表符
all:
make -C $(KERDIR) M=$(CURDIR) modules
#make clean执行的操作是删除后缀为o的文件
#注意!假如复制到Makefile后,下行提示红色,把 clean:下面一行的make前面的空格删除后添加(Tab)制表符
clean:
make -C $(KERDIR) M=$(CURDIR) clean
コンパイル
makeを直接実行して、koモジュールをコンパイルおよび生成します
。作成者で次のエラーが発生しました。
make -C /home1/zhugeyifan/source/K5/3519av100/packages/linux_lsp/kernel/linux-4.9.37/ M=/home1/zhugeyifan/source/K5/3519av100/packages/linux_lsp/kernel/test_ko/hello modules
make[1]: Entering directory `/home1/zhugeyifan/source/K5/3519av100/packages/linux_lsp/kernel/linux-4.9.37'
ERROR: Kernel configuration is invalid.
include/generated/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.
WARNING: Symbol version dump ./Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /home1/zhugeyifan/source/K5/3519av100/packages/linux_lsp/kernel/test_ko/hello/hello.o
In file included from <command-line>:0:0:
././include/linux/kconfig.h:4:32: fatal error: generated/autoconf.h: No such file or directory
#include <generated/autoconf.h>
^
compilation terminated.
make[2]: *** [/home1/zhugeyifan/source/K5/3519av100/packages/linux_lsp/kernel/test_ko/hello/hello.o] Error 1
make[1]: *** [_module_/home1/zhugeyifan/source/K5/3519av100/packages/linux_lsp/kernel/test_ko/hello] Error 2
make[1]: Leaving directory `/home1/zhugeyifan/source/K5/3519av100/packages/linux_lsp/kernel/linux-4.9.37'
make: *** [all] Error 2
その理由は、カーネルがコンパイルされていないためです。最初にカーネルのコンパイルを処理します
生成
コンパイルが成功すると、生成されるファイルは次のようになります。
zhugeyifan@DriverTeam:~/hello/ls
hello.c hello.ko hello.mod.c hello.mod.o hello.o Makefile modules.order Module.symvers