X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs%2F.git;a=blobdiff_plain;f=wince%2Fynandif.c;h=2812549ac37b42dcf8e9a75faee77f4fc81a26a1;hp=5e982b502ae7755c9ca19047d5ccf5a5a3eeaadb;hb=f0494eb05c40ce19d74bedc92a020a743fbec08e;hpb=572f34a1cc2b7bddbd8d66f64be95ba158703a2e diff --git a/wince/ynandif.c b/wince/ynandif.c index 5e982b5..2812549 100644 --- a/wince/ynandif.c +++ b/wince/ynandif.c @@ -2,9 +2,10 @@ * YAFFS: Yet another FFS. A NAND-flash specific file system. * ynandif.c: NAND interface functions for the WinCE port of YAFFS. * - * Copyright (C) 2002 Trimble Navigation Ltd. + * Copyright (C) 2002-2003 Trimble Navigation Ltd. * * Created by Brad Beveridge + * Modified for CE 4.x by Steve Fogle * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -18,19 +19,31 @@ * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * $Id: ynandif.c,v 1.1 2002-11-08 07:30:00 charles Exp $ + * $Id: ynandif.c,v 1.2 2003-01-31 00:52:53 charles Exp $ */ -#include "ynandif.h" #include +#include +#include "ynandif.h" +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER < 400 +// For Win'CE 4.0 FSDMGR instead of direct access. HANDLE devHandle = 0; +#endif +//slf021220a end Cleanup block driver interface /* * Functions that need to be provided for YAFFS */ int ynandif_WriteChunkToNAND(yaffs_Device *dev, int chunkInNAND,const __u8 *data, yaffs_Spare *spare) { +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER >= 400 + if (dev) +#else if (devHandle) +#endif +//slf021220a end Cleanup block driver interface { ynandif_data writeData; int result; @@ -39,7 +52,13 @@ int ynandif_WriteChunkToNAND(yaffs_Device *dev, int chunkInNAND,const __u8 *data writeData.data = (__u8 *)data; writeData.spare = (char *)spare; +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER >= 400 + if (!FSDMGR_DiskIoControl((HDSK)dev->genericDevice, +#else if (!DeviceIoControl(devHandle, +#endif +//slf021220a end Cleanup block driver interface YNANDIF_WRITE, &writeData, sizeof(ynandif_data), @@ -57,7 +76,13 @@ int ynandif_WriteChunkToNAND(yaffs_Device *dev, int chunkInNAND,const __u8 *data int ynandif_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare) { +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER >= 400 + if (dev) +#else if (devHandle) +#endif +//slf021220a end Cleanup block driver interface { ynandif_data readData; int result; @@ -66,7 +91,13 @@ int ynandif_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaf readData.data = data; readData.spare = (char *)spare; +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER >= 400 + if (!FSDMGR_DiskIoControl((HDSK)dev->genericDevice, +#else if (!DeviceIoControl(devHandle, +#endif +//slf021220a end Cleanup block driver interface YNANDIF_READ, &readData, sizeof(ynandif_data), @@ -84,11 +115,23 @@ int ynandif_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaf int ynandif_EraseBlockInNAND(yaffs_Device *dev, int blockNumber) { +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER >= 400 + if (dev) +#else if (devHandle) +#endif +//slf021220a end Cleanup block driver interface { int result; - if (!DeviceIoControl(devHandle, +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER >= 400 + if (!FSDMGR_DiskIoControl((HDSK)dev->genericDevice, +#else + if (!DeviceIoControl(devHandle, +#endif +//slf021220a end Cleanup block driver interface YNANDIF_ERASE, &blockNumber, sizeof(int), @@ -108,6 +151,10 @@ int ynandif_EraseBlockInNAND(yaffs_Device *dev, int blockNumber) int ynandif_InitialiseNAND(yaffs_Device *dev) { + +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER < 400 +// For Win'CE 4.0 FSDMGR instead of direct access. RETAILMSG(1, (L"ynandif_InitialiseNAND\r\n")); devHandle = CreateFile(L"YND1:", GENERIC_READ|GENERIC_WRITE, @@ -117,13 +164,30 @@ int ynandif_InitialiseNAND(yaffs_Device *dev) 0, 0); - if (!devHandle) +//slf021220d Begin CreateFile returns INVALID_HANDLE_VALUE not null fix. + if (INVALID_HANDLE_VALUE == devHandle) + { + devHandle = NULL; return 0; + } +// if (!devHandle) +// return 0; +//slf021220d end CreateFile returns INVALID_HANDLE_VALUE not null fix. RETAILMSG(1, (L"devhandle open\r\n")); +#endif +//slf021220a Begin Cleanup block driver interface RETAILMSG(1, (L"DeviceIo INIT\r\n")); - if (!DeviceIoControl(devHandle, +//slf021220a Begin Cleanup block driver interface + if (dev) + { +#if _WINCEOSVER >= 400 + if (!FSDMGR_DiskIoControl((HDSK)dev->genericDevice, +#else + if (!DeviceIoControl(devHandle, +#endif +//slf021220a end Cleanup block driver interface YNANDIF_INIT, NULL, 0, @@ -131,12 +195,17 @@ int ynandif_InitialiseNAND(yaffs_Device *dev) 0, NULL, NULL)) - return 0; - + return 0; +//slf021220a Begin Cleanup block driver interface + } +//slf021220a end Cleanup block driver interface if (dev) { - int nBlocks = ynandif_GetChipSize(0xFF) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); +//slf021220a Begin Cleanup block driver interface +// int nBlocks = ynandif_GetChipSize(0xFF) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); + int nBlocks = ynandif_GetChipSize(dev,0xFF) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); +//slf021220a end Cleanup block driver interface dev->startBlock = 1; // Don't use block 0 dev->endBlock = nBlocks - 1; } @@ -144,10 +213,27 @@ int ynandif_InitialiseNAND(yaffs_Device *dev) return 1; } +//slf021220a Begin Cleanup block driver interface +void ynandif_DeinitialiseNAND(yaffs_Device *dev) +{ + RETAILMSG(1, (L"ynandif_DeinitialiseNAND\r\n")); +#if _WINCEOSVER < 400 + if (devHandle) + { + CloseHandle(devHandle); + devHandle = NULL; + } +#endif +} +//slf021220a end Cleanup block driver interface + int ynandif_EraseAllBlocks(yaffs_Device *dev) { int numBlocks, counter; - numBlocks = ynandif_GetChipSize(0xFF) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); +//slf021220a Begin Cleanup block driver interface +// numBlocks = ynandif_GetChipSize(0xFF) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); + numBlocks = ynandif_GetChipSize(dev,0xFF) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK); +//slf021220a end Cleanup block driver interface for (counter = 0; counter < numBlocks; counter++) { ynandif_EraseBlockInNAND(dev, counter); @@ -155,14 +241,29 @@ int ynandif_EraseAllBlocks(yaffs_Device *dev) return YAFFS_OK; } -int ynandif_GetChipSize(unsigned char chipNumber) +//slf021220a Begin Cleanup block driver interface +//int ynandif_GetChipSize(unsigned char chipNumber) +int ynandif_GetChipSize(yaffs_Device *dev, unsigned char chipNumber) +//slf021220a end Cleanup block driver interface { int ret = 0; RETAILMSG(1, (L"DeviceIo GETSIZE\r\n")); +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER >= 400 + if (dev) +#else if (devHandle) +#endif +//slf021220a end Cleanup block driver interface { RETAILMSG(1, (L"DeviceIo GETSIZE - getting ret\r\n")); +//slf021220a Begin Cleanup block driver interface +#if _WINCEOSVER >= 400 + FSDMGR_DiskIoControl((HDSK)dev->genericDevice, +#else DeviceIoControl(devHandle, +#endif +//slf021220a end Cleanup block driver interface YNANDIF_GETSIZE, NULL, 0,