projects
/
yaffs2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
yaffs Normalise copyright headers
[yaffs2.git]
/
yaffs_mtdif1.c
diff --git
a/yaffs_mtdif1.c
b/yaffs_mtdif1.c
index f4d35fc5a659900f62f191d3b0f366fb4c88329a..b6d6713d9ededa5ca6942034aeed17f2b6401e14 100644
(file)
--- a/
yaffs_mtdif1.c
+++ b/
yaffs_mtdif1.c
@@
-1,10
+1,11
@@
/*
* YAFFS: Yet another FFS. A NAND-flash specific file system.
/*
* YAFFS: Yet another FFS. A NAND-flash specific file system.
- * yaffs_mtdif1.c NAND mtd interface functions for small-page NAND.
*
*
- * Copyright (C) 2002 Aleph One Ltd.
+ * Copyright (C) 2002
-2010
Aleph One Ltd.
* for Toby Churchill Ltd and Brightstar Engineering
*
* 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.
* 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.
@@
-18,15
+19,17
@@
*
* These functions are invoked via function pointers in yaffs_nand.c.
* This replaces functionality provided by functions in yaffs_mtdif.c
*
* These functions are invoked via function pointers in yaffs_nand.c.
* This replaces functionality provided by functions in yaffs_mtdif.c
- * and the yaffs_
Tags
Compatability functions in yaffs_tagscompat.c that are
+ * and the yaffs_
tags_t
Compatability functions in yaffs_tagscompat.c that are
* called in yaffs_mtdif.c when the function pointers are NULL.
* called in yaffs_mtdif.c when the function pointers are NULL.
- * We assume the MTD layer is performing ECC (use
NANDECC
is true).
+ * We assume the MTD layer is performing ECC (use
_nand_ecc
is true).
*/
#include "yportenv.h"
*/
#include "yportenv.h"
+#include "yaffs_trace.h"
#include "yaffs_guts.h"
#include "yaffs_packedtags1.h"
#include "yaffs_guts.h"
#include "yaffs_packedtags1.h"
-#include "yaffs_tagscompat.h" /* for yaffs_CalcTagsECC */
+#include "yaffs_tagscompat.h" /* for yaffs_calc_tags_ecc */
+#include "yaffs_linux.h"
#include "linux/kernel.h"
#include "linux/version.h"
#include "linux/kernel.h"
#include "linux/version.h"
@@
-36,8
+39,6
@@
/* Don't compile this module if we don't have MTD's mtd_oob_ops interface */
#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
/* Don't compile this module if we don't have MTD's mtd_oob_ops interface */
#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
-const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.9 2009-03-06 17:20:52 wookey Exp $";
-
#ifndef CONFIG_YAFFS_9BYTE_TAGS
# define YTAG1_SIZE 8
#else
#ifndef CONFIG_YAFFS_9BYTE_TAGS
# define YTAG1_SIZE 8
#else
@@
-51,12
+52,12
@@
const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.9 2009-03-06 17:20
* adjust 'oobfree' to match your existing Yaffs data.
*
* This nand_ecclayout scatters/gathers to/from the old-yaffs layout with the
* adjust 'oobfree' to match your existing Yaffs data.
*
* This nand_ecclayout scatters/gathers to/from the old-yaffs layout with the
- * page
S
tatus byte (at NAND spare offset 4) scattered/gathered from/to
+ * page
_s
tatus byte (at NAND spare offset 4) scattered/gathered from/to
* the 9th byte.
*
* Old-style on-NAND format: T0,T1,T2,T3,P,B,T4,T5,E0,E1,E2,T6,T7,E3,E4,E5
* the 9th byte.
*
* Old-style on-NAND format: T0,T1,T2,T3,P,B,T4,T5,E0,E1,E2,T6,T7,E3,E4,E5
- * We have/need PackedTags1 plus page
S
tatus: T0,T1,T2,T3,T4,T5,T6,T7,P
- * where Tn are the tag bytes, En are MTD's ECC bytes, P is the page
S
tatus
+ * We have/need PackedTags1 plus page
_s
tatus: T0,T1,T2,T3,T4,T5,T6,T7,P
+ * where Tn are the tag bytes, En are MTD's ECC bytes, P is the page
_s
tatus
* byte and B is the small-page bad-block indicator byte.
*/
static struct nand_ecclayout nand_oob_16 = {
* byte and B is the small-page bad-block indicator byte.
*/
static struct nand_ecclayout nand_oob_16 = {
@@
-88,42
+89,40
@@
static struct nand_ecclayout nand_oob_16 = {
* Any underlying MTD error results in YAFFS_FAIL.
* Returns YAFFS_OK or YAFFS_FAIL.
*/
* Any underlying MTD error results in YAFFS_FAIL.
* Returns YAFFS_OK or YAFFS_FAIL.
*/
-int nandmtd1_WriteChunkWithTagsToNAND(yaffs_
Device
*dev,
- int
chunkInNAND, const __u8 *data, const yaffs_ExtendedT
ags *etags)
+int nandmtd1_WriteChunkWithTagsToNAND(yaffs_
dev_t
*dev,
+ int
nand_chunk, const __u8 *data, const yaffs_ext_t
ags *etags)
{
{
- struct mtd_info *mtd =
dev->genericDevice
;
- int chunkBytes = dev->
nDataBytesPerC
hunk;
- loff_t addr = ((loff_t)
chunkInNAND
) * chunkBytes;
+ struct mtd_info *mtd =
yaffs_dev_to_mtd(dev)
;
+ int chunkBytes = dev->
data_bytes_per_c
hunk;
+ loff_t addr = ((loff_t)
nand_chunk
) * chunkBytes;
struct mtd_oob_ops ops;
yaffs_PackedTags1 pt1;
int retval;
struct mtd_oob_ops ops;
yaffs_PackedTags1 pt1;
int retval;
- /* we assume that PackedTags1 and yaffs_
Tags
are compatible */
+ /* we assume that PackedTags1 and yaffs_
tags_t
are compatible */
compile_time_assertion(sizeof(yaffs_PackedTags1) == 12);
compile_time_assertion(sizeof(yaffs_PackedTags1) == 12);
- compile_time_assertion(sizeof(yaffs_Tags) == 8);
-
- dev->nPageWrites++;
+ compile_time_assertion(sizeof(yaffs_tags_t) == 8);
yaffs_PackTags1(&pt1, etags);
yaffs_PackTags1(&pt1, etags);
- yaffs_
CalcTagsECC((yaffs_Tags
*)&pt1);
+ yaffs_
calc_tags_ecc((yaffs_tags_t
*)&pt1);
/* When deleting a chunk, the upper layer provides only skeletal
/* When deleting a chunk, the upper layer provides only skeletal
- * etags, one with
chunkD
eleted set. However, we need to update the
+ * etags, one with
is_d
eleted set. However, we need to update the
* tags, not erase them completely. So we use the NAND write property
* that only zeroed-bits stick and set tag bytes to all-ones and
* zero just the (not) deleted bit.
*/
#ifndef CONFIG_YAFFS_9BYTE_TAGS
* tags, not erase them completely. So we use the NAND write property
* that only zeroed-bits stick and set tag bytes to all-ones and
* zero just the (not) deleted bit.
*/
#ifndef CONFIG_YAFFS_9BYTE_TAGS
- if (etags->
chunkD
eleted) {
+ if (etags->
is_d
eleted) {
memset(&pt1, 0xff, 8);
/* clear delete status bit to indicate deleted */
pt1.deleted = 0;
}
#else
((__u8 *)&pt1)[8] = 0xff;
memset(&pt1, 0xff, 8);
/* clear delete status bit to indicate deleted */
pt1.deleted = 0;
}
#else
((__u8 *)&pt1)[8] = 0xff;
- if (etags->
chunkD
eleted) {
+ if (etags->
is_d
eleted) {
memset(&pt1, 0xff, 8);
memset(&pt1, 0xff, 8);
- /* zero page
S
tatus byte to indicate deleted */
+ /* zero page
_s
tatus byte to indicate deleted */
((__u8 *)&pt1)[8] = 0;
}
#endif
((__u8 *)&pt1)[8] = 0;
}
#endif
@@
-137,20
+136,20
@@
int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev,
retval = mtd->write_oob(mtd, addr, &ops);
if (retval) {
retval = mtd->write_oob(mtd, addr, &ops);
if (retval) {
-
yaffs_trace
(YAFFS_TRACE_MTD,
-
"write_oob failed, chunk %d, mtd error %d\n"
,
-
chunkInNAND, retval
);
+
T
(YAFFS_TRACE_MTD,
+
(TSTR("write_oob failed, chunk %d, mtd error %d"TENDSTR)
,
+
nand_chunk, retval)
);
}
return retval ? YAFFS_FAIL : YAFFS_OK;
}
}
return retval ? YAFFS_FAIL : YAFFS_OK;
}
-/* Return with empty ExtendedTags but add ecc
R
esult.
+/* Return with empty ExtendedTags but add ecc
_r
esult.
*/
*/
-static int rettags(yaffs_
ExtendedTags *etags, int eccR
esult, int retval)
+static int rettags(yaffs_
ext_tags *etags, int ecc_r
esult, int retval)
{
if (etags) {
memset(etags, 0, sizeof(*etags));
{
if (etags) {
memset(etags, 0, sizeof(*etags));
- etags->ecc
Result = eccR
esult;
+ etags->ecc
_result = ecc_r
esult;
}
return retval;
}
}
return retval;
}
@@
-158,30
+157,28
@@
static int rettags(yaffs_ExtendedTags *etags, int eccResult, int retval)
/* Read a chunk (page) from NAND.
*
* Caller expects ExtendedTags data to be usable even on error; that is,
/* Read a chunk (page) from NAND.
*
* Caller expects ExtendedTags data to be usable even on error; that is,
- * all members except ecc
Result and blockB
ad are zeroed.
+ * all members except ecc
_result and block_b
ad are zeroed.
*
* - Check ECC results for data (if applicable)
* - Check for blank/erased block (return empty ExtendedTags if blank)
* - Check the PackedTags1 mini-ECC (correct if necessary/possible)
* - Convert PackedTags1 to ExtendedTags
*
* - Check ECC results for data (if applicable)
* - Check for blank/erased block (return empty ExtendedTags if blank)
* - Check the PackedTags1 mini-ECC (correct if necessary/possible)
* - Convert PackedTags1 to ExtendedTags
- * - Update ecc
Result and blockB
ad members to refect state.
+ * - Update ecc
_result and block_b
ad members to refect state.
*
* Returns YAFFS_OK or YAFFS_FAIL.
*/
*
* Returns YAFFS_OK or YAFFS_FAIL.
*/
-int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_
Device
*dev,
- int
chunkInNAND, __u8 *data, yaffs_ExtendedT
ags *etags)
+int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_
dev_t
*dev,
+ int
nand_chunk, __u8 *data, yaffs_ext_t
ags *etags)
{
{
- struct mtd_info *mtd =
dev->genericDevice
;
- int chunkBytes = dev->
nDataBytesPerC
hunk;
- loff_t addr = ((loff_t)
chunkInNAND
) * chunkBytes;
+ struct mtd_info *mtd =
yaffs_dev_to_mtd(dev)
;
+ int chunkBytes = dev->
data_bytes_per_c
hunk;
+ loff_t addr = ((loff_t)
nand_chunk
) * chunkBytes;
int eccres = YAFFS_ECC_RESULT_NO_ERROR;
struct mtd_oob_ops ops;
yaffs_PackedTags1 pt1;
int retval;
int deleted;
int eccres = YAFFS_ECC_RESULT_NO_ERROR;
struct mtd_oob_ops ops;
yaffs_PackedTags1 pt1;
int retval;
int deleted;
- dev->nPageReads++;
-
memset(&ops, 0, sizeof(ops));
ops.mode = MTD_OOB_AUTO;
ops.len = (data) ? chunkBytes : 0;
memset(&ops, 0, sizeof(ops));
ops.mode = MTD_OOB_AUTO;
ops.len = (data) ? chunkBytes : 0;
@@
-200,9
+197,9
@@
int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
*/
retval = mtd->read_oob(mtd, addr, &ops);
if (retval) {
*/
retval = mtd->read_oob(mtd, addr, &ops);
if (retval) {
-
yaffs_trace
(YAFFS_TRACE_MTD,
-
"read_oob failed, chunk %d, mtd error %d\n"
,
-
chunkInNAND, retval
);
+
T
(YAFFS_TRACE_MTD,
+
(TSTR("read_oob failed, chunk %d, mtd error %d"TENDSTR)
,
+
nand_chunk, retval)
);
}
switch (retval) {
}
switch (retval) {
@@
-213,23
+210,23
@@
int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
case -EUCLEAN:
/* MTD's ECC fixed the data */
eccres = YAFFS_ECC_RESULT_FIXED;
case -EUCLEAN:
/* MTD's ECC fixed the data */
eccres = YAFFS_ECC_RESULT_FIXED;
- dev->
eccF
ixed++;
+ dev->
n_ecc_f
ixed++;
break;
case -EBADMSG:
/* MTD's ECC could not fix the data */
break;
case -EBADMSG:
/* MTD's ECC could not fix the data */
- dev->
eccU
nfixed++;
+ dev->
n_ecc_u
nfixed++;
/* fall into... */
default:
rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0);
/* fall into... */
default:
rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0);
- etags->block
B
ad = (mtd->block_isbad)(mtd, addr);
+ etags->block
_b
ad = (mtd->block_isbad)(mtd, addr);
return YAFFS_FAIL;
}
/* Check for a blank/erased chunk.
*/
return YAFFS_FAIL;
}
/* Check for a blank/erased chunk.
*/
- if (yaffs_
CheckFF
((__u8 *)&pt1, 8)) {
- /* when blank, upper layers want ecc
R
esult to be <= NO_ERROR */
+ if (yaffs_
check_ff
((__u8 *)&pt1, 8)) {
+ /* when blank, upper layers want ecc
_r
esult to be <= NO_ERROR */
return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK);
}
return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK);
}
@@
-241,37
+238,37
@@
int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
deleted = !pt1.deleted;
pt1.deleted = 1;
#else
deleted = !pt1.deleted;
pt1.deleted = 1;
#else
- deleted = (yaffs_
CountB
its(((__u8 *)&pt1)[8]) < 7);
+ deleted = (yaffs_
count_b
its(((__u8 *)&pt1)[8]) < 7);
#endif
/* Check the packed tags mini-ECC and correct if necessary/possible.
*/
#endif
/* Check the packed tags mini-ECC and correct if necessary/possible.
*/
- retval = yaffs_
CheckECCOnTags((yaffs_Tags
*)&pt1);
+ retval = yaffs_
check_tags_ecc((yaffs_tags_t
*)&pt1);
switch (retval) {
case 0:
/* no tags error, use MTD result */
break;
case 1:
/* recovered tags-ECC error */
switch (retval) {
case 0:
/* no tags error, use MTD result */
break;
case 1:
/* recovered tags-ECC error */
- dev->
tagsEccF
ixed++;
+ dev->
n_tags_ecc_f
ixed++;
if (eccres == YAFFS_ECC_RESULT_NO_ERROR)
eccres = YAFFS_ECC_RESULT_FIXED;
break;
default:
/* unrecovered tags-ECC error */
if (eccres == YAFFS_ECC_RESULT_NO_ERROR)
eccres = YAFFS_ECC_RESULT_FIXED;
break;
default:
/* unrecovered tags-ECC error */
- dev->
tagsEccU
nfixed++;
+ dev->
n_tags_ecc_u
nfixed++;
return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL);
}
/* Unpack the tags to extended form and set ECC result.
return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL);
}
/* Unpack the tags to extended form and set ECC result.
- * [set shouldBeFF just to keep yaffs_
UnpackT
ags1 happy]
+ * [set shouldBeFF just to keep yaffs_
unpack_t
ags1 happy]
*/
pt1.shouldBeFF = 0xFFFFFFFF;
*/
pt1.shouldBeFF = 0xFFFFFFFF;
- yaffs_
UnpackT
ags1(etags, &pt1);
- etags->ecc
R
esult = eccres;
+ yaffs_
unpack_t
ags1(etags, &pt1);
+ etags->ecc
_r
esult = eccres;
/* Set deleted state */
/* Set deleted state */
- etags->
chunkD
eleted = deleted;
+ etags->
is_d
eleted = deleted;
return YAFFS_OK;
}
return YAFFS_OK;
}
@@
-282,15
+279,15
@@
int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
*
* Returns YAFFS_OK or YAFFS_FAIL.
*/
*
* Returns YAFFS_OK or YAFFS_FAIL.
*/
-int nandmtd1_MarkNANDBlockBad(struct yaffs_
DeviceStruct *dev, int blockN
o)
+int nandmtd1_MarkNANDBlockBad(struct yaffs_
dev_s *dev, int block_n
o)
{
{
- struct mtd_info *mtd =
dev->genericDevice
;
- int blocksize = dev->
nChunksPerBlock * dev->nDataBytesPerC
hunk;
+ struct mtd_info *mtd =
yaffs_dev_to_mtd(dev)
;
+ int blocksize = dev->
param.chunks_per_block * dev->data_bytes_per_c
hunk;
int retval;
int retval;
-
yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad\n", blockNo
);
+
T(YAFFS_TRACE_BAD_BLOCKS,(TSTR("marking block %d bad"TENDSTR), block_no)
);
- retval = mtd->block_markbad(mtd, (loff_t)blocksize * block
N
o);
+ retval = mtd->block_markbad(mtd, (loff_t)blocksize * block
_n
o);
return (retval) ? YAFFS_FAIL : YAFFS_OK;
}
return (retval) ? YAFFS_FAIL : YAFFS_OK;
}
@@
-305,9
+302,9
@@
static int nandmtd1_TestPrerequists(struct mtd_info *mtd)
int oobavail = mtd->ecclayout->oobavail;
if (oobavail < YTAG1_SIZE) {
int oobavail = mtd->ecclayout->oobavail;
if (oobavail < YTAG1_SIZE) {
-
yaffs_trace
(YAFFS_TRACE_ERROR,
-
"mtd device has only %d bytes for tags, need %d\n"
,
- oobavail, YTAG1_SIZE);
+
T
(YAFFS_TRACE_ERROR,
+
(TSTR("mtd device has only %d bytes for tags, need %d"TENDSTR)
,
+ oobavail, YTAG1_SIZE)
)
;
return YAFFS_FAIL;
}
return YAFFS_OK;
return YAFFS_FAIL;
}
return YAFFS_OK;
@@
-322,13
+319,13
@@
static int nandmtd1_TestPrerequists(struct mtd_info *mtd)
*
* Always returns YAFFS_OK.
*/
*
* Always returns YAFFS_OK.
*/
-int nandmtd1_QueryNANDBlock(struct yaffs_
DeviceStruct *dev, int blockN
o,
- yaffs_
BlockState
*pState, __u32 *pSequenceNumber)
+int nandmtd1_QueryNANDBlock(struct yaffs_
dev_s *dev, int block_n
o,
+ yaffs_
block_state_t
*pState, __u32 *pSequenceNumber)
{
{
- struct mtd_info *mtd =
dev->genericDevice
;
- int chunkNo = block
No * dev->nChunksPerB
lock;
- loff_t addr = (loff_t)chunkNo * dev->
nDataBytesPerC
hunk;
- yaffs_
ExtendedT
ags etags;
+ struct mtd_info *mtd =
yaffs_dev_to_mtd(dev)
;
+ int chunkNo = block
_no * dev->param.chunks_per_b
lock;
+ loff_t addr = (loff_t)chunkNo * dev->
data_bytes_per_c
hunk;
+ yaffs_
ext_t
ags etags;
int state = YAFFS_BLOCK_STATE_DEAD;
int seqnum = 0;
int retval;
int state = YAFFS_BLOCK_STATE_DEAD;
int seqnum = 0;
int retval;
@@
-336,22
+333,21
@@
int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
/* We don't yet have a good place to test for MTD config prerequists.
* Do it here as we are called during the initial scan.
*/
/* We don't yet have a good place to test for MTD config prerequists.
* Do it here as we are called during the initial scan.
*/
- if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK)
{
+ if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK)
return YAFFS_FAIL;
return YAFFS_FAIL;
- }
retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags);
retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags);
- etags.block
B
ad = (mtd->block_isbad)(mtd, addr);
- if (etags.block
B
ad) {
-
yaffs_trace
(YAFFS_TRACE_BAD_BLOCKS,
-
"block %d is marked bad\n", blockNo
);
+ etags.block
_b
ad = (mtd->block_isbad)(mtd, addr);
+ if (etags.block
_b
ad) {
+
T
(YAFFS_TRACE_BAD_BLOCKS,
+
(TSTR("block %d is marked bad"TENDSTR), block_no)
);
state = YAFFS_BLOCK_STATE_DEAD;
state = YAFFS_BLOCK_STATE_DEAD;
- } else if (etags.ecc
R
esult != YAFFS_ECC_RESULT_NO_ERROR) {
+ } else if (etags.ecc
_r
esult != YAFFS_ECC_RESULT_NO_ERROR) {
/* bad tags, need to look more closely */
state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
/* bad tags, need to look more closely */
state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
- } else if (etags.chunk
U
sed) {
+ } else if (etags.chunk
_u
sed) {
state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
- seqnum = etags.seq
uenceN
umber;
+ seqnum = etags.seq
_n
umber;
} else {
state = YAFFS_BLOCK_STATE_EMPTY;
}
} else {
state = YAFFS_BLOCK_STATE_EMPTY;
}