3

I have a 32 bit MIPS machine and would like to run Linux on it. I need to cross compile Linux to MIPS using my Windows 7 machine. I am confused on how to go about this. Could someone tell me what the steps to this are and why? I do not understand all the different tools involved in this process. Thanks.

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
mcmiln
  • 143
  • 1
  • 6
  • 3
    Cross-compiling a Linux kernel on a Windows machine sounds like a non-trivial project, especially if you're a beginner. Since you say you "would like to run Linux", it sounds like you have nothing installed on the MIPS machine at all. Basically, you want to build [Linux From Scratch](http://www.linuxfromscratch.org/lfs/view/stable/), which is a whole book, and not a Stack Overflow answer. – 200_success Nov 22 '15 at 10:11
  • I doubt you're gonna have answer for this one. Maybe there is a way to do that under Windows, but it must be really hard. And besides, everyone I know who is working on Linux kernel (including MIPS architecture) using Linux for building kernel and rootfs. So I suggest you install Linux distribution (Ubuntu 14.04 will do) and use it for building the kernel and rootfs, and flashing built images to your device. You may want to ask a new question about building kernel for MIPS under Linux, but be sure to provide more details (what is CPU, what is device, kernel version etc). – Sam Protsenko Nov 22 '15 at 14:44
  • I think the `mingw` project can help here, though I agree with @SamProtsenko it will be quite hard to do, for example, to find everything you need of the proper version. – 0andriy Nov 22 '15 at 15:30
  • @200_success you are correct in assuming nothing is on the MIPs machine. The processor is actually homemade VHDL. Glad I'm not wrong in seeing this as difficult. I guess I should scale back the question to be what are the necessities in compiling Linux on Windows. I will read the given link, It looks very good. – mcmiln Nov 22 '15 at 20:55
  • @Sam Protsenko That's a fair step. I will likely end up doing that, but am now curious as to the intricacies of compiling Linux on Windows. If it is truly that hard, I would like to figure it out. – mcmiln Nov 22 '15 at 20:58
  • @mcmiln First of all, you need to figure out which components need to be built. I'm not sure you really want Linux From Scratch. If I remember correctly, it's intended for building PC environment. If you have some embedded system, LFS would be a bit over-engineered solution. For the starters I'd recommend you to build Linux kernel alone (using MIPS cross-compiler from MIPS toolchain) and then to build [BusyBox](http://www.busybox.net/) based [rootfs](https://en.wikipedia.org/wiki/Root_directory). Then you can flash both on your device and have minimal working environment. – Sam Protsenko Nov 22 '15 at 21:12
  • @SamProtsenko Thanks, that sounds like a good starting place. I will run with this game plan in mind. – mcmiln Nov 22 '15 at 21:17
  • @mcmiln As for the OS choice: well, you **can** (theoretically) build kernel and BusyBox rootfs under Windows, see [MIPS toolchain for Windows](http://stackoverflow.com/questions/5291190/how-to-cross-compile-for-mips). 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 easily and natural using Linux for Linux development. In short: Windows is alien environment for Linux, try to avoid using it. – Sam Protsenko Nov 22 '15 at 21:18
  • @SamProtsenko I appreciate the answer. I see what you are saying, and there is no reason to work against myself. Though an interesting challenge for the future, I have reformatted my question. If you want to essentially just put your comments into an answer I would be happy to accept it. – mcmiln Nov 22 '15 at 21:30
  • Another place to gather info on building a Linux kernel for MIPS (but on a Linux system, no Windows, as far as I know) might be the [OpenWRT](https://openwrt.org/) project. recently installed it on a MIPS based routerboard. OpenWRT provides the bae crosscompilation environment (buildroot based I think) that you will need to configure and compile for your specific hw board. – sergico Nov 22 '15 at 22:27
  • @mcmiln Done. Also added some extra stuff about cross-compiling. – Sam Protsenko Nov 22 '15 at 23:26

1 Answers1

9

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:

  1. 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.
  2. 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:

Once toolchain installed you need to do next things in your working environment (shell).

  1. Update your PATH environment variable, adding bin/ directory of your toolchain to it:

    $ export PATH=/opt/path/to/your/toolchain/bin:$PATH
    
  2. Export CROSS_COMPILE environment variable, which should contain prefix for your toolchain. E.g., if you see mips-sde-elf-gcc in your toolchain bin/ directory, then you should do next:

    $ export CROSS_COMPILE=mips-sde-elf-
    
  3. 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.

mja
  • 1,273
  • 1
  • 20
  • 22
Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75