Home > Linux, Linux 2.6, Programming > Cross compiling Berkeley DB for ARM and MIPS

Cross compiling Berkeley DB for ARM and MIPS

Following my blog entry about Databases for Linux Embedded Systems, here are the instructions to cross-compile Oracle Berkeley DB.

First download the source code of the latest version of Berkeley DB (version 11gR2 – 11.2.5.1.25). You’ll need to register on Oracle website first on the download page http://www.oracle.com/technetwork/database/berkeleydb/downloads/index.html to download http://download.oracle.com/otn/berkeley-db/db-5.1.25.tar.gz (with AES encryption) or  http://download.oracle.com/otn/berkeley-db/db-5.1.25.NC.tar.gz (if you don’t need encryption).

Extract the source code:

tar xzvf ../Downloads/db-5.1.25.tar.gz

Configure and build the source code. I’ll use mipsel-linux-gcc, but any other cross-compiler could be used.

cd db-5.1.25/build_unix
../dist/configure –host=mipsel-linux CC=mipsel-linux-gcc RANLIB=mipsel-linux-ranlib STRIP=mipsel-linux-strip AR=mipsel-linux-ar –prefix=/home/jaufranc/edev/lib/db-11g
make
make install

The full berkeley DB package is 79MB:

jaufranc@CNX-TOWER:~/edev/lib/db-11g$ du –max-depth=1 -h
6.6M    ./lib
308K    ./bin
72M    ./docs
176K    ./include
79M    .

However, you won’t need the include and docs directory in your embedded target. So you do not need to copy those. You may or may need the utilities in the bin file. The lib diirectory contains two versions of the static library (why?) and one dynamic library  libdb-5.1.so (1.8MB).

Using CFLAGS=”-Os” at the configure step above will slightly decrease the size of the library (1.7MB).

For further size reduction, add –enable-smallbuild (equivalent to –disable-cryptography, –disable-hash, –disable-queue, –disable-replication, and –disable-verify) in the configure script as follows:

../dist/configure –host=mipsel-linux CC=mipsel-linux-gcc RANLIB=mipsel-linux-ranlib STRIP=mipsel-linux-strip AR=mipsel-linux-ar –enable-smallbuild –prefix=/home/jaufranc/edev/lib/db-11g CFLAGS=”-Os”

The size of the dynamic library (libdb-5.1.so) is decrease to 938KB and the bin directory to 288KB.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter

  1. xichen
    July 12th, 2012 at 13:52 | #1

    1. ../dist/configure –host=mips-linux –prefix=/home/kexf/bdb/bulid/mips.5.2/ –with-mutex=MIPS/gcc-assembly
    2. make
    ./libtool –mode=compile mips-linux-cc -c -I. -I../src -D_GNU_SOURCE -D_REENTRANT -O3 ../src/mutex/mut_tas.c
    libtool: compile: mips-linux-cc -c -I. -I../src -D_GNU_SOURCE -D_REENTRANT -O3 ../src/mutex/mut_tas.c -fPIC -DPIC -o .libs/mut_tas.o
    /tmp/ccD53pYU.s: Assembler messages:
    /tmp/ccD53pYU.s:102: Error: opcode not supported on this processor: mips1 (mips1) `sync ‘
    make: *** [mut_tas.lo] Error 1

    can you help me?

  2. xichen
    July 12th, 2012 at 13:53 | #2

    version is 5.2.36

  3. July 12th, 2012 at 15:10 | #3

    @ xichen
    Not sure what causes this, maybe an issue with the toolchain. First, I would check if there is assembler code in mut-tas.c and if any, see if you can change it. If there isn’t any, try another toolchain if possible or change some settings. (e.g. -O0)

  4. xichen
    July 12th, 2012 at 17:31 | #4

    I use another toolchain but also have the error.
    And, using arm and x86 are ok.

  5. xichen
    July 12th, 2012 at 18:03 | #5

    there is assembler code in mut-tas.c, but how can i do ?

  6. xichen
    July 12th, 2012 at 18:21 | #6

    thank you !
    I have made!

  7. July 12th, 2012 at 19:59 | #7

    @ xichen
    Great! If you can post your modifications here, it would be great. Alternatively, you could also send a patch to Berkeley DB developers.

  8. xichen
    July 13th, 2012 at 10:21 | #8

    I add “.set mips2″ before “sync”.

  1. No trackbacks yet.