Embedded Systems Programming

Similar documents
Yocto Project & Embedded Linux

Cross Compiling. Real Time Operating Systems and Middleware. Luca Abeni

Raspberry Pi Kernel Install. By: Daniel Rizko

How to cross compile with LLVM based tools. Peter Smith, Linaro


Lab2 - Bootloader. Conventions. Department of Computer Science and Information Engineering National Taiwan University

Embedded Systems. Mail: Web: Université de Nice - Sophia Antipolis

MV 4412 Android 4.0 Compilation

Adding hardware support to Buildroot

Yocto Project components

Itron Riva Dev Software Development Getting Started Guide

Lab11 - Bare Metal Programming. Department of Computer Science and Information Engineering National Taiwan University

OSELAS.Support OSELAS.Training OSELAS.Development OSELAS.Services

Sourcery CodeBench Lite. ARM GNU/Linux Sourcery CodeBench Lite Getting Started

GUT. GUT Installation Guide

D1 - Embedded Linux. Building and installing an embedded and real-time Linux platform. Objectives. Course environment.

CIT 595 Spring System Software: Programming Tools. Assembly Process Example: First Pass. Assembly Process Example: Second Pass.

NDK OVERVIEW OF THE ANDROID NATIVE DEVELOPMENT KIT


MV V310 Android 4.0 Compilation

GUT. GUT Installation Guide

Introduction to Linux

Lecture 1. Course webpage. Syllabus and schedule, textbooks CS Lab, Virtual Box. Handouts, assignments Supplemental resources

Download, Install and Setup the Linux Development Workload Create a New Linux Project Configure a Linux Project Configure a Linux CMake Project

Gcc Get Current Instruction Pointer

Obtained the source code to gcc, one can just follow the instructions given in the INSTALL file for GCC.

The Scratchbox development environment

Errors During Compilation and Execution Background Information

Mesos on ARM. Feng Li( 李枫 ),

FreeBSD Tool Chain. Ed Maste BSDCan 2017

Rethinking the core OS in 2015

Installation Guide for OS/161

Cross-compilation with Buildroot

COSE222 Computer Architecture

C03c: Linkers and Loaders

PaPP cross-platform development system version 15.0

Compiler (1A) Young Won Lim 6/8/14

Structure of the RISC- V So0ware Stack. Sagar Karandikar UC Berkeley

Building graphic-rich and better performing native applications. Pro. Android C++ with the NDK. Onur Cinar

Building U-Boot in CodeWarrior ARMv8

Intel Do-It-Yourself Challenge Compile C/C++ for Galileo Nicolas Vailliet

Crosstoolchains in Debian

ECM583 Special Topics in Computer Systems

Qtopia Core Application Note

Android System Development Training 4-day session

Zephyr Kernel Installation & Setup Manual

UFCETW-20-2 Examination Answer all questions in Section A (60 marks) and 2 questions from Section B (40 marks)

RTEMS Source Builder. Release (master) Copyright 2017, RTEMS Project (built 29th June 2018)

Preview. Story about Linux. Story about Linux. Story about Linux. Story about GNU/Linux. Story about GNU/LINUX 1/26/2018

EMBEDDED LINUX ON ARM9 Weekend Workshop

Essentials for Scientific Computing: Source Code, Compilation and Libraries Day 8

Buildroot: a deep dive into the core

Developing Environment for Intel Mainstone Board

2012 LLVM Euro - Michael Spencer. lld. Friday, April 13, The LLVM Linker

A tale of ELFs and DWARFs

Shared Libraries: The Dynamic Linker

Laboratory of Networked Embedded Systems

MV V210 Android 4.0 Compilation

The distcc Utility for Remote Compiling

Introduction p. 1 Why Linux? p. 2 Embedded Linux Today p. 3 Open Source and the GPL p. 3 Free Versus Freedom p. 4 Standards and Relevant Bodies p.

Porting uclinux to MIPS

D1Y - Embedded Linux with Yocto

Aurelien Jarno 26/02/2006 FOSDEM. Debian GNU/kFreeBSD. Aurelien Jarno. What? Why? Status. The future. How to help?

RELEASE NOTES. GNU Toolchain for Atmel ARM Embedded Processors. Introduction

Freescale Semiconductor gcc linaro toolchain, Rev

μc/probe on the element14 BeagleBone Black

Introduction of Linux

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

Blackfin cross development with GNU Toolchain and Eclipse

Cross build in the FreeBSD ports tree

Rethinking the core OS in 2015

Integrating Open Source Tools for Developing Embedded Linux Applications

Dynamic & Static Libraries in Linux (New Talk!) Wim Cardoen and Brett Milash CHPC User Services

Setting up cross compiling environment & Qt/X11 for the DXSERIES with the ELDK cross compiler

Imperas Guide to using Virtual Platforms. Platform / Module Specific Information for mips.ovpworld.org / BareMetalMipsSingle. Imperas Software Limited

Embedded Linux system development

Programs. Function main. C Refresher. CSCI 4061 Introduction to Operating Systems

GNU-AVR Building the GNU AVR Toolchain for Mac OS X and Linux

RED HAT DEVELOPER TOOLSET: Build, Run, & Analyze Applications On Multiple Versions of Red Hat Enterprise Linux

Generic Programming in C

MRCP. Installation Manual. Developer Guide. Powered by Universal Speech Solutions LLC

Embedded Linux system development

RELEASE NOTES. GNU Toolchain for Atmel AVR8 Embedded Processors. Introduction

Using colinux to develop under Windows XP

Embest IDE Pro for ARM 2005

The build2 Toolchain Installation and Upgrade

GNUPro Toolkit User s Guide for Altera for ARM and ARM/ Thumb Development

Embedded Linux development made easier. User s manual. Version:

FreeBSD on latest ARM Processors

Debugging Linux systems using GDB and QEMU. Khem Raj

Multiarch - why it s important

DS-5 ARM. Getting Started with DS-5. Version 5.6. Copyright 2010, 2011 ARM. All rights reserved. ARM DUI 0478F (ID071411)

Development Environment Embedded Linux Primer Ch 1&2

Programming Project 1: Introduction to the BLITZ Tools

Lecture 11 - Portability and Optimizations

Department of Computer Science and Engineering Yonghong Yan

Freescale Semiconductor Inc. Vybrid DS-5 Getting Started Guide Rev 1.0

A simple tutorial on generating PTX assembler out of Ada source code using LLVM NVPTX backend

RISC-V Software Ecosystem

Raspberry Pi Network Boot

Transcription:

Embedded Systems Programming OS Linux - Toolchain Iwona Kochańska Gdansk University of Technology

Embedded software Toolchain compiler and tools for hardwaredependent software developement Bootloader initializes hardware and loads OS kernel Kernel a heart of a system, manages resources and communicates with hardware Root filesystem GUT Intel 2015/16 2/34 libraries and applications

What is toolchain? Toolchain - set of tools that compiles source code into executables that can run on the target device, and includes: a compiler, a linker, run-time libraries Toolchain is needed to build the other three elements of an embedded Linux system: the bootloader, the kernel, the root filesystem. GUT Intel 2015/16 3/34

What is Toolchain? Toolchain has to be able to compile code written in assembly, C, and C++ since these are the languages used in the base open source packages Usually, toolchains for Linux are based on components from the GNU project (http://www.gnu.org) Alternative: Clang compiler and the associated LLVM project (http://llvm.org) GUT Intel 2015/16 4/34

Toolchain components Standard GNU toolchain consists of three main components: Binutils: binary utilities including assembler, linker, ld. It is available at http://www.gnu.org/software/binutils/. GNU Compiler Collection (GCC): the compilers for C and other languages, include C++, Objective-C, Objective-C++, Java, Fortran, Ada, and Go. It is available at http://gcc.gnu.org/. C library: a standardized API based on the POSIX specification which is the principle interface to the operating system kernel from applications.... and a copy of the Linux kernel headers. GUT Intel 2015/16 5/34

Cross-compilation Basic definitions: build: Also called the local platform, the platform that you physicaly perform the compiling on (for example PC with Debian distribution) target: The destination platform (for example Raspberry Pi) host: OS providing virtual environment guest: OS in virtual environment GUT Intel 2015/16 6/34

Cross-compilation There are two main problems in cross-compiling: All C/C++ include files and libraries for the target must be available on the build platform. The cross-compiler and related tools must generate code suitable for the target platform. GUT Intel 2015/16 7/34

Types of toolchains There are several types of toolchains, based on the architecture of build, host and target machines: Native (common in desktop computers) build machine host machine target machine arch. A arch. A arch. A Cross-compilation build machine host machine target machine arch. A arch. A arch. B GUT Intel 2015/16 8/34

Types of toolchains Cross-native build machine host machine target machine arch. A arch. B arch. B Canadian build machine host machine target machine arch. A arch. B arch. C GUT Intel 2015/16 9/34

CPU architectures The toolchain has to be built according to the capabilities of the target CPU, which includes: CPU architecture: arm, mips, x86_64, and so on Big- or little-endian operation: Some CPUs can operate in both modes, but the machine code is different for each Floating point support: Not all versions of embedded processors implement a hardware floating point unit, in which case, the toolchain can be configured to call a software floating point library instead Application Binary Interface (ABI): The calling convention used for passing parameters between function calls GUT Intel 2015/16 10/34

ARM ABI architectures OABI - Old Application Binary Interface (OABI) - discontinued 2011 EABI - Extended Application Binary Interface (EABI) - general purpose (integer) registers EABIHF - Hard Float Extended Application Binary Interface - uses floating point registers. GUT Intel 2015/16 11/34

GNU prefix GNU uses a prefix consisting of a tuple of three or four components separated by dashes: CPU: arm, mips, x86_64, el = little-endian, eb = big-endian; e.g. armeb = big-endian ARM Vendor, e.g. poky Kernel, e.g. linux Operating system: a name for the user space component, which might be gnu or uclibcgnu. The ABI may be appended (gnueabi, gnueabihf, uclibcgnueabi, or uclibcgnueabihf). $ gcc dumpmachine x86_64 l i n u x gnu GUT Intel 2015/16 12/34

C library The programming interface to the Unix operating system is defined in the C language (POSIX standards). The C library is the implementation of that interface (gateway to the kernel for Linux programs). Whenever the C library needs the services of the kernel it will use the kernel system call interface to transition between user space and kernel space. GUT Intel 2015/16 13/34

C libraries glibc - standard GNU C library, most complete implementation of the POSIX API eglibc - embedded GLIBC; a series of patches to glibc which added configuration options and support for architectures not covered by glibc; merged back into glibc as of version 2.20 uclibc - micro controller C library; first developed to work with uclinux (Linux for CPUs without memory management units), but has since been adapted to be used with full Linux musl libc - new C library designed for embedded systems. GUT Intel 2015/16 14/34

Building a toolchain using crosstool-ng Crosstool-NG (2007) - a way to create a stand-alone cross toolchain from sourcesoc or board vendor Install: $ sudo apt get i n s t a l l automake bison chrpath f l e x g++ g python2.7 dev t e x i n f o Download sources from http://crosstool-ng.org/download/crosstool-ng and: $ t a r x f c r o s s t o o l ng 1.9.3. t a r. bz2 $ cd c r o s s t o o l ng 1.9.3 $. / c o n f i g u r e $ make $ make i n s t a l l enable-local option - program will be installed into the current directory, instead of /usr/local/bin. GUT Intel 2015/16 15/34

Building a toolchain using crosstool-ng Launch the crosstool menu: $. / ct ng List of sample configurations $. / ct ng l i s t samples Select target configuration: $. / ct ng arm cortex_a8 l i n u x gnueabi Make changes using the configuration menu: $. / ct ng menuconfig The configuration data is saved into a file named.config. Build the toolchain: $. / ct ng b u i l d GUT Intel 2015/16 16/34

Building a toolchain using crosstool-ng Toolchain directory: arm cortex_a8 l i n u x gnueabi / bin / Add directory to the cross compiler to PATH: $ PATH = /... / arm cortex_a8 l i n u x gnueabihf / bin :$PATH Compile helloworld.c: $ arm cortex_a8 l i n u x gnueabihf gcc h e l l o w o r l d. c o h e l l o Check the type of the executable: $ f i l e h e l l o w o r l d h e l l o w o r l d : ELF 32 b i t LSB executable, ARM, version 1 (SY GUT Intel 2015/16 17/34

Building a toolchain using crosstool-ng Check the cross-compiler version: $ arm cortex_a8 l i n u x gnueabi gcc version Check the cross-compiler configuration: $ arm cortex_ a8 l i n u x gnueabi gcc v Print out the the range of architecture-specific options available: $ arm cortex_a8 l i n u x gnueabihf gcc t a r g e t help GUT Intel 2015/16 18/34

Building a toolchain using crosstool-ng The toolchain sysroot - a directory which contains subdirectories for libraries, header files, and other configuration files. It can be set when the toolchain is configured through with-sysroot= or it can be set on the command line, using sysroot=. Check the location of the default sysroot: $ arm cortex_a8 l i n u x gnueabi gcc p r i n t sysroot GUT Intel 2015/16 19/34

Building a toolchain using crosstool-ng Sysroot contains: lib: shared objects for the C library and the dynamic linker/loader, ld-linux usr/lib: the static library archives for the C library and any other libraries that may be installed subsequently usr/include: headers for all the libraries usr/bin: utility programs that run on the target, such as the ldd command usr/share: used for localization and internationalization sbin: Provides the ldconfig utility, used to optimize library loading paths Some of these are needed on the development host to compile programs, others are needed on the target at runtime. GUT Intel 2015/16 20/34

Tools of a toolchain Command addr2line ar as c++filt cpp elfedit g++ gcc gcov gdb gprof Description Converts program addresses into filenames and numbers Archive utility used to create static libraries. GNU assembler demangle C++ and Java symbols C preprocessor update the ELF header of ELF files GNU C++ front-end GNU C front-end code coverage tool GNU debugger program profiling tool GUT Intel 2015/16 21/34

Tools of a toolchain Command ld nm objcopy objfump ranlib readelf size strings strip Description GNU linker list of symbols from object files used to copy and translate object files display information from object files creates or modifies an index in a static library, making the link displays information about files in ELF object format lists section sizes and the total size display strings of printable characters in files strip an object file of debug symbol tables GUT Intel 2015/16 22/34

C library Four main parts implement POSIX standard libc: main C library that contains the well-known POSIX functions (printf, open, close, read, write) libm: maths functions (cos, exp, log) libpthread: all the POSIX thread functions with names beginning with pthread_ librt: The real-time extensions to POSIX, including shared memory and asynchronous I/O libc is always linked in but the others have to be explicitly linked with the -l option arm cortex_ a8 l i n u x gnueabihf gcc myprog. c o myprog lm GUT Intel 2015/16 23/34

C library Which libraries have been linked? $ arm cortex_a8 l i n u x gnueabihf r e a d e l f a myprog grep 0x00000001 (NEEDED) Shared l i b r a r y : [ libm. so. 6 ] 0x00000001 (NEEDED) Shared l i b r a r y : [ l i b c. so. 6 ] Check the run-time linker: $ arm cortex_a8 l i n u x gnueabihf r e a d e l f a myprog grep GUT Intel 2015/16 24/34

Static and dynamic linking The library code can be linked in two different ways: statically - all the library functions the application calls and their dependencies are pulled from the library archive and bound into the executable; dynamically - references to the library files and functions in those files are generated in the code but the actual linking is done dynamically at runtime GUT Intel 2015/16 25/34

Static libraries Static linking is useful: when building a small system which consists of only BusyBox and some script files, it is simpler to link BusyBox statically and avoid having to copy the runtime library files and linker when running a program before the filesystem that holds the runtime libraries is available Tell gcc to link all libraries statically: $ arm cortex_a8 l i n u x gnueabihf gcc s t a t i c h e l l o w o r l d. c GUT Intel 2015/16 26/34

Static libraries Creating a static library: $ arm cortex_a8 l i n u x gnueabihf gcc c t e s t 1. c $ arm cortex_a8 l i n u x gnueabihf gcc c t e s t 2. c $ arm cortex_a8 l i n u x gnueabihf ar rc l i b t e s t. a t e s t 1. o Linking libtest into helloworld program: $ arm cortex_a8 l i n u x gnueabihf gcc h e l l o w o r l d. c l t e s t GUT Intel 2015/16 27/34

Shared libraries Shared objects linked at runtime, Efficient use of storage and system memory, since only one copy of the code needs to be loaded. Easy to update library files without having to re-link all the programs that use them. GUT Intel 2015/16 28/34

Shared libraries Creating a shared library: $ arm cortex_a8 l i n u x gnueabihf gcc fpic c t e s t 1. c $ arm cortex_a8 l i n u x gnueabihf gcc fpic c t e s t 2. c $ arm cortex_a8 l i n u x gnueabihf gcc shared o l i b t e s t. s PIC flag tells GCC to produce code that does not contain references to specific memory locations for functions and variables Linking libtest into helloworld program: $ arm cortex_a8 l i n u x gnueabihf gcc h e l l o w o r l d. c l t e s t The linker will look for libtest.so in the default search path: /lib and /usr/lib. Other directories with shared libraries - place a colon-separated list of paths in the shell variable LD_LIBRARY_PATH GUT Intel 2015/16 29/34

Shared libraries names ldd - searches the standard system library paths and shows which library versions would be used by a particular program. ldd h e l l o w o r l d Shared libraries names: libjpeg.a: library archive used for static linking libjpeg.so -> libjpeg.so.8.0.2 : symbolic link, used for dynamic linking libjpeg.so.8 -> libjpeg.so.8.0.2: symbolic link used when loading the library at runtime libjpeg.so.8.0.2: actual shared library, used at both compile time and runtime GUT Intel 2015/16 30/34

Build systems for cross compiling Simple makefiles where the toolchain is controlled by the make variable CROSS_COMPILE The GNU build system known as Autotools CMake (https://cmake.org) GUT Intel 2015/16 31/34

Simple makefiles For packages simple to cross compile (the Linux kernel, the U-Boot bootloader, Busybox) put the toolchain prefix in the make variable CROSS_COMPILE, for example: $ make CROSS_COMPILE=arm cortex_ a8 l i n u x gnueabi Or set it as a shell variable: $ export CROSS_COMPILE=arm cortex_a8 l i n u x gnueabi $ make GUT Intel 2015/16 32/34

GNU Autotools Autotools refers to a group of tools that are used as the build system in many open source projects. The components: GNU Autoconf GNU Automake GNU Libtool Gnulib Packages that use Autotools come with a script named configure that checks dependencies and generates makefiles. To configure, build, and install a package for the native operating system $. / c o n f i g u r e $ make $ sudo make i n s t a l l GUT Intel 2015/16 33/34

For Further Reading I C. Simmonds. Mastering Embedded Linux Programming. Packt Publishing, 201 GUT Intel 2015/16 34/34