打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
交叉编译fdisk
转自:http://blog.csdn.net/l_backkom/article/details/38072441


基本开发环境

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' 我在源文件中确实没找到相关的参数定义,无奈选了个老版本)

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

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

  1. #cp mkdosfs /work/tony_fs/usr/sbin  

二 增加mke2fs 格式化磁盘命令

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

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

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

查看tmp目录,可看到:


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

  1. #cp mke2fs /work/tony_fs/usr/sbin  

三.  磁盘分区命令 parted

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

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

  1. #tar zxvf parted-3.0.tar.gz  
  2. #cd parted-3.0  
  3. #mkdir arch  
  4. #./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  
  5. #make  
  6. #make install  
查看arch目录:


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

  1. #cp parted /work/tony_fs/usr/sbin  

三 .增加磁盘分区fdisk命令

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

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

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

  1. #tar zxvf fdisk-1.3.0a.tar.gz   
  2. #cd fdisk-1.3.0a  
  3. #mkdir tmp  
  4. #./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   
  5. #make  
  6. #make install  
此时进入tmp目录,果真生成了可执行文件fdisk


  1. #cp fdisk /work/tony_fs/usr/sbin  

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

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

  1. 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.c  
  2. fdisk.c: In function 'do_mkpart':  
  3. fdisk.c:725: error: 'const struct _PedFileSystemOps' has no member named 'create'  
  4. fdisk.c: In function 'do_resize':  
  5. fdisk.c:1564: error: 'const struct _PedFileSystemOps' has no member named 'resize'  
  6. fdisk.c:1571: warning: initialization makes pointer from integer without a cast  
  7. fdisk.c:1572: warning: assignment makes pointer from integer without a cast  
  8. fdisk.c: In function '_init_messages':  
  9. fdisk.c:2080: error: 'const struct _PedFileSystemOps' has no member named 'create'  
  10. fdisk.c:2117: error: 'const struct _PedFileSystemOps' has no member named 'resize'  
  11. make[2]: *** [fdisk.o] Error 1  
  12. make[2]: Leaving directory `/work/fdisk-1.2.4/src'  
  13. make[1]: *** [all-recursive] Error 1  
  14. make[1]: Leaving directory `/work/fdisk-1.2.4'  
  15. make: *** [all] Error 2  

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

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

  1. [root@FriendlyARM /]# fdisk /dev/ramdisk   
  2. 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目录即可。

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


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





本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
automake安装1.14.1版本
鲲鹏社区:华为方舟编译器编译工具正式发布,附源码下载
redis —— linux下源码安装
Linux源代码配置安装 samba 3.5.8
Nginx安装解决报错
ubifs的制作,移植的重点详解
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服