之前我们都是把整个系统镜像复制到RAM中运行,这样启动时间较慢,也占用内存.使用Multi-Bin的模式,将需要复制到RAM的组件和可存放在存储设备(如Nand)中的组件分开,系统启动时只需要将CE核心组件复制到内存中运行,然后需要的组件从Nand中读取即可.之前我们已经在eboot中添加了操作BINFS分区的支持.然后就可以进行系统镜像的定制了.
如何实现可以参考PB帮助How to Implement BinFS一节.
1.修改config.bib进行地址设置
XIPKERNEL 80001000 00400000 RAMIMAGE
CHAIN 80401000 00001000 RESERVED
NK 80402000 02BFF000 NANDIMAGE
RAM 8C200000 01E00000 RAM
FLASH 92000000 00100000 RESERVED
XIPKERNEL就是我们的RAMIMAGE,即最小内核,里面存放了启动时必须复制到内存的文件,这里设置4MB大小,可以根据编译出来的XIPKERNEL.bin大小进行调整,MS帮助里用的是NK最为RAMIMAGE,由于RAMIMAGE里的文件较少,为了减少工作量,把common.bib中的少部分文件修改属性(NK->XIPKERNEL)即可.
NK为NANDIMAGE,其他文件就存放在这个区域
CHAIN保持了bin文件的信息
关于RAM的设置,使用Multi-Bin可以增加更多的内存,实际上80402000~82000000范围的内存也可以作为内存来使用,但是由于两片SDRAM的地址不连续,在oemaddrtab_cfg.inc中可以看到:
DCD 0x80000000, 0x32000000, 32 ; 32 MB DRAM BANK 6
DCD 0x82000000, 0x08000000, 32 ; 32 MB SROM(SRAM/ROM) BANK 1
DCD 0x84000000, 0x10000000, 32 ; nGCS2: PCMCIA/PCCARD
DCD 0x86000000, 0x18000000, 32 ; 32 MB SROM(SRAM/ROM) BANK 3
DCD 0x88000000, 0x20000000, 32 ; 32 MB SROM(SRAM/ROM) BANK 4
DCD 0x8A000000, 0x28000000, 32 ; 32 MB SROM(SRAM/ROM) BANK 5
DCD 0x8C000000, 0x30000000, 32 ; 32 MB DRAM BANK 6
而这里只能设置一片连续的RAM(8C200000起始的一段),关于如何将地址不连续的两段内存同时能被CE使用,我们将在下一节进行研究.
以下为配置信息,注意XIPSCHAIN应该为CHAIN的起始地址
CONFIG
AUTOSIZE=ON
COMPRESSION=ON
DLLADDR_AUTOSIZE=ON
KERNELFIXUPS=ON
PROFILE=OFF
RAM_AUTOSIZE=OFF
ROMFLAGS=0
ROM_AUTOSIZE=OFF
ROMSIZE=03000000
ROMSTART=80001000
ROMWIDTH=32
XIPSCHAIN=80401000
2.修改common.bib
接下来就是文件分配了,XIPKERNEL包括的主要是nk.exe,filesys.exe,还有和binfs存储相关的dll,binfs.dll,mspart.dll等,经过反复测试,需要包括的文件具体如下(可能会有不需要的文件),:
nk.exe $(_FLATRELEASEDIR)/kern.exe XIPKERNEL SHXL
kd.dll $(_FLATRELEASEDIR)/kd.dll XIPKERNEL SHK
hd.dll $(_FLATRELEASEDIR)/hd.dll XIPKERNEL SHK
osaxst0.dll $(_FLATRELEASEDIR)/osaxst0.dll XIPKERNEL SHK
osaxst1.dll $(_FLATRELEASEDIR)/osaxst1.dll XIPKERNEL SHK
coredll.dll $(_FLATRELEASEDIR)/coredll.dll XIPKERNEL SHXL
filesys.exe $(_FLATRELEASEDIR)/filesys.exe XIPKERNEL SHM
device.exe $(_FLATRELEASEDIR)/device.exe XIPKERNEL SHM
devmgr.dll $(_FLATRELEASEDIR)/devmgr.dll XIPKERNEL SHM
regenum.dll $(_FLATRELEASEDIR)/regenum.dll XIPKERNEL SH
busenum.dll $(_FLATRELEASEDIR)/busenum.dll XIPKERNEL SH
pm.dll $(_FLATRELEASEDIR)/pm.dll XIPKERNEL SHM
fatfsd.dll $(_FLATRELEASEDIR)/fatfsd.dll XIPKERNEL SH
diskcache.dll $(_FLATRELEASEDIR)/diskcache.dll XIPKERNEL SH
fatutil.dll $(_FLATRELEASEDIR)/fatutil.dll XIPKERNEL SH
fsdmgr.dll $(_FLATRELEASEDIR)/fsdmgr.dll XIPKERNEL SH
binfs.dll $(_FLATRELEASEDIR)/binfs.dll XIPKERNEL SH
mspart.dll $(_FLATRELEASEDIR)/mspart.dll XIPKERNEL SH
ceddk.dll $(_FLATRELEASEDIR)/ceddk.dll XIPKERNEL SH
wince.nls $(_FLATRELEASEDIR)/wince.nls XIPKERNEL SHU
default.fdf $(_FLATRELEASEDIR)/default.fdf XIPKERNEL SH
boot.hv $(_FLATRELEASEDIR)/boot.hv XIPKERNEL SH
但是将这段设置放到common.bib下会报重复定义的错误(Warning: Found duplicate entry 'nk.exe')因为这些文件之前都定义在NK上,这样新的设置有可能被忽略掉了,因此我将这些文件的NK属性直接修改为XIPKERNEL(先备份好common.bib,位于/PUBLIC/COMMON/OAK/FILES/common.bib)
如:
IF IMGSIGN
IF IMGPROFILER
nk.exe $(_FLATRELEASEDIR)/kernkitlprof.exe XIPKERNEL SHXL
ENDIF IMGPROFILER
IF IMGPROFILER !
IF IMGNOKITL
nk.exe $(_FLATRELEASEDIR)/kern.exe XIPKERNEL SHXL
ENDIF IMGNOKITL
IF IMGNOKITL !
nk.exe $(_FLATRELEASEDIR)/kernkitl.exe XIPKERNEL SHXL
ENDIF IMGNOKITL !
ENDIF IMGPROFILER !
ENDIF IMGSIGN
3.注册表设置
[HKEY_LOCAL_MACHINE/init/BootVars]
"SystemHive"="Documents and Settings//system.hv"
"ProfileDir"="Documents and Settings"
"Flags"=dword:3 ;equals to "Start DevMgr"=dword:1
"RegistryFlags"=dword:1 ;auto flush system.hv
; END HIVE BOOT SECTION
; @CESYSGEN ENDIF FILESYS_FSREGHIVE
; HIVE BOOT SECTION
; @CESYSGEN IF CE_MODULES_SDNPCID
; Default values for binfs. These can be overridden per profile
[HKEY_LOCAL_MACHINE/System/StorageManager/BinFS]
"FriendlyName"="BIN Filesystem"
"Dll"="binfs.dll"
"Paging"=dword:1
"Folder"="BINFS"
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/MSFlash]
"Profile"="MSFlash"
"IClass"=multi_sz:"{A4E7EDDA-E575-4252-9D6B-4195D48BB865}"
"Order"=dword:0
"FriendlyName"="MSFLASH Driver"
"Dll"="smflash.dll"
"Prefix"="DSK"
"Ioctl"=dword:4
"Flags"=dword:1000
"BootPhase"=dword:0
[HKEY_LOCAL_MACHINE/System/StorageManager/AutoLoad/MSFlash]
"DriverPath"="Drivers//BuiltIn//MSFlash"
; LoadFlags 0x01 == load synchronously
"LoadFlags"=dword:1
"Order"=dword:0
"BootPhase"=dword:0
; @CESYSGEN ENDIF CE_MODULES_SDNPCID
; END HIVE BOOT SECTION
; HIVE BOOT SECTION
; @CESYSGEN IF CE_MODULES_SDNPCID
[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/MSFlash]
"DefaultFileSystem"="BINFS"
"PartitionDriver"="mspart.dll"
"MountAsROM"=dword:1
"MountHidden"=dword:1 ;hide BINFS folder
"Folder"="Flash Disk"
"Name"="FLASH Disk Block Device"
"AutoMount"=dword:1
"AutoPart"=dword:1
"BootPhase"=dword:0
"Flags"=dword:1000
"AutoFormat"=dword:1
; Keep FATFS from trying to shadow /Windows
[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/MSFlash/FATFS]
"MountAsROM"=dword:0
"MountHidden"=dword:0 ;display Flash Dish folder
"MountAsBootable"=dword:1
"Flags"=dword:00000014 ;FATFS_FORCE_WRITETHROUGH | FATFS_DISABLE_AUTOSCAN
"EnableWriteBack"=dword:1
"CheckForFormat"=dword:1
; @CESYSGEN ENDIF CE_MODULES_SDNPCID
; END HIVE BOOT SECTION
最终编译出来的xip.bin为9.55MB(没有中文支持),里面包含了XIPKERNEL.bin(1.34MB),NK.bin(8.2MB),chain.bin,通过PB将xip.bin烧写到BINFS分区中.设置eboot启动读BINFS分区镜像大小(2MB),这样启动速度明显加快,可以看到BINFS文件夹(MountHidden设为0).
至此,Multi-Bin已基本实现,还剩将两段地址不连续的内存都注册给CE使用,这样内存就能大大增加了.