This is a guide to cross compiling a linux kernel for your Netus and creating a matching root file store.
If you want a pre-created system then please read Debian
This was all done on an Ubuntu 9.10 PC (Doug Gilbert reports this also works on Ubuntu 10.04, an earlier version worked on Ubuntu 8.10).
Although the Netus is completely capable of compiling applications and the kernel natively on the Netus itself cross compiling can be considerably faster. My Core 2 Duo 2 1 Gigabyte RAM PC can cross compile programs at least 10 times faster and for big programs over 20 times faster.
A few years back the people behind the ARM cpu range improved the way function calls were made. This new technique was called the “Embedded Abstract Binary Interface” or EABI for short. The ARM design also allowed for both big-endian and little-endian byte arrangements. The Netus is setup to use the new EABI as little-endian - ARM EABI little - or ARMEL for short.
Emdebian is short for the Embedded Debian Project an ongoing project to build Debian for small ARM based systems. In the long term I'm sure projects will be able to use all the space saving advances of Emdebian's Grip and Crush highly compact set ups. But here we are just going to use its ARM cross compiler capable of being run on Intel processors.
As root edit
/etc/apt/sources.list and add the following to the end of the file:
# # -- Emdebian cross toolchains # # deb http://www.emdebian.org/debian/ unstable main # deb http://www.emdebian.org/debian/ testing main deb http://www.emdebian.org/debian/ lenny main
Now we need to tell apt to use this new repo':
sudo apt-get install emdebian-archive-keyring sudo apt-get update
Finally we can install the GCC, G++ cross compilers and support programs
sudo apt-get install libc6-armel-cross libc6-dev-armel-cross sudo apt-get install binutils-arm-linux-gnueabi sudo apt-get install gcc-4.3-arm-linux-gnueabi sudo apt-get install g++-4.3-arm-linux-gnueabi sudo apt-get install uboot-mkimage sudo apt-get install apt-cross dpkg-cross sudo apt-get install libncurses5-dev
sudo apt-get install gcc-4.3-arm-linux-gnueabimay fail to load with a dependancy mismatch. In which case use the 4.2 versions of gcc and g++.
Thanks to Geert Vancompernolle for reporting that the 4.3 versions install under Ubuntu 9.10.
If you plan on cross compiling non-kernel code also add the following:
sudo apt-get install linux-libc-dev-armel-cross
(Thanks to Doug Gilbert for this one.)
As of writing this page (Jan 2010) the latest stable Linux kernel is linux-22.214.171.124 and can be found in the usual home for all Linux kernels: http://kernel.org/
Download and extract the kernel:
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-126.96.36.199.tar.bz2 tar -xvjf linux-188.8.131.52.tar.bz2
Although a recent unpatched kernel will work on your Netus it will not be able to access all the hardware. Nor is it simple to cross compile and generate the correct bootable kernel image. To overcome these issues download extract these patches to your new linux source dirrector and apply them: linux-184.108.40.206-foxg20-patches-v5.txt
cd linux-220.127.116.11 patch -p1 < linux-18.104.22.168-foxg20-patches-v5.txt
If you are building a kernel with just the minimal features (perhaps for a specialist hardward project) I recommend you start with
netus.config-22.214.171.124-SIMPLE and add to it as required as this will avoid the time required to build unused modules:
cp foxg20.config-126.96.36.199-SIMPLE.txt .config
If you are building a full featured system (like a desktop system) and you want access to a wide range of kernel modules start with
cp foxg20.config-188.8.131.52-COMPLEX-v3 .config
Whichever config you choose you must now configure it:
Once you are happy with your kernel configuration you can build a new kernel with:
and if you require modules:
make modules make modules_install
Note that modules are not installed but rather all copied to the
./FoxModules sub-directory. If you don't want old modules you've build before then instead of that last line do:
rm -rf ./FoxModules make modules_install
If you have already followed the steps in Debian on the FOX Board G20 you can:
On the first FAT16 partition labeled kernel you need to copy also the file foxg20-script.bin read this article to read how to generate it: Create foxg20-script.bin u-Boot environment file.
If you have already have your Netus running Debian you can upgrade the kernel without removing the microSD card.
First become root on the Netus and:
mount /dev/mmcblk0p1 /mnt
Now copy uImage from your build machine to /mnt on your Netus. I use scp (your IP details might vary):
scp uImage firstname.lastname@example.org:/mnt/uimage
Now on back on your Netus:
sync umount /mnt
Copy your module tree from your build machine's FoxModules/lib to the Netus:
rsync -avc FoxModules/lib/. email@example.com:/lib/.
If it doesn't work install rsync on the FOX with the command:
apt-get install rsync
Back to the Netus again to update the module dependencies:
Finally reboot the Netus to load the new kernel.
Debian comes with a useful tool for systems installers called
debootstrap that eases creating your initial root file store.
debootstrap (in case it's not yet installed on your Ubuntu distro), type:
sudo apt-get install debootstrap
debootstrap is usually run in two stages. The first stage is on a working Debian (or Ubuntu) machine to create a very basic area. The second stage is run on the target machine (in this case your Netus) to fill in that area.
The steps are detailed and minor mistakes can lead to an unbootable system or a system that is highly unreliable.
To make life easier you can use this shell script: gen_root3.sh
There are some settings at the start of the script that you may want to change. In particular:
# Where to get Debian files from - pick one local to you! url=http://ftp.uk.debian.org/debian
You can find the official list of alternate mirrors here: http://www.debian.org/mirror/list
# This MUST match the version of the kernel you are using on your target kernel_version=184.108.40.206
# Either set eth=static and then also address, netmask and gateway # OR set eth=dhcp # Comment out which ever you are NOT using # Target machine network details eth=static address=192.168.1.90 netmask=255.255.255.0 gateway=192.168.1.1 #eth=dhcp
gen_root3.sh has to be run as root (it is a requirement of debootstrap):
When the script runs, it will create the sub-directory
armel-root in the Linux directory and will copy the first stage bootstrap files in there.
Once completed, you need to copy the contents of the directory
armel-root to the root area of your microSD. If your microSD card uses the recommended Debian layout and is mounted in your (Debian/Ubuntu) host then you can copy it with:
sudo cp -rp armel-root/. /media/rootfs sync
As with all large microSD operations the
cp may complete almost instantly - because the files are still being copied over by Linux. Then
sync will take a long time as it waits for the files to really appear on the microSD.
Now unmount your microSD card, transfer it to your Netus and boot.
Depending on your network connection (and the speed/load of the Debian repository) stage2 can take 30 minutes or more to complete. At which time the Netus will reboot automatically into multi-user Debian.
You can login as root with no password.
I STRONGLY advise that your first steps are to set a root password (the Netus root password used elsewhere is
netusg20) and then to run:
apt-get update apt-get install locales dpkg-reconfigure locales
At the very least this will stop
perl (and everything that uses perl) from complaining about locale issues!
apt-get install locales-all
before running dpkg-reconfigure.
: installing locales-all takes a long time - at least 15 minutes!
You now have a basic Debian system running. I suggest you run:
apt-get install ntpdate
and then follow the steps outlined in first_debian_boot
The above instructions generate a root filestore for Debian Lenny which is the current stable Debian distribution. However some of you might want to try the more up-to-date but more experimental Debian Squeeze (also called Testing) instead. To do so use this alternative version of my gen root script: gen_root4_squeeze.sh but otherwise follow the same instructions.
Depending on what you plan to use your Fox for you may need the on-chip hardware watchdog to work under Linux and with the default setup it does not.
The keen eyed of you will have spotted that the kernel prints the following as it boots:
sorry, watchdog is disabled
This is because before Linux starts the watchdog has already been disabled by the bootstrap.
The hardware watchdog on the AT91SAM9G20 can only be configured once. Added to that on power-on the watchdog is set to fire after about 16 seconds and force a reboot. So the standard at91bootstrap disables the watchdog to prevent it from causing problems while booting. Also the most recent versions of u-boot also either configure or disable the watchdog for the same reason.
So for Linux to control the watchdog we need to replace the on flash at91bootstap and u-boot. To do that download this tar archive:
and extract the contents. Then follow the instructions on Restore the Netus dataflash content but using the at91bootstrap.bin and u-boot.bin from the tar archive.
In addition to not touching the watchdog these versions are also faster than the originals and as the FOX boots the red led will flash once at the three key stages of the bootstrap (start, Linux loading start, switching to Linux) and on an error will flash rapidly for one second.