Reputation: 113
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
Upvotes: 11
Views: 21077
Reputation: 389
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.
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
Upvotes: 0
Reputation: 11515
Check out:
http://www.kegel.com/crosstool/
It's the authoritative site on cross-compiling under GCC.
Upvotes: 1
Reputation: 93468
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.
Upvotes: 11