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. Github 的其他用法

    一.概述 Github 除了作为代码托管库外,有趣的程序员们还利用它解锁了有趣的新姿势. 二.新姿势 2.1 Github Pages 可以为项目建立静态主页(即gh-pages分支), 也可以建立命 ...

  2. MiniGUI 显示中文

    修改/usr/local/etc/MiniGUI.cfg # The first system font must be a logical font using RBF device font.[s ...

  3. Json日期格式 转化为 YYYY-MM-DD-hh-mm-ss

    function timeStamp2String(time) { var datetime = new Date(); datetime.setTime(time); var year = date ...

  4. Zabiix 监控图形乱码问题

    Zabiix切换为中文 配置中文乱码问题 在C:\Windows\Fonts中复制想要的字体,后缀为ttf,若本身问大写,请改成小写的文件后缀ttf,并上传至zabbix服务器的/usr/local/ ...

  5. Apache 虚拟主机配置

    开放虚拟主机文件 修改主配置文件 解开注释,使用虚拟主机配置文件. vim /usr/local/apache2/conf/httpd.conf Include conf/extra/httpd-vh ...

  6. 使用John the ripper工具来尝试破解Linux密码

    这篇文章主要介绍了使用John the ripper工具来尝试破解Linux密码的方法,这款工具可能主要被用来破解系统用户的密码以获得文件操作权限,需要的朋友可以参考下 John有别于Hdra之类的工 ...

  7. Jquery 动态生成的元素绑定事件

    使用 on方法 $("#id1").on("click","#id2",function(){}) 这里要注意的是#id1必须是原来就存在的 ...

  8. caffe python lmdb读写

    caffe中可以采取lmdb健值数据库的方式向网络中输入数据. 所以操作lmdb就围绕"键-值"的方式访问数据库就好了. Write 我们可以采用cv2来读入自己的图像数据,采用d ...

  9. Scala的两种变量

    Scala有两种变量,val和var.val类似于Java的final变量,一旦初始化了,就不能再赋值了.var如同Java中的非final变量,可以在生命周期内被多次赋值.

  10. contos LAMP环境搭建

    LINUX搭建LAMP笔记 .YUM:Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器.基于R ...