[Linux Device Driver] Hello World under Linux OS

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值