Exemplo n.º 1
0
int yaffs_CheckECCOnTags(yaffs_Tags * tags)
{
    unsigned ecc = tags->ecc;

    yaffs_CalcTagsECC(tags);

    ecc ^= tags->ecc;

    if (ecc && ecc <= 64) {
        /* TODO: Handle the failure better. Retire? */
        unsigned char *b = ((yaffs_TagsUnion *) tags)->asBytes;

        ecc--;

        b[ecc / 8] ^= (1 << (ecc & 7));

        /* Now recvalc the ecc */
        yaffs_CalcTagsECC(tags);

        return 1;	/* recovered error */
    } else if (ecc) {
        /* Wierd ecc failure value */
        /* TODO Need to do somethiong here */
        return -1;	/* unrecovered error */
    }

    return 0;
}
Exemplo n.º 2
0
int yaffs_CheckECCOnTags(yaffs_Tags * tags)
{
	unsigned ecc = tags->ecc;

	yaffs_CalcTagsECC(tags);

	ecc ^= tags->ecc;

	if (ecc && ecc <= 64) {
		
		unsigned char *b = ((yaffs_TagsUnion *) tags)->asBytes;

		ecc--;

		b[ecc / 8] ^= (1 << (ecc & 7));

		
		yaffs_CalcTagsECC(tags);

		return 1;	
	} else if (ecc) {
		
		
		return -1;	
	}

	return 0;
}
Exemplo n.º 3
0
static void yaffs_LoadTagsIntoSpare(yaffs_Spare * sparePtr,
				    yaffs_Tags * tagsPtr)
{
	yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr;

	yaffs_CalcTagsECC(tagsPtr);

	sparePtr->tagByte0 = tu->asBytes[0];
	sparePtr->tagByte1 = tu->asBytes[1];
	sparePtr->tagByte2 = tu->asBytes[2];
	sparePtr->tagByte3 = tu->asBytes[3];
	sparePtr->tagByte4 = tu->asBytes[4];
	sparePtr->tagByte5 = tu->asBytes[5];
	sparePtr->tagByte6 = tu->asBytes[6];
	sparePtr->tagByte7 = tu->asBytes[7];

#if defined(CONFIG_MOT_FEAT_MTD_FS) && defined(YAFFS_OOB_DEBUG) 
        if (mtd_fs_runtime_info >= 2)
        {
            printk("%s: (Before Write)\n",__FUNCTION__);
            printk("  Tags: chunkId=%d, SN=%d, byteCount=%d, OId=%d\n",
                      tagsPtr->chunkId, tagsPtr->serialNumber, tagsPtr->byteCount,
                      tagsPtr->objectId);
            printk("  Spare: tagByte0=0x%x, tagByte1=0x%x, tagByte2=0x%x, tagByte3=0x%x\n",
                   sparePtr->tagByte0, sparePtr->tagByte1, sparePtr->tagByte2,sparePtr->tagByte3);
            printk("         tagByte4=0x%x, tagByte5=0x%x, tagByte6=0x%x, tagByte7=0x%x\n",
                   sparePtr->tagByte4, sparePtr->tagByte5, sparePtr->tagByte6,sparePtr->tagByte7);
            printk("         pageStatus=0x%x\n",sparePtr->pageStatus);
        }
#endif

}
Exemplo n.º 4
0
/* Write a chunk (page) of data to NAND.
 *
 * Caller always provides ExtendedTags data which are converted to a more
 * compact (packed) form for storage in NAND.  A mini-ECC runs over the
 * contents of the tags meta-data; used to valid the tags when read.
 *
 *  - Pack ExtendedTags to PackedTags1 form
 *  - Compute mini-ECC for PackedTags1
 *  - Write data and packed tags to NAND.
 *
 * Note: Due to the use of the PackedTags1 meta-data which does not include
 * a full sequence number (as found in the larger PackedTags2 form) it is
 * necessary for Yaffs to re-write a chunk/page (just once) to mark it as
 * discarded and dirty.  This is not ideal: newer NAND parts are supposed
 * to be written just once.  When Yaffs performs this operation, this
 * function is called with a NULL data pointer -- calling MTD write_oob
 * without data is valid usage (2.6.17).
 *
 * 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_ExtendedTags * etags)
{
	struct mtd_info * mtd = dev->genericDevice;
	int chunkBytes = dev->nDataBytesPerChunk;
	loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
	struct mtd_oob_ops ops;
	yaffs_PackedTags1 pt1;
	int retval;

	/* we assume that PackedTags1 and yaffs_Tags are compatible */
	compile_time_assertion(sizeof(yaffs_PackedTags1) == 12);
	compile_time_assertion(sizeof(yaffs_Tags) == 8);

	dev->nPageWrites++;

	yaffs_PackTags1(&pt1, etags);
	yaffs_CalcTagsECC((yaffs_Tags *)&pt1);

	/* When deleting a chunk, the upper layer provides only skeletal
	 * etags, one with chunkDeleted 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
	if (etags->chunkDeleted) {
		memset(&pt1, 0xff, 8);
		/* clear delete status bit to indicate deleted */
		pt1.deleted = 0;
	}
#else
	((__u8 *)&pt1)[8] = 0xff;
	if (etags->chunkDeleted) {
		memset(&pt1, 0xff, 8);
		/* zero pageStatus byte to indicate deleted */
		((__u8 *)&pt1)[8] = 0;
	}
#endif

	memset(&ops, 0, sizeof(ops));
	ops.mode = MTD_OOB_AUTO;
	ops.len = (data) ? chunkBytes : 0;
	ops.ooblen = YTAG1_SIZE;
	ops.datbuf = (__u8 *)data;
	ops.oobbuf = (__u8 *)&pt1;

	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);
	}
	return retval ? YAFFS_FAIL : YAFFS_OK;
}
Exemplo n.º 5
0
int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev,
	int chunkInNAND, const __u8 *data, const yaffs_ExtendedTags *etags)
{
	struct mtd_info *mtd = dev->genericDevice;
	int chunkBytes = dev->nDataBytesPerChunk;
	loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
	struct mtd_oob_ops ops;
	yaffs_PackedTags1 pt1;
	int retval;

	
	compile_time_assertion(sizeof(yaffs_PackedTags1) == 12);
	compile_time_assertion(sizeof(yaffs_Tags) == 8);

	yaffs_PackTags1(&pt1, etags);
	yaffs_CalcTagsECC((yaffs_Tags *)&pt1);

	
#ifndef CONFIG_YAFFS_9BYTE_TAGS
	if (etags->chunkDeleted) {
		memset(&pt1, 0xff, 8);
		
		pt1.deleted = 0;
	}
#else
	((__u8 *)&pt1)[8] = 0xff;
	if (etags->chunkDeleted) {
		memset(&pt1, 0xff, 8);
		
		((__u8 *)&pt1)[8] = 0;
	}
#endif

	memset(&ops, 0, sizeof(ops));
	ops.mode = MTD_OOB_AUTO;
	ops.len = (data) ? chunkBytes : 0;
	ops.ooblen = YTAG1_SIZE;
	ops.datbuf = (__u8 *)data;
	ops.oobbuf = (__u8 *)&pt1;

	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);
	}
	return retval ? YAFFS_FAIL : YAFFS_OK;
}
Exemplo n.º 6
0
static void yaffs_LoadTagsIntoSpare(yaffs_Spare * sparePtr,
                                    yaffs_Tags * tagsPtr)
{
    yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr;

    yaffs_CalcTagsECC(tagsPtr);

    sparePtr->tagByte0 = tu->asBytes[0];
    sparePtr->tagByte1 = tu->asBytes[1];
    sparePtr->tagByte2 = tu->asBytes[2];
    sparePtr->tagByte3 = tu->asBytes[3];
    sparePtr->tagByte4 = tu->asBytes[4];
    sparePtr->tagByte5 = tu->asBytes[5];
    sparePtr->tagByte6 = tu->asBytes[6];
    sparePtr->tagByte7 = tu->asBytes[7];
}
Exemplo n.º 7
0
static void yaffs_LoadTagsIntoSpare(yaffs_Spare * sparePtr,
				    yaffs_Tags * tagsPtr)
{
	printk("CALL [%s]\n", __FUNCTION__);	//Ken
	yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr;

	yaffs_CalcTagsECC(tagsPtr);

	sparePtr->tagByte0 = tu->asBytes[0];
	sparePtr->tagByte1 = tu->asBytes[1];
	sparePtr->tagByte2 = tu->asBytes[2];
	sparePtr->tagByte3 = tu->asBytes[3];
	sparePtr->tagByte4 = tu->asBytes[4];
	sparePtr->tagByte5 = tu->asBytes[5];
	sparePtr->tagByte6 = tu->asBytes[6];
	sparePtr->tagByte7 = tu->asBytes[7];
}