Drobo

Cross-Compiling for DroboFS: python 2.6.6

[/code]Cross-compiling for DroboFS: Python 2.6.6

Hi everyone,

Here is another post on the cross-compile series for DroboFS.

Introduction: Why Python?

Because I thought getting pyTivo runing would be really cool, well interesting.

Overall compiling complexity: A little more work than expected.

Step 1: Background info

To be able to make use of this post, you need a VM configured as indicated in this post.

Step 2: Dependencies

Python needs (More accurately likes to have…):
ncurses
openssl

Others are helpful later… like zlib etc, might be needed for your script, might not be.

Step 3: Building python and pgen

Since the python build requires the use of python during the build, you first need to build python under a normal environment. This is because the cross-compiled version of python will not work on your host system. All of this very helpful information was obtained from http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html.

Step 4: Get the source code

Python website: http://www.python.org/download/releases/
Version: 2.6.6
Direct link: http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz

Make sure that you are in a folder that you can build under the normal environment (you can do this by NOT executing the crosscompile script detailed in the vm setup, or as part of another account), then type:

wget http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tgz tar zxf Python-2.6.6.tgz cd Python-2.6.6

Step 5: Configuration

Here is where it gets a bit more complicated. Because the python build
requires the use of python during the build process, you need to create python and pgen executables for your platform. So, NOT in your
chroot jail, perform the following steps:

cd Python-2.6.6
./configure
make python Parser/pgen
mv python hostpython
mv Parser/pgen Parser/hostpgen

If (like me) you built in a different account than you chroot jail account, move the hostpython and hostpgen files to the proper location for your chroot jail. so…

sudo cp Python-2.6.6.tgz /var/chroot/drobofs/root/code
sudo cp hostpython /var/chroot/drobofs/root/code
sudo cp Parser/hostpgen /var/chroot/drobofs/root/code

Now back to building the cross compiled version:

Step 6: Enter the cross-compiling environment

See step 2 of this post to see instructions on how to enter the chroot environment.

Make sure you are in the /root/code folder and perform the following:

tar zxf Python-2.6.6.tgz
cd Python-2.6.6
cp ../hostpython .
cp ../hostpgen Parser/hostpgen

Now you need to patch the python build process to use the host variants of python you just created, so… Download the proper patch file from here, or if you are using 2.6.6, that’s available here

apt-get install patch
wget http://randomsplat.com/wp-content/uploads/2010/10/Python-2.6.6-xcompile.patch
patch -p1 <Python-2.6.6-xcompile.patch

Step 7: Configuration in cross-compile environment

Now that your build environment has been patched, you are ready to configure, perform the following steps:

make distclean

./configure --host=arm-none-linux-gnueabi --build=i686-pc-linux-gnu --prefix=/python --without-readline --without-gcc

This should return no errors, note the make distclean is not needed unless this is the location you just used to build python and pgen for the host.

Step 8: Compiling

Within the folder /root/code/python-2.6.6

make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED="arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes

Again this should complete with no errors, if it does check for typos…

Step 9: Installation

Installation is fairly straight forward, however it does require a few extra options…

make install HOSTPYTHON=./hostpython BLDSHARED="arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes prefix=/usr/arm/

Python will now be installed in /usr/arm

Then we package the whole /usr/arm and copy it over to the DroboFS, as indicated on step 9 here.

As with wget, and additional step is to ensure that your PATH variable looks up this version first instead of the embedded one. Your PATH variable should look like this:

PATH="/usr/arm/bin:/usr/bin:/bin"

or simply ensure that python is always exectuted with a fully qualified path. You may also need to set PYTHONHOME and or PYTHONPATH

Step: 10 Testing…

ssh to your drobo, and execute the built in tests:

cd /usr/arm/bin
./python ../lib/python2.6/test/test___all__.py

Note that you may get a few modules not being able to be imported, thats okay UNLESS you plan on using them. Then you will need to locate them and build them.
[/code]
Also, to decrease the size of the python installation, check out this page towards the bottom.

Congratulations!