Cross Compile Python 2.7.3 for UltraSAM Platform

Posted by: Mubashir Chaudhry Comments: 0 0 Post Date: 20/11/2014

If you want to just use Python for UltraSAM, it is here.

1. Setup cross compiler

  1. Download and install Ubuntu 12.04 64 bit Edition

Note: Theoretically, other Linux distribution should also work. In this document, Ubuntu 12.04 64 bit Edition is used.

  1. Signup and download Sourcery CodeBench Lite Edition for ARM GNU (IA32 GNU/Linux TAR)
  1. Extract the achieve file to /opt/
  1. Add the compiler to environment variable

    [bash]sudo gedit /etc/environment[/bash]

    Add save the following and exit

    [bash]PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/arm-2012.03/bin"[/bash]

  1. Open a terminal and try command

    [bash]arm-none-linux-gnueabi-gcc –version[/bash]

    It should print out the version number. Now the cross compiler is working.

2. Cross compile Python2.7.3  from source

  1. Download and extract Python 2.7.3 source file
  1. Download Python 2.7.3 cross compile patch file and place it into the Python 2.7.3 source folder
  1. Lunch a terminal run the following commands one by one

    [bash]
    ./configure

    make python Parser/pgen

    mv python hostpython

    mv Parser/pgen Parser/hostpgen

    make distclean

    patch -p1 < Python-2.7.3-xcompile.patch

    CC=arm-none-linux-gnueabi-gcc CXX=arm-none-linux-gnueabi-g++ AR=arm-none-linux-gnueabi-ar RANLIB=arm-none-linux-gnueabi-ranlib ./configure –host=arm-linux-gnueabi –build=x86_64-linux-gnu –prefix=/python

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

    make install HOSTPYTHON=./hostpython BLDSHARED=" arm-none-linux-gnueabi-gcc -shared" CROSS_COMPILE=arm-none-linux-gnueabi- CROSS_COMPILE_TARGET=yes prefix=~/Python/ARM_Python/Python-2.7.3/_install

    arm-none-linux-gnueabi-strip –strip-unneeded ~/Python/ARM_Python/Python-2.7.3/_install/bin/python2.7
    [/bash]

    1. Check the binary file property by

    [bash]file ~/Python/ARM_Python/Python-2.7.3/_install/bin/python2.7[/bash]

     

    It should reports something like below:

    [bash]python2.7: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, stripped[/bash]

    Congratulations! You just cross compiled Python for UltraSAM.

    The ARM executable Python is located at ~/Python/ARM_Python/Python-2.7.3/_install/

Share this post