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

nand flash无盘符问题

发布时间:2020-12-15 07:14:31 所属栏目:百科 来源:网络整理
导读:作者:wogoyixikexie@gliet?2008-12-05 ??????????昨晚看以前优龙的老4.2BSP的flash驱动,发现和我现在不能发现这个盘符的驱动有些差别。下面这个函数是flash驱动加载的时候要执行的,作用是检测flash有没有坏块。我发现我在新的flash驱动中犯了严重的错误。

作者: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注册表部分

  1. [HKEY_LOCAL_MACHINE/System/StorageManager/Profiles/FlashDrv]
  2. ??"DriverPath"="Drivers//BuiltIn//FlashDrv"
  3. ??"DefaultFileSystem"="FATFS"//这在失败哪里是没有的,居然是binfs不可思议。
  4. ??"PartitionDriver"="mspart.dll"
  5. ??"AutoMount"=dword:1
  6. ??"AutoPart"=dword:1
  7. ??"AutoFormat"=dword:1//这个也没有,这个会对没有格式化过的flash自动格式化。
  8. ??"Folder"="nand?flash"
  9. ??"Name"="Microsoft?Flash?Disk"
  10. ??"BootPhase"=dword:0
  11. ??"Flags"=dword:1000//这个有什么用?
  12. ??"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代码

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

  1. C:/WINCE500/PRIVATE/WINCEOS/COREOS/STORAGE/DOSPART/helper.cpp(747):BOOL?WriteMBR(DriverState?*state,?SECTORNUM?snSectorNum,?SECTORNUM?snNumSectors,?BYTE?fileSysType,?BOOL?bCreateMBR)?
  2. //重新创建MBR,这个不知道在哪里被调用了,但是可以解释优龙的问题。
  3. /*****************************************************************************?
  4. *??WriteMBR?-?adds?a?partition?entry?to?the?master?boot?record.?The?partition?
  5. *??table?is?traversed?to?find?the?placement?for?this?partition.??Entries?within?
  6. *??the?MBR?are?sorted?by?the?start?sector.?
  7. *?
  8. *??Input:??state?-?structure?for?this?store?
  9. *??????????snSectorNum?-?start?sector?number?for?this?partition?
  10. *??????????snNumSectors?-?number?of?sectors?in?this?partition?
  11. *??????????fileSysType?-?partition?type?
  12. *??????????bCreateMBR?-?TRUE?to?generate?a?new?MBR,?FALSE?to?add?to?the?
  13. *??????????????????????existing?MBR?
  14. *?
  15. *??Output:?none?
  16. *?
  17. *??Return:?TRUE?if?successfully?written,?FALSE?for?failures,?ERROR_DISK_FULL?
  18. *??????????will?be?set?if?no?room?in?the?MBR?
  19. *?
  20. *****************************************************************************/?
  21. BOOL?WriteMBR(DriverState?*state,?BOOL?bCreateMBR)?
  22. {?
  23. ????PBYTE??????buffer?=?NULL;?
  24. ????PPARTENTRY??tmpbuffer,?tmpbuffer1;?
  25. ????BOOL????????bResult;?
  26. ????int????????i,?partIndex,?partNum?=?-1;?
  27. ????//?don't?create?the?MBR,?it?already?exists?so?use?it? 这个要特别注意,检测是否已经分区,没有就重新写入MBR
  28. ????if?(!bCreateMBR)?
  29. ????{?
  30. ????????bResult?=?ReadSectors?(state,?0,?1,?&buffer);?
  31. ????????if?(!bResult)?
  32. ????????????return?FALSE;?
  33. ????????for?(i?=?0,?partIndex?=?0,?tmpbuffer?=?(PPARTENTRY)(buffer?+?PARTTABLE_OFFSET);?i?<?4;?i++,?tmpbuffer++)?
  34. ????????{?
  35. ????????????if?(tmpbuffer->Part_TotalSectors?==?0)?
  36. ????????????{?
  37. ????????????????partNum?=?i;?
  38. ????????????????break;?
  39. ????????????}?
  40. ????????????//?find?the?index?of?the?partition?located?just?before?this?one?
  41. ????????????if?(snSectorNum?>?tmpbuffer->Part_StartSector)?
  42. ????????????????partIndex?=?i?+?1;?
  43. ????????}?
  44. ????????if?(partNum?==?-1)?
  45. ????????{?
  46. ????????????//?we?return?this?error?code?so?the?caller?can?tell?that?there's?no?room?in?the?MBR?
  47. ????????????LocalFree(buffer);?
  48. ????????????SetLastError(ERROR_DISK_FULL);?
  49. ????????????return?FALSE;?
  50. ????????}?
  51. ????????//?these?indexes?would?be?equal?if?we?are?adding?to?the?end?of?the?table?
  52. ????????if?(partIndex?!=?partNum)?
  53. ????????{?
  54. ????????????//?this?partition?needs?to?be?added?in?the?order?that?it?appears?on?the?disk?-?so?this?may?involve?
  55. ????????????//??shifting?some?of?the?existing?partition?entries?to?open?up?the?partition?entry?where?this?belongs?
  56. ????????????tmpbuffer?=?(PPARTENTRY)(buffer?+?PARTTABLE_OFFSET?+?(partNum?*?sizeof(PARTENTRY)));?
  57. ????????????tmpbuffer1?=?(PPARTENTRY)(buffer?+?PARTTABLE_OFFSET?+?((partNum?-1)?*?sizeof(PARTENTRY)));?
  58. ????????????for?(;?partNum?>?partIndex;?partNum--)?
  59. ????????????{?
  60. ????????????????memcpy(tmpbuffer,?tmpbuffer1,?sizeof(PARTENTRY));?
  61. ????????????????tmpbuffer--;?
  62. ????????????????tmpbuffer1--;?
  63. ????????????}?
  64. ????????}?
  65. ????}?
  66. ????else?
  67. ????{?
  68. ????????buffer?=?(PBYTE)LocalAlloc(LMEM_ZEROINIT,?state->diskInfo.di_bytes_per_sect);?
  69. ????????if?(!buffer)?
  70. ????????????return?FALSE;?
  71. ????????//?add?header?and?trailer?info?to?the?MBR?
  72. ????????*(WORD?*)(buffer?+?BOOT_SIGNATURE)?=?BOOTSECTRAILSIGH;?
  73. ????????buffer[0]?=?0xE9;?
  74. ????????buffer[1]?=?0xfd;?
  75. ????????buffer[2]?=?0xff;?
  76. ????????partNum?=?0;?
  77. ????}?
  78. ????tmpbuffer?=?(PPARTENTRY)(buffer?+?PARTTABLE_OFFSET?+?partNum?*?(int)sizeof(PARTENTRY));?
  79. ????//?create?the?partition?entry?for?the?extended?partition?
  80. ????bResult?=?ConvertLBAtoCHS?(state,?snSectorNum,?&tmpbuffer->Part_FirstTrack,?&tmpbuffer->Part_FirstHead,?&tmpbuffer->Part_FirstSector);?
  81. ????tmpbuffer->Part_FileSystem?=?fileSysType;?
  82. ????tmpbuffer->Part_StartSector?=?(DWORD)snSectorNum;?
  83. ????tmpbuffer->Part_TotalSectors?=?(DWORD)snNumSectors;?
  84. ????bResult?=?ConvertLBAtoCHS?(state,?tmpbuffer->Part_StartSector?+?tmpbuffer->Part_TotalSectors?-1,?&tmpbuffer->Part_LastTrack,?&tmpbuffer->Part_LastHead,?&tmpbuffer->Part_LastSector);?
  85. ????bResult?=?WriteSectors(state,?buffer);?
  86. ????LocalFree(buffer);?
  87. ????return?bResult;?
  88. }?

如果eboot不格式化FAT分区,就要在flash驱动中把NK所占block标记为坏块。才行。? 但是如何让系统自动格式化位binfs我就不知道怎么搞了。这个不行的。因为当时已经存在NK了,不能再格式化了。? 哈哈,终于弄明白优龙为何不支持binfs了。? 哈哈,现在如果在ADS增加binfs格式化那么就好办了。

(编辑:李大同)

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

    推荐文章
      热点阅读