[PATCH] [MTD] OneNAND: Add support for auto-placementofout-of-banddata

Kyungmin Park kmpark at infradead.org
Wed Jan 31 22:13:36 EST 2007


>  /**
> + * onenand_transfer_auto_oob - [Internal] oob auto-placement transfer
> + * @param mtd		MTD device structure
> + * @param buf		destination address
> + * @param column	oob offset to read from
> + * @param thislen	oob length to read
> + */
> +static int onenand_transfer_auto_oob(struct mtd_info *mtd, 
> uint8_t *buf, int column,
> +				int thislen)
> +{
> +	struct onenand_chip *this = mtd->priv;
> +	struct nand_oobfree *free;
> +	int readcol = column;
> +	int readend = column + thislen;
> +	int lastgap = 0;
> +	uint8_t *oob_buf = this->page_buf + mtd->writesize;
> +
> +	for (free = this->ecclayout->oobfree; free->length; ++free) {
> +		if (readcol >= lastgap)
> +			readcol += free->offset - lastgap;
> +		if (readend >= lastgap)
> +			readend += free->offset - lastgap;
> +		lastgap = free->offset + free->length;
> +	}
> +	this->read_bufferram(mtd, ONENAND_SPARERAM, oob_buf + readcol,
> +			     readcol, readend - readcol);

How about to read full oobsize? since 32 bytes memcpy is optimized.
Now there are two cases.
case 1: readcol = 2, readend = 36, so read length is 34
case 2: readcol = 2, readend = 64, so read length is 62
Buf if we change to colume = 0, length = 64. we only do 2 loop in memcpy.

this->read_bufferram(mtd, ONENAND_SPARERAM, oob_buf, 0, mtd->oobsize);

The contents of buffer are handled correctly (see below)

> +	for (free = this->ecclayout->oobfree; free->length; ++free) {
> +		int free_end = free->offset + free->length;
> +		if (free->offset < readend && free_end > readcol) {
> +			int st = max_t(int,free->offset,readcol);
> +			int ed = min_t(int,free_end,readend);
> +			int n = ed - st;
> +			memcpy(buf, oob_buf + st, n);
> +			buf += n;
> +		}
> +	}
> +	return 0;
> +}
> +





More information about the linux-mtd mailing list