加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSSRSS-巴斯仪表网
您当前的位置:首页 > 电子发烧 > 单片机学习

S3c2440A平台HIVE注册表+binfs的实现

时间:2013-09-08  来源:123485.com  作者:9stone

今天总结一些实现的过程和原理。
      我的例子是基于samsung S3C2440A+samsung ONENAND+WinCE5.0的,开发平台是platform builder 5.0,首先我们基于RAM register的image已经可以正常跑起来了,Flash除了放置image外其他的空间为用户提供文件系统,这部分的驱动程序是用三星的 PocetStoreII15。

      先来回味一下底层的东东,我们的Image主要由两部分组成:XIPKERNEL.bin和 NK.bin,XIPKERNEL.bin中的东西就是那些WinCE中比较核心的又需要经常加载的一些程序和DLL文件,这些文件会被Boot Loader在刚启动的时候拷贝到RAM中去,这样就可以在RAM中XIP(Excute in place)了。在NK.bin中的基本上是需要但不至于要常驻内存的一些程序和DLL了,比如我们BuildIn下的大部分驱动,比如微软的IE, mediaplayer等应用程序,甚至连设备管理器device.exe也可以放到这里面,这些文件只有在需要的时候才被复制到内存中去执行,节约了内存并且也加快了启动的时间。嘿,到这里大概知道binfs的工作原理和重要性吧。

       binfs的建立工作是在用UT(OEM自己的一种底层的工具集)实现的,UT在烧image的时候会自动把XIPKERNEL和NK分别保存到flash的特定的逻辑扇区上.启动的时候Boot Loader会先把XIPKERNEL复制到RAM中,然后跳到RAM中的XIPKERNEL的入口点去执行,这个时候会跑一些OEMinit之类的 CPU,内存,中短等初始化的过程,接着OS会从注册表中找到binfs的一些设置,然后加载binfs的驱动使binfs分区对OS来讲是可用的,假如 device.exe是在NK.bin中的话,那么在这个时候就可以用/binfs/device.exe(/binfs是假设的装载路径)来调用它了,如果这个时候binfs没有初始化成功那么,device.exe得不到执行,那么系统肯定就起不来了。

       现在来讲讲HIVE,其实 HIVE是个很简单的东西,都怪和binfs牵到一起搞得很多问题都走错了方向,本来一天就能搞定结果搞了四五天,NND。这么说吧,WinCE下面就两种注册表,一种是RAM based,另外就是HIVE based了,缺省用的是前者,如果用前者PB会在编译的时候把common.reg和platform.reg的内容做到一个叫reginit.ini 的文件然后压缩成default.***(忘记扩展名了,有过老迹象了哈)的文件放到XIPKERNEL中去,image在起来的时候会把这个文件解压到 RAM中形成RAM based注册表,既然是RAM based那么所有的改动都会在断电后蒸发,哈哈。怎么办呢?其实再笨你也能想出来,保存到磁盘上不就结了吗!?对你太聪明了,但是你想如果你把注册表全放到磁盘(SDMMC或HDD或Flash)上WinCE怎么在没有加载你磁盘的驱动的情况下读到注册表呢?而一般情况加载磁盘的驱动程序也是要注册表的支持啊!嘿,对了,这就是HIVE想到的,看它怎么做,它把注册表分成两部分(其实是三部分,当时大体还是两步分,把user.hv和system.hv 做一部分),第一部分就是叫做boot.hv的注册表,里面的东西就是一些在没有拿到保存在磁盘的注册表之前引导时需要的一些设置,这部分的注册表和 RAM based的是一样的,改了之后断电就没了,所以这部分的注册表项都是不需要改动的,需要改动的都放到第二部分就是了,这第二部分就是system.hv 和user.hv了,也就是一直提到的要放到磁盘上的注册表. 编译的时候PB会根据platform.reg和Common.reg中的标签判断哪些表项放到boot.hv中,这个标签就是;HIVE BOOT SECTION ;END BOOT SECTION,夹在这个标签之间的表项PB在编译的时候会把它们塞到boot.hv中去(boot.hv是二进制文件,要看里面到底放了哪些表项用一个老外写的工具吧,好像叫d_readvol.exe,到google上找得到的),其他的内容会分别塞到default.hv和user.hv中去,最后会把这三个hv文件统统塞到XIPKERNEL中去,这样WinCE在引导的第一阶段就把所有的hv扔到RAM中去了,然后打开boot.hv拿到必要的资料,这其中包括如何加载放置system.hv的磁盘的驱动,所以那些和加载这个磁盘相关的驱动要统统放到boot.hv中,比如FAT文件系统驱动, mspart分区驱动等等,这里有一点很重要就是假如你用binfs而且device.exe在NK.bin中,那么一定在第一阶段要保证binfs可用,否则这里就不可能为system.hv创造条件了。WinCE第一次启动时候磁盘上没有东东,这个时候WinCE会将内存中的default.hv和 user.hv复制到注册表BootVars指定的地方,default.hv往往会被重命名为system.hv,第二次启动会先检查磁盘上的hv是不是和内存中的一致,不一致就加载磁盘上的表项。

整个过程就是这样子,但要注意一点,HIVE注册表也是在内存中运行的,不同的是启动的时候会从磁盘上去读改动的表项,因为这样才能保证速度,所以你做的的注册表改动也是在内存中做的,这个时候如果你不掉用FlushRegister去将内存中的数值保存到磁盘上那么这些改动还是会丢失的。两种方法来避免丢失,一种是认为去调用FlushRegister,令一种就设置一个flag让 WinCE在每次改动注册表后自动Flush.

最后总结一下我到底做了哪些事情:
1)在PB中将HIVEbased Registers拉到项目的WorkSpaces中来。
2)把Platform.reg中的下列表项加到boot.hv中
3)Build Image了

附上我的注册表设置做参考:

;-----------------------------------------------------------------------------------------
;ALL these entries below will be add to boot.hv when hive register is enabled!
;HIVE BOOT SECTION

[HKEY_LOCAL_MACHINE/init/BootVars]
"SYSTEMHIVE"="Documents and Settings//system.hv"     ;system.hv会保存到/HDD/Documents and Settings/system.hv
;"PROFILEDIR"="Documents and Settings"   ;user.hv会保存到/HDD/Documents and Settings/default/user.hv
"Start DevMgr"=dword:1   ;这个说是启动device.exe,但是wince 5.0好像不用这个
"DefaultUser"="default"       ;咱们只有一个用户default,基本上就是决定user.hv的路径了
"Flags"=dword:3 ;这个应该是wince 5.0下决定在哪个阶段启动device.exe的表项
"RegistryFlags"=dword:1   ;这个就是设置注册表每次改动后自动flush到system.hv

;###########################################################################
;这个部分是binfs的注册表项,如果你不是用的binfs那么不用将它们拉到boot.hv中
[HKEY_LOCAL_MACHINE/System/StorageManager/AutoLoad/SMFlash]
"DriverPath"="Drivers//BlockDevice//SMFlash"
"LoadFlags"=dword:1
"MountFlags"=dword:11
"BootPhase"=dword:0
"Flags"=dword:1000
[HKEY_LOCAL_MACHINE/Drivers/BlockDevice/SMFlash]
"Prefix"="DSK"
"Dll"="BIBDrv.dll"
"Order"=dword:0
"Ioctl"=dword:4
"Profile"="SMFlash"
"FriendlyName"="Samsung Flash Driver"
"MountFlags"=dword:11
"BootPhase"=dword:0
"Flags"=dword:1000
; Bind BINFS to the block driver
[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/SMFlash]
"DefaultFileSystem"="BINFS"   ;binfs的路径为/BINFS
"PartitionDriver"="mspart.dll"
"AutoMount"=dword:1
"AutoPart"=dword:1
"MountFlags"=dword:11
"Folder"="ResidentFlash"
"Name"="Samsung Flash Disk"
"BootPhase"=dword:0
"Flags"=dword:1000
"MountHidden"=dword:0   ;有了这个你就可以在/BINFS目录下看到所有的NK.bin的东东了

;###########################################################################

;###########################################################################
;这个部分是设置保存system.hv的磁盘的驱动程序,每个人不一样了,但是大同小异
;我这里用的是PoketStroeII15的Flash驱动,system.hv保存在第一个Flash分区上
IF BSP_POCKETSTORE
[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/PocketStore]
  "Prefix"="DSK"
  "Dll"="ONDisk.dll"
  "Order"=dword:1
  "Profile"="PocketStore"
  "IClass"=multi_sz:"{A4E7EDDA-E575-4252-9D6B-4195D48BB865}"
  "BmlVolumeId"=dword:0 ; BML volume ID = 0
  "BmlPartitionId"=dword:8 ; BML parition ID = PARTITION_ID_FILESYSTEM
  "Index"=dword:2   
  "Flags"=dword:1000   ;这个flag指定这个驱动只在boot.hv中加载一次
[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/PocketStore]
  "DefaultFileSystem"="FATFS"
  "PartitionDriver"="mspart.dll"
  "AutoMount"=dword:1
  "AutoPart"=dword:1
  "AutoFormat"=dword:1
  "MountAsBootable"=dword:1   ;这个是wince 5.0下指定这个分区保存system.hv的关键
  "Folder"="HDD"
  "Name"="NAND Drive"
  "Ioctl"=dword:4

[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/PocketStore/FATFS]
  "EnableCacheWarm"=dword:0
 
ENDIF
;###########################################################################

;END HIVE BOOT SECTION

That's ALL,THANK U.
有问题请和我一起讨论,我喜欢寻根问底哈!

补充:
我的Flash划分了四个区,第一个区是放4k的只能以nor模式运行的bootloader,然后第二个区放置UT,第三个区放置XIPKERNEL和 BINFS,第四个区是将剩下的所有的扇区格式化为一个FAT分区作为文件系统,system.hv就是放置在最后一个分区中,在wince起来之后可以看到有个document and setting文件夹,里面的hv文件都是隐藏的。
我们用的是三星的ONENAND的flash,其实就是拥有4K NOR的NAND flash,我们的bootloader也分成三部份,第一部分bootloader主要是映射到0x00000000地址的一些跳转指令,这个部分会被烧写到flash的前4K里面,然后三星的ONENAND会自动复制前4K的数据到一个类似NOR的物理模块中,这个NOR模块支持CPU的直接寻址;第二部份叫IPL,它的功能是加载在NAND flash中的image或UT,然后在加载后跳转到其RAM中的入口去执行,因为CPU的数据线和地址线在这个时候还只能直接访问NOR flash,要访问NAND flash的话必须要有NAND的接口驱动,所以在IPL的部分会有NAND的接口驱动的代码,这就导致IPL的代码一般有几十到上百K,我们的 flash一个块是128K,前两部分一共占了两个块;第三个部分是UT,就是一些通用的工具,比如烧image,烧bootloader,格式化 flash等常用的维护和image升级工具,这个部分的数据最多包括了很多的驱动程序,体积也很大,有300K的样子。

最后我们的三个部分的bootloader一共占据了flash的头10个块(block),128K*10,但这三个部分在三星的flash的分区中是两个BML分区(三星的flash驱动PocetStoreII里面的概念,你就把它看成普通的磁盘分区好了),等下后面给的图示可以看到。

接下来的块会放置一个MBR,然后从11个块开始我们放置wince的image了,这个区是第三个BML分区,大小一般在40-200个块左右,因为wince的 image也就在4M-20M左右,这些划分分区的工作都是由上面提到的UT去做的,我也没有仔细看源代码,只是看到有BMLFormat之类的函数,其参数就是后面看到的图示。如果是binfs那么这个区会放置两个模块:XIPKERNEL和NK,NK的区域会被binfs的驱动识别并且加载成FAT分区的样子,可以在wince的资源管理器中看到的,具体是怎么被识别的还没有认真的搞懂。

大概算下来,前面所有的空间也就被占用20多M 的样子,剩下的空间了你可以随意利用了,分区的方法还是调用三星的flash驱动中的BMLFormat和STLformat,分区的参数定好了它们就会自动把分区建好,这部分的工作我们在BT中完成的。然后WinCE中仅仅需要将这些分区读出来并显示成磁盘就行了,这个就和SD、HDD的驱动相似了,参考楼顶的介于“IF BSP_POCKETSTORE”部分的注册表写法就行了。

BML分区的图示

gstXSRPartI.stPEntry[0].nID= PARTITION_ID_EBOOT;
gstXSRPartI.stPEntry[0].nAttr= BML_PI_ATTR_RO | BML_PI_ATTR_FROZEN;
gstXSRPartI.stPEntry[0].n1stVbn= EBOOT_START;
gstXSRPartI.stPEntry[0].nNumOfBlks = EBOOT_NUM;

gstXSRPartI.stPEntry[1].nID= PARTITION_ID_IPL;
gstXSRPartI.stPEntry[1].nAttr= BML_PI_ATTR_RO | BML_PI_ATTR_FROZEN;
gstXSRPartI.stPEntry[1].n1stVbn= IPL_START;
gstXSRPartI.stPEntry[1].nNumOfBlks = IPL_NUM;

gstXSRPartI.stPEntry[2].nID= PARTITION_ID_COPIEDOS;
gstXSRPartI.stPEntry[2].nAttr= BML_PI_ATTR_RO | BML_PI_ATTR_FROZEN;
gstXSRPartI.stPEntry[2].n1stVbn= OS_START;
gstXSRPartI.stPEntry[2].nNumOfBlks = OS_NUM;

gstXSRPartI.stPEntry[3].nID= PARTITION_ID_FILESYSTEM;
gstXSRPartI.stPEntry[3].nAttr= BML_PI_ATTR_RW;
gstXSRPartI.stPEntry[3].n1stVbn= FAT0_START;
gstXSRPartI.stPEntry[3].nNumOfBlks = FAT0_NUM;

/* Additional BML partition information for 2nd TFAT */
gstXSRPartI.stPEntry[4].nID= PARTITION_ID_FILESYSTEM1;
gstXSRPartI.stPEntry[4].nAttr= BML_PI_ATTR_RW;
Multi-Partition Application Note 2Samsung Confidential
gstXSRPartI.stPEntry[4].n1stVbn= FAT1_START;
gstXSRPartI.stPEntry[4].nNumOfBlks = FAT1_NUM;

gstXSRPartI.stPEntry[5].nID= PARTITION_ID_EBOOTCFG;
gstXSRPartI.stPEntry[5].nAttr= BML_PI_ATTR_RW;
gstXSRPartI.stPEntry[5].n1stVbn= EBOOTCFG_START;
gstXSRPartI.stPEntry[5].nNumOfBlks = EBOOTCFG_NUM;


本文引用须注明来源:http://blog.csdn.net/fredzeng

推荐:英文版

The binfs filesystem based WinCE image is divided into two part. Part I: XIPKERNEL region ; Part II: NK region. Part I hold the files that need to be copied to the RAM and excute in XIP mode in boot phase 0 , Part II hold the others system modules or files are needed but not nessessary and frenqencely invoked.

And while the HIVE based Registry is make up with boot.hv , user.hv and default.hv, these three files can also be divided into two part. Part I: boot.hv , Part II:user.hv and default.hv. Part I must be saved into the image part I which is XIPKERNEL region and Part II can saved in both XIPKERNEL or NK region.

UT will copy all the files in the XIPKERNEL include the boot.hv to the RAM at every cold boot time, at this time,the RAM region take up by the XIPKERNEL is action as ROM. The WinCE OS will start up from the special address in the RAM region after the UT finished the moving job and then the WinCE will init the CPU , MMC , interrupt and some other things are nessessary , include init the filesys.exe and Registry API. Because kernel is Registry dependent, boot.hv must be readed and parsed now.

Are there somethings else must be added into the XIPKERNEL?
Because the WinCE need the files such as device.exe which is save in the NK region default, so we must enable binfs and then the files in NK region can be available. These Registry entries descript how to configurate the binfs must be hold by boot.hv and the relatived DLL file must be saved in the XIPKERNEL region.
Some other module and files needed in this boot phase will be add automatically by the platform builder 5.0 thought the common.bib setting.

Are all the DLL files descripted in the boot.hv must be saved into the XIPKERNEL region?
The answer is no! Because binfs will waked in very early time and all the files in the NK region will be available after binfs is loaded normally, so the DLL files such as the flash stream driver ONDISK.DLL can also be saved in NK region and it will be available for WinCE when the time it is needed.

After finished the boot.hv boot phase and binfs is available, the WinCE OS will read the system hv Registry from XIPKERNEL or NK region, but before continue, you must load the FAT partition that will hold the system.hv first. So we must mention which disk partion will hold the system hive file and add all the relatived Registry entries into the boot.hv. The WinCE OS will parse the system hv and continue its boot up progress after the relatived FAT parttiion is available.

The boot sequence is like this:
BootLoader --> OEMinit --> Load boot.hv --> Init binfs --> Load default.hv from binfs --> Load device.exe from binfs --> device.exe load other drivers in default.hv --> Load user.hv --> Load explorer.exe

Implementation:

 

1. Change to the Hive-based Registry Component in PB5.0

    To enable Hive-based Registry on WinCE, firstly you need add the Hive-based Registry Catalog item(SYSGEN_FSREGHIVE) to your OS design. Once you add it, The Hive-based Registry component will replace RAM-based Registry automatically.

  

2. Add the following registry setting in the platform.reg

[HKEY_LOCAL_MACHINE/init/BootVars]

"SYSTEMHIVE"="Documents and Settings//system.hv" 

"PROFILEDIR"="Documents and Settings" 

"Start DevMgr"=dword:1   ;这个说是启动device.exe,但是wince 5.0好像不用这个

"DefaultUser"="default"     ;咱们只有一个用户default,基本上就是决定user.hv的路径了

"Flags"=dword:3 ;这个应该是wince 5.0下决定在哪个阶段启动device.exe的表项

"RegistryFlags"=dword:1   ;这个就是设置注册表每次改动后自动flush到system.hv

 

3. Add binfs driver into the boot phase 0

    You should let binfs is variable before the OS need the Registry entries saved in the default.hv and user.hv, so you need add all the binfs relatived Registry entries into boot.hv and add the binfs driver DLL file into XIPKERNEL region.

Verify the binfs Registry entries is sandwich between the labels:

;HIVE BOOT SECTION

;END HIVE BOOT SECTION

1)Add the following registry setting in the platform.reg:

;HIVE BOOT SECTION

;###########################################################################

;这个部分是binfs的注册表项,如果你不是用的binfs那么不用将它们拉到boot.hv中

[HKEY_LOCAL_MACHINE/System/StorageManager/AutoLoad/SMFlash]

"DriverPath"="Drivers//BlockDevice//SMFlash"

"LoadFlags"=dword:1

"MountFlags"=dword:11

"BootPhase"=dword:0

"Flags"=dword:1000 ; 这个flag标签让你的驱动不会重复加载,下面类似

[HKEY_LOCAL_MACHINE/Drivers/BlockDevice/SMFlash]

"Prefix"="DSK"

"Dll"="BIBDrv.dll"

"Order"=dword:0

"Ioctl"=dword:4

"Profile"="SMFlash"

"FriendlyName"="Samsung Flash Driver"

"MountFlags"=dword:11

"BootPhase"=dword:0

"Flags"=dword:1000

; Bind BINFS to the block driver

[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/SMFlash]

"DefaultFileSystem"="BINFS"   ;binfs的路径为/BINFS

"PartitionDriver"="mspart.dll"

"AutoMount"=dword:1

"AutoPart"=dword:1

"MountFlags"=dword:11

"Folder"="ResidentFlash"

"Name"="Samsung Flash Disk"

"BootPhase"=dword:0

"Flags"=dword:1000

"MountHidden"=dword:0 ;有了这个你就可以在/BINFS目录下看到所有的NK.bin的东东了

;###########################################################################

;END HIVE BOOT SECTION

2) In platform.bib add binfs DLL file into XIPKERNEL(If it has be added in common.bib , you can skip this step):

BIBDrv.dll     $(_FLATRELEASEDIR)/ BIBDrv.dll     $(XIPKERNEL)   SH

 

4. Start all drivers that control the media on which the system hive registry is stored in the first boot phase

We using PocketStoreII15 driver as the flash driver and we select the first FAT flash partitions to store the system hive Registry file. So we need add the following registry setting in the platform.reg:

;HIVE BOOT SECTION

;###########################################################################

;这个部分是设置保存system.hv的磁盘的驱动程序,每个人不一样了,但是大同小异

;这里用的是PoketStroeII15的Flash驱动,system.hv保存在第一个Flash分区上

IF BSP_POCKETSTORE

[HKEY_LOCAL_MACHINE/Drivers/BuiltIn/PocketStore]

  "Prefix"="DSK"

  "Dll"="ONDisk.dll"

  "Order"=dword:1

  "Profile"="PocketStore"

  "IClass"=multi_sz:"{A4E7EDDA-E575-4252-9D6B-4195D48BB865}"

  "BmlVolumeId"=dword:0 ; BML volume ID = 0

  "BmlPartitionId"=dword:8 ; BML parition ID = PARTITION_ID_FILESYSTEM

  "Index"=dword:2   

  "Flags"=dword:1000   ;这个flag指定这个驱动只在boot.hv中加载一次

[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/PocketStore]

  "DefaultFileSystem"="FATFS"

  "PartitionDriver"="mspart.dll"

  "AutoMount"=dword:1

  "AutoPart"=dword:1

  "AutoFormat"=dword:1

  "MountAsBootable"=dword:1   ;这个是wince 5.0下指定这个分区保存system.hv

  "Folder"="HDD"

  "Name"="NAND Drive"

  "Ioctl"=dword:4

 

[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/PocketStore/FATFS]

  "EnableCacheWarm"=dword:0

 

ENDIF

;###########################################################################

;END HIVE BOOT SECTION

 

5. Add the boot hive registry file in XIPKERNEL region

When Hive based Registry feature is setted in the PB5.0 , default.fdf will not be generated, so we must delete it from platform.bib and while we must add the boot.hv into the XIPKERNEL region. Default.hv and user.hv can saved in either NK region or XIPKERNEL region.

1) In platform.bib, delete the entry:

; default.fdf   $(_FLATRELEASEDIR)/default.fdf         $(XIPKERNEL)   SH

2) In platform.bib add boot.hv into XIPKERNEL:

boot.hv     $(_FLATRELEASEDIR)/boot.hv         $(XIPKERNEL)   SH

 

What will cause the system can not boot up normally?

1.             You didn’t add the binfs Registry entries into the boot.hv or relatived dll is not added into the XIPKERNEL.bin. I suggest you using a third-part tool named d_readvol.exe to convent the boot.hv from binary to understandable text format. You can find it by searching on google.

2.             You didn’t add the Registry of the FAT partition which will hold the persist Registry files into the boot.hv.

3.             You not mention which FAT partion to hold the persist Registry file. You should add "MountAsBootable"=dword:1 under the profile key entry of the disk partition.

4.             You not write some other Registry entries in right way.

本文引用须注明来源:http://blog.csdn.net/fredzeng


分享到:
来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
栏目导航->单片机学习
  • 电子应用基础
  • 电源技术
  • 无线传输技术
  • 信号处理
  • PCB设计
  • EDA技术
  • 单片机学习
  • 电子工具设备
  • 技术文章
  • 精彩拆解欣赏
  • 推荐资讯
    使用普通运放的仪表放大器
    使用普通运放的仪表放
    3V与5V混合系统中逻辑器接口问题
    3V与5V混合系统中逻辑
    数字PID控制及其改进算法的应用
    数字PID控制及其改进
    恶劣环境下的高性价比AD信号处理数据采集系统
    恶劣环境下的高性价比
    栏目更新
    栏目热门