1 embedded system 2009/7/16 曹伯瑞. 2 outline what is embedded system embedded system booting...
Post on 20-Dec-2015
230 views
TRANSCRIPT
2
OutlineOutline
What is Embedded SystemEmbedded System
Booting Process
Setup Host/Target DevelopmentHost / Target Development Setups
Develop Tool
Building OS
Application PortingInstall an application
Optimizing Application Issues
Virtual Machine
Homework
4
Embedded System ?Embedded System ?
WhatEmbedded System is a special-purpose computer system designed to specific functions.
WhereIt can be found everywhere
MP3 player, air condition, vehicle control system, and so on.
How“We” often use linux-based operating system
5
The Scale of Embedded SystemThe Scale of Embedded System
Small-scaleLow-powerAbout 2 MB ROM, 4 MB RAM
Medium-scaleAbout 32MB ROM, 64MB RAMPerhaps with storage deviceEX: PDA, MP3 player
Large-scalePower-full or multi-coreUsually no resource constrain
6
System LayerSystem Layer
Hardware
Firmware
Operating System
Application
Hardware
Firmware
Operating System
Application
Hardware
Firmware
Desktop computer Complex embedded computer
Simple embedded computer
8
HardwareHardware
CPUsARM (arm7tdmi, arm9, strongARM, Xscale, …etc.)
MIPS
X86, 8086
SH
PowerPC…
Memory Technology DeviceROM
Flash
RAM
HD or CF card or USB storage
9
Hardware (Cont’)Hardware (Cont’)
Peripheralskeypad
USB device
RS232 (UART)
Network
IrDA
CF card others memory cards
10
Embedded OSEmbedded OS
DOSPalm OS WinCESymbianLinux
uCLinux - support non-MMU CPURTLinux - for real-time systemAndroid - Java and linux-based OS by googleOpenMoko Etc.
11
Memory Management Unit (MMU)Memory Management Unit (MMU)
CPUCore MemoryMMU
CPU
Physical Address
Virtual Address
12
LibraryLibrary
GNU C Library – glibcStandardInclude several libraries, ex: libm, libc, and so on.Too large for embedded system
uC-libc Original designed for uClinuxFor No MMU systemSupport m68000, ColdFire and ARMMost APIs are compatible to Glibc, but not all
uClibcAlso support MMUMore compatible to glibc, but still not allSupport m68000, ColdFire, ARM, MIPS, x86, SuperH, PowerPCSupport share library
14
What the hell is the black box doing?What the hell is the black box doing?
Power on
BIOSLoad the hardware configurationFind the booting device
MBR of booting deviceMBR (master boot record) is in the first sector of booting deviceBoot loader is stored in the MBR of booting deviceWhen booting, it will read the booting information of boot loader in MBR.
15
It’s time to prepare for workingIt’s time to prepare for working
Loading KernelBoot loader knows where the kernel is stored.
De-compress the compressed kernel image and start to drive the hardware device.
InitThe first executed process is init.
It reads the file “/etc/inittab”
Run-levelrun some application of /etc/rc.d/rcx.d
Login/bin/login
16
Root FilesystemRoot Filesystem
Root filesystem contains the set of applications, libraries, and related files needed to run the system
According to the requirement of the system, the architecture of Root filesystem is different.
Generally, the most useful directories of root filesystem arebin
dev
etc
lib
sbin
usr
proc*
17
MBRMBR
address Description Size (byte)
0 Code area 440 (max 446)
440 Optional Disk signature 4
444 Usually Nulls; 0x0000 2
446 Table of primary partitions 64
510 MBR signature 2
Total: 512 bytes
18
What is boot loader ?What is boot loader ?
Definition of Boot LoaderThe first section of code to be executed after the embedded system is powered on.
Boot Loader in x86 PC consists of two partsBIOS (Basic Input/Output System)OS Loader (located in MBR of Hard Disk)
Ex. LILO and GRUB
In some embedded systems the role of the boot loader is more complicated
Since these systems may not have a BIOS to initial system configuration
19
Boot loader Boot loader
Boot Loader is varied from CPU to CPU, from board to board
Since Boot Loader is very close to hardware
Hardware manufacturer may provide corresponding boot loader.
Examples:
LILO、 GRUBx86 compatible boot loader
PPCBOOTBoot loader for PowerPC based embedded Linux systems
20
Boot loader (Cont’)Boot loader (Cont’)
PMONFor MIPS architecture
Das U-Boot“Universal Boot loader“
For PowerPC, ARM, XScale, MIPS, Coldfire, NIOS, x86, etc.
21
BTWBTW
Because of the boot loader functionality, the boot loader we use have to depend on our OS
The boot loader have to “know” the kernel file-system.
LILO and GRUB support Windows and Linux, but the windows boot loader does not.
22
GRUBGRUB
grub.confdefault 0 timeout 5
title Fedora Core root (hd0,0)kernel /vmlinuz-2.6.18-1 root=/dev/sda1 initrd /initrd-2.6.18-1.img
title=Windows XP root (hd0,5) makeactive chainloader +1
24
First type of Host/Target Development SetupsFirst type of Host/Target Development Setups
Linked SetupHost contains the cross-platform development environment
Target contains an appropriate bootloader, kernel, and root filesystem
Kernel could be available via TFTP
Root filesystem could be NFS
25
Second type of Host/Target Development SetupsSecond type of Host/Target Development Setups
Removable Storage Setup OS is written into storage by the host, and then is transferred to the target, and is used to boot the target deviceHost contains the cross-platform development environmentTarget contains bootloaderThe rest of the components are stored on a removable storage media
26
Third type of Host/Target Development SetupsThird type of Host/Target Development Setups
Standalone Setup Target is a self-contained development system and includes all the required software to boot, operate, and develop additional software
28
Cross-Compiler ToolchainCross-Compiler Toolchain
Toolchain means not only compilerBut also Library, Linker (ld), assembler (as), other binutils, etc.
For two reasons we need the ToolchainDifferent architecture (ex: X86 & arm)
Different Library
Usually Toolchain is downloaded from Internet and just use it
If you have to setup Toolchain by yourself, you will get into big trouble
29
Setup Cross-Compiler Toolchain (1/3)Setup Cross-Compiler Toolchain (1/3)
Componentsgcc
binutilsas, ld, nm, etc
Libraryglibc or uClibc
PatchFix bug
Add some functions
30
Setup Cross Compiler Toolchain (2/3)Setup Cross Compiler Toolchain (2/3)
Versions are very importantnot all versions of one tool will build properly when combined with different versions of the others“New” doesn’t mean “Suitable”The only way to find the appropriate tool set is just “Try” or Google it
31
Setup Cross Compiler Toolchain (3/3)Setup Cross Compiler Toolchain (3/3)
Five main steps
1. Kernel headers setup
2. Binary utilities setup
3. Bootstrap compiler setupSome languages supported by gcc, such as C++, require C library support
Only support C language here
4. C library setupCompile library used in target system
5. Full compiler setupBuild full compiler with C library
33
Make and MakefileMake and Makefile
Development problemsIt is hard to manage the relationship of files in large project.Every change requires long compilation
MotivationTo manage the project well and automatically in the case of
Many lines of codeMultiple componentsMore than one programmer
34
Make and Makefile (Cont’)Make and Makefile (Cont’)
A Makefile is a file (script) containingProject structure (files, dependencies)
Instructions for files creation
The “make” command reads a Makefile, understands the project structure and makes up the executable
Note that the Makefile mechanism is not limited to C programs
36
Makefile ExampleMakefile Example
ExampleProgram contains 3 files
main.c, sum.c, sum.h
sum.h included in both .c files
Executable should be the file summarysummary
sum.omain.o
sum.csum.h sum.hmain.c
37
Makefile Example (Cont’)Makefile Example (Cont’)
summary: main.o sum.o
gcc -o summary main.o sum.o
main.o: main.c sum.h
gcc -c main.c
sum.o: sum.c sum.h
gcc -c sum.c
39
Building uClinuxBuilding uClinux
uClinux-dist http://www.uclinux.org/pub/uClinux/dist/
Full source packageincluding kernel, libraries and application
40
Platform ConfigPlatform Config
make menuconfig/ make xconfigSelect your platform & kernel version
43
Start to compile uClinuxStart to compile uClinux
Compilemake dep
Check the dependence of files
make
make Errors occur solve it (Google it) make again
44
Make for each componentsMake for each components
Make linux_onlyUsed to make kernel
Make user_onlyUsed to make application
Make lib_onlyUsed to make necessary library
Make romfsProduce Romfs (ROM file-system folder)
Make imageAccording Romfs folder, produce image file
45
Final outputFinal output
Finally, there are two files generated:zImage
uClinux kernel 2.4.x compress image
romfs.imgRom file-system
Write files into corresponding locationbootloader.bin
zImage
romfs.img
47
Install an applicationInstall an application
Advanced Packaging ToolThe APT is a free user interface to handle the installation and removal of software on the Debian GNU/Linux OS and its variants.Ex: $apt-get install vlc
Yellowdog Updater, ModifiedThe YUM is an open-source command-line package-management utility for RPM-compatible Linux operating systems and has been released under the GNU General Public License. Ex: #yum install vlc
Tarball installUse tar to compress source code in a fileUse source code to compile and install
48
Tarball installTarball install
Download application tarball and untar
Configureconfigure -h
for information about parameters
Some times the Makefile is generated by configure
configure --parametersEx: configure --enable-release --enable-optimizations
Compilemake
make Errors occur solve it (Google it) make again
make installInstall application or lib into specific location
49
Example: VLCExample: VLC
EnvironmentFedora Core 6
Kernel: 2.6.18
vlc-0.8.6b.tar.bz2http://download.videolan.org/pub/videolan/vlc/
configure --enable-dvb
make; make install
50
When installingWhen installing
Add the path of Toolchain to PATHexport PATH=/example/toolchain/path:$PATH
--prefix=PREFIXIndicate where to install application
--target=TARGETconfigure for building compilers for TARGET [HOST]
52
Down SizeDown Size
Remove unused part of applicationconfigure --disable-(something)
Reduce binary code sizestrip
One of binutils tool
Strip symbols and debug messages from object files
uClinuxELF -> FLAT
Optimum size in compile timegcc -Os
Cut down libraryAce in the hole
53
EfficiencyEfficiency
Dynamic linking -> Static
Use more efficient function in programEx: memcpy vs mmap
Even use assembly language to rewrite critical part
Optimum in configureconfigure --enable-release --enable-optimizations
Turn up gcc optimum levelgcc -O0 ~ -O3
56
VirtualizationVirtualization
At one time, desktop computers were “one machine, one operating system, one application”
The advent of “one machine, one operating system, many applications”
Today, virtualization lets users have “one machine, multiple operating systems, multiple applications”
Lets developers easily test their programs on multiple OSs
59
VMWare WorkstationVMWare Workstation
VMware Workstation is a virtual machine software suite allows users to set up multiple x86 and x86-64 virtual computers and to use one or more of these virtual machines simultaneously with the hosting operating system.
http://www.vmware.com/
60
VirtualBoxVirtualBox
VirtualBox is a general-purpose full virtualizer for x86 hardware. Targeted at server, desktop and embedded use, it is now the only professional-quality virtualization solution that is also Open Source Software.
http://www.virtualbox.org/
62
VLCVLC
Fulfill install process of VLC by page 49Use Tarball (Source code) install
Report configure parameters, encountering problems, the result and what you has learned from this
The VLC you install should can play music (ex:*.mp3) and Video (ex:*.avi)
63
ReferenceReference
Building Embedded Linux Systems, Karim Yaghmour, O’Reilly, 2003
uClinux, http://www.uclinux.org
VideoLAN developers, http://www.videolan.org/developers/vlc.html