Bering-uClibc 5.x - Developer Guide - Adding a Hardware Architecture Variant

From bering-uClibc
Revision as of 22:01, 20 March 2012 by Davidmbrooke (Talk | contribs) (Added Kernel CPU Architecture section and re-worked Concepts and Terminology)

Jump to: navigation, search

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!