yaffs Added some more tests to timothy_tests.
[yaffs2.git] / direct / yaffs_nandif.c
index 26d4f69..e103757 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
  *
- * Copyright (C) 2002-2007 Aleph One Ltd.
+ * Copyright (C) 2002-2010 Aleph One Ltd.
  *   for Toby Churchill Ltd and Brightstar Engineering
  *
  * Created by Charles Manning <charles@aleph1.co.uk>
@@ -13,7 +13,6 @@
 
 #include "yportenv.h"
 #include "yaffs_guts.h"
-#include "devextras.h"
 
 
 #include "yaffs_nandif.h"
  * We assume that the data buffer is of size totalBytersPerChunk so that we can also
  * use it to load the tags.
  */
-int ynandif_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND,
-                                     const __u8 * data,
-                                     const yaffs_ExtendedTags * tags)
+int ynandif_WriteChunkWithTagsToNAND(struct yaffs_dev * dev, int nand_chunk,
+                                     const u8 * data,
+                                     const struct yaffs_ext_tags * tags)
 {
 
        int retval = 0;
-       yaffs_PackedTags2 pt;
+       struct yaffs_packed_tags2 pt;
        void *spare;
        unsigned spareSize = 0;
-       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driverContext);
+       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
-       T(YAFFS_TRACE_MTD,
-         (TSTR
-          ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p"
-           TENDSTR), chunkInNAND, data, tags));
+       yaffs_trace(YAFFS_TRACE_MTD,
+               "nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p",
+               nand_chunk, data, tags);
            
 
        /* For yaffs2 writing there must be both data and tags.
@@ -51,125 +49,127 @@ int ynandif_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND,
         * the end of the data buffer.
         */
 
-       if(dev->param.inbandTags){
-               yaffs_PackedTags2TagsPart *pt2tp;
-               pt2tp = (yaffs_PackedTags2TagsPart *)(data + dev->nDataBytesPerChunk);
-               yaffs_PackTags2TagsPart(pt2tp,tags);
+       if(dev->param.inband_tags){
+               struct yaffs_packed_tags2_tags_only *pt2tp;
+               pt2tp = (struct yaffs_packed_tags2_tags_only *)
+                       (data + dev->data_bytes_per_chunk);
+               yaffs_pack_tags2_tags_only(pt2tp,tags);
                spare = NULL;
                spareSize = 0;
        }
        else{
-               yaffs_PackTags2(&pt, tags,!dev->param.noTagsECC);
+               yaffs_pack_tags2(&pt, tags,!dev->param.no_tags_ecc);
                spare = &pt;
-               spareSize = sizeof(yaffs_PackedTags2);
+               spareSize = sizeof(struct yaffs_packed_tags2);
        }
        
-       retval = geometry->writeChunk(dev,chunkInNAND,
-                                         data, dev->param.totalBytesPerChunk, spare, spareSize);
+       retval = geometry->writeChunk(dev,nand_chunk,
+                               data, dev->param.total_bytes_per_chunk,
+                               spare, spareSize);
 
        return retval;
 }
 
-int ynandif_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
-                                      __u8 * data, yaffs_ExtendedTags * tags)
+int ynandif_ReadChunkWithTagsFromNAND(struct yaffs_dev * dev, int nand_chunk,
+                                      u8 * data, struct yaffs_ext_tags * tags)
 {
-       yaffs_PackedTags2 pt;
+       struct yaffs_packed_tags2 pt;
        int localData = 0;
        void *spare = NULL;
        unsigned spareSize;
        int retval = 0;
        int eccStatus; //0 = ok, 1 = fixed, -1 = unfixed
-       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driverContext);
+       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
-       T(YAFFS_TRACE_MTD,
-         (TSTR
-          ("nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p"
-           TENDSTR), chunkInNAND, data, tags));
+       yaffs_trace(YAFFS_TRACE_MTD,
+               "nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p",
+               nand_chunk, data, tags);
            
        if(!tags){
                spare = NULL;
                spareSize = 0;
-       }else if(dev->param.inbandTags){
+       }else if(dev->param.inband_tags){
                
                if(!data) {
                        localData = 1;
-                       data = yaffs_GetTempBuffer(dev,__LINE__);
+                       data = yaffs_get_temp_buffer(dev,__LINE__);
                }
                spare = NULL;
                spareSize = 0;
        }
        else {
                spare = &pt;
-               spareSize = sizeof(yaffs_PackedTags2);
+               spareSize = sizeof(struct yaffs_packed_tags2);
        }
 
-       retval = geometry->readChunk(dev,chunkInNAND,
+       retval = geometry->readChunk(dev,nand_chunk,
                                         data,
-                                        data ? dev->param.totalBytesPerChunk : 0,
+                                        data ? dev->param.total_bytes_per_chunk : 0,
                                         spare,spareSize,
                                         &eccStatus);
 
-       if(dev->param.inbandTags){
+       if(dev->param.inband_tags){
                if(tags){
-                       yaffs_PackedTags2TagsPart * pt2tp;
-                       pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk];    
-                       yaffs_UnpackTags2TagsPart(tags,pt2tp);
+                       struct yaffs_packed_tags2_tags_only * pt2tp;
+                       pt2tp = (struct yaffs_packed_tags2_tags_only *)&data[dev->data_bytes_per_chunk];        
+                       yaffs_unpack_tags2_tags_only(tags,pt2tp);
                }
        }
        else {
                if (tags){
-                       yaffs_UnpackTags2(tags, &pt,!dev->param.noTagsECC);
+                       yaffs_unpack_tags2(tags, &pt,!dev->param.no_tags_ecc);
                }
        }
 
-       if(tags && tags->chunkUsed){
+       if(tags && tags->chunk_used){
                if(eccStatus < 0 || 
-                  tags->eccResult == YAFFS_ECC_RESULT_UNFIXED)
-                       tags->eccResult = YAFFS_ECC_RESULT_UNFIXED;
+                  tags->ecc_result == YAFFS_ECC_RESULT_UNFIXED)
+                       tags->ecc_result = YAFFS_ECC_RESULT_UNFIXED;
                else if(eccStatus > 0 ||
-                            tags->eccResult == YAFFS_ECC_RESULT_FIXED)
-                       tags->eccResult = YAFFS_ECC_RESULT_FIXED;
+                            tags->ecc_result == YAFFS_ECC_RESULT_FIXED)
+                       tags->ecc_result = YAFFS_ECC_RESULT_FIXED;
                else
-                       tags->eccResult = YAFFS_ECC_RESULT_NO_ERROR;
+                       tags->ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
        }
 
        if(localData)
-               yaffs_ReleaseTempBuffer(dev,data,__LINE__);
+               yaffs_release_temp_buffer(dev,data,__LINE__);
        
        return retval;
 }
 
-int ynandif_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockId)
+int ynandif_MarkNANDBlockBad(struct yaffs_dev *dev, int blockId)
 {
-       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driverContext);
+       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
        return geometry->markBlockBad(dev,blockId);
 }
 
-int ynandif_EraseBlockInNAND(struct yaffs_DeviceStruct *dev, int blockId)
+int ynandif_EraseBlockInNAND(struct yaffs_dev *dev, int blockId)
 {
-       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driverContext);
+       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
        return geometry->eraseBlock(dev,blockId);
 
 }
 
 
-static int ynandif_IsBlockOk(struct yaffs_DeviceStruct *dev, int blockId)
+static int ynandif_IsBlockOk(struct yaffs_dev *dev, int blockId)
 {
-       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driverContext);
+       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
        return geometry->checkBlockOk(dev,blockId);
 }
 
-int ynandif_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockId, yaffs_BlockState *state, __u32 *sequenceNumber)
+int ynandif_QueryNANDBlock(struct yaffs_dev *dev, int blockId, 
+               enum yaffs_block_state *state, u32 *seq_number)
 {
        unsigned chunkNo;
-       yaffs_ExtendedTags tags;
+       struct yaffs_ext_tags tags;
 
-       *sequenceNumber = 0;
+       *seq_number = 0;
        
-       chunkNo = blockId * dev->param.nChunksPerBlock;
+       chunkNo = blockId * dev->param.chunks_per_block;
        
        if(!ynandif_IsBlockOk(dev,blockId)){
                *state = YAFFS_BLOCK_STATE_DEAD;
@@ -178,14 +178,14 @@ int ynandif_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockId, yaffs_Bl
        {
                ynandif_ReadChunkWithTagsFromNAND(dev,chunkNo,NULL,&tags);
 
-               if(!tags.chunkUsed)
+               if(!tags.chunk_used)
                {
                        *state = YAFFS_BLOCK_STATE_EMPTY;
                }
                else 
                {
                        *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
-                       *sequenceNumber = tags.sequenceNumber;
+                       *seq_number = tags.seq_number;
                }
        }
 
@@ -193,18 +193,18 @@ int ynandif_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockId, yaffs_Bl
 }
 
 
-int ynandif_InitialiseNAND(yaffs_Device *dev)
+int ynandif_InitialiseNAND(struct yaffs_dev *dev)
 {
-       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driverContext);
+       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
        geometry->initialise(dev);
 
        return YAFFS_OK;
 }
 
-int ynandif_DeinitialiseNAND(yaffs_Device *dev)
+int ynandif_Deinitialise_flash_fn(struct yaffs_dev *dev)
 {
-       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driverContext);
+       ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
        geometry->deinitialise(dev);
 
@@ -212,45 +212,46 @@ int ynandif_DeinitialiseNAND(yaffs_Device *dev)
 }
 
 
-struct yaffs_DeviceStruct * 
-       yaffs_AddDeviceFromGeometry(const YCHAR *name,
+struct yaffs_dev * 
+       yaffs_add_dev_from_geometry(const YCHAR *name,
                                        const ynandif_Geometry *geometry)
 {
-       YCHAR *clonedName = YMALLOC(sizeof(YCHAR) * (yaffs_strnlen(name,YAFFS_MAX_NAME_LENGTH)+1));
-       struct yaffs_DeviceStruct *dev = YMALLOC(sizeof(struct yaffs_DeviceStruct));
+       YCHAR *clonedName = malloc(sizeof(YCHAR) * (strnlen(name,YAFFS_MAX_NAME_LENGTH)+1));
+       struct yaffs_dev *dev = malloc(sizeof(struct yaffs_dev));
 
        if(dev && clonedName){
-               memset(dev,0,sizeof(struct yaffs_DeviceStruct));
-               yaffs_strcpy(clonedName,name);
+               memset(dev,0,sizeof(struct yaffs_dev));
+               strcpy(clonedName,name);
 
                dev->param.name = clonedName;
-               dev->param.writeChunkWithTagsToNAND  = ynandif_WriteChunkWithTagsToNAND;
-               dev->param.readChunkWithTagsFromNAND = ynandif_ReadChunkWithTagsFromNAND;
-               dev->param.eraseBlockInNAND          = ynandif_EraseBlockInNAND;
-               dev->param.initialiseNAND            = ynandif_InitialiseNAND;
-               dev->param.queryNANDBlock            = ynandif_QueryNANDBlock;
-               dev->param.markNANDBlockBad          = ynandif_MarkNANDBlockBad;
-               dev->param.nShortOpCaches                          = 20;
-               dev->param.startBlock                = geometry->startBlock;
-               dev->param.endBlock                  = geometry->endBlock;
-               dev->param.totalBytesPerChunk              = geometry->dataSize;
-               dev->param.spareBytesPerChunk              = geometry->spareSize;
-               dev->param.inbandTags                              = geometry->inbandTags;
-               dev->param.nChunksPerBlock                 = geometry->pagesPerBlock;
-               dev->param.useNANDECC                              = geometry->hasECC;
-               dev->param.isYaffs2                                = geometry->useYaffs2;
-               dev->param.nReservedBlocks                 = 5;
-               dev->driverContext                         = (void *)geometry;
-
-               yaffs_AddDevice(dev);
+               dev->param.write_chunk_tags_fn = ynandif_WriteChunkWithTagsToNAND;
+               dev->param.read_chunk_tags_fn = ynandif_ReadChunkWithTagsFromNAND;
+               dev->param.erase_fn = ynandif_EraseBlockInNAND;
+               dev->param.initialise_flash_fn = ynandif_InitialiseNAND;
+               dev->param.query_block_fn = ynandif_QueryNANDBlock;
+               dev->param.bad_block_fn = ynandif_MarkNANDBlockBad;
+               dev->param.n_caches = 20;
+               dev->param.start_block = geometry->start_block;
+               dev->param.end_block   = geometry->end_block;
+               dev->param.total_bytes_per_chunk  = geometry->dataSize;
+               dev->param.spare_bytes_per_chunk  = geometry->spareSize;
+               dev->param.inband_tags            = geometry->inband_tags;
+               dev->param.chunks_per_block       = geometry->pagesPerBlock;
+               dev->param.use_nand_ecc           = geometry->hasECC;
+               dev->param.is_yaffs2              = geometry->useYaffs2;
+               dev->param.n_reserved_blocks      = 5;
+               dev->driver_context               = (void *)geometry;
+
+               yaffs_add_device(dev);
 
                return dev;
        }
 
        if(dev)
-               YFREE(dev);
+               free(dev);
        if(clonedName)
-               YFREE(clonedName);
+               free(clonedName);
 
        return NULL;
 }
+