Professional Documents
Culture Documents
~ Kiran Divekar
Agenda
Embedded Linux
Run on Limited Resource
Real Time
Dedicated Device Drivers
Embedded Linux
PowerPC CPU
16MB DRAM 16MB Flash
Serial & Ethernet Ports
Linux and IEC1131 Programming/Modbus
Sharp Zaurus
Lineo Embedix
206 MHz StrongARM
64 MB DRAM 16MB Flash
3.5 display (320x240) 64K
colors
Opera browser & Qtopia
QT/Embedded GUI
GITWiT Mobile
Phone
Aplio/PRO IP Phone
uCLinux
Built-in Ethernet port
100 MHz ETRAX CPU
16 MB RAM
Humanoid Robots
Isamu
Univ. of
Tokyo/Kawanda
Ind.
Dual Pentium CPU
RT-Linux
Height: 53 inches
Weight: 121 lbs.
Humanoid Robots
HOAP
Fujitsu
RT-Linux
Height: 48 cm
Weight: 6 kg
100 units/yr
Modular
Scalable
Configurable
Small footprint
CPU support
Device drivers
etc, etc, etc...
Soft
Kinda, sorta, usually
QualComm : REX OS
Palm Computing
PalmOS
Symbian
SymbianOS, S60, S80, S90
Microsoft
Embedded NT/XP
Real-time control
Windows CE (CE.NET)
Internet devices
Pocket PC 2002
Handheld PCs and PDAs
Coollogic Coollinux
combines Linux and Java for Internet apps
Coventive Xlinux
kernel can be as small as 143KB
Lineo Embedix
supports real time and high availability apps
LynuxWorks BlueCat
general purpose embedded solution
MontaVista Linux
general purpose embedded solution
PalmPalm Tynux
Internet appliuance and multimedia
Tuxia TASTE
distro targets Internet appliances
ETLinux
for PC104 SBCs
uCLinux
for microprocessors that dont have MM
uLinux (muLinux)
distro fits on a single floppy
RTLinux
GUI Applications
GUI
Kernel
Device Driver
Hardware
Linux on PC
#
#
#hello world :-(
#
#
PC
User Apps
Keybo
Kernel
ard
Disk File
System
Memory
IO
Devices
File System
File system on disk
User Apps
CPU
RAM
ROM
IO
Kernel
File System
File system on chip
UI
Printf
Kernel
Kernel
Device
Driver
Scanf
Display Adaptor
#
#
#hello world :-(
#
#
Keyboard Driver
Keybo
ard
UI on Embedded System
Printf
Kernel
Device
Driver
Scanf
Kernel
Display Adaptor
Any Output
Device
Keyboard Driver
Any Input
Device
Replacing
Displayer
LCD
Button
UART
Touch
screen
LED
Network
Replacing
Keyboard
UART
Network
UI on UART
Printf
Kernel
Device
Driver
Scanf
Kernel
UART Driver
Txd
Rxd
Layout
System
Memory
Usage
(Static)
Bootloader
ROM
Kernel
Rootdisk
RAM
System
Memory
Usage
(Running)
Bootloader
ROM
Kernel
Rootdisk
Kernel
RAM
Rootdisk
User
Memory
Ethernet
RS232
Local
Booting
Linux
kernel
RAM
RAM Disk
0x0xffe00000
u-boot
ROM
Zipped Linux
kernel
Zipped root
image
Linux
kernel
192.168.0.3
DHCP server
RAM
TFTP server
Zipped kernel
Linux image
(/home/TFTPdir/uImage)
NFS server
0x0xffe00000
u-boot
ROM
MyIP: 192.168.0.253
Server IP: 192.168.0.3
Kernel Name: uImage
NFS position: /home/NFSdir
Bootloader
Redboot
U-boot
Homemade bootloader
Grub ???
Function of
Bootloader
Bootloader
ROM
Rootdisk
Init Board
Also support some basic
debugging function
Loading Kernel
From ROM or From
Remote Server
Kernel
RAM
Root Disk
Host Target Development environment
Arm
targets : Linux supports 10 distinct ARM
Advanced RISC Machine
http://www.arm.linux.org.uk
SCSI, USB, I2C buses
Parallel, Serial ports
MTD storage
Host Target
Host: Development machine
Target: Embedded target system
Make ARCH=arm CROSSCOMPILE=arm-linux-
Cross-compilation
Components
Kernel uImage
Loadable modules if non-GPL
RFS
Init scripts
Busybox (configrable)
Apps
Done !!!
Kernel uImage
Configuration
Make allnoconfig ?
Arch/<arch>/configs/
B.S.P. [ Board Support Package ]
RFS
Jffs2 images
Squashfs images
Initrd.gz for GRUB
PC
1010010
1101100
1111011
1110101
1101010
Download File To
Development Board
Development
Board
ROM
RFS
Jffs2, squashfs images
Netboot
setenv x_bootargs_root 'root=/dev/nfs rw nfsroot=$(serverip):$(rootpath) ip=$
(ipaddr):$(serverip):$(bootargs_end);'
setenv serverip 192.168.1.1
setenv ipaddr 192.168.1.10
setenv rootpath /home/test/exports/
NFS
PC
With NFS Server
Ethernet
1111011
1110101
1101010
Cable
Development
Board
(Running
Linux)
uclibc
C
program
Compiled with
shared libraries
glibC
Hello
World
uClibc
Compiled statically
glibC
uClibc
4.6 K
4.4 K
475 K
25 K
Busybox 245 K
231 K
843 K
311 K
Tools
Files
ls Busybox
/dev/console Device files
myapp cross-compiled application
watchdog
stability module
Optimizations
1. kernel optimizations
2. memory
3. performance
4. Size
5. Security
Startup Optimizations
System startup /etc/inittab
SysV init:
Starts services sequentially. Waits for the
current startup script to be complete to start the
next one! While dependencies exist, some tasks
can be run in parallel!
Initng: http://initng.thinktux.net
New alternative to SysV init, which can start
services in parallel, as soon as their
preconditions are met
Memory Optimizations
Upfront memory allocations
Implement and manage memory pools
This reduces the overheads of allocation and
freeing of memory.
Adds pool maintenance overhead
Security Tools
Selinux
Grsec
Lids
Lidsadm
Listconf
Network Performance
TCP / IP tuning
/etc/sysctl.conf
net/core/rmem_max = 8738000
net/core/wmem_max = 6553600
net/ipv4/tcp_rmem = 8192 873800 8738000
net/ipv4/tcp_wmem = 4096 655360 6553600
Prelinking (1)
Applies to executables using shared libraries
To load and start an executable, the
dynamic linker has a significant amount of
work to do (mainly address relocation)
It can take a lot of time for executables
using many shared libraries!
In many systems in which executables and
shared libraries never change, the same
job is done every time the executable is
started.
Use a profiler
Using a profiler can help to identify
unexpected behavior degrading application
performance.
For example, a profiler can tell you in which
functions most of the time is spent.
Easy to do with Valgrind: http://valgrind.org/
Linux-Tiny
Goal: reduce the disk footprint and RAM size
of the Linux kernel
Set of patches against the mainstream Linux
kernel.
Mergeability in mainstream is a priority.
Many changes have already been merged in
recent kernels.
All features can be selected in kernel
configuration (CONFIG_EMBEDDED).
panic...)
Hunt excess inlining (speed vs. size tradeoff)
Hunt excess memory allocations
Memory (slob instead of slab) allocator more
space efficient for small systems.
Simpler alternative implementations of kernel
functionalities with less features, or not
supporting special cases.
Kernel XIP
strip command.
This can save a very significant amount of
space!
gcc -o hello hello.c
(output size:
4635 bytes)
strip hello
(output
size: 2852 bytes, -38.5%)
Don't forget to strip libraries too!
How to strip
Some lightweight tools, like busybox, are
automatically stripped when you build them.
Makefiles for many standard tools offer a
special command:
make install-strip
Caution: stripping is architecture
dependent.
Use the strip command from your crosscompiling toolchain:
arm-linux-strip potato
Library Optimizer
http://libraryopt.sourceforge.net/
Examines the complete target file system,
resolves all shared library symbol
references, and rebuilds the shared
libraries with only the object files required
to satisfy the symbol references.
Can also take care of stripping executables
and libraries.
Restartable applications
When RAM is scarce, can be useful to
abort applications that are not in use.
Better to do it before the Linux Kernel
OOM (Out Of Memory) killer comes and
makes bad decisions.
To support this, design your programs with
the capability to save their state when they
are aborted and return to it when they are
restarted. [ HA ???]
Compressing filesystems
Can significantly increase your storage
capacity
MTD (flash or rom) storage: use jffs2
Block storage: use SquashFS (
http://squashfs.sourceforge.net) instead
of CramFS for read-only partitions. It
compresses much better and is much
faster too.
Tickless kernel
Kernel configuration: NO_HZ setting in Processor type
and features
To implement multitasking, the processor receives a
timer interrupt
at a given frequency (every 4 ms by default on Linux
2.6). On idle systems, this wakes up the processor all
the time, just to realize there is nothing to do!
Idea: when all processors are idle, disable the timer
interrupt, and re-enable it when something happens (a
real interrupt). This saves power in laptops, in
embedded systems and with virtual servers!
Software suspend
http://www.suspend2.net/
Lots of great features for notebook users,
such as RAM suspend or hibernate to disk.
Unfortunately, restricted on some Intel
compatible processors and targeting only
machines with APM or ACPI
Not addressing the requirements of
embedded systems
Tickless operation
CPU frequency control
Suspend hidden GUIs
Software suspend (for PC embedded
systems)
Kernel and application XIP
Power management in device drivers
Use mlockall()
Parts of the address space of a process may be
swapped out or not loaded yet (on-demand paging:
the kernel only loads process pages with are
actually accessed, and loads other ones when
actually accessed). This causes unpredictable
delays in process execution.
The mlockall() system call can be used to make
sure that the entire address space of a running
process is loaded in RAM.
Useful for real-time applications needing
predictable response time.
Debugging
Gdb server on Target
Target remote over serial/network
Unstripped binaries at host
Mechanisms to export cores.
Accidental reboots.
Remote
Debugging
Ethernet
Cable
GBD Server
Remote PC
Running Linux
GDB
Ethernet
RS232
Unified tools
Android : software platform and operating
system written by Google and the Open Handset
Alliance
Openwrt
Scratchbox
Code-sourcery
Metroworks
Further info
Home page:
http://handhelds.org/
Mailing lists:
http://www.handhelds.org/email_lists.html
LinuxDevices.com
http://www.linuxdevices.com/
Embedded Linux Consortium
http://www.embedded-linux.org/index.php3
All Linux Devices
http://alllinuxdevices.com/
Embedded Linux StarGate
http://linux-embedded.com/
54 48 41 4E 4B
59 4F 55