The Lab Book Pages

An online collection of electronics information

http://www.labbookpages.co.uk

Dr. Andrew Greensted
Last modified: 21st April 2010

Hide Menu


Valid XHTML Valid CSS
Valid RSS VIM Powered
RSS Feed Icon

This site uses Google Analytics to track visits. Privacy Statement

Page Icon

Developing Code

Gumstix recommend using OpenEmbedded for creating system images. This page describes how to OpenEmbedded is setup.


OpenEmbedded Setup

Setting up the OpenEmbedded environment is very simple. Gumstix.net has a good set of instructions.

Here is a slightly more concise set of instructions. These instructions direct you to specify the location of the OpenEmbedded environment.

The final collection of files is easily over 5GB, so you probably want to put them somewhere other than your home directory.

Step 1

First create somewhere to put the OpenEmbedded files. The Gumstix documentation suggest your home directory, personally I like to keep stuff like this elsewhere, so that's the plan I'll describe here.

> mkdir /files/gumstix
> cd /files/gumstix

Step 2

Now get the latest snapshot of files.

> svn co https://gumstix.svn.sourceforge.net/svnroot/gumstix/trunk gumstix-oe

Step 3

The next stage is to tell the build tools where to put and find files. You need to edit two files.

Edit /files/gumstix/gumstix-oe/build/conf/site.conf. This specifies where source files will be downloaded to.

File: /files/gumstix/gumstix-oe/build/conf/site.conf
DL_DIR = "/files/gumstix/sources"

Edit /files/gumstix/gumstix-oe/extras/profile. This specifies the root of the build environment.

File: /files/gumstix/gumstix-oe/extras/profile
export GUMSTIXTOP="/files/gumstix/gumstix-oe"

Step 4

The next step is to create a location where source files can be stored, create a directory to hold your own user packages and setup your profile. This last step makes sure the right environment variables are set like PATH.

> mkdir /files/gumstix/sources
> mkdir -p /files/gumstix/gumstix-oe/user.collection/packages
> source  /files/gumstix/gumstix-oe/extras/profile

Step 5

Last of all, build a Gumstix image.

Note:Gentoo users, make sure you have the following installed on your system: python +sqlite, diffstat, texi2html and (optionally) psyco.

> bitbake gumstix-minimal-image
> ls -l /files/gumstix/gumstix-oe/tmp/deploy/glibc/images/gumstix-custom-verdex/

Having reached this stage, you now have a cross-compile environment. If you take a look in /files/gumstix/gumstix-oe/tmp/cross/bin/ you can see the compiling tools such as gcc.


Hello World

OpenEmbedded uses recipes to create user packages, but this can be a lot of effort if you just want to create a simple binary. Instead, you can just have a simple Makefile that uses the cross compile tools created in the stages above.

Below is a 'Hello world' example, that creates a binary for the Gumstix, that then can be copied over to the device and executed.

File: hello.c
#include <stdio.h>

int main(void)
{
   printf("Hello\n");
   return 0;
}
File: Makefile
CC       = /files/gumstix/gumstix-oe/tmp/cross/bin/arm-angstrom-linux-gnueabi-gcc
CFLAGS   = -Wall

all: hello.c
   $(CC) $(CFLAGS) -o hello hello.c

Finally, copy over the binary and execute.

> make
> scp hello root@gumstix:/media/ram

Problems and Solutions

Here as some solutions to bitbake problems/errors you might face. Note: In most cases you'll need to delete the /files/gumstix/gumstix-oe/tmp directory after correcting the error and reissuing a bitbake command. There is probably a better approach that doesn't require rebuilding everything, but it works.

binutils-cross

The error reads something like:

| cc1: warnings being treated as errors
| /files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/binutils-cross-2.18-r1/binutils-2.18/bfd/elf32-arm.c: In function 'find_thumb_glue':
| /files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/binutils-cross-2.18-r1/binutils-2.18/bfd/elf32-arm.c:2524: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result
| /files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/binutils-cross-2.18-r1/binutils-2.18/bfd/elf32-arm.c: In function 'find_arm_glue':
| /files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/binutils-cross-2.18-r1/binutils-2.18/bfd/elf32-arm.c:2557: error: ignoring return value of 'asprintf', declared with attribute warn_unused_result
| make[4]: *** [elf32-arm.lo] Error 1
| make[4]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/binutils-cross-2.18-r1/binutils-2.18/build.x86_64-linux.arm-angstrom-linux-gnueabi/bfd'
| make[3]: *** [all-recursive] Error 1
| make[3]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/binutils-cross-2.18-r1/binutils-2.18/build.x86_64-linux.arm-angstrom-linux-gnueabi/bfd'
| make[2]: *** [all] Error 2
| make[2]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/binutils-cross-2.18-r1/binutils-2.18/build.x86_64-linux.arm-angstrom-linux-gnueabi/bfd'
| make[1]: *** [all-bfd] Error 2
| make[1]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/binutils-cross-2.18-r1/binutils-2.18/build.x86_64-linux.arm-angstrom-linux-gnueabi'
| make: *** [all] Error 2
| FATAL: oe_runmake failed

Add the following line to the end of the file /files/gumstix/gumstix-oe/build/conf/local.conf.

BUILD_CPPFLAGS += "-Wno-format-security -U_FORTIFY_SOURCE"

As mentioned above, you might need to delete directory /files/gumstix/gumstix-oe/tmp for the solution to work.

Error: previous declaration of 'getline'

The error reads something like:

ERROR: log data follows (/files/gumstix/gumstix-oe/tmp/work/i686-linux/unifdef-native-2.6.18+git-r0/temp/log.do_compile.4277)
| /files/gumstix/gumstix-oe/tmp/work/i686-linux/unifdef-native-2.6.18+git-r0/unifdef.c:209: error: conflicting types for 'getline'
| /usr/include/stdio.h:651: error: previous declaration of 'getline' was here

Change the three instances of getline to getline2 in file /files/gumstix/gumstix-oe/org.openembedded.snapshot/packages/unifdef/files/unifdef.c

arm-angstrom-linux-gnueabi-gcc: Command not found

This is essentially the same problem as above. The error looks something like this:

| NOTE: make -e MAKEFLAGS= headers_install INSTALL_HDR_PATH=/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/linux-libc-headers-2.6.20-r7/image/usr ARCH=arm
| make: arm-angstrom-linux-gnueabi-gcc: Command not found
|   CHK     include/linux/version.h
|   UPD     include/linux/version.h
| make[1]: Entering directory `/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/linux-libc-headers-2.6.20-r7/linux-2.6.20'
| make[1]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/linux-libc-headers-2.6.20-r7/linux-2.6.20'
| make[1]: Entering directory `/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/linux-libc-headers-2.6.20-r7/linux-2.6.20'
|   HOSTCC  scripts/unifdef
| scripts/unifdef.c:209: error: conflicting types for 'getline'
| /usr/include/stdio.h:651: error: previous declaration of 'getline' was here
| make[1]: *** [scripts/unifdef] Error 1
| make[1]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/linux-libc-headers-2.6.20-r7/linux-2.6.20'
| make: *** [headers_install] Error 2
| FATAL: oe_runmake failed

There are two solutions. The quick one is to edit /files/gumstix/gumstix-oe/tmp/work/armv5te-angstrom-linux-gnueabi/linux-libc-headers-2.6.20-r7/linux-2.6.20/scripts/unifdef.c, replacing all three instances of getline with getline2. The problem is, if you feel the need to clean up the 'tmp' directory you'll need to remember to make the changes again.

The second solution corrects the problem at the source. The kernel archive linux-2.6.20.tar.bz2 contains the unifdef.c file that causes the problem. We need to unpack this, edit the unifdef.c file and re-archive.

> tar -jxf /files/gumstix/sources/linux-2.6.20.tar.bz2
> sed -i 's/getline/getline2/' linux-2.6.20/scripts/unifdef.c
> tar -jcf /files/gumstix/sources/linux-2.6.20.tar.bz2 linux-2.6.20
> rm -r linux-2.6.20

Next, we need to adjust the checksum records, so that bitbake thinks the new archive is OK.

Edit the file /files/gumstix/gumstix-oe/org.openembedded.snapshot/conf/checksums.ini and search for the entry for http://kernel.org//pub/linux/kernel/v2.6/linux-2.6.20.tar.bz2. Just change the entries for md5 and sha256, with those output from the commands listed below.

> md5sum /files/gumstix/sources/linux-2.6.20.tar.bz2
> sha256sum /files/gumstix/sources/linux-2.6.20.tar.bz2

gmp and dbus

The error reads something like:

| scanf/.libs/vsscanf.o: In function `__gmpz_abs':
| vsscanf.c:(.text+0x3df): multiple definition of `__gmpz_abs'
| .libs/assert.o:assert.c:(.text+0x434): first defined here
| collect2: ld returned 1 exit status
| make[2]: *** [libgmp.la] Error 1
| make[2]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/x86_64-linux/gmp-native-4.2.1-r2/gmp-4.2.1'
| make[1]: *** [all-recursive] Error 1
| make[1]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/x86_64-linux/gmp-native-4.2.1-r2/gmp-4.2.1'
| make: *** [all] Error 2
| FATAL: oe_runmake failed

or like this:

| dbus-sysdeps-unix.c: In function '_dbus_read_credentials_unix_socket':
| dbus-sysdeps-unix.c:996: error: storage size of 'cr' isn't known
| dbus-sysdeps-unix.c:999: warning: pointer targets in passing argument 5 of 'getsockopt' differ in signedness
| dbus-sysdeps-unix.c:996: warning: unused variable 'cr'
| dbus-sysdeps-unix.c: In function 'split_paths_and_append':
| dbus-sysdeps-unix.c:2550: warning: passing argument 1 of '_dbus_string_init_const' discards qualifiers from pointer target type
| dbus-sysdeps-unix.c: In function '_dbus_get_standard_session_servicedirs':
| dbus-sysdeps-unix.c:2719: warning: passing argument 1 of '_dbus_string_init_const' discards qualifiers from pointer target type
| make[3]: *** [dbus-sysdeps-unix.lo] Error 1
| make[3]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/x86_64-linux/dbus-native-1.0.1-r0/dbus-1.0.1/dbus'
| make[2]: *** [all] Error 2
| make[2]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/x86_64-linux/dbus-native-1.0.1-r0/dbus-1.0.1/dbus'
| make[1]: *** [all-recursive] Error 1
| make[1]: Leaving directory `/files/gumstix/gumstix-oe/tmp/work/x86_64-linux/dbus-native-1.0.1-r0/dbus-1.0.1'
| make: *** [all] Error 2
| FATAL: oe_runmake failed

This solution is copied from this post.

Add the following four lines to this file, /files/gumstix/gumstix-oe/com.gumstix.collection/conf/machine/include/gumstix.inc.

PREFERRED_VERSION_gmp = "4.2.2"
PREFERRED_VERSION_gmp-native = "4.2.2"
PREFERRED_VERSION_dbus = "1.2.1"
PREFERRED_VERSION_dbus-native = "1.2.1" 

Then, as shown below, get hold of a newer recipe for gmp and add to the collection.

> wget http://www.klc.net.nz/images/gmp.tar.gz
> tar -zxf gmp.tar.gz -C /files/gumstix/gumstix-oe/org.openembedded.snapshot/packages/
> wget http://www.klc.net.nz/images/dbus.tar.gz
> tar -zxf dbus.tar.gz -C /files/gumstix/gumstix-oe/org.openembedded.snapshot/packages/

Note: It seems there is no need to delete the 'tmp' directory for this one.

Cannot download zlib-1.2.3.tar.bz2

The official zlib site doesn't seem to host this file anymore, but you can get it from SourceForge. You'll need to create the md5 file otherwise bitbake will keep trying to download it!

> cd /files/gumstix/sources
> wget http://prdownloads.sourceforge.net/libpng/zlib-1.2.3.tar.bz2
> md5sum zlib-1.2.3.tar.bz2 | awk '{printf $1}' > zlib-1.2.3.tar.bz2.md5

PATH_MAX undeclared

The error reads something like:

| scripts/mod/sumversion.c: In function 'get_src_version':
| scripts/mod/sumversion.c:384: error: 'PATH_MAX' undeclared (first use in this function)
| scripts/mod/sumversion.c:384: error: (Each undeclared identifier is reported only once
| scripts/mod/sumversion.c:384: error: for each function it appears in.)
| scripts/mod/sumversion.c:384: warning: unused variable 'filelist'

Again we have two solutions. The quick one is to add #include <limits.h> to files/gumstix/gumstix-oe/tmp/work/gumstix-custom-verdex-angstrom-linux-gnueabi/gumstix-kernel-2.6.21-r1/linux-2.6.21/scripts/mod/sumversion.c

The alternative is to adjust the linux-2.6.21.tar.bz2 source archive.


Book Logo