Difference between revisions of "Linux Development for XScale modules"

From Compulab Mediawiki
Jump to: navigation, search
(Networked Root Filesystem)
(Building the Linux kernel for XScale modules)
Line 138: Line 138:
 
There may be cases when default kernel for device does not fit your system requirements and you would like to build your own kernel. Both EM-X270 and CM-X270 platforms are supported by vanilla kernel starting from version 2.6.23 and 2.6.24 respectively. Yet, the support present there is incomplete and does not include several features. This features can be enabled if you apply EM-X270 (or CM-X270) patchset to vanilla kernel and make proper kernel configuration.
 
There may be cases when default kernel for device does not fit your system requirements and you would like to build your own kernel. Both EM-X270 and CM-X270 platforms are supported by vanilla kernel starting from version 2.6.23 and 2.6.24 respectively. Yet, the support present there is incomplete and does not include several features. This features can be enabled if you apply EM-X270 (or CM-X270) patchset to vanilla kernel and make proper kernel configuration.
  
Keep in mind that to build Linux kernel for CM-X270 and EM-X270 you need cross-compilation toolchain and for EM-X270 you will also need '''mkimage''' utility from [http://www.denx.de/wiki/UBoot/WebHome U-Boot].
+
Keep in mind that to build Linux kernel for CM-X270 and EM-X270 you need cross-compilation toolchain and for EM-X270 you will also need {{cmd|1=mkimage}} utility from [http://www.denx.de/wiki/UBoot/WebHome U-Boot].
  
 
Below is a brief description of Linux kernel build process for CompuLab Xscale modules along with an example commands sequence.
 
Below is a brief description of Linux kernel build process for CompuLab Xscale modules along with an example commands sequence.
Line 166: Line 166:
 
</pre>
 
</pre>
  
In the above example, the Linux kernel image (''uImage'') will be created in ''/home/development/em-x270/kernel/linux-2.6.23/arch/arm/boot'', and the loadable kernel modules will be installed into the ''/home/development/em-x270/rootfs/lib/modules'' directory.
+
In the above example, the Linux kernel image ({{filename|1=uImage}}) will be created in {{filename|1=/home/development/em-x270/kernel/linux-2.6.23/arch/arm/boot}}, and the loadable kernel modules will be installed into the {{filename|1=/home/development/em-x270/rootfs/lib/modules}} directory.
  
Now, if you boot EM-X270 with newly created kernel image and with networked root filesysem at ''/home/development/em-x270/rootfs/'' the system will be able to properly load kernel modules and you avoid modules versioning problems.
+
Now, if you boot EM-X270 with newly created kernel image and with networked root filesysem at {{filename|1=/home/development/em-x270/rootfs/}} the system will be able to properly load kernel modules and you avoid modules versioning problems.
  
 
=== Building the Linux kernel for CM-X270 ===
 
=== Building the Linux kernel for CM-X270 ===
Line 187: Line 187:
 
</pre>
 
</pre>
  
In the above example, the Linux kernel image (''zImage'') will be created in ''/home/development/em-x270/kernel/linux-2.6.16/arch/arm/boot'', and the loadable kernel modules will be installed into the ''/home/development/cm-x270/rootfs/lib/modules'' directory.
+
In the above example, the Linux kernel image ({{filename|1=zImage}}) will be created in {{filename|1=/home/development/cm-x270/kernel/linux-2.6.16/arch/arm/boot}}, and the loadable kernel modules will be installed into the {{filename|1=/home/development/cm-x270/rootfs/lib/modules}} directory.
  
Now, if you boot CM-X270 with newly created kernel image and with networked root filesysem at ''/home/development/cm-x270/rootfs/'' the system will be able to properly load kernel modules and you avoid modules versioning problems.
+
Now, if you boot CM-X270 with newly created kernel image and with networked root filesysem at {{filename|1=/home/development/cm-x270/rootfs/}} the system will be able to properly load kernel modules and you avoid modules versioning problems.
  
 
== OE installation ==
 
== OE installation ==

Revision as of 15:31, 6 March 2008

Cross-Compilation

In the embedded world, software development is almost always done on a system other than the one on which the software will eventually run. It is common nowadays to use x86 desktop workstations to develop software for ARM-based embedded products. Such an approach requires cross-compilation tools and environment.

Building a cross compiler became recently relatively simple thanks to such tools as crosstool. But working cross-compiler is not enough. Modern applications rely on variety of libraries, frameworks and utilities. All these has to be cross-compiled also. Most Linux and Open Source software projects use a configure script to configure their software for compilation. Configure is meant to ease configuring the software for compilation and its default assumption is that the software will be run in the same environment and processor in which it was compiled and run from the place in which it was installed. The second problem of many configure scripts, is that most application developers don't take cross-compilation into account, so configure ends up cross-compiling test code and trying to run it on the build host, which breaks the configuration. Thus, cross compilation tools are not enough for embedded application development and complete cross-development environment is required.

Nowadays, there are several popular cross-development environments: Scratchbox, OpenEmbedded, it's spin-off Poky Linux, and Embedded Linux Development Kit.

Scratchbox

Scratchbox is a chrooted cross-compilation environment. This means one has to log into the Scratchbox like one would log into a real machine. Once you logged in, you develop your application as if you were developing it on native ARM machine, but with computational power of modern x86 workstation.

OpenEmbedded

OpenEmbedded is a development environment allowing users to target a wide variety of devices and configurations. OpenEmbedded enables you to build an entire Linux distribution optimized for specific device needs. Additionally, it includes devshell addon that provides you with an interactive shell with all the appropriate variables set for cross-compiling.

Poky Linux

Poky is an embedded Linux build system, distribution and developer environment which builds upon OpenEmbedded technologies. It is less generic than OpenEmbedded, but on the other side, you may find it more tuned and optimized for such devices as PDAs and smartphones.

ELDK

Embedded Linux Development Kit (ELDK) is a collection of GNU cross development tools, such as compilers, binutils, gdb, etc., and a number of pre-built target tools and libraries necessary to provide some functionality on the target system. It is not full-featured cross-development environment like Scratchbox, OpenEmbedded, or Poky, but it is known to have stable and reliable cross compilation tools.

Networked Root Filesystem

It is convenient to use the same filesystem on host workstation and target device. Because the filesystem exists on the workstation, it is easy to use it for cross-development. And because the workspace is mounted on the target device also, we can test code developed on the host by running it on the target device.

The host workstation need to have NFS server packages installed. The package name depends on the distribution you use:

Ubuntu/Debian

apt-get install nfs-kernel-server nfs-common portmap

Fedora Core

yum install nfs-utils

Gentoo

emerge -av nfs-utils

After the NFS tools are installed on the host workstation, you can use images/angstrom-em-x270.tar.bz2 from EM-X270 Linux package and disk.dat from CM-X270 Linux package for networked root filesystem. For EM-X270 just extract the archive to some directory:

mkdir /home/development/em-x270/rootfs
cd /home/development/em-x270/rootfs
tar xjf /path/to/em-x270-package/images/angstrom-em-x270.tar.bz2

or copy disk.dat contents to appropriate directory for CM-X270:

mkdir /home/development/cm-x270/rootfs
mount –t ext3 –o loop /path/to/disk.dat /tmp/cm_x270_mount
cp -a /tmp/cm_x270_mount/* /home/development/cm-x270/rootfs

Afterwards add this directory to /etc/exports:

/home/development/em-x270/rootfs \
        192.168.0.0/255.255.255.0(no_root_squash,sync,rw)

and make the NFS server export this directory:

/usr/sbin/exportfs -a

Linux kernel has Root on NFS feature, allowing mounting root filesystem form a server rather than from local storage device. Default kernels shipped by CompuLab have this feature built in. If you are planing to use custom kernel you can enable Root on NFS as follows: in the kernel configuration choose "Networking -> Networking Options" menu and enable "IP: kernel level autoconfiguration"

  +-------------------------- Networking options ---------------------------+
  |  Arrow keys navigate the menu.  <Enter> selects submenus --->.          |
  |  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes, |
  |  <M> modularizes features.  Press <Esc><Esc> to exit, <|> for Help, </> |
  |  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >       |
  | +---------------------------------------------------------------------+ |
  | |    [ ] Network packet debugging                                     | |
  | |    <*> Packet socket                                                | |
  | |    [ ]   Packet socket: mmapped IO                                  | |
  | |    <*> Unix domain sockets                                          | |
  | |    < > Transformation user configuration interface                  | |
  | |    [ ] Transformation sub policy support (EXPERIMENTAL)             | |
  | |    < > PF_KEY sockets                                               | |
  | |    [*] TCP/IP networking                                            | |
  | |    [ ]   IP: multicasting                                           | |
  | |    [ ]   IP: advanced router                                        | |
  | |    [*]   IP: kernel level autoconfiguration                         | |
  | |    [*]     IP: DHCP support (NEW)                                   | |
  | |    [*]     IP: BOOTP support (NEW)                                  | |
  | |    [ ]     IP: RARP support (NEW)                                   | |
  | |    < >   IP: tunneling                                              | |
  | |    < >   IP: GRE tunnels over IP                                    | |
  | |    [ ]   IP: ARP daemon support (EXPERIMENTAL)                      | |
  | |    [ ]   IP: TCP syncookie support (disabled per default)           | |
  | +----v(+)-------------------------------------------------------------+ |
  +-------------------------------------------------------------------------+
  |                    <Select>    < Exit >    < Help >                     |
  +-------------------------------------------------------------------------+

Afterwards choose "File Systems -> Network File Systems" menu and enable NFS options:

  +------------------------- Network File Systems --------------------------+
  |  Arrow keys navigate the menu.  <Enter> selects submenus --->.          |
  |  Highlighted letters are hotkeys.  Pressing <Y> includes, <N> excludes, |
  |  <M> modularizes features.  Press <Esc><Esc> to exit, <|> for Help, </> |
  |  for Search.  Legend: [*] built-in  [ ] excluded  <M> module  < >       |
  | +---------------------------------------------------------------------+ |
  | |    <*> NFS file system support                                      | |
  | |    [*]   Provide NFSv3 client support                               | |
  | |    [ ]     Provide client support for the NFSv3 ACL protocol extensi| |
  | |    [ ]   Provide NFSv4 client support (EXPERIMENTAL)                | |
  | |    [*]   Allow direct I/O on NFS files                              | |
  | |    <M> NFS server support                                           | |
  | |    [*]   Provide NFSv3 server support                               | |
  | |    [ ]     Provide server support for the NFSv3 ACL protocol extensi| |
  | |    [ ]     Provide NFSv4 server support (EXPERIMENTAL)              | |
  | |    [*]   Provide NFS server over TCP support                        | |
  │ │    [*]   Root file system on NFS                                    │ │
  | +----v(+)-------------------------------------------------------------+ |
  +-------------------------------------------------------------------------+
  |                    <Select>    < Exit >    < Help >                     |
  +-------------------------------------------------------------------------+

After the kernel is built it can be loaded with

root=/dev/nfs nfsroot=<serverip>:/path/to/nfsroot

options and access the filesystem on the host workstation and used for software development. More information about how to use NFS root can be found in Documentation/nfsroot.txt in the Linux kernel source tree.

Building the Linux kernel for XScale modules

There may be cases when default kernel for device does not fit your system requirements and you would like to build your own kernel. Both EM-X270 and CM-X270 platforms are supported by vanilla kernel starting from version 2.6.23 and 2.6.24 respectively. Yet, the support present there is incomplete and does not include several features. This features can be enabled if you apply EM-X270 (or CM-X270) patchset to vanilla kernel and make proper kernel configuration.

Keep in mind that to build Linux kernel for CM-X270 and EM-X270 you need cross-compilation toolchain and for EM-X270 you will also need mkimage utility from U-Boot.

Below is a brief description of Linux kernel build process for CompuLab Xscale modules along with an example commands sequence.

  • Download Linux kernel source from preferred mirror
  • Unpack it to some directory
  • Apply EM-X270 or CM-X270 patchset
  • Set environment variables ARCH, and CROSS_COMPILE so that kernel build system cross compile the kernel
  • Build the kernel, and modules
  • Install the modules

Building the Linux kernel for EM-X270

mkdir /home/development/em-x270/kernel
cd /home/development/em-x270/kernel
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.23.tar.bz2
tar xjf linux-2.6.23.tar.bz2
cd linux-2.6.23
cat /path/to/x270em-linux-img/kernel/linux-2.6.23-em-x270.patch | patch -p1
export ARCH=arm
export CROSS_COMPILE=arm-linux-
make em_x270_defconfig
make menuconfig
make && make uImage && \
     INSTALL_MOD_PATH=/home/development/em-x270/rootfs make modules_install

In the above example, the Linux kernel image (uImage) will be created in /home/development/em-x270/kernel/linux-2.6.23/arch/arm/boot, and the loadable kernel modules will be installed into the /home/development/em-x270/rootfs/lib/modules directory.

Now, if you boot EM-X270 with newly created kernel image and with networked root filesysem at /home/development/em-x270/rootfs/ the system will be able to properly load kernel modules and you avoid modules versioning problems.

Building the Linux kernel for CM-X270

mkdir /home/development/cm-x270/kernel
cd /home/development/cm-x270/kernel
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.tar.bz2
tar xjf linux-2.6.16.tar.bz2
cd linux-2.6.16
cat /path/to/x270cm-linux-drv/2.6.16/linux-2.6.16-cm-x270.patch | patch -p1
export ARCH=arm
export CROSS_COMPILE=arm-linux-
make cm_x270_defconfig
make menuconfig
make && \
     INSTALL_MOD_PATH=/home/development/cm-x270/rootfs make modules_install

In the above example, the Linux kernel image (zImage) will be created in /home/development/cm-x270/kernel/linux-2.6.16/arch/arm/boot, and the loadable kernel modules will be installed into the /home/development/cm-x270/rootfs/lib/modules directory.

Now, if you boot CM-X270 with newly created kernel image and with networked root filesysem at /home/development/cm-x270/rootfs/ the system will be able to properly load kernel modules and you avoid modules versioning problems.

OE installation

Angstrom Linux images for EM-X270 are built with OpenEmbedded development environment. If you would like to build custom image you need to install the OpenEmbedded environment. Getting Started page of OpenEmbedded documentation describes the installation process.

Here we assume that you followed the Getting Started instructions and you have the same directory structure.

After you completed the installation of OpenEmbedded, you need to configure it to be able to build images for EM-X270. Recent versions of OpenEmbedded support EM-X270 and the only thing you need is to place local.conf from CompuLab package to /stuff/build/conf/local.conf:

cp -r /path/to/x270-em-linux/oe/build/conf/local.conf /stuff/build/conf

Another possibility is to use all OpenEmbedded related files from [CompuLab Linux package for EM-X270:

cp -r /path/to/x270-em-linux/oe/* /stuff/

Now you are ready to build Linux images for EM-X270:

cd /stuff/build
bitbake x11-image

After some time the image will be created and put into /stuff/build/tmp/deploy/glibc/images/em-x270 directory. Default configuration creates two types of images: tar, and jffs2. The jffs2 image can be transfered to the EM-X270 on-board NAND flash. The tar archive can be extracted to some directory on the host workstation, and this directory can be used as networked root filesystem for the device.