2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2007 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 const char *yaffs_nand_c_version =
15 "$Id: yaffs_nand.c,v 1.7 2007/02/14 01:09:06 wookey Exp $";
17 #include "yaffs_nand.h"
18 #include "yaffs_tagscompat.h"
19 #include "yaffs_tagsvalidity.h"
22 int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
24 yaffs_ExtendedTags * tags)
27 yaffs_ExtendedTags localTags;
29 int realignedChunkInNAND = chunkInNAND - dev->chunkOffset;
31 /* If there are no tags provided, use local tags to get prioritised gc working */
35 if (dev->readChunkWithTagsFromNAND)
36 result = dev->readChunkWithTagsFromNAND(dev, realignedChunkInNAND, buffer,
39 result = yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(dev,
44 tags->eccResult > YAFFS_ECC_RESULT_NO_ERROR){
46 yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, chunkInNAND/dev->nChunksPerBlock);
47 yaffs_HandleChunkError(dev,bi);
53 int yaffs_WriteChunkWithTagsToNAND(yaffs_Device * dev,
56 yaffs_ExtendedTags * tags)
58 chunkInNAND -= dev->chunkOffset;
62 tags->sequenceNumber = dev->sequenceNumber;
64 if (!yaffs_ValidateTags(tags)) {
66 (TSTR("Writing uninitialised tags" TENDSTR)));
70 (TSTR("Writing chunk %d tags %d %d" TENDSTR), chunkInNAND,
71 tags->objectId, tags->chunkId));
73 T(YAFFS_TRACE_ERROR, (TSTR("Writing with no tags" TENDSTR)));
77 if (dev->writeChunkWithTagsToNAND)
78 return dev->writeChunkWithTagsToNAND(dev, chunkInNAND, buffer,
81 return yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(dev,
87 int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo)
89 blockNo -= dev->blockOffset;
92 if (dev->markNANDBlockBad)
93 return dev->markNANDBlockBad(dev, blockNo);
95 return yaffs_TagsCompatabilityMarkNANDBlockBad(dev, blockNo);
98 int yaffs_QueryInitialBlockState(yaffs_Device * dev,
100 yaffs_BlockState * state,
101 unsigned *sequenceNumber)
103 blockNo -= dev->blockOffset;
105 if (dev->queryNANDBlock)
106 return dev->queryNANDBlock(dev, blockNo, state, sequenceNumber);
108 return yaffs_TagsCompatabilityQueryNANDBlock(dev, blockNo,
114 int yaffs_EraseBlockInNAND(struct yaffs_DeviceStruct *dev,
119 blockInNAND -= dev->blockOffset;
122 dev->nBlockErasures++;
123 result = dev->eraseBlockInNAND(dev, blockInNAND);
128 int yaffs_InitialiseNAND(struct yaffs_DeviceStruct *dev)
130 return dev->initialiseNAND(dev);