int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 *data, yaffs_ExtendedTags *etags) { struct mtd_info *mtd = dev->genericDevice; int chunkBytes = dev->nDataBytesPerChunk; loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; int eccres = YAFFS_ECC_RESULT_NO_ERROR; struct mtd_oob_ops ops; yaffs_PackedTags1 pt1; int retval; int deleted; memset(&ops, 0, sizeof(ops)); ops.mode = MTD_OOB_AUTO; ops.len = (data) ? chunkBytes : 0; ops.ooblen = YTAG1_SIZE; ops.datbuf = data; ops.oobbuf = (__u8 *)&pt1; #if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 20)) ops.len = (ops.datbuf) ? ops.len : ops.ooblen; #endif 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); } switch (retval) { case 0: break; case -EUCLEAN: eccres = YAFFS_ECC_RESULT_FIXED; dev->eccFixed++; break; case -EBADMSG: dev->eccUnfixed++; default: rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); etags->blockBad = (mtd->block_isbad)(mtd, addr); return YAFFS_FAIL; } if (yaffs_CheckFF((__u8 *)&pt1, 8)) { return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); } #ifndef CONFIG_YAFFS_9BYTE_TAGS deleted = !pt1.deleted; pt1.deleted = 1; #else deleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); #endif retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); switch (retval) { case 0: break; case 1: dev->tagsEccFixed++; if (eccres == YAFFS_ECC_RESULT_NO_ERROR) eccres = YAFFS_ECC_RESULT_FIXED; break; default: dev->tagsEccUnfixed++; return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL); } pt1.shouldBeFF = 0xFFFFFFFF; yaffs_UnpackTags1(etags, &pt1); etags->eccResult = eccres; etags->chunkDeleted = deleted; return YAFFS_OK; }
/* Read a chunk (page) from NAND. * * Caller expects ExtendedTags data to be usable even on error; that is, * all members except eccResult and blockBad 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 * - Update eccResult and blockBad members to refect state. * * Returns YAFFS_OK or YAFFS_FAIL. */ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 *data, yaffs_ExtendedTags *etags) { struct mtd_info *mtd = yaffs_DeviceToMtd(dev); int chunkBytes = dev->nDataBytesPerChunk; loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; int eccres = YAFFS_ECC_RESULT_NO_ERROR; struct mtd_oob_ops ops; yaffs_PackedTags1 pt1; int retval; int deleted; memset(&ops, 0, sizeof(ops)); ops.mode = MTD_OOB_AUTO; ops.len = (data) ? chunkBytes : 0; ops.ooblen = YTAG1_SIZE; ops.datbuf = data; ops.oobbuf = (__u8 *)&pt1; #if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 20)) /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. */ ops.len = (ops.datbuf) ? ops.len : ops.ooblen; #endif /* Read page and oob using MTD. * Check status and determine ECC result. */ retval = mtd->read_oob(mtd, addr, &ops); if (retval) { T(YAFFS_TRACE_MTD, (TSTR("read_oob failed, chunk %d, mtd error %d"TENDSTR), chunkInNAND, retval)); } switch (retval) { case 0: /* no error */ break; case -EUCLEAN: /* MTD's ECC fixed the data */ eccres = YAFFS_ECC_RESULT_FIXED; dev->eccFixed++; break; case -EBADMSG: /* MTD's ECC could not fix the data */ dev->eccUnfixed++; /* fall into... */ default: rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); etags->blockBad = (mtd->block_isbad)(mtd, addr); return YAFFS_FAIL; } /* Check for a blank/erased chunk. */ if (yaffs_CheckFF((__u8 *)&pt1, 8)) { /* when blank, upper layers want eccResult to be <= NO_ERROR */ return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); } #ifndef CONFIG_YAFFS_9BYTE_TAGS /* Read deleted status (bit) then return it to it's non-deleted * state before performing tags mini-ECC check. pt1.deleted is * inverted. */ deleted = !pt1.deleted; pt1.deleted = 1; #else deleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); #endif /* Check the packed tags mini-ECC and correct if necessary/possible. */ retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); switch (retval) { case 0: /* no tags error, use MTD result */ break; case 1: /* recovered tags-ECC error */ dev->tagsEccFixed++; if (eccres == YAFFS_ECC_RESULT_NO_ERROR) eccres = YAFFS_ECC_RESULT_FIXED; break; default: /* unrecovered tags-ECC error */ dev->tagsEccUnfixed++; 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_UnpackTags1 happy] */ pt1.shouldBeFF = 0xFFFFFFFF; yaffs_UnpackTags1(etags, &pt1); etags->eccResult = eccres; /* Set deleted state */ etags->chunkDeleted = deleted; return YAFFS_OK; }