Linux 从 x86 交叉编译 MIPS 路由器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4751709/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 02:33:50  来源:igfitidea点击:

Cross compiling for MIPS router from x86

linuxgccembeddedmipsuclibc

提问by sagenite

My end goal is to compile wireless tools for my old Actiontec modem/router so I can configure it as a wireless to ethernet bridge. Currently it's wireless features are (seemingly) controlled by the same binary that manages most of the web interface, but it appears that they used the library wireless tools uses internally for at least some of the functionality.

我的最终目标是为我的旧 Actiontec 调制解调器/路由器编译无线工具,以便我可以将其配置为无线到以太网的桥接器。目前,它的无线功能(似乎)由管理大部分 Web 界面的同一个二进制文件控制,但似乎他们使用了内部无线工具使用的库,至少用于某些功能。

I've never cross compiled for a different CPU architecture before and not sure how to fully identity what I need to do. I'm trying to use uClibc since it appears to be used in the rest of the system, but I'm not sure how to configure buildroot for the modems environment. I made a best guessat what the configuration should be based on the information from proc below, but somethings wrong since a simple C application that only returns 0 compiled with it fails to run properly.

我以前从未针对不同的 CPU 架构进行交叉编译,并且不确定如何完全识别我需要做的事情。我正在尝试使用 uClibc,因为它似乎用于系统的其余部分,但我不确定如何为调制解调器环境配置 buildroot。我根据下面来自 proc 的信息对配置应该是什么做出了最好的猜测,但有些错误,因为一个只返回 0 编译的简单 C 应用程序无法正常运行。

# cat /proc/version 
Linux version 2.4.17_mvl21-malta-mips_fp_le ([email protected]) (gcc version 2.95.3 20010315 (release/MontaVista)) #1 Thu Apr 21 18:04:37 PDT 2005
# cat /proc/cpuinfo 
processor               : 0
cpu model               : MIPS 4KEc V4.8
BogoMIPS                : 149.91
wait instruction        : no
microsecond timers      : yes
extra interrupt vector  : yes
hardware watchpoint     : yes
VCED exceptions         : not available
VCEI exceptions         : not available

采纳答案by karlphillip

You are right, you need a proper mips toolchainto cross-compile your application and Buildrootcan do that. But you may need to tweak buildroot's menuconfigoptions. Depending on the output of file, your options may change. On my system, binary apps inform the following:

您是对的,您需要一个合适的mips 工具链来交叉编译您的应用程序,而Buildroot可以做到这一点。但是您可能需要调整 buildroot 的menuconfig选项。 根据 的输出file,您的选项可能会改变。在我的系统上,二进制应用程序通知以下内容:

ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV)

ELF 32-bit MSB executable, MIPS, MIPS32 rel2 version 1 (SYSV)

These are the options I have enabled for my Buildroot's menuconfig:

这些是我为 Buildroot 的菜单配置启用的选项:

Target Architecture (mips)  ---> 
Target Architecture Variant (mips 32r2)  --->                                                            
Target ABI (o32)  --->                                                                                   
Target options  --->                                                                                     
Build options  --->   
    (/opt/cross-mips-buildroot) Toolchain and header file location?                                                                                   
Toolchain  --->        
    Toolchain type (Buildroot toolchain)  ---> 
    Kernel Headers (Linux 2.6.34.x kernel headers)  --->
    uClibc C library Version (uClibc 0.9.31.x)  ---> 
    [*] Build/install a shared libgcc?
    [*] Enable compiler tls support       
    [*] Build gdb debugger for the Target
    [*] Build gdb server for the Target
    [*] Build gdb for the Host
        GDB debugger Version (gdb 6.8)  --->
    [*] Enable large file (files > 2 GB) support?
    [*] Enable WCHAR support
    [*] Use software floating point by default
    [*] Enable stack protection support
    [*] Build/install c++ compiler and libstdc++?
    [*] Include target utils in cross toolchain  
Package Selection for the target  --->   
    [*] BusyBox
    [*]   Run BusyBox's own full installation
    Libraries  ---> 
        Networking  ---> 
            [*] libcurl
        Text and terminal handling  ---> 
            [*] icu
            -*- ncurses    
Target filesystem options  --->                                                                          
Bootloaders  --->                                                                                        
Kernel  --->

The toolchain itself is installed at /opt/cross-mips-buildroot. You can find the compiler and other tools on /opt/cross-mips-buildroot/usr/bin/

工具链本身安装在/opt/cross-mips-buildroot。您可以在/opt/cross-mips-buildroot/usr/bin/上找到编译器和其他工具

Try to compile a simple hello worldapplication and see if you can run it inside the mips system.

尝试编译一个简单的hello world应用程序,看看是否可以在 mips 系统中运行它。

Note:this configuration will not build a C++ compiler. If you need it, you can grep LIBSTDCPP .configand check if it's enable or not and change it to your likes. Then make menuconfigto make it happen.

注意:此配置不会构建 C++ 编译器。如果您需要它,您可以grep LIBSTDCPP .config检查它是否已启用并将其更改为您喜欢的。然后make menuconfig让它发生。

回答by Brad

Check out:

查看:

http://www.kegel.com/crosstool/

http://www.kegel.com/crosstool/

It's the authoritative site on cross-compiling under GCC.

它是GCC下交叉编译的权威站点。