WinCE6.0 Developer Guide
WinCE6.0 Developer Guide
WinCE6.0 Developer Guide
0 MOC
Introduction
Victor Lin
Field Application Engineer
SYNNEX INTERNATIONAL CORP.
(02)25063320-2231
victorlin@synnex.com.tw
SYNNEX
Overview
Toolkit.
OS Architecture.
Memory Architecture.
Driver Development.
Application Development.
SYNNEX
Toolkit
SYNNEX
Runtime Image of the CE 6.0 Operating System
Application Services
NK.BIN
OS Layer
Kernel
SYNNEX
Visual Studio 2005 Platform Builder
Solution
Platforms
Connectivity
Status
Connectivity
Device Name
Code
Editor
Project
Tree
Debug tool
status
indicators
Output
Selection Tabbed Output
Windows
SYNNEX
Visual Studio 2005 Platform Builder
SYNNEX
Building the Run-time Image
SYNNEX
Building the Run-time Image
SYNNEX
CE 6.0 Build Steps
Pre-Sysgen Build 0
Post-Sysgen Build 2
SYNNEX
System Generation Phase
Pre-Sysgen Build 0
Post-Sysgen Build 2
Sysgen
y Generates system configuration based on chosen
Catalog items in OS design
SYNNEX
System Generation Phase
Complete Linked
system libraries SYSGEN libraries
SYNNEX
System Generation Phase
%__PROJROOT%\CESYSGEN
MAKEFILE
yyy_lib.lib zzzz.lib
aaa.Exe
aaa.Dll
SYNNEX
System Generation Phase
Filtering
y Uses @CESYSGEN comment tags to filter files based
on component settings
y Run from inside
%__PROJROOT%\CESYSGEN\MAKEFILE
SYNNEX
System Generation Phase
Filtering
SYNNEX
Post-Sysgen Build Phase
Pre-Sysgen Build 0
Post-Sysgen Build 2
SYNNEX
Post-Sysgen Build Phase
SYNNEX
Build Release Directory Phase
Pre-Sysgen Build 0
Post-Sysgen Build 2
SYNNEX
Build Release Directory Phase
SYNNEX
Build Release Directory Phase
SYNNEX
Make Run-Time Image Phase
Pre-Sysgen Build 0
Post-Sysgen Build 2
SYNNEX
Make Run-Time Image Phase
SYNNEX
Build Phases
Sysgen No No Yes No
SYNNEX
Build Types
SYNNEX
The Build Tool Of The
Build System
SYNNEX
Build.exe – The Build Tool
Build.exe \MyProj
DIRs DIRS
\Proj1
Sources
Nmake.exe Makefile
Sources
SYNNEX
DIRS Files
DIRS
y Contains a list of “project subdirectories”
y Text file that lists subdirectories containing other DIRS or SOURCES
files
y BUILD.EXE will read the contents of DIRS files to determine what
subdirectories to enter
y Supports * wildcard
DIRS=\
Display \
Mouse \
Keyboard \
SYNNEX
SOURCES
MAKEFILE
Local MAKEFILE.DEF
%_MAKEENVROOT%
Project
Folder
SOURCES
SYNNEX
SOURCES
SOURCES
y List of source code files for the project
TARGETNAME
y Name of output target (without extension)
TARGETTYPE
y PROGRAM – (.EXE) Application
y DYNLINK – (.DLL) Dynamic Link Library
y LIBRARY – (.LIB) Static library
SYNNEX
SOURCES
TARGETLIBS
y List of libraries to include in the target
Not used when TARGETTYPE=LIBRARY
Typically used for import libs from DLLs
SOURCELIBS
y List of source libraries to include in target
RELEASETYPE
y Indicates where build output file should be placed
LOCAL, OAK, PLATFORM
SYNNEX
SOURCES
POSTLINK_PASS_CMD
y Specifies a command to run after link completes
Usually a BAT file, often useful for copying raw data files to
%_FLATRELEASEDIR% as there is no custom BUILDREL
support for PBPXML projects
PRELINK_PASS_CMD
y Specifies a command to run BEFORE linking the final
output
SYNNEX
SOURCES
SYNNEX
MAKEFILE.DEF
SYNNEX
SOURCES.CMN
SYNNEX
Mapping the IDE to the Command Line
Build Menu
y Build Solution
blddemo –q
y Rebuild Solution
blddemo clean –q
y Build <OS Design project name>
blddemo -q
y Rebuild <OS Design project name>
blddemo clean -q
y Copy Files to Release Directory
buildrel
y Make Run-Time Image
makeimg
SYNNEX
Mapping the IDE to the Command Line
SYNNEX
Mapping the IDE to the Command Line
SYNNEX
Mapping the IDE to the Command Line
SYNNEX
Mapping the IDE to the Command Line
SYNNEX
Downloading the Run-time Image
SYNNEX
Downloading the Run-time Image
SYNNEX
Downloading the Run-time Image
SYNNEX
Downloading the Run-time Image
SYNNEX
Downloading the Run-time Image
SYNNEX
Testing and Debugging the Run-time Image
SYNNEX
Debug Windows
SYNNEX
Program Launch Options
Command Line
y RUN from the Target Device’s Start Button.
Target Control Window
s explorer
Target | Run Programs
SYNNEX
Remote Tools
SYNNEX
CE 6.0 Directory
Structure
SYNNEX
Environment Variables in the Build
SYNNEX
CE Development System Directory Structure
SYNNEX
Directory Structure
OSDesigns Directory
y Located at the path
%_WINCEROOT%\OSDesigns
y Contains OS Design projects
and subprojects
SYNNEX
\WINCE600\PLATFORM
SYNNEX
\WINCE600\PUBLIC
SYNNEX
\WINCE600\PRIVATE
Private Directory
y Option at installation
Agree to separate Shared Source license
Includes full Kernel source code among others
y Can ship modified versions of the private code with your
product
y Premium (“Almost everything”) Source available
GWES components
Filesys components
Others
SYNNEX
\WINCE600\PRIVATE
SYNNEX
\WINCE600\SDK
SYNNEX
\WINCE600\Others
SYNNEX
CE Development System Directory Structure
SYNNEX
CE Development System Directory Structure
SYNNEX
Board Support
Package
SYNNEX
BSP Overview
Acronym Review
y OEM - Original Equipment Manufacturer
y OAL - OEM Adaptation Layer
y BSP - Board Support Package
y KITL – Kernel Independent Transport Layer
SYNNEX
BSP Overview
SYNNEX
BSP Overview
PLATFORM Directory
Contains all BSPs
y Microsoft sample reference platforms
y Third party platforms
y Your BSP
Common Directory
y Source code for libraries of routines available for use by
BSPs
y Contains implementations for many BSP requirements
y No platform specific dependencies
SYNNEX
Platform Common Code Of
Board Support Package
SYNNEX
Platform Common Code
Architecture
Implemented in \WINCE600\PLATFORM\COMMON
y Organized by CPU dependency and function
Exposed to BSP as libraries
y Referenced with _PLATCOMMONLIB in sources file
y _PLATCOMMONLIB = (_PLATFORMROOT)\common\lib
y BSP links to individual libraries as needed
SYNNEX
Platform Common Code
Organization
Common Code
y \WINCE600\PLATFORM\COMMON\SRC\COMMON
y No CPU dependencies
y CPU independent modules, e.g.
• bootloader framework
• kitl
• PCI
• interrupt framework
• timer framework
SYNNEX
Platform Common Code
Organization
CPU Architecture Specific
y \WINCE600\PLATFORM\COMMON\SRC\<arch>
ARM, MIPS, SHX, X86
y May be further divided into sub architecture and common code
y Contains routines that are common to all CPUs in a particular
architecture/family
y CPU architecture dependent modules, e.g.
• cache routines
• abort handlers
• memory map support
• architecture specific interrupt support
SYNNEX
Platform Common Code
Organization
System On Chip (SOC) Specific
y \WINCE600\PLATFORM\COMMON\SRC\SOC\<soc_vendor_version>
E.g. PXA27X_MS_V1
SYNNEX
Platform Common Code
Documentation
Header Files
y \WINCE600\PLATFORM\COMMON\INC\
#include <oal.h>
Platform Builder Documentation
Bringing Up a Hardware Platform
Developing a Board Support Package
Developing an OEM Adaptation Layer
Production-Quality OAL
Source code
y Always the best documentation
SYNNEX
Platform Common Code
SYNNEX
BSP Components Of Board
Support Package
SYNNEX
BSP Directory Structure
SYNNEX
Bootloader
SYNNEX
Bootloader
SYNNEX
Bootloader
SYNNEX
Bootloader
Startup
Main
BootloaderMain
OEMDebugInit
OEMPlatformInit
OEMPreDownload
DownloadImage
OEMWriteFlash
OEMLaunch
SYNNEX
OAL
SYNNEX
OAL
Architecture
y OAL is a separate component
-No longer statically linked as part of OS kernel
SYNNEX
OAL
SYNNEX
OAL – Required Function Interface
SYNNEX
OAL – Common Functions
OEMInitDebugSerial
y First call to OEM code by kernel
y Opportunity to initialize serial debug communications
OEMInit
y Second call to OEM code by kernel
y Very early in boot sequence
No system calls allowed
Single threaded
No blocking
Exception handlers not available
y Initialize all necessary hardware interfaces, OS timer etc
y Register ISRs (except ARM)
y Initialize Kitl
SYNNEX
OAL – Common Functions
OEMInterruptEnable
y Enables specified interrupt based on interrupt identifier
y Called by InterruptInitialize and InterruptMask
OEMInterruptDisable
y Disables specified interrupt based on interrupt identifier
y Called by InterruptDisable and InterruptMask
OEMInterruptDone
y Unmasks specified interrupt based on interrupt identifier
y Called by InterruptDone
OEMInterruptHandler (ARM only)
y Interrupt handler function (ISR)
y Returns interrupt identifier corresponding to interrupt source
SYNNEX
OAL – Common Functions
OEMIdle
y Called when no threads are scheduled to run
y Opportunity to place CPU in low power state
OEMPowerOff
y Called in response to SetSystemPowerState()
POWER_STATE_OFF
POWER_STATE_SUSPEND
POWER_STATE_CRITICAL
y Place CPU in lowest power “suspend” state
SYNNEX
OAL – Common Functions
OEMIoControl
y Called in response to KernelIoControl
y Generic IOCTL interface for the kernel
y Some standard IOCTLs must be implemented
y Can be extended by the OEM
y Implements interrupt identifier management
SYNNEX
OAL – Common IOCTLs
IOCTL_HAL_INIT_RTC
y Resets the realtime clock
IOCTL_HAL_GET_DEVICE_INFO
y Supports SystemParametersInfo function
IOCTL_HAL_REQUEST_IRQ
y Returns IRQ based on device location
IOCTL_HAL_REQUEST_SYSINTR
y Returns interrupt identifier based on IRQ
IOCTL_HAL_REBOOT
y Warm boots the target device
SYNNEX
OAL – Common Functions
OEMSetRealTime/OEMGetRealTime
y Called by the kernel to get/set the real time clock
y Called in response to Get/SetSystemTime
OEMSetAlarmTime
y Set the Real Time Clock alarm
SYNNEX
Drivers
SYNNEX
Drivers
SYNNEX
Drivers
SYNNEX
Miscellaneous Files Of
Board Support Package
SYNNEX
Catalog File
SYNNEX
Platform Batch File
deviceemulator.bat
<snip>
REM -----------------------------------------------
REM Select which KITL transport to use.
REM
REM -----------------------------------------------
set BSP_KITL_ETHERNET=
set BSP_KITL_DMA=1
set IMGNOSIR=1
set IMG_RESERVERAMFMD=1
set IMGSDKCERTS=1
set IMGHEADSET=1
<snip>
SYNNEX
Configuration Files
SYNNEX
Configuration Files: .BIB Files
MEMORY section
y Partitions the memory into two types
RAMIMAGE Contains OS image (‘ROM’), supports XIP
RAM Program and Data memory
Name
Name Start
Startaddress
address Size(bytes)
Size(bytes) Type
Type
-----------------------------------------------
-----------------------------------------------
NK
NK 8C800000
8C800000 00800000
00800000 RAMIMAGE
RAMIMAGE
RAM
RAM 8C050000
8C050000 007B0000
007B0000 RAM
RAM
CONFIG section
y Contains settings that control certain kernel features
y Contains settings that control characteristics of the build output file
SYNNEX
The Configuration Files: .BIB Files
MODULES section
y Lists modules to include in the run-time image
y Components in this section will be configured to XIP
y Only executable modules can be listed here
FILES section
y Other modules to be included in the run-time image
y Can include both executable modules and data files
y Will be managed by the object store file system
;Name
;Name Path
Path Memory
MemoryType
Type
-----------------------------------------------------
-----------------------------------------------------
Tahoma.ttf
Tahoma.ttf $(_FLATRELEASEDIR)\Tahoma.ttf
$(_FLATRELEASEDIR)\Tahoma.ttf NK
NK SHU
SHU
SYNNEX
FILES – Config.bib
MEMORY Section
RAMIMAGE Type
y Specifies memory range OS will execute from
y Virtual Addresses
Corresponds to mapping in OEMAddressTable (ARM, X86) or fixed static
mapping (other processors)
y Could be RAM or ROM
y Virtual memory range must be physically contiguous
y Must be aligned on 64KB boundary
y Size must be 64KB granularity
y Must be large enough to contain the entire operating system image
SYNNEX
FILES – Config.bib
MEMORY Section
RAM Type
y Specifies memory range available for program and
storage (working RAM)
y Virtual Addresses
Corresponds to mapping in OEMAddressTable (ARM, X86) or
fixed static mapping (other processors)
y Must be RAM
y Virtual memory range must be physically contiguous
y Must be aligned on 64KB boundary
y Size must be 64KB granularity
SYNNEX
FILES – Config.bib
MEMORY Section
RESERVED Type
y Ignored by build tools
y Document use of other memory regions
Bootloader
DMA buffers
Framebuffer
Etc
SYNNEX
FILES – Config.bib
CONFIG Section
AUTOSIZE
y Allows boundary between RAM/RAMIMAGE sections to
be dynamically determined
y Makes efficient use of RAM resources
y Only works with images running entirely from RAM
SYNNEX
FILES – Platform.bib
SYNNEX
Configuration Files: .REG Files
[HKEY_LOCAL_MACHINE\init]
[HKEY_LOCAL_MACHINE\init]
“Launch10”=“shell.exe”
“Launch10”=“shell.exe”
“Launch20”=“device.dll”
“Launch20”=“device.dll”
SYNNEX
BIB REG Editor VS2005
SYNNEX
The Configuration Files: .DAT Files
Root:-Directory(“My
Root:-Directory(“MyDocuments”)
Documents”)
Directory(“\My
Directory(“\MyDocuments”):-File(“MyFile.doc”,“\
Documents”):-File(“MyFile.doc”,“\
Windows\Myfile.doc”)
Windows\Myfile.doc”)
SYNNEX
The Configuration Files: .DB Files
SYNNEX
Creating a New BSP Of
Board Support Package
SYNNEX
Creating a New BSP
SYNNEX
Creating a New BSP
SYNNEX
Creating a New BSP
SYNNEX
Creating a New BSP
SYNNEX
The SDK Of
Customizing the OS
Design
SYNNEX
SDK
Platform Builder
CE 6.0 OS Design OEM Adaptation Layer Run-time Libraries
(OAL)
Custom SDK
Platform Manager SDK Documentation
SYNNEX
SDK Development Steps
SYNNEX
Configuring the SDK Options - General
SYNNEX
Configuring the SDK Options - Install
SYNNEX
Configuring the SDK Options – CPU Families
SYNNEX
Configuring the SDK – Adding User-defined Files
SYNNEX
Building an SDK
SYNNEX
Installing the SDK
SYNNEX
Operating System
Internals
SYNNEX
CE 6.0 Architecture – User Processes
SYNNEX
CE 6.0 Architecture – Kernel
DEVMGR.DLL FILESYS.DLL
KERNEL.DLL Networking
GWES.DLL
DLLs
Drivers FSDMGR.DLL
OAL
KCOREDLL.DLL
SYNNEX
CE 6.0 Architecture – Kernel
DEVMRG.DLL FILESYS.DLL
KERNEL.DLL Networking
GWES.DLL
DLLs
Drivers FSDMGR.DLL
OAL
KCOREDLL.DLL
SYNNEX
CE 6.0 Architecture - Hardware
DEVMGR.DLL FILESYS.DLL
KERNEL.DLL Networking
GWES.DLL
DLLs
Drivers FSDMGR.DLL
OAL
KCOREDLL.DLL
DEVMGR.DLL FILESYS.DLL
KERNEL.DLL Networking
GWES.DLL
DLLs
Drivers FSDMGR.DLL
OAL
KCOREDLL.DLL
OAL Component
SYNNEX
CE 6.0 Architecture
DEVMGR.DLL FILESYS.DLL
KERNEL.DLL Networking
GWES.DLL
DLLs
Drivers FSDMGR.DLL
OAL
KCOREDLL.DLL
SYNNEX
Applications, Processes & Threads
Application
y A logical group of executable code
Process
y A process is a single instance of an application
y Static context within which one or more threads execute
y Up to 32,000 processes loaded simultaneously
Thread
y Basic unit of execution managed by the scheduler
y Each process has at least one thread called the primary thread
y Number of threads limited by maximum number of handles in a
process
SYNNEX
Operating System
Internals Memory
Architecture
SYNNEX
Memory Architecture Overview
Memory Overview
Virtual Memory Model
Program Memory
y Heaps and Stacks
y Processes, Threads and Memory
Memory System Tools
SYNNEX
Memory Overview
Memory Types
y Random Access Memory (RAM)
y Read Only Memory (ROM)
What Uses Memory?
y Bootloader
y Operating System
y Applications
y Object Store - File system, Registry, Databases
y Shared heap
y Memory Mapped Files
SYNNEX
Memory Overview
SYNNEX
Memory Overview
SYNNEX
Memory Overview
SYNNEX
Virtual Memory Architecture
Virtual Memory
y Single 32-bit (4 Gigabyte) flat virtual memory address space
y Permits efficient use of physical memory with protection
Virtual Addressing
y Memory Management Unit (MMU) “owns” physical memory
y Virtual addresses translated to physical addresses by MMU
y A valid virtual address must map to a physical address
y Static or Dynamically mapped virtual addressing
y All CE components use virtual, not physical addresses
Physical Addressing
y Used by CPU before MMU is activated during power-up and by bus
mastering components such as DMA controllers.
SYNNEX
Virtual Address Mapping – Static Mapping Example
Kernel
Space
C000 0000
Uncached
32 MB Flash
512 MB
64 MB RAM
A000 0000
512 MB
Cached
32 MB Flash
82000000
32 MB Flash 64 MB RAM
04000000 8000 0000
64 MB Flash
User
2 GB
Address User
Translation Space
00000000 0000 0000
SYNNEX
Virtual Memory Map
Kernel
2 GB Filesystem
kernel GWES
space Drivers
Memory
mapped files
2 GB VM
..
User DLLs
per
..
process
..
..
Process code
32 K
processes
SYNNEX
Kernel Memory Space
CPU Specific VM
Kernel VM
(if supported by CPU)
256 MB
Kernel Space Kernel VM
2 Gigabytes 256 MB
Fixed
Object Store (128 MB)
mapping
Kernel XIP DLLs (128 MB)
independent
of user space Static Mapped
Uncached
512 MB
Static Mapped
Cached
512 MB
SYNNEX
User Memory Space
Process Space
1 GB process
SYNNEX
Program Memory
SYNNEX
Program Memory - Heap
Heap Characteristics
y Dynamic memory allocation
y Processor-independent (hides memory paging)
y Automatically allocates memory and commits pages on
demand
SYNNEX
Program Memory - Heap
SYNNEX
Program Memory - Stack
Creation
y Default stack allocated for each thread at creation
y All threads of a process have same stack size by default
y Default thread stack size override with /STACK linker
switch
y Individual threads can be created dynamically with
unique stack size
Note: CE 6.0 compiler automatically inserts code to detect
buffer overruns on the stack with the /GS switch
SYNNEX
Program Memory - Processes and Threads
Process
Primary Thread
Heap
Stack
Additional Thread
Stack
SYNNEX
Operating System Internals
Threads and Scheduling
SYNNEX
Threads
SYNNEX
Processes and Threads
Priority-based Scheduling
y Preemptive scheduling within 256 priority levels
y Round-robin scheduling of threads on same priority
y Priority 0 (or highest priority) threads run to completion
SYNNEX
Scheduler – Quantum Time Slicing
t1 t2 t3 t4 t5 t6 t7
Priority Component
0 - 96 Typically reserved for real-time drivers
SYNNEX
Priority Inversion
OS Priority OS Priority
Inversion Restoration
Preempt
Medium Priority Thread 2 Thread 2
Preempt
Low Priority Thread 3 Thread 3
SYNNEX
Thread APIs
Thread Creation
y CreateThread
Creates a new thread at normal priority
Thread Priority
y CeGetThreadPriority
Get current priority level of a thread
y CeSetThreadPriority
Set priority level of a thread
y SetThreadPriority
Legacy function
y GetThreadPriority
Legacy function
SYNNEX
Thread Blocking APIs
SYNNEX
Operating System
Internals Interrupt
Model
SYNNEX
Interrupt Model
Interrupt
KERNEL.DLL Service
Event Thread
Exception Handler
(IST)
4
3
Interrupt ID
Interrupt
2
Device Interrupt Service Routine (ISR)
Interrupt Processing
1. Device raises registered hardware interrupt
2. Kernel gets exception, calls associated Interrupt Service Routine (ISR)
3. Interrupt Service Routine (ISR) quickly deals with pending interrupt
4. Interrupt Service Thread (IST) in driver is signaled to process interrupt
SYNNEX
Interrupt Service Routine (ISR)
Registered to an IRQ
Called to handle the hardware interrupt
Acknowledges hardware and determines Interrupt ID
Returns Interrupt ID (SYSINTR) to kernel
Static (built into NK.EXE) or Installable (chained in) via
Kernel call
Must be written to run quickly with no outside
dependencies
SYNNEX
Interrupt Service Thread (IST)
SYNNEX
ISRs And ISTs Work Together
SYNNEX
Installable ISRs
SYNNEX
Shared Interrupts Using Chaining
SYNNEX
Operating System
Components Power
Management
SYNNEX
Concepts – Role of the Power Manager
SYNNEX
Concepts – Role of the Power Manager
Application
Notification
Message Application
APIs
Queue
Power Manager
APIs
Driver
APIs
Power
Manager Drivers
(pm.dll)
SYNNEX
Concepts – Device Power States
SYNNEX
Concepts – System Power States
SYNNEX
Concepts - System Power States
SYNNEX
Concepts – Activity Timers
Activity Timers
y Named timers implemented by Power Manager
Configurable in registry
Any number of timers can be implemented
General purpose mechanism that can be used by any component
y Implemented with named events
y Used by default Power Manager implementation
PM implements two timers for its own use
Used to determine user and system activity
Some OS components reset timers to indicate activity
GWES, Networking
SYNNEX
Power Manager Implementation
SYNNEX
Power Manager Implementation
SYNNEX
Device Power Management
SYNNEX
Device Power Management
SYNNEX
Device Power Management
Power
Manager
PM.DLL
PM APIs
DevicePowerNotify DeviceIoControl
Device Driver
SYNNEX
Device Power Management
case IOCTL_POWER_SET:
// update device registers
...
deviceDx = *(PCEDEVICE_POWER_STATE) pOutBuf;
fBoostRequested = FALSE;
fReductionRequested = FALSE;
break;
SYNNEX
Applications and Power Management
SYNNEX
Applications and Power Management
SYNNEX
Applications and Power Management
SYNNEX
Application Power Management APIs
GetSystemPowerState
y Retrieve the current system power state
SetSystemPowerState
y Request a particular system power state
SetPowerRequirement
y Request specific device to maintain minimum power level
ReleasePowerRequirement
y Release device requirement
RequestPowerNotifications
y Request notification when certain types of power related events
occur
StopPowerNotifications
y No longer have a need to receive power notifications
SYNNEX
Idle Power Management
SYNNEX
Suspend/Resume
Suspend
y Lowest possible power state
y Device is off from user perspective, but maintains volatile
memory
y Must be supported by cpu
Resume
y “Instant on”
y Returns to state that existed prior to entering suspend
y Transparent to applications
SYNNEX
Suspend/Resume
SYNNEX
Suspend/Resume
Suspend Path
y PM disables all PM-aware non-block drivers
y PM calls IOCTL_HAL_PRESUSPEND
y PM notifies file systems
y PM disables all PM-aware block drivers
y System goes “single threaded”
y Kernel calls all legacy xxx_PowerDown functions
y Kernel calls OEMPowerOff
SYNNEX
Suspend/Resume
Resume Path
y CPU wakes up and continues executing
y OEMPowerOff returns
y Kernel calls all legacy xxx_PowerUp routines
y System goes multi-threaded
y PM enables PM-aware block drivers
y PM enables file systems
y PM enables remaining PM-aware drivers
SYNNEX
Operating System
Components
Internationalization
SYNNEX
Internationalization
SYNNEX
Internationalization
Locale Support
Arabic
English (U.S.)
English (Worldwide)
French
German
Hebrew
Indic
Japanese
Korean
Simplified Chinese
Traditional Chinese
Thai
SYNNEX
Internationalization
Adding locales
Selecting codepages
SYNNEX
Multilingual User Interface
German French
DLL DLL
English Spanish
DLL DLL
CE OS
SYNNEX
Device Driver
Concepts
SYNNEX
What is a Device Driver?
Application
Driver
CE 6.0
Device
SYNNEX
Monolithic vs Layered
SYNNEX
Monolithic vs. Layered
Monolithic Drivers
y Does not leverage high level shared library of interface
routines
y Written to implement requirements as efficiently as
possible
y Can have increased or otherwise unique feature set (not
dependent on MDD implementation)
y Less code reuse, more complex development
y Can be more efficient due to streamlined functions
SYNNEX
Monolithic vs. Layered
Hybrid Drivers
y MDDs are not immutable. Clone and modify as
necessary
y Modified MDDs are often used to implement missing
feature requirements
y Maintains ease of development benefits by starting with
existing high level driver implementation
SYNNEX
Native vs. Stream
Native
y Fixed set of native device classes defined by CE
•Keyboard
•Display
•Touch
y Drivers loaded directly by GWES, not managed by device
y Each has its own model
SYNNEX
Native Device Driver Model
MDD
Monolithic
Native Driver
PDD
Device
SYNNEX
Native vs. Stream
Stream Drivers
y Loaded and managed by Device Manager
y Support any type of physical or virtual device
y Device Manager imposes minimum interface
requirements (driver entry points and behavior)
y Stream model applies to most drivers
y Exposed to applications through filesystem APIs
y Can be loaded at boot or dynamically
SYNNEX
Stream Interface Device Driver Model
Device Manager
MDD NDIS
Miniport
Monolithic
Stream NDIS Wrapper
Interface NDIS
Driver
PDD
Device
SYNNEX
Stream Driver
Architecture
SYNNEX
Device File Names
SYNNEX
Device File Names
Legacy Namespace
y Original naming convention
y Used by most legacy drivers
y Consists of Prefix followed by Index (0-9)
Limited to 10 instances of a particular prefix (COM0 -
COM9)
y Prefix included in driver entry points
Unless special registry flag is set
SYNNEX
Device File Names
Device
y Similar to Legacy namespace
y Consists of Prefix followed by number
y Provides support for more than 10 devices
“\$device\COM27”
SYNNEX
Device File Names
Bus
y Typically used with client drivers loaded by a bus driver
y Provides mechanism to differentiate between IO and bus
control operations
y Provides mechanism for more sophisticated driver
loading/unloading/power management features
SYNNEX
Stream Driver Architecture
Application
CreateFile
File System
Stream Interface
Driver
(Loaded at Boot up)
Device
Window CE
Manager
Kernel
OAL
Interrupt Events
Software
Hardware
SYNNEX
Implementing Generic Stream Drivers
SYNNEX
Stream Entry Points: Init, Deinit
XXX_Init
y Called when Device Manager loads the driver
y Initialize necessary resources
y Perform memory mapping
y Initialize IST
XXX_Deinit
y Called when Device Manager unloads the driver
y Frees allocated resources, stops the IST
SYNNEX
Stream Entry Points: Open, Close
XXX_Open
y Called in response to CreateFile on device name
y Provides handle for use by other IO functions
y Allocate resources for open context and prepare for
operation
XXX_Close
y Called in response to CloseHandle
y Clean up open context
SYNNEX
Stream Entry Points: Read, Write and Seek
XXX_Read
y Called in response to ReadFile
XXX_Write
y Called in response to WriteFile
XXX_Seek
y Called in response to SetFilePointer
SYNNEX
Stream Entry Points: IOControl
XXX_IOControl
y Called in response to DeviceIoControl
y Provides mechanism supporting custom driver
operations
y Workhorse of most drivers
y I/O control code identifies the operation
y I/O control code is device-specific
SYNNEX
Stream Entry Points: PowerUp, PowerDown
XXX_PowerDown
y Callback notifying device that OS is suspending
y Allows driver to perform any desired operations
necessary to go into low power mode
XXX_PowerUp
y Callback notifying device that OS is resuming
y Allows driver to perform any desired operations
necessary to exit low power mode
SYNNEX
Stream Entry Points: PreClose, PreDeinit
XXX_PreClose
y Called prior to XXX_Close when application calls
CloseHandle
y Provides opportunity for driver to wake sleeping threads
y Eliminates potential race condition with multiple threads
XXX_PreDeinit
y Called prior to XXX_Deinit when driver unloads
y Provides opportunity for driver to mark handle as invalid
y Eliminates potential race condition with multiple threads
SYNNEX
Stream Driver Interfaces – Entry Points
SYNNEX
User and Kernel Mode Drivers
DEVMRG.DLL FILESYS.DLL
KERNEL.DLL Networking
GWES.DLL
DLLs
Drivers FSDMGR.DLL
OAL
K.COREDLL.DLL
SYNNEX
User vs. Kernel Mode Drivers – Kernel Mode
SYNNEX
User vs. Kernel Mode Drivers – User Mode
SYNNEX
User Mode Driver Framework
Improved stability
y User-Mode Drivers are isolated from other drivers
y Kernel is isolated from user-mode drivers
Increased security
y Kernel protected from compromised drivers
y Lower privileges restrain a compromised driver
Recoverability
y System can recover after a driver crash
y Driver can be restarted without rebooting
SYNNEX
Loading a User Mode Driver
10 HANDLE
1 Returned
SYNNEX
Registry For User Mode Driver
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Ethman]
"Prefix"="ETM"
"Dll"="ethman.dll"
"Index"=dword:1
; WZCSVC must be started before ethman
"Order"=dword:2A
; Flags==12 is DEVFLAGS_LOADLIBRARY and DEVFLAGS_LOAD_AS_USERPROC
"Flags"=dword:12
"UserProcGroup"=dword:3 ; // default to group 3
SYNNEX
BIB File Issues
SYNNEX
Device Driver
Concepts Interrupts
SYNNEX
Interrupt Terminology
SYNNEX
Interrupt Terminology
IRQ
y Hardware identifier indicating interrupt source
y Interpretation specific to BSP
y Could map to multiple SYSINTRs (shared interrupts)
SYSINTR
y Software identifier indicating interrupt source
y Mapped to a single IRQ by the OAL
y Associated with Event object by InterruptInitialize
y Returned by ISR to kernel
SYNNEX
Setup Interrupt
SYNNEX
Interrupt Service Thread
SYNNEX
Installable ISRs
SYNNEX
Installable ISRs
SYNNEX
Installable ISRs - APIs
LoadIntChainHandler
y Loads DLL into kernel
y Registers for particular IRQ
y Indicates handler function within DLL
FreeIntChainHandler
y Unload interrupt handler
KernelLibIoControl
y IST interface to ISR
SYNNEX
Generic Installable ISR (GIISR)
SYNNEX
Loading Stream
Drivers
SYNNEX
Driver Loading
SYNNEX
Driver Registry Settings
Dll [Required]
y Specifies the name of the driver DLL
Prefix [Optional]
y Specifies the file name for the device driver
Order [Optional]
y Specifies order to load driver
Index [Optional]
y Specifies the device index (x in COMx:)
IClass [Optional]
y Specifies GUID(s) for device class(es) for use by PnP notification
system
Flags [Optional]
y Specifies load flags for the driver
SYNNEX
Driver Registry Settings – Flags Parameter
SYNNEX
Driver Registry Settings – Bus Information
InterfaceType
y Specifies the Interface (Bus) type used for a device
See INTERFACE_TYPE enumeration in CEDDK.H for a complete
list of interface types defined by Microsoft. (You can define new
ones if you need to)
BusNumber
y Bus Instance number
Uniquely identifies the specific bus in case there is more than one
of the specified type in the system
SYNNEX
Driver Registry Settings – Memory and I/O
Windows
Memory and I/O Window information may be populated by a Plug and
Play Bus Driver or configured by the system OEM
IoBase
y Specifies the bus relative base of an I/O mapped window used by the
device.
Multiple windows specified using a binary array of 32bit values, one for each
window needed
IoLen
y Specifies the length of each I/O window needed by the device
MemBase
y Specifies the bus relative base of a memory mapped window used by
the device.
Multiple windows specified using a binary array of 32bit values, one for each
window needed
MemLen
y Specifies the length of each memory mapped window needed by the
device
SYNNEX
Driver Registry Settings – Interrupts
IRQ
y Specifies the physical IRQ used by the device
SYSINTR
y Specifies a Logical interrupt Identifier
Typically allocated by a bus driver for shared IRQs, the Device driver reads
this value and if present uses the one provided by the bus driver. Otherwise
the driver should use the IRQ to request a new logical ID.
IsrDll
y Specifies a DLL to containing an installable interrupt handler
IsrHandler
y Specifies the ISR handler in the ISR DLL
SYNNEX
Bus Drivers
SYNNEX
Bus Enumerator
SYNNEX
Device Manager – Loading Drivers at Boot
SYNNEX
Sample Registry
Example:
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\AmdNorFMD]
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\AmdNorFMD]
"Dll"="amdnord.dll"
"Dll"="amdnord.dll"
"Prefix"=“DSK"
"Prefix"=“DSK"
"Flags"=dword:00010000
"Flags"=dword:00010000
"Order"=dword:2
"Order"=dword:2
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Backlight]
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Backlight]
"Dll"=“backlight.dlll"
"Dll"=“backlight.dlll"
"Prefix"=“BKL“
"Prefix"=“BKL“
"Order"=dword:1
"Order"=dword:1
SYNNEX
Application
Development
SYNNEX
Application Development Options
Languages
y C, C++, C#, VB and Assembler
Frameworks
y WIN32
y MFC, ATL, WTL, STL
y .NET Compact Framework
SYNNEX
.NET Managed Applications
SYNNEX
Native Applications
SYNNEX
Managed Applications
SYNNEX
~Thank You~
WinCE MOC Training Partner
Bsquare
TechWare
巨匠
SYNNEX