• 검색 결과가 없습니다.

Device Driver - Daum

N/A
N/A
Protected

Academic year: 2024

Share "Device Driver - Daum"

Copied!
33
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

Device Driver

W.E.E.G

Edited by andro78 [email protected]

(2)

Contents

• Device Driver란 무엇인가?

• Driver의 종류

• Steam Driver의 구조

• User Mode Driver의 프레임 워크

• Loading a Steam Driver

(3)

Device Driver란?

• 디바이스 드라이버는 OS상에서 물리적 또는 가상 장치의 기능을 사용하기 위한 소프트웨어

Driver Application

Device CE 6.0

(4)

Device Driver의 종류

• Native

vs

Stream

어떤 프로세스에 의해 로드 되는가? Who !

• User

vs

Kernel

드라이버의 위치 Where !

• Monolithic

vs

Layered (MDD/PDD)

개발 방법 how !

• Built In

vs

Dynamic/Installable

when !

• Driver Family

(5)

Monolithic vs Layered

• Monolithic Drivers

Upper Edge와 Lower Edge를 한꺼번에 구현

호환성 문제 많은 시갂과 비용

적은 코드의 재사용성

꾀 복잡한 개발

높은 성능

(6)

Monolithic vs Layered

• MDD/PDD 또는 Layerd Drivers

Model Device Driver + Platform Device Driver = Driver

PB에서 샘플소스 제공 Upper Edge  MDD

MDD를 사용하는 경우에 개발자가 담당하는 Lower Edge

PDD

PDD (Platform Dependent Driver)

• 하드웨어 종속적인 코드만을 구현

DDSI(Device Driver Service Provider Interfave)

(7)

Monolithic vs Layered

Device.exe 또는 GWES.exe

MDD모듈

PDD모듈 모노리딕 드라이버 Layerd 드라이버

(DLL)

(8)

Native vs Stream

• Native

저마다 자신에게 가장 적합한 드라이버 인터페이스를 갖 고 있는 드라이버

• Keyboard

• Display

• Touch

GWES.exe 프로세스 아래에서 동작

각자의 고유의 드라이버 모델

(9)

Native Device Driver Model

Monolithic Native Driver Device Driver Interface (DDI)

Graphics, Windowing, and Events System (GWES)

MDD

PDD

Device Driver Interface (DDI)

Device

(10)

Native vs Stream

• Stream Drivers

장치관리자(Device.exe, Devmgr.dll)에 의해 로드 및 관리

물리적, 가상적 장치의 어떠한 타입이든 지원

최소한의 인터페이스 요구사항

• 드라이버 엔트리 포인트…

파일을 접근하듯이

• Win32 API CreateFile(), Readfile(), Writefile(), Device Control(), SetFilePointer(), CloseHandle() 등의 함수 사용

부팅 또는 직접적(설치)으로 로딩

(11)

Stream Interface Device Driver Model

Monolithic Stream Interface

Driver Stream Interface

Stream Interface

NDIS Wrapper

Device Manager

Stream Interface

(DDI)

MDD

NDIS

NDIS Wrapper NDIS Miniport

PDD

Device

(12)

Device File Names

• 드라이버는 특별한 파일 시스템 장치로 접근

• 접두어 세글자

Legacy – “COM1:”

Device – “\$device\COM1”

Bus – “\$bus\PCMCIA_0_0_0”

• 이와 동시에 인터페이스 GUID를 시스템 레지스트 리에 같이 등록

(13)

Stream Driver 구조

응용프로그램

파일 시스템

Stream Interface Driver

(부팅하면서 로딩) Window CE

Kernel 장치관리자

H/W 플랫폼 Built-in

Hardware Software Interrupt Events

OAL

CreateFile

(14)

Stream Driver의 실행

• 정해짂 접두어 세글자를 선택

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Serial]

"Irq"=dword:16 ; 22 IRQ_FFUART

"SysIntr"=dword:1d ; 29 SYSINTR_FFUART

"MemBase"=dword:40100000 ; FFUART Register

"MemLen"=dword:40

"DeviceArrayIndex"=dword:80 ; FFUART object

"Prefix"="COM"

• 엔트리 포인트 (DDI 함수들을 구현)

• *.def 파일 생성

• 드라이버를 로드하기 위한 레지스트리값 생성

(15)

Stream Entry Point : Init, Deinit

• XXX_Init

장치 관리자가 드라이버를 로드 할 때

필요한 자원의 초기화

메모리 매핑

IST초기화

• XXX_Deinit

장치 관리자가 드라이버 해제 할 때

자원을 내놓으며, IST 중지

(16)

Stream Entry Point : Read, Write …

• XXX_Read

ReadFile() 함수 - 데이터를 읽음

• XXX_Write

WriteFile() 함수 - 데이터를 기록

• XXX_Seek

setFilePoint() 함수 – 시작위치를 정의

(17)

Stream entry Points : Open, Close

• XXX_Open

CreateFile() 함수를 사용해 드라이버에 접근

CreateFile() 함수는 적젃한 디바이스 드라이버의 XXX_Open을 호출

복수 개의 쓰레드로부터 동시에 XXX_Open()

또는 한번에 하나의 쓰레드만이 XXX_Open()호출

• XXX_Close

CloseHandle() 함수를 이용

사용하던 권한을 반납

(18)

Stream Entry Points : IOControl

• XXX_IOControl

응용프로그램과 통신

DeviceIoControl() 함수를 사용해 응용프로그램이 2개의 버퍼를 제공 (app  D.D, D.D  app)

비교적 적은 양의 데이터를 사용

이 함수가 호출되기 젂에 XXX_Open()함수가 먼저 호출

BOOL XXX_IOControl(

DWORD hOpenContext, DWORD dwCode,

PBYTE pBufIn, DWORD dwLenIn,

(19)

Stream Entry Points : 기타

• XXX_PreClose

• XXX_PreDeinit

• XXX_PowerUP

• XXX_PowerDown

(20)

User Mode Driver Framework

• CE 5.0이젂, 드라이버는 User Mode에서 동작

특별한 UI상의 제약 없다

• Windows Embedded CE 6.0에서는 대부분의 드라 이버가 커널모드에서 동작

• 커널모드의 드라이버는 UI요청을 위해서는 User Mode에서 동작하는 Dll을 준비하여 사용

• CeCallUserProc () 함수를 사용

(21)

User Interface(사용예)

// Windows CE 5.0 이젂 버젂 MessageBOX(…)

//Windows Embedded CE 6.0

If (!CeCallUserProc(L”DllName”, L”FuncName”, IpInBuffer, ninBufferSize, IpOutBufferSize, IpBytesReturned))

{}

====================================

FuncName 함수

BOOL FuncName(LPVOID IpInBuffer, DWORD nInBufferSize, LPVOID IpOutBuffer, DWORD nOutBufferSize, PDWORD pBytesReturnd)

{MessageBox(Parameters unpacked from InBuffer);

}

(22)

User 와 Kernel 모드 드라이버

Windows CE

Application Shell

ServicesD.EXE Udevice.EXE Udevice.EXE User

Mode Driver 1

User Mode Driver n

Win32 CE APIs –COREDLL / WINSOCK / COMMCTRL / COMMDLG Service

1

Service n

KERNEL.DLL DEVMRG.DLL

GWES.DLL

FILESYS.DLL

OAL Drivers FSDMGR.DLL

Networking DLLs

User Memory Spaceel Memory Space

Marshalling

(23)

커널레벨의 드라이버(Kernel Mode)

• 기본적인 드라이버 모델 (CE6.0)

• 커널 가상 메모리 공갂에서 동작

• Coredll, k.coredll.dll 의 커널 버젂에 링크

자동적이며, 빌드방법을 바꿀 필요는 없음.

• 높은 성능

커널 API로 빠르게 접근

사용자 버퍼로 곧바로 접근

(24)

사용자 레벨의 드라이버(

User Mode Driver

)

• 장치관리자에 의해 관리

• Udevice.exe 가 Host의 역할

• 사용자레벨의 드라이버 < 커널레벨 드라이버

커널 구역이나 메모리에는 접근 불가능

커널에서만 사용하는 API에 대한 호출 불가능

제약된 커널 API에 대해서만 접근

• 시스템 안정성 증가

• Ex> USB, SDIO

(25)

사용자 레벨 드라이버 프레임워크

• 안정성의 향상

다른 드라이버와 구분

커널은 사용자 레벨 드라이버와 구분

• 보안성 증가

손상된 드라이버로부터 커널 보호

손상된 드라이버는 권한이 낮아짐

• 복구성

시스템은 드라이버가 손상된 후에 복구

재부팅 없이 드라이버 동작가능

(26)

유저레벨 드라이버의 로딩

1

User Application

User Mode Driver Host Process

udevice.exe User Mode Driver

Reflector Service

Device Manager 2

3 9

8

10 User Mode

Kernel Mode ActivateDeviceEx

CreateProcess(,,Volume Name) 4

5 6

7 XXX_Init(…)

9

Device Context 10

HANDLE Returned HANDLE

Returned

XXX_Init forwarded to UM Driver Host

(27)

유저레벨 드라이버 Registry

• Udevice.exe(User Mode Drive Host Process)는 레 지스트리 세팅에 의해서 실행되고 관리됨

[HKEY_LOCAL_MACHINE\Drivers\ProcGroup_0002]

"ProcName” = "udevice.exe“

"ProcVolPrefix” = "$services“

"Privilege” = dword:xxxxxx

[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\Serial]

"SysIntr” = dword:13

"IoBase” = dword:02F8

"IoLen” = dword:8

"Flags” = dword:10 (DEVFLAGS_LOAD_AS_USERPROC - 0x10)

"ProcGroup” = dword:2

"IsrDll” = “isr16550.dll"

"IsrHandler“ = "ISRHandler“

“Dll”=“ser16550.dll”

(28)

유저레벨 드라이버 – bib Files 설정

• *.bib 파일의 Module부분에 드라이버를 추가

Ex> common.bib

• K  커널레벨의 가상메모리 공갂

• K가 없으면 유저레벨의 가상메모리 공갂

• Q  커널 유저레벨 두군데 존재

(29)

Driver 로딩

• 드라이버 로딩은 레지스트리 키값에 의해 제어

When, How

Driver 파라미터

• 드라이버는 ActivateDeviceEx로 호출

다양한 변수들을 Active키 아래에 추가적으로 등록

Builtin

Plug and Play

(30)

드라이버의 레지스트리 세팅

• Dll (필수)

고유한 드라이버 DLL이름

• Prefix (옵션)

디바이스 드라이버 이름 (세글자)

• Order (옵션)

드라이버 우선순위

• Index (옵션)

드라이버 인덱스 (COM1:)

• Iclass (옵션)

PnP를 사용하기 위한 GUID

(31)

Sample 레지스트리

[HKEY_LOCAL_MACHINE\Drivers\ProcGroup_0003]

"ProcName"="udevice.exe"

"ProcVolPrefix"="$udevice"

[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

(32)
(33)

참조

관련 문서