yaffs2: Yaffs endian support
[yaffs2.git] / direct / test-framework / yaffs_nandsim_file.c
1 /*
2  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 Aleph One Ltd.
5  *   for Toby Churchill Ltd and Brightstar Engineering
6  *
7  * Created by Charles Manning <charles@aleph1.co.uk>
8  *
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.
12  */
13
14
15 #include "yaffs_nandsim_file.h"
16
17 #include "nandsim_file.h"
18 #include "nand_chip.h"
19 #include "yaffs_guts.h"
20 #include <stddef.h>
21
22
23 struct yaffs_dev *yaffs_nandsim_install_drv(const char *dev_name,
24                                         const char *backing_file_name,
25                                         int n_blocks)
26 {
27         struct yaffs_dev *dev;
28         char *name_copy = NULL;
29         struct yaffs_param *param;
30         struct nand_chip *chip = NULL;
31
32
33
34         dev = malloc(sizeof(struct yaffs_dev));
35         name_copy = strdup(dev_name);
36
37         if(!dev || !name_copy)
38                 goto fail;
39
40         memset(dev, 0, sizeof(*dev));
41         chip = nandsim_file_init(backing_file_name, n_blocks, 64, 2048, 64, 0);
42         if(!chip)
43                 goto fail;
44
45         param = &dev->param;
46
47         param->name = name_copy;
48
49         param->total_bytes_per_chunk = chip->data_bytes_per_page;
50         param->chunks_per_block = chip->pages_per_block;
51         param->n_reserved_blocks = 5;
52         param->start_block = 0; // First block
53         param->end_block = n_blocks - 1; // Last block
54         param->is_yaffs2 = 1;
55         param->use_nand_ecc = 1;
56         param->n_caches = 10;
57         param->stored_endian = 2;
58
59         if(yaffs_nand_install_drv(dev, chip) != YAFFS_OK)
60                 goto fail;
61
62         /* The yaffs device has been configured, install it into yaffs */
63         yaffs_add_device(dev);
64
65         return dev;
66
67 fail:
68         free(dev);
69         free(name_copy);
70         return NULL;
71 }