【问题标题】:Cross compiling for MIPS router from x86从 x86 交叉编译 MIPS 路由器
【发布时间】:2011-06-12 17:02:04
【问题描述】:

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

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

# cat /proc/version 
Linux version 2.4.17_mvl21-malta-mips_fp_le (root@localhost.localdomain) (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

【问题讨论】:

  • 在 mips 系统上找到任何二进制应用程序并在其上执行 file 并与我们共享输出
  • 好的,系统可执行文件的文件输出是:ELF 32 位 LSB 可执行文件,MIPS,MIPS-I 版本 1 (SYSV),动态链接(使用共享库),已剥离 谢谢到目前为止您的所有帮助。

标签: linux gcc embedded mips uclibc


【解决方案1】:

请随时查看dockcross 项目。他们为各种架构提供了作为 docker 容器的跨工具链。

就个人而言,我更喜欢让我的主机系统尽可能干净,所以这对我来说是完美的匹配。 要启动并运行一个简单的 hello world 示例,请按照README.rst 中的步骤操作。

MIPS 上的 HelloWorld.c

但是,请查看我的 hello world 编译以了解运行 DD-WRTNetgear N600 wndr3700v2 路由器。 (我已经链接了 openWRT wiki 页面而不是 dd-wrt,更喜欢这个)。

检查路由器上使用了哪个架构,请信任 wiki 页面或通过 ssh/telnet 连接并运行 uname -a 命令。

root@DD-WRT:~# uname -a
Linux DD-WRT 3.10.108-d10 #63184 Tue Nov 3 05:20:50 +03 2020 mips DD-WRT

所以我们可以从 dockerhub 拉取 mips 容器:

# pull dockcross container for mips
# repo: dockerhub -> https://hub.docker.com/r/dockcross/linux-mips
user@x86-host:~# docker pull dockcross/linux-mips:latest

# check if everything went correct
user@x86-host:~# docker images
dockcross/linux-mips   latest    cf6e2d5003c8   3 years ago    1.03GB

# create dockcross runner
user@x86-host:~# docker run --rm dockcross/linux-mips > ./dockercross-mips
user@x86-host:~# chmod +x ./dockercross-mips
# this will create a dockercross runner script in the current directory

让我们创建一个名为helloWorld 的简单项目文件夹,并在其中添加一些代码。

# helloWorld.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    printf("Hello World from dockercrossMips\n");
    return EXIT_SUCCESS;
}             

现在我们可以用dockcross编译它了。

# check if all files exists
user@x86-host:~# ll
total 12K
-rwxr-xr-x 1 user user 5.5K Feb 12 19:22 dockercross-mips
-rw-r--r-- 1 user user  151 Feb 12 18:51 helloWorld.c

# compile source into ELF
user@x86-host:~# ./dockercross-mips bash -c '$CC ./helloWorld.c -o helloWorld'

# check ELF file -> should show the proper type and machine
user@x86-host:~# readelf -h helloWorld 
ELF Header:
  Magic:   7f 45 4c 46 01 02 01 00 01 00 00 00 00 00 00 00 
  Class:                             ELF32
  ...
  OS/ABI:                            UNIX - System V
  ABI Version:                       1
  Type:                              EXEC (Executable file)
  Machine:                           MIPS R3000
  ...

现在我们已准备好传输并运行您的 helloWorld 可执行文件。

# copy via scp, use your favorite method 
user@x86-host:~# scp helloWorld root@192.168.0.2:/tmp/root/

# run it
root@DD-WRT:~# ./helloWorld 
# if you get some error like this one: -sh: ./helloWorld: not found
# please just start it via your loader
root@DD-WRT:~# /lib/ld-musl-mips-sf.so.1 helloWorld 
# and you should see the desire output.
Hello World from dockercrossMips

如果您不知道您的装载机在哪里,请使用file 命令。如果命令不可用,请查看entware 项目。 这里是官方的 dd-wrt ​​install tut here

【讨论】:

    【解决方案2】:

    退房:

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

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

    【讨论】:

      【解决方案3】:

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

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

      这些是我为 Buildroot 的 menuconfig 启用的选项:

      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  --->
      

      工具链本身安装在 /opt/cross-mips-buildroot。您可以在 /opt/cross-mips-buildroot/usr/bin/

      上找到编译器和其他工具

      尝试编译一个简单的hello world应用,看看能不能在mips系统中运行。

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

      【讨论】:

      • @nightfly19 您可能想要更改 Target Architecture Variant,因为您的是第 1 版,而不是第 2 版。
      • 谢谢!!您提供了使工具链正常工作所需的所有帮助。我的配置也被证明是小端的,对于任何关注这个问题的类似情况的人来说也是如此,所以架构需要是 mipsel。
      猜你喜欢
      • 1970-01-01
      • 2020-07-05
      • 2011-07-14
      • 2019-01-18
      • 1970-01-01
      • 2018-05-31
      • 2017-08-29
      • 2015-08-23
      • 1970-01-01
      相关资源
      最近更新 更多