11

Python for CRIS Etrax

Using a howto from this site I managed to cross-compile python 2.5.1 for my embedded linux board . Although AXIS provides python 2.4 with their SDK and configures it with no threads and stuff, I compiled the the original python 2.5.1 with only this patch applied to prevent tests from running while cross compiling and to byte-compile python scripts using host's python compiler.

The patch is heavily based on Chris', which is heavily based on K's :) I modified only what was need to successfully patch 2.5.1 (Chris' patch is for 2.5.0)

Here is a small howto to get you going:

Get python

wget http://python.org/ftp/python/2.5.1/Python-2.5.1.tgz
wget http://www.sealabs.net/seadog/files/python-2.5.1-cris.patch
tar zxf Python-2.5.1.tgz

Apply Patch

cd Python-2.5.1
patch < ../python-2.5.1-cris.patch

Now we compile python for our host architecture to get python and Parser/pgen executables. These are needed to byte-compile python during our cross compile procedure.

./configure
make

Save native python and pgen

mv python hostpython
mv Parser/pgen Parser/hostpgen

Clean everything up

make clean

Now we are ready to cross-compile!

If you have downloaded Acme criss-gcc debian package, don't forget to add /usr/local/cris/bin to PATH

export PATH="/usr/local/cris/bin:$PATH"

Set enviroment variables

export HOST="cris-axis-linux-gnu"
export CC=" gcc-cris -mlinux -mno-mul-bug-workaround"
export CXX=$(CC)

export LN=" ln"
export RM=" rm -f"

export AR=" ar-cris"
export INSTALL=" install_elinux -p"
export LD=" ld-cris -mcrislinux"
export OBJCOPY=" objcopy-cris"
export RANLIB=" ranlib-cris"
export STRIP=" strip-cris"

export OPT="-Os"
export CFLAGS="-Wall -Wshadow -g"
export LDFLAGS="-fPIC"
export HOSTPYTHON=./hostpython
export HOSTPGEN=./Parser/hostpgen
export CROSS_COMPILE=yes

Configure

./configure --host=$HOST --prefix=/tmp/cris-python --build=`uname -m`-pc-linux-gnu

Make and install respecting enviroment variables

make -e
make -e install

Now check if you can run your cross compiled binary /tmp/cris-python/bin/python. (You shouldn't!)

seadog@plu:~/Projects/fox/cris-binary/python/bin$ ./python
bash: ./python: cannot execute binary file

Dada! You have a cross-compiled binary!

I also cross compiled twisted python 2.5.0 and pyxml 0.8.

You just untar and execute (python is native binary)

python -E setup.py install --prefix=../cris-python --install-scripts=/tmp/cris-python/bin

I have a bazaar repository with binary python here http://www.sealabs.net/cris/cris-binary which you can checkout using

bzr checkout http://www.sealabs.net/cris/cris-binary

And now my jabber bots can run on my fox board! :)

  1. Maurizio Branca says:

    Hi Giorgos,
    i found this post searching info on how to build Python 2.5 for my foxboard. It’s a hugely useful post! Really!

    I need exactly your setup, composed by Python 2.5, Twisted and a few easy pure-python packages: pyserial, httplib2. With an exception: sqlite3.

    Have you evere tried to build sqlite3 module (with the native _sqlite3 conunterpart) or pysqlite2?

    My best outcome it’s been this error:

    [root@axis-00408c169069 /usr/lib]99# python
    Python 2.5.1 (r251:54863, Apr 11 2008, 11:23:55)
    [GCC 3.2.1 Axis release R63/1.63] on linux2
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>>
    >>> import _sqlite3
    Traceback (most recent call last):
    File “”, line 1, in
    ImportError: /mnt/flash/usb/cris-python/lib/python2.5/lib-dynload/_sqlite3.so: undefined symbol: __ctype_tolower_loc
    >>>

    I should improve, isn’t it? ;-)

    I’ve initially started cross compiling sqlite3-3.5.7 using this guide: http://www.acmesystems.it/articles/00033/FoxSqlite3ForDummiesVersion3.pdf. The resulting binary sqlite3 command-line utility works great. I’ve then copied the libsqlite3.a library under the /tmp/cris-python/lib and build (finally!) the _sqlite3.so python module.

    No luck. With these file I got the error, even using a sqlite3 cli and library compiled from a 3.4.2 sqlite3 snapshot.

    Any clue?

    Anyway, great post. Congrats!

    zmoog

  2. Fx says:

    Hi Giorgos,
    wonderful post, starting from here I have done a lot of ports :D .
    But, what about your jabber bots? I do someone but I really cant make them accept files… do you had some good news for me?
    I’m tring to port hplip and cups now and it should be fantastic to let my printer to print alone if i send a document to one jabber bot of mine…

    See you soon
    Fabio

  3. seadog says:

    @Fx
    In fact I ‘ve never tried to exchange files using jabber. As far as I know an open port is required for file transfer to work on jabber network, maybe that helps you. I ‘m really busy this period but I want to get some time to give my jabber bots some love, because they are long dead. If I do, I will try file exchange. Until then, I wish you luck :)

  4. Fx says:

    Hi Giorgos,
    I’m near to file exchange (receive :D )! an open port is not necessary while bytestream can be done throught socks5 proxy… Actually I do almost all but when I try to use a socket to connect to the socks proxy the things go messy… may I wrong something, I wish you a better luck :D !
    Obviously if you want don’t hesitate to ask my script!

    a presto(see you soon)
    Fabio

  5. Clark says:

    Your link to your patch seems broken.

  6. seadog says:

    sorry for that, I forgot to attach the patch! :)

  7. Anonymous coward says:

    Did you have to patch Twisted to cross-compile it ?
    I have built and installed zope, but when I build Twisted it says zope is not installed.

  8. seadog says:

    twisted provides zope.Interface which seems it need an extra python setup command. Just cd to Twisted-2.5.0/zope.interface-3.3.0 and execute python setup as above.

    You don’t have to install any other zope packages!

  9. Anonymous coward says:

    Thank you for your answer.
    I have another issue with “BeautifulSoup”(very small):
    ‘hostpython setup.py build’ raise an ImportError : it can’t find libm.so.0 (some other modules can’t find libc.so.0)
    I think the problem is between glibc (host) and uclibc (target). are you using uclibc on your target ?
    Another strange behaviour is directly in the hostpython prompt:
    ‘>>>help()’ returns an importerror after the ‘make clean’ but is working before.

  10. seadog says:

    Hey,
    I also tried to compile sqlite bindings but I didn’t managed to and because I wasn’t going to store much I wrote some XML code.

    If you are still interested I will give it a try this week.

    thanks for commenting,
    sd

  11. Maurizio Branca says:

    Hi,
    thanks for writing the post! ;)

    Yes, i’m still interested in the sqlite thing because a sql datastore is best fit.

    I’ll try again from today..

    thanks again, i hope to hear you soon ;)

    zmoog