helloworld.c 代码

#include <linux/init.h>
#include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); static int hello_init(void)
{
printk(KERN_ALERT "Hello world\n");
return ;
} static void hello_exit(void)
{
printk(KERN_ALERT "goodbye,cruel world\n");
} module_init(hello_init);
module_exit(hello_exit);

Makefile 代码

 obj-m := helloworld.o

 CURRENT_DIR :=$(shell pwd)

 KERNEL_DIR := /usr/src/linux-headers-$(shell uname -r)

 all:
$(MAKE) -C $(KERNEL_DIR) M=$(CURRENT_DIR) modules clean:
rm -rf %.o

执行make

 ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ make
make -C /usr/src/linux-headers-3.13.--generic M=/data1/Ryan/demo/helloworld modules
make[]: Entering directory `/usr/src/linux-headers-3.13.--generic'
Building modules, stage .
MODPOST modules
make[]: Leaving directory `/usr/src/linux-headers-3.13.--generic'

加载模块

 ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ sudo insmod helloworld.ko
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$

dmesg查看

 ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ dmesg
 [178401.813566] sr :::: [sr0] Device not ready
[178401.813570] sr :::: [sr0]
[178401.813571] Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE
[178401.813572] sr :::: [sr0]
[178401.813573] Sense Key : Not Ready [current]
[178401.813575] sr :::: [sr0]
[178401.813577] Add. Sense: Medium not present - tray closed
[178401.813579] sr :::: [sr0] CDB:
[178401.813580] Read(): 2f
[178401.813584] end_request: I/O error, dev sr0, sector
[179614.794066] helloworld: module verification failed: signature and/or required key missing - tainting kernel
[179614.794552] Hello world
[180458.268623] goodbye,cruel world
[180514.941519] Hello world
[180549.136795] goodbye,cruel world
[181244.193514] Hello world

卸载模块

 ryan@Ryan-pc:/data1/Ryan/demo/helloworld$ sudo rmmod helloworld
ryan@Ryan-pc:/data1/Ryan/demo/helloworld$

HelloWorld 模块的更多相关文章

  1. 一步一步实现Linux设备驱动的Helloworld模块

    学了那么多程序语言,总是有一个Hello world开头,不禁感叹Hello world的强大.呵呵,废话少说,咋们的故事当然要从这个Hello world开始. 先查看自己OS使用的内核版本[don ...

  2. Helloworld模块之内核makefile详解

    Hello World 模块以及对应的内核makefile详解 hello.c: #include <linux/module.h> //所有模块都需要的头文件 #include < ...

  3. 利用Makefile安装helloworld模块(速成)

    这学期对了一门操作系统,满怀着好奇装了虚拟机然后安了Ubuntu,这周作业是编译内核和安装个模块,妈耶,折腾了我一两天.终于弄完,CSDN上有挺多类似的教程,例如陈皓的跟我一起写Makefile,写的 ...

  4. helloworld模块

    环境: HelperA64开发板 Linux3.10内核 时间:2019.01.11 目标:编译helloword模块 ​ 1.当出先下面错误时候,查找问题 ​ 问题为Make的时候默认为PC-X86 ...

  5. openWRT自学---如何开发新的用户态模块-helloworld

    以http://www.gargoyle-router.com/wiki/doku.php?id=openwrt_coding为参考文档 1.要获得openWRT的sdk环境.只要在Backfire的 ...

  6. Nginx模块开发(1)————类helloworld

    Nginx看了一点了,准备写个helloworld试试,觉得只看书的话很多东西都乱乱的,晕晕的,印象不深. 我的helloworld模块的目的就是:能够在浏览器里输入http://你的ip地址/lcw ...

  7. 基于ASP.NET MVC的热插拔模块式开发框架(OrchardNoCMS)--瘦身计划

    Orchard CMS是针对CMS开发的,对于很多开发需求来说,内容管理这块儿可能并不需要,而需要它的模块式开发模式.所以我这里通过对OrchardCMS进行瘦身,去除 内容管理部分的内容,保留简单的 ...

  8. Orchard helloworld

    原文链接:http://www.orchardproject.net/docs/Building-a-hello-world-module.ashx 命令行语法:http://www.cnblogs. ...

  9. linux驱动开发之HelloWorld

    最近实习,公司项目搞的是平板开发,而我分配的任务是将驱动加载到内核中. 准备工作,必要知识了解:加载有两种方式,一种是动态加载和卸载即模块加载,另一种是直接编译进入内核:Linux内核把驱动程序划分为 ...

随机推荐

  1. jQuery二级下拉菜单

    在线演示 本地下载

  2. NOIP Mayan游戏

    描述 Mayan puzzle是最近流行起来的一个游戏.游戏界面是一个7行5列的棋盘,上面堆放着一些方块,方块不能悬空堆放,即方块必须放在最下面一行,或者放在其他方块之上.游戏通关是指在规定的步数内消 ...

  3. fabric查看本地与远程主机信息

    #!/usr/bin/pythonfrom fabric.api import *env.user='root'env.hosts=['172.10.224.183','172.10.224.132' ...

  4. 数组排序array_multisort

    array_multisort --对多个数组或者多维数组进行排序[参考:secure.php.net] 说明: bool array_multisort ( array &$array1 [ ...

  5. 多线程-信号量Semaphore

    计数信号量用来控制同时访问某个特定资源的操作数量.Semaphore可以用于实现资源池,例如数据库连接池.我们可以构造一个固定长度的资源池,当资源池为空的时候,请求资源将会阻塞,而不是失败.当资源池非 ...

  6. Android中Fragment的Hide和Show

    我们都知道,Fragment动态添加的时候我们可以使用FragmentTransaction的add和replace方法,replace方法就等效于对这个Fragment先执行remove(),再执行 ...

  7. BZOJ 4726 [POI2017]Sabota?:树形dp

    传送门 题意 某个公司有 $ n $ 个人,上下级关系构成了一个有根树.其中有个人是叛徒(这个人不知道是谁).对于一个人, 如果他下属(直接或者间接, 不包括他自己)中叛徒占的比例超过 $ x $ , ...

  8. Entity Framework 6:专家版本

    随着 Entity Framework 最新主版本 EF6 的推出,Microsoft 对象关系映射 (ORM) 工具达到了新的专业高度,与久负盛名的 .NET ORM 工具相比已不再是门外汉. EF ...

  9. 智课雅思词汇---二十三、名词性后缀mony

    智课雅思词汇---二十三.名词性后缀mony 一.总结 一句话总结:Latin: action, result of an action or condition; a suffix that for ...

  10. ipmitool 查看硬件信息

    [root@75-6-25-yf-core ~]# cat /var/log/mcelog MCE 0HARDWARE ERROR. This is *NOT* a software problem! ...