Setting up a cross-compilation toolchain
Actually, we are still in the testing phase, for now, check out the forum discussion (topic: cross-compilation [1]).
Toolchains 101
A toolchain is a set of executable programs that enables you to build (assemble, compile and link) your own executable programs from source code (typically C, C++, fortran or other programming languages). To build these executables, the source code needs to be translated into machine-readable code. This is what a toolchain does. The translation proceeds in three steps (well, you may think of it this way): translation into low-level code (compilation), translation to machine-readable code (assembly), combination with other code libraries (linking). Compilation/assembly mostly proceeds in a single go. So, for a toolchain you need at least three programs: a compiler, an assembler, and a linker. In almost all cases you will also need a C-library to link with.
Unlike source code, executables are machine-specific. That means that executables built for the Intel x86 architecture (the basis for most computers in the world today) will not run on other types of processors, for example the ARM architecture, the basis for many embedded systems. Our Sammys are ARM-based machines. To build executables for a Samsung TV on an x86-based machine, you will need a toolchain that runs on the x86-architecture and builds executable code for the ARM-architecture. This procedure is called cross-compilation, and requires a cross compilation toolchain. This wiki page deals with the installation of the toolchain provided by Samsung, on an x86, Linux or Windows (Cygwin) platform.
Samsung toolchain
The source code for the Samsung ARM toolchain is available on the net, but needs some adjustments before it can be built. We will discuss that later. The main parts are:
- GNU binutils (containing among other things an assembler and a linker)
- GCC, the GNU C/C++ compiler (and a host of other languages we will not use)
- Glibc, the GNU C library
- linux kernel sources, for operating system/processor specific details.
For the remainder of this wiki page, we will use the toolchain for the 32B650/32B550/... TV's as an example. The source code for this toolchain is stored in the file 32B650.zip. Download this file and store it in the directory where you want to build your toolchain. Download the SamyGO patches that enable compilation of the toolchain here: [2]
Building the toolchain on Linux
Since most Linux distro's come standard with a full toolchain for building packages, building the cross-compilation toolchain on this platform is fairly straightforward, and proceeds in 6 stages.
1: Unpack and install the source code files. This is done with the script install_sources.sh: edit paths and code versions to your liking:
#! /bin/sh # # install_sources.sh installs the source code for the toolchain for Samsung # TV's, as found in the file 32B650.zip. Place this file together with the # patches tarball (SamyGO-toolchain_fc11_patches.tgz) in the ${BUILDROOT} # directory, defined below, and run this script. # BUILDROOT=/tmp/arm-tools # edit according to your needs. cd ${BUILDROOT} mkdir -p ${BUILDROOT}/src # unpack the Samsung zip file unzip 32B650.zip # remove unnecessary stuff and move the kernel and toolchain code rm -f libgphoto2-2.3.1.tar.zip rm -f libusb-0.1.12.tar.gz rm -f SDL-1.2.11.zip mv linux.chelsea.tgz ${BUILDROOT}/src # unpack the toolchain and remove unnecessary stuff tar -zxvf SELP.3.2.x-Chelsea.src.tgz rm -f SELP.3.2.x-Chelsea.src.tgz mv ./SELP.3.2.x-Chelsea.src/Toolchain/gcc-4.2.0-4.0.9.tgz ${BUILDROOT}/src mv ./SELP.3.2.x-Chelsea.src/Toolchain/binutils-2.17.50.tgz ${BUILDROOT}/src mv ./SELP.3.2.x-Chelsea.src/Toolchain/glibc-2.5.90-9.0.9.tgz ${BUILDROOT}/src rm -rf ./SELP.3.2.x-Chelsea.src # unpack the patches and move them tar -zxvf SamyGO-toolchain_fc11_patches.tgz mv *.patch ${BUILDROOT}/src
2: Install the kernel header files. You will need these when you want to build your own kernel modules for your TV. For that, the kernel source code's version has to match your TV's kernel version _exactly_. The installation is done with the install_kernel_src.sh script: again, edit to meet your needs.
#! /bin/sh # how to install kernel headers using this script: # # Create the ${BUILDROOT} directory, put this script (install_kernel_src.sh) # in it. # In ${BUILDROOT}, create a directory ./src and put the linux tarball in it. # go up one directory and run this script. TARGET=arm-SamyGO-linux-gnueabi BUILDROOT=/tmp/arm-tools PREFIX=/usr/local # change to your needs SYSROOT=${BUILDROOT}/sysroot export ARCH=arm export CROSS_COMPILE=${TARGET}- export PATH=$PATH:${PREFIX}/bin cd ${BUILDROOT}/src # remove previous installation if it is there: rm -rf linux rm -rf linux-r011 rm -rf RFS rm -rf ssdtv_platform # unpack, move up one dir and link: tar -zxvf linux.chelsea.tgz # from 32B650.zip mv ./linux/* . rm -rf linux/ ln -s ./linux-r011 linux cd linux # copy header files to sysroot: mkdir -p ${SYSROOT}/usr/include cp -a ${BUILDROOT}/src/linux/include/linux ${SYSROOT}/usr/include/linux cp -a ${BUILDROOT}/src/linux/include/asm-arm ${SYSROOT}/usr/include/asm cp -a ${BUILDROOT}/src/linux/include/asm-generic ${SYSROOT}/usr/include/asm-generic # remove stale link to ssdtv headers: rm -rf ${SYSROOT}/usr/include/asm/arch-ssdtv # ... and copy these as well: cp -a ${BUILDROOT}/src/ssdtv_platform/include/asm-arm/arch-ssdtv ${SYSROOT}/usr/include/asm
Everything is now installed (but not yet unpacked). The remainder of the installation consists of the actual building of the tools: First the binutils are built: as, ld and a bunch of others. For cross-compilation, these tools do not need any resources for the target platform (ARM, in this case).
3: Building of the binutils. Apart from a small bug in one of the source files and a configuration change to be made to part of the code (patches are included) the build is straightforward, done with mkbinutils.sh:
#! /bin/sh # how to build binutils using this script: # # Create the ${BUILDROOT} directory, put this script (mkbinutils.sh) in it. # In ${BUILDROOT}, create a directory ./src and put the binutils tarball and # the patch in it. # go up one directory and run this script. TARGET=arm-SamyGO-linux-gnueabi BUILDROOT=/tmp/arm-tools # change to your needs PREFIX=/usr/local # change to your liking SYSROOT=${BUILDROOT}/sysroot UTILS=binutils-2.17.50 export ARCH=arm export CROSS_COMPILE=${TARGET}- export PATH=$PATH:${PREFIX}/bin cd ${BUILDROOT}/src tar -zxvf binutils-2.17.50.tgz # from 32B650.zip patch -p0 < ./binutils-2.17.50_fc11.patch mkdir -p BUILD/${UTILS} cd BUILD/${UTILS} ../../${UTILS}/configure --prefix=${PREFIX} --target=${TARGET} \ --with-sysroot=${SYSROOT} make make install mkdir -p $PREFIX/$TARGET/include cp ${BUILDROOT}/src/${UTILS}/include/libiberty.h $PREFIX/$TARGET/include
To be continued soon ...