<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RandomSplat &#187; Cross-Compiling</title>
	<atom:link href="http://randomsplat.com/idcategory/cross-compiling/feed" rel="self" type="application/rss+xml" />
	<link>http://randomsplat.com</link>
	<description>Software Commentary</description>
	<lastBuildDate>Sat, 21 Jan 2012 12:26:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Building a Hard-float ARM Toolchain</title>
		<link>http://randomsplat.com/id192-building-a-hard-float-arm-toolchain.html</link>
		<comments>http://randomsplat.com/id192-building-a-hard-float-arm-toolchain.html#comments</comments>
		<pubDate>Sun, 04 Dec 2011 12:07:57 +0000</pubDate>
		<dc:creator>Paul Gibson</dc:creator>
				<category><![CDATA[arm]]></category>
		<category><![CDATA[Cross-Compiling]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[toolchain]]></category>
		<category><![CDATA[Cortex-A8]]></category>
		<category><![CDATA[cross-compile]]></category>
		<category><![CDATA[Embedded]]></category>
		<category><![CDATA[hard-float]]></category>
		<category><![CDATA[neon]]></category>
		<category><![CDATA[vfp]]></category>
		<category><![CDATA[vfpv3]]></category>

		<guid isPermaLink="false">http://randomsplat.com/?p=192</guid>
		<description><![CDATA[The ARM architecture receives a huge performance advantage by using a hard-float tool-chain, however most distributions only provide a soft-float tool-chain.  CodeSourcery charges a fee for a hard-float tool-chain, but this post will show you how to build one using crosstool-NG.

I'll specifically detail the process for a Cortex-A8, but the same principles apply for other ARM architectures.  My build environment is Ubuntu 11.10 with a Freescale i.MX53 Quick Start development board.]]></description>
			<content:encoded><![CDATA[<p>The ARM architecture receives a <a title="ArmHardFloatPort" href="http://wiki.debian.org/ArmHardFloatPort/VfpComparison" target="_blank">huge performance advantage</a> by using a hard-float tool-chain, however most distributions only provide a soft-float tool-chain.  <a title="Code Sourcery" href="http://codesourcery.com/">CodeSourcery</a> charges a fee for a hard-float tool-chain, but this post will show you how to build one using <a title="crosstool-NG" href="http://crosstool-NG.org/" target="_blank">crosstool-NG.</a></p>
<p>I&#8217;ll specifically detail the process for a Cortex-A8, but the same principles apply for other ARM architectures.  My build environment is Ubuntu 11.10 with a Freescale i.MX53 Quick Start development board.<span id="more-192"></span></p>
<p class="warning">This is a post for advanced gcc/Linux/Toolchain developers.  Please do not proceed unless you fully understand concepts such as hard-float (vfp and neon), soft-float, ARM, Linux and gcc linking.</p>
<p>Firstly, download and install the latest crosstool-NG (This post uses 1.13.2)</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>crosstool-ng.org<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>crosstool-ng<span style="color: #000000; font-weight: bold;">/</span>crosstool-ng-1.13.2.tar.bz2<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvjf</span> crosstool-ng-1.13.2.tar.bz2<br />
<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> crosstool-ng-1.13.2<br />
<br />
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #007800;">$PWD</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span><br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></div></div>
<p>Configure ct-ng:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>ct-ng menuconfig</div></div>
<p>Firstly, configure the paths and misc options.  This is mostly user dependent, but I thought I would show my settings:</p>

<a href="http://randomsplat.com/wp-content/gallery/hard-float/ct_paths_and_misc_options.png" title="" class="shutterset_singlepic8" >
	<img class="ngg-singlepic" src="http://randomsplat.com/wp-content/gallery/cache/8__575x320_ct_paths_and_misc_options.png" alt="ct_paths_and_misc_options" title="ct_paths_and_misc_options" />
</a>

<p>Then go into Target Options:</p>

<a href="http://randomsplat.com/wp-content/gallery/hard-float/ct_target_options.png" title="" class="shutterset_singlepic4" >
	<img class="ngg-singlepic" src="http://randomsplat.com/wp-content/gallery/cache/4__575x320_ct_target_options.png" alt="ct_target_options" title="ct_target_options" />
</a>

<p>You must configure for the vfpv3 floating point engine in this step and you must use -mfloat-abi=hard.  ARM processors will have different vfp options, such as <strong>vfpv3</strong> or <strong>vfpv3-d16</strong>.  You can also use <strong>neon</strong> here if you want.  Choose the right one for your processor.  The cortex-a8 tuning is an optimization step and is CPU dependent.</p>
<p>For reference the following are the equivalents in the configuration file:<br />
CT_ARCH_CPU=&#8221;cortex-a8&#8243;<br />
CT_ARCH_TUNE=&#8221;cortex-a8&#8243;<br />
CT_ARCH_FPU=&#8221;vfpv3&#8243;<br />
CT_TARGET_CFLAGS=&#8221;-mfloat-abi=hard -mfpu=vfpv3&#8243;</p>
<p>Then we configure the toolchain options.  Nothing really hard here, I have decided to give the toolchain a vendor string (cortex_a8) and an alias (arm-):</p>

<a href="http://randomsplat.com/wp-content/gallery/hard-float/ct_toolchain_options.png" title="" class="shutterset_singlepic5" >
	<img class="ngg-singlepic" src="http://randomsplat.com/wp-content/gallery/cache/5__575x320_ct_toolchain_options.png" alt="ct_toolchain_options" title="ct_toolchain_options" />
</a>

<p>Next, we look at the target Operating System.  I have used Linux 3.0.4 as my target operating system.</p>

<a href="http://randomsplat.com/wp-content/gallery/hard-float/ct_operating_system.png" title="" class="shutterset_singlepic3" >
	<img class="ngg-singlepic" src="http://randomsplat.com/wp-content/gallery/cache/3__575x320_ct_operating_system.png" alt="ct_operating_system" title="ct_operating_system" />
</a>

<p>Next we setup the binary utilities, nothing too exciting here:</p>

<a href="http://randomsplat.com/wp-content/gallery/hard-float/ct_binary_utilities.png" title="" class="shutterset_singlepic9" >
	<img class="ngg-singlepic" src="http://randomsplat.com/wp-content/gallery/cache/9__575x320_ct_binary_utilities.png" alt="ct_binary_utilities" title="ct_binary_utilities" />
</a>

<p>Now we come to the interesting part, the C-compiler settings and C-library settings.  To overcome the performance penalty of a soft-float toolchain, we need to rebuild everything as hard-float.  This includes the gcc libraries and glibc.</p>
<p>Firstly the C-compiler settings:</p>

<a href="http://randomsplat.com/wp-content/gallery/hard-float/ct_c_compiler.png" title="" class="shutterset_singlepic1" >
	<img class="ngg-singlepic" src="http://randomsplat.com/wp-content/gallery/cache/1__575x320_ct_c_compiler.png" alt="ct_c_compiler" title="ct_c_compiler" />
</a>

<p>You can setup any components of gcc that you require, but the important setup is <strong>Core gcc extra config</strong> and <strong>gcc extra config</strong>.  These must be set to &#8211;with-float=hard.</p>
<p>For reference they are these elements in the config file:</p>
<p>CT_CC_CORE_EXTRA_CONFIG_ARRAY=&#8221;&#8211;with-float=hard&#8221;<br />
CT_CC_EXTRA_CONFIG_ARRAY=&#8221;&#8211;with-float=hard&#8221;</p>
<p>Next, we setup the C-library options.  We must build glibc (or equivalent C library) with the correct hard-float options.</p>

<a href="http://randomsplat.com/wp-content/gallery/hard-float/ct_c_library.png" title="" class="shutterset_singlepic2" >
	<img class="ngg-singlepic" src="http://randomsplat.com/wp-content/gallery/cache/2__575x320_ct_c_library.png" alt="ct_c_library" title="ct_c_library" />
</a>

<p>In this case <strong>extra target CFLAGS</strong> and <strong>gcc extra flags</strong> must be set to -mfloat-abi=hard -mfpu=vfpv3.  These options are different to the C-compiler setup because in this case we are passing these options into the gcc to build glibc.  In the C-compiler setup, we were configuring gcc and gcc&#8217;s libraries (libgcc, libstdc++, etc).</p>
<p>For reference here are the equivalent parameters in the configuration file:</p>
<p>CT_LIBC_GLIBC_EXTRA_CFLAGS=&#8221;-U_FORTIFY_SOURCE -mfloat-abi=hard -mfpu=vfpv3&#8243;<br />
CT_LIBC_EXTRA_CC_ARGS=&#8221;-mfloat-abi=hard -mfpu=vfpv3&#8243;</p>
<p>&nbsp;</p>
<p>The next four configuration screens, Debug Facilities, Companion Libraries, Companian Tools and Test Suite, I will leave to the user to configure, but I will show the screen-shot of Companion Libraries in case you need it:</p>

<a href="http://randomsplat.com/wp-content/gallery/hard-float/ct_companion_libraries.png" title="" class="shutterset_singlepic11" >
	<img class="ngg-singlepic" src="http://randomsplat.com/wp-content/gallery/cache/11__575x320_ct_companion_libraries.png" alt="ct_companion_libraries" title="ct_companion_libraries" />
</a>

<p>Ok, so the configuring is done. At this stage you may want to review the <a title="crosstool-NG" href="http://crosstool-NG.org/">crosstool-NG</a> instructions to make sure that your machine is setup correctly to build the toolchain.</p>
<p>Lets build the toolchain.  Firstly, create the tarballs directory we used in configure:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> tarballs</div></div>
<p>Build the toolchain using ct-ng.  My example uses 8 cores, but you should adjust this for your build machine:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>ct-ng build.8</div></div>
<p>Well, the toolchain will probably take 30 minutes to build on an i7.   If all goes well you will end up with a build log like this:</p>
<pre>[INFO ]  Performing some trivial sanity checks
[INFO ]  Build started 20111204.164331
[INFO ]  Building environment variables
[EXTRA]  Preparing working directories
[EXTRA]  Installing user-supplied crosstool-NG configuration
[EXTRA]  =================================================================
[EXTRA]  Dumping internal crosstool-NG configuration
[EXTRA]    Building a toolchain for:
[EXTRA]      build  = x86_64-unknown-linux-gnu
[EXTRA]      host   = x86_64-unknown-linux-gnu
[EXTRA]      target = arm-cortex_a8-linux-gnueabi
[EXTRA]  Dumping internal crosstool-NG configuration: done in 0.10s (at 00:02)
[INFO ]  =================================================================
[INFO ]  Retrieving needed toolchain components' tarballs
[INFO ]  Retrieving needed toolchain components' tarballs: done in 0.16s (at 00:02)
[INFO ]  =================================================================
[INFO ]  Extracting and patching toolchain components
[INFO ]  Extracting and patching toolchain components: done in 3.87s (at 00:06)
[INFO ]  =================================================================
[INFO ]  Installing GMP
[EXTRA]    Configuring GMP
[EXTRA]    Building GMP
[EXTRA]    Installing GMP
[INFO ]  Installing GMP: done in 43.53s (at 00:50)
[INFO ]  =================================================================
[INFO ]  Installing MPFR
[EXTRA]    Configuring MPFR
[EXTRA]    Building MPFR
[EXTRA]    Installing MPFR
[INFO ]  Installing MPFR: done in 16.18s (at 01:06)
[INFO ]  =================================================================
[INFO ]  Installing PPL
[EXTRA]    Configuring PPL
[EXTRA]    Building PPL
[EXTRA]    Installing PPL
[INFO ]  Installing PPL: done in 165.04s (at 03:51)
[INFO ]  =================================================================
[INFO ]  Installing CLooG/ppl
[EXTRA]    Configuring CLooG/ppl
[EXTRA]    Building CLooG/ppl
[EXTRA]    Installing CLooG/ppl
[INFO ]  Installing CLooG/ppl: done in 7.06s (at 03:58)
[INFO ]  =================================================================
[INFO ]  Installing MPC
[EXTRA]    Configuring MPC
[EXTRA]    Building MPC
[EXTRA]    Installing MPC
[INFO ]  Installing MPC: done in 9.58s (at 04:08)
[INFO ]  =================================================================
[INFO ]  Installing binutils
[EXTRA]    Configuring binutils
[EXTRA]    Building binutils
[EXTRA]    Installing binutils
[INFO ]  Installing binutils: done in 39.71s (at 04:47)
[INFO ]  =================================================================
[INFO ]  Installing static core C compiler
[EXTRA]    Configuring static core C compiler
[EXTRA]    Building static core C compiler
[EXTRA]    Installing static core C compiler
[INFO ]  Installing static core C compiler: done in 146.93s (at 07:14)
[INFO ]  =================================================================
[INFO ]  Installing kernel headers
[EXTRA]    Installing kernel headers
[EXTRA]    Checking installed headers
[INFO ]  Installing kernel headers: done in 8.98s (at 07:23)
[INFO ]  =================================================================
[INFO ]  Installing C library headers &amp; start files
[EXTRA]    Configuring C library
[EXTRA]    Installing C library headers
[EXTRA]    Installing C library start files
[INFO ]  Installing C library headers &amp; start files: done in 45.50s (at 08:09)
[INFO ]  =================================================================
[INFO ]  Installing shared core C compiler
[EXTRA]    Configuring shared core C compiler
[EXTRA]    Building shared core C compiler
[EXTRA]    Installing shared core C compiler
[INFO ]  Installing shared core C compiler: done in 163.11s (at 10:52)
[INFO ]  =================================================================
[INFO ]  Installing C library
[EXTRA]    Configuring C library
[EXTRA]    Building C library
[EXTRA]    Installing C library
[INFO ]  Installing C library: done in 483.20s (at 18:55)
[INFO ]  =================================================================
[INFO ]  Installing final compiler
[EXTRA]    Configuring final compiler
[EXTRA]    Building final compiler
[EXTRA]    Installing final compiler
[INFO ]  Installing final compiler: done in 257.40s (at 23:13)
[INFO ]  =================================================================
[INFO ]  Installing binutils for target
[EXTRA]    Configuring binutils for target
[EXTRA]    Building binutils' libraries (libiberty bfd) for target
[EXTRA]    Installing binutils' libraries (libiberty bfd) for target
[INFO ]  Installing binutils for target: done in 74.09s (at 24:27)
[INFO ]  =================================================================
[INFO ]  Installing native gdb
[EXTRA]    Building static target ncurses
[EXTRA]    Building static target expat
[EXTRA]    Configuring native gdb
[EXTRA]    Building native gdb
[EXTRA]    Installing native gdb
[EXTRA]    Cleaning up ncurses
[INFO ]  Installing native gdb: done in 241.59s (at 28:28)
[INFO ]  =================================================================
[INFO ]  Installing gdbserver
[EXTRA]    Configuring gdbserver
[EXTRA]    Building gdbserver
[EXTRA]    Installing gdbserver
[INFO ]  Installing gdbserver: done in 14.77s (at 28:43)
[INFO ]  =================================================================
[INFO ]  Installing GCC test suite
[INFO ]  Installing GCC test suite: done in 34.60s (at 29:18)
[INFO ]  =================================================================
[INFO ]  Cleaning-up the toolchain's directory
[EXTRA]    Installing the populate helper
[EXTRA]    Installing a cross-ldd helper
[EXTRA]    Creating toolchain aliases
[EXTRA]    Removing access to the build system tools
[EXTRA]    Removing installed documentation
[INFO ]  Cleaning-up the toolchain's directory: done in 0.79s (at 29:19)
[INFO ]  Build completed at 20111204.171250
[INFO ]  (elapsed: 29:18.74)
[INFO ]  Finishing installation (may take a few seconds)...</pre>
<p class="warning">One final word of note: This is a hard-float toolchain and you cannot link any soft-float code to it.  You will have to rebuild all of your software with this toolchain and use the following options:</p>
<p>-mfloat-abi=hard -mfpu=vfpv3 -march=armv7-a -mtune=cortex-a8</p>
<p>Otherwise you will get linker errors like this:</p>
<div class="codecolorer-container bash blackboard" style="border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>paulg<span style="color: #000000; font-weight: bold;">/</span>hmccore-arm<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>arm-cortex_a8-linux-gnueabi<span style="color: #000000; font-weight: bold;">/</span>4.6.2<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>arm-cortex_a8-linux-gnueabi<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ld: error: hello uses VFP register arguments, <span style="color: #7a0874; font-weight: bold;">test</span> does not <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>paulg<span style="color: #000000; font-weight: bold;">/</span>hmccore-arm<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>arm-cortex_a8-linux-gnueabi<span style="color: #000000; font-weight: bold;">/</span>4.6.2<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>..<span style="color: #000000; font-weight: bold;">/</span>arm-cortex_a8-linux-gnueabi<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>ld: failed to merge target specific data of <span style="color: #c20cb9; font-weight: bold;">file</span> hello collect2: <span style="color: #c20cb9; font-weight: bold;">ld</span> returned <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">exit</span> status</div></div>
<pre>Specifically note the "xxxx uses VFP register arguments, yyyy does not" error.</pre>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://randomsplat.com/id192-building-a-hard-float-arm-toolchain.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross Compiling Python for Embedded Linux</title>
		<link>http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html</link>
		<comments>http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html#comments</comments>
		<pubDate>Wed, 16 Nov 2011 04:48:14 +0000</pubDate>
		<dc:creator>Paul Gibson</dc:creator>
				<category><![CDATA[arm]]></category>
		<category><![CDATA[Cross-Compiling]]></category>
		<category><![CDATA[Embedded Linux]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PowerPC]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Embedded]]></category>

		<guid isPermaLink="false">http://randomsplat.com/?p=5</guid>
		<description><![CDATA[This article details how to cross compile Python for the ARM and PowerPC platforms.  It should apply equally to other platforms just plug in the correct cross-compiler.  The article supports Python versions 2.6.6, 2.7.2 and 3.1.1, 3.1.2, 3.1.3, 3.2.2.]]></description>
			<content:encoded><![CDATA[<p>This article details how to cross compile Python for the ARM and PowerPC platforms.  It should apply equally to other platforms as well, just plug-in the correct cross-compiler.  The article supports Python versions, 2.6.6 (Thanks to evadeflow), 2.7.2 and 3.1.1, 3.1.2, 3.1.3, 3.2.2.<span id="more-5"></span></p>
<p>Firstly, download the Python that you want to use from <a href="http://www.python.org">http://www.python.org/</a></p>
<p>Unpack the Python package using tar:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xvzf</span> Python-2.7.2.tgz</div></div>
<p>This will create a directory called Python-2.7.2.  Goto the directory:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> Python-2.7.2</div></div>
<p>Then run these commands to build the host components:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">.<span style="color: #000000; font-weight: bold;">/</span>configure<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> python Parser<span style="color: #000000; font-weight: bold;">/</span>pgen<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">mv</span> python hostpython<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">mv</span> Parser<span style="color: #000000; font-weight: bold;">/</span>pgen Parser<span style="color: #000000; font-weight: bold;">/</span>hostpgen<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> distclean</div></div>
<p>Download the correct patch for your version of Python:</p>
<ul>
<li><a href="../wp-content/uploads/2010/10/Python-2.6.6-xcompile.patch">Python-2.6.6-xcompile.patch</a></li>
<li><a href="http://randomsplat.com/wp-content/uploads/2011/10/Python-2.7.2-xcompile.patch">Python-2.7.2-xcompile.patch</a> (With ctypes thanks to Jaux (<a title="http://jaux.net" href="http://jaux.net/">jaux.net</a>)</li>
<li><a href="http://randomsplat.com/wp-content/uploads/2009/08/Python-3.1.1-xcompile.patch">Python-3.1.1-xcompile.patch</a></li>
<li><a href="../wp-content/uploads/2010/04/Python-3.1.2-xcompile.patch">Python-3.1.2-xcompile.patch</a></li>
<li><a href="../wp-content/uploads/2011/01/Python-3.1.3-xcompile.patch">Python-3.1.3-xcompile.patch</a></li>
<li><a href="http://randomsplat.com/wp-content/uploads/2011/10/Python-3.2.2-xcompile.patch">Python-3.2.2-xcompile.patch</a></li>
</ul>
<p>Then apply the patch:</p>
<p><code class="codecolorer text blackboard"><span class="text">patch -p1 &lt; Python-2.7.2-xcompile.patch</span></code></p>
<p>Then run this (where ~/Python-2.7.2/_install/ is your desired installation path).  Note also that you must replace all instances of the cross compiler and the host build system in the lines below.  If you are on an x86_64 machine, then you should use x86_64-linux-gnu as the host.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">CC</span>=ppc_6xx-gcc <span style="color: #007800;">CXX</span>=ppc_6xx-g++ <span style="color: #007800;">AR</span>=ppc_6xx-ar <span style="color: #007800;">RANLIB</span>=ppc_6xx-ranlib .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--host</span>=ppc-linux <span style="color: #660033;">--build</span>=x86_64-linux-gnu <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>python<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #007800;">HOSTPYTHON</span>=.<span style="color: #000000; font-weight: bold;">/</span>hostpython <span style="color: #007800;">HOSTPGEN</span>=.<span style="color: #000000; font-weight: bold;">/</span>Parser<span style="color: #000000; font-weight: bold;">/</span>hostpgen <span style="color: #007800;">BLDSHARED</span>=<span style="color: #ff0000;">&quot;ppc_6xx-gcc -shared&quot;</span> <span style="color: #007800;">CROSS_COMPILE</span>=ppc_6xx- <span style="color: #007800;">CROSS_COMPILE_TARGET</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span> <span style="color: #007800;">HOSTARCH</span>=ppc-linux <span style="color: #007800;">BUILDARCH</span>=x86_64-linux-gnu<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #007800;">HOSTPYTHON</span>=.<span style="color: #000000; font-weight: bold;">/</span>hostpython <span style="color: #007800;">BLDSHARED</span>=<span style="color: #ff0000;">&quot;ppc_6xx-gcc -shared&quot;</span> <span style="color: #007800;">CROSS_COMPILE</span>=ppc_6xx- <span style="color: #007800;">CROSS_COMPILE_TARGET</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span> <span style="color: #007800;">prefix</span>=~<span style="color: #000000; font-weight: bold;">/</span>Python-2.7.2<span style="color: #000000; font-weight: bold;">/</span>_install</div></div>
<p>This will install all your python binaries and libraries in ~/Python-2.7.2/_install.</p>
<p>Copy the entire _install directory to the device, setup the PATH environment variable to include the path the Python executable and run:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">python lib<span style="color: #000000; font-weight: bold;">/</span>Python-<span style="color: #000000;">2.7</span><span style="color: #000000; font-weight: bold;">/</span>test<span style="color: #000000; font-weight: bold;">/</span>test___all___.py</div></div>
<p>&#8230;and hopefully all the tests will run correctly.</p>
<p>To speed up the importing of Python modules on the target, I recommend to zip up the lib directory to make a file called python27.zip.  This means that we do not have to copy all the Python files to the target, just the one zip file.  This technique might also save space, but that depends on your file system.  On the host machine:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> _install<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>python2.7<br />
<br />
<span style="color: #c20cb9; font-weight: bold;">zip</span> <span style="color: #660033;">-r</span> <span style="color: #660033;">-y</span> python27.zip .</div></div>
<p>Delete libpythonxxx.a site-packages, lib-dynload, config and anything else you do not need from the python27.zip file.</p>
<p>Copy the _install/bin/python to the /usr/bin directory on the target:</p>
<p>Copy the python27.zip file to the /usr/lib directory on the target:</p>
<p>Create a directory on the target called python2.7 in the /usr/lib directory and copy the following directories to that directory:</p>
<ul>
<li>./lib/python2.7/config</li>
<li>./lib/python2.7/lib-dynload</li>
<li>./lib/python2.7/site-packages</li>
</ul>
<p>Your directory structure on the target must be as follows:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib <span style="color: #666666; font-style: italic;"># ls</span><br />
<br />
python2.7 python27.zip<br />
<br />
<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>python2.7 <span style="color: #666666; font-style: italic;"># ls</span><br />
<br />
config lib-dynload site-packages</div></div>
<p>Set the PYTHONHOME environment variable to /usr/ and you are ready to run Python on the target.</p>
<p>The above patches are based on Chris Lambacher&#8217;s patches for Python 2.5 here:</p>
<p><a href="http://whatschrisdoing.com/blog/2006/10/06/howto-cross-compile-python-25/">http://whatschrisdoing.com/blog/2006/10/06/howto-cross-compile-python-25/</a></p>
<p>Other links and credits:</p>
<p><a href="http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html">http://www.ailis.de/~k/archives/19-ARM-cross-compiling-howto.html</a></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 570px; width: 1px; height: 1px;"><a href="http://randomsplat.com/wp-content/uploads/2009/08/Python-2.6.2-xcompile.patch">Python-2.6.2-xcompile.patch</a></div>
]]></content:encoded>
			<wfw:commentRss>http://randomsplat.com/id5-cross-compiling-python-for-embedded-linux.html/feed</wfw:commentRss>
		<slash:comments>76</slash:comments>
		</item>
	</channel>
</rss>

