Re: Porting Linux to a new architecture

Mitchell Blank Jr (mitch@execpc.com)
Thu, 8 Jul 1999 15:01:34 -0500


James K Whiting wrote:
> My lab is designing control boards for some robots, and they would like me
> to port Linux to run on them. Where can I find documentation on what needs
> to be done to port Linux to a new architecture?
>
> We are going to be using Hitachi SuperH SH-4 based computers.

First check out: http://linuxsh3.cjb.net/ These folks are organizing
a port to the hitachi sh-3 (which I guess is similar(?)). They don't
seem to be far yet, but they might have developed some insight into
the problem.

The first thing to do is determine how your hardware will load the
kernel. If your existing bootstrap system can deal with an ELF executable
then you're in business. Otherwise you have to decide if you're going
to (1) make a new bootstrap, (2) make a two-stage loader, or (3)
hack together a post-processor that turns the compiled kernel into
something that your hardware will like. Make sure your bootloader
can deal with initrd filesystems.

You should make sure that your toolchain is in order. The GNU tools
all support the Hitachi, IIRC, but make sure that they can produce
something resembling linux-elf.

Test your bootstrap and toolchain by making a tiny ELF executable
that just does some simple hardware thing (like writing a string to
a serial port).

Now, the kernel. Make a new include/asm-* and arch/* directory.
These aren't completely documented but there are plenty of examples - just
look around. One thing you'll have to is determine how the userland
will interface with the kernel - i.e. what a system call will look
like, etc. Sometimes the hardware makes the choice real easy, sometimes
there's a lot of flexibility. Anyway, choose carefully since it'll
be hard to fix later.

As for initial stuff to write - just get a console device up (usually
a serial port is easiest). Don't worry about disk or network yet -
you can boot off an initrd filesystem. (For an initrd filesystem, just
make an "/sbin/init" that does a few simple system calls and loops)
The other nice advantage of not doing disk or network is that you
don't have to worry about getting DMA right initially.

Once that is working, you can easily start work in multiple directions.
The obvious one is filling out the list of device drivers. The other
one is to start porting libc (which is a whole 'nother mailing list :-)
Once you have libc working you can start compiling a full userland.
Congratulations, you're done.

-Mitch

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/