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

如果eboot不格式化FAT分区,就要在flash驱动中把NK所占block标记为坏块。才行。 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值