root@debian-mipsel:/home/user/wansview/devel# readelf -h unzip1 ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement,little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: MIPS R3000 Version: 0x1 Entry point address: 0x401cc0 Start of program headers: 52 (bytes into file) Start of section headers: 169960 (bytes into file) Flags: 0x10001007,noreorder,pic,cpic,o32,mips2 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 6 Size of section headers: 40 (bytes) Number of section headers: 24 Section header string table index: 23 root@debian-mipsel:/home/user/wansview/devel# file unzip1 unzip1: ELF 32-bit LSB executable,MIPS,MIPS-II version 1 (SYSV),dynamically linked (uses shared libs),stripped
然后我下载了MIPSEL版本的Debian,我正在QEMU中运行它.当我运行上面检索的程序时,我得到:
root@debian-mipsel:/home/user/wansview/devel# ./unzip1 -bash: ./unzip1: No such file or directory
我理解的意思是说它不是正确的平台.固执地,我编译了一个你好世界,以比较ELF和文件信息.我的hello世界在Debian MIPSEL中运行良好,但也返回没有这样的文件或目录在嵌入式设备上.它是自己,文件输出是非常相似的:
root@debian-mipsel:/home/user/wansview/devel# readelf -h hello ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement,little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: MIPS R3000 Version: 0x1 Entry point address: 0x400740 Start of program headers: 52 (bytes into file) Start of section headers: 3652 (bytes into file) Flags: 0x10001005,mips2 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 10 Size of section headers: 40 (bytes) Number of section headers: 36 Section header string table index: 35 root@debian-mipsel:/home/user/wansview/devel# file hello hello: ELF 32-bit LSB executable,for GNU/Linux 2.6.26,BuildID[sha1]=0xeb3877062337a3dfd15cc09305691685ac0e8c57,with unknown capability 0xf41 = 0x756e6700,with unknown capability 0x70100 = 0x1040000,stripped
我正在努力更好地了解我的两个系统的不同之处,以及为什么这两个可执行文件不能运行.有没有任何标志,我可以添加到gcc成功编译嵌入式设备?
有关设备的更多信息
# cat /proc/cpuinfo system type : Ralink SoC processor : 0 cpu model : MIPS 24K V4.12 BogoMIPS : 239.10 wait instruction : yes microsecond timers : yes tlb_entries : 32 extra interrupt vector : yes hardware watchpoint : yes ASEs implemented : mips16 dsp VCED exceptions : not available VCEI exceptions : not available
更多关于Debian MIPSEL的信息
(在debian-mipsel上编译的二进制文件不会在目标嵌入式设备上运行)
root@debian-mipsel:/home/user/wansview/devel# cat /proc/cpuinfo system type : MIPS Malta processor : 0 cpu model : MIPS 24Kc V0.0 FPU V0.0 BogoMIPS : 1038.33 wait instruction : yes microsecond timers : yes tlb_entries : 16 extra interrupt vector : yes hardware watchpoint : yes,count: 1,address/irw mask: [0x0ff8] ASEs implemented : mips16 shadow register sets : 1 kscratch registers : 0 core : 0 VCED exceptions : not available VCEI exceptions : not available
更多关于Aboriginal Linux Mipsel的信息
(在原住民Linux上编译的二进制文件将在嵌入式设备上运行,它可以运行从设备检索的二进制文件,我不满意,因为它没有make和其他编译更大应用程序所需的工具)
(mipsel:1) /home/wansview # cat /proc/cpuinfo system type : MIPS Malta machine : Unknown processor : 0 cpu model : MIPS 24Kc V0.0 FPU V0.0 BogoMIPS : 1013.76 wait instruction : yes microsecond timers : yes tlb_entries : 16 extra interrupt vector : yes hardware watchpoint : yes,address/irw mask: [0x0ff8] isa : mips1 mips2 mips32r1 mips32r2 ASEs implemented : mips16 shadow register sets : 1 kscratch registers : 0 core : 0 VCED exceptions : not available VCEI exceptions : not available
LDD
这是一个屏幕截图,ldd针对我的hello世界,反对unzip1在原住民linux和debian mipsel.土着Linux运行从设备检索的应用程序很好,如果我在原住民Linux下编译,我可以在嵌入式设备上运行生成的二进制文件.我不满意土着原因的原因是,没有GNU make和其他有用的工具用于更大的应用程序,也没有简单的方法让他们在那里.
解决方法
wget http://buildroot.uclibc.org/downloads/buildroot-2014.11.tar.gz tar zxf http://buildroot.uclibc.org/downloads/buildroot-2014.11.tar.gz cd buildroot-2014.11
预先配置mipsel的技巧,R1没有软浮点(我的意志,检查你的):
cat <<_EOF > .config BR2_HAVE_DOT_CONFIG=y BR2_mipsel=y BR2_ARCH="mipsel" BR2_ENDIAN="LITTLE" BR2_GCC_TARGET_ARCH="mips32" BR2_GCC_TARGET_ABI="32" BR2_ARCH_HAS_ATOMICS=y BR2_mips_32=y # BR2_MIPS_SOFT_FLOAT is not set BR2_MIPS_OABI32=y _EOF
完成您在Buildroot menuconfig中的选择,但可以
保存并退出,也可以这样保存.
make menuconfig # tweak options at your will,make -j8 # takes 8 minutes on my machine
然后,您的编译器可以在./output/host/usr/bin中找到
一个真实的例子:
echo '#include <stdio.h> int main(int argc,char* argv[]) { printf("Hello World.\n"); return 0; }' > hello.c
并用您全新的uClibc GCC编译器进行编译
output/host/usr/bin/mipsel-buildroot-linux-uclibc-gcc -o hello hello.c
瞥见你的hello程序:(没有时间修复我的ldd …)
$file hello hello: ELF 32-bit LSB executable,MIPS32 version 1 (SYSV),not stripped $strings hello | grep "lib.*so*" /lib/ld-uClibc.so.0 libgcc_s.so.1 libc.so.0
它完成了工具链并编译您的程序.
现在你有时间:-)看看Buildroot提供的内容:
许多架构中嵌入式系统的完整分布(输出/目标/).
编辑:更好的执行机会
您可以静态链接您的程序,以最大限度地提高在任何目标上运行代码的机会.
$output/host/usr/bin/mipsel-linux-gcc -Wall -o hello -static hello.c $file ./hello ./hello: ELF 32-bit LSB executable,not stripped
现在,由于该静态版本不再依赖于任何外部库(仅适用于uClibc),所以该MIPS可执行文件甚至可以在我的x86_64机器上运行(感谢binfmt和Qemu):
$uname -mo x86_64 GNU/Linux $./hello Hello World.
干杯.