From: =?ISO-8859-1?Q?J=F6rg?= Krause Date: Thu, 12 Jul 2018 08:17:32 +0200 Subject: [U-Boot] [PATCH v4 2/6] mtd: nand: mxs_nand: use self init In-Reply-To: <20180622151951.12851-3-stefan@agner.ch> References: <20180622151951.12851-1-stefan@agner.ch> <20180622151951.12851-3-stefan@agner.ch> Message-ID: List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: u-boot@lists.denx.de Hi Stefan, this patch crashes my NAND SPL loader on an i.MX6ULL board. See below my comment about `scan_bbt`. On Fri, 2018-06-22 at 17:19 +0200, Stefan Agner wrote: > From: Stefan Agner >=20 > Instead of completing initialization via scan_bbt callback use > NAND self init to initialize the GPMI (MXS) NAND controller. >=20 > Suggested-by: Scott Wood > Signed-off-by: Stefan Agner > --- >=20 > Changes in v4: > - Update SPL driver accordingly >=20 > Changes in v3: > - Fix indentation >=20 > Changes in v2: None >=20 > drivers/mtd/nand/Kconfig | 1 + > drivers/mtd/nand/mxs_nand.c | 53 ++++++++++++++++++++----------------- > drivers/mtd/nand/mxs_nand.h | 1 + > 3 files changed, 31 insertions(+), 24 deletions(-) >=20 > diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig > index 94fbf89e4b..4db259fcb2 100644 > --- a/drivers/mtd/nand/Kconfig > +++ b/drivers/mtd/nand/Kconfig > @@ -143,6 +143,7 @@ config NAND_MXC > config NAND_MXS > bool "MXS NAND support" > depends on MX23 || MX28 || MX6 || MX7 > + select SYS_NAND_SELF_INIT > imply CMD_NAND > select APBH_DMA > select APBH_DMA_BURST if ARCH_MX6 || ARCH_MX7 > diff --git a/drivers/mtd/nand/mxs_nand.c b/drivers/mtd/nand/mxs_nand.c > index 5b7ad18c42..14d3210017 100644 > --- a/drivers/mtd/nand/mxs_nand.c > +++ b/drivers/mtd/nand/mxs_nand.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -47,6 +48,7 @@ > #define MXS_NAND_BCH_TIMEOUT 10000 > =20 > struct mxs_nand_info { > + struct nand_chip chip; > int cur_chip; > =20 > uint32_t cmd_queue_len; > @@ -972,20 +974,15 @@ static int mxs_nand_block_bad(struct mtd_info *mtd,= loff_t ofs) > } > =20 > /* > - * Nominally, the purpose of this function is to look for or create the = bad > - * block table. In fact, since the we call this function at the very end= of > - * the initialization process started by nand_scan(), and we doesn't hav= e a > - * more formal mechanism, we "hook" this function to continue init proce= ss. > - * > * At this point, the physical NAND Flash chips have been identified and > * counted, so we know the physical geometry. This enables us to make so= me > * important configuration decisions. > * > * The return value of this function propagates directly back to this dr= iver's > - * call to nand_scan(). Anything other than zero will cause this driver = to > + * board_nand_init(). Anything other than zero will cause this driver to > * tear everything down and declare failure. > */ > -static int mxs_nand_scan_bbt(struct mtd_info *mtd) > +int mxs_nand_setup_ecc(struct mtd_info *mtd) > { > struct nand_chip *nand =3D mtd_to_nand(mtd); > struct mxs_nand_info *nand_info =3D nand_get_controller_data(nand); > @@ -1047,8 +1044,7 @@ static int mxs_nand_scan_bbt(struct mtd_info *mtd) > mtd->_block_markbad =3D mxs_nand_hook_block_markbad; > } > =20 > - /* We use the reference implementation for bad block management. */ > - return nand_default_bbt(mtd); > + return 0; > } > =20 > /* > @@ -1177,7 +1173,6 @@ int mxs_nand_init_spl(struct nand_chip *nand) > nand->cmd_ctrl =3D mxs_nand_cmd_ctrl; > nand->dev_ready =3D mxs_nand_device_ready; > nand->select_chip =3D mxs_nand_select_chip; > - nand->scan_bbt =3D mxs_nand_scan_bbt; The NAND SPL loader trace is nand_spl_load_image() -> mxs_nand_init() -> nand_chip.scan_bbt(mtd) [1]. Because the function pointer is invalid, the SPL loader crashes and the board resets. > nand->read_byte =3D mxs_nand_read_byte; > nand->read_buf =3D mxs_nand_read_buf; > @@ -1192,27 +1187,22 @@ int mxs_nand_init_spl(struct nand_chip *nand) > return 0; > } > =20 > -/*! > - * This function is called during the driver binding process. > - * > - * @param pdev the device structure used to store device specific > - * information that is used by the suspend, resume and > - * remove functions > - * > - * @return The function always returns 0. > - */ > -int board_nand_init(struct nand_chip *nand) > +void board_nand_init(void) > { > + struct mtd_info *mtd; > struct mxs_nand_info *nand_info; > + struct nand_chip *nand; > int err; > =20 > nand_info =3D malloc(sizeof(struct mxs_nand_info)); > if (!nand_info) { > printf("MXS NAND: Failed to allocate private data\n"); > - return -ENOMEM; > + return; > } > memset(nand_info, 0, sizeof(struct mxs_nand_info)); > =20 > + nand =3D &nand_info->chip; > + mtd =3D nand_to_mtd(nand); > err =3D mxs_nand_alloc_buffers(nand_info); > if (err) > goto err1; > @@ -1231,13 +1221,19 @@ int board_nand_init(struct nand_chip *nand) > nand->dev_ready =3D mxs_nand_device_ready; > nand->select_chip =3D mxs_nand_select_chip; > nand->block_bad =3D mxs_nand_block_bad; > - nand->scan_bbt =3D mxs_nand_scan_bbt; > =20 > nand->read_byte =3D mxs_nand_read_byte; > =20 > nand->read_buf =3D mxs_nand_read_buf; > nand->write_buf =3D mxs_nand_write_buf; > =20 > + /* first scan to find the device and get the page size */ > + if (nand_scan_ident(mtd, CONFIG_SYS_MAX_NAND_DEVICE, NULL)) > + goto err2; > + > + if (mxs_nand_setup_ecc(mtd)) > + goto err2; > + > nand->ecc.read_page =3D mxs_nand_ecc_read_page; > nand->ecc.write_page =3D mxs_nand_ecc_write_page; > nand->ecc.read_oob =3D mxs_nand_ecc_read_oob; > @@ -1249,12 +1245,21 @@ int board_nand_init(struct nand_chip *nand) > nand->ecc.size =3D 512; > nand->ecc.strength =3D 8; > =20 > - return 0; > + /* second phase scan */ > + err =3D nand_scan_tail(mtd); > + if (err) > + goto err2; > + > + err =3D nand_register(0, mtd); > + if (err) > + goto err2; > + > + return; > =20 > err2: > free(nand_info->data_buf); > free(nand_info->cmd_buf); > err1: > free(nand_info); > - return err; > + return; > } > diff --git a/drivers/mtd/nand/mxs_nand.h b/drivers/mtd/nand/mxs_nand.h > index 9bb7148d98..379ed24f05 100644 > --- a/drivers/mtd/nand/mxs_nand.h > +++ b/drivers/mtd/nand/mxs_nand.h > @@ -8,3 +8,4 @@ > */ > =20 > int mxs_nand_init_spl(struct nand_chip *nand); > +int mxs_nand_setup_ecc(struct mtd_info *mtd); [1] http://git.denx.de/?p=3Du-boot.git;a=3Dblob;f=3Ddrivers/mtd/nand/mxs_na= nd_spl.c;h=3D2d7bbe83cce5419ad7030736a4ebd19708d5523f;hb=3D8c5d4fd0ec222701= 598a27b26ab7265d4cee45a3#l202 Best regards, J=C3=B6rg Krause