Debian Codegraph @

rpython/doc/arm.rst

raw
1 .. _arm:
2
3 Cross-translating for ARM
4 =========================
5
6 .. note::
7
8 The information here is unfortunately only of historical value. Scratchbox is
9 no longer functional. However it seems translation of ARM32 is possible on a
10 aarch64 machine using chroot and ``setarch linux32 pypy rpython/bin/rpython
11 ...``
12
13 Here we describe the setup required and the steps needed to follow to translate
14 an interpreter using the RPython translator to target ARM using a cross
15 compilation toolchain.
16
17 To translate an RPython program for ARM we can either
18 translate directly on an ARM device following the normal translation steps.
19 Unfortunately this is not really feasible on most ARM machines. The
20 alternative is to cross-translate using a cross-compilation toolchain.
21
22 To cross-translate we run the translation on a more powerful (usually
23 x86) machine and generate a binary for ARM using a cross-compiler to compile
24 the generated C code. There are several constraints when doing this. In
25 particular we currently only support Linux as translation host and target
26 platforms (tested on Ubuntu). Also we need a 32-bit environment to run the
27 translation. This can be done either on a 32bit host or in 32bit chroot.
28
29
30 Requirements
31 ------------
32
33 The tools required to cross translate from a Linux based host to an ARM based Linux target are:
34
35 - A checkout of PyPy (default branch).
36 - The GCC ARM cross compiler (on Ubuntu it is the ``gcc-arm-linux-gnueabi package``) but other
37 toolchains should also work.
38 - Scratchbox 2, a cross-compilation engine (``scratchbox2`` Ubuntu package).
39 - A 32-bit PyPy or Python.
40 - And the following (or corresponding) packages need to be installed to create an ARM based chroot:
41
42 * ``debootstrap``
43 * ``schroot``
44 * ``binfmt-support``
45 * ``qemu-system``
46 * ``qemu-user-static``
47
48 - The dependencies above are in addition to the ones needed for a regular
49 translation, `listed here`_.
50
51 .. _`listed here`: http://pypy.readthedocs.org/en/latest/build.html#install-build-time-dependencies
52
53
54 Creating a Qemu based ARM chroot
55 --------------------------------
56
57 First we will need to create a rootfs containing the packages and dependencies
58 required in order to translate PyPy or other interpreters. We are going to
59 assume, that the files will be placed in ``/srv/chroot/precise_arm``.
60
61 Create the rootfs by calling:
62
63 ::
64
65 mkdir -p /srv/chroot/precise_arm
66 qemu-debootstrap --variant=buildd --arch=armel precise /srv/chroot/precise_arm/ http://ports.ubuntu.com/ubuntu-ports/
67
68 Next, copy the qemu-arm-static binary to the rootfs.
69
70 ::
71
72 cp /usr/bin/qemu-arm-static /srv/chroot/precise_arm/usr/bin/qemu-arm-static
73
74 For easier configuration and management we will create a schroot pointing to
75 the rootfs. We need to add a configuration block (like the one below) to the
76 schroot configuration file in /etc/schroot/schroot.conf.
77
78
79 ::
80
81 [precise_arm]
82 directory=/srv/chroot/precise_arm
83 users=USERNAME
84 root-users=USERNAME
85 groups=users
86 aliases=default
87 type=directory
88
89
90 To verify that everything is working in the chroot, running ``schroot -c
91 precise_arm`` should start a shell running in the schroot environment using
92 qemu-arm to execute the ARM binaries. Running ``uname -m`` in the chroot should
93 yield a result like ``armv7l``. Showing that we are emulating an ARM system.
94
95 Start the schroot as the user root in order to configure the apt sources and
96 to install the following packages:
97
98 ::
99
100 schroot -c precise_arm -u root
101 echo "deb http://ports.ubuntu.com/ubuntu-ports/ precise main universe restricted" > /etc/apt/sources.list
102 apt-get update
103 apt-get install libffi-dev libgc-dev python-dev build-essential libncurses5-dev libbz2-dev
104
105
106 Now all dependencies should be in place and we can exit the schroot environment.
107
108
109 Configuring scratchbox2
110 -----------------------
111
112 To configure the scratchbox we need to cd into the root directory of the rootfs
113 we created before. From there we can call the sb2 configuration tools which
114 will take the current directory as the base directory for the scratchbox2
115 environment.
116
117 ::
118
119 cd /srv/chroot/precise_arm
120 sb2-init -c `which qemu-arm` ARM `which arm-linux-gnueabi-gcc`
121
122 This will create a scratchbox2 based environment called ARM that maps calls to
123 gcc done within the scratchbox to the arm-linux-gnueabi-gcc outside the
124 scratchbox. Now we should have a working cross compilation toolchain in place
125 and can start cross-translating programs for ARM.
126
127 Translation
128 -----------
129
130 Having performed all the preliminary steps we should now be able to cross
131 translate a program for ARM. You can use this minimal
132 target to test your setup before applying it to a larger project.
133
134 Before starting the translator we need to set two environment variables, so the
135 translator knows how to use the scratchbox environment. We need to set the
136 **SB2** environment variable to point to the rootfs and the **SB2OPT** should
137 contain the command line options for the sb2 command. If our rootfs is in the
138 folder /srv/chroot/precise_arm and the scratchbox environment is called "ARM",
139 the variables would be defined as follows.
140
141 ::
142
143 export SB2=/srv/chroot/precise_arm
144 export SB2OPT='-t ARM'
145
146 Once this is set, you can call the translator. For example save this file
147
148 ::
149
150 def main(args):
151 print "Hello World"
152 return 0
153
154 def target(*args):
155 return main, None
156
157 and call the translator
158
159 ::
160
161 pypy ~/path_to_pypy_checkout/rpython/bin/rpython -O2 --platform=arm target.py
162
163 If everything worked correctly this should yield an ARM binary. Running this
164 binary in the ARM chroot or on an ARM device should produce the output
165 ``"Hello World"``.
166
167 To translate the full python pypy interpreter with a jit, you can cd into pypy/goal and call
168
169 ::
170
171 pypy <path to rpython>/rpython/bin/rpython -Ojit --platform=arm targetpypystandalone.py
172
173