Compiling the Linux kernel for MIPS [closed]

2020-03-07 05:10发布

问题:

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 4 years ago.

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.

回答1:

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:

  • ELF toolchain
  • GNU/Linux toolchain

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.