0. 无题
如图片所示,我们需要修改三个文件。
1. kernel/msm-3.18/drivers/Makefile
在此文件的最后加一句话:
+obj-y += helloworld/
2. 添加helloword相关的代码
在以下路径LA.UM.5.6\kernel\msm-3.18\drivers添加文件夹helloworld,
这个就对应刚才加的Makefile的修改。
然后在helloworld里面新增加两个文件,一个是helloworld.c,一个是Makefile;
Helloworld.c里面的代码如下:
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
static int hello_init(void)
{
printk("Hello! PHP is the best programming language in the world!\n");
return 0;
}
static void hello_exit(void)
{
printk("Goodbye! I will miss you\n");
return;
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
Makefile里面的文件内容如下(就加一句话):
obj-m := helloworld.o
3. 编译
OK,接下来我们遵循编译系统的方法,开始编译:
source build/envsetup.sh,然后选择lunch项,编译boot.img即可。
然后把out目录下面的ko文件拷贝到桌面上:
LA.UM.5.6\out\target\product\msm8953_64\system\lib\modules\helloworld.ko
4. 找个设备导入ko
adb push C:\Users\Administrator\Desktop\helloworld.ko /system/lib/modules/
C:\Users\Administrator>adb shell
msm8953_64:/ # cd /system/lib/modules/
cd /system/lib/modules/
msm8953_64:/system/lib/modules #
4.1加载ko文件
insmod helloworld.ko
dmesg | grep Hello
终端会显示 log : Hello! PHP is the best programming language in the world!
4.2 卸载ko文件
rmmod helloworld.ko
dmesg | grep Good
终端会显示 log : Goodbye! I will miss you