Difference between revisions of "Bering-uClibc 5.x - Developer Guide - Adding a Hardware Architecture Variant"

From bering-uClibc
Jump to: navigation, search
(Created initial stub)
 
(Added Kernel CPU Architecture section and re-worked Concepts and Terminology)
Line 3: Line 3:
 
In principle it would now be possible to build [[Bering-uClibc 5.x]] for SPARC, MIPS or other CPU architectures.
 
In principle it would now be possible to build [[Bering-uClibc 5.x]] for SPARC, MIPS or other CPU architectures.
 
These notes provide guidance on what changes are required to add support for a brand new target architecture variant.
 
These notes provide guidance on what changes are required to add support for a brand new target architecture variant.
The addition of support for the ARM11 processor on the Raspberry Pi single board computer is used as an example.
+
The addition of support for the ARM11 processor on the [http://en.wikipedia.org/wiki/Raspberry_Pi Raspberry Pi] single board computer is used as an example.
  
 
The first step is to understand exactly what hardware the target platform consists of.
 
The first step is to understand exactly what hardware the target platform consists of.
 
In particular:
 
In particular:
 
* What is the model number of the CPU?
 
* What is the model number of the CPU?
** The [http://en.wikipedia.org/wiki/Raspberry_Pi Raspberry Pi] has a [http://www.broadcom.com/products/BCM2835 Broadcom BCM2835] "system on a chip" integrated circuit containing an [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0301h/index.html ARM1176JZF-S] CPU
+
** The Raspberry Pi has a [http://www.broadcom.com/products/BCM2835 Broadcom BCM2835] "system on a chip" integrated circuit containing an [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0301h/index.html ARM1176JZF-S] CPU
 
* What is the "architecture" of the CPU?
 
* What is the "architecture" of the CPU?
 
** The ARM1176JZF-S CPU implements the [http://en.wikipedia.org/wiki/ARM11 ARMv6] architecture standard
 
** The ARM1176JZF-S CPU implements the [http://en.wikipedia.org/wiki/ARM11 ARMv6] architecture standard
  
  
==Concepts and Terminology==
+
==Linux Kernel CPU Architecture Selection==
 +
The standard Linux kernel source tree includes CPU architecture specific code for quite a number of CPU types.
 +
This code is in the "<code class="filename">arch</code>" directory within the kernel source tree and it is sensible to review the contents of this directory.
 +
If you have not already extracted the Kernel source run:
 +
./buildtool.pl source kernel
 +
cd source/linux/linux-3.2.*/arch
 +
 
 +
Each of the directory names under "<code class="filename">arch</code>" represents a fundamental "architecture" variant.
 +
The [[Bering-uClibc]] toolchain references this via the <code>'''ARCH'''</code> variable.
 +
 
 +
'''Note:''' There are a few "special cases", which include <code class="filename">i386</code> and <code class="filename">x86_64</code>!
 +
Refer to the commnents and code in <code class="filename">source/linux/linux-3.2.*/Makefile</code> (starting around line 174) for further details.
 +
 
 +
Since there is a sub-directory of "<code class="filename">arch</code>" called
 +
"<code class="filename">arm</code>" that is what we need to set the "<code>ARCH</code>" variable to when building a toolchain to target the Raspberry Pi.
 +
Details of how and where to do that are provided below.
 +
 
 +
 
 +
==GCC and Binutils CPU Architecture Selection==
 
The toolchain is responsible for building code for the target environment and it relies on the GCC (cross-)compiler to do most of the work.
 
The toolchain is responsible for building code for the target environment and it relies on the GCC (cross-)compiler to do most of the work.
In addition it is necesary to configure the Linux kernel (and, to a lesser extent, uClibc) for the target hardware environment.
 
  
 
The GNU toolset (most notably "configure") has a well-established way of identifying different target platforms by a hyphen-separated list of the key characteristics known as the "[http://www.gnu.org/software/libc/manual/html_node/Hierarchy-Conventions.html configuration name]".
 
The GNU toolset (most notably "configure") has a well-established way of identifying different target platforms by a hyphen-separated list of the key characteristics known as the "[http://www.gnu.org/software/libc/manual/html_node/Hierarchy-Conventions.html configuration name]".
This was initially the triplet <code>cpu-manufacturer-kernel</code> but is now more commonly the quadruplet <code>cpu-manufacturer-kernel-os</code> (though this is still normally referred to as a "triplet").
+
This was initially the triplet <code>cpu-manufacturer-kernel</code> but is now more commonly the quadruplet ''<code>cpu-manufacturer-kernel-os</code>'' (though this is still often referred to as a "triplet").
 
For example, <code>i486-unknown-linux-uclibc</code> refers to:
 
For example, <code>i486-unknown-linux-uclibc</code> refers to:
 
* an <code>i486</code> CPU, installed in
 
* an <code>i486</code> CPU, installed in
Line 24: Line 41:
 
* the <code>linux</code> kernel, and
 
* the <code>linux</code> kernel, and
 
* a <code>uclibc</code> C library-based operating system
 
* a <code>uclibc</code> C library-based operating system
 +
 +
The first field ("<code>cpu</code>") is of particular interested here.
 +
Having identified the Kernel CPU Architecture (<code>ARCH</code>)refer to the appropriate sub-page of [http://gcc.gnu.org/onlinedocs/gcc/Submodel-Options.html the GCC "Hardware Models and Configurations" page] in order to understand what options are available.
 +
 +
For example, on the [http://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html ARM Options] sub-page there is a definition of the permissible values for the <code>-march</code> command-line option to GCC and related tools. One of the permissible values is "<code>armv6</code>" which is an obvious match for the ARMv6 architecture which we know the ARM11 CPU family uses.
 +
 +
The [[Bering-uClibc 5.x]] toolchain references this (the setting for <code>-march</code>) via the <code>'''GNU_ARCH'''</code> variable.
 +
 +
This also forms the first entry in the hyphen-separated "configuration name" string. Since the other three entries in this string are always the same for [[Bering-uClibc 5.x]] we therefore know what this full string is.
 +
For the Raspberry Pi the full string is "<code>armv6-unknown-linux-uclibc</code>".
 +
 +
The [[Bering-uClibc 5.x]] toolchain references this "configuration name" via the <code>'''GNU_TARGET'''</code> variable.
 +
 +
Since this "configuration name" captures all the characteristics of the target system which need to be hard-coded into the toolchain it is a good string to use to identify and differentiate multiple toolchains.
 +
The <code class="filename">buildtool.pl</code> and <code class="filename">buildpacket.pl</code> scripts therefore use this "configuration name" as their "toolchainname", and <code class="filename">buildtool.pl</code> sets the environment variable <code>$GNU_TARGET</code> based on the specified (or default) toolchainname.
 +
 +
TODO: Describe '''GNU_TUNE'''
 +
 +
 +
TODO - Lots more!

Revision as of 22:01, 20 March 2012

Introduction

A major enhancement added in Bering-uClibc 5.x is the ability to target non-x86 runtime platforms. In principle it would now be possible to build Bering-uClibc 5.x for SPARC, MIPS or other CPU architectures. These notes provide guidance on what changes are required to add support for a brand new target architecture variant. The addition of support for the ARM11 processor on the Raspberry Pi single board computer is used as an example.

The first step is to understand exactly what hardware the target platform consists of. In particular:

  • What is the model number of the CPU?
  • What is the "architecture" of the CPU?
    • The ARM1176JZF-S CPU implements the ARMv6 architecture standard


Linux Kernel CPU Architecture Selection

The standard Linux kernel source tree includes CPU architecture specific code for quite a number of CPU types. This code is in the "arch" directory within the kernel source tree and it is sensible to review the contents of this directory. If you have not already extracted the Kernel source run:

./buildtool.pl source kernel
cd source/linux/linux-3.2.*/arch

Each of the directory names under "arch" represents a fundamental "architecture" variant. The Bering-uClibc toolchain references this via the ARCH variable.

Note: There are a few "special cases", which include i386 and x86_64! Refer to the commnents and code in source/linux/linux-3.2.*/Makefile (starting around line 174) for further details.

Since there is a sub-directory of "arch" called "arm" that is what we need to set the "ARCH" variable to when building a toolchain to target the Raspberry Pi. Details of how and where to do that are provided below.


GCC and Binutils CPU Architecture Selection

The toolchain is responsible for building code for the target environment and it relies on the GCC (cross-)compiler to do most of the work.

The GNU toolset (most notably "configure") has a well-established way of identifying different target platforms by a hyphen-separated list of the key characteristics known as the "configuration name". This was initially the triplet cpu-manufacturer-kernel but is now more commonly the quadruplet cpu-manufacturer-kernel-os (though this is still often referred to as a "triplet"). For example, i486-unknown-linux-uclibc refers to:

  • an i486 CPU, installed in
  • an unknown hardware platform ("unknown" as in "we don't care whether a PC is made by HP, IBM, Dell etc."), running
  • the linux kernel, and
  • a uclibc C library-based operating system

The first field ("cpu") is of particular interested here. Having identified the Kernel CPU Architecture (ARCH)refer to the appropriate sub-page of the GCC "Hardware Models and Configurations" page in order to understand what options are available.

For example, on the ARM Options sub-page there is a definition of the permissible values for the -march command-line option to GCC and related tools. One of the permissible values is "armv6" which is an obvious match for the ARMv6 architecture which we know the ARM11 CPU family uses.

The Bering-uClibc 5.x toolchain references this (the setting for -march) via the GNU_ARCH variable.

This also forms the first entry in the hyphen-separated "configuration name" string. Since the other three entries in this string are always the same for Bering-uClibc 5.x we therefore know what this full string is. For the Raspberry Pi the full string is "armv6-unknown-linux-uclibc".

The Bering-uClibc 5.x toolchain references this "configuration name" via the GNU_TARGET variable.

Since this "configuration name" captures all the characteristics of the target system which need to be hard-coded into the toolchain it is a good string to use to identify and differentiate multiple toolchains. The buildtool.pl and buildpacket.pl scripts therefore use this "configuration name" as their "toolchainname", and buildtool.pl sets the environment variable $GNU_TARGET based on the specified (or default) toolchainname.

TODO: Describe GNU_TUNE


TODO - Lots more!