[FE training-materials-updates] Cross-compiling: add back explanations about CROSS_COMPILE

Michael Opdenacker michael.opdenacker at free-electrons.com
Mon Nov 27 18:36:51 CET 2017

Repository : git://git.free-electrons.com/training-materials.git
On branch  : master
Link       : http://git.free-electrons.com/training-materials/commit/?id=e515f5fcd49196d7b4407460fdbd74b145c6b37d


commit e515f5fcd49196d7b4407460fdbd74b145c6b37d
Author: Michael Opdenacker <michael.opdenacker at free-electrons.com>
Date:   Mon Nov 27 18:36:51 2017 +0100

    Cross-compiling: add back explanations about CROSS_COMPILE
    - I remember writing them but they got lost by the
      time I committed my changes.
    Signed-off-by: Michael Opdenacker <michael.opdenacker at free-electrons.com>


 .../sysdev-kernel-building.tex                     | 50 ++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/slides/sysdev-kernel-building/sysdev-kernel-building.tex b/slides/sysdev-kernel-building/sysdev-kernel-building.tex
index a28b912..43e66cf 100644
--- a/slides/sysdev-kernel-building/sysdev-kernel-building.tex
+++ b/slides/sysdev-kernel-building/sysdev-kernel-building.tex
@@ -341,6 +341,56 @@ CONFIG_NTFS_RW=y
 \subsection{Compiling and installing the kernel}
+  \frametitle{Choose a compiler}
+  The compiler invoked by the kernel Makefile is \code{$(CROSS_COMPILE)gcc}
+  \begin{itemize}
+    \item When compiling natively
+      \begin{itemize}
+	 \item Leave \code{CROSS_COMPILE} undefined and the kernel
+	    will be natively compiled for the host architecture
+            using \code{gcc}.
+      \end{itemize}
+    \item When using a cross-compiler
+      \begin{itemize}
+      \item To make the difference with a native compiler, cross-compiler
+          executables are prefixed by the name of the target system,
+          architecture and sometimes library. Examples:\\
+          \small
+          \code{mips-linux-gcc}: the prefix is \code{mips-linux-}\\
+          \code{arm-linux-gnueabi-gcc}: the prefix is \code{arm-linux-gnueabi-}
+      \item So, you can specify your cross-compiler as follows:\\
+          \code{export CROSS_COMPILE=arm-linux-gnueabi-}
+      \end{itemize} 
+  \end{itemize}
+  \code{CROSS_COMPILE} is actually the prefix of the cross compiling
+tools (\code{gcc}, \code{as}, \code{ld}, \code{objcopy}, \code{strip}...).
+  \frametitle{Specifying ARCH and CROSS\_COMPILE}
+  There are actually two ways of defining \code{ARCH} and \code{CROSS_COMPILE}:
+  \begin{itemize}
+  \item Pass \code{ARCH} and \code{CROSS_COMPILE} on the \code{make}
+    command line: \\
+    \code{make ARCH=arm CROSS_COMPILE=arm-linux- ...} \\
+    Drawback: it is easy to forget to pass these variables when
+    you run any \code{make} command, causing your build and
+    configuration to be screwed up.
+  \item Define \code{ARCH} and \code{CROSS_COMPILE} as environment
+    variables: \\
+    \code{export ARCH=arm} \\
+    \code{export CROSS_COMPILE=arm-linux-} \\
+    Drawback: it only works inside the current
+    shell or terminal. You could put these settings in a file
+    that you source every time you start working on the project.
+    If you only work on a single architecture with always the
+    same toolchain, you could even put these settings in your
+    \code{~/.bashrc} file to make them permanent and visible from
+    any terminal.
+  \end{itemize}
   \frametitle{Kernel compilation}
   \item \code{make}

More information about the training-materials-updates mailing list