linux驱动摸索 --arm平台上添加操作磁盘相关命令

来源:互联网 发布:数据库系统原理 pdf 编辑:程序博客网 时间:2024/05/21 09:30
基本开发环境

Linux平台:虚拟机下ubuntu 14.04

交叉编译工具:gcc-4.4.3

arm开发板:mini2440

arm 内核版本:linux-2.6.32.2

开发板采用nfs挂接网络根文件系统,假设我的路径是:/work/tony_fs


跟着韦东山的二期视频,学习linux驱动,一路走来也有好些时候了。没想到在块设备这一节中卡了壳,主要是视频中介绍的mkdosfs,fdisk等命令在我的开发板上的文件系统中并没有集成,于是我只能从网上找源码,编译安装,网上对于这方面的介绍并不是很多,前前后后,折腾了有一天多,终于是有点起色了。

下面分几部分,分别介绍各命令的添加方式:

一.   增加mkdosfs 格式化磁盘命令

1.从http://daniel-baumann.ch/software/dosfstools/ 下载源码

    我下载的版本是dosfstools-3.0.0.tar.gz(下载最新版本dosfstools-3.0.26.tar.gz,用arm-linux-编译时,会出错,显示undefined reference to `htole32' 我在源文件中确实没找到相关的参数定义,无奈选了个老版本)

#tar zxvf dosfstools-3.0.0.tar.gz  #cd dosfstools-3.0.0  #make CC=arm-linux-gcc 

之后在当前目录下会生成mkdosfs将该可执行文件拷贝到我们的开发板的文件系统/usr/sbin/ 目录下即可

#cp mkdosfs /work/tony_fs/usr/sbin

二 增加mke2fs 格式化磁盘命令

1.从http://sourceforge.net/projects/e2fsprogs/ 下载源码 

  选了一个不是最新的版本,e2fsprogs-1.42.6.tar.gz

#tar zxvf e2fsprogs-1.42.6.tar.gz #cd e2fsprogs-1.42.6#mkdir tmp#./configure CC=arm-linux-gcc --prefix=$(pwd)/tmp --host=arm-linux#make#make install#make install-libs    //为下一个parted磁盘分区命令生成相关的库

查看tmp目录,可看到:


在sbin目录下,生成了mke2fs可执行文件,将该可执行文件拷贝到我们的开发板的文件系统/usr/sbin/ 目录下即可

#cp mke2fs /work/tony_fs/usr/sbin

三.  磁盘分区命令 parted

该命令依赖于e2fsprogs生成的相关头文件和库,故先得编译e2fsprogs源码,之后在编译parted源码。

从http://ftp.gnu.org/gnu/parted/下载源码,这次选了parted-3.0.tar.gz

#tar zxvf parted-3.0.tar.gz#cd parted-3.0#mkdir arch#./configure CFLAGS=-I/work/e2fsprogs-1.42.6/tmp/include/ LDFLAGS=-L/work/e2fsprogs-1.42.6/tmp/lib CC=arm-linux-gcc --prefix=$(pwd)/arch --host=arm-linux --disable-device-mapper --without-readline#make#make install
查看arch目录:


在sbin目录下,生成了parted可执行文件,将该可执行文件拷贝到我们的开发板的文件系统/usr/sbin/ 目录下即可

#cp parted /work/tony_fs/usr/sbin

三 .增加磁盘分区fdisk命令

      从http://ftp.gnu.org/gnu/fdisk/下载源码。

      之前configure配置时,一直出现该种类型错误,网上找了N久也没找到合适的解决方法。

checking parted/parted.h usability... nochecking parted/parted.h presence... nochecking for parted/parted.h... nochecking for special C compiler options needed for large files... nochecking for _FILE_OFFSET_BITS value needed for large files... 64checking for parted/parted.h... (cached) noconfigure: error: <parted/parted.h> not found; install GNU/Parted
     从第三个例子,猜想会不会依赖与parted生成的相关库的,决定尝试一下,  选择fdisk-1.3.0a.tar.gz 源码包

#tar zxvf fdisk-1.3.0a.tar.gz #cd fdisk-1.3.0a#mkdir tmp#./configure CFLAGS=-I/work/parted-3.0/arch/include/ LDFLAGS=-L/work/parted-3.0/arch/lib CC=arm-linux-gcc --prefix=$(pwd)/tmp --host=arm-linux #make#make install
此时进入tmp目录,果真生成了可执行文件fdisk


#cp fdisk /work/tony_fs/usr/sbin

四个指令整整花了一天的时间,才搞定,中间的过程确实很坎坷,每个源码的版本都试了N次。才选了合适的

比如之前选fdisk-1.2.4.tar.gz时,./configure可以,在make是出现:

arm-linux-gcc -DLOCALEDIR=\"/work/fdisk-1.2.4/tmp/share/locale\" -DHAVE_CONFIG_H -I. -I..  -I../lib -I../lib   -I/work/parted-3.0/arch/include/ -D_FILE_OFFSET_BITS=64 -MT fdisk.o -MD -MP -MF .deps/fdisk.Tpo -c -o fdisk.o fdisk.cfdisk.c: In function 'do_mkpart':fdisk.c:725: error: 'const struct _PedFileSystemOps' has no member named 'create'fdisk.c: In function 'do_resize':fdisk.c:1564: error: 'const struct _PedFileSystemOps' has no member named 'resize'fdisk.c:1571: warning: initialization makes pointer from integer without a castfdisk.c:1572: warning: assignment makes pointer from integer without a castfdisk.c: In function '_init_messages':fdisk.c:2080: error: 'const struct _PedFileSystemOps' has no member named 'create'fdisk.c:2117: error: 'const struct _PedFileSystemOps' has no member named 'resize'make[2]: *** [fdisk.o] Error 1make[2]: Leaving directory `/work/fdisk-1.2.4/src'make[1]: *** [all-recursive] Error 1make[1]: Leaving directory `/work/fdisk-1.2.4'make: *** [all] Error 2

查看源码后,猜测在parted定义的结构体和该版本的结构体不匹配,可能是fdisk的版本比较老,于是换了个fdisk-1.3.0a.tar.gz ,编译,错误消失了

在开发板上试验时,fdisk dev/ramdisk   出现:

[root@FriendlyARM /]# fdisk /dev/ramdisk fdisk: error while loading shared libraries: libparted.so.1: cannot open shared object file: No such file or directory
将第三部分在parted-3.0/arch生成的lib库,找到相关链接库,直接拷贝到/usr/lib目录即可。

cp /work/parted-3.0/arch/lib/libparted.so.1 /work/tony_fs/usr/lib/


类似的问题还有很多很多,纠结了一天,终于都搞定了。哈哈,能安心睡觉了





0 0