http://hi.baidu.com/kkernel/blog/item/1df359ccf49b431c01e9281a.html
http://my.oschina.net/zengsai/blog/2460
本文转载
2010-05-21 16:50
Author: Guo Wenxue
Data: 2010.05.21 file命令的移植: 1,从下面ftp站点下载最新的Linux file命令源代码file-5.04.tar.gz: ftp://ftp.astron.com/pub/file 2,解压缩并编写configure脚本如下,并执行该脚本: [guowenxue@localhost file-5.04]$ cat build.sh #!/bin/sh CROSS=/opt/buildroot_350/build_arm/staging_dir/bin/arm-linux- ./configure --host=arm-linux --enable-static --disable-shared CC=${CROSS}gcc AS=${CROSS}as LD=${CROSS}ld AR=${CROSS}ar RANLIB=${CROSS}ranlib 3,修改file-5.04/src/Makefile文件,添加--static到CFLAGS里,使用静态链接: CFLAGS = -g -O2 --static 4,修改源代码file-5.04/src/file.c中的main()函数,将 const char *magicfile 设置为 "/usr/share/magic.mgc"或其它路径; 5,执行make,编译生成file-5.04/src/file二进制文件; [guowenxue@localhost file-5.04]$ file src/file src/file: ELF 32-bit LSB executable, ARM, version 1 (ARM), statically linked, not stripped 6,将编译生成的file二进制文件和file-5.04/magic/Magdir/放到下载到ARM开发板(/tmp目录下),使用file命令生成magic.mgc文件: /tmp >: ./file -C -m Magdir /tmp >: ls Magdir.mgc Magdir.mgc 在使用file -C -m Magdir生成magic file之前,我们可以到Magdir里删除一些不用的类型,这样能减小magic.mgc文件的大小。 7,将Magdir.mgc拷贝为/usr/share/magic.mgc; 8,现在可以在ARM上使用file命令了. /tmp >: ./file -m Magdir.mgc file file: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped /tmp >: mv Magdir.mgc /usr/share/magic.mgc /tmp >: ./file file file: ELF 32-bit LSB executable, ARM, version 1, statically linked, not stripped /tmp >: ./file /usr/sbin/nup /usr/sbin/nup: POSIX shell script text executable 如果没有magic.mgc或file命令找不到该文件的话,会报错: /tmp >: file file: could not find any magic files! Reference: http://blog.chinaunix.net/u1/38994/showart_2034559.html lsz/lrz 是linux下x/y/zmodem传输文件协议的实现: http://www.ohse.de/uwe/software/lrzsz.html [guowenxue@localhost lrzsz-0.12.20]$ cat build.sh #!/bin/sh CROSS=/opt/buildroot_350/build_arm/staging_dir/bin/arm-linux- export CC=${CROSS}gcc export AR=${CROSS}ar export LD=${CROSS}ld export AS=${CROSS}as export RANLIB=${CROSS}ranlib ./configure --host=arm-linux [guowenxue@localhost lrzsz-0.12.20]$ sh build.sh && make Traffic Control with Linux Command Line tool, "tc"命令的移植 tc是iproute2中的一个子集: http://devresources.linuxfoundation.org/dev/iproute2/download/ 解压缩iproute2-2.6.34.tar.bz2后修改顶层Makefile: #options for ipx ADDLIB+=ipx_ntop.o ipx_pton.o CROSS=/opt/buildroot_350/build_arm/staging_dir/bin/arm-linux- CC = ${CROSS}gcc AR=${CROSS}ar LD=${CROSS}ld AS=${CROSS}as RANLIB=${CROSS}ranlib HOSTCC = gcc CCOPTS = -D_GNU_SOURCE -O2 -Wstrict-prototypes -Wall CFLAGS = $(CCOPTS) -I../include $(DEFINES) YACCFLAGS = -d -t -v 修改 SUBDIRS=lib tc ip misc netem genl 为 SUBDIRS=lib tc 执行make即得到tc [guowenxue@localhost iproute2-2.6.34]$ file tc/tc tc/tc: ELF 32-bit LSB executable, ARM, version 1 (ARM), dynamically linked (uses shared libs), not stripped |