Personal tools

Log in

Changes

From IGEP - ISEE Wiki

Jump to: navigation, search

How to setup a development environment

20,369 bytes added, 12:18, 23 March 2010
creation of the page, first writes...
This tutorial was written for the [http://www.igep-platform.com/index.php?option=com_content&view=article&id=46&Itemid=55 ''igep revB''] board, but it is transposable to other ''OMAP3530'' boards (above all for the ''DSP'' part). It is a summary (with some adaptations) of several tutorials found on Internet (see [[How_to_setup_a_development_environment#References|References]]). All files will be installed in the $HOME directory.

This tutorial is a translation of a French tutorial we wrote on our robotic [http://as.tech.free.fr/wiki/index.php?title=Cr%C3%A9er_un_environnement_de_d%C3%A9veloppement_pour_l%27OMAP3530 web site]. Sorry for the English, fill free to correct mistakes.

= ''Rootfs'' =

This section describes how to obtain the [http://www.pokylinux.org/ ''Poky''] distribution. This is the distribution shipped with the ''igep'' boad; it is based on [http://wiki.openembedded.net/index.php/Main_Page ''Open Embedded''].

The first thing to do is set ''Bash'' as default ''sh'' ''shell'':

<pre>
sudo dpkg-reconfigure dash
</pre>

answer no to the question. Thus, "/bin/sh" will point towards "/bin/bash" (and not "/bin/dash"). Then, some kernels settings have to be changed. Edit the file "/etc/sysctl.conf" as ''root'' and set :

<pre>
vm.mmap_min_addr = 0
</pre>
then, to take the modification into account:
<pre>
sudo sysctl -p
</pre>

Some additional packages need to be installed to satisfy ''bitbake'' dependencies. First, add the following repositories to "/etc/apt/sources.list" :
<pre>
deb http://debian.o-hand.com etch/
deb http://debian.o-hand.com unstable/
deb http://debian.o-hand.com feisty/
deb http://debian.o-hand.com gutsy/
deb http://debian.o-hand.com hardy/
</pre>
Update the data base and install the following packages:
<pre>
sudo apt-get update
sudo aptitude install python-psyco hgsvn qemu poky-depends poky-scripts
</pre>
<!--
a priori ceci est automatiquement installé :
sudo aptitude install subversion cvs git-core \
build-essential help2man diffstat texi2html texinfo \
libncurses5-dev gawk python-dev python-psyco python-pysqlite2 \
scrollkeeper gnome-doc-utils gettext automake hgsvn qemu poky-depends poky-scripts
-->
Then, download and decompress the last stable version of ''Poky'':

<pre>
mkdir -p $HOME/igep/poky
cd $HOME/igep/poky
wget http://pokylinux.org/releases/poky-purple-3.2.tar.bz2
tar -xjf poky-purple-3.2.tar.bz2
</pre>

The configuration file of ''Poky'' is located in the directory $HOME/igep/poky/build/conf :
<pre>
cd build/conf
nano local.conf
</pre>
And paste the modified version for the ''igep'' board:
<pre>
# Where to cache the files Poky downloads
DL_DIR ?= "${OEROOT}/sources"
BBFILES += "\
${OEROOT}/meta/packages/*/*.bb \
${OEROOT}/meta-moblin/packages/*/*.bb"

BBFILE_COLLECTIONS = "normal moblin"
BBFILE_PATTERN_normal = "^${OEROOT}/meta/"
BBFILE_PATTERN_moblin = "^${OEROOT}/meta-moblin/"

BBFILE_PRIORITY_normal = "5"
BBFILE_PRIORITY_moblin = "5"

# Uncomment and set to allow bitbake to execute multiple tasks at once.
# For a quadcore, BB_NUMBER_THREADS = "4", PARALLEL_MAKE = "-j 4" would
# be appropriate.
# BB_NUMBER_THREADS = "2"
# Also, make can be passed flags so it run parallel threads e.g.:
# PARALLEL_MAKE = "-j 2"

# The machine to target
MACHINE ?= "igep0020b"

TARGET_FPU_arm ?= "hard"

# Other supported machines
#MACHINE ?= "qemux86"
#MACHINE ?= "qemuarm"
#MACHINE ?= "c7x0"
#MACHINE ?= "akita"
#MACHINE ?= "spitz"
#MACHINE ?= "nokia770"
#MACHINE ?= "nokia800"
#MACHINE ?= "fic-gta01"
#MACHINE ?= "bootcdx86"
#MACHINE ?= "cm-x270"
#MACHINE ?= "em-x270"
#MACHINE ?= "htcuniversal"
#MACHINE ?= "mx31ads"
#MACHINE ?= "mx31litekit"
#MACHINE ?= "mx31phy"
#MACHINE ?= "netbook"
#MACHINE ?= "zylonite"

DISTRO ?= "poky"
# For bleeding edge / experimental / unstable package versions
# DISTRO ?= "poky-bleeding"

# Poky has various extra metadata collections (openmoko, extras).
# To enable these, uncomment all (or some of) the following lines:
# BBFILES = "\
# ${OEROOT}/meta/packages/*/*.bb \
# ${OEROOT}/meta-extras/packages/*/*.bb \
# ${OEROOT}/meta-openmoko/packages/*/*.bb \
# ${OEROOT}/meta-moblin/packages/*/*.bb \
# "
# BBFILE_COLLECTIONS = "normal extras openmoko moblin"
# BBFILE_PATTERN_normal = "^${OEROOT}/meta/"
# BBFILE_PATTERN_extras = "^${OEROOT}/meta-extras/"
# BBFILE_PATTERN_openmoko = "^${OEROOT}/meta-openmoko/"
# BBFILE_PATTERN_moblin = "^${OEROOT}/meta-moblin/"
# BBFILE_PRIORITY_normal = "5"
# BBFILE_PRIORITY_extras = "5"
# BBFILE_PRIORITY_openmoko = "5"
# BBFILE_PRIORITY_moblin = "5"

BBMASK = ""

# EXTRA_IMAGE_FEATURES allows extra packages to be added to the generated images
# (Some of these are automatically added to certain image types)
# "dbg-pkgs" - add -dbg packages for all installed packages
# (adds symbol information for debugging/profiling)
# "dev-pkgs" - add -dev packages for all installed packages
# (useful if you want to develop against libs in the image)
# "tools-sdk" - add development tools (gcc, make, pkgconfig etc.)
# "tools-debug" - add debugging tools (gdb, strace)
# "tools-profile" - add profiling tools (oprofile, exmap, lttng valgrind (x86 only))
# "tools-testapps" - add useful testing tools (ts_print, aplay, arecord etc.)
# "debug-tweaks" - make an image for suitable of development
# e.g. ssh root access has a blank password
# There are other application targets too, see meta/classes/poky-image.bbclass
# and meta/packages/tasks/task-poky.bb for more details.

EXTRA_IMAGE_FEATURES = "tools-debug tools-profile tools-testapps debug-tweaks"

# The default IMAGE_FEATURES above are too large for the mx31phy and
# c700/c750 machines which have limited space. The code below limits
# the default features for those machines.
EXTRA_IMAGE_FEATURES_c7x0 = "tools-testapps debug-tweaks"
EXTRA_IMAGE_FEATURES_mx31phy = "debug-tweaks"
EXTRA_IMAGE_FEATURES_mx31ads = "tools-testapps debug-tweaks"

# A list of packaging systems used in generated images
# The first package type listed will be used for rootfs generation
# include 'package_deb' for debs
# include 'package_ipk' for ipks
#PACKAGE_CLASSES ?= "package_deb package_ipk"
PACKAGE_CLASSES ?= "package_ipk"

# POKYMODE controls the characteristics of the generated packages/images by
# telling poky which type of toolchain to use.
#
# Options include several different EABI combinations and a compatibility
# mode for the OABI mode poky previously used.
#
# The default is "eabi"
# Use "oabi" for machines with kernels < 2.6.18 on ARM for example.
# Use "external-MODE" to use the precompiled external toolchains where MODE
# is the type of external toolchain to use e.g. eabi.
# POKYMODE = "external-eabi"

# Uncomment this to specify where BitBake should create its temporary files.
# Note that a full build of everything in OpenEmbedded will take GigaBytes of hard
# disk space, so make sure to free enough space. The default TMPDIR is
# <build directory>/tmp
TMPDIR = "${OEROOT}/build/tmp-${MACHINE}"


# Uncomment this if you are using the Openedhand provided qemu deb - see README
ASSUME_PROVIDED += "qemu-native"

# Comment this out if you don't have a 3.x gcc version available and wish
# poky to build one for you. The 3.x gcc is required to build qemu-native.
#ASSUME_PROVIDED += "gcc3-native"

# Uncomment these two if you want BitBake to build images useful for debugging.
# DEBUG_BUILD = "1"
# INHIBIT_PACKAGE_STRIP = "1"

# Uncomment these to build a package such that you can use gprof to profile it.
# NOTE: This will only work with 'linux' targets, not
# 'linux-uclibc', as uClibc doesn't provide the necessary
# object files. Also, don't build glibc itself with these
# flags, or it'll fail to build.
#
# PROFILE_OPTIMIZATION = "-pg"
# SELECTED_OPTIMIZATION = "${PROFILE_OPTIMIZATION}"
# LDFLAGS =+ "-pg"

# Uncomment this if you want BitBake to emit debugging output
# BBDEBUG = "yes"
# Uncomment this if you want BitBake to emit the log if a build fails.
BBINCLUDELOGS = "yes"

# Specifies a location to search for pre-generated tarballs when fetching
# a cvs:// or svn:// URI. Uncomment this, if you do not want to pull directly
# from CVS or Subversion
SRC_TARBALL_STASH = "http://pokylinux.org/sources/"

# Set this if you wish to make pkgconfig libraries from your system available
# for native builds. Combined with extra ASSUME_PROVIDEDs this can allow
# native builds of applications like oprofileui-native (unsupported feature).
#EXTRA_NATIVE_PKGCONFIG_PATH = ":/usr/lib/pkgconfig"
#ASSUME_PROVIDED += "gtk+-native libglade-native"

ENABLE_BINARY_LOCALE_GENERATION = "0"

# The architecture to build SDK items for, by setting this you can build SDK
# packages for architectures other than the host i.e. building i586 packages
# on an x86_64 host.
# Supported values are i586 and x86_64
SDKMACHINE="i586"
</pre>

The following section needs to be adapted to the number of CPU the host machine has:
<pre>
# Uncomment and set to allow bitbake to execute multiple tasks at once.
# For a quadcore, BB_NUMBER_THREADS = "4", PARALLEL_MAKE = "-j 4" would
# be appropriate.
# BB_NUMBER_THREADS = "2"
# Also, make can be passed flags so it run parallel threads e.g.:
# PARALLEL_MAKE = "-j 2"
</pre>

The build environment needs to be setup by the following command:
<pre>
cd ../..
source poky-init-build-env
</pre>
A target can be built using:
<pre>
bitbake <target>
</pre>
there is a lot of targets, which can be an image (take a look at the "meta/packages/images/" directory) or more simply a ''recipe'' corresponding to a software. A detailed list of images can be found on the [http://www.pokylinux.org/doc/poky-handbook.html#ref-images Poky Handbook]. To build an image without ''X11'' server:
<pre>
bitbake poky-image-base
</pre>

This step is very long (several hours) and take a lot of space (like 16 gigas) on the host's hard disk. If you are behind a ''proxy'', take a look at this [http://www.pokylinux.org/doc/poky-handbook.html#id3403214 part] of ''Poky's'' FAQ.

If everything compiles well, the resulting image (''rootfs'' and kernel) will be placed in the directory:
<pre>
tmp-igep0020b/deploy/images/
</pre>
and ''.ipk'' packages in:
<pre>
tmp-igep0020b/deploy/ipk/
</pre>

We will see in section [[How_to_setup_a_development_environment_for_OMAP3530#Boot_rootfs_and_kernel|''Boot'' on ''rootfs'' and kernel]] how to use it. Yet, ''bitbake'' will download by default the kernel "linux-omap-2.6.28.10-igep0020b-0" which is not the last one provided by ''ISEE''. See section [[How_to_setup_a_development_environment_for_OMAP3530#Kernel_compilation|Kernel compilation]] to compile another version.

TODO: modify ''recipes'' to download another kernel version

= Cross toolchain for the ''ARM''=

Aparently, there is a ''bug'' in one of ''Poky's'' ''recipes'', which implies that the cross toolchain doesn't include automatically the ''C++'' ''headers'', see [http://lists.o-hand.com/poky/1420.html this thread]. A ''patch'' has benn proposed; to apply it :
<pre>
cd $HOME/igep/poky
wget http://lists.o-hand.com/poky/att-1420/fix-gxx-include-dir.patch
patch -p1 < fix-gxx-include-dir.patch
</pre>

The cross toolchain can be built using ''bitbake'':
<pre>
source poky-init-build-env
bitbake meta-toolchain-sdk
</pre>
The result will be placed in the directory:
<pre>
tmp-igep0020b/deploy/sdk/
</pre>
as an archive to decompress in the directory "/usr/local/poky".

In order to cross compile code for the ''ARM'', the following script needs to be run to set up paths:
<pre>
source /usr/local/poky/eabi-glibc/environment-setup-arm-poky-linux-gnueabi
</pre>

= Kernel compilation =

Currently, the last stable kernel provided by ''ISEE'' is "linux-omap-2.6.28.10-igep0020b-2". Check in the ''download'' section of [http://www.myigep.com/index.php?option=com_weblinks&view=category&id=50&Itemid=85 www.myigep.com] which is the last one. More recent versions (but unstable) can be downloaded on the [http://git.myigep.com/gitweb ''git''] of ''ISEE''.

=== Kernel compilation under ''bitbake'' ===

=== Kernel compilation outside ''bitbake'' ===

First, download the kernel sources:
<pre>
cd $HOME/igep
wget http://downloads.myigep.com/sources/kernel/linux-omap-2.6.28.10-igep0020b-2.tar.gz
tar -xzf linux-omap-2.6.28.10-igep0020b-2.tar.gz
cd linux-omap-2.6.28.10-igep0020b-2
</pre>

Configure the kernel:
<pre>
source /usr/local/poky/eabi-glibc/environment-setup-arm-poky-linux-gnueabi
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- igep0020b_defconfig
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- menuconfig
</pre>
The last line is only needed if you want to customize the kernel.

To compile kernel and modules:
<pre>
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- uImage modules
</pre>

The resulting image is placed in "arch/arm/boot" directory.

We will see in the section [[How_to_setup_a_development_environment_for_OMAP3530#Boot_on_the_rootfs_and_the_kernel|Boot on the ''rootfs'' and the kernel]] how to use kernel and modules.

= Boot on the ''rootfs'' and the kernel =

There are several methods to do it. For developing purposes, the easiest way is to boot over network, which avoid flashing operations or coping on the memory card. Yet, these two solutions are essentials for applications where the board need to be independent from the host computer.

=== Over network ===

Two servers are needed. The ''NFS'' (''Network File System'') server allows the target to accede its ''rootfs'' by the network. The ''TFTP'' (''Trivial File Transfer Protocol'') server allows the target to download the kernel over network. Thus, ''UBoot'' needs to be correctly setup to boot on the correct files. To do this, plug a serial cable on the board (''115200n8'') and stop ''UBoot'' by pressing a key. The environment variable of ''UBoot'' we need to change are:
*''serverip'': the server's ''IP'' address, need to be on the ''192.168.254.x'' subred (except if you change the board address, which is not explained here). By default, the server's ''IP'' address is ''192.168.254.10''.
*''distro'': the distribution's name, by default ''poky''.
*''machine'': the card's name, by default ''igep0020b''.
*''project'': the project's name, that is to say the ''rootfs'' generated [[How_to_setup_a_development_environment_for_OMAP3530#Rootfs|previously]].

To change a variable, use the command ''setenv''. Thus, to change the project's name and use the one we have just made, set:
<pre>
setenv project poky-image-base
</pre>
Then, to boot:
<pre>
run bootcmd
</pre>
which will execute the contents of the ''bootcmd'' variable. The 'printenv'' command allow to show the content of a variable; for example:
<pre>
printenv bootcmd
</pre>
returns by default:
<pre>
run mmc-boot; run nfs-boot; run onenand-boot
</pre>
That is to say the board will first check if a memory card is present to boot with it. If memory card is not present, the board will newt ''ping'' the server to boot over network. If server does not answer, the board will boot on the flash. Take a look at ''mmc-boot'', ''nfs-boot'' and ''onenand-boot'' variables for more details. In addition, the factory settings of ''UBoot'' are given [http://wiki.myigep.com/trac/wiki/HowToSetupUBootFactorySetting here].

In order to save ''UBoot'' environment variables in the flash, do:
<pre>
saveenv
</pre>
which will avoid to reenter it every time...

Once ''<serverip>'', ''<distro>'', ''<project>'', and ''<machine>'' variables setup, ''UBoot'' will search on the server of address ''<serverip>'':
* a kernel image ''uImage'' in the directory "/srv/tftp/''<distro>''/''<project>''/''<machine>''" accessible by ''TFTP''.
* a ''rootfs'' in the directory "/srv/nfs/''<distro>''/''<project>''/''<machine>''" accessible by ''NFS''.

We assume now that ''<distro>=poky'', ''<project>=poky-image-base'' and ''<machine>=igep0020b''.

Thus, create the following directories on the host:
<pre>
sudo mkdir -p /srv/nfs/poky/poky-image-base/igep0020b
sudo mkdir -p /srv/tftp/poky/poky-image-base/igep0020b
</pre>
Next, copy the kernel. If it was made [[How_to_setup_a_development_environment_for_OMAP3530#Compilation_du_noyau_.C3.A0_l.27ext.C3.A9rieur_de_bitbake|outside ''bitbake'']]:
<pre>
sudo cp $HOME/igep/linux-omap-2.6.28.10-igep0020b-2/arch/arm/boot/uImage /srv/tftp/poky/poky-image-base/igep0020b/
</pre>
or if it was made [[How_to_setup_a_development_environment_for_OMAP3530#Rootfs|with the ''rootfs'']] or [[Créer_un_environnement_de_développement_pour_l'OMAP3530#Compilation_du_noyau_sous_bitbake|with ''bitbake'']]:
<pre>
sudo cp $HOME/igep/poky/build/tmp-igep0020b/deploy/images/uImage /srv/tftp/poky/poky-image-base/igep0020b/
</pre>
Next, install the ''rootfs'' in the good directory:
<pre>
pushd /srv/nfs/poky/poky-image-base/igep0020b
sudo cpio -idm< $HOME/igep/poky/build/tmp-igep0020b/deploy/images/poky-image-base-igep0020b.cpio
popd
</pre>
If kernel was built [[How_to_setup_a_development_environment_for_OMAP3530#Compilation_du_noyau_.C3.A0_l.27ext.C3.A9rieur_de_bitbake|outside ''bitbake'']], install kernel modules in the ''rootfs'' as follows:
<pre>
cd $HOME/igep/linux-omap-2.6.28.10-igep0020b-2
source /usr/local/poky/eabi-glibc/environment-setup-arm-poky-linux-gnueabi
make ARCH=arm CROSS_COMPILE=arm-poky-linux-gnueabi- modules_install INSTALL_MOD_PATH=/srv/nfs/poky/poky-image-base/igep0020b
</pre>
Finally, install the two servers on host:
<pre>
sudo apt-get install tftpd nfs-kernel-server
</pre>
By default, the ''TFTP'' server shares the "/srv/tftp" directory, which is the one we are using. If necessary, you can change this by editing the "/etc/inetd.conf" file :
<pre>
#:BOOT: TFTP service is provided primarily for booting. Most sites
# run this only on machines acting as "boot servers."
tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /srv/tftp
</pre>

The configuration file of ''NFS'' server is "/etc/exports". Add the following line for each ''rootfs'' :
<pre>
# Poky image rootfs
/srv/nfs/<distro>/<project>/<machine> <target_ip>(rw,no_root_squash,no_subtree_check,sync)
</pre>
where ''<target_ip>'' is the ''ip'' address of the target. By default, ''igep'' address is ''192.168.254.254''. It is also possible to put ''*'' to allow a wider range of addresses. In our case, write :
<pre>
/srv/nfs/poky/poky-image-base/igep0020b 192.168.254.254(rw,no_root_squash,no_subtree_check,sync)
</pre>

=== Copy kernel and ''rootfs'' in ''flash'' memory ===

Copy can be done either from ''uboot'' or ''linux''.

First step is to create the ''jffs2'' file (if you do not have it), which will be used to copy the ''rootfs''. The following package needs to be installed:
<pre>
sudo apt-get install mtd-utils
</pre>
Then use the command:
<pre>
mkfs.jffs2 -r <root file system> -e <erase block size> -o <output file>
</pre>
where <root file system> is the path to the directory to copy (ie /srv/nfs/poky/poky-image-base/igep0020b), <erase block size> is the block size to erase in KB and <output file> name of the output file.
Block size can be seen with the following command:
<pre>
cat /proc/mtd
</pre>
On ''igep'', it returns:
<pre>
dev: size erasesize name
mtd0: 00080000 00040000 "X-Loader"
mtd1: 00180000 00040000 "U-Boot"
mtd2: 00080000 00040000 "U-Boot Env"
mtd3: 00300000 00040000 "Kernel"
mtd4: 1fa80000 00040000 "File System"
</pre>
Thus, the size is 0x40000=265KB.

====Copy from ''uboot''====


====Copy from ''linux''====

To do this, you will have to boot the card from ''nfs'' or memory card; but not from flash.

Partitions can be seen with the following command:
<pre>
cat /proc/mtd
</pre>
On ''igep'', it returns:
<pre>
dev: size erasesize name
mtd0: 00080000 00040000 "X-Loader"
mtd1: 00180000 00040000 "U-Boot"
mtd2: 00080000 00040000 "U-Boot Env"
mtd3: 00300000 00040000 "Kernel"
mtd4: 1fa80000 00040000 "File System"
</pre>
To copy the kernel, erase the corresponding memory area before doing the copy:
<pre>
flash_eraseall /dev/mtd3
nandwrite -p /dev/mtd3 uImage
</pre>
same thing for the ''rootfs''
<pre>
flash_eraseall /dev/mtd4
nandwrite -p /dev/mtd4 rootfs.jffs2
</pre>
And now reboot. In case of errors (such as ''bad crc'' on the ''kernel'' for example), it is necessary to reflash all, see [http://wiki.myigep.com/trac/wiki/HowToUpgradeTheFactoryFirmware this].

=== Copier le noyau et le ''rootfs'' dans la carte mémoire ===
0
edits