在Ubuntu1004下驱动开发环境搭建

上传人:大米 文档编号:432605285 上传时间:2023-06-20 格式:DOCX 页数:7 大小:19.16KB
返回 下载 相关 举报
在Ubuntu1004下驱动开发环境搭建_第1页
第1页 / 共7页
在Ubuntu1004下驱动开发环境搭建_第2页
第2页 / 共7页
在Ubuntu1004下驱动开发环境搭建_第3页
第3页 / 共7页
在Ubuntu1004下驱动开发环境搭建_第4页
第4页 / 共7页
在Ubuntu1004下驱动开发环境搭建_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《在Ubuntu1004下驱动开发环境搭建》由会员分享,可在线阅读,更多相关《在Ubuntu1004下驱动开发环境搭建(7页珍藏版)》请在金锄头文库上搜索。

1、在 Ubuntu10.04 驱动开发环境搭建一、准备开发工具开发工具主要有 gcc、gdb、make在 Ubuntu 中可以通过下面这个命令安装:$apt-get install build-essential我没有执行上面的命令,因为我在之前编译过Android,相关工具已经配置好了:$sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev libc6-dev x11proto-core-dev libx11-dev libgl1-mesa-dev g+-multilib

2、 mingw32 tofrodos libncurses5-dev二、下载 Linux 源代码linux 源码可以通过以下几种途径获得:1)直接去 www.kernel.org 下载2)通过包管理工具下载源码 用下面指令查看可用的源码包:$ sudo apt-cache search linux-sourcelinux-source - Linux kernel source with Ubuntu patches linux-source-2.6.32 - Linux kernel source for version 2.6.32 with Ubuntu patches在 Ubuntu 中

3、可以通过下面这个命令下载:$apt-get install linux-source-(版本号)$sudo apt-get install linux-source-2.6.32下载后的文件linux-source-2632.tar.bz2在/usr/src目录中,解压:$su 一 root$cd /usr/src$tar jxvf linux-source-2.6.32.tar.bz2解压后在/usr/src目录下产生了一个linux-source-2.6.32源码目录三、编译内核依次执行下列命令(必须都执行,否则编译错误,如果不是root用户,命令前加sudo):1)配置内核$su 一 r

4、oot$cd /usr/src/linux-source-2.6.32$make config或$make menuconfig或者$ sudo cp ./linux-headers-2.6.32-21-generic/.config./.config如果当前运行内核打开了 CONFIG_IKCONFIG_PROC 参数,则可以$zcat /proc/config.gz .config$make oldconfig2)编译内核2.6版本后前两步不需要,直接make即可$make prepare$make scripts$make3)安装模块$make modules这一步不需要$make mo

5、dule_install执行结束之后,会在/lib/modules下生成新的目录/lib/modules/2.6.32.44+drm33.19四、生成镜像文件1)生成内核镜像文件$make bzImage执行完成后将在arch/i386/boot/目录下生成bzImage镜像文件,使用下面命令安装到系 统的/boot目录下:$sudo make installsh/usr/src/linux-source-2.6.32/arch/x86/boot/install.sh2.6.32.44+drm33.19arch/x86/boot/bzImage System.map /boot命 令 完 成

6、后 在 /boot 目 录 下 , 将 多 了 vmlinuz-2.6.32.44+drm33.19 和 System.map-2.6.32.44+drm33.19 两个文件或者直接拷贝$ sudo cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.32.44+drm33.192)生成要载入ramdisk的映像文件如果linux系统按照在scsi磁盘上,这部是必须的,否则可以跳过。我的linux是装在 vmware上的,用的是虚拟的scsi磁盘,所以必须要这一步。输入命令:mkinitramfs -o /boot/initrd.img-linux2.6.3

7、2.44+drm33.19 2.6.32.44+drm33.19第二个参数是版本号,必须和/lib/modules/目录下新内核对应的模块的文件夹名字一致, 即 2.6.32.44+drm33.19 。五、使用新编译的内核Ubuntu 采用 Grub 引导,要使用新内核,必须配置 grub。1)更改 grub 配置,显示启动菜单$su -root$gedit /etc/default/grub &注释 GRUB_HIDDEN_TIMEOUT=0 语句,及改成#GRUB_HIDDEN_TIMEOUT=0 后保 存2)更新启动配置文件$update-grub执行命令后,该命令自动搜索/boot文件

8、夹,将相应的镜像加入/boot/grub/grub.cfg启动菜 单,并根据/etc/default/grub内容更新配置文件。更新后,将增加如下内容:menuentry Ubuntu, with Linux 2.6.32.44+drm33.19 -class ubuntu -class gnu-linux -class gnu -class os recordfailinsmod ext2set root=(hd0,5)search -no-floppy -fs-uuid -set 4aaa411a-c1ab-4c9e-94bf-770717be6d9alinux /vmlinuz-2.6.

9、32.44+drm33.19 root=/dev/sda8 ro quiet splash menuentry Ubuntu, with Linux 2.6.32.44+drm33.19 (recovery mode) -class ubuntu -class gnu-linux -class gnu -class os recordfailinsmod ext2set root=(hd0,5)search -no-floppy -fs-uuid -set 4aaa411a-c1ab-4c9e-94bf-770717be6d9aecho Loading Linux 2.6.32.44+drm3

10、3.19 .linux /vmlinuz-2.6.32.44+drm33.19 root=/dev/sda8 ro singleecho Loading initial ramdisk . 3) 手工更改配置文件因为是SCSI,须手工加入启动时需要的ramdisk的映像文件,initrd开头部分: menuentry Ubuntu, with Linux 2.6.32.44+drm33.19 -class ubuntu -class gnu-linux -class gnu -class os recordfailinsmod ext2set root=(hd0,5)search -no-fl

11、oppy -fs-uuid -set 4aaa411a-c1ab-4c9e-94bf-770717be6d9a linux /vmlinuz-2.6.32.44+drm33.19 root=/dev/sda8 ro quiet splash initrd /initrd.img-linux2.6.32.44+drm33.19menuentry Ubuntu, with Linux 2.6.32.44+drm33.19 (recovery mode) -class ubuntu -class gnu-linux -class gnu -class os recordfail insmod ext

12、2set root=(hd0,5)search -no-floppy -fs-uuid -set 4aaa411a-c1ab-4c9e-94bf-770717be6d9a echoLoading Linux 2.6.32.44+drm33.19 .linux /vmlinuz-2.6.32.44+drm33.19 root=/dev/sda8 ro singleechoLoading initial ramdisk .initrd /initrd.img-linux2.6.32.44+drm33.19 修改完成并保存后,重新启动系统,应该出现让你选择内核的菜单。六、准备 Helloworld

13、源代码和 Makefile 文件$mkdir hello$cd hello$gedit Helloworld.c Makefile &Helloworld.c 内容:#include #include MODULE_LICENSE(Dual BSD/GPL);static int hello_init(void) printk(KERN_ALERT Hello, worldn); return 0;static void hello_exit(void) printk(KERN_ALERT Goodbye, cruel worldn); module_init(hello_init); mod

14、ule_exit(hello_exit);Makefile 内容:#Makefile 2.6ifneq ($(KERNELRELEASE),)#kbuild syntax dependency relationship of files and target modules are listed here. mymodule-objs:=helloworld.o obj-m:=helloworld.oelsePWD:=$(shell pwd) #为正在运行的内核编译模块,使用下列配置KVER?=$(shell uname -r) #KDIR:=/lib/modules/$(KVER)/buil

15、d#或使用/usr/src/linux-headers-2.6.32-21-generic 目录#不是为正在运行的内核编译模块,使用下列配置#KDIR:=/usr/src/linux-2.6.32.21/ KDIR:=/usr/src/linux-source-2.6.32/all:$(MAKE) -C $(KDIR) M=$(PWD)clean:rm -rf .*.com *.o *.mod.c *.ko .tmp_versions modules.order Module.symvers endif七、编译并安装模块1)编译 编译前,请先编译新内核,否则出现警告信息$cd /hello$make2)安装模块$sudo insmod helloworld.ko3)移除模块$rmmod helloworld4)查看模块信息$sudo modinfo helloworld$lsmod 列

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号