阅读:2863回复:2
请做过CE 6.0 R2 新的nandflash driver的朋友帮忙
有没有用CE 6.0 R2, nandflash 新的驱动模型(MDD+PDD)做driver的兄弟?微软为新的nandflash 提供了新的分区,MDD的dll,没有源代码.我从外部用DeviceIoControl访问nandflash总是失败.
附件是一个应用App, 用来测试flash接口的,总是失败; 我这里nand driver 写好后发现IOCTL_DISK_READ 总是失败,还没有找到原因...只是说DeviceIoControl的参数无效,但是我仔细检查参数,没有发现错误,同样的参数传给以前用FAL+FMD的和SD都没有问题... #include "stdafx.h" #include <windows.h> #include <diskio.h> #include <storemgr.h> #include <winioctl.h> #include <pkfuncs.h> #define PRX_DEVICE_NAME_LEN 256 static HANDLE g_hStore=INVALID_HANDLE_VALUE; static DISK_INFO g_diDiskInfo; static TCHAR g_szDeviceName[PRX_DEVICE_NAME_LEN]; static BOOL g_fLegacyBlockDriver = FALSE; // IOCTL_DISK_Xxx or DISK_IOCTL_Xxx #define DUMP_DISKINFO(di) { \ RETAILMSG(1, (_T("%s bytes per sector = %u\r\n"), g_szDeviceName, di.di_bytes_per_sect)); \ RETAILMSG(1, (_T("%s cylinders = %u\r\n"), g_szDeviceName, di.di_cylinders)); \ RETAILMSG(1, (_T("%s flags = 0x%x\r\n"), g_szDeviceName, di.di_flags)); \ RETAILMSG(1, (_T("%s heads = %u\r\n"), g_szDeviceName, di.di_heads)); \ RETAILMSG(1, (_T("%s sectors = %u\r\n"), g_szDeviceName, di.di_sectors)); \ RETAILMSG(1, (_T("%s total sectors = %u\r\n"), g_szDeviceName, di.di_total_sectors)); \ } #define USESTORE 1 int _tmain(int argc, TCHAR *argv[], TCHAR *envp[]) { DWORD dwError; BOOL fResult; DWORD dwBytesReturned; //open store of nandflash _tcscpy(g_szDeviceName,_T("DSK1:")); //-->DSK1: for nand, DSK2 for SD #if USESTORE g_hStore = OpenStore(g_szDeviceName); #else g_hStore = CreateFile(g_szDeviceName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,OPEN_EXISTING, 0,NULL); #endif if ((g_hStore == NULL) || (g_hStore == INVALID_HANDLE_VALUE)) { dwError = GetLastError(); RETAILMSG(1, (_T( "Failed to open store %s; error = %u\r\n" ), g_szDeviceName, dwError)); goto EXIT; } RETAILMSG(1, (_T("Opened store %s\r\n"), g_szDeviceName)); //read disk info RETAILMSG(1,(_T("IOCTL_DISK_GETINFO =0x%X\r\n"),IOCTL_DISK_GETINFO)); // read disk information fResult = DeviceIoControl( g_hStore, IOCTL_DISK_GETINFO, NULL, 0, &g_diDiskInfo, sizeof(g_diDiskInfo), &dwBytesReturned, NULL); if (!fResult) { RETAILMSG(1,(_T("IOCTL_DISK_GETINFO Failed,GetLastError:0x%X\r\n"), GetLastError())); goto EXIT; } RETAILMSG(1, (_T("Get disk Info success %s\r\n"), g_szDeviceName)); DUMP_DISKINFO(g_diDiskInfo); //read sector PBYTE pBuffer = (PBYTE)LocalAlloc(LPTR, g_diDiskInfo.di_bytes_per_sect); if (pBuffer != NULL) { SG_REQ sgReq; DWORD dwBytesReturned; sgReq.sr_start = 1; sgReq.sr_num_sec = 1; sgReq.sr_num_sg = 1; sgReq.sr_status = 0; sgReq.sr_callback = NULL; sgReq.sr_sglist[0].sb_buf = pBuffer; sgReq.sr_sglist[0].sb_len = g_diDiskInfo.di_bytes_per_sect; BOOL bResult = DeviceIoControl(g_hStore, IOCTL_DISK_READ, &sgReq, sizeof(SG_REQ), NULL, 0, &dwBytesReturned, NULL); if (!bResult) { RETAILMSG(1,(_T("IOCTL_DISK_READ Failed:0x%X\r\n"),GetLastError())); goto EXIT; } RETAILMSG(1,(_T("IOCTL_DISK_READ success...\r\n"))); } EXIT: if (pBuffer!=NULL) { LocalFree(pBuffer); } #if USESTORE #else CloseHandle(g_hStore); #endif return 0; } 我的结果: **************************** Debug info: Opened store DSK1: IOCTL_DISK_GETINFO =0x71C00 Get disk Info success DSK1: DSK1: bytes per sector = 2048 DSK1: cylinders = 884 DSK1: flags = 0x8 DSK1: heads = 1 DSK1: sectors = 128 DSK1: total sectors = 113152 !!DecodeAPI: invalid handle! (h = 0297000a, iApiSet = 00000002 'NONE', pActvProc ->dwId = 0297000a) ObjectCall: returning 8037cce4 IOCTL_DISK_READ Failed:0x57 ************************************ |
|
|
沙发#
发布于:2008-05-20 10:11
我试着用creatfile 来获得handle,而且msdn里面关于DeviceIoControl的第一个参数确实要求用CreatFile来获得,但是这样获得handle,虽然可以将请求传入,但在pdd收到参数还是我传入的参数,MDD没有进行任何处理...比如扇区映射等等...连IOCode都没有转化成flash专用的IOCode...
|
|
板凳#
发布于:2010-01-08 16:13
忘了来结贴,
MDD 必须用 partion handle 替代 store handle 才行... |
|