Phytec phyCORE-iMX35/Gentoo/Desktop

Cross-compiling Linux kernel and root file system for Phytec phyCORE-i.MX35 with portage. The root file system for a simple desktop system is created.

About this tutorial
This tutorial will show you step by step how to cross-compile the Linux kernel and cross-emerge the whole root file system for the board Phytec phyCORE-i.MX35. Portage is used to install and build all the software packages. All software packages are taken from the gentoo portage tree together with the embedded-cross overlay.

Cross-compilation is done in a chroot environment. The chroot environment is set up in order to be independent from the main root folder and protect it. Because cross-compilation or cross-emerge need specific overlays, package versions or configurations, it is better to use a separate chroot environment for it.

After the kernel and the root file system have been built on the host system, the target is booted as a diskless system. The bootloader u-boot loads the Linux kernel from a TFTP server. The Linux kernel mounts the root files system via NFS.

In this example the size of the created root file system is about 250MB, when the profile is used. The sizes of the folders and  are not taken into account.

The portage tree and the overlays are shared among host, build and target system.

For some problems which occured, simple workarounds are presented. Any hints or improvements are welcome.

Last time the commands have been tested: 2010.10.06

Important docs or information
http://www.gentoo.org/proj/en/base/embedded/handbook/

http://www.gentoo.org/proj/en/overlays/userguide.xml

Prepare the installation
Login as root

Check the current settings

Set path macros. Here: use root folder

The current settings are defined as environment host

Move the portage tree
Usally the gentoo portage tree is in the folder and the overlays of layman are in. In order to share the portage tree and overlays with the chroot environment and the target system, the folders need to be mounted. Therefore is moved to  and  to. Then only the folder needs to be mounted by the chroot environment or the target system. You can move other overlays to too.

Move portage tree

Adjust configuration file make.conf. Define PORTDIR and DISTDIR.

The link make.profile should point now into /MyPortageTree/portage/profiles

Move layman storage
If you are already using layman, you have to move the layman storage too.

Adjust configuration file make.conf. Don't use layman/make.conf anymore. Change PORTDIR_OVERLAY accordingly.

Change layman settings

Prepare etc/portage folder
Which package.* are still files.

Replace package.* files by folders

Install layman on your system
If layman is not yet installed, define use flags for layman

Emerge layman

Workaround for problem with dev-perl/DBD-SQLite-1.29-r2
This problem has still been encountered on 2010.10.06

When you emerge layman you could get the error message:

emerge: there are no ebuilds built with USE flags to satisfy ">=dev-db/sqlite-3.6.22[extensions]".!!! One of the following packages is required to complete your request: - dev-db/sqlite-3.6.23.1 (Change USE: +extensions) This problem occurs even when USE flag extensions is defined for sqlite.

This problem occurs when dev-perl/DBD-SQLite-1.29- r2 is emerged.

This problem doesn't occur when dev-perl/DBD-SQLite-1.29 or dev-perl/DBD-SQLite-1.14 are emerged.

It seems that $PORTDIR/portage/dev-perl/DBD-SQLite/DBD-SQLite-1.29- r2 .ebuild is missing inheritance from eutils.

Solution: 

Mask this version of DBD-SQLite.

Try to emerge layman again.

Configure layman
Change layman storage

Load overlay embedded-cross

Install terminal application
You can use the terminal application minicom to connect to the serial port of the target.

Or you can use the application cu to connect to the serial port of the target.

Create host system for cross-compilation
Set path macros. Here: don't use your real root folder!

/MyDevelop/host-phyCORE-iMX35 is the folder where the new root file system for chroot is prepared.

The current settings are defined as environment build_prepare

Create root directory for new Linux root file system

Create portage config directory

Change file

Keep your settings of

CFLAGS CXXFLAGS CHOST GENTOO_MIRRORS MAKEOPTS VIDEO_CARDS INPUT_DEVICES LINGUAS ACCEPT_LICENSE

Prepare etc/portage folder
Which links should be created

Create links

Check current settings. Folder tmp, var are created.

Check which packages would be installed

Check which packages would be installed from the embedded-cross overlay

Emerge system, e.g. gcc, python and portage are installed.

Install pkgconfig, setuptools and less, if they have not yet been installed

Install glib on the host, when you want to install syslog-ng on the target

Install gentoolkit, if you like to use equery

Install layman on your system
Define use flags for layman

Emerge layman

Configure layman
Change layman storage

Prepare host for chroot into build system
only once

Copy over nameserver information

Define the timezone

Create folders, if they don't exist

Create folders

Change prompt to reflect that you are in a chroot environment. Add string 'chroot' to PS1.

Prepare host for chroot into build system
Each time you want to use chroot.

/MyPortageTree is the location of the portage tree and overlays in your real root file system.

Change root to the build system
Set path macros, here: use root folder

'''You are now in your build system. Your real root is protected now.'''

The current settings are defined as environment build

Check what is already installed

Create locale

Emerge and build cross compiler
Set keywords

Emerge crossdev

Check which package versions crossdev will use

Check if overlay is used

cross-arm-unknown-linux-gnueabi/binutils-2.18- r4

cross-arm-unknown-linux-gnueabi/gcc-4.4.3

cross-arm-unknown-linux-gnueabi/linux-headers-2.6.35

cross-arm-unknown-linux-gnueabi/glibc-2.11.2

Create cross-compiler

Check cross-emerge settings
crossdev calls emerge-wrapper. emerge-wrapper copies the folder /usr/share/crossdev/etc into /usr/arm-unknown-linux-gnueabi.

Adjust the contents of make.conf

Check cross-emerge info

Check if SYSROOT=/usr/arm-unknown-linux-gnueabi

Check ROOT, PORTAGE_CONFIGROOT

Default settings of compilers are in

Show installed overlays

Which ebuilds are available

Install u-boot tools
The bootloader on the board is u-boot.

Prepare usage of cross-compiler
Each time you want to use it.

The current settings are defined as environment cross

Prepare etc/portage folder
Edit make.conf and replace it completely by the text below

Add also the definitions of other macros to this file, like MAKEOPTS and GENTOO_MIRRORS.

Define make.profile

Which links should be created

Create links

Edit file openmoko-local-mask

Edit file openmoko-local-keywords

Now you can build the kernel or the root file system.You may skip building the kernel and start with building the root file system

Linux kernel
IMPORTANT: read how to cross compile the Linux kernel: http://www.gentoo.org/proj/en/base/embedded/handbook/?part=1

Emerge kernel sources
Switch to environment cross

Emerge kernel sources:

Build kernel
Switch to environment cross

Define macro

The current settings are defined as environment cross_kernel

Create the config file This .config file has been used /Config

Build kernel and modules, install modules

Modules are installed into

Create kernel which can be loaded by the bootloader u-boot

The image is

Build root file system
Switch to environment cross

Emerge all packages, which are needed:

Workaround for problem with mpfr
Still needed on 2010.10.06.

When dev-libs/mpfr is built you get the error message:

/usr/lib/libgmp.so: could not read symbols: File in wrong format

Check the file type

/usr/lib/libgmp.so.3.5.2: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, stripped Check the file type

/usr/arm-unknown-linux-gnueabi/usr/lib/libgmp.so.3.5.2: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked, stripped /usr/arm-unknown-linux-gnueabi/usr/lib/libgmp.so is the library which should be linked

You can change the libdir path manually or with the tool cross-root-fix:

Change the libdir path in the libgmp.la file manually:

Use cross-root-fix to change the libdir path

Resume

Prepare portage config files
Change ROOT and remove CBUILD in make.conf.

Prepare target root file system
Create /dev/console. If /dev/console doesn't exist, you get the error message when you boot the board: Warning: unable to open an initial console.

Check and configure the init scripts. Ignore the error messages about broken runlevel entries.

Enable remote login through ssh

Enable system log

bash needs libgcc

Adjust inittab

eth0 is already configured.

Adjust fstab

Create mount point

Define the timezone

To disable the root password, just delete the 'x'. This is needed for the first login, because the password is not yet defined.

Allow root login on serial port:

Create folders, if they don't exist

Workaround for user sshd
User and group sshd is not defined.

Edit file passwd

Leave chroot environment
Each time you want to leave chroot.

You have left the chroot environment now!

Unmount folders
If you don't want to chroot again, you should unmount the folders, which have been used by chroot. If you will chroot again, you can leave these folders mounted

You are back in environment host

Server
Switch to environment host

Configure tftp server
Setup tftp server

Start the tftp server

Configure nfs server
Setup nfs server. is the root file system for the target. is the folder which contains the portage tree and the overlays.

Start the nfs server

Kernel image for u-boot
Copy the kernel image into the tftp folder

Configure u-boot
Connect to the board. Use the top serial port. Baud rate is 115200 8N1. You can use the terminal application minicom

Or you can use the application cu to connect to the board.

Note: When I use cu, I get only the output from the target. No characters are sent to the target. Therefore I am using minicom.

Reset the board. Enter the command line of u-boot. Change the u-boot config file.

Save the file and leave the editor:

Save the environment

Connect the ethernet cable to the board and boot the board

Now u-boot should load via tftp the Linux kernel and mount via nfs the root file system. After a short time you should be able to login as root.

This is the output during startup /Target_Log.

Login
At first you use the console to login as root and set the password

Now you may use a ssh client to connect via ethernet to the board.

Check time and date and change it if necessary.

When you want to stop the target

This is the output of simple commands /Target_Log.

Environments
This is an overview of the features of the different environments which are used. Afterwards the commands are shown, which are needed to switch from one environment to the other.

Environment host
Features of the environment: host

System: Host_X

ROOT=

PORTAGE_CONFIGROOT=

PORTDIR=

DISTDIR=

PORTDIR_OVERLAY is not defined

SYSROOT is not defined

In file

storage  :

Emerge command: emerge --info -v

Commands which work and use

etc-update

rc-update</tt>

Exectute commands in : yes

NFS server:

export root fs:

export portage tree and overlays:

TFTP server:

provide the kernel image

IP Address:

Environment build_prepare
Features of the environment: build_prepare

System: Host_X

ROOT=

PORTAGE_CONFIGROOT=

PORTDIR=

DISTDIR=

PORTDIR_OVERLAY=

SYSROOT is not defined

In file

storage  :

Emerge command: emerge --info -v</tt>

Commands which work and use

etc-update</tt>

rc-update</tt>

Exectute commands in : no

Environment build
Features of the environment: build

System: Host_X

chroot:

ROOT=

PORTAGE_CONFIGROOT=

PORTDIR=

DISTDIR=

PORTDIR_OVERLAY=

SYSROOT is not defined

In file

storage  :

Emerge command: emerge --info -v</tt>

Commands which work and use

etc-update</tt>

rc-update</tt>

Exectute commands in : yes

Environment cross
Features of the environment: cross

System: Host_X

chroot:

ROOT=

PORTAGE_CONFIGROOT=

PORTDIR=

DISTDIR=

PORTDIR_OVERLAY=

SYSROOT is not defined

In file

storage  :

Emerge command: arm-unknown-linux-gnueabi-emerge --info -v</tt>

Commands which work and use

etc-update</tt>

rc-update</tt>

Exectute commands in : no

Environment cross_kernel
Features of the environment: cross_kernel

System: Host_X

chroot:

ROOT=

PORTAGE_CONFIGROOT=

PORTDIR=

DISTDIR=

PORTDIR_OVERLAY=

SYSROOT=

In file

storage  :

Emerge command: arm-unknown-linux-gnueabi-emerge --info -v</tt>

Commands which work and use

etc-update</tt>

rc-update</tt>

Exectute commands in : no

Environment target
Features of the environment: target

System: Target_Y

nfs root: mount root via nfs from Host_X

nfs portage: mount portage tree and overlays via nfs from Host_X

ROOT=

PORTAGE_CONFIGROOT=

PORTDIR=

DISTDIR=

PORTDIR_OVERLAY=

SYSROOT is not defined

In file

storage  :

Emerge command: emerge --info -v</tt>

Commands which work and use

etc-update</tt>

rc-update</tt>

Exectute commands in : yes

IP Address:

NFS server of root fs and portage tree IP Address:

Start with environment host
The commands which are needed, to start with the environment host. Find further explanations above.

Switch from environment host to build_prepare
The commands which are needed, to switch from environment host to build_prepare. Find further explanations above.

Switch from environment host to build
The commands which are needed, to switch from environment host to build. Find further explanations above.

Switch from environment build to cross
The commands which are needed, to switch from environment build to cross. Find further explanations above.

Switch from environment cross to cross_kernel
The commands which are needed, to switch from environment cross to cross_kernel. Find further explanations above.

Switch from environment cross to host
The commands which are needed, to switch from environment cross to host. Find further explanations above.

Other useful information
http://gentoo.mindzoo.de/index.cgi/wiki

http://gitorious.org/gentoo-arm-overlay

http://git.overlays.gentoo.org/gitweb/

Target Logs
Boot Log: Output when the board is booted and Linux is started..

Simple Commands: Output of some simple commands executed on the target.