From: Miquel RAYNAL <miquel.raynal@free-electrons.com>
To: Boris Brezillon <boris.brezillon@free-electrons.com>
Cc: Richard Weinberger <richard@nod.at>,
David Woodhouse <dwmw2@infradead.org>,
Brian Norris <computersforpeace@gmail.com>,
Marek Vasut <marek.vasut@gmail.com>,
Cyrille Pitchen <cyrille.pitchen@wedev4u.fr>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mtd: nand: fix lack of oob layout when using no ecc
Date: Mon, 10 Jul 2017 13:35:48 +0200 [thread overview]
Message-ID: <20170710133548.1d151b15@xps13> (raw)
In-Reply-To: <20170710132713.64198b70@bbrezillon>
On Mon, 10 Jul 2017 13:27:13 +0200
Boris Brezillon <boris.brezillon@free-electrons.com> wrote:
> On Mon, 10 Jul 2017 12:37:26 +0200
> Miquel Raynal <miquel.raynal@free-electrons.com> wrote:
>
> > Fix nand core lack of OOB layout when:
> > - the NFC driver does not provide any OOB layout,
> > - ECC operations are disabled (using NAND_ECC_NONE).
> > Using this configuration leads to a crash during the probe.
> >
> > Add layout functions for small and large pages with mainly free
> > bytes plus reserved space for bad block markers.
> >
> > Check the configuration and eventually assign this OOB layout in
> > nand_scan_tail().
> >
> > Bad block markers position was extracted from the existing OOB
> > layouts by assigning as free all the bytes marked as ECC.
> >
> > Signed-off-by: Miquel Raynal <miquel.raynal@free-electrons.com>
> > ---
> > drivers/mtd/nand/nand_base.c | 75
> > +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74
> > insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mtd/nand/nand_base.c
> > b/drivers/mtd/nand/nand_base.c index c5221795a1e8..28ff58e4385f
> > 100644 --- a/drivers/mtd/nand/nand_base.c
> > +++ b/drivers/mtd/nand/nand_base.c
> > @@ -53,7 +53,45 @@ static int nand_get_device(struct mtd_info *mtd,
> > int new_state); static int nand_do_write_oob(struct mtd_info *mtd,
> > loff_t to, struct mtd_oob_ops *ops);
> >
> > -/* Define default oob placement schemes for large and small page
> > devices */ +/*
> > + * Define default OOB placement schemes for:
> > + * - no ECC or software ECC
> > + * - small or large page devices
> > + */
> > +static int nand_ooblayout_ecc_sp_bbm_only(struct mtd_info *mtd,
> > int section,
> > + struct mtd_oob_region
> > *oobregion)
>
> Can you suffix it with _no_ecc instead of _bbm_only?
Sure, I will send a v2.
>
> Looks good otherwise.
>
> > +{
> > + return -ERANGE;
> > +}
> > +
> > +static int nand_ooblayout_free_sp_bbm_only(struct mtd_info *mtd,
> > int section,
> > + struct mtd_oob_region
> > *oobregion) +{
> > + if (section > 1)
> > + return -ERANGE;
> > +
> > + if (!section) {
> > + if (mtd->oobsize == 16) {
> > + oobregion->offset = 0;
> > + oobregion->length = 4;
> > + } else {
> > + oobregion->offset = 0;
> > + oobregion->length = 5;
> > + }
> > + } else {
> > + oobregion->offset = 6;
> > + oobregion->length = mtd->oobsize -
> > oobregion->offset;
> > + }
> > +
> > + return 0;
> > +}
> > +
> > +const struct mtd_ooblayout_ops nand_ooblayout_sp_bbm_only_ops = {
> > + .ecc = nand_ooblayout_ecc_sp_bbm_only,
> > + .free = nand_ooblayout_free_sp_bbm_only,
> > +};
> > +EXPORT_SYMBOL_GPL(nand_ooblayout_sp_bbm_only_ops);
> > +
> > static int nand_ooblayout_ecc_sp(struct mtd_info *mtd, int section,
> > struct mtd_oob_region *oobregion)
> > {
> > @@ -109,6 +147,30 @@ const struct mtd_ooblayout_ops
> > nand_ooblayout_sp_ops = { };
> > EXPORT_SYMBOL_GPL(nand_ooblayout_sp_ops);
> >
> > +static int nand_ooblayout_ecc_lp_bbm_only(struct mtd_info *mtd,
> > int section,
> > + struct mtd_oob_region
> > *oobregion) +{
> > + return -ERANGE;
> > +}
> > +
> > +static int nand_ooblayout_free_lp_bbm_only(struct mtd_info *mtd,
> > int section,
> > + struct mtd_oob_region
> > *oobregion) +{
> > + if (section)
> > + return -ERANGE;
> > +
> > + oobregion->offset = 2;
> > + oobregion->length = mtd->oobsize - oobregion->offset;
> > +
> > + return 0;
> > +}
> > +
> > +const struct mtd_ooblayout_ops nand_ooblayout_lp_bbm_only_ops = {
> > + .ecc = nand_ooblayout_ecc_lp_bbm_only,
> > + .free = nand_ooblayout_free_lp_bbm_only,
> > +};
> > +EXPORT_SYMBOL_GPL(nand_ooblayout_lp_bbm_only_ops);
> > +
> > static int nand_ooblayout_ecc_lp(struct mtd_info *mtd, int section,
> > struct mtd_oob_region *oobregion)
> > {
> > @@ -4635,6 +4697,17 @@ int nand_scan_tail(struct mtd_info *mtd)
> > chip->oob_poi = chip->buffers->databuf + mtd->writesize;
> >
> > /*
> > + * When using ECC_NONE, ooblayout must only reserve space
> > for bad block
> > + * markers.
> > + */
> > + if (!mtd->ooblayout && ecc->mode == NAND_ECC_NONE) {
> > + if (mtd->writesize <= 512)
> > + mtd_set_ooblayout(mtd,
> > &nand_ooblayout_sp_bbm_only_ops);
> > + else
> > + mtd_set_ooblayout(mtd,
> > &nand_ooblayout_lp_bbm_only_ops);
> > + }
> > +
> > + /*
> > * If no default placement scheme is given, select an
> > appropriate one. */
> > if (!mtd->ooblayout &&
>
next prev parent reply other threads:[~2017-07-10 11:36 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-10 10:37 [PATCH] mtd: nand: fix lack of oob layout when using no ecc Miquel Raynal
2017-07-10 10:37 ` Miquel Raynal
2017-07-10 11:27 ` Boris Brezillon
2017-07-10 11:35 ` Miquel RAYNAL [this message]
2017-07-10 11:35 ` Boris Brezillon
2017-07-10 12:05 ` [PATCH v2] " Miquel RAYNAL
2017-07-18 7:53 ` Boris Brezillon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170710133548.1d151b15@xps13 \
--to=miquel.raynal@free-electrons.com \
--cc=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=cyrille.pitchen@wedev4u.fr \
--cc=dwmw2@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=marek.vasut@gmail.com \
--cc=richard@nod.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.