Windows CE Object Store 특징과 FAT File system

Download Report

Transcript Windows CE Object Store 특징과 FAT File system

Windows CE Object Store 특징과
FAT File system
김 재형 ([email protected])
DST㈜ 기술팀 과장
Agenda
Windows CE Object Store
Registry Solution
Hive-Based Registry 구현
비 휘발성 Object Store 구현
FAT File-system
Boot Loader with FAT
DEMO
Windows CE의 Object Store
Object Store = OS의 주 기억장소
RAM FS
Cold Boot
Data Base
Registry
Windows CE의 Object Store
RAM-Based Registry
SYSGEN_FSREGRAM
Cold 부팅 시 설정이 지워짐.
Registry 설정을 저장 및 복구할 수 있는 OAL 함수가 제공됨.
pReadRegistryFromOEM
pWriteRegistryToOEM
RAM-Based Object store
SYSGEN_FSRAMROM
Object Store는 File system의 Root로 사용되며, 항상 mount됨.
Cold 부팅 시 File및 Data들이 지워짐.
File 저장 과 실행 Memory로 구성
FSRAMPERCENT
SetSystemMemoryDivision()
RAM Object store는 256 MB size 제한
Windows CE의 Object Store
RAM-Based File System
보통 모든 File System의 Root로 사용 (‘\’)
RAM Memory 영역의 Read/Write 가능한 영역
BIB file의 “FILES”에 정의된 file들
기본적으로 file을 압축하여 저장
“nknocompr”로 file압축기능 해제
개별 file의 압축기능 해제는 CreateFile()에
“FILE_FLAG_RANDOM_ACCESS” flag 사용
ROM-Based File System
“\Windows” 폴더로 표현되는 ROM의 file들을 처리
Read-Only File system
BIB file의 “MODULES”에 정의된 실행 file들
File-Shadowing 기능으로 일시적인 update가능
Registry Solution
두 형태의 Registry Solution이 제공
RAM-Based Registry
Hive-Based Registry
Registry는 DRE 와 PRE로 분류
DRE : Default Registry Entries
Windows CE OS image(NK.bin) 에 포함
RAM-Based의 경우 “Default.fdf”
Hive-Based의 경우 “Boot.hv”,“System.hv”,”User.hv”
PRE : Persistent Registry Entries
Windows CE OS image(NK.bin)에 분리
영구저장 장치에 registry저장
RAM-Based의 경우 대부분 Binary 형태로 저장
Hive-Based의 경우 “System.hv” 와 “User.hv”가 file로 저장
Registry Solution
DRE는 Windows CE OS
Build 4단계 에서 모든
*.REG file이 통합된 후
압축되어 만들어짐.
*.REG
Merge
REGINIT.INI
Compres
s
Boot.hv
Default.hv
Default.fdf
User.hv
RAM based Registry
Hive based Registry
NK.Bin
Registry Solution
RAM-Based Registry의 PRE 구현
OAL의 OEMInit()에
WriteRegistryToOEM 과 ReadRegistryFromOEM 연결
OS는 이들 function을 사용하기 위한 포인터 만 제공
Memory Device Vendor에서 관련 code 제공
M-systems(Boot SDK), Intel(IPSM), VIA(HDD-Regsave)
Registry Solution
RAM-Based Registry환경의
Booting 과정
NK.exe
Filesys.exe
RAM File System & Data Base
sub system 초기화
YES
RAM의 registry를
system registry로 사용
RAM에 registry가 있는지 확인
NO
ReadRegistryFromOEM() 확인
YES
ReadRegistryFormOEM()
를 통해서 PRE 복원
NO
NK.Bin에 있는 DRE를 load하여
system registry로 사용.
Hive-Based Registry 구현
Hive는 File system에 저장되는 Registry
File.
Boot Hive
System hive를 읽어오기 위한 최소한의 boot설정이
담겨있음.
System Hive (Default Hive)
System Registry Data (HKLM, HKCR, HKU)
User Hive
User Registry Data (HKCU)
사용자 별 설정.
Hive-Based Registry 구현
Catalog에서 Component 추가 사항
Hive Based Registry Component 추가
(SYSGEN_FSREGHIVE)
File-system, Storage Manager 추가
SYSGEN_STOREMGR
FAT (SYSGEN_FATFS) ?
TFAT (SYSGEN_TFAT) ?
Partition Driver (SYSGEN_MSPART) ?
Hive-Based Registry 구현
Hive Boot Section관련 registry 정의
Boot media를 Access하여 System을 boot하기
위한 component와 driver들을 정의.
아래와 같은 주석으로 묶인 registry를 포함.
;Hive Boot Section
<registry settings>
;End Hive Boot Section
Common.reg 에는 기본 setting이 정의됨
Hive-Based Registry 구현
Block Device Driver가 두 번 load되지 않도록
registry 설정.
[HKLM\Builtin\drivers\BuiltIn\BlockDeviceDriver]
“Flags”=dword:1000
System Registry가 저장되는 장치.
[HKLM\System\StorageManager\Profiles\
BlockDeviceDriverProfile]
“MountFlags”=dword:2
or
“MountAsBootable”=dword:1
Hive-Based Registry 구현
Boot Variable Registry 설정
[HKLM\init\BootVars]
"SystemHive"="<system hive path>”
name
"Start DevMgr"=dword:<your value>
;0 = don’t start
사용
;1 = Start
“Default User”=“<username>”
“ProfileDir”= <path>
“Flags” = dword:3
;Bit 0 = start storage manager
;Bit 1 = start device manager
“RegistryFlags”=dword:<your value>
여부
;1 = enables aggressive flushing
;0 = default behavior
: System.hv의 저장 경로 및
: Device Manager실행 여부
Windows CE .NET 4.2에서
: User.hv의 저장 경로
: Device Manager 실행 여부
Windows CE 5.0에서 사용
: Aggressive Flushing 적용
Hive-Based Registry 구현
Registry 저장 방법
Suspend/Resume/PowerDown시 자동으로
Registry 저장(RegFlushKey()호출)
다양한 Registry 저장 방법이 있다.
RegCloseKey()가 호출 될 때 Registry 저장
Aggressive Flushing
NAND Media Flash에서는 Bad Block유의
[HKLM\init\BootVars]
“RegistryFlags"=dword:1
주기적인 Registry 저장.
Lazy Flushing Thread사용
PRJ_ENABLE_REGFLUSH_THREAD (환경변수선언)
Hive-Based Registry 구현
Registry 지우는 방법
System hive는 RegReplaceKey( )으로,
User hive는 DeleteFile( )으로 삭제.
OS booting중 IOCTL_HAL_GET_HIVE_CLEAN_FLAG
OEMIoControl Code 이용
NK.exe
Filesys.exe
OAL
(OEMIoControl)
Hardware
Out
KernelIoControl
(IOCTL_HAL_GET_HIVE_CLEAN_FLA
G)
Input buffer =
HIVECLEANFLAG_SYSTEM
KernelIoControl
(IOCTL_HAL_GET_HIVE_CLEAN_FLA
G)
Input buffer =
HIVECLEANFLAG_USERS
Buffer
= TRUE
Out Buffer = FALSE
저장 장치의
PRE 삭제
저장 장치의
PRE 사용
Hive-Based Registry 구현
IOCTL_HAL_GET_HIVE_CLEAN_FLAG Sample
code
Hive-Based Registry Solution 의
Booting 과정
A. Filesys.exe 실행
* I 단계에서 Filesys.exe는 device manager 에
System/BootPhase2 named event를 발생하여
device manager가 system registry를 기반으로
driver를 다시 enumerate 하도록 한다.
B.
Filesys.exe는 Boot
registry(boot.hv)를 load
C.
Device manager 실행
(device.exe)
D.
Driver load
E.
Block driver와 file system
초기화
F.
Filesys.exe는 mount된 file
system에서 system
registry를 load
G. System registry 로 Kernel
초기화
H.
Filesys.exe 실행
I.
Application 또는 다른
component 실행
Hive-based registry 이점
DRAM의 Back up power의 공급 없이 cold
boot에서도 변경된 registry를 사용.
Windows CE가 인식한 어떠한 File 저장
장치에 Registry를 저장.
암호 저장 기능.
암호는 해킹 방지를 위해 Registry에 저장되지
않고 Object Store에 저장됨, hive는 암호를
영구 저장하기 위한 해킹 불가능한 별도의
공간을 가지고 있음.
비 휘발성 Object Store 구현
Catalog에서 Component 추가 사항
ROM-Only File System Component추가
(SYSGEN_FSROMONLY)
Storage 관리자 Component 추가
SYSGEN_STOREMGR
FAT (SYSGEN_FATFS) ?
FAT (SYSGEN_TFAT) ?
Partition Driver (SYSGEN_MSPART) ?
비 휘발성 Object Store 구현
Mount Root File System
[HKLM\System\StorageManager\Profiles\
BlockDeviceDriverProfile]
“MountAsRoot” = dword:1
비 휘발성 Object Store 구현
Config.bib의 FSRAMPERCENT 를 수정
0x80808080이 기본 설정 값.
Set FSRAMPERCENT to >= 32KB
일부 기능에서 RAM Object Store 사용.
Recycle Bin
Copy Operations
Manage Stack and Memory Heap
Compress and Expand Files
비 휘발성 Object Store 장점
Cold Boot System의 간결화
Data 와 Registry설정 이 영구 저장됨.
응용 프로그램을 한번만 설치 하면 됨.
Data의 저장 및 복구의 요구사항이 줄어 듬.
Object Store Size의 제한이 없음.
배터리 Power 관리 효율
백업 배터리를 없애거나 사용을 줄 일수 있다.
배터리 사용시간 증가.
적은 량의 RAM을 요구 = 저전력
System의 비용절감
데이터 저장용으로 Flash가 RAM 보다 저렴.
비 휘발성 Object Store 장점
OS의 System file update.
Cold boot후 에도 File-Shadow 된 Component는
영구적 사용 가능.
File-Shadowing
같은 이름의 File을 ROM 과 RAM에 저장 가능.
ROM = Windows 폴더 (Nk.bin)
RAM = Object Store (RAM or 저장장치)
File 또는 OS component의 일시적 update효과.
Cold boot시 update된 File이 지워짐
ROM에 있는 File로 다시 복구됨.
RAM & ROM File system은 Cold boot후 모두 지워짐.
Update된 file이 저장소에서 지워지면
ROM-imgae(NK.bin)로 부터 복원됨.
OS binary image(nk.bin)를 update할 필요가 없다.
사용자가 생성한 바탕 화면 ICON 과 폴더의 저장.
비 휘발성 Object Store 특징
RAM and ROM File
System
ROM-Only File System
성능에 대한 고려사항
RAM based Object Store에 비하여 성능이 느리다.
NOR Flash Memory
읽기 속도가 빠르다.
쓰기 속도가 NAND보다 느리다.
NAND Flash Memory
읽기 속도가 NOR보다 느리다.
쓰기 속도가 NOR보다 빠르다.
RAM Drive를 사용하여 Application의 성능을 향상 시킬 수 있다.
적절한 File System Cache 설정
HKLM\SYSTEM\StorageManager\FATFS
“EnableCache” = dword:1
“CacheSize” = dword:?
FATFS_VERIFY_WRITES Flag ?
FATSF_WRITETHROUGH Flag ?
성능향상을 위한 File System Driver 튜닝.
DOC Example
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\TrueFFS]
"Index"=dword:1
"Dll"="TrueFFS.dll"
"Prefix"="DSK"
"Order"=dword:1
"Ioctl"=dword:4
"AutoFormat"=dword:1 ; test for format to boot
"DocAccessType"=dword:10
"WindowBase"=dword:0c000000
"IClass"="{A4E7EDDA-E575-4252-9D6B-4195D48BB865}“
"Flags"=dword:1000
"BootPhase"=dword:1
;avoid loading the driver twice
;NLS support required
DOC Example
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\TRUEFFS_DOC]
"Name"="DiskOnChip M-Systems"
"Folder"="DiskOnChip"
"AutoFormat"=dword:1 ;auto format if needed
"AutoPart"=dword:1
;auto partition if needed
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\TRUEFFS_DOC]
"DefaultFileSystem"="FATFS"
"AutoMount"=dword:1
;mount any partition automatically
"MountAsRoot"=dword:1
;makes trueffs the root of the file system
"MountAsBootable"=dword:1
;specifies that Trueffs contains the system hive.
"BootPhase"=dword:1
;NLS required
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\TRUEFFS_DOC\FATFS]
“MountAsBootable"=dword:1
;FATFS is mounted as bootable
"MountAsRoot"=dword:1
;FATFS contains the system hive
FAT File-system
FAT (File Allocation Table) 란 ?
Reserved 영역 : MBR, PBR, Reserved
FAT 영역 : File Allocation Tables (FAT)
일반적으로 2개의 FAT가 제공(back up용도)
File을 구성하는 여러 개의 물리 Cluster의 연결정보
Root Directory 영역 : FAT 12/16 에서만 지원
Sub directory, files등 설명하는 entry의 집합
File and Directory Data 영역
실제 file 및 sub directory의 data가 담겨있는 영역
Sector들의 집합인 Cluster들로 분리
FAT에 의해 저장공간이 할당됨
Reserved
Region
FAT
Region
Root Dir
Region
(FAT12/16)
File and Directory
Data Region
FAT File-system
FAT File 접근 방법
Directory entry에서 file의 시작 cluster위치를 읽어온다
FAT영역의 cluster의 연결 정보를 통해서 data영역의
2 – 4 – 5번 cluster에서 file data를 읽어온다
Reserved
Region
Root Dir
Region
FAT
Region
(FAT12/16)
File and Directory
Data Region
Index
0
1
2
3
4
5
Value
X
X
4
0
5
EOF
Cluster
2
3
4
5
6
Contents
File1
Data
X
File1
Data
File1
Data
…
FAT File-system
MBR (Master Boot Record)
Sector 0번에 위치
Disk 정보 및 용량
PBR의 위치 정보
PBR의 시작 Sector번호
Offset
Bytes
Parameter
Data
Boot Command (not in use)
00h … 00h
000h –1BDh
446
1BEh
1
1BFh
1
Start Head No. (0-based)
(01h)
1C0h
1
Start Sector No. (1-based)
(01h)
1C1h
1
Start Cylinder No. (0-based)
(00h)
1C2h
1
Partition Type
1C3h
1
End Head No. (0-based)
(07h)
1C4h
1
End Sector No. (1-based)
(e0h)
1C5h
1
End Cylinder No. (0-based)
(d1h)
1C6h-1C9h
4
Start Logical Sector No.
1CAh-1CDh
4
Total Available Sectors
1CEh-1DDh
16
Partition 2 (not in use)
1DEh-1EDh
16
Partition 3 (not in use)
1EEh-1FDh
16
Partition 4 (not in use)
1FEh-1FFh
2
Signature
Boot ID (Active Disk)
Partition 1
80h
06h
20h
FAT File-system
PBR (Partition Boot Record) (Sector 32번)
Disk partition의 정보
FAT영역, Root Directory영역, Data Cluster영역 정의
Offset
Bytes
Description
Data
000h-002h
3
JMP Instruction to PBR boot code
003h-00Ah
8
OEM Name and Version
00Bh-00Ch
2
Bytes per Sector
512
00Dh
1
Sectors per Cluster
4
00Eh-00Fh
2
Reserved Sectors
8
“MSDOS5.0”
010h
1
The number of FAT
2
011h-012h
2
The number of root directory entities
512
013h-014h
2
Total Available Sectors ①
63965
015h
1
Media ID Bytes ②
F8h
016h-017h
2
Sectors per each FAT
244
018h-019h
2
Sectors per Track
16
01Ah-01Bh
2
The number of Heads
8
01Ch-01Fh
4
Hidden Sectors ③
35
020h-023h
4
Huge Sectors ④
0
024h
1
Driver number (00h=floppy, 80h=fixed)
80h
025h
1
Reserved
00h
026h
1
Extended Boot Signature
29h
027h-02Ah
4
Volume ID or Serial number
0
Bios Parameter Block
02Bh-035h
11
Volume Label
“
036h-03Dh
8
File System Type ⑤
1 (FAT16)
03Eh-1FDh
448
1FEh-1FFh
2
Boot Code
Signature Word
55AAh
“
FAT File-system
FAT0 시작 sector번호 =
PBR시작 sector번호 + Reserved sector수 =
(32 + 8) = 40번
FAT1 시작 sector번호 =
FAT0시작 sector번호 + FAT sector수(Sectors per each FAT) =
(40 + 244) = 284번
Root Directory 시작 sector번호 =
FAT1시작 sector번호 + FAT sector수 =
(284 + 244) = 528번
Data Cluster(Cluster 2)시작 sector번호 =
Root Directory시작 sector번호 + Root Dir sector수 =
(528 + 32) = 560번
Root Directory sector수 =
(Directory entry 수 * 32) / Bytes per sector =
(512 * 32 ) / 512 =32개
Root Directory Entry는 32Byte로 구성
FAT File-system
FAT 0번 (Sector 40번)
File data가 저장된 Cluster의 연결 정보
“FFF8”,”FFFF”는 FAT ID표식으로 Cluster 0,1번에
Disk정보(Reserved)가 있음을 표시.
File data영역은 Cluster 2번 부터 시작한다.
아래 그림은 하나의 Cluster에 File data를 저장 할 수 있는 file이
6개 있음을 나타낸다.
FAT 1번 (Sector 284번)은 backup용도
Windows CE는 FAT 하나만 사용.
TFAT (Transaction-Safe FAT)을 적용하면 FAT1 포함
FAT ID
Cluster 2, 마지막 cluster
FAT 16
Description
000h
Unused cluster
001h
Reserved
002h - FEFh
Next data cluster
FFF0h – FFF6h
Reserved
FFF7h
Defective cluster
FFF8h - FFFFh
Last cluster
FAT File-system
Root Directory Entry (Sector 528번)
Disk상의 File및 Sub Directory의 정보
File의 속성 및 size,시작 cluster위치 등등
32Byte entry로 구성
Attribute
“5678.TXT
”
Offset
Bytes
Contents
Bit
0-7
8
File Name
0
read-only
8-10
3
Extension
1
hidden
11
1
Attribute
2
system
12-21
10
reserved
3
volume label
22-23
2
Time
4
subdirectory
24-25
2
Date
5
archive
26-27
2
Start Cluster Number
6
reserved
28-31
4
File Size (in bytes)
7
reserved
FAT File-system
Long File Name entry
Virtual FAT entry + DOS entry
8.3 형식의 File name을 벗어나 최대 255자의 File name을 지원
Windows 95부터 지원
File name의 길이에 따라 LFN이 사용되지 않음
Unicode (2Bytes)기반의 File name 저장
Windows CE의 경우 8.3 형식의 file에서도 LFN적용
“Control Panel.lnk”
Contr
ol Pan
el
.lnk
VFAT
“CONTRO~1,LNK”
Bytes
Content
0
Bits 0-4: sequence number,
6: final part of name
1-10
Unicode characters 1-5
11
Attribute: 0xf
12
Type: 0
13
Checksum of short name
14-25
Unicode characters 6-11
26-27
Starting cluster: 0
28-31
Unicode characters 12-13
FAT File-system
File Data 영역 (Sector 560번)
Cluster 2번 부터 시작
“5678.TXT” file의 data =
“HIJKLM”
Cluster당 4개의 sector로 구성
Boot Loader with FAT
일반적인 Boot Loader의 흐름
StartUp()
BootLoaderMain()
OEMDebugInit()
OEMPreDownLoad()
OEMPlatformInit()
OEMLaunch()
DownloadImage()
BLCOMMON
OEMReadData()
OEMShowProgress()
OEMMapMemAddr()
Download
functions
OEMIsFlashAddr()
OEMWriteFlash()
OEMFinishEraseFlash()
OEMStartEraseFlash()
OEMContinueEraseFLash()
FLASH Functions
Boot Loader with FAT
Boot Loader with FAT
StartUp()
BootLoaderMain()
OEMDebugInit()
OEMPreDownLoad()
OEMPlatformInit()
PCMCIA Init
CF Memory Card ?
Yes
NO
OEMLaunch()
DownloadImage()
Read Sector 0
Load FAT
Read PBR
Read Data form Cluster
Read Root Dir Ent
Find OS Image
Yes
NO
Save Data to DRAM
NO
Next Cluster != FFFF
Yes
Data
OEMReadData()
Boot Loader with FAT
CF Memory Card check
Attribute Space에서 CIS (Card Information
Structure)를 Read
CIS Tuple 중 “Function ID Tuple”(21) check
Device Type == 4 이면 ATA Disk
ATA Disk초기화
ATA Disk의 configuration register위치를 CIS의
“Configuration Tuple”에서 확인 (대부분0x200h)
ATA Disk를 I/O mapped로 설정
*(pAttribute + 0x200) = 0x42;
Boot Loader with FAT
ATA Disk Read Command
I/O space의 ATA I/O Register Base Address
(Primary : 0x170, Secondary : 0x1f0)
LBA mode로 sector번호 지정
ATA Disk가 command를 수행 완료할 때 까지 대기
Read Data Buffer
Boot Loader with FAT
Sector 0번을 read하여 PBR의 위치 확인
PBR에서 Disk정보를 read하여 FAT, Root
Directory, Data Cluster위치 확인
Cluster chain정보를 FAT에서 load
Boot Loader with FAT
OS Image를 Root Directory entry 찾음
Cluster chain에서 다음 cluster의 위치
확인 후 Data read
읽은 data를 DRAM에 copy
Boot Loader with FAT
Boot Loader main()
OEMPreDownload()
Ethernet port download 방지
Boot Loader with FAT
Boot Loader main()
OEMReadData()
DRAM에 copy된 OS image data를 Boot loader의
DownloadImage()에 전달
Boot Loader with FAT
Boot Loader main()
OEMLaunch()
OS image Booting 또는 Flash에 writing
Boot Loader with FAT
Tools & Resources
msdn.microsoft.com/
embedded
msdn.microsoft.com/
mobility
microsoft.public.
windowsxp.embedded
windowsce.platbuilder
windowsce.embedded.vc
microsoft.public.
pocketpc.developer
smartphone.developer
dotnet.framework.compactframework
Blogs
blogs.msdn.com/
mikehall
blogs.msdn.com/
windowsmobile
vsdteam
netcfteam
Tools
Windows CE 5.0 Eval Kit
Windows XP Embedded Eval Kit
Websites
Newsgroups
DST Corp : www.DSTcorp.com
WECOM : WECOM.DSTcorp.com
© 2004 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.