* [PATCH v2] mtd: nand: imx-bbm: use raw reading when checking for factory BBM
@ 2016-07-08 7:25 Uwe Kleine-König
2016-07-11 5:48 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2016-07-08 7:25 UTC (permalink / raw)
To: barebox
This is necessary to prevent the imx_nand_bbm command to bail out
on ECC errors which leaves the device without BBT.
Also simplify buffer management: Use on-stack buffer instead of malloc.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
Changes since (implicit) v1 sent with Message-Id: 1467884923-24060-1-git-send-email-u.kleine-koenig@pengutronix.de:
- drop two now unused variables fixing two compiler warnings
drivers/mtd/nand/nand_imx_bbm.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)
diff --git a/drivers/mtd/nand/nand_imx_bbm.c b/drivers/mtd/nand/nand_imx_bbm.c
index 251dfe5d3f12..23722a906473 100644
--- a/drivers/mtd/nand/nand_imx_bbm.c
+++ b/drivers/mtd/nand/nand_imx_bbm.c
@@ -52,12 +52,20 @@
* on the flash BBT.
*
*/
-static int checkbad(struct mtd_info *mtd, loff_t ofs, void *__buf)
+static int checkbad(struct mtd_info *mtd, loff_t ofs)
{
- int ret, retlen;
- uint8_t *buf = __buf;
-
- ret = mtd->read(mtd, ofs, mtd->writesize, &retlen, buf);
+ int ret;
+ uint8_t buf[mtd->writesize + mtd->oobsize];
+ struct mtd_oob_ops ops;
+
+ ops.mode = MTD_OPS_RAW;
+ ops.ooboffs = 0;
+ ops.datbuf = buf;
+ ops.len = mtd->writesize;
+ ops.oobbuf = buf + mtd->writesize;
+ ops.ooblen = mtd->oobsize;
+
+ ret = mtd_read_oob(mtd, ofs, &ops);
if (ret < 0)
return ret;
@@ -72,7 +80,6 @@ static void *create_bbt(struct mtd_info *mtd)
struct nand_chip *chip = mtd->priv;
int len, i, numblocks, ret;
loff_t from = 0;
- void *buf;
uint8_t *bbt;
if ((chip->bbt_td && chip->bbt_td->pages[0] != -1) ||
@@ -88,18 +95,12 @@ static void *create_bbt(struct mtd_info *mtd)
if (!bbt)
return ERR_PTR(-ENOMEM);
- buf = malloc(mtd->writesize);
- if (!buf) {
- ret = -ENOMEM;
- goto out2;
- }
-
numblocks = mtd->size >> (chip->bbt_erase_shift - 1);
for (i = 0; i < numblocks;) {
- ret = checkbad(mtd, from, buf);
+ ret = checkbad(mtd, from);
if (ret < 0)
- goto out1;
+ goto out;
if (ret) {
bbt[i >> 3] |= 0x03 << (i & 0x6);
@@ -113,9 +114,7 @@ static void *create_bbt(struct mtd_info *mtd)
return bbt;
-out1:
- free(buf);
-out2:
+out:
free(bbt);
return ERR_PTR(ret);
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mtd: nand: imx-bbm: use raw reading when checking for factory BBM
2016-07-08 7:25 [PATCH v2] mtd: nand: imx-bbm: use raw reading when checking for factory BBM Uwe Kleine-König
@ 2016-07-11 5:48 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2016-07-11 5:48 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Fri, Jul 08, 2016 at 09:25:43AM +0200, Uwe Kleine-König wrote:
> This is necessary to prevent the imx_nand_bbm command to bail out
> on ECC errors which leaves the device without BBT.
>
> Also simplify buffer management: Use on-stack buffer instead of malloc.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> Changes since (implicit) v1 sent with Message-Id: 1467884923-24060-1-git-send-email-u.kleine-koenig@pengutronix.de:
>
> - drop two now unused variables fixing two compiler warnings
>
> drivers/mtd/nand/nand_imx_bbm.c | 33 ++++++++++++++++-----------------
> 1 file changed, 16 insertions(+), 17 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/drivers/mtd/nand/nand_imx_bbm.c b/drivers/mtd/nand/nand_imx_bbm.c
> index 251dfe5d3f12..23722a906473 100644
> --- a/drivers/mtd/nand/nand_imx_bbm.c
> +++ b/drivers/mtd/nand/nand_imx_bbm.c
> @@ -52,12 +52,20 @@
> * on the flash BBT.
> *
> */
> -static int checkbad(struct mtd_info *mtd, loff_t ofs, void *__buf)
> +static int checkbad(struct mtd_info *mtd, loff_t ofs)
> {
> - int ret, retlen;
> - uint8_t *buf = __buf;
> -
> - ret = mtd->read(mtd, ofs, mtd->writesize, &retlen, buf);
> + int ret;
> + uint8_t buf[mtd->writesize + mtd->oobsize];
> + struct mtd_oob_ops ops;
> +
> + ops.mode = MTD_OPS_RAW;
> + ops.ooboffs = 0;
> + ops.datbuf = buf;
> + ops.len = mtd->writesize;
> + ops.oobbuf = buf + mtd->writesize;
> + ops.ooblen = mtd->oobsize;
> +
> + ret = mtd_read_oob(mtd, ofs, &ops);
> if (ret < 0)
> return ret;
>
> @@ -72,7 +80,6 @@ static void *create_bbt(struct mtd_info *mtd)
> struct nand_chip *chip = mtd->priv;
> int len, i, numblocks, ret;
> loff_t from = 0;
> - void *buf;
> uint8_t *bbt;
>
> if ((chip->bbt_td && chip->bbt_td->pages[0] != -1) ||
> @@ -88,18 +95,12 @@ static void *create_bbt(struct mtd_info *mtd)
> if (!bbt)
> return ERR_PTR(-ENOMEM);
>
> - buf = malloc(mtd->writesize);
> - if (!buf) {
> - ret = -ENOMEM;
> - goto out2;
> - }
> -
> numblocks = mtd->size >> (chip->bbt_erase_shift - 1);
>
> for (i = 0; i < numblocks;) {
> - ret = checkbad(mtd, from, buf);
> + ret = checkbad(mtd, from);
> if (ret < 0)
> - goto out1;
> + goto out;
>
> if (ret) {
> bbt[i >> 3] |= 0x03 << (i & 0x6);
> @@ -113,9 +114,7 @@ static void *create_bbt(struct mtd_info *mtd)
>
> return bbt;
>
> -out1:
> - free(buf);
> -out2:
> +out:
> free(bbt);
>
> return ERR_PTR(ret);
> --
> 2.8.1
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-07-11 5:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-08 7:25 [PATCH v2] mtd: nand: imx-bbm: use raw reading when checking for factory BBM Uwe Kleine-König
2016-07-11 5:48 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox