Fix M18 driver for 64-bit systems
[yaffs2.git] / direct / test-framework / yaffs_m18_drv.c
index 0325968..9a8ee49 100644 (file)
 
 /* Compile this for a simulation */
 #include "ynorsim.h"
-#define m18_drv_FlashInit() ynorsim_initialise()
-#define m18_drv_FlashDeinit() ynorsim_shutdown()
-#define m18_drv_FlashWrite32(addr,buf,nwords) ynorsim_wr32(addr,buf,nwords)
-#define m18_drv_FlashRead32(addr,buf,nwords) ynorsim_rd32(addr,buf,nwords)
-#define m18_drv_FlashEraseBlock(addr) ynorsim_erase(addr)
-#define DEVICE_BASE     ynorsim_get_base()
+
+static struct nor_sim *nor_sim;
+
+#define m18_drv_FlashInit() do {nor_sim = ynorsim_initialise("emfile-m18", BLOCKS_IN_DEVICE, BLOCK_SIZE_IN_BYTES); } while(0)
+#define m18_drv_FlashDeinit() ynorsim_shutdown(nor_sim)
+#define m18_drv_FlashWrite32(addr,buf,nwords) ynorsim_wr32(nor_sim,addr,buf,nwords)
+#define m18_drv_FlashRead32(addr,buf,nwords) ynorsim_rd32(nor_sim,addr,buf,nwords)
+#define m18_drv_FlashEraseBlock(addr) ynorsim_erase(nor_sim,addr)
+#define DEVICE_BASE     ynorsim_get_base(nor_sim)
+
 #else
 
 /* Compile this to hook up to read hardware */
 #define DEVICE_BASE     (32 * 1024 * 1024)
 #endif
 
+
 static u32 *Block2Addr(struct yaffs_dev *dev, int blockNumber)
 {
-       u32 addr;
+       u8 *addr;
        dev=dev;
 
-       addr = (u32) DEVICE_BASE;
+       addr = (u8*) DEVICE_BASE;
        addr += blockNumber * BLOCK_SIZE_IN_BYTES;
 
        return (u32 *) addr;
@@ -98,9 +103,9 @@ static u32 *Block2Addr(struct yaffs_dev *dev, int blockNumber)
 
 static u32 *Block2FormatAddr(struct yaffs_dev *dev,int blockNumber)
 {
-       u32 addr;
+       u8 *addr;
 
-       addr = (u32) Block2Addr(dev,blockNumber);
+       addr = (u8*) Block2Addr(dev,blockNumber);
        addr += FORMAT_OFFSET;
 
        return (u32 *)addr;
@@ -110,12 +115,12 @@ static u32 *Chunk2DataAddr(struct yaffs_dev *dev,int chunk_id)
 {
        unsigned block;
        unsigned chunkInBlock;
-       u32  addr;
+       u8 *addr;
 
        block = chunk_id/dev->param.chunks_per_block;
        chunkInBlock = chunk_id % dev->param.chunks_per_block;
 
-       addr = (u32) Block2Addr(dev,block);
+       addr = (u8*) Block2Addr(dev,block);
        addr += chunkInBlock * DATA_BYTES_PER_CHUNK;
 
        return (u32 *)addr;
@@ -125,12 +130,12 @@ static u32 *Chunk2SpareAddr(struct yaffs_dev *dev,int chunk_id)
 {
        unsigned block;
        unsigned chunkInBlock;
-       u32 addr;
+       u8 *addr;
 
        block = chunk_id/dev->param.chunks_per_block;
        chunkInBlock = chunk_id % dev->param.chunks_per_block;
 
-       addr = (u32) Block2Addr(dev,block);
+       addr = (u8*) Block2Addr(dev,block);
        addr += SPARE_AREA_OFFSET;
        addr += chunkInBlock * (SPARE_BYTES_PER_CHUNK + M18_SKIP);
        return (u32 *)addr;
@@ -315,6 +320,7 @@ static int m18_drv_InitialiseNAND(struct yaffs_dev *dev)
 static int m18_drv_Deinitialise_flash_fn(struct yaffs_dev *dev)
 {
        dev=dev;
+
        m18_drv_FlashDeinit();
 
        return YAFFS_OK;