[ Aleph One home page | Company Information | Security Privacy and Terms of sale | Search ]



Aleph One
Logo

HOWTO: Linux on Brutus and other Arms


This HOWTO has been written by Cameron Morland, and is published here with permission. Aleph One is hosting it and associated scripts and patches.

Introduction

This document will outline what is required to get Linux working on various Arm based computers, but is written and tested for Intel's Brutus board.

I have tried to go into detail about each step, and include all commands to type at the prompt; it may be necessary to modify some of these commands. For example, you will need to replace "cjmorlan" (my username) with yours. Don't do everything as root. If you have problems with any package, hopefully it has an included INSTALL or README file. If you feel that I go too slowly and check too often, it's because there are many things that can go wrong, and knowing what is working is helpful.

I welcome feedback; if there is a problem with this document, please tell me. I can't check, as I no longer have a Brutus as of May 2000. If you want to donate one, I'd not complain. :')

This process requires a computer with one RS-232 serial port, running some sort of *NIX. You must be able to run i386 Linux binaries. If you can't, you can still follow this procedure, but you will need to build binaries for your system. If you build non-i386 replacements for any of the packages, email me so I can link to your copy. Also, on all systems, your compiler must be GCC, as other compilers are apparently unable to compile Glibc.

If you haven't set up your *NIX partitions yet, you should make a spare one; 16 MBytes is more than enough, 5 is as little as you can have. Without a spare partition, you will have to have loopback support in your kernel, and learn how to use it.

I'm assuming that all files downloaded will go into ~/gz/ (ie a sub directory called "gz" in your home directory). You require root access for just a little bit, everything else should be done as a user.

There is no warranty with this HOWTO. At least one step could trash your *NIX install. I assume no responsibility for this or other problems.

Summary

  1. Do root-level tasks
  2. Interface with Angel
  3. Modify the ramdisk filesystem
  4. Get a working cross compiler
  5. Compile a custom kernel
  6. Glibc
  7. Write a test userspace program
  8. Create a kernel module

Do root-level tasks

Almost nothing here does requires root access, so what is required I've grouped together. You need to be able to write to the serial port. I'm using (and the default is) /dev/ttyS0, so
[/root]# chmod 666 /dev/ttyS0
Now you need to own the spare hard disk partition, and someplace to mount it. I'm using /dev/sda5 but you probably aren't, and you must change every mention I make of it to a spare partition. (If you don't have a spare partition you will need loopback support in your kernel.)
[/root]# chown cjmorlan /dev/sda5
[/root]# mkdir /mnt/ram
[/root]# mkdir /usr/arm
[/root]# chown cjmorlan /usr/arm
[/root]# mkdir /usr/arm-linux
[/root]# chown cjmorlan /usr/arm-linux
To let yourself mount the filesystem, add this line to /etc/fstab:
/dev/sda5 /mnt/ram ext2 user,noauto 0 0
The spare partition should not already exist in /etc/fstab; if it does, then it isn't spare. If you use /dev/sda5 and it is not a spare partition you may destroy your system!

You will need to be root again for a few moments later on.

Interface with Angel

You need to be able to download to the development board. The program for this is called angelboot. It interfaces with the Angel debugger in Brutus's flash. A working demo (with working boot disk and such) is available at ftp://ftp.netwinder.org/users/n/nico/brutus-test.tgz. Download and untar
[cjmorlan]$ tar -xvzf ~/gz/brutus-test.tgz
[cjmorlan]$ cd brutus-test
then hook up Brutus, switch it on, and type
[brutus-test]$ ./go
Downloading to Brutus sometimes halts, and needs to be started over. Hit CTRL-C (^C) until the program quits (or kill it), switch Brutus off then on, and run "./go" again. Sometimes this takes several tries; it appears to be a hardware problem, and Intel seems unable/unwilling to fix it. Once it downloads successfully, you should see a Penguin on the LCD screen, and be able to login as root using the keyboard. Poor connections to the LCD are also a problem.

Modify the ramdisk filesystem

Now you can download a ramdisk. This is irrelevant if you can't modify the contents, but thankfully it's easy to do so. The default ramdisk is really out of date, but you want to keep a copy.
[brutus-test]$ mv ramdisk.gz ramdisk-old.gz
Now download a newer ramdisk Put this one in the brutus-test directory.
[brutus-test]$ mv ~/gz/ramdisk.gz .
To mount the disk, use edit_image.sh and save_image.sh. You must edit these two scripts to replace /dev/sda5 with your spare partition. Because you already own the partition, you don't need to be root to mount it. Put the scripts in ~/brutus/brutus-test/, then run edit_image.sh. The '-d' option is required to extract the information from ramdisk.gz. Check that the disk is mounted with df.
[brutus-test]$ mv ~/gz/*_image.sh .
[brutus-test]$ chmod +x *_image.sh
[brutus-test]$ sh edit_image.sh -d
dumping ramdisk.gz to /dev/sda5
10240+0 records in
10240+0 records out
mounting /dev/sda5
[brutus-test]$ df
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda5             480M   83M  372M  18% /
/dev/hda1             9.5M  1.8M  7.2M  20% /boot
/dev/sda6             2.0G  1.8G   85M  96% /usr
pluto:/home            28G   20G  6.8G  74% /home
/dev/sda5              16M  4.6M  1.2M  79% /mnt/ram
Now that the data have been dumped to /dev/sda5, you will not require the '-d' switch for edit_image.sh, unless you want to start over or use a different ramdisk.

You need to be root again for a moment, to let you write to /root on the ramdisk.

[/root]# chown cjmorlan /mnt/ram/root
There isn't anything interesting to do to the filesystem, so for now just prove you can modify it.
[brutus-test]$ ls /mnt/ram/root
greet.c  greet.o  light.c  light.o
[brutus-test]$ touch /mnt/ram/root/FOO
[brutus-test]$ ls /mnt/ram/root
FOO  greet.c  greet.o  light.c  light.o
There is a new file called FOO. The others are example kernel modules. I will deal with them later. For now, you need to dump the ramdisk back to a file.
[brutus-test]$ sh save_image.sh
unmounting /dev/sda5
retrieving ramdisk from /dev/sda5
5+0 records in
5+0 records out
gzipping ramdisk
Now you can run "go" again to boot with the modified ramdisk. /root/FOO should exist when you login on the Arm.

Get a working cross compiler

By now you can put any file you like onto a ramdisk and download it to the Brutus board. If every program you need already exists as a binary, and you're happy with the default kernel, you're done. But this isn't true, as you obviously want to write your own C programs.

Building a cross compiler by hand can be difficult. But someone has built one to compile for the Arm using a i386 host. It is available from ftp://ftp.netwinder.org/users/n/nico/arm-xtoolchain.tgz. Expand it from / and make yourself own it. You will need to be root.

[/root]# cd /
[/]# tar -xvzf ~cjmorlan/gz/arm-xtoolchain.tgz
[/]# chown -R cjmorlan /usr/local/arm-linux/
[/]# chown -R cjmorlan /usr/local/lib/gcc-lib/arm-linux/
Non-i386 users will have to make their own cross compiler.

Creating a custom Kernel

You will want to compile your own kernel, and it is necessary to do so before setting up glibc. To determine what version of the kernel you can download, find the appropriate patches (fill in the details) from ftp://ftp.arm.linux.org.uk/pub/linux/arm/source/kernel-patches/v2.3/patch-2.3.39.gz and ftp://ftp.netwinder.org/users/p/philb/kernel/linux-2.3.39rmk1-cvs000121.diff.gz I used 2.3.35, as both of these sites had a patch for that version at the time. You also, of course, need Linux itself from ftp://ftp.kernel.org/pub/linux/kernel/, but get the patches first so you know what kernel version to use.
[brutus-test]$ cd /usr/arm
[arm]$ mkdir src
[arm]$ cd src
[src]$ tar -xvzf ~/gz/linux-2.3.39.tar.gz
...
[src]$ cd linux
[linux]$ gzip -dc ~/gz/patch-2.3.39-rmk1.gz | patch -p1
[linux]$ gzip -dc ~/gz/linux-2.3.39rmk1-cvs000121.diff.gz | patch -p1
You now need to edit /usr/arm/src/linux/Makefile. Remove the line
ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/)
(or something like that) with
ARCH = arm
Now you need to setup a configuration. Do this by saying
[linux]$ make menuconfig
You may need to remove a few things to make it conpile successfully. I had to remove the following: and also add the following: It might be instructive to look at my .config file, though it is by no means perfect.

Now to actually compile the kernel,

[linux]$ make dep
[linux]$ make zImage
If it fails, run "make menuconfig" again, remove/add whatever seems appropriate, and run "make zImage" again. A few iterations might be required. The list above is probably what you will need to change.

Take note that the only kernel I have successfully compiled is 2.3.35 with patch-2.3.35-rmk1.gz and diff-2.3.35-rmk1-np7.gz, the latter being a replacement for the patch from ftp.netwinder.org.

So now you probably have a working kernel, and can link the kernel headers to allow compilation of userspace programs.

[linux]$ ln -s /usr/arm/src/linux/include/linux /usr/local/arm-linux/include
[linux]$ ln -s /usr/arm/src/linux/include/asm-arm /usr/local/arm-linux/include/asm

Installing Glibc

You need to install glibc before you can compile anything. You need the latest glibc from ftp://sourceware.cygnus.com/pub/glibc/releases/ and the matching linux-threads file. You also need a linux-crypt file, which can't be exported from the US, so it's developed elsewhere. Download it from ftp://ftp.funet.fi/pub/gnu/funet/ , unless you're in the US, in which case you could legally get it from sourceware.cygnus.com
[linux]$ cd /usr/arm/src
[src]$ tar -xvzf ~/glibc-2.1.tar.gz
[src]$ cd glibc-2.1
[glibc-2.1]$ tar -xvzf ~/gz/glibc-linuxthreads-2.1.tar.gz
[glibc-2.1]$ tar -xvzf ~/gz/glibc-crypt-2.1.tar.gz
[glibc-2.1]$ CC=arm-linux-gcc
[glibc-2.1]$ ./configure arm-linux --build=i586-linux --prefix=/usr/local/arm-linux --enable-add-ons
[glibc-2.1]$ make
[glibc-2.1]$ make install

Write a test userspace program

We need a program to prove that the cross compiler works properly. The simple hello.c program is the place to start. Compile it using the Arm cross compiler.
[brutus-test]$ mv ~/gz/hello.c .
[brutus-test]$ arm-linux-gcc hello.c -o hello
Copy it to the ramdisk, and download the new ramdisk to Brutus. Run it at the Brutus console.
[root@localhost /root]# ./hello
Hello, world!

Create a kernel module

It's a good guess that you want to interface special hardware to the Brutus board. Even if this isn't so, you might feel like writing the device driver for some of the unsupported hardware in the Brutus. Modern kernel module support is the reason you downloaded a new ramdisk image near the beginning. Try the modules in /root.
[root@localhost /root]# insmod greet.o
Hello, world
[root@localhost /root]# lsmod
Module                  Size  Used by
greet                  64184   0  (unused)
[root@localhost /root]# rmmod greet
Goodbye cruel world
[root@localhost /root]# insmod light.o
[root@localhost /root]# rmmod light
When "light" is loaded, the light connected to GPIO 20 should switch on.

These modules may not work without being recompiled unless your kernel is the same as mine. Recompiling one should fix it; you can compile a kernel module by saying

[cjmorlan]$ cp /mnt/ram/root/greet.c .
[cjmorlan]$ arm-linux-gcc -c greet.c
I recommend Linux Device Drivers by Alessandro Rubini if you want to write device drivers.

Other Resources

Additional Notes

If you don't have a spare partion, ensure your kernel has loopback support. Then look at the edit_image script for a guess how to use it.
Copyright © 2000 Cameron Morland
$Revision: 1.8 $ - $Date: 2000/03/29 18:21:17 $
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

Valid HTML 3.2  Last Updated: 2000.08.24 Use any browser

[ Aleph One home page | Company Information | Security Privacy and Terms of sale | Search ]