Cross compiling for MIPS router from x86
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.
Compile parameters for MIPS based codesourcery toolchain?
Do you have libgcc_s.so.1 on teh file system? If not, the toolchain will have a folder to copy onto the file system. Do that.
If you do, ensure LD_LIBRARY_PATH is correctly set.
EDIT: Generic issue resolution
When you create a executable, you link to libraries. Those libraries must also be present in the environment where you run the executable. Hence in general in a embedded system 3 things must match
- The kernel headers
- The toolchain
- The file system
Here is how they are related
Your kernel headers are used as #include in your program in some form finally. So what headers the toolchain uses must match the actual one running and will be present in the file system.
The toolchain will consist of libraries to link to, so that the executable can be created [think libc and others]. These must be the same present in your runtime environment which is your filesystem
The toolchain must create a format agreable to your kernel. Executable format.
So in general if you don't have a file in your filesystem while trying to execute it should come from some sdk or your toolchain.
If you have it in the filesystem then you can instruct your toolchain to use it from there.
One way to get around the problem if you do not have the libraries in the filesystem for some reason is to build static executables. But you must be sure you know what you are doing.
EDIT: Specific issue you are facing
If you filesystem is readonly then either you already have everything on it and a sdk is provided to develop against. If you dont have that you can still develop by getting your toolchain to use libraries from your filesystem [think -I, -L].
EDIT 2:
Your file system seems to be a ucLibc one. Your toolchain seems to be built against a libc. There is your mismatch.
Now you seem to have a read only file system with no development sdk. So I am not sure the following will work.
Your toolchain has to be configured to use only the files from your filesystem and configured for ucLibc. If the router guys have made sure all files needed for development is available in the rilesystem its good enough. Else you need their sdk. See above edit for explanation.
Compiling a driver for MIPS architecture on 4.4 kernel
In mipsisa32-be-elf.inc file, given the path /kernel/include/uapi in -isystem compilation flag. This helps to solve the above compilation issue.
buildroot,how to set the host platform architecture
In Buildroot:
- the machine on which you build is called host. Buildroot downloads and builds host packages, in order to prepare to cross-compilation.
- machine on which you are going to run your Embedded Linux is called target.
So if your target is MIPS, you should select this as target architecture and start the build. Buildroot will be able to figure out the toolchain needed and properly build your Embedded Linux image for the target (kernel, bootloader, rootfs).
This answer may help if you are building for MIPS:
Cross compiling for MIPS router from x86
You can also build a minimal image using an existing defconfig:
For example:
cd buildroot
make qemu_mips64r6_malta && make
which will create an image for QEMU with MIPS 64-bit architecture for Malta board.
I guess your confusion comes from the fact that you have 2 target CPUs that need to run Linux, and you call them host & target. But in buildroot terms, host is the build machine, and target is the embedded board/CPU. You don't need to change host/build machine architecture.
Cross Compiling Samba 4.0.5 i686 to MIPS
Alright, I've found a solution and I'll leave the answer if someone encounters similar situation.
The above steps are completely correct. Yet the one should make sure that the headers are taken from the MIPS compiler directory. So I changed the source code of sysquotas_4A.c by specifying the full path to the quota.h which in my case is /opt/buildroot-gcc342/include/sys/quota.h and it works just fine.
Cheers,
Constantine
Compiling the Linux kernel for MIPS
OS concerns
Well, you can (theoretically) build kernel and BusyBox rootfs under Windows, see MIPS toolchain for Windows. But it can be rather hard to prepare the correct build environment in Windows (probably Cygwin or MinGW, I'm not sure). For example, in Ubuntu you have everything ready just out-of-the-box.
Another point is development -- it's much more easy and natural to use Linux for Linux kernel development. Everyone I know who is working on Linux kernel (including MIPS architecture) is using Linux for development and building the kernel and rootfs.
In short: Windows is an alien environment for Linux development, try to avoid using it.
So I suggest you to install Linux distribution and use it for building the kernel and rootfs, and flashing built images to your device. Latest Ubuntu LTS will do (which is Ubuntu 14.04 for now).
Components
First of all, you need to figure out which components need to be built. If you have embedded system -- for the starters I'd recommend you to do next:
- build bootloader; I recommend U-Boot
- build Linux kernel alone (
git clone
stable version from here) - build BusyBox-based rootfs
- flash bootloader, kernel and rootfs images to your device
Now you have minimal working environment.
Toolchain
Before building anything, make sure that you have MIPS toolchain installed and your environment (shell) is configured properly. There are 2 kinds of toolchains out there:
- ELF toolchain (has
-elf
or-none-eabi
in its name): intended for bare-metal programs. You should use it to build your bootloader and kernel. - GNU/Linux toolchain (has
-linux-gnu
or-linux-gnueabi
in its name): it depends on Linux system calls and has C Standard Library, so it's intended for building user-space applications running under Linux. You should use it for building BusyBox, as it's user-space program.
I may recommend you to look into Sourcery CodeBench toolchains. Particularly you are interested in next:
- ELF toolchain
- GNU/Linux toolchain
Once toolchain installed you need to do next things in your working environment (shell).
Update your
PATH
environment variable, addingbin/
directory of your toolchain to it:$ export PATH=/opt/path/to/your/toolchain/bin:$PATH
Export
CROSS_COMPILE
environment variable, which should contain prefix for your toolchain. E.g., if you seemips-sde-elf-gcc
in your toolchainbin/
directory, then you should do next:$ export CROSS_COMPILE=mips-sde-elf-
Export ARCH env. var. set to your architecture:
$ export ARCH=mips
Now you can build your kernel and BusyBox the same way as you do it for x86:
$ make <target>
Useful reading
As it was recommended in comments, it may be worth to look into OpenWrt project, as it's intended for MIPS architecture (it's quite popular open-source firmware for various routers) and it's extensively using MIPS tools. Take a look at OpenWrt build system documentation to get some clue about those tools.
Related Topics
How to Find Files Modified in Last X Minutes (Find -Mmin Does Not Work as Expected)
Maximum Number of Files/Directories on Linux
How Use Qt in Visual Studio Code
What's the Meaning of a ! Before a Command in the Shell
How to Enable Bash in Windows 10 Developer Preview
Linux Execute Command Remotely
Gcc-Arm-Linux-Gnueabi Command Not Found
How to Fix the Rust Error "Linker 'Cc' Not Found" for Debian on Windows 10
Deleting a Folder from Svn Repository
Iterate Over Lines Instead of Words in a for Loop of Shell Script
Http Debugging Proxy for Linux and MAC
What's the Best Way to Distribute a Binary Application for Linux
How to Pass Arguments with Special Characters to Call Shell Script
How the Share Library Be Shared by Different Processes
Why Characters Received in Serial Connection Only After Pressing Enter