]>
git.ipfire.org Git - people/ms/u-boot.git/blob - fs/yaffs2/yaffs_mtdif.c
2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2007 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.
20 #include "yaffs_mtdif.h"
22 #include <linux/mtd/mtd.h>
23 #include <linux/types.h>
24 #include <linux/time.h>
25 #include <linux/mtd/rawnand.h>
28 static inline void translate_spare2oob(const struct yaffs_spare
*spare
, u8
*oob
)
35 oob
[5] = spare
->tb5
& 0x3f;
36 oob
[5] |= spare
->block_status
== 'Y' ? 0 : 0x80;
37 oob
[5] |= spare
->page_status
== 0 ? 0 : 0x40;
42 static inline void translate_oob2spare(struct yaffs_spare
*spare
, u8
*oob
)
44 struct yaffs_nand_spare
*nspare
= (struct yaffs_nand_spare
*)spare
;
50 spare
->tb5
= oob
[5] == 0xff ? 0xff : oob
[5] & 0x3f;
51 spare
->block_status
= oob
[5] & 0x80 ? 0xff : 'Y';
52 spare
->page_status
= oob
[5] & 0x40 ? 0xff : 0;
53 spare
->ecc1
[0] = spare
->ecc1
[1] = spare
->ecc1
[2] = 0xff;
56 spare
->ecc2
[0] = spare
->ecc2
[1] = spare
->ecc2
[2] = 0xff;
58 nspare
->eccres1
= nspare
->eccres2
= 0; /* FIXME */
62 int nandmtd_WriteChunkToNAND(struct yaffs_dev
*dev
, int chunkInNAND
,
63 const u8
*data
, const struct yaffs_spare
*spare
)
65 struct mtd_info
*mtd
= (struct mtd_info
*)(dev
->driver_context
);
66 struct mtd_oob_ops ops
;
69 loff_t addr
= ((loff_t
) chunkInNAND
) * dev
->data_bytes_per_chunk
;
70 u8 spareAsBytes
[8]; /* OOB */
73 retval
= mtd_write(mtd
, addr
, dev
->data_bytes_per_chunk
,
76 if (dev
->param
.use_nand_ecc
) {
77 translate_spare2oob(spare
, spareAsBytes
);
78 ops
.mode
= MTD_OPS_AUTO_OOB
;
79 ops
.ooblen
= 8; /* temp hack */
81 ops
.mode
= MTD_OPS_RAW
;
82 ops
.ooblen
= YAFFS_BYTES_PER_SPARE
;
84 ops
.len
= data
? dev
->data_bytes_per_chunk
: ops
.ooblen
;
85 ops
.datbuf
= (u8
*)data
;
87 ops
.oobbuf
= spareAsBytes
;
88 retval
= mtd_write_oob(mtd
, addr
, &ops
);
97 int nandmtd_ReadChunkFromNAND(struct yaffs_dev
*dev
, int chunkInNAND
, u8
*data
,
98 struct yaffs_spare
*spare
)
100 struct mtd_info
*mtd
= (struct mtd_info
*)(dev
->driver_context
);
101 struct mtd_oob_ops ops
;
105 loff_t addr
= ((loff_t
) chunkInNAND
) * dev
->data_bytes_per_chunk
;
106 u8 spareAsBytes
[8]; /* OOB */
109 retval
= mtd_read(mtd
, addr
, dev
->data_bytes_per_chunk
,
112 if (dev
->param
.use_nand_ecc
) {
113 ops
.mode
= MTD_OPS_AUTO_OOB
;
114 ops
.ooblen
= 8; /* temp hack */
116 ops
.mode
= MTD_OPS_RAW
;
117 ops
.ooblen
= YAFFS_BYTES_PER_SPARE
;
119 ops
.len
= data
? dev
->data_bytes_per_chunk
: ops
.ooblen
;
122 ops
.oobbuf
= spareAsBytes
;
123 retval
= mtd_read_oob(mtd
, addr
, &ops
);
124 if (dev
->param
.use_nand_ecc
)
125 translate_oob2spare(spare
, spareAsBytes
);
134 int nandmtd_EraseBlockInNAND(struct yaffs_dev
*dev
, int blockNumber
)
136 struct mtd_info
*mtd
= (struct mtd_info
*)(dev
->driver_context
);
138 ((loff_t
) blockNumber
) * dev
->data_bytes_per_chunk
139 * dev
->param
.chunks_per_block
;
140 struct erase_info ei
;
145 ei
.len
= dev
->data_bytes_per_chunk
* dev
->param
.chunks_per_block
;
149 ei
.priv
= (u_long
) dev
;
151 /* Todo finish off the ei if required */
154 retval
= mtd_erase(mtd
, &ei
);
162 int nandmtd_InitialiseNAND(struct yaffs_dev
*dev
)