博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux 2.6 驱动笔记(一)
阅读量:4544 次
发布时间:2019-06-08

本文共 1398 字,大约阅读时间需要 4 分钟。

本文作为linux 2.6 驱动笔记,记录环境搭建及linux基本内核模块编译加载。

环境搭建:

硬件:OK6410开发板

目标板操作系统:linux 2.6

交叉编译环境:windows 7 + vmware work station + redhat 9 + arm-gcc-linux

步骤:

编写简单内核模块,如下

#include
#include
static int hello_init(void){ printk("hello_init"); return 0;}static void hello_exit(void){ printk("hello_exit"); }module_init(hello_init); //加载时调用modeule_exit(hello_exit);//卸载时调用

编写makefile(网上现成的模板):

KERNELDIR = /home/linux-2.6.36/linux-2.6.36.2-v1.05 //交叉编译环境中的内核源码路径PWD := $(shell pwd)CC    = arm-linux-gccobj-m := driver01.o //与编译的.c文件同名modules:    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules //前面要有tagclean:    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions.PHONY: modules clean

编译产生driver01.ko,拷贝至目标板(采用SD卡),执行:insmod driver01.ko,控制台打印“hello_init”。执行lsmod后显示:

备注:

1. “ error: generated/bounds.h: No such file or directory” 编译错误,makefile中的kerneldir是内核源码的地址,在编译时用于头文件的引用。bounds.h是需要linux编译后生成,因此出现该问题需要make一下linux源码;

2. "module license 'unspecified' taints kernel" 告警,原因是内核模块源码中未增加“MODULE_LICENSE("GPL");”

3. arm-linux-gcc安装完后,在redhat linux中通过修改etc/profile增加环境变量,如下:

# Path manipulationif [ `id -u` = 0 ]; then    pathmunge /sbin    pathmunge /usr/sbin    pathmunge /usr/local/sbin    pathmunge /home/arm/usr/local/arm/4.3.2/bin fi

4. 在windows 7下通过ssh客户端连接vmware上的redhat时,IP用的是vmawre的虚拟网卡,而非xp时真实的网口ip。

转载于:https://www.cnblogs.com/Fredric-2013/p/3145005.html

你可能感兴趣的文章
使用 iTextSharp 生成 PDF 表格
查看>>
sql 查出一张表中重复的所有记录数据
查看>>
IIS 上传大文件 30MB 设置限制了上传大小
查看>>
vue2.0结合Element实现select动态控制input禁用
查看>>
【Codeforces Round #455 (Div. 2) A】Generate Login
查看>>
【Codeforces 476C】Dreamoon and Sums
查看>>
【codeforces 505C】Mr.Kitayuta,the Treasure Hunter
查看>>
混合应用 微信登录授权 微信登录认证失败 ios PGWXAPI错误-1 code:-100 / 安卓 message:invalid appsecret innerCode:40125...
查看>>
MSSQL按分页前去盘查了局的存储进程
查看>>
运用centosplus来更新你的CentOS
查看>>
wxDownload Fast 0.4.5
查看>>
<实训|第十天>从底层解释一下U盘内存为什么变小的原因附数据恢复的基本原理...
查看>>
测试Windows Live Writer插件
查看>>
常用正则封装,积少成多
查看>>
文件下载工具类
查看>>
Python 定义自己的常量类
查看>>
C++读取文本文件
查看>>
Python 字典排序
查看>>
sql中写标量函数生成大写拼音首字母
查看>>
ASP.NET Core 2.1 : 十五.图解路由(2.1 or earler)
查看>>