2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2011 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
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.
14 #include "yaffs_nand.h"
15 #include "yaffs_tagscompat.h"
17 #include "yaffs_getblockinfo.h"
18 #include "yaffs_summary.h"
20 static int apply_chunk_offset(struct yaffs_dev *dev, int chunk)
22 return chunk - dev->chunk_offset;
25 int yaffs_rd_chunk_tags_nand(struct yaffs_dev *dev, int nand_chunk,
26 u8 *buffer, struct yaffs_ext_tags *tags)
29 struct yaffs_ext_tags local_tags;
30 int flash_chunk = apply_chunk_offset(dev, nand_chunk);
34 /* If there are no tags provided use local tags. */
38 result = dev->tagger.read_chunk_tags_fn(dev, flash_chunk, buffer, tags);
39 if (tags && tags->ecc_result > YAFFS_ECC_RESULT_NO_ERROR) {
41 struct yaffs_block_info *bi;
42 bi = yaffs_get_block_info(dev,
44 dev->param.chunks_per_block);
45 yaffs_handle_chunk_error(dev, bi);
50 int yaffs_wr_chunk_tags_nand(struct yaffs_dev *dev,
52 const u8 *buffer, struct yaffs_ext_tags *tags)
55 int flash_chunk = apply_chunk_offset(dev, nand_chunk);
60 yaffs_trace(YAFFS_TRACE_ERROR, "Writing with no tags");
65 tags->seq_number = dev->seq_number;
67 yaffs_trace(YAFFS_TRACE_WRITE,
68 "Writing chunk %d tags %d %d",
69 nand_chunk, tags->obj_id, tags->chunk_id);
71 result = dev->tagger.write_chunk_tags_fn(dev, flash_chunk,
74 yaffs_summary_add(dev, tags, nand_chunk);
79 int yaffs_mark_bad(struct yaffs_dev *dev, int block_no)
81 block_no -= dev->block_offset;
82 dev->n_bad_markings++;
83 return dev->tagger.mark_bad_fn(dev, block_no);
87 int yaffs_query_init_block_state(struct yaffs_dev *dev,
89 enum yaffs_block_state *state,
92 block_no -= dev->block_offset;
93 return dev->tagger.query_block_fn(dev, block_no, state, seq_number);
96 int yaffs_erase_block(struct yaffs_dev *dev, int block_no)
100 block_no -= dev->block_offset;
102 result = dev->drv.drv_erase_fn(dev, block_no);
106 int yaffs_init_nand(struct yaffs_dev *dev)
108 if (dev->drv.drv_initialise_fn)
109 return dev->drv.drv_initialise_fn(dev);
113 int yaffs_deinit_nand(struct yaffs_dev *dev)
115 if (dev->drv.drv_deinitialise_fn)
116 return dev->drv.drv_deinitialise_fn(dev);