加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

再次学习flash驱动——挖掘不能发现nand flash盘符的原因

发布时间:2020-12-15 17:53:15 所属栏目:百科 来源:网络整理
导读:http://www.voidcn.com/article/p-fjfmzkvj-rz.html? (推荐,gooogleman) 作者:wogoyixikexie@gliet?2008-12-05 ??????????昨晚看以前优龙的老4.2BSP的flash驱动,发现和我现在不能发现这个盘符的驱动有些差别。下面这个函数是flash驱动加载的时候要执行的

http://www.voidcn.com/article/p-fjfmzkvj-rz.html? (推荐,gooogleman)

作者:wogoyixikexie@gliet?2008-12-05

??????????昨晚看以前优龙的老4.2BSP的flash驱动,发现和我现在不能发现这个盘符的驱动有些差别。下面这个函数是flash驱动加载的时候要执行的,作用是检测flash有没有坏块。我发现我在新的flash驱动中犯了严重的错误。等下会在代码中说明。

  1. DWORD?FMD_GetBlockStatus(BLOCK_ID?blockID)
  2. {
  3. ????SECTOR_ADDR?Sector?=?(blockID?*?NAND_PAGE_CNT);
  4. ????SectorInfo?SI;
  5. ????DWORD?dwResult?=?0;
  6. ????
  7. //我在新的flash驱动根本没有这句关键代码,这句的作用是把NK和bootloader
  8. //占用的flash?的block标记为坏块,这样起到保护的作用
  9. //其实这个并不完整,因为这样会检测超出最大block数目正确的做法是
  10. //if(blockID<0x280||blockID>flash总block数目-1)//这样就不会越界了。
  11. ????if(blockID<0x280)//
  12. ????????return?BLOCK_STATUS_BAD;
  13. ????if?(IsBlockBad(blockID))
  14. ????????return?BLOCK_STATUS_BAD;
  15. if?(!FMD_ReadSector(Sector,?NULL,?&SI,?1))?
  16. return?BLOCK_STATUS_UNKNOWN;
  17. if?(!(SI.bOEMReserved?&?OEM_BLOCK_READONLY))??
  18. ????????dwResult?|=?BLOCK_STATUS_READONLY;
  19. if?(!(SI.bOEMReserved?&?OEM_BLOCK_RESERVED))??
  20. ????????dwResult?|=?BLOCK_STATUS_RESERVED;
  21. return(dwResult);
  22. }

?

我还发现一些注册表的问题。

这是4.2可发现盘符的BSP的flash注册表部分

[HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/FlashDrv]
  • ??"DriverPath"="Drivers//BuiltIn//FlashDrv"
  • ??"DefaultFileSystem"="FATFS"//这在失败哪里是没有的,居然是binfs不可思议。
  • ??"PartitionDriver"="mspart.dll"
  • ??"AutoMount"=dword:1
  • ??"AutoPart"=dword:1
  • ??"AutoFormat"=dword:1//这个也没有,这个会对没有格式化过的flash自动格式化。
  • ??"Folder"="nand?flash"
  • ??"Name"="Microsoft?Flash?Disk"
  • ??"BootPhase"=dword:0
  • ??"Flags"=dword:1000//这个有什么用?
  • ??"Ioctl"=dword:4//这个有什么用?
  • ?

    少了那几个东西,对于使用优龙的BIOS来说,是不能发现盘符的。

    ?

    在这里重新回到优龙ADS bootloader的话题,我仔细看过,里面的确没有binfs以及FAT分区功能。

    那经过上面注册表之后为什么就实现分区了呢?

    ?

    ——————查看CSDN老帖,有:

    有几个问题求教,望高手们赐教: ??
    ? 1 ? 用CreatePartition函数会自动生成MBR和分区表吗? ??
    ? 2 ? 我用DeviceIoControl函数时,好象只能对某个分区进行读写。我想用CreateFile,第一个参数应该指定一个物理设备名,对于Nand ? Flash应该指定为什么字符串啊?

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

    是可以生成mbr,以及mbr里的partition ? table的。 ??
    ? ??
    ? 参见C:/WINCE420/PRIVATE/WINCEOS/COREOS/STORAGE/DOSPART/part.cpp代码

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

    C:/WINCE500/PRIVATE/WINCEOS/COREOS/STORAGE/DOSPART/helper.cpp(747):BOOL?WriteMBR(DriverState?*state,?SECTORNUM?snSectorNum,?SECTORNUM?snNumSectors,?BYTE?fileSysType,?BOOL?bCreateMBR)?
  • //重新创建MBR,这个不知道在哪里被调用了,但是可以解释优龙的问题。
  • /*****************************************************************************?
  • *??WriteMBR?-?adds?a?partition?entry?to?the?master?boot?record.?The?partition?
  • *??table?is?traversed?to?find?the?placement?for?this?partition.??Entries?within?
  • *??the?MBR?are?sorted?by?the?start?sector.?
  • *?
  • *??Input:??state?-?structure?for?this?store?
  • *??????????snSectorNum?-?start?sector?number?for?this?partition?
  • *??????????snNumSectors?-?number?of?sectors?in?this?partition?
  • *??????????fileSysType?-?partition?type?
  • *??????????bCreateMBR?-?TRUE?to?generate?a?new?MBR,?FALSE?to?add?to?the?
  • *??????????????????????existing?MBR?
  • *?
  • *??Output:?none?
  • *??Return:?TRUE?if?successfully?written,?FALSE?for?failures,?ERROR_DISK_FULL?
  • *??????????will?be?set?if?no?room?in?the?MBR?
  • *****************************************************************************/?
  • BOOL?WriteMBR(DriverState?*state,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px"> {?
  • ????PBYTE??????buffer?=?NULL;?
  • ????PPARTENTRY??tmpbuffer,?tmpbuffer1;?
  • ????BOOL????????bResult;?
  • int????????i,?partIndex,?partNum?=?-1;?
  • ????//?don't?create?the?MBR,?it?already?exists?so?use?it? 这个要特别注意,检测是否已经分区,没有就重新写入MBR
  • if?(!bCreateMBR)?
  • ????{?
  • ????????bResult?=?ReadSectors?(state,?0,?1,?&buffer);?
  • if?(!bResult)?
  • ????????????return?FALSE;?
  • for?(i?=?0,?partIndex?=?0,?tmpbuffer?=?(PPARTENTRY)(buffer?+?PARTTABLE_OFFSET);?i?<?4;?i++,?tmpbuffer++)?
  • ????????{?
  • if?(tmpbuffer->Part_TotalSectors?==?0)?
  • ????????????{?
  • ????????????????partNum?=?i;?
  • ????????????????break;?
  • ????????????}?
  • ????????????//?find?the?index?of?the?partition?located?just?before?this?one?
  • ????????????if?(snSectorNum?>?tmpbuffer->Part_StartSector)?
  • ????????????????partIndex?=?i?+?1;?
  • ????????}?
  • if?(partNum?==?-1)?
  • ????????{?
  • ????????????//?we?return?this?error?code?so?the?caller?can?tell?that?there's?no?room?in?the?MBR?
  • ????????????LocalFree(buffer);?
  • ????????????SetLastError(ERROR_DISK_FULL);?
  • ????????//?these?indexes?would?be?equal?if?we?are?adding?to?the?end?of?the?table?
  • if?(partIndex?!=?partNum)?
  • //?this?partition?needs?to?be?added?in?the?order?that?it?appears?on?the?disk?-?so?this?may?involve?
  • //??shifting?some?of?the?existing?partition?entries?to?open?up?the?partition?entry?where?this?belongs?
  • ????????????tmpbuffer?=?(PPARTENTRY)(buffer?+?PARTTABLE_OFFSET?+?(partNum?*?sizeof(PARTENTRY)));?
  • ????????????tmpbuffer1?=?(PPARTENTRY)(buffer?+?PARTTABLE_OFFSET?+?((partNum?-1)?*?sizeof(PARTENTRY)));?
  • for?(;?partNum?>?partIndex;?partNum--)?
  • ????????????{?
  • ????????????????memcpy(tmpbuffer,?tmpbuffer1,?sizeof(PARTENTRY));?
  • ????????????????tmpbuffer--;?
  • ????????????????tmpbuffer1--;?
  • ????}?
  • else?
  • ????{?
  • ????????buffer?=?(PBYTE)LocalAlloc(LMEM_ZEROINIT,?state->diskInfo.di_bytes_per_sect);?
  • if?(!buffer)?
  • return?FALSE;?
  • //?add?header?and?trailer?info?to?the?MBR?
  • ????????*(WORD?*)(buffer?+?BOOT_SIGNATURE)?=?BOOTSECTRAILSIGH;?
  • ????????buffer[0]?=?0xE9;?
  • ????????buffer[1]?=?0xfd;?
  • ????????buffer[2]?=?0xff;?
  • ????????partNum?=?0;?
  • ????}?
  • ????tmpbuffer?=?(PPARTENTRY)(buffer?+?PARTTABLE_OFFSET?+?partNum?*?(int)//?create?the?partition?entry?for?the?extended?partition?
  • ????bResult?=?ConvertLBAtoCHS?(state,?snSectorNum,?&tmpbuffer->Part_FirstTrack,?&tmpbuffer->Part_FirstHead,?&tmpbuffer->Part_FirstSector);?
  • ????tmpbuffer->Part_FileSystem?=?fileSysType;?
  • ????tmpbuffer->Part_StartSector?=?(DWORD)snSectorNum;?
  • ????tmpbuffer->Part_TotalSectors?=?(DWORD)snNumSectors;?
  • ????bResult?=?WriteSectors(state,?buffer);?
  • ????LocalFree(buffer);?
  • return?bResult;?
  • }?
  • 如果eboot不格式化FAT分区,就要在flash驱动中把NK所占block标记为坏块。才行。?

    但是如何让系统自动格式化位binfs我就不知道怎么搞了。这个不行的。因为当时已经存在NK了,不能再格式化了。?
    哈哈,终于弄明白优龙为何不支持binfs了。?
    哈哈,现在如果在ADS增加binfs格式化那么就好办了。

    ?

    转载请标明:作者wogoyixikexie@gliet.桂林电子科技大学一系科协。如有错误,希望能够留言指出。

    (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读