Python in a FriendlyArm (minicom 2440)

This post was developed as a project of Specialization in Mobile Devices Fatec-Jp subject in Python. We’ll talk over how to cross post the python compiler for ARM platform (FriendlyArm minicom 2440).

First let’s do cross-compile a Hello World in C before porting python to friendlyarm, and so we need to install the cross-compiling toolchains for ARM platform (arm-linux-gcc)

To do this we split the tutorial in a few steps:

Step 1: Install the arm-linux-gcc

To do the cross-compiler used the arm-linux-gcc-4.3.2.tgz, which is available at:                                      http://www.friendlyarm.net/dl.php?file=arm-linux-gcc-4.3.2.tgz

Unzip it in /usr/local/armgcc and then add the path in the path like this:
export PATH=/usr/local/armgcc/bin:$PATH

Step 2: Create a sample helloword in C and make the cross-compiler for arm

Create a C program helloworld.c

#include <stdio.h>
main(){
printf (“Hello World!\n”);
}

Make a normal build:                                                                                                                                                                                                                                                                                                                                                                                 gcc helloworld.c -o helloNormal

Then do:
file helloNormal

The output will be the one below, which shows that this file is compiled to processor pc:
helloNormal: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU / Linux 2.6.15, not stripped

With this file is not possible to run at friendlyarm they still did not cross-compiler.

To generate the binary cross-compiled arm to do so:
arm-linux-gcc -s helloworld.c -o helloArm

Now we have a program in C that can run on FriendlyArm, to be sure, let’s check the file:
file helloArm

The output will be the one below, which shows that this file is compiled to FriendlyArm:
helloArm: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, stripped

Okay, now just put the file in helloArm FriendlyArm and run:
./helloArm

As output we get:
Hello World!

Step 3: Porting python to FriendlyArm

We will download the python in http://www.python.org.
We will use the example version 2.6.5

Once you have downloaded the python will unpack it using tar:

tar -xvzf Python-2.6.5.tgz

The result is the creation of the directory Python-2.6.5, now enter the created directory:

cd Python-2.6.5

Now, execute the following commands to create the components of the host:

./configure

make python Parser/pgen

mv hostpython python

mv Parser/Parser pgen/hostpgen

make distclean

The next step is to download the correct patch for your version of python which is located in:
http://www.4shared.com/file/AuTr9Rf6/Python-265-xcompile.html

Then we will apply the patch:

patch -p1 < Python-2.6.5-xcompile.patch

Then run the following commands:

CC=ppc_6xx-gcc CXX=ppc_6xx-g++ AR=ppc_6xx-ar RANLIB=ppc_6xx-ranlib ./configure –host=ppc-linux –build=i686-pc-linux-gnu –prefix=/python

make HOSTPYTHON=./hostpython HOSTPGEN=./Parser/hostpgen BLDSHARED=”ppc-linux-gcc -shared” CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes

make  install HOSTPYTHON=./hostpython BLDSHARED=”ppc-linux-gcc -shared” CROSS_COMPILE=ppc_6xx- CROSS_COMPILE_TARGET=yes prefix=~/Python-2.6.5/_install

This will install the binaries and libs in ~/Python-2.6.5/_install.

Copy the entire _install directory to the device, setup the PATH environment variable to include the location of the Python executable and run:

python lib/Python-2.6/test/test___all___.py

To accelerate the import of Python modules, we recommend creating one. Zip, with that we will not need to copy “all” the files manually.

cd _install/lib/python2.6

zip -r -y python26.zip .

Copy the _install/bin/python to the /usr/bin directory on the target:

Copy the python26.zip file to the /usr/lib directory on the target:
Create a directory named python2.6 /usr/lib and copy it to the following directories:

./lib/python2.6/config

./lib/python2.6/lib-dynload

./lib/python2.6/site-packages

The structure of your directory should be like the one below:

/usr/lib # ls

python2.6  python26.zip

/python/lib/python2.6 # ls

config  lib-dynload  site-package

Set the environment variable PYTHONHOME para /usr/ and you will already be running python in his FriendlyArm

Further, this process will build only the binary python, So the libraries will not be running.