Bina Software Development © http://www.bna.co.il1
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
Bina Software Development © http://www.bna.co.il17
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
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
DistributionsCommercial:
MontaVista BlueCat Linux…
MMU lessuCLinux
Hard Real-time supportRTLinux
© Bina Software Development http://www.bna.co.il20
Embedded Linux SystemBoot loader
U-bootGRUB…
KernelFile system
Many types
© Bina Software Development http://www.bna.co.il21
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
DevelopmentChoose C libraryUse the toolchain to create
User space applicationsKernel modules (drivers)
Many free tools
© Bina Software Development http://www.bna.co.il23
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");
Free toolsC libraryToolchainsEmulatorsRoot file systemsGraphical toolkits….
© Bina Software Development http://www.bna.co.il25
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)
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.
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
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.
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.
uClibc toolchains
Free Electrons uClibc toolchainshttp://free-electrons.com/community/tools/uclibcRun on i386 GNU/LinuxSupported platformsarm, armeb, i386, m68k, ppc, mips, mipsel, sh
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)
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.
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.
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!).
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
Other emulators
ColdFire emulatorhttp://www.slicer.ca/coldfire/Can boot uClinux
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
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.
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).
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)
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.
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
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.
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
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/
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!
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