Mittwoch, 3. August 2011

Cross Compiling Netatalk 2.2 for DD-WRT on Ubuntu 11.04

This is a straight up history on how I got netatalk 2.2 compiled to run on my Netgear WNR3500L router. I used Ubuntu 11.04 but this should work on various distributions.

I am not an expert on the matter. So in case you are wondering about some commands that might not be necessary ... its just how I got it to work. It might not be the most efficient way!
On my machine I needed the packages bison, flex and texinfo installed before I could start cross compiling. So we start up a Terminal and install them:

> sudo apt-get install bison flex texinfo


In case you do not have subversion installed:


> sudo apt-get install subversion


Now we are set to retrieve the optware packages und install our toolchain. Change to a directory you want this workspace located and execute:


> svn co http://svn.nslu2-linux.org/svnroot/optware/trunk optware


Once that completed successfully we want to setup the dd-wrt toolchain. So change into the optware directory:


> cd optware
> make ddwrt-target
> cd ddwrt
> make directories ipkg-utils toolchain


Note: the target depends on your router and the build of dd-wrt you have installed! The dd-wrt target happens to fit in this case. Read up on what target system you need before starting out!


Now that will take some time. Afterwards however we are ready to go. There are several dependencies netatalk needs. These are: openssl, libgcrypt and libdb (Berkeley DB > =4.6). So we are starting out by compiling openssl and libgcrypt:


> make openssl-stage
> make libgcrypt-stage


For libdb we need to alter the libdb.mk file in the directory make. There are two things we need to change in order for this lib to play nice on the router later on. First we need to chose the correct version, which in my case is 4.7.25:

LIBDB_VERSION=4.7.25
LIBDB_LIB_VERSION=4.7

Secondly we need to add a configuration flag (around line 127):


--with-mutex=MIPS/gcc-assembly \


This configuration flag is important so libdb is not linked against libpthread. When this flag is not set libdb will not play nice with netatalk and OS X will create a warning each and every time you want to access a share. Save the changes and compile!


> make libdb-ipk
> make libdb-stage


Now we are set to get to netatalk. First we need to change the version in make/netatalk.mk just as we did with libdb. We change it to version 2.2.0:


NETATALK_VERSION=2.2.0


and disable the line where patches are applied (line 49)


#NETATALK_PATCHES=$(NETATALK_SOURCE_DIR)/db3-check.patch


also we need to change the libgcrypt configuration flag around line 137 from 


--with-libgcrypt-prefix=$(STAGING_PREFIX) \


to 


--with-libgcrypt-dir=$(STAGING_PREFIX) \


This puts uams_dhx2.so into our ipk. Also add the configuration flag:


--with-cnid-cdb-backend \


We are ready to compile netatalk now:


> make netatalk-ipk


The process might stop on an error telling you that the variable AI_NUMERICSERV is nowhere to be found. I fixed this by adding:


#ifndef AI_NUMERICSERV
#define AI_NUMERICSERV 0
#endif 


in builds/netatalk/libatalk/cnid/dbd/cnid_dbd.c right before the function static int tsock_getfd(const char *host, const char *port)  Now we are starting the building process again and it should run smoothly and create the ipk.


> make netatalk-ipk


Thats it! We have created libdb and netatalk packages which we can deploy on the router now. Copy builds/libdb_4.7.25-3_mipsel.ipk and builds/netatalk_2.2.0-2_mipsel.ipk onto your router and install them (in case afpd is running kill it first):


ipkg install libdb_4.7.25-3_mipsel.ipk
ipkg install netatalk_2.2.0-2_mipsel.ipk


Cheers!

8 Kommentare:

  1. I keep getting this error after I followed your instructions. Only difference is compiling on rhel6:

    dbif.o: In function `dbif_env_remove':
    /files/dev/optware/ddwrt/builds/netatalk/etc/cnid_dbd/dbif.c:809: undefined reference to `db_env_create_5002'
    /files/optware/ddwrt/builds/netatalk/etc/cnid_dbd/dbif.c:810: undefined reference to `db_strerror_5002'
    /files/dev/optware/ddwrt/builds/netatalk/etc/cnid_dbd/dbif.c:848: undefined reference to `db_env_create_5002'
    /files/dev/optware/ddwrt/builds/netatalk/etc/cnid_dbd/dbif.c:835: undefined reference to `db_strerror_5002'
    /files/dev/optware/ddwrt/builds/netatalk/etc/cnid_dbd/dbif.c:849: undefined reference to `db_strerror_5002'
    /files/dev/optware/ddwrt/builds/netatalk/etc/cnid_dbd/dbif.c:823: undefined reference to `db_strerror_5002'
    /files/dev/optware/ddwrt/builds/netatalk/etc/cnid_dbd/dbif.c:840: undefined reference to `db_strerror_5002'
    /files/dev/optware/ddwrt/builds/netatalk/etc/cnid_dbd/dbif.c:854: undefined reference to `db_strerror_5002'
    collect2: ld returned 1 exit status
    make[4]: *** [dbd] Error 1
    make[4]: Leaving directory `/files/dev/optware/ddwrt/builds/netatalk/etc/cnid_dbd'
    make[3]: *** [all-recursive] Error 1
    make[3]: Leaving directory `/files/dev/optware/ddwrt/builds/netatalk/etc'
    make[2]: *** [all-recursive] Error 1
    make[2]: Leaving directory `/files/dev/optware/ddwrt/builds/netatalk'
    make[1]: *** [all] Error 2
    make[1]: Leaving directory `/files/dev/optware/ddwrt/builds/netatalk'
    make: *** [/files/dev/optware/ddwrt/builds/netatalk/.built] Error 2

    AntwortenLöschen
  2. seems they make changes to netatalk.mk recently, and since then it will not compile with 4.7.25. it compiles ok against libdb52, but i cant use --with-mutex=MIPS/gcc-assembly with this version. I'll try it without and see if it works.

    AntwortenLöschen
  3. ok i got libdb52 to compile. I added the --with-mutex=MIPS/gcc-assembly to it, and then added a couple of cflags to get it to compile (-mips32 -mtune=mips32). Now it compiles. I do get this weird error message in the afpd.log though:

    {cnid_dbd.c:88} (E:Default): tsock_getfd: getaddrinfo: CNID server localhost:4700 : Bad value for ai_flags

    then i get:

    Aug 24 23:50:05.078017 afpd[14399] {cnid_dbd.c:428} (E:CNID): transmit: Request to dbd daemon (db_dir /tmp/files) timed out.

    then i get a message in osx saying the cnid database is corrupt and it's switchingg to a temporary version.

    any ideas?

    AntwortenLöschen
  4. Hey smlacc I had that OS X message too when I did my trys with netatalk. It basically means that afpd cannot connect with libdb. When I had had that error I added the --with-mutex=MIPS/gcc-assembly so that libdb did not compile against pthread which was the problem back then.

    I have no idea what changed with libdb 5.2 and I did not see yet what changed in the new netatalk.mk. What version is being installed with the new netatalk.mk?

    AntwortenLöschen
  5. 2.2.0

    there are differences in netatalk.mk which stop it compiling against 4.7.25. I am reverting to revision 12529 (svn cp -r 12529) to see if that works. will keep you posted. if you figure out how to compile using current svn, that will be helpful too!

    AntwortenLöschen
  6. ok i got it working. Instead of this line in your docs:

    > svn co http://svn.nslu2-linux.org/svnroot/optware/trunk optware

    do this:

    > svn co -r 12529 http://svn.nslu2-linux.org/svnroot/optware/trunk optware

    instead of the current version, it downloads an old version that works with the rest of your post. the compile then works exactly as you describe. This is good enough to get it going. If you ever work out how to compile against libdb52 though, id be very interested to see how!

    thanks again for your post,
    Smlacc

    AntwortenLöschen
  7. Thanks for the feedback smlacc! I will look into the libdb 5.2 issue soon.

    AntwortenLöschen
  8. Thanks for this tutorial. Unfortunately it seems that binutils-2.17.50.0.8 is no longer available.

    is there a newer version available or how can I mark up the files generated from this tutorial to still work with the rest?

    My goal is to build version of netatalk 3.0.4 for mips.. It seems that Mountain Lion requires this version. With 2.2, I keep getting the server you are trying to connect to is of an incompatible version.

    AntwortenLöschen