資工系網媒所NEWS實驗室

Download Report

Transcript 資工系網媒所NEWS實驗室

嵌入式作業系統實作
Implementation of
Embedded Operating Systems
Introduction
薛智文
[email protected]
http://www.csie.ntu.edu.tw/~cwhsueh/
國立台灣大學
資訊工程學系
12:02
1 /5
資工系網媒所
NEWS實驗室
Rules in Class
Be on Time for class, deliverable, …
Food is OK but no alcohol.
Nap is OK but no snoring.
Ask questions in classes, not between.
Do participate.
Course Outline is a reference.
12:02
2 /5
資工系網媒所
NEWS實驗室
Outline
Introduction to Embedded System
Introduction to Embedded
Operating System
Case Studies
SoCKernel
12:02
3 /64
資工系網媒所
NEWS實驗室
Preface
Linux
image
files
directories
lines
bytes
2.6.4
1150K
13400
960
5.6M
167M
2.4.25
1177K
11000
670
5M
149M
2.2.26
507K
5100
280
2.5M
75M
ThreadX
129K
158
1
29K
1.5M
uC/OS-II
55K
13
1
5.5K
0.4M
Tinix’
0.5K
1
1
20
0.5K
Window 2000, 30M lines.
Netscape Communicator 5, 17M lines.
A 圍棋 program, 0.01M lines.
A SOHO router, 0.6M lines.
What is Embedded (Linux/system)?
12:02
4 /64
資工系網媒所
NEWS實驗室
Embedded OS trends 2001-2002,
sorted by 2001
30%
25%
20%
2001
15%
2002
10%
5%
0%
Chorus
LynxOS
Green Hills
Nucleus
QNX
WinCE
Embedded Linux
DOS
VxWorks
Home grown
12:02
5 /64
資工系網媒所
NEWS實驗室
Embedded OS trends 2001-2002,
sorted by 2002
30%
25%
20%
2001
15%
2002
10%
5%
0%
Home grown
Chorus
DOS
QNX
Green Hills
BSD
LynxOS
WinCE
VxWorks
Embedded Linux
12:02
6 /64
資工系網媒所
NEWS實驗室
電子書包與數位學習輔具分工架構圖
數位學習平台
數位學習輔具
數
位
學
習
輔
具
Physical
•Serial
•USB
•1394
•IrDA
•Bluetooth
•802.11
電子書包平台結構
數位學
習平台
閱讀
程式
SCORM
HTML
XML
開發工具
電子書包教學數位內容
電子書包數位內容
開發工具
教師教學
應用軟體
教學 / 同儕群體
應用軟體開發工具
同儕群體
應用軟體
電子書包教學應用平台
系統軟體開發工具 (SDK)
相容性測試軟體工具(TCK)
電子書包作業系統 (OS / UI / CM)
Protocol
•SyncML
12:02
電子書包發展硬體
ICE
DDK
7 /64
資工系網媒所
NEWS實驗室
Tinix’
org 07c00h
mov ax, cs
mov ds, ax
mov es, ax
call DispStr
jmp $
DispStr:
mov ax, BootMessage
mov bp, ax
mov cx, 16
mov ax, 01301h
mov bx, 000ch
-“自己動手寫作業系統,” 于淵
; tell the assembler to load onto 7c00, 0100h for DOS
; call string display procedure
; infinite loop
; ES:BP = string address
; CX = string length
; AH = 13, AL = 01h
; page number is 0 (BH = 0) black background red character
; (BL = 0Ch, highlight)
mov dl, 0
int 10h
; the 10h software interrupt
ret
BootMessage:
db
"Hello, OS world!"
times 510-($-$$) db 0 ; fill the rest of sector (512 bytes) with 0
dw 0xaa55
; end of sector
資工系網媒所
NEWS實驗室
Example
Ethernet
RS485
Ethernet
RS485
12:02
9 /64
資工系網媒所
NEWS實驗室
Application vs. Response Time
12:02
10 /43
資工系網媒所
NEWS實驗室
在嵌入式軟體開發中採用的作業環境
EE Times-Asia, 2006 Dec
12:02
資工系網媒所
11/257 NEWS實驗室
在設計專案中採用即時作業系統
EE Times-Asia, 2006 Dec
12:02
資工系網媒所
12/257 NEWS實驗室
在韌體開發中採用的語言
EE Times-Asia, 2006 Dec
12:02
資工系網媒所
13/257 NEWS實驗室
在嵌入式應用開發中採用的語言
EE Times-Asia, 2006 Dec
12:02
資工系網媒所
14/257 NEWS實驗室
不同工具的重要性及工程師滿意程度
12:02
資工系網媒所
15/257 NEWS實驗室
嵌入式設計中前10名軟硬體開發工具
Hardware/software
Development Tools
GNU compilers
Logic analyzers
Compilers
IDE
Oscilloscopes
JTAG emulators
GNU debuggers
Debuggers
ICE
Networking protocols
12:02
資工系網媒所
16/257 NEWS實驗室
12:02
資工系網媒所
17/257 NEWS實驗室
Introduction
Unix SVR4, System V Release 4, AT&T, now owned by
Santa Cruz Operation, Inc.;
4.4 BSD, UC Berkeley
Digital Unix, DEC  Compaq  HP
AIX, IBM
HP-UX, HP
Solaris, Sun Microsystems, Stanford University
Linux, 1991 Linus Torvalds on 80386  Alpha, SPARC,
680x0, PowerPC, IBM 390, ARM, …
A Unix kernel with other applications available under GNU
General Public License
GNU’s Not Unix
POSIX, Portable OS based on Unix
12:02
18 /64
資工系網媒所
NEWS實驗室
Outline
Introduction to Embedded System
Introduction to Embedded
Operating System
Software Engineering
Case Studies
SoCKernel
Paper discussion
12:02
19 /64
資工系網媒所
NEWS實驗室
What is an Embedded System?
A system designed to perform a specific
function, e.g. eBook, PDA, eWatch, …
A combination of computer hardware and
software, and perhaps additional mechanical
or other parts.
Embedded vs. General-Purpose
What is a specific function?
Is there a limitation?
Cost, Robust, Low-power, Small, …
Using C + Assembly, Java ?
12:02
20 /64
資工系網媒所
NEWS實驗室
Embedded System Examples
Computer peripherals
Keyboard, Mouse, …
Information Appliances
Set-Up Boxes, WebTV, …
Monitors and Sensors
Fire Alarm, Heartbeat Detector, …
Controllers in Electronics
Refrigerator, Air Conditioner, …
Communication Devices
Hub, Router, …
…
12:02
21 /64
資工系網媒所
NEWS實驗室
Business Issues of ES
Time-to-market for new devices
Design to delivery: in weeks
Sustained pressure to reduce costs
Many proprietary choices yield low-margins
Life cycle management
New products overlapping each other
Positioning nightmares
Open platform choices considered risky?
Resources expended on “recreating the
wheel…” not on product differentiation.
12:02
22 /64
資工系網媒所
NEWS實驗室
12:02
23 /64
資工系網媒所
NEWS實驗室
ES Technology Issues
Need more complex technology integrated for
new services
broadband, wireless, real-time, low-power, …
Multiple emerging standards need to be
deployed simultaneously.
Product released globally on the same day!
Tools, Tools, Tools, …
Third party software
No one company can do it all anymore
Support nightmares
Lack of sources from proprietary choices
Open sources sound seductive … but risky.
12:02
24 /64
資工系網媒所
NEWS實驗室
Real-Time Systems vs.
Embedded Systems
RTS
ES
RTES
.Radar
12:02
.ABS
.Calculator
25 /64
資工系網媒所
NEWS實驗室
Real-Time Systems
Value
Deadline
Soft RTS
Hard RTS
FirmRTS
Time
-Value
12:02
26 /64
資工系網媒所
NEWS實驗室
Real-Time Systems (RTS)
Open
Distributed
Hard RTS
Soft RTS
Proprietary
Centralized
Firm RTS
Embedded
12:02
27 /64
資工系網媒所
NEWS實驗室
Outline
Introduction to Embedded System
Introduction to Embedded
Operating System
Software Engineering
Case Studies
SoCKernel
Paper discussion
12:02
28 /64
資工系網媒所
NEWS實驗室
Linux
2.2 Aims to be compliant with IEEE POSIX
Source codes from other Unix-like kernel can
be compiled and executed with little efforts,
even without patches.
Include modern OS features, i.e. virtual
memory, virtual filesystem, lightweight
processes, signals, IPC, SMP, …
Was not very innovative except General Public
License (GPL).
12:02
29 /64
資工系網媒所
NEWS實驗室
Linux vs. Other Unix-Like Kernels
Linux kernel is monolithic.
Same as most other Unix variants while Mach 3.0,
uses microkernel (task management + semaphore +
timer), from CMU
Linux supports modules.
Traditional kernels are compiled and linked statically.
Limited kernel threads
can not execute user programs,
Nonstandard lightweight process, using clone().
Linux is a nonpreemptive kernel.
Only Solaris 2.x, Mach 3.0 are fully preemptive.
Introduce fixed preemption points to cure.
12:02
30 /64
資工系網媒所
NEWS實驗室
Linux vs. Other Unix-Like Kernels (cont.)
Multiprocessor support after 2.2.
filesystem and network operation still remain
sequential.
Filesystem is standard but is easy to port other
filesystem through VFS.
EXT2, EXT3 (Journaling), ReiserFS (small files)
IBM AIX, Journaling File System
SGI Irix, XFS filesystem, for big volume, guaranteed
I/O rate, and journaling.
No STREAMS I/O subsystem, from SVR4,
popular in other Unix kernels for writing device
drivers, terminal drivers, and network protocols.
rejected by Linus because of performance.
12:02
31 /64
資工系網媒所
NEWS實驗室
Why Linux?
Free, no charge.
Free, fully customizable in all components.
Runs on low-end cheap HW platforms.
Embedded Linux is very hot.
Powerful.
open source so as to fully utilize HW.
High standard for source code quality.
low failure rate and maintenance time.
Kernel can be very small and compact.
Highly compatible with other OSes.
Filesystem, networking, code executed directly.
Well supported.
12:02
32 /64
資工系網媒所
NEWS實驗室
Hardware Dependency
Linux maintains a neat distinction between hardware-dependent and
hardware-independent source code.
alpha  Hewlett-Packard's Alpha workstations
arm  ARM processor-based computers and embedded devices
cris  "Code Reduced Instruction Set" CPUs used by Axis in its thin-servers,
such as web cameras or development boards
i386  IBM-compatible personal computers based on 80 x 86 microprocessors
ia64  Workstations based on Intel 64-bit Itanium microprocessor
m68k  Personal computers based on Motorola MC680 x 0 microprocessors
mips  Workstations based on MIPS microprocessors
mips64  Workstations based on 64-bit MIPS microprocessors
parisc  Workstations based on Hewlett Packard HP 9000 PA-RISC
microprocessors
ppc  Workstations based on Motorola-IBM PowerPC microprocessors
s390  32-bit IBM ESA/390 and zSeries mainframes
s390 x  IBM 64-bit zSeries servers
sh  SuperH embedded computers developed jointly by Hitachi and
STMicroelectronics
sparc  Workstations based on Sun Microsystems SPARC microprocessors
sparc64  Workstations based on Sun Microsystems 64-bit Ultra SPARC
microprocessors
Taiwan Core
12:02
33 /64
資工系網媒所
NEWS實驗室
Power Management
Halting in the idle process
idle process executes hlt on Intel
low-power consumption mode
Suspending the system
patches for suspending to disk
APM: Advance Power Management
laptop standard power management
ACPI: Advanced Configuration and Power Interface
new comprehensive standard from Intel-Microsoft
Power-management is essential for mobile systems
12:02
34 /64
資工系網媒所
NEWS實驗室
Linux 2.6 Highlights
New scheduler
New architectures and processor types
have been added – including support for
MMU-less systems
New set of drivers for audio and
multimedia have been added
Others (kernel core dumping, fast mutex
support, an improved I/O subsysem etc.)
12:02
35 /64
資工系網媒所
NEWS實驗室
2.4 vs. 2.6
Kernel 2.4 had
A Global runqueue.
All CPUs had to wait for other CPUs to finish
execution.
An O(n) scheduler.
In 2.4, the scheduler used to go through the entire
“ global runqueue” to determine the next task to be
run.
This was an O(n) algorithm where 'n' is the number
of processes. The time taken was proportional to
the number of active processes in the system.
This lead to large performance hits during
heavy workloads.
12:02
36 /64
資工系網媒所
NEWS實驗室
Driver Porting to Linux 2.6
Quicker kernel build system
New set of module utilities
Makefiles for 2.4 won’t work in 2.6
.ko module object instead of an .o
module_init and module_exit instead of
init_module and cleanup_module
New module loading utility minimize the
occurrence of race conditions
The module usage count move to outside of
module code
12:02
37 /64
資工系網媒所
NEWS實驗室
Workqueue Interface
Used to schedule kernel tasks
Each workqueue has dedicated worker
threads associated with it and all the
tasks from the run queue run in the
context of the process
Driver can use the default workqueue
provided by the kernel
12:02
38 /64
資工系網媒所
NEWS實驗室
Other Notable Changes
File systems
IBM’s JFS ( journaling file system ) and
SGI’s XFS have been merged into 2.6
Audio
New Linux audio architecture ALSA
(Advanced Linux Sound Architecture)
replaces OSS (Open Sound System)
12:02
39 /64
資工系網媒所
NEWS實驗室
Other Notable Changes
Power management
Support for ACPI (Advanced Configuration
and Power Interface), for CPU scaling
Under testing
Networking and IPSec
The IPSec feature uses the new crypto API,
including MD4, MD5, DES, etc
Support for the new NFSv4
User interface layer
Support touch screen, braille device, etc
12:02
40 /64
資工系網媒所
NEWS實驗室
Downsizing
Why?
1M  500K  300K  100K  46K 
16K  5K
How?
12:02
41 /64
資工系網媒所
NEWS實驗室
What is a Real-Time System?
A system enforcing timing constraints, e.g.
Avionics, Missile Control, …
The correctness of the system depends not only
on the logical result of the computation, but also
on the time at which the results are produced.
Real-Time vs. High Performance
What is a timing constraint?
A constraint of timing requirements, e.g. period,
distance, deadline, ready time, …
Functional and temporal correct.
12:02
42 /64
資工系網媒所
NEWS實驗室
What is a
Real-Time Operating System?
An operating system enforcing timing
constraints, Lynx, pSOS, VxWorks,
eCOS, uCLinux, LynxOS, RTLinux,
KURT, uC/OS-II, QNX, …
12:02
43 /64
資工系網媒所
NEWS實驗室
Systems Issues
In RTS, the OS and AP are very tightly
coupled, than time-sharing systems.
shared memory, special buses (instruction, data,
event, memory, control, invalidate, …).
A RTOS must response to internal and
external events deterministically.
Low-priority tasks may wait for high-priority
task or events indefinitely.
System architecture needs to provide high
computational speed, high-speed interrupt
handling, and high I/O throughput, + faulttolerance.
12:02
44 /64
資工系網媒所
NEWS實驗室
TORNADO II:
VxWorks
國立台灣大學
資訊工程學系
TORNADO II:VxWorks
Embedded Development Tools
VxWorks Real Time Operating System
Wind Microkernel
Snapshoot of Host Development Tools
12:02
46 /64
資工系網媒所
NEWS實驗室
The Next Generation of
Embedded Development Tools
12:02
47 /64
資工系網媒所
NEWS實驗室
VxWorks
12:02
48 /64
資工系網媒所
NEWS實驗室
Wind Microkernel
12:02
49 /64
資工系網媒所
NEWS實驗室
Embedded Internet
12:02
50 /64
資工系網媒所
NEWS實驗室
Virtual Memory
12:02
51 /64
資工系網媒所
NEWS實驗室
Multiprocessing
12:02
52 /64
資工系網媒所
NEWS實驗室
Graphics
12:02
53 /64
資工系網媒所
NEWS實驗室
File Systems
12:02
54 /64
資工系網媒所
NEWS實驗室
Networking
12:02
55 /64
資工系網媒所
NEWS實驗室
WindView
12:02
56 /64
資工系網媒所
NEWS實驗室
Stethoscope
12:02
57 /64
資工系網媒所
NEWS實驗室
Tips to be familiar with
embedded boards
Buy a new notebook for each of your
embedded board.
Lots of notes to be kept.
Search for on-line and off-line manuals.
Ask someone who understands the board.
Call your vendors.
There may be news groups to discuss all
kinds questions on your venders’ homepage.
Join them!!
Search on Google.
12:02
58 /64
資工系網媒所
NEWS實驗室
Why Hardware?
A software engineer who writes only
applications may spend an entire career and
learn nothing about hardware, BUT …
An embedded software engineer must often:
understand the hardware in order to write correct
software,
must install the software on the hardware,
must figure out whether a problem is a software
bug or hardware error, and
read hardware schematic diagram and suggest
corrections.
12:02
59 /64
資工系網媒所
NEWS實驗室
Overview (1/2)
The Linux is composed of four major
subsystems.
User Application
O/S services
Linux Kernel
Hardware controller
User Application
O/S Services
Linux Kernel
Hardware Controller
Decomposion of Linux system
12:02
60 /64
資工系網媒所
NEWS實驗室
Overview (2/2)
Before we port Linux into target board, we
must know hardware differences between host
and target.
Usually, target board has limit hardware
support. It might have no MMU or floating
point.
Target board might support other special
hardware or mechanism that host has not.
12:02
61 /64
資工系網媒所
NEWS實驗室
Linux Kernel with MMU (1/5)
The Linux kernel use MMU to manage
memory usage. But, Samsung-S3C4
does not have MMU function on it.
We need to consider many part of Linux
Kernel for target without MMU.
12:02
62 /64
資工系網媒所
NEWS實驗室
Linux Kernel with MMU (2/5)
ARM MMU functions
Translate virtual address into physical
address
Control memory access permissions
Domain control
Hardware requirement for MMU
TLB(Translation look aside buffer)
Access control logic
Translation-table-walking logic
12:02
63 /64
資工系網媒所
NEWS實驗室
Linux Kernel with MMU (3/5)
Virtual memory does more than just
make your computer’s memory go
further. It provides:
Large address spaces
Protection
Memory mapping
Fair physical memory allocation
Shared virtual memory
12:02
64 /64
資工系網媒所
NEWS實驗室
Linux Kernel with MMU (4/5)
Memory access control
Some memory, such as that containing
executable code, naturally read only
memory.
The operating system should not allow a
process to write data over its executable
code.
12:02
65 /64
資工系網媒所
NEWS實驗室
Linux Kernel with MMU (5/5)
Linux page table
Need to translate a virtual address into a physical one.
Page allocation and de-allocation
Process
While we create a process, Linux uses a technique
called “copy on write”.
The read only memory, for example the executable
code, will always be shared.
While the new process writes, then Linux would
allocate a new page for writing.
Processes use dynamic linking library to share memory.
12:02
66 /64
資工系網媒所
NEWS實驗室
Linux Kernel without MMU (1/5)
Linux kernel based on MMU. We must change
the Linux kernel to support target devices in
which has no MMU.
Virtual memory
The target has no MMU cannot use virtual memory
to allocate memory.
The function that allocate and de-allocate virtual
memory are modified into physical memory
allocation and de-allocation function.
12:02
67 /64
資工系網媒所
NEWS實驗室
Linux Kernel without MMU (2/5)
Memory access control
The target has no MMU cannot control
memory access permissions and domain.
All of the MMU control, and memory access
control functions are masked to support flat
memory.
Flat memory model treats the entire
memory on your computer the same,
without artificial boundaries or special
exclusions.
12:02
68 /64
資工系網媒所
NEWS實驗室
Linux Kernel without MMU (3/5)
Page allocation and de-allocation
Because of no MMU, virtual memory can
not be used.
All images have to be loaded to memory.
Process
Without MMU, processes cannot map
image from file directly with ELF or A.OUT
format.
We convert ELF into FLAT by using
application elf2flat.
12:02
69 /64
資工系網媒所
NEWS實驗室
Linux Kernel without MMU (4/5)
vLinux memory map
vLinux uses very simple memory map to
support target without MMU.
Page table entry is not used but reserved
for other platform.
Programs are loaded into free memory area
when execute.
12:02
70 /64
資工系網媒所
NEWS實驗室
Linux Kernel without MMU (5/5)
Free memory area
ROOT File system
Linux Kernel
Page Table Entry
DRAM Base
12:02
Exception Handler
71 /64
資工系網媒所
NEWS實驗室
FireLinux
Developed by Real-Time Systems Laboratory
of CS Dept. at CCU
Aims of this system
A flexible interface for run-time dynamic
loading/unloading scheduler module
Support both time-driven and priority-driven
scheduling approaches
A micro-second resolution one-shot timer
Shorten the task dispatch latency (interval between
event and task switching)
12:02
72 /64
資工系網媒所
NEWS實驗室
Architecture of FireLinux
Pinwheel
User Space
…
EDF
RM
Task1
Load/Unload
Task2
Kernel Space
Flexible Scheduler Interface
FireTimer
12:02
Scheduler
Task Queue
Direct Access
73 /64
資工系網媒所
NEWS實驗室
•Configurable OS on SOA
MP3
Home
Control
MPEG4
… User
Digital
Album
Space
SOA
System
Configuration
Tool
Kernel
Space
COS
EDF
RM
Buddy
PW
Bitmap
Sched
Paging
NRT
Task
MM
RT
Task
Thread
…
Task
Interfaces
Kernel
HAL
BSP Tool
Porting
SOC
ARM
12:02
MIPS
UniCore
ISS
74 /64
…
資工系網媒所
NEWS實驗室
Overall Architecture
Long way to go
Focus
Teamwork
SW open kernel
HW patented
Taiwan Core
SOC Platform
Configurable
Power-Aware
Real-Time
SELF-Verification
12:02
xCore
C1:多媒體
A3:Compiler
FU
A1:結構&
SOC 平台
C2:網路
A2:RTOS
QoS
B1:電路設計
B3:電性驗證
B2:功能驗證
75 /64
資工系網媒所
NEWS實驗室
References
“Understanding the Linux Kernel (2nd Edition),” Daniel P. Bovert
& Marco Cesati, O’Reilly, ISBN 0-596-00213-0, 天瓏
"MicroC OS II: The Real Time Kernel," Jean J. Labrosse, CMP
Books; ISBN 1578201039
"Linux Device Drivers," 2nd Edition, Alessandro Rubini, Jonathan
Corbet, O’Reilly, ISBN 0-596-00008-1,
“Linkers & Loaders” by John Levine Morgan Kaufmann 2000.
The official site of uClinux:
http://www.uclinux.org/
Arcturus Networks now officially hosting the uClinux project:
http://www.rt-control.com/
http://www-106.ibm.com/developerworks/linux/library/linside.html#resources
http://kernelnewbies.org/documents/kdoc/mousedrivers.pdf
http://www.cs.ccu.edu.tw/~chsueh
12:02
76 /64
資工系網媒所
NEWS實驗室