Ubuntu-12.04 驱动开发环境配置
2013-07-12 01:10
375 查看
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
---亲自试验到现在,编译没错,我用的是ubuntu-12.04.2LTS
8. #make module_install //这个命令没有,要先make modules ,然后再make mudules_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
---亲自试验到现在,编译没错,我用的是ubuntu-12.04.2LTS
8. #make module_install //这个命令没有,要先make modules ,然后再make mudules_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(x64) 配置Anroid开发环境相关问题
- Ubuntu 12.04 配置c++开发环境
- Ubuntu 12.04 配置intel c++ compiler开发环境
- Ubuntu 12.04,配置Ruby on Rails开发环境
- Ubuntu 12.04下安装配置Python 2.7集成开发环境Eric4
- Ubuntu 14.04上驱动开发环境配置,及最简单一个驱动编写。
- Ubuntu 10.10 驱动开发环境IDE 配置 ---基于kate
- 环境: ubuntu 12.04 上面Android ndk 开发环境一键配置(cdt, adt, ndk 及Ogre工程移植)
- Ubuntu 12.04下安装配置Python 2.7集成开发环境Eric4
- Ubuntu 12.04 上配置ios开发环境搭建
- ubuntu下配置驱动开发环境
- VirtualBox下安装已经配置好Linux驱动开发环境的Ubuntu系统的方法
- linux 下 VNC Server安装配置及 eclipse CDT C/C++ 开发环境搭建(我用的是阿里云服务器 ubuntu 12.04 64-bit,无图形化界面)
- Ubuntu 12.04下安装配置Python 2.7集成开发环境Eric4
- 环境: ubuntu 12.04 上面Android ndk 开发环境一键配置(cdt, adt, ndk 及Ogre工程移植)
- 【转载】Ubuntu 14.04上驱动开发环境配置,及最简单一个驱动编写。
- 转载:Ubuntu 12.04下安装配置Python 2.7集成开发环境Eric4
- ubuntu 12.04 配置 Eclipse的 C/C++开发环境
- ubuntu系统中搭建Android应用层、framework层、驱动层开发环境