Cross-compiling (ES series)


From SamyGO
Revision as of 18:00, 6 January 2013 by E3V3A (talk | contribs)
Jump to: navigation, search

This is Work In Progress !!

No answers/solutions can be expected here yet. If you need quick answers Google the forums.

@developers:
Do not change or update this page without first checking/asking on the "Talk" page or support forum thread for latest status/info.


Cross Compiling

This is an introduction to cross-compiling for MST10P (MStar/MediaTek) based TV sets. It is primary intended as a crash course for getting even a novice to be able to quickly compile his/her own programs to run on their TV sets. As such, we will assume that you are using a Windows based PC with a basic installation of Cygwin. The modification for using a Linux based PC will then be minimal and even simpler.

Introduction

If you have never cross-compiled anything before, this is the right place for you. If you already have experience and knowledge with cross compilation, this wiki may still be helpful to get you started. If you are looking for information on how to build your own cross-compiler, this place is not for you. (Look HERE instead.)


What this Wiki will cover and not.

- We will use a popular pre-compiled cross-compiler.
- We will work on a Windows (Intel/AMD) based PC.
- All examples herein are based on a UExxES5700 TV set, and should be reproducable on the same.

- We will not cover the compilation of a cross-compiler!
- We will not cover other cross-compilers, operating systems or processor architectures.


A few Questions and Answers:

Q:  What is a cross-compiler?
A:  Basically it is just a compiler built to run on one type of processor (e.g. Intel x86), 
    but which is built and configured for compiling code for another processor (e.g. ARM).
Q:  Should I get a pre-compiled cross-compiler or compile my own?
A:  We hate to waste our time compiling compilers, so always try to find a pre-compiled one!
Q:  Where can I find help to configure my cross-compiler?
A:  Not here. If it's not already in here or in our forums, we don't know.
Q:  Do I need to install the TV specific platform sources? (Such as UExxES6xxx.zip ?)
A: ** It depends on what you need to compile. (See below.)
Q:  Do I have to install the Samsung platform ARM toolchain? (Such as VDLinux-ARMv7-4.4-202-toolchain-v2r2-20110630.tgz ?)
A:  ** Hopefully not, but it depends on what you need to compile. (See below.)

** = unknown and not fact!


Things you need to get started.

WIP! This need checking and adjustment...

1. Install Cygwin for Windows. (Not necessary, but very helpful for the various *nix tools and file utilities.)
2. Install a good text editor (EditPlus, Notepad++ etc.)
3. Download a suitable pre-compiled cross-compiler. 
4. Download your TV kernel sources.
5. Download your TV firmware sources. (?)
6. 



Steps:

(A) Install & Verify the pre-compiled cross-compiler on your PC.
(B) Verify your TV sets processor / architecture. 
(C) Compile "HelloWorld" and run it on TV.

Extras:

(D) Installing the Samsung cross-compiler.

(E) Installing your TV Kernel sources.   
(F) Installing your TV firmware sources.

(G) Compiling the Kernel
(H) Compiling a Kernel module


(A) Installing the Cross-Compiler

Go to the Mentor Graphics website, and download the "Sourcery CodeBench Lite Edition" from HERE. (You'll need to supply an email to get a download link.) There you will get a few different choices based on the platform. You will have choices such as:

arm-2012.09-63-arm-none-eabi.exe
arm-2012.09-63-arm-none-eabi-i686-mingw32.tar.bz2
arm-2012.09-64-arm-none-linux-gnueabi.exe
arm-2012.09-64-arm-none-linux-gnueabi-i686-mingw32.tar.bz2
arm-2012.09-64-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2

If you use a x86 Windows based system, choose: "arm-2012.09-64-arm-none-linux-gnueabi.exe". Run it, and when asked, change the installation directory to something simple like: C:\zarm\csbench
The rest of the installation procedure is self explanatory.

After installation, verify that the cross-compiler PATH variable is properly set and working:

$ arm-none-linux-gnueabi-gcc --version

arm-none-linux-gnueabi-gcc.exe (Sourcery CodeBench Lite 2012.09-64) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

Since this is a Windows installer, Cygwin may or may not catch the updated system PATH variable. Open a new Cygwin shell and check:

$ echo $PATH

If it's not working, you'll have to add the following line in your ~/.bash_profile file. (On some systems this file is called ".profile".)

PATH=${PATH}:/cygdrive/path/to/csbench/bin;

This should do it.

*******************************************************************************
If you want to have access to the cross-compiler's man pages you'll have to 
add the following line to /etc/man.conf:

 MANPATH_MAP /path/to/csbench/bin /path/to/csbench/share/doc/arm-arm-none-linux-gnueabi/man

and/or possibly this line to your ~/.bashrc

 MANPATH=${MANPATH}:/path/to/csbench/share/doc/arm-arm-none-linux-gnueabi/man;

*******************************************************************************


If you have more questions, check out the Sourcery ARM FAQ.


(B) Determine the TV processor & architecture

In order to properly compile and run anything, you need to know what processor you're programming for. Here is how to find that information.

1. Root your TV and login to a shell. (Instructions HERE.)

2. Verify your TV's processor type and architecture by executing the following at the shell prompt.


shell> cat /proc/cpuinfo

Processor       : ARMv7 Processor rev 0 (v7l)
processor       : 0
BogoMIPS        : 1794.04
processor       : 1
BogoMIPS        : 1794.04
Features        : swp half thumb fastmult vfp edsp neon vfpv3
CPU implementer : 0x41
CPU architecture: 7
CPU variant     : 0x3
CPU part        : 0xc09
CPU revision    : 0 
Hardware        : amber3
Revision        : 0000
Serial          : 0000000000000000


Now, this is not obvious in any way. Problem is that an "ARM" processor is really only a license to manufacture a processor according to ARM Holding's specifications. Therefore any hardware manufacturer can have a processor with an ARM "core". In addition, and to make it even more confusing, an ARM "core" belong to an ARM "architecture" which belong to an ARM "family", whose numbers are little related...

The only way to get some insight is looking at the WikiPedia entries:

1. "List of ARM microprocessor cores"
2. "ARM architecture"

and compare what you find there with the interpretation of the ARM "Features" above, where:


-----------------------------------------------------------------------------
Feature         Description
-----------------------------------------------------------------------------
swp             SWP (SWaP) instruction, which is used to implement a binary semaphore (mutex)
half            Half-precision (16-bit) floating point, "__fp16" data type in gcc
thumb           Thumb instructions
fastmult        Fast multiplication
vfp             Vector Floating Point instruction extension
edsp            Enhanced DSP instructions
neon            NEON SIMD instructions
vfpv3           Vector Floating Point instruction extension Version 3
-----------------------------------------------------------------------------


So from the above we think we have a dual core processor of the ARMv7-R or ARMv7-A architecture. (Of either the Coretx-R or A families, respectively.) But the only NEON enabled processors with both DSP and VFPV3, are the Cortex-A8 and "Cortex-A9 MPCore". But this is not good enough...for a perfectionist. So we search in the ARM on-line documentation for "Main ID Register":


Main ID Register bit functions:

-----------------------------------------------------------------------------
Bits    Field                   Value   Function
-----------------------------------------------------------------------------
[31:24] Implementor             0x41    implementor: ARM
[23:20] Variant                 0x3     variant number or major revision of the processor
[19:16] Architecture            0x7     architecture is given in the feature registers
[15:4]  Primary part number     0xC09   part number: Cortex-A9
[3:0]   Revision                0x0     revision number or minor revision of the processor
-----------------------------------------------------------------------------


Here is a brief list of ARM primary part numbers.


ARM core       CPU part
------------------------
ARM920         0x920
ARM926         0x926
ARM946         0x946
ARM966         0x966

ARM1136        0xb36
ARM1156        0xb56
ARM1176        0xb76
ARM11 MPCore   0xb02

Cortex A5      0xc05
Cortex A8      0xc08
Cortex A9      0xc09
Cortex A15     0xc0f
Cortex R4      0xc14 
Cortex R5      0xc15
------------------------

We finally conclude that our TV processor contains a dual core Cortex-A9 MPCore from the ARMv7-A architecture.

Done!