arm-crosscompile-howto.sgml 16.9 KB
Newer Older
1 2 3
<!doctype linuxdoc system>
<linuxdoc><article>
<titlepag>
4
  <title>Cross compiling VLC for ARM-Linux based platforms</title>
5
  <author>Marc Ariberti <tt><htmlurl url="mailto:marcari@videolan.org" name="<marcari@videolan.org>"></tt></author>
6 7
  <author>Jean-Paul Saman <tt><htmlurl url="mailto:jpsaman@wxs.nl" name="<jpsaman@wxs.nl>"></tt></author>
  <date>v0.0.2, 19 march 2004</date>
8 9 10 11 12 13 14 15 16 17 18
  <abstract>
    This document describes all the steps to cross compile vlc for ARM based
    platforms. It describes how to build a cross compilation toolchain, how to
    build the libraries needed by vlc and the compilation of the vlc itself.
  </abstract>
</titlepag>

<toc>

<sect>
  <heading>Introduction</heading>
19 20 21 22 23
  <p>
  This document is only a first draft. It does not intend to cover all the 
  subject. You may still have some problems at some steps or find better 
  way to do them. If you have any comment do not hesitate to contact us.
  </p>
24
  <sect1>
25 26 27 28 29
    <heading>Which platforms are targeted ?</heading>
    <p>
      I will describe here how to compile vlc for an ARM based
      PDA running linux. It includes for example :
      <itemize>
30
      <item>Compaq - iPaq (H36xx, H38xx,...), using Familiar Linux
31
        <itemize>
32
          <item>GNU Portable Environment (GPE)
33 34 35 36 37 38 39
          <item>Opie
        </itemize>
      </item>
      <item>YOPY/Linupy</item>
      <item>Zaurus</item>
      </itemize>
    </p>
40 41 42 43 44
  </sect1> 
  <sect1>
    <heading>Requirements for cross-compilation</heading>
  </sect1>
  <sect1>
45 46 47 48 49 50 51 52 53 54 55 56 57 58
    <heading>Why cross-compiling ?</heading>
    <p>
      It is of course possible to compile directly on the targeted platform.
      But there are a lot of great advantages to cross-compile :
      <itemize>
      <item>The most important one is probably the speed, because a
        desktop computer is most of the time faster than a PDA for
        compilation.</item>
      <item>Another big problem is that a complete compilation toolchain
        does take a great amount of disk space. And this space is usually
        very limited on embedded systems.</item>
      <item>And there also may not be enough memory to compile big files.</item>
      </itemize>
    </p>
59 60 61 62 63 64
  </sect1>
</sect>

<sect>
  <heading>Building the toolchain</heading>
  <sect1>
65 66
    <heading>Prerequisite</heading>
    <sect2>
67
      <heading>Importants paths</heading>
68
      <p>
69
        During this section, we will use the following paths :
70
      </p>
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
      <p>I would personally advise to compile everything as a normal user and
      then install everything as root.</p>
      <sect3>
        <heading>${SRCDIR}</heading>
        <p>
        This is where the sources will be located and where the compilation
        will be done.
        (eg: <tt>/usr/src</tt> or <tt>/home/foobar/arm-src</tt>).
        </p>
      </sect3>
      <sect3>
        <heading>${PREFIX}</heading>
        <p>This is where you want to install your cross compilation toolchain.
        It can be either installed system-wide (in <tt>/usr/local/arm/2.95.3</tt> for example). Installation steps (i.e. <tt>make install</tt>) will have
        to be done as <tt>root</tt>.
        Or it can be installed in user-land, for the user's own use (<tt>/home/foobar/arm/2.95.3</tt> for example).
        In this paper, the chosen prefix is <tt>/usr/local/arm/2.95.3</tt>,
        you will have to adapt the commands to what you choose..
        </p>
      </sect3>
91 92 93
    </sect2>
    <sect2>
      <heading>Files needed</heading>
94 95
      <p>Download the following files and put them in the <bf>${SRCDIR}</bf>.
      Most of them are available on the <htmlurl url="http://www.videolan.org/vlc/download-sources.html" name="VideoLAN website">.
96 97 98 99
        <itemize>
          <item><tt>binutils-2.11.2.tar.gz</tt></item>
          <item><tt>linux-2.4.19.tar.bz2</tt></item>
          <item><tt>patch-2.4.19-rmk4.bz2</tt></item>
100 101 102 103 104 105 106 107 108 109 110 111 112
          <item><tt>gcc-2.95.3.tar.gz</tt></item>
          <item><tt>gcc-2.95.3.diff.bz2</tt></item>
          <item><tt>gcc-2.95.3.diffbis.bz2</tt></item>
          <item><tt>gcc-2.95.3.diff2</tt></item>
          <item><tt>glibc-2.2.5.tar.gz</tt></item>
          <item><tt>glibc-linuxthreads-2.2.5.tar.gz</tt></item>
          <item><tt>SDL-1.2.5.tar.gz</tt></item>
          <item><tt>glib-1.2.10.tar.gz</tt></item>
          <item><tt>ffmpeg.tar.gz</tt></item>
          <item><tt>mad-0.14.2b.tar.gz</tt></item>
          <item><tt>flac-1.1.0.tar.gz</tt></item>
          <item><tt>libdvbpsi-0.1.2.tar.gz</tt></item>
          <item><tt>a52dec-0.7.4.tar.gz</tt></item>
113 114 115
        </itemize>
      </p>
    </sect2>
116 117 118
  </sect1>
  <sect1>
    <heading>Binutils</heading>
119 120
    <p>Compiling binutils is pretty simple :
    <tscreen><verb>
121
tar -xzf binutils-2.11.2.tar.gz
122 123 124 125
cd binutils-2.11.2
./configure --target=arm-linux --prefix=/usr/local/arm/2.95.3
make
make install
126 127 128 129 130 131 132
    </verb></tscreen>
    </p>
  </sect1>
  <sect1>
    <heading>Preparing linux kernel</heading>
    <p>
    <tscreen><verb>
133
tar -xzf linux-2.4.19.tar.bz2
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
bunzip2 patch-2.4.19-rmk4.bz2
cd linux-2.4.19
patch -p1 &lt; ../patch-2.4.19-rmk4.bz2
make clean ARCH=arm CROSS_COMPILE=arm-linux-
make ARCH=arm h3600_config
  </verb></tscreen>
  <bf>Do not forget</bf> to save the configuration even if no changes 
  are made !
  <tscreen><verb>
make ARCH=arm menuconfig
make symlinks ARCH=arm CROSS_COMPILE=arm-linux-
mkdir -p /usr/local/arm/2.95.3/arm-linux/include
cp -Rf include/asm include/asm-arm include/linux \
                      /usr/local/arm/2.95.3/arm-linux/include
cd /usr/local/arm/2.95.3/arm-linux
ln -s include sys-linux
150 151 152 153 154 155
    </verb></tscreen>
    </p>
  </sect1>
  <sect1>
    <heading>Basic cross compiler (gcc)</heading>
    <p>
156
    <tscreen><verb>
157
tar -xvzf gcc-2.95.3.tar.gz
158 159 160 161 162 163 164 165 166 167
bunzip2 gcc-2.95.3.diff.bz2
bunzip2 gcc-2.95.3.diffbis.bz2
patch -p1 -d gcc-2.95.3 &lt; gcc-2.95.3.diff
patch -p1 -d gcc-2.95.3 &lt; gcc-2.95.3.diffbis
cd gcc-2.95.3
./configure --target=arm-linux --disable-threads --enable-languages=c \
        --prefix=/usr/local/arm/2.95.3 --with-headers=linux-2.4.19/include
make
make install
    </verb></tscreen>
168 169
    </p>

170 171 172
  </sect1>
  <sect1>
    <heading>Compiling glibc</heading>
173 174
    <p>
    Depending on your target, you may choose another glibc version (eg: 2.1.3 for linupy 1.4)
175
    <tscreen><verb>
176
tar -xvzf glibc-2.2.5.tar.gz
177
cd glibc-2.2.5
178
tar -xvzf ../glibc-linuxthreads-2.2.5.tar.gz
179 180 181
CC=arm-linux-gcc ./configure arm-linux --target=arm-linux \
          --prefix=/usr/local/arm/2.95.3/arm-linux --enable-add-ons
    </verb></tscreen>
182

183 184 185 186 187 188 189 190 191 192 193 194 195
The following step is quite long !

    <tscreen><verb>
CC=arm-linux-gcc make
    </verb></tscreen>

If you have problems compiling glibc due to pread/pwrite, edit <tt>sysdeps/unix/sysv/linux/kernel-features.h</tt>
and turn <tt>__ASSUME_PREAD_SYSCALL</tt> and 
<tt>__ASSUME_PWRITE_SYSCALL</tt> from 1 to 0.

    <tscreen><verb>
CC=arm-linux-gcc make install
    </verb></tscreen>
196 197 198 199
    </p>
  </sect1>
  <sect1>
    <heading>Full cross compiler (gcc)</heading>
200 201 202
    <p>
    <tscreen><verb>
rm -Rf gcc-2.95.3
203
tar -xvzf gcc-2.95.3.tar.gz
204 205 206 207 208 209 210 211 212 213 214
patch -p1 -d gcc-2.95.3 &lt; gcc-2.95.3.diff
patch -p1 -d gcc-2.95.3 &lt; gcc-2.95.3.diff2
cd gcc-2.95.3
./configure --target=arm-linux --prefix=/usr/local/arm/2.95.3
make
make install
    </verb></tscreen>
    </p>
  </sect1>
  <sect1>
    <heading>Compiling linux kernel</heading>
215 216 217
  </sect1>
  <sect1>
    <heading>Misc</heading>
218 219
    <p>
    Add <tt>/usr/local/arm/2.95.3/bin</tt> to your PATH. Add the following line (depends on your shell)
220
    to your shell's configuration file :
221 222 223 224 225 226 227
    <tscreen><verb>
export PATH=/usr/local/arm/2.95.3/bin:$PATH
    </verb></tscreen>
    I would advise you to completely log out and then log in again, so that
    the change would be taken into account. You can now check that when you
    type <tt>arm-linux-gcc</tt>, it launches the cross-compiler.
    </p>
228

229 230 231 232 233 234 235 236 237 238 239 240 241 242
    <p>
    Next are some packages that you may compile by yourself, but I found
    it was easier to use the precompiled packages. You can take them
    at <htmlurl url="http://ipkgfind.handhelds.org/" name="ipkgfind">.
    You may find packages with other version numbers which should not be
    a problem.
    <descrip>
    <tag><tt>libgcc1_3.1.1-1_arm.ipk</tt></tag>
        This provides libgcc.so.1 which is needed to compile some libraries.
    <tag><tt>xlibs_4.1-5_arm.ipk</tt>, <tt>xlibs-dev_4.1.0-16_arm.ipk</tt></tag>
        Those are the libraries ans the development files for X windows.
    <tag><tt>zlib1g_1.1.4-3_arm.ipk</tt>, <tt>zlib1g-dev_1.1.3-fam1_arm.ipk</tt></tag>
        These libraries are needed by some libraries to compile.
    </descrip>
243
    
244 245 246 247 248 249 250
    Install these packages on your compiler box in <tt>/usr/local/arm/2.95.3/arm-linux</tt> :
     You can use the script <tt>install.sh</tt> :
    <tscreen><verb>
#!/bin/sh
# script to install .ipk into the arm-toolchain
# usage : ./install.sh foobar.ipk

251
if ! tar -xvzf $1 2> /dev/null
252 253 254 255 256
then
    ar xv $1 2> /dev/null
fi
cp data.tar.gz /usr/local/arm/2.95.3/arm-linux
cd /usr/local/arm/2.95.3/arm-linux
257
tar -xvzf data.tar.gz
258 259
    </verb></tscreen>
    </p>
260 261 262
  </sect1>
</sect>

263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
<sect>
  <heading>Setting up Opie cross-compile environment</heading>
  <p>Download the Opie SDK from the website <htmlurl url="http://opie.handhelds.org/" name="OPIE website">
using the menuitem "Download Opie SDK" or try the direct link here: <htmlurl url="ftp://ftp.handhelds.org/zecke/" name="Download Opie SDK">.
Download all files to your ${SOURCES}/opie directory.
  </p>
  <sect1>
    <heading>Opie SDK</heading>
    <p>The Opie SDK does not come with a README file or installation instructions.
I give them here instead. There are two tar files in the download a OpieSDK.tar.gz2 and a kdevelop_src.tar.bz2.
The last file is a modified kdevelop for use with the OpieSDK. In this tutorial we will not use that.
Unpack OpieSDK.tar.bz2 in your sources <tt>cd ${SOURCES}/opie</tt> directory.
    <tscreen><verb>
cd ${SOURCES}/opie
tar -xjvf OpieSdk.tar.bz2
    </verb></tscreen>
    It creates a directories structure <tt>${SOURCES}/opie/opt/OpieSDK</tt>. Inside that directory a script is present to
<tt>start_kdevelop</tt>. Modify this script so that it uses the correct paths for you setup.
    <tscreen><verb>
#!/bin/sh
source ${SOURCES}/opie/opt/OpieSdk/dev_env
284

285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
export KDEDIR=${SOURCES}/opie/opt/OpieSdk/kde
export PATH=${SOURCES}/opie/opt/OpieSdk/kde/bin:$PATH
kbuildsycoca
kdevelop
    </verb></tscreen>
    Save the script. Do the same with the script <tt>arm_source</tt>
    <tscreen><verb>
source ${SOURCES}/opie/opt/OpieSdk/dev_env
export QTDIR=$QTDIR_ARM
export OPIEDIR=$OPIEDIR_ARM
    </verb></tscreen>
    Save the script and modify the script <tt>host_source</tt> in the same manner as above.
    <tscreen><verb>
source ${SOURCES}/opie/opt/OpieSdk/dev_env
export QTDIR=$QTDIR_NAT
export OPIEDIR=$OPIEDIR_NAT
    </verb></tscreen>
    Save the script and modify the script <tt>dev_env</tt> in the same manner as above.
    <tscreen><verb>
export PYTHONPATH=${SOURCES}/opie/opt/OpieSdk/python/opie:${SOURCES}/opie/opt/OpieSdk/python/sip
export PATH=/usr/local/arm/2.95.3/bin:/opt/OpieSdk/host_tools:${SOURCES}/opie/opt/OpieSdk/opie/x86/qt-2.3.7/bin:$PATH
export PATH=${SOURCES}/opie/opt/OpieSdk/opie/x86/qmake:$PATH
export QTDIR_NAT=${SOURCES}/opie/opt/OpieSdk/opie/x86/qt-2.3.7
export OPIEDIR_NAT=${SOURCES}/opie/opt/OpieSdk/opie/x86/sdk
export QTDIR_ARM=${SOURCES}/opie/opt/OpieSdk/opie/arm/qt-2.3.7
export OPIEDIR_ARM=${SOURCES}/opie/opt/OpieSdk/opie/arm/sdk
export OPIE_SDK_BASE=${SOURCES}/opie/opt/OpieSdk/
export OPIE_SDK_QMAKE_BASE=${SOURCES}/opie/opt/OpieSdk/opie/x86/sdk/mkspecs/qws/
export OPIE_DOC=${SOURCES}/opie/opt/OpieSdk/apidocs

export LD_LIBRARY_PATH=${SOURCES}/opie/opt/OpieSdk/sip/lib:$OPIEDIR_NAT/lib:$QTDIR_NAT/lib:$LD_LIBRARY_PATH
export OPIE_LANGUAGES=de:en:cz:da:dk:es:fr:hu:it:ja:ko:lv:mk:nl:no:pl:pt:pt_BR:ru:sl:zh_CN:zh_TW
    </verb></tscreen>
    The symbolic linke to the tool <tt>qmake</tt> points now to the wrong place. We need to fix this symbolic link.
Here is the way to do that.
    <tscreen><verb>
cd host_tools
ln -sf /home/jpsaman/src/opie/opt/OpieSdk/opie/x86/sdk/qmake/qmake qmake
cd ../
    </verb></tscreen>
    Now it is time to fire up our development environment and start hacking in Opie.
    </p>
  </sect1>
</sect>
329

330 331
<sect>
  <heading>Cross compiling libraries needed by vlc</heading>
332
  <p>
333 334 335
  Download <tt>ipaq-config.site</tt> to ${SOURCES}.
  When downloading source tarballs copy them to your ${SOURCES} directory.
  Each section is supposed to begin with <tt>cd ${SOURCES}</tt>.
336
  </p>
337 338
  <sect1>
    <heading>SDL</heading>
339 340 341 342 343 344 345 346 347 348
    <p>
    It is not clean at all but did not found a better working method.
    Using config.site
    it compiles well, but when linking with vlc there are problems !
    </p>
    <p>
    <tt>/usr/local/arm/2.95.3/arm-linux/bin</tt> should contain the cross 
    compiler without the prefix <tt>arm-linux-</tt>.
    
    <tscreen><verb>
349
tar -xvzf SDL-1.2.5.tar.gz
350
cd SDL-1.2.5
351
./configure --enable-release --target=arm-linux --host=arm-linux \
352 353 354 355 356 357
      --disable-esd \
      --prefix=/usr/local/arm/2.95.3/arm-linux/usr \
      --x-includes=/usr/local/arm/2.95.3/arm-linux/usr/X11R6/include \
      --x-libraries=/usr/local/arm/2.95.3/arm-linux/usr/X11R6/lib \
      --disable-video-opengl

358 359 360
export PATH=/usr/local/arm/2.95.3/arm-linux/bin:$PATH

make && make install
361 362
    </verb></tscreen>
    </p>
363 364 365
  </sect1>
  <sect1>
    <heading>Glib/GTK+</heading>
366 367
    <p>
    <tscreen><verb>
368
tar -xvzf glib-1.2.10.tar.gz
369 370 371 372 373 374
cd glib-1.2.10
CONFIG_SITE=../ipaq-config.site ./configure \
      --prefix=/usr/local/arm/2.95.3/arm-linux/usr
make
make install
cd ..
375
tar -xvzf gtk+-1.2.10.tar.gz
376 377 378 379 380 381 382
cd gtk+-1.2.10
CONFIG_SITE=../ipaq-config.site ./configure \
      --prefix=/usr/local/arm/2.95.3/arm-linux/usr --with-glib=../glib-1.2.10
make 
make install
    </verb></tscreen>
    </p>
383 384 385
  </sect1>
  <sect1>
    <heading>ffmpeg</heading>
386 387
    <p>
    <tscreen><verb>
388
tar -xvzf ffmpeg.tar.gz
389 390 391 392 393 394
cd ffmpeg
./configure --cpu=armv4l --cc=arm-linux-gcc --disable-mmx \
        --prefix=/usr/local/arm/2.95.3/arm-linux/usr --enable-shared
cd libavcodec
make
    </verb></tscreen>
395 396

    Vlc does not require that you install ffmpeg.
397
    </p>
398 399 400
  </sect1>
  <sect1>
    <heading>mad</heading>
401 402
    <p>
    <tscreen><verb>
403
tar -xvzf mad-0.14.2b.tar.gz
404
cd mad-0.14.2b
405
./configure --enable-release --target=arm-linux --host=arm-linux \
406 407 408 409 410
      --disable-esd \
      --prefix=/usr/local/arm/2.95.3/arm-linux/usr \
      --x-includes=/usr/local/arm/2.95.3/arm-linux/usr/X11R6/include \
      --x-libraries=/usr/local/arm/2.95.3/arm-linux/usr/X11R6/lib \
      --disable-video-opengl
411
export PATH=/usr/local/arm/2.95.3/arm-linux/bin:$PATH
412 413 414
make
    </verb></tscreen>
    </p>
415 416 417
  </sect1>
  <sect1>
    <heading>gpe</heading>
418 419 420
  </sect1>
  <sect1>
    <heading>tremor</heading>
421 422
    <p>
    Tremor is an integer decoder for the vorbis audio codec. Download the
423
    source through CVS at the <htmlurl url="http://www.xiph.org/" name="xiph.org"> website.
424 425 426 427 428 429 430 431 432 433 434 435
    </p>
    <p>
    Log into CVS using the password : <tt>anoncvs</tt>.
    <tscreen><verb>
cvs -d :pserver:anoncvs@xiph.org:/usr/local/cvsroot login
cvs -d :pserver:anoncvs@xiph.org:/usr/local/cvsroot co Tremor
cd Tremor
CONFIG_SITE=../ipaq-config.site ./configure \
              --prefix=/usr/local/arm/2.95.3/arm-linux/usr
make
</verb></tscreen>
    </p>
436 437 438
  </sect1>
  <sect1>
    <heading>ogg</heading>
439 440 441 442 443 444 445 446 447 448 449
    <p>
    For ogg, it is the same as Tremor.
    <tscreen><verb>
cvs -d :pserver:anoncvs@xiph.org:/usr/local/cvsroot login
cvs -d :pserver:anoncvs@xiph.org:/usr/local/cvsroot co ogg
cd ogg
CONFIG_SITE=../ipaq-config.site ./configure \
             --prefix=/usr/local/arm/2.95.3/arm-linux/usr
make
    </verb></tscreen>
    </p>
450 451 452
  </sect1>
  <sect1>
    <heading>flac</heading>
453 454
    <p>
    <tscreen><verb>
455
tar -xvzf flac-1.1.0.tar.gz
456 457 458 459 460 461 462 463 464 465 466 467
cd flac-1.1.0
./configure --enable-release --host=arm-linux --target=arm-linux \
            --prefix=/usr/local/arm/2.95.3/arm-linux/usr
    </verb></tscreen>
    It will probably fail (due to the xmms plugin), but it is not a problem, 
    we will continue installation by hand.
    <tscreen><verb>
cp -Rf include/FLAC /usr/local/arm/2.95.3/arm-linux/include
cd src/libFLAC
make install
    </verb></tscreen>
    </p>
468 469 470
  </sect1>
  <sect1>
    <heading>libdvbpsi</heading>
471 472
    <p>
    <tscreen><verb>
473
tar -xvzf libdvbpsi-0.1.2.tar.gz
474 475 476 477 478 479
cd libdvbpsi-0.1.2
./bootstrap
./configure --target=arm-linux --host=arm-linux
make
    </verb></tscreen>
    </p>
480 481 482
  </sect1>
  <sect1>
    <heading>a52</heading>
483 484
    <p>
    <tscreen><verb>
485
tar -xvzf a52dec-0.7.4.tar.gz
486 487 488 489 490 491
cd a52dec-0.7.4
./configure --enable-release --host=arm-linux --target=arm-linux \
            --prefix=/usr/local/arm/2.95.3/arm-linux/usr
make && make install
    </verb></tscreen>
    </p>
492 493 494 495 496
  </sect1>
</sect>

<sect>
  <heading>Cross compiling vlc itself</heading>
497 498 499 500 501 502 503 504 505 506 507 508
  <p>
  First of all, run the <tt>./bootstrap</tt> script.
  Then run one of the <tt>ipkg/rules.*</tt>, according to what you want to compile.
  Finally you just have to type make and you'll get a stand alone vlc.
  </p>
  <p>
  Run <tt>arm-linux-strip</tt> to remove symbols and so the size of the file,
  and now you can test it easily on your PDA.
  </p>
  <p>
    Enjoy !
  </p>
509 510
</sect>

511

512
</article></linuxdoc>