作者:wogoyixikexie@gliet 2008-12-05
昨晚看以前优龙的老4.2BSP的flash驱动,发现和我现在不能发现这个盘符的驱动有些差别。下面这个函数是flash驱动加载的时候要执行的,作用是检测flash有没有坏块。我发现我在新的flash驱动中犯了严重的错误。等下会在代码中说明。
- DWORD FMD_GetBlockStatus(BLOCK_ID blockID)
- {
- SECTOR_ADDR Sector = (blockID * NAND_PAGE_CNT);
- SectorInfo SI;
- DWORD dwResult = 0;
- //我在新的flash驱动根本没有这句关键代码,这句的作用是把NK和bootloader
- //占用的flash 的block标记为坏块,这样起到保护的作用
- //其实这个并不完整,因为这样会检测超出最大block数目正确的做法是
- //if(blockID<0x280||blockID>flash总block数目-1)//这样就不会越界了。
- if(blockID<0x280)//
- return BLOCK_STATUS_BAD;
- if (IsBlockBad(blockID))
- return BLOCK_STATUS_BAD;
- if (!FMD_ReadSector(Sector, NULL, &SI, 1))
- return BLOCK_STATUS_UNKNOWN;
- if (!(SI.bOEMReserved & OEM_BLOCK_READONLY))
- dwResult |= BLOCK_STATUS_READONLY;
- if (!(SI.bOEMReserved & OEM_BLOCK_RESERVED))
- dwResult |= BLOCK_STATUS_RESERVED;
- return(dwResult);
- }
我还发现一些注册表的问题。
这是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, SECTORNUM snSectorNum, SECTORNUM snNumSectors, BYTE fileSysType, BOOL bCreateMBR)
- {
- 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);
- return FALSE;
- }
- // 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)sizeof(PARTENTRY));
- // 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 = ConvertLBAtoCHS (state, tmpbuffer->Part_StartSector + tmpbuffer->Part_TotalSectors -1, &tmpbuffer->Part_LastTrack, &tmpbuffer->Part_LastHead, &tmpbuffer->Part_LastSector);
- bResult = WriteSectors(state, 0, 1, buffer);
- LocalFree(buffer);
- return bResult;
- }
如果eboot不格式化FAT分区,就要在flash驱动中把NK所占block标记为坏块。才行。
但是如何让系统自动格式化位binfs我就不知道怎么搞了。这个不行的。因为当时已经存在NK了,不能再格式化了。
哈哈,终于弄明白优龙为何不支持binfs了。
哈哈,现在如果在ADS增加binfs格式化那么就好办了。