嵌入式作業系統實作 implementation of embedded operating systems introduction
DESCRIPTION
嵌入式作業系統實作 Implementation of Embedded Operating Systems Introduction. 薛智文 [email protected] http://www.csie.ntu.edu.tw/~cwhsueh/. Outline. Introduction to Embedded System Introduction to Embedded Operating System Case Studies SoCKernel. Preface. Window 2000, 30M lines. - PowerPoint PPT PresentationTRANSCRIPT
國立台灣大學資訊工程學系
嵌入式作業系統實作 Implementation of
Embedded Operating Systems
Introduction
http://www.csie.ntu.edu.tw/~cwhsueh/
資工系網媒所 NEWS實驗室
22:39 /642
Outline
Introduction to Embedded System
Introduction to Embedded Operating System
Case Studies
SoCKernel
資工系網媒所 NEWS實驗室
22:39 /643
Preface
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)?
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
資工系網媒所 NEWS實驗室
22:39 /644
Embedded OS trends 2001-2002,
sorted by 2001
0%
5%
10%
15%
20%
25%
30%
Hom
e grown
VxW
orks
DO
S
Em
bedded Linux
WinC
E
QN
X
Nucleus
Green H
ills
LynxO
S
Chorus
2001
2002
資工系網媒所 NEWS實驗室
22:39 /645
Embedded OS trends 2001-2002, sorted by 2002
0%
5%
10%
15%
20%
25%
30%
Em
bedded Linux
VxW
orks
WinC
E
LynxO
S
BSD
Green H
ills
QN
X
DO
S
Chorus
Hom
e grown
2001
2002
資工系網媒所 NEWS實驗室
22:39 /646
電子書包發展硬體
電子書包作業系統 (OS / UI / CM)
教學 / 同儕群體應用軟體開發工具
系統軟體開發工具 (SDK)相容性測試軟體工具 (TCK)
ICE DDK
開發工具電子書包平台結構
教師教學應用軟體
電子書包教學應用平台
電子書包教學數位內容 電子書包數位內容開發工具
同儕群體應用軟體數
位學習輔具
數位學習平台
閱讀程式SCOR
MHTMLXML
數位學習輔具
數位學習平台
Physical•Serial•USB•1394•IrDA•Bluetooth•802.11
Protocol
•SyncML
電子書包與數位學習輔具分工架構圖
資工系網媒所 NEWS實驗室
org 07c00h ; tell the assembler to load onto 7c00, 0100h for DOS
mov ax, cs
mov ds, ax
mov es, ax
call DispStr ; call string display procedure
jmp $ ; infinite loop
DispStr:
mov ax, BootMessage
mov bp, ax ; ES:BP = string address
mov cx, 16 ; CX = string length
mov ax, 01301h ; AH = 13, AL = 01h
mov bx, 000ch ; 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
Tinix’ -“自己動手寫作業系統 ,” 于淵
資工系網媒所 NEWS實驗室
22:39 /648
Example
RS485
RS485
Ethernet
Ethernet
資工系網媒所 NEWS實驗室
22:39 /649
IntroductionUnix SVR4, System V Release 4, AT&T, now owned by Santa Cruz Operation, Inc.;4.4 BSD, UC BerkeleyDigital Unix, DEC Compaq HPAIX, IBMHP-UX, HPSolaris, Sun Microsystems, Stanford UniversityLinux, 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 UnixPOSIX, Portable OS based on Unix
資工系網媒所 NEWS實驗室
22:39 /6410
Outline
Introduction to Embedded System
Introduction to Embedded Operating System
Software Engineering
Case Studies
SoCKernel
Paper discussion
資工系網媒所 NEWS實驗室
22:39 /6411
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 ?
資工系網媒所 NEWS實驗室
22:39 /6412
Embedded System Examples
Computer peripheralsKeyboard, Mouse, …
Information AppliancesSet-Up Boxes, WebTV, …
Monitors and SensorsFire Alarm, Heartbeat Detector, …
Controllers in ElectronicsRefrigerator, Air Conditioner, …
Communication DevicesHub, Router, …
…
資工系網媒所 NEWS實驗室
22:39 /6413
Business Issues of ES
Time-to-market for new devicesDesign to delivery: in weeks
Sustained pressure to reduce costsMany proprietary choices yield low-margins
Life cycle managementNew products overlapping each otherPositioning nightmares
Open platform choices considered risky?Resources expended on “recreating the wheel…” not on product differentiation.
資工系網媒所 NEWS實驗室
22:39 /6414
ES Technology IssuesNeed 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 anymoreSupport nightmares
Lack of sources from proprietary choicesOpen sources sound seductive … but risky.
資工系網媒所 NEWS實驗室
22:39 /6415
Real-Time Systems vs. Embedded Systems
RTS ESRTES
.Radar .Calculator.ABS
資工系網媒所 NEWS實驗室
22:39 /6416
Real-Time Systems
Time
Value
Hard RTS
Soft RTS
FirmRTS
Deadline
-Value
資工系網媒所 NEWS實驗室
22:39 /6417
Real-Time Systems (RTS)
Firm RTS
Soft RTSHard RTS
Proprietary
Open
Centralized
Distributed
Embedded
資工系網媒所 NEWS實驗室
22:39 /6418
Outline
Introduction to Embedded System
Introduction to Embedded Operating System
Software Engineering
Case Studies
SoCKernel
Paper discussion
資工系網媒所 NEWS實驗室
22:39 /6419
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).
資工系網媒所 NEWS實驗室
22:39 /6420
Linux vs. Other Unix-Like KernelsLinux 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.
資工系網媒所 NEWS實驗室
22:39 /6421
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 SystemSGI 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.
資工系網媒所 NEWS實驗室
22:39 /6422
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.
資工系網媒所 NEWS實驗室
22:39 /6423
Hardware DependencyLinux maintains a neat distinction between hardware-dependent and hardware-independent source code.
alpha Hewlett-Packard's Alpha workstationsarm ARM processor-based computers and embedded devicescris "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 microprocessorm68k Personal computers based on Motorola MC680 x 0 microprocessors mips Workstations based on MIPS microprocessorsmips64 Workstations based on 64-bit MIPS microprocessorsparisc Workstations based on Hewlett Packard HP 9000 PA-RISC microprocessorsppc Workstations based on Motorola-IBM PowerPC microprocessorss390 32-bit IBM ESA/390 and zSeries mainframess390 x IBM 64-bit zSeries serverssh SuperH embedded computers developed jointly by Hitachi and STMicroelectronics sparc Workstations based on Sun Microsystems SPARC microprocessorssparc64 Workstations based on Sun Microsystems 64-bit Ultra SPARC microprocessors
Taiwan Core
資工系網媒所 NEWS實驗室
22:39 /6424
Power Management
Halting in the idle processidle process executes hlt on Intel
low-power consumption mode
Suspending the systempatches for suspending to disk
APM: Advance Power Managementlaptop standard power management
ACPI: Advanced Configuration and Power Interfacenew comprehensive standard from Intel-Microsoft
Power-management is essential for mobile systems
資工系網媒所 NEWS實驗室
22:39 /6425
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.)
資工系網媒所 NEWS實驗室
22:39 /6426
2.4 vs. 2.6
Kernel 2.4 hadA 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.
資工系網媒所 NEWS實驗室
22:39 /6427
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
資工系網媒所 NEWS實驗室
22:39 /6428
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
資工系網媒所 NEWS實驗室
22:39 /6429
Other Notable Changes
File systemsIBM’s JFS ( journaling file system ) and SGI’s XFS have been merged into 2.6
AudioNew Linux audio architecture ALSA (Advanced Linux Sound Architecture) replaces OSS (Open Sound System)
資工系網媒所 NEWS實驗室
22:39 /6430
Other Notable Changes
Power managementSupport for ACPI (Advanced Configuration and Power Interface), for CPU scalingUnder testing
Networking and IPSecThe IPSec feature uses the new crypto API, including MD4, MD5, DES, etcSupport for the new NFSv4
User interface layerSupport touch screen, braille device, etc
資工系網媒所 NEWS實驗室
22:39 /6431
Downsizing
Why?
1M 500K 300K 100K 46K 16K 5K
How?
資工系網媒所 NEWS實驗室
22:39 /6432
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.
資工系網媒所 NEWS實驗室
22:39 /6433
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, …
資工系網媒所 NEWS實驗室
22:39 /6434
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, + fault-tolerance.
國立台灣大學資訊工程學系
TORNADO II :VxWorks
資工系網媒所 NEWS實驗室
22:39 /6436
TORNADO II : VxWorks
Embedded Development Tools
VxWorks Real Time Operating System
Wind Microkernel
Snapshoot of Host Development Tools
資工系網媒所 NEWS實驗室
22:39 /6437
The Next Generation of Embedded Development Tools
資工系網媒所 NEWS實驗室
22:39 /6438
VxWorks
資工系網媒所 NEWS實驗室
22:39 /6439
Wind Microkernel
資工系網媒所 NEWS實驗室
22:39 /6440
Embedded Internet
資工系網媒所 NEWS實驗室
22:39 /6441
Virtual Memory
資工系網媒所 NEWS實驗室
22:39 /6442
Multiprocessing
資工系網媒所 NEWS實驗室
22:39 /6443
Graphics
資工系網媒所 NEWS實驗室
22:39 /6444
File Systems
資工系網媒所 NEWS實驗室
22:39 /6445
Networking
資工系網媒所 NEWS實驗室
22:39 /6446
WindView
資工系網媒所 NEWS實驗室
22:39 /6447
Stethoscope
資工系網媒所 NEWS實驗室
22:39 /6448
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.
資工系網媒所 NEWS實驗室
22:39 /6449
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.
資工系網媒所 NEWS實驗室
22:39 /6450
Overview (1/2)
The Linux is composed of four major subsystems.
User Application
O/S services
Linux Kernel
Hardware controller
User ApplicationO/S ServicesLinux Kernel
Hardware Controller
Decomposion of Linux system
資工系網媒所 NEWS實驗室
22:39 /6451
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.
資工系網媒所 NEWS實驗室
22:39 /6452
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.
資工系網媒所 NEWS實驗室
22:39 /6453
Linux Kernel with MMU (2/5)
ARM MMU functionsTranslate virtual address into physical address
Control memory access permissions
Domain control
Hardware requirement for MMUTLB(Translation look aside buffer)
Access control logic
Translation-table-walking logic
資工系網媒所 NEWS實驗室
22:39 /6454
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
資工系網媒所 NEWS實驗室
22:39 /6455
Linux Kernel with MMU (4/5)
Memory access controlSome 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.
資工系網媒所 NEWS實驗室
22:39 /6456
Linux Kernel with MMU (5/5)
Linux page tableNeed to translate a virtual address into a physical one.
Page allocation and de-allocation
ProcessWhile 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.
資工系網媒所 NEWS實驗室
22:39 /6457
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 memoryThe 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.
資工系網媒所 NEWS實驗室
22:39 /6458
Linux Kernel without MMU (2/5)
Memory access controlThe 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.
資工系網媒所 NEWS實驗室
22:39 /6459
Page allocation and de-allocationBecause of no MMU, virtual memory can not be used.
All images have to be loaded to memory.
ProcessWithout MMU, processes cannot map image from file directly with ELF or A.OUT format.
We convert ELF into FLAT by using application elf2flat.
Linux Kernel without MMU (3/5)
資工系網媒所 NEWS實驗室
22:39 /6460
Linux Kernel without MMU (4/5)
vLinux memory mapvLinux 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.
資工系網媒所 NEWS實驗室
22:39 /6461
Linux Kernel without MMU (5/5)
Exception Handler
Page Table Entry
Linux Kernel
ROOT File system
Free memory area
DRAM Base
資工系網媒所 NEWS實驗室
22:39 /6462
FireLinux
Developed by Real-Time Systems Laboratory of CS Dept. at CCU
Aims of this systemA 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)
資工系網媒所 NEWS實驗室
22:39 /6463
Architecture of FireLinux
Pinwheel RM EDF …
User Space
Kernel Space
Scheduler
Load/Unload
FireTimer
Task1 Task2
Task QueueFlexible Scheduler Interface
Direct Access
資工系網媒所 NEWS實驗室
22:39 /6464
•Configurable OS on SOA•Configurable OS on SOA
System Configuration
Tool
HAL
BSP Tool
SOC
ARM MIPS UniCore …ISS
Porting
MP3 MPEG4 … User Space
HomeControl
DigitalAlbum
COS
Interfaces
Sched
PWRM
EDF
MM
PagingBitmap
Buddy
Task
ThreadNRTTask
RTTask
…
SOA Kernel Space
Kernel
資工系網媒所 NEWS實驗室
22:39 /6465
Overall Architecture
Long way to goFocusTeamwork
SW open kernelHW patented
Taiwan CoreSOC PlatformConfigurablePower-AwareReal-TimeSELF-Verification
xCore
A3:Compiler
A2:RTOS
C1: 多媒體
FU
A1: 結構 &
SOC 平台
B1: 電路設計
C2: 網路
QoS
B3: 電性驗證 B2: 功能驗證
資工系網媒所 NEWS實驗室
22:39 /6466
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/l-inside.html#resourceshttp://kernelnewbies.org/documents/kdoc/mousedrivers.pdfhttp://www.cs.ccu.edu.tw/~chsueh