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

Similar documents
Embedded Systems Programming

Arm cross development tools

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

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras


Systems Programming. Fatih Kesgin &Yusuf Yaslan Istanbul Technical University Computer Engineering Department 18/10/2005

Rethinking the core OS in 2015

ECE 471 Embedded Systems Lecture 4

CS 550 Operating Systems Spring Process I

Porting uclinux to MIPS

ECE 498 Linux Assembly Language Lecture 1

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

SFO17-315: OpenDataPlane Testing in Travis. Dmitry Eremin-Solenikov, Cavium Maxim Uvarov, Linaro

Operating System Architecture. CS3026 Operating Systems Lecture 03

Introduction to Pintos

C03c: Linkers and Loaders

The Challenges of X86 Hardware Virtualization. GCC- Virtualization: Rajeev Wankar 36

Developing Environment for Intel Mainstone Board

Rethinking the core OS in 2015

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

ECE 471 Embedded Systems Lecture 4

Embedded Linux Architecture

Creating a system call in Linux. Tushar B. Kute,

ArcReader System Requirements

Yocto Project & Embedded Linux

ArcGIS Engine Developer Kit System Requirements

Gold. Ian Lance Taylor Google. What? Why? How? Gold. Performance. Features. Future. Ian Lance Taylor Google. Who? June 17, 2008

A Survey on Virtualization Technologies

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

Overview. This Lecture. Interrupts and exceptions Source: ULK ch 4, ELDD ch1, ch2 & ch4. COSC440 Lecture 3: Interrupts 1

Generating Programs and Linking. Professor Rick Han Department of Computer Science University of Colorado at Boulder

CNIT 127: Exploit Development. Ch 3: Shellcode. Updated

A Plan 9 C Compiler for RISC-V

MV 4412 Android 4.0 Compilation

Virtual Machines and Dynamic Translation: Implementing ISAs in Software

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University

Miscellaneous C-programming Issues

PRoot: a Step Forward for QEMU User-Mode

Topics. Operating System. What is an Operating System? Let s Get Started! What is an Operating System? Where in the Book are we?

Integrating Open Source Tools for Developing Embedded Linux Applications

TEMU installation and user manual

Yocto Project components

ArcGIS Engine Runtime System Requirements

SDK. About the Cisco SDK. Installing the SDK. Procedure. This chapter contains the following sections:

The Scratchbox development environment

Dynamic Translator-Based Virtualization

Advanced Computer Architecture

24-vm.txt Mon Nov 21 22:13: Notes on Virtual Machines , Fall 2011 Carnegie Mellon University Randal E. Bryant.

MV V310 Android 4.0 Compilation

ELEC 377 Operating Systems. Week 1 Class 2

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

Topics. Operating System I. What is an Operating System? Let s Get Started! What is an Operating System? OS History.

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

Computer Organization & Assembly Language Programming (CSE 2312)

GCC and LLVM collaboration

ECE 471 Embedded Systems Lecture 5

Building Open Source Software on DEC ULTRIX V4.5 (Revision ) RISC / VAX. Revision Joachim Buss

Compilation, Disassembly, and Profiling (in Linux)

Ingenic GCC Cross-Compiler Tool Chain Handbook. 1 Installation and usage of Ingenic GCC cross-compile

Qtopia Core Application Note

Overview of Unix / Linux operating systems

Libraries and Compilation Environment (I) Computadors Grau en Ciència i Enginyeria de Dades Q2

Cross-compiling Linux Kernels on x86_64: A tutorial on How to Get Started

CSE 303: Concepts and Tools for Software Development

Building and Installing QGIS

Khem Raj Embedded Linux Conference 2014, San Jose, CA

Metasm. a ruby (dis)assembler. Yoann Guillot. 20 october 2007

GCC Configuration and Building

CS2141 Software Development using C/C++ Libraries

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

GBA Dev In Linux - GCC for GBA for Linux

CSCI 8530 Advanced Operating Systems. Part 19 Virtualization

Introduction to Virtual Machines. Michael Jantz

CSC258: Computer Organization. Functions and the Compiler Tool Chain

COS 318: Operating Systems

Department of Computer Science and Engineering Yonghong Yan

LIEF: Library to Instrument Executable Formats

COSE222 Computer Architecture

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

Crosstoolchains in Debian

Virtualization. ...or how adding another layer of abstraction is changing the world. CIS 399: Unix Skills University of Pennsylvania.

13-2 EE 4770 Lecture Transparency. Formatted 8:18, 13 March 1998 from lsli

5 Lecture: Intro. to Concurrency

Chapter 8: Main Memory

Programming Tools. Venkatanatha Sarma Y. Lecture delivered by: Assistant Professor MSRSAS-Bangalore

2018/04/11 00:10 1/6 NuttX Protected Build

Developing Real-Time Applications

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

What are some common categories of system calls? What are common ways of structuring an OS? What are the principles behind OS design and

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

Intro to Segmentation Fault Handling in Linux. By Khanh Ngo-Duy

Porting Linux to a New Architecture

Cost of Your Programs

Raspberry Pi Kernel Install. By: Daniel Rizko

Prelinker Usage for MIPS Cores CELF Jamboree #11 Tokyo, Japan, Oct 27, 2006

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

Chapter 8: Memory-Management Strategies

Porting Linux to a New Architecture

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Björn Döbel. Microkernel-Based Operating Systems. Exercise 3: Virtualization

Transcription:

Cross Compiling Real Time Operating Systems and Middleware Luca Abeni luca.abeni@unitn.it

The Kernel Kernel OS component interacting with hardware Runs in privileged mode (Kernel Space KS) User Level Kernel Level switch through special CPU instructions (INT, TRAP,...) User Level invokes system calls or IPCs Kernel Responsibilities Process management Memory management Device management System Calls CPU Applications Kernel memory devices User Level Kernel Level Hardware

System Libraries Applications generally don t invoke system calls directly They generally use system libraries (like glibc), which Provide a more advanced user interface (example: fopen() vs open()) Hide the US KS switches Provide some kind of stable ABI (application binary interface)

Static vs Shared Libraries - 1 Libraries can be static or dynamic <libname>.a vs <libname>.so Static libraries (.a) Collections of object files (.o) Application linked to a static library the needed objects are included into the executable Only needed to compile the application

Static vs Shared Libraries - 2 Dynamic libraries (.so, shared objects) Are not included in the executable Application linked to a dynamic library only the library symbols names are written in the executable Actual linking is performed at loading time.so files are needed to execute the application Linking static libraries produces larger executables......but these executables are self contained

Embedded Development Embedded systems are generally based on low power CPUs......And have not much ram or big disks not suitable for hosting development tools Development is often performed by using 2 different machines: host and guest Guest: the embedded machine; Host: the machine used to compile Host and Guest often have different CPUs and architectures cross-compiling is needed

Cross-Compilers Cross Compiler: runs on the Host, but produces binaries for the Target Separate the Host environment from the Target environment Embedded systems: sometimes, scarce resources No disks / small (solid state) disks Reduced computational power... In some cases, cross-compilation is the only way to build programs!

Cross-Compiling Environments Cross-Compiling environment Cross-compiler (and some related utilities) libraries (at least system libraries) static or dynamic C compiler and C library: strictly interconnected building (and using) a proper cross-compiling environment is not easy

Cross-Compilers Internals - gcc gcc: Gnu Compiler Collection Compiler: high-level (C, C++, etc...) code assembly code (.s files, machine dependant) Assembler as: assembly machine language (.o files, binary) Linker ld: multiple.o files + libraries executable (ELF, COFF, PE,...) file ar, nm, objdump,... gcc -S: run only the compiler; gcc -c: run compiler and assembler,...

Cross-Compilers - Dependencies Assembler, linker, and similar programs are part of the binutils package gcc depends on binutils ld needs standard libraries to generate executables gcc depends on a standard C library But this library must be compiled using gcc... Circular dependency? Building a Cross-Compiler can be tricky...

Cross-Configuring GNU Packages gcc, binutils, etc... GNU tools configure script generated by automake / autoconf (--host=, --target=,...) Configuration Name (configuration triplet): cpu-manufacturer-operating system Systems which support different kernels and OSs: cpu-manufacturer-kernel-operating system Examples: mips-dec-ultrix, i586-pc-linux-gnu, arm-unknown-elf,...

Configuration Names cpu: type of processor used on the system (tipically i386, or sparc, or specific variants like mipsel ) manufacturer: freeform string indicating the manufacturer of the system (often unknown, pc,...) operating system: name of the OS (system libraries matter) Some embedded systems do not run any OS... use the object file format, such as elf or coff

Kernel vs OS Sometimes, no 1 1 correspondance between OS and kernel This mainly happens on linux-based systems The configuration name can specify both kernel and OS Example: i586-pc-linux-gnulibc1 vs i586-pc-linux-gnu The kernel ( linux ) is separated from the OS The OS depends on the used system libraries ( gnu glibc,...)

Building a gcc Cross-Compiler - Step 1: binutils First of all, build binutils./configure --target=arm-unknown-linux-gnu --host=i686-host pc-linux-gnu --prefix=... --disable-nls Generally, --host= is not needed (config.guess can guess it)

Building a gcc Cross-Compiler - Step 2: system headers Then, install some header files needed to build gcc Some headers provided by the Linux kernel (API for syscalls) Other headers provided by the standard C library (API for standard C functions) Sanitized kernel headers glibc headers

Building a gcc Cross-Compiler - Step 3: gcc Rember? Circular dependency with standard C library... How to break it? gcc must be built 2 times First, to build glibc (no threads, no shared libraries, etc...) Then, a full version after building glibc The first gcc build (stage1) can compile libraries, but not applications

Building a gcc Cross-Compiler - Step 4: glibc After building gcc the first time, glibc is built Then, a fully working gcc (using the glibc we just compiled) can be finally built Support for threads, the shared libraries we just built, etc For non-x86 architectures, some patches are sometimes needed

Helpful Scripts As seen, correctly building a cross-compiler can be difficult, long, and boring...... But there are scripts doing the dirty work for us! crosstool http://kegel.com/crosstool A slightly different (but more detailed) description can be found on the eglibc web site: www.eglibc.org

An Example: ARM Crosscompiler Download it from www.dit.unitn.it/ abeni/cross/cross.tgz Untar it in /tmp and properly set the path: cd /tmp tar xvzf cross.tgz #use the right path instead of cross.tgz PATH=$PATH:/tmp/Cross/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin Ready to compile: try arm-unknown-linux-gnu-gcc -v It is an ARM crosscompiler built with crosstool gcc 4.1.0 glibc 2.3.2

The Crosscompiler The crosscompiler is installed in /tmp/cross/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu In particular, the.../bin directory contains gcc and the binutils All the commands begin with arm-unknown-linux-gnu- Compile a dynamic executable with arm-unknown-linux-gcc hello.c Static executable: arm-unknown-linux-gcc -static hello.c

Testing the Crosscompiler Working ARM cross-compiler Runs on Intel-based PCs Generates ARM executables So, we now have an ARM executable... How to run it? Can I test the generated executable without using an ARM board? ARM Emulator: Qemu! qemu-arm a.out

QEMU QEMU: generic (open source) emulator Can also do virtualization Generic: it supports different CPU models ARM Can emulate CPU only or a whole system QEMU as a CPU emulator: executes Linux programs compiled for a different CPU. Example: ARM quemu-arm To execute a static ARM program, qemu-arm <program name> What about dynamic executables?

QEMU and Dynamic Executables To run a dynamic executable, the system libraries must be dynamically linked to it This happens at load time QEMU can load dynamic libraries, but you have to provide a path to them -L option qemu-arm -L <path to libraries> <program name> qemu-arm -L \ /tmp/cross/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/arm-unknown-linux-gnu \ /tmp/a.out