ubuntu 12.04驱动开发环境配置
来源:互联网 发布:免费采购软件 编辑:程序博客网 时间:2024/05/22 12:28
1.在终端运行#uname-r查看现有的内核的版本,本人ubuntu 12.04的是3.2.0.30-generic
2. 用下面指令查看可用的源码包:#sudo apt-cache search linux-source
得到的结果是
linux-source - Linux kernel source with Ubuntu patches
linux-source-3.2.0 - Linux kernelsource for version 3.2.0 with Ubuntu patches
3. 在Ubuntu中可以通过下面这个命令下载:
#apt-get install linux-source-(版本号)
#sudo apt-get install linux-source-3.2.0
4.下载后的文件linux-source-3.2.0.tar.bz2在/usr/src目录中,解压:
#cd /usr/src/
#tar jxvf linux-source-3.2.0.tar.bz2
解压后在/usr/src目录下产生了一个linux-source-3.2.0源码目录
5. #cd linux-source-3.2.0
#make config或#makemenuconfig或者# cp ../linux-headers-3.2.0.30-generic/.config ./.config
6.sudo make oldconfig
7. make
如果有下列错:
ERROR: "__modver_version_show" [drivers/staging/rts5139/rts5139.ko] undefined!
WARNING: modpost: Found 11 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
make[1]: *** [__modpost] 错误 1
make: *** [modules] 错误 2
修改.config文件: changing CONFIG_RTS5139=n
make
8. #make module_install
执行结束之后,会在/lib/modules下生成新的目录/lib/modules/3.2.40
9.#make install
10. 使用新编译的内核
Ubuntu采用Grub引导,要使用新内核,必须配置grub。
1) 更改grub配置,显示启动菜单
#gedit/etc/default/grub
注释GRUB_HIDDEN_TIMEOUT=0语句,及改成#GRUB_HIDDEN_TIMEOUT=0后保存
2)更新启动配置文件
#update-grub
11.修改/boot/grub/grub.cfg文件,修改你喜欢的内核版本顺序
#reboot
12.使用#uname -r查看内核版本是否已修改。
编写简单的hello world测试
1.hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hi,girl do you remember me!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT"I miss you so much\n");
}
module_init(hello_init);
module_exit(hello_exit);
2.Makefile
obj-m := hello.o
KERNELDIR := /lib/modules/3.2.40/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
3.进入hello.c所在目录make,生成hello.ko文件
4.sudo insmod hello.ko
如果成功,则运行#dmesg | tail
应有:Hi,girl do you remember me!的log!
2. 用下面指令查看可用的源码包:#sudo apt-cache search linux-source
得到的结果是
linux-source - Linux kernel source with Ubuntu patches
linux-source-3.2.0 - Linux kernelsource for version 3.2.0 with Ubuntu patches
3. 在Ubuntu中可以通过下面这个命令下载:
#apt-get install linux-source-(版本号)
#sudo apt-get install linux-source-3.2.0
4.下载后的文件linux-source-3.2.0.tar.bz2在/usr/src目录中,解压:
#cd /usr/src/
#tar jxvf linux-source-3.2.0.tar.bz2
解压后在/usr/src目录下产生了一个linux-source-3.2.0源码目录
5. #cd linux-source-3.2.0
#make config或#makemenuconfig或者# cp ../linux-headers-3.2.0.30-generic/.config ./.config
6.sudo make oldconfig
7. make
如果有下列错:
ERROR: "__modver_version_show" [drivers/staging/rts5139/rts5139.ko] undefined!
WARNING: modpost: Found 11 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
make[1]: *** [__modpost] 错误 1
make: *** [modules] 错误 2
修改.config文件: changing CONFIG_RTS5139=n
make
8. #make module_install
执行结束之后,会在/lib/modules下生成新的目录/lib/modules/3.2.40
9.#make install
10. 使用新编译的内核
Ubuntu采用Grub引导,要使用新内核,必须配置grub。
1) 更改grub配置,显示启动菜单
#gedit/etc/default/grub
注释GRUB_HIDDEN_TIMEOUT=0语句,及改成#GRUB_HIDDEN_TIMEOUT=0后保存
2)更新启动配置文件
#update-grub
11.修改/boot/grub/grub.cfg文件,修改你喜欢的内核版本顺序
#reboot
12.使用#uname -r查看内核版本是否已修改。
编写简单的hello world测试
1.hello.c
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hi,girl do you remember me!\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT"I miss you so much\n");
}
module_init(hello_init);
module_exit(hello_exit);
2.Makefile
obj-m := hello.o
KERNELDIR := /lib/modules/3.2.40/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
3.进入hello.c所在目录make,生成hello.ko文件
4.sudo insmod hello.ko
如果成功,则运行#dmesg | tail
应有:Hi,girl do you remember me!的log!
- Ubuntu-12.04 驱动开发环境配置
- ubuntu 12.04驱动开发环境配置
- ubuntu驱动开发环境配置
- ubuntu驱动开发环境
- 驱动开发环境配置
- Ubuntu 10.10 驱动开发环境IDE 配置 ---基于kate
- ubuntu 下 驱动开发环境
- ubuntu 下 驱动开发环境
- ubuntu 下 驱动开发环境
- ubuntu 下 驱动开发环境
- ubuntu 下 驱动开发环境
- Ubuntu 开发环境配置
- ubuntu开发环境配置
- 配置Ubuntu开发环境
- ubuntu开发环境配置
- Ubuntu开发环境配置
- ubuntu 开发环境配置
- Ubuntu配置开发环境
- Visual Studio 2013 使用笔记
- extends ,implements
- apache drill网址
- oracle导入大数据时日志问题
- 中国联通SP业务接入开发总结SGIP1.2 协议
- ubuntu 12.04驱动开发环境配置
- poj 2418
- linux TOMCAT Error
- POJ 1018 Communication System
- apache drill学习资料网络地址
- Objective-C特点及特征
- css控制表格细边框
- 【PAT Advanced Level】1007. Maximum Subsequence Sum (25)
- vs2010断点调试技巧