yaffs Added some more tests to timothy_tests.
[yaffs2.git] / direct / yaffs_nandif.c
index 8a8f3fb..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_dev_t * dev, int nand_chunk,
-                                     const __u8 * data,
-                                     const yaffs_ext_tags * 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->driver_context);
 
-       T(YAFFS_TRACE_MTD,
-         (TSTR
-          ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p"
-           TENDSTR), nand_chunk, 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.
@@ -52,28 +50,30 @@ int ynandif_WriteChunkWithTagsToNAND(yaffs_dev_t * dev, int nand_chunk,
         */
 
        if(dev->param.inband_tags){
-               yaffs_PackedTags2TagsPart *pt2tp;
-               pt2tp = (yaffs_PackedTags2TagsPart *)(data + dev->data_bytes_per_chunk);
-               yaffs_PackTags2TagsPart(pt2tp,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.no_tags_ecc);
+               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,nand_chunk,
-                                         data, dev->param.total_bytes_per_chunk, spare, spareSize);
+                               data, dev->param.total_bytes_per_chunk,
+                               spare, spareSize);
 
        return retval;
 }
 
-int ynandif_ReadChunkWithTagsFromNAND(yaffs_dev_t * dev, int nand_chunk,
-                                      __u8 * data, yaffs_ext_tags * 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;
@@ -81,10 +81,9 @@ int ynandif_ReadChunkWithTagsFromNAND(yaffs_dev_t * dev, int nand_chunk,
        int eccStatus; //0 = ok, 1 = fixed, -1 = unfixed
        ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
-       T(YAFFS_TRACE_MTD,
-         (TSTR
-          ("nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p"
-           TENDSTR), nand_chunk, data, tags));
+       yaffs_trace(YAFFS_TRACE_MTD,
+               "nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p",
+               nand_chunk, data, tags);
            
        if(!tags){
                spare = NULL;
@@ -100,7 +99,7 @@ int ynandif_ReadChunkWithTagsFromNAND(yaffs_dev_t * dev, int nand_chunk,
        }
        else {
                spare = &pt;
-               spareSize = sizeof(yaffs_PackedTags2);
+               spareSize = sizeof(struct yaffs_packed_tags2);
        }
 
        retval = geometry->readChunk(dev,nand_chunk,
@@ -111,9 +110,9 @@ int ynandif_ReadChunkWithTagsFromNAND(yaffs_dev_t * dev, int nand_chunk,
 
        if(dev->param.inband_tags){
                if(tags){
-                       yaffs_PackedTags2TagsPart * pt2tp;
-                       pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->data_bytes_per_chunk];  
-                       yaffs_unpack_tags2tags_part(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 {
@@ -139,14 +138,14 @@ int ynandif_ReadChunkWithTagsFromNAND(yaffs_dev_t * dev, int nand_chunk,
        return retval;
 }
 
-int ynandif_MarkNANDBlockBad(struct yaffs_dev_s *dev, int blockId)
+int ynandif_MarkNANDBlockBad(struct yaffs_dev *dev, int blockId)
 {
        ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
        return geometry->markBlockBad(dev,blockId);
 }
 
-int ynandif_EraseBlockInNAND(struct yaffs_dev_s *dev, int blockId)
+int ynandif_EraseBlockInNAND(struct yaffs_dev *dev, int blockId)
 {
        ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
@@ -155,17 +154,18 @@ int ynandif_EraseBlockInNAND(struct yaffs_dev_s *dev, int blockId)
 }
 
 
-static int ynandif_IsBlockOk(struct yaffs_dev_s *dev, int blockId)
+static int ynandif_IsBlockOk(struct yaffs_dev *dev, int blockId)
 {
        ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
        return geometry->checkBlockOk(dev,blockId);
 }
 
-int ynandif_QueryNANDBlock(struct yaffs_dev_s *dev, int blockId, yaffs_block_state_t *state, __u32 *seq_number)
+int ynandif_QueryNANDBlock(struct yaffs_dev *dev, int blockId, 
+               enum yaffs_block_state *state, u32 *seq_number)
 {
        unsigned chunkNo;
-       yaffs_ext_tags tags;
+       struct yaffs_ext_tags tags;
 
        *seq_number = 0;
        
@@ -193,7 +193,7 @@ int ynandif_QueryNANDBlock(struct yaffs_dev_s *dev, int blockId, yaffs_block_sta
 }
 
 
-int ynandif_InitialiseNAND(yaffs_dev_t *dev)
+int ynandif_InitialiseNAND(struct yaffs_dev *dev)
 {
        ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
@@ -202,7 +202,7 @@ int ynandif_InitialiseNAND(yaffs_dev_t *dev)
        return YAFFS_OK;
 }
 
-int ynandif_Deinitialise_flash_fn(yaffs_dev_t *dev)
+int ynandif_Deinitialise_flash_fn(struct yaffs_dev *dev)
 {
        ynandif_Geometry *geometry = (ynandif_Geometry *)(dev->driver_context);
 
@@ -212,35 +212,35 @@ int ynandif_Deinitialise_flash_fn(yaffs_dev_t *dev)
 }
 
 
-struct yaffs_dev_s * 
+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_dev_s *dev = YMALLOC(sizeof(struct yaffs_dev_s));
+       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_dev_s));
-               yaffs_strcpy(clonedName,name);
+               memset(dev,0,sizeof(struct yaffs_dev));
+               strcpy(clonedName,name);
 
                dev->param.name = clonedName;
-               dev->param.write_chunk_tags_fn  = ynandif_WriteChunkWithTagsToNAND;
+               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;
+               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);
 
@@ -248,9 +248,10 @@ struct yaffs_dev_s *
        }
 
        if(dev)
-               YFREE(dev);
+               free(dev);
        if(clonedName)
-               YFREE(clonedName);
+               free(clonedName);
 
        return NULL;
 }
+