This document reflects what I have learned through porting several MIPS machines and other related Linux work. Hopefully it will help beginners to get started and give the experienced a reference point.
This document goes through all the major steps to port Linux to a MIPS machine. The focus can perhaps be called "MIPS machine abstraction layer", i.e., the interface between machine-specific code and, mostly, MIPS common code. Another useful document focuses on "Linux hardware abstraction layer", i.e., the interface between Linux common code and architecture-specific code. The document is written by C Hanish Menon (www.hanishkvc.com).
- Know C programming.
- Have some knowledge of OS concepts, such as interrupt handling, system calls, memory management.
- Know how to configure and make Linux kernel. You can find many helps on this if you are not very comfortable.
- Have some knowledge of MIPS CPU. More than likely you will need to deal with CP0 registers, enable or disable interrupts, etc..
- You don't have to be an expert in MIPS assembly, but total ignorance of it might make you handicapped in some situations.
- Obviously, you need a MIPS hardware to play with.
- Finally but most importantly, you need a willing-to-learn heart and perhaps many restless debugging hours. :-)
It is also highly recommanded to read through the Linux MIPS HOWTO by Ralf Bächle, email@example.com. By the way, as part of the pre-requisite, you should also remember Ralf's name. :-)
Kernel source trees
The common MIPS tree is the CVS tree at linux-mips.org. See the instructions in "Anonymous CVS servers" section in Linux/MIPS HOWTO. The current kernel version as of 2004/01/26 is 2.6.1. You can always check out earlier stable revisions by using "linux_2_4" or even "linux_2_2" branch tag.
For various reasons, a kernel tree may leave bugs there for a quite long time before a suitable fix is checked in. There are various places to get patches. Here are some of the more common ones:
Cross-compilation and toolchains
More than likely your MIPS box does not run Linux yet (why would you bother otherwise?). Therefore you will need another machine to build the kernel image. Once the image is built, you need to download this image to your MIPS machine and let it run your MIPS kernel. This is called cross-development. Your MIPS box is often called the target machine and the machine used to build the kernel image is called the host machine.
Cross-development is common for developing on embedded targets, because usually embedded targets do not have enough power or the peripherals to develop natively.
The most common host machine is probably Linux on i386/PCs
You need to have cross-development tools setup on your host before you can start. Several years of experience have show that while you can find instructions to build cross-compilation tools, your best bet is probably to get some ready-made ones. Another reason is that a full toolchain build has become quite time consuming so you probably want to avoid it.
MontaVista used to offer for free Journeyman edition, which includes a full featured toolchain. Unfortunately, it does not offer that anymore. Instead you can download the preview kit, which includes a "slim" version of toolchain. You can get the kit from http://www.mvista.com/previewkit/index.html
Dan Kegel has a set of scripts that build cross-compiling tools. You can check it out here.
The following are links to pre-build toolchains, instructions to build your own toolchain and finally pre-compiled distributions for MIPS boards:
- Brad LaRonde's cross toolchain for Linux
- Steve Hill's toolchains for glibc and uClibc
- Toolchains from MIPS Technologies
- Distributions for MIPS
Overall porting steps
Depending on your specific cases, some of the following steps can be skipped.
- Hello World! - Get board setup, serial porting working, and print out "Hello, world!" through the serial port.
- Add your own code.
- Get early printk working - Make the first MIPS image and see the printk output from kernel.
- Serial Driver and Console - Get the real printk working with the serial console.
- KGDB can be enormously helpful in your development. It is highly recommended and it is not that difficult to set up.
- CPU support - If your MIPS CPU is not currently supported, you need to add new code that supports it.
- Board specific support - Create your board-specific directory. Setup interrupt routing/handling and kernel timer services.
- PCI subsystem - If your machine has PCI, you need to get the PCI subsystem working before you can use PCI devices.
- Ethernet drivers - You should already have the serial port working before attempting this. Usually the next driver you want is the ethernet driver. With ethernet driver working, you can set up a NFS root file system which gives you a fully working Linux userland.
- ROMFS root file system - Alternatively you can create a userland file system as a ROMFS image stored in a ramdisk.
- Some words on Debugging.
Next page: Hello World