HelloWorld 模块
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 模块的更多相关文章
- 一步一步实现Linux设备驱动的Helloworld模块
学了那么多程序语言,总是有一个Hello world开头,不禁感叹Hello world的强大.呵呵,废话少说,咋们的故事当然要从这个Hello world开始. 先查看自己OS使用的内核版本[don ...
- Helloworld模块之内核makefile详解
Hello World 模块以及对应的内核makefile详解 hello.c: #include <linux/module.h> //所有模块都需要的头文件 #include < ...
- 利用Makefile安装helloworld模块(速成)
这学期对了一门操作系统,满怀着好奇装了虚拟机然后安了Ubuntu,这周作业是编译内核和安装个模块,妈耶,折腾了我一两天.终于弄完,CSDN上有挺多类似的教程,例如陈皓的跟我一起写Makefile,写的 ...
- helloworld模块
环境: HelperA64开发板 Linux3.10内核 时间:2019.01.11 目标:编译helloword模块 1.当出先下面错误时候,查找问题 问题为Make的时候默认为PC-X86 ...
- openWRT自学---如何开发新的用户态模块-helloworld
以http://www.gargoyle-router.com/wiki/doku.php?id=openwrt_coding为参考文档 1.要获得openWRT的sdk环境.只要在Backfire的 ...
- Nginx模块开发(1)————类helloworld
Nginx看了一点了,准备写个helloworld试试,觉得只看书的话很多东西都乱乱的,晕晕的,印象不深. 我的helloworld模块的目的就是:能够在浏览器里输入http://你的ip地址/lcw ...
- 基于ASP.NET MVC的热插拔模块式开发框架(OrchardNoCMS)--瘦身计划
Orchard CMS是针对CMS开发的,对于很多开发需求来说,内容管理这块儿可能并不需要,而需要它的模块式开发模式.所以我这里通过对OrchardCMS进行瘦身,去除 内容管理部分的内容,保留简单的 ...
- Orchard helloworld
原文链接:http://www.orchardproject.net/docs/Building-a-hello-world-module.ashx 命令行语法:http://www.cnblogs. ...
- linux驱动开发之HelloWorld
最近实习,公司项目搞的是平板开发,而我分配的任务是将驱动加载到内核中. 准备工作,必要知识了解:加载有两种方式,一种是动态加载和卸载即模块加载,另一种是直接编译进入内核:Linux内核把驱动程序划分为 ...
随机推荐
- 开发者需要知道的iOS 12
总体概况 iOS 12总体来看是对现有iOS的一次改进,并没有太多突破性的功能或者框架,但是Apple在底层做了很多优化的工作,优化了性能,提供了更强大的安全性,增强了AR.Siri体验,让人工智能更 ...
- spring boot Rabbitmq集成,延时消息队列实现
本篇主要记录Spring boot 集成Rabbitmq,分为两部分, 第一部分为创建普通消息队列, 第二部分为延时消息队列实现: spring boot提供对mq消息队列支持amqp相关包,引入即可 ...
- sublime Text emmet插件使用手册
转自:http://www.w3cplus.com/tools/emmet-cheat-sheet.html 介绍 Emmet (前身为 Zen Coding) 是一个能大幅度提高前端开发效率的一个工 ...
- Spring 之定义切面尝试(基于 XML)
有些场景下只能基于 XML 来定义切面. [Spring 之定义切面尝试] 1.XML 下定义切面(首先是要有一个对应的类...显然要比基于注解的麻烦) <?xml version=" ...
- Nginx进阶-不停服更新
前言 7*24小时不间断的提供对外服务和产品快速迭代是互联网行业的特征,基于需求所有的发布都不能停止当前对外的服务.本文围绕此话题衍生出,不停服上下线工具实现. 看本文前请先看 Nginx初识 Ten ...
- jQuery全屏图片焦点图
在线演示 本地下载
- java常见异常(更新中)
Java的异常分为两种,一种是运行时异常(RuntimeException),一种是非运行异常也叫检查式异常(CheckedException) .NullPointerException 空指针异常 ...
- redhat 6.8 配置yum源
一般安装好redhat后,不能注册的话,不能使用系统自带的yum源.但是我们可以自己配置yum源来解决这一问题.下面介绍下redhat配置163yum源. 1. 检查是否安装yum包 rpm -qa ...
- git原理学习
http://git.oschina.net/progit/ 这一点值得牢记:Git 会把工作目录的内容恢复为检出某分支时它所指向的那个提交对象的快照.它会自动添加.删除和修改文件以确保目录的内容 ...
- Bellman-Ford算法优化
2017-07-27 16:02:48 writer:pprp 在BEllman-Ford算法中,其最外层的循环的迭代次数为n-1,如果不存在负权回路,需要迭代的次数是远远小于n-1; 如果在某一次迭 ...