Top Banner
Bina Software Development © http://www.bna.co.il 1 Introduction to Embedded Linux
48

Bina Software Development © 1 Introduction to Embedded Linux.

Dec 23, 2015

Download

Documents

Geoffrey Carter
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Bina Software Development ©  1 Introduction to Embedded Linux.

Bina Software Development © http://www.bna.co.il1

Introduction to Embedded Linux

Page 2: Bina Software Development ©  1 Introduction to Embedded Linux.

What is LinuxA fully-networked 32/64-Bit Unix-like Operating

SystemUnix Tools

Compilers

Network Tools

Multi-user, Multitasking, MultiprocessorHas the X Windows GUI

Runs on multiple platforms Includes the Source Code

Page 3: Bina Software Development ©  1 Introduction to Embedded Linux.

Where did it come from?Linus Torvalds created it

with assistance from programmers around the worldfirst posted on Internet in 1991

Linux 1.0 in 1994; 2.6 in 2003Open Source:

When programmers on the Internet can read, redistribute, and modify the source for a piece of software, it evolves

People improve it, people adapt it, people fix bugs. And this can happen at a speed that, compared to conventional software development, seems astonishing

Page 4: Bina Software Development ©  1 Introduction to Embedded Linux.

How do you get it?Download it from the InternetFrom a “Distribution” (e.g. RedHat)

Linux kernelX Windows system and GUIWeb, e-mail, FTP serversInstallation & configuration support3rd party appsHardware support

Page 5: Bina Software Development ©  1 Introduction to Embedded Linux.

Why is it significant?Growing popularityPowerful

Runs on multiple hardware platformsUsers like its speed and stabilityNo requirement for latest hardware

It’s “free”Licensed under GPLVendors are distributors who package Linux

Page 6: Bina Software Development ©  1 Introduction to Embedded Linux.

The Linux System

User commands

Shell

File SystemsKernel

Device Drivers

Hardware

User commands includes executable programs and scripts

The shell interprets user commands. It is responsible for finding the commands

and starting their execution. Several different shells are available. Bash is

popular,

The kernel manages the hardware resources for the rest of the system.

Page 7: Bina Software Development ©  1 Introduction to Embedded Linux.

ShellsAn interface between the Linux system and

the userUsed to call commands and programsAn interpreterPowerful programming language

“Shell scripts” = .bat .cmd EXEC REXXMany available (bsh; ksh; csh; bash; tcsh)

Character Based and Graphics Based

Page 8: Bina Software Development ©  1 Introduction to Embedded Linux.

Portability and hardware supportRuns on most architectures.

ScalabilityCan run on super computers as well as on tiny devices(4 MB of RAM is enough).

Compliance to standards and interoperability.

Exhaustive networking support.

SecurityIt can't hide its flaws. Its code is reviewed by many experts.

Stability and reliability.Modularity

Can include only what a system needs even at run time.

Easy to programYou can learn from existing code. Many useful resources on the net.

Linux Kernel

Page 9: Bina Software Development ©  1 Introduction to Embedded Linux.

Supported hardware architecturesSee the arch/ directory in the kernel sourcesMinimum: 32 bit processors, with or without MMU32 bit architectures (arch/ subdirectories)

alpha, arm, cris, frv, h8300, i386, m32r, m68k, m68knommu, mips, parisc, ppc, s390, sh, sparc, um, v850, xtensa

64 bit architectures:ia64, mips64, ppc64, sh64, sparc64, x86_64

Page 10: Bina Software Development ©  1 Introduction to Embedded Linux.

Kernel architecture

System call interface

Processmanagement

Memorymanagement

Filesystemsupport

Devicecontrol Networking

CPU supportcode

Filesystemtypes

Storagedrivers

Characterdevice drivers

Networkdevice drivers

CPU / MMU support code

C library

App1 App2 ... Userspace

Kernelspace

Hardware

CPU RAM Storage

Page 11: Bina Software Development ©  1 Introduction to Embedded Linux.

Linux Device Handling

Devices are the way linux talks to the worldDevices are special files in the /dev directory

(try ls /dev)

/dev/ttyx TTY devices/dev/hdb IDE hard drive/dev/hdb1 Partition 1-IDE hard drive/dev/null The null device /dev/zero An endless stream of zeroes/dev/mouse Link to mouse

Page 12: Bina Software Development ©  1 Introduction to Embedded Linux.

Devices and DriversEach /dev file has a major and minor

numberMajor defines the device typeMinor defines device within that typeDrivers register a device type

brw-r--r-- 1 root root 64, 0 Jun 1 1999 /dev/mndacrw-r--r-- 1 root root 5, 0 Jan 5 09:18 /dev/tty

Major no. Minor no.Device Type :b - blockc - character

Page 13: Bina Software Development ©  1 Introduction to Embedded Linux.

Special Files - /procInformation about internal Linux processes

are accessible to users via the /proc file system (in memory)

/proc/cpuinfo CPU Information

/proc/interrupts Interrupt usage

/proc/version Kernel version

/proc/modules Active modules

cat /proc/cpuinfovendor_id : IBM/S390

#processors : 1bogomips per cpu: 86.83processor 0: version = FF, identification = 045226, machine = 9672

Page 14: Bina Software Development ©  1 Introduction to Embedded Linux.

File SystemsLinux supports many different typesMost commonly, ext2fs

Filenames of 255 charactersFile sizes up to 2GB Theoretical limit 4TB

Derived from extfsHighly reliable and high performer

Page 15: Bina Software Development ©  1 Introduction to Embedded Linux.

File SystemsOther file systems:

sysv - SCO/Xenixufs - SunOS/BSDvfat - Win9xmsdos - MS-

DOS/Winumsdos -

Linux/DOSntfs - WinNT (r/o)hpfs - OS/2 (r/o)

Other File systems:iso9660 (CD-ROM)nfs - NFScoda - NFS-likencp - Novellsmb - LANManager

etc

Page 16: Bina Software Development ©  1 Introduction to Embedded Linux.

ProcessesProcesses are created in a hierarchical

structure whose depth is limited only by the virtual memory available to the virtual machine

A process may control the execution of any of its descendants by suspending or resuming it, altering its relative priority, or even terminating it

Termination of a process by default causes termination of all its descendants; termination of the root process causes termination of the session

Linux assigns a process ID (PID) to the process

Page 17: Bina Software Development ©  1 Introduction to Embedded Linux.

Bina Software Development © http://www.bna.co.il17

Embedded Linux

Page 18: Bina Software Development ©  1 Introduction to Embedded Linux.

What is Embedded Linux?porting the Linux kernel to run on a

particular CPU and board which will be put into an embedded device.

There are many companies that sell embedded Linux solutions.

These usually include a ported Linux kernel with cross-development tools, and sometimes with real time extensions.

the APIs and kernel codebase are the same for embedded Linux as desktop Linux

© Bina Software Development http://www.bna.co.il18

Page 19: Bina Software Development ©  1 Introduction to Embedded Linux.

Why Embedded Linux?Royalty-freeStrong networking supportHas already been ported to many different

CPU architecturesRelatively small for its feature setEasy to configureHuge application baseModern OS (eg. memory management,

kernel modules, etc.)

© Bina Software Development http://www.bna.co.il19

Page 20: Bina Software Development ©  1 Introduction to Embedded Linux.

DistributionsCommercial:

MontaVista BlueCat Linux…

MMU lessuCLinux

Hard Real-time supportRTLinux

© Bina Software Development http://www.bna.co.il20

Page 21: Bina Software Development ©  1 Introduction to Embedded Linux.

Embedded Linux SystemBoot loader

U-bootGRUB…

KernelFile system

Many types

© Bina Software Development http://www.bna.co.il21

Page 22: Bina Software Development ©  1 Introduction to Embedded Linux.

Building systemConfigure and compile Toolchain

Better idea: use already madeConfigure and make the boot-loaderInstall the boot loader on the target

Use special hardware or older board boot loader

Configure and compile the kernelBuild file system

© Bina Software Development http://www.bna.co.il22

Page 23: Bina Software Development ©  1 Introduction to Embedded Linux.

DevelopmentChoose C libraryUse the toolchain to create

User space applicationsKernel modules (drivers)

Many free tools

© Bina Software Development http://www.bna.co.il23

Page 24: Bina Software Development ©  1 Introduction to Embedded Linux.

Kernel modules

© Bina Software Development http://www.bna.co.il24

/* hello.c */#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>

static int __init hello_init(void){ printk(KERN_ALERT "Good morrow"); printk(KERN_ALERT "to this fair assembly.\n"); return 0;}

static void __exit hello_exit(void){ printk(KERN_ALERT "Alas, poor world, what treasure"); printk(KERN_ALERT "hast thou lost!\n");}

module_init(hello_init);module_exit(hello_exit);MODULE_LICENSE("GPL");MODULE_DESCRIPTION("Greeting module");MODULE_AUTHOR("William Shakespeare");

Page 25: Bina Software Development ©  1 Introduction to Embedded Linux.

Free toolsC libraryToolchainsEmulatorsRoot file systemsGraphical toolkits….

© Bina Software Development http://www.bna.co.il25

Page 26: Bina Software Development ©  1 Introduction to Embedded Linux.

C library

http://www.gnu.org/software/libc/License: LGPLC library from the GNU projectDesigned for performance, standards

compliance and portabilityFound on all GNU / Linux host systemsQuite big for small embedded systems:

about 1.7 MB on Familiar Linux iPAQs (libc: 1.2 MB, libm: 500 KB)

Page 27: Bina Software Development ©  1 Introduction to Embedded Linux.

uClibc

http://www.uclibc.org/ for CodePoet ConsultingLicense: LGPLLightweight C library for small embedded systems,

with most features though.The whole Debian Woody was ported to it...

You can assume it satisfied most needs!Size (arm): 4 times smaller than glibc!

uClibc: approx. 400 KB (libuClibc: 300 KB, libm: 55KB)glibc: approx 1700 KB (libc: 1.2 MB, libm: 500 KB)

Now supported by MontaVista and TimeSys.

Page 28: Bina Software Development ©  1 Introduction to Embedded Linux.

Honey, I shrunk the programs!

C program Compiled with shared libraries Compiled statically

glibc uClibc glibc uClibc

Plain “hello world” 4.6 K 4.4 K 475 K 25 K

Busybox 245 K 231 K 843 K 311 K

Page 29: Bina Software Development ©  1 Introduction to Embedded Linux.

newlib

http://sources.redhat.com/newlib/Minimal C library for very small embedded

systemsLets you remove floating point support

wherever you don't need it. Also provides an integer only iprintf() function. Much smaller!

Provides single precision math library functions. Much faster than the standard IEEE compliant ones.

Page 30: Bina Software Development ©  1 Introduction to Embedded Linux.

klibc

http://www.kernel.org/pub/linux/libs/klibc/“Kernel C library”Tiny and minimalistic C library designed for use in an initramfs at boot time (alternative to initrds).Fine for the creation of simple shell scripts.Not elaborate enough to support BusyBox applications.

Page 31: Bina Software Development ©  1 Introduction to Embedded Linux.

uClibc toolchains

Free Electrons uClibc toolchainshttp://free-electrons.com/community/tools/uclibcRun on i386 GNU/LinuxSupported platformsarm, armeb, i386, m68k, ppc, mips, mipsel, sh

Page 32: Bina Software Development ©  1 Introduction to Embedded Linux.

Platform specific toolchains

ARMCode Sourcery (glibc only, used by many):

http://www.codesourcery.com/gnu_toolchains/arm/

Also available for Solaris and Windows workstations.

ftp://ftp.handhelds.org/projects/toolchain/ (glibc only)

MIPShttp://www.linux-mips.org/wiki/Toolchains

(useful links)

Page 33: Bina Software Development ©  1 Introduction to Embedded Linux.

Toolchain building utilities

Buildroot: http://buildroot.uclibc.org/Dedicated Makefile to build uClibc based

toolchainsand even entire root filesystems.

Downloads sources and applies patches.Crosstool: http://www.kegel.com/crosstool/Dedicated script to build glibc based toolchains

Doesn’t support uClibc yet.Downloads sources and applies patches.

Page 34: Bina Software Development ©  1 Introduction to Embedded Linux.

Scratchbox

http://scratchbox.org/ - A cross-compiling toolkit projectMakes it easier to cross-compilea complete embedded Linux system.Works by allowing tools to be cross-compiled in a transparent way, making building tools believe they are doing a native compile job.Supported platforms: arm, x86Uses the qemu emulator to transparently run built arm binaries.Experimental support for ppc, mips and cris.

Page 35: Bina Software Development ©  1 Introduction to Embedded Linux.

qemu

http://qemu.orgFast processor emulatorusing a portable dynamic translator.

Full system emulationEmulates the processor and various peripheralsSupported: x86, x86_64, ppc, arm, sparc, mipsTo know which machine types are supported:qemu-system-arm -M ?i386, x86_64 system emulation: now close to native speedsthanks to the kqemu kernel module (now GPL v2!).

Page 36: Bina Software Development ©  1 Introduction to Embedded Linux.

ARM emulators

Only Free Software, of course!SkyEye: http://skyeye.sourceforge.net

Emulates several ARM platforms (AT91, Xscale...) and can boot several operating systems (Linux, uClinux, and others)

Softgun: http://softgun.sourceforge.netVirtual ARM system with many virtual on-board peripherals. Boots Linux.

SWARM - Software ARM - arm7 emulatorhttp://www.cl.cam.ac.uk/~mwd24/phd/swarm.html

Can run uClinux

Page 37: Bina Software Development ©  1 Introduction to Embedded Linux.

Other emulators

ColdFire emulatorhttp://www.slicer.ca/coldfire/Can boot uClinux

Page 38: Bina Software Development ©  1 Introduction to Embedded Linux.

Minicom

Definition: serial communication programAvailable in all GNU / Linux distributionsCapabilities (all through a serial link):

Serial console to a remote Unix systemFile transferModem control and dial-upSerial port configuration

Page 39: Bina Software Development ©  1 Introduction to Embedded Linux.

General purpose toolbox: BusyBox

http://www.busybox.net/Most Unix command line utilities within a single executable!

It even includes a web server!Sizes less than < 500 KB (statically compiled with uClibc) or

less than 1 MB (statically compiled with glibc).Easy to configure which features to include.The best choice for

Initramfs / initrd with complex scriptsSmall and medium size embedded systems

See http://www-128.ibm.com/developerworks/linux/library/l-busybox/

for a nice introduction.

Page 40: Bina Software Development ©  1 Introduction to Embedded Linux.

ssh server and client: dropbear

http://matt.ucc.asn.au/dropbear/dropbear.htmlVery small memory footprint ssh server for embedded

systemsSatisfies most needs. Both client and server!Size: 110 KB, statically compiled with uClibc on i386.

(OpenSSH client and server: approx 1200 KB,dynamically compiled with glibc on i386)

Useful to:Get a remote console on the target deviceCopy files to and from the target device (scp or

rsync -e ssh).

Page 41: Bina Software Development ©  1 Introduction to Embedded Linux.

Benefits of a web server interface

Many network enabled devices can just have a network interface

Examples: modems / routers, IP cameras, printers...No need to develop drivers and applications for

computers connected to the device. No need to support multiple operating systems!

Just need to develop static or dynamic HTML pages(possibly with powerful client-side JavaScript).Easy way of providing access to device information and parameters.

Reduced hardware costs (no LCD, very little storage space needed)

Page 42: Bina Software Development ©  1 Introduction to Embedded Linux.

thttpd

Tiny/Turbo/Throttling HTTP serverhttp://acme.com/software/thttpd/SimpleImplements the HTTP/1.1 minimum (or just a little more)Simple to configure and run.SmallExecutable size: 88K (version 2.25b), Apache 2.0.52: 264KVery low memory consumption: does not fork and very careful about memory consumption.

PortableCompiles cleanly on most Unix-like operating systems

FastAbout as fast as full-featured servers. Much faster on very high loads (because reduces the server load for the same amount of work)

SecureDesigned to protect the webserver machine from attacks.

Page 43: Bina Software Development ©  1 Introduction to Embedded Linux.

Other web servers (1)

BusyBox http server: http://busybox.netTiny: only adds 9 K to BusyBox 1.5 (dynamically linked with glibc on i386, with all features enabled.)! Sufficient features for many devices with a web interface, including CGI, http authentication and script support (like PHP).License: GPL

KLone: http://koanlogic.com/kl/cont/gb/html/klone.htmlLightweight but full featured web server for embedded systems.Can enclose dynamic (written in C/C++ <% code %>) and compressed content all in an executable of an approximate size of 150 KB.License: Dual GPL / Commercial.See also http://linuxdevices.com/news/NS8234701895.html

Page 44: Bina Software Development ©  1 Introduction to Embedded Linux.

Other web servers (2)

Boa: http://www.boa.org/Designed to be simple, fast and secure.Unlike thttpd, no particular care for memory or disk footprint though.Embedded systems: pretty popular, though not targeted by developers.

lighthttpd: http://lighttpd.netLow footprint server good at managing high loads.May be useful in embedded systems too.

Page 45: Bina Software Development ©  1 Introduction to Embedded Linux.

Graphical toolkits

Licenses matter here!Toolkits allowing proprietary applications

Nano-X / Microwindows, FLTK, SDL, DirectFB, GTK

GPL toolkits (commercial license required for proprietary apps)MiniGUI, Qt Embedded

Graphical environments and applicationsQtopia, Opie, GPE

Web browser based interfaces

Page 46: Bina Software Development ©  1 Introduction to Embedded Linux.

Linux porting projects

Useful to find patches, binaries, documentation, toolchains...Only ports for embedded systems are listedarm: http://www.arm.linux.org.uk/See also http://www.linux-arm.org/ (from ARM Limited)m68k: http://www.linux-m68k.org/mips: http://www.linux-mips.org/ppc: http://penguinppc.org/embedded/sh: http://linuxsh.sourceforge.net/xtensa: http://xtensa.sourceforge.net/

Page 47: Bina Software Development ©  1 Introduction to Embedded Linux.

Useful web sites

LinuxDevices.com: http://linuxdevices.comWeekly newsletter with news and

announcements about embedded devices running Linux.

Articles, whitepapers, and Linux embedded devices catalog.

An excellent site to follow industry news!

Page 48: Bina Software Development ©  1 Introduction to Embedded Linux.

More infohttp://free-electrons.com

Best site: many resourceshttp://bina-soft.blogspot.com/

Our blog and source repository

© Bina Software Development http://www.bna.co.il48