Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751961AbdHZF7w (ORCPT ); Sat, 26 Aug 2017 01:59:52 -0400 Received: from mail.free-electrons.com ([62.4.15.54]:57207 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750737AbdHZF7u (ORCPT ); Sat, 26 Aug 2017 01:59:50 -0400 Date: Sat, 26 Aug 2017 07:59:38 +0200 From: Boris Brezillon To: Andrea Adami Cc: Dmitry Eremin-Solenikov , Richard Weinberger , Robert Jarzmik , linux-kernel@vger.kernel.org, Haojian Zhuang , Marek Vasut , linux-mtd@lists.infradead.org, Cyrille Pitchen , =?UTF-8?B?UmFmYcWCIE1pxYJlY2tp?= , Brian Norris , David Woodhouse Subject: Re: [PATCH v6] mtd: sharpslpart: Add sharpslpart partition parser Message-ID: <20170826075938.5a9b861d@bbrezillon> In-Reply-To: <20170825001129.091badb4@bbrezillon> References: <1503394972-12541-1-git-send-email-andrea.adami@gmail.com> <20170825001129.091badb4@bbrezillon> X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1992 Lines: 63 On Fri, 25 Aug 2017 00:11:29 +0200 Boris Brezillon wrote: > > +/* > > + * The logical block number assigned to a physical block is stored in the OOB > > + * of the first page, in 3 16-bit copies with the following layout: > > + * > > + * 01234567 89abcdef > > + * -------- -------- > > + * ECC BB xyxyxy > > + * > > + * When reading we check that the first two copies agree. > > + * In case of error, matching is tried using the following pairs. > > + * Reserved values 0xffff mean the block is kept for wear leveling. > > + * > > + * 01234567 89abcdef > > + * -------- -------- > > + * ECC BB xyxy oob[8]==oob[10] && oob[9]==oob[11] -> byte0=8 byte1=9 > > + * ECC BB xyxy oob[10]==oob[12] && oob[11]==oob[13] -> byte0=10 byte1=11 > > + * ECC BB xy xy oob[12]==oob[8] && oob[13]==oob[9] -> byte0=12 byte1=13 > > I know there's a depends on "MTD_NAND_SHARPSL || MTD_NAND_TMIO" in the > Kconfig entry, but one could enable those options just to use the sharpsl > part parser even if the OOB layout is incompatible with the sharpsl FTL. > > I'd recommend that you check that OOB bytes 8 to 15 are actually free > to be used by the MTD user in sharpsl_parse_mtd_partitions(). > > Can be done with something like that: > > static int sharpsl_nand_check_ooblayout(struct mtd_info *mtd) > { > u8 freebytes = 0; > int section = 0; > > while (true) { > struct mtd_oob_region oobfree = { }; > int ret, i; > > ret = mtd_ooblayout_free(mtd, section++, &oobfree); > if (ret) > break; > > if (!oobfree.length || oobfree.offset > 15 || > (oobfree.offset + oobfree.length) < 8) > continue; > > i = oobfree.offset >= 8 ? : 8; As you reported on IRC there's an mistake here, it should be: i = oobfree.offset >= 8 ? oobfree.offset : 8 > for (; i < oobfree.offset + oobfree.length && i < 16; i++) > freebytes |= BIT(i - 8); > > if (freebytes == 0xff) > return 0; > } > > return -ENOTSUPP; > }