2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
\r
3 * ynandif.c: NAND interface functions for the WinCE port of YAFFS.
\r
5 * Copyright (C) 2002 Trimble Navigation Ltd.
\r
7 * Created by Brad Beveridge <brad.beveridge@trimble.co.nz>
\r
9 * This program is free software; you can redistribute it and/or modify
\r
10 * it under the terms of the GNU General Public License version 2 as
\r
11 * published by the Free Software Foundation.
\r
13 * This program is distributed in the hope that it will be useful,
\r
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
16 * General Public License for more details. You should have received a
\r
17 * copy of the GNU General Public License along with this program;
\r
18 * if not, write to the Free Software Foundation, Inc.,
\r
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
21 * $Id: ynandif.c,v 1.1 2002-11-08 07:30:00 charles Exp $
\r
23 #include "ynandif.h"
\r
24 #include <windows.h>
\r
26 HANDLE devHandle = 0;
\r
29 * Functions that need to be provided for YAFFS
\r
31 int ynandif_WriteChunkToNAND(yaffs_Device *dev, int chunkInNAND,const __u8 *data, yaffs_Spare *spare)
\r
35 ynandif_data writeData;
\r
38 writeData.chunk = chunkInNAND;
\r
39 writeData.data = (__u8 *)data;
\r
40 writeData.spare = (char *)spare;
\r
42 if (!DeviceIoControl(devHandle,
\r
45 sizeof(ynandif_data),
\r
58 int ynandif_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare)
\r
62 ynandif_data readData;
\r
65 readData.chunk = chunkInNAND;
\r
66 readData.data = data;
\r
67 readData.spare = (char *)spare;
\r
69 if (!DeviceIoControl(devHandle,
\r
72 sizeof(ynandif_data),
\r
85 int ynandif_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
\r
91 if (!DeviceIoControl(devHandle,
\r
104 // if we return YAFFS_FAIL, then yaffs will retire this block & mark it bad, not exactly
\r
105 // what we want to do by default.
\r
109 int ynandif_InitialiseNAND(yaffs_Device *dev)
\r
111 RETAILMSG(1, (L"ynandif_InitialiseNAND\r\n"));
\r
112 devHandle = CreateFile(L"YND1:",
\r
113 GENERIC_READ|GENERIC_WRITE,
\r
123 RETAILMSG(1, (L"devhandle open\r\n"));
\r
125 RETAILMSG(1, (L"DeviceIo INIT\r\n"));
\r
126 if (!DeviceIoControl(devHandle,
\r
139 int nBlocks = ynandif_GetChipSize(0xFF) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
\r
140 dev->startBlock = 1; // Don't use block 0
\r
141 dev->endBlock = nBlocks - 1;
\r
147 int ynandif_EraseAllBlocks(yaffs_Device *dev)
\r
149 int numBlocks, counter;
\r
150 numBlocks = ynandif_GetChipSize(0xFF) / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
\r
151 for (counter = 0; counter < numBlocks; counter++)
\r
153 ynandif_EraseBlockInNAND(dev, counter);
\r
158 int ynandif_GetChipSize(unsigned char chipNumber)
\r
161 RETAILMSG(1, (L"DeviceIo GETSIZE\r\n"));
\r
164 RETAILMSG(1, (L"DeviceIo GETSIZE - getting ret\r\n"));
\r
165 DeviceIoControl(devHandle,
\r
174 RETAILMSG(1, (L"DeviceIo GETSIZE ret %X\r\n", ret));
\r