从 x86 交叉编译 MIPS 路由器

发布于 2024-10-13 02:11:42 字数 1024 浏览 3 评论 0原文

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

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

# 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

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.

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 guess at 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.

# 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最佳男配角 2024-10-20 02:11:42

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

ELF 32 位 MSB 可执行文件、MIPS、MIPS32 rel2 版本 1 (SYSV)

这些是我为 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  --->

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

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

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

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

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

These are the options I have enabled for my Buildroot's 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  --->

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/

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

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

人事已非 2024-10-20 02:11:42

查看:

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

这是跨领域的权威网站在 GCC 下编译。

Check out:

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

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

昔梦 2024-10-20 02:11:42

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

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

MIPS 上的 HelloWorld.c

不过,请查看我的 hello world 编译,了解正在运行的 Netgear N600 wndr3700v2 路由器DD-WRT。 (我链接了 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 [email protected]:/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 ​​安装图这里

please feel free to look into dockcross project. They offer cross tool-chains as docker containers for various architectures.

Personally, I prefer to keep my host system as clean as possible, so this is a perfect match for me.
To get a simple hello world example up and running please just follow the steps from the README.rst.

HelloWorld.c on MIPS

However, please checkout my hello world compilation for a Netgear N600 wndr3700v2 router running DD-WRT. (I have linked the openWRT wiki page instead of the dd-wrt, prefer this one).

Check which arch is used on the router, please trust the wiki pages or just connect via ssh/telnet and run uname -a command.

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

So we can pull the mips container from dockerhub:

# 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

Let's create a simple project folder called helloWorld and but some code into it.

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

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

Now we can compile it with 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
  ...

Now we are ready to transfer and run your helloWorld executable.

# copy via scp, use your favorite method 
user@x86-host:~# scp helloWorld [email protected]:/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

In case you do not know where your loader is located, please use file command. In case the command is not available, please checkout entware project.
Here would be the official dd-wrt install tut here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文