yaffs-direct: Refactor nand simulator driver look-up.
authorCharles Manning <cdhmanning@gmail.com>
Thu, 9 May 2013 09:23:31 +0000 (21:23 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Thu, 9 May 2013 09:23:31 +0000 (21:23 +1200)
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/test-framework/FrameworkRules.mk
direct/test-framework/yaffs_nand_drv.c
direct/test-framework/yaffs_nand_drv.h
direct/test-framework/yaffs_nandsim_file.c [new file with mode: 0644]
direct/test-framework/yaffs_nandsim_file.h [new file with mode: 0644]

index d634793..f4d955c 100644 (file)
@@ -38,8 +38,8 @@ COMMONTESTOBJS = yaffscfg2k.o yaffs_osglue.o yaffs_hweight.o yaffs_error.o\
                 yaffs_nameval.o yaffs_attribs.o \
                 yaffs_m18_drv.o  yaffs_nor_drv.o ynorsim.o \
                 yaffs_nand_drv.o \
-                nanddrv.o nandsim.o \
-                nandsim_file.o nandstore_file.o \
+                nanddrv.o \
+                yaffs_nandsim_file.o nandsim.o nandsim_file.o nandstore_file.o \
                 yaffs_allocator.o \
                 yaffs_bitmap.o \
                 yaffs_yaffs1.o \
@@ -85,6 +85,7 @@ FRAMEWORKEXTRASYMLINKS = \
                yaffs_ramdisk.c yaffs_ramdisk.h yaffs_ramem2k.c \
                nand_chip.h nanddrv.c nanddrv.h nandsim.c nandsim.h nand_store.h \
                nandsim_file.c nandsim_file.h nandstore_file.c nandstore_file.h \
+               yaffs_nandsim_file.c yaffs_nandsim_file.h \
                ynorsim.h ynorsim.c yaffs_osglue.c
 
 FRAMEWORK_SOURCES = $(YAFFSDIRECTSYMLINKS) $(FRAMEWORKEXTRASYMLINKS)
index d9c4e73..9bdcb55 100644 (file)
@@ -220,6 +220,7 @@ static int yaffs_nand_drv_Initialise(struct yaffs_dev *dev)
 {
        struct nand_chip *chip = dev_to_chip(dev);
 
+       (void)chip;
        return YAFFS_OK;
 }
 
@@ -227,56 +228,23 @@ static int yaffs_nand_drv_Deinitialise(struct yaffs_dev *dev)
 {
        struct nand_chip *chip = dev_to_chip(dev);
 
+       (void) chip;
        return YAFFS_OK;
 }
 
-#include "nandsim_file.h"
 
-struct yaffs_dev *yaffs_nandsim_install_drv(const char *name,
-                                       const char *file_name,
-                                       int n_blocks)
+int yaffs_nand_install_drv(struct yaffs_dev *dev, struct nand_chip *chip)
 {
-       struct yaffs_dev *dev;
-       char *name_copy = NULL;
-       struct yaffs_param *param;
-       struct yaffs_driver *drv;
-       struct nand_chip *chip = NULL;
-       struct nand_context *ctxt = NULL;
+       struct yaffs_driver *drv = &dev->drv;
        u8 *buffer = NULL;
+       struct nand_context *ctxt = NULL;
 
-       dev = malloc(sizeof(struct yaffs_dev));
        ctxt = malloc(sizeof(struct nand_context));
-       name_copy = strdup(name);
-
-       if(!dev || !ctxt || !name_copy)
-               goto fail;
-
-       chip = nandsim_file_init(file_name, n_blocks, 64, 2048, 64, 0);
-       if(!chip)
-               goto fail;
-
        buffer = malloc(chip->spare_bytes_per_page);
 
-       if(!buffer)
+       if(!buffer || !ctxt)
                goto fail;
 
-       param = &dev->param;
-       drv = &dev->drv;
-
-       memset(dev, 0, sizeof(*dev));
-       memset(ctxt, 0, sizeof(*ctxt));
-
-       param->name = name_copy;
-
-       param->total_bytes_per_chunk = chip->data_bytes_per_page;
-       param->chunks_per_block = chip->pages_per_block;
-       param->n_reserved_blocks = 5;
-       param->start_block = 0; // Can use block 0
-       param->end_block = chip->blocks - 1; // Last block
-       param->is_yaffs2 = 1;
-       param->use_nand_ecc = 1;
-       param->n_caches = 10;
-
        drv->drv_write_chunk_fn = yaffs_nand_drv_WriteChunk;
        drv->drv_read_chunk_fn = yaffs_nand_drv_ReadChunk;
        drv->drv_erase_fn = yaffs_nand_drv_EraseBlock;
@@ -288,15 +256,10 @@ struct yaffs_dev *yaffs_nandsim_install_drv(const char *name,
        ctxt->chip = chip;
        ctxt->buffer = buffer;
        dev->driver_context = (void *) ctxt;
-
-       yaffs_add_device(dev);
-
-       return dev;
+       return YAFFS_OK;
 
 fail:
-       free(dev);
        free(ctxt);
-       free(name_copy);
        free(buffer);
-       return NULL;
+       return YAFFS_FAIL;
 }
index 3e93644..047ab34 100644 (file)
 #ifndef __YAFFS_NAND_DRV_H__
 #define __YAFFS_NAND_DRV_H__
 
-struct nand_store;
+#include "yaffs_guts.h"
+#include "nand_chip.h"
 
-struct yaffs_dev *
-       yaffs_nand_install_drv(const char *name,
-                               struct nand_store *ns);
-
-struct yaffs_dev *yaffs_nandsim_install_drv(const char *name,
-                                       const char *file_name,
-                                       int n_blocks);
+int yaffs_nand_install_drv(struct yaffs_dev *dev, struct nand_chip *chip);
 
 #endif
diff --git a/direct/test-framework/yaffs_nandsim_file.c b/direct/test-framework/yaffs_nandsim_file.c
new file mode 100644 (file)
index 0000000..962b3d6
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2011 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Charles Manning <charles@aleph1.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+
+#include "yaffs_nandsim_file.h"
+
+#include "nandsim_file.h"
+#include "nand_chip.h"
+#include "yaffs_guts.h"
+#include <stddef.h>
+
+
+struct yaffs_dev *yaffs_nandsim_install_drv(const char *dev_name,
+                                       const char *backing_file_name,
+                                       int n_blocks)
+{
+       struct yaffs_dev *dev;
+       char *name_copy = NULL;
+       struct yaffs_param *param;
+       struct nand_chip *chip = NULL;
+
+
+
+       dev = malloc(sizeof(struct yaffs_dev));
+       name_copy = strdup(dev_name);
+
+       if(!dev || !name_copy)
+               goto fail;
+
+       memset(dev, 0, sizeof(*dev));
+       chip = nandsim_file_init(backing_file_name, n_blocks, 64, 2048, 64, 0);
+       if(!chip)
+               goto fail;
+
+       param = &dev->param;
+
+       param->name = name_copy;
+
+       param->total_bytes_per_chunk = chip->data_bytes_per_page;
+       param->chunks_per_block = chip->pages_per_block;
+       param->n_reserved_blocks = 5;
+       param->start_block = 0; // First block
+       param->end_block = n_blocks - 1; // Last block
+       param->is_yaffs2 = 1;
+       param->use_nand_ecc = 1;
+       param->n_caches = 10;
+
+
+       if(yaffs_nand_install_drv(dev, chip) != YAFFS_OK)
+               goto fail;
+
+       /* The yaffs device has been configured, install it into yaffs */
+       yaffs_add_device(dev);
+
+       return dev;
+
+fail:
+       free(dev);
+       free(name_copy);
+       return NULL;
+}
diff --git a/direct/test-framework/yaffs_nandsim_file.h b/direct/test-framework/yaffs_nandsim_file.h
new file mode 100644 (file)
index 0000000..0960dac
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2011 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Charles Manning <charles@aleph1.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __YAFFS_NAND_DRV_H__
+#define __YAFFS_NAND_DRV_H__
+
+struct yaffs_dev;
+
+struct yaffs_dev *yaffs_nandsim_file_install(const char *dev_name,
+                                       const char *backing_file_name,
+                                       int n_blocks);
+
+#endif