mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest
@ 2021-03-30  6:50 Stefan Riedmueller
  2021-03-30  6:50 ` [PATCH 2/4] nandtest: Fix status print for NAND which size exceeds 4 GB Stefan Riedmueller
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stefan Riedmueller @ 2021-03-30  6:50 UTC (permalink / raw)
  To: barebox

NAND_ECC_HW is no longer optional so remove the dependency from
nandtest. Otherwise nandtest won't be build for HW ECC boards.

Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
---
 commands/Kconfig | 1 -
 1 file changed, 1 deletion(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index 6d84c956e576..8e8b5a926fbb 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1884,7 +1884,6 @@ config CMD_NANDTEST
 	tristate
 	depends on NAND
 	depends on PARTITION
-	depends on NAND_ECC_HW || NAND_ECC_SOFT
 	prompt "nandtest"
 	help
 	  NAND flash memory test
-- 
2.25.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/4] nandtest: Fix status print for NAND which size exceeds 4 GB
  2021-03-30  6:50 [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Stefan Riedmueller
@ 2021-03-30  6:50 ` Stefan Riedmueller
  2021-03-30  6:50 ` [PATCH 3/4] mtd: nand_msx: Implement ooblayout ops Stefan Riedmueller
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Riedmueller @ 2021-03-30  6:50 UTC (permalink / raw)
  To: barebox

Nandsize can be larger than 4 GB. So during status print the number of
blocks calculation needs to use 64 bit division.

Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
---
 commands/nandtest.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/commands/nandtest.c b/commands/nandtest.c
index bfe4c4c0ed03..1bb59c7fdba5 100644
--- a/commands/nandtest.c
+++ b/commands/nandtest.c
@@ -178,12 +178,14 @@ static int erase_and_write(loff_t ofs, unsigned char *data,
 }
 
 /* Print stats of nandtest. */
-static void print_stats(int nr_passes, int length)
+static void print_stats(int nr_passes, loff_t length)
 {
 	unsigned int i;
+	uint64_t blocks = (uint64_t)length;
+
+	do_div(blocks, meminfo.erasesize);
 	printf("-------- Summary --------\n");
-	printf("Tested blocks		: %d\n", (length/meminfo.erasesize)
-			* nr_passes);
+	printf("Tested blocks		: %lld\n", blocks * nr_passes);
 
 	for (i = 0; i < MAX_ECC_BITS; i++)
 		printf("ECC %d bit error(s)	: %u\n", i + 1, ecc_stats[i]);
-- 
2.25.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 3/4] mtd: nand_msx: Implement ooblayout ops
  2021-03-30  6:50 [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Stefan Riedmueller
  2021-03-30  6:50 ` [PATCH 2/4] nandtest: Fix status print for NAND which size exceeds 4 GB Stefan Riedmueller
@ 2021-03-30  6:50 ` Stefan Riedmueller
  2021-03-30  6:50 ` [PATCH 4/4] imx-bbu-nand-fcb: Inform user if the barebox partition is too small Stefan Riedmueller
  2021-04-01  8:26 ` [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Riedmueller @ 2021-03-30  6:50 UTC (permalink / raw)
  To: barebox

The default ooblayout ops do not work on nand_mxs devices and can lead
to an unresponsible system when doing a 'nand -i' on that device.

Thus implement the ooblayout ops for the nand_mxs driver separately.
Since writing the oob area is not supported simply return the whole oob
area as ecc.

Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
---
 drivers/mtd/nand/nand_mxs.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/mtd/nand/nand_mxs.c b/drivers/mtd/nand/nand_mxs.c
index 96ae71364efb..285ae3c121b6 100644
--- a/drivers/mtd/nand/nand_mxs.c
+++ b/drivers/mtd/nand/nand_mxs.c
@@ -269,6 +269,33 @@ static void mxs_nand_return_dma_descs(struct mxs_nand_info *info)
 	info->desc_index = 0;
 }
 
+/*
+ * We don't support writing the oob area so simply return the whole oob
+ * as ECC.
+ */
+static int mxs_nand_ooblayout_ecc(struct mtd_info *mtd, int section,
+				  struct mtd_oob_region *oobregion)
+{
+	if (section)
+		return -ERANGE;
+
+	oobregion->offset = 0;
+	oobregion->length = mtd->oobsize;
+
+	return 0;
+}
+
+static int mxs_nand_ooblayout_free(struct mtd_info *mtd, int section,
+				   struct mtd_oob_region *oobregion)
+{
+	return -ERANGE;
+}
+
+static const struct mtd_ooblayout_ops mxs_nand_ooblayout_ops = {
+	.ecc = mxs_nand_ooblayout_ecc,
+	.free = mxs_nand_ooblayout_free,
+};
+
 static uint32_t mxs_nand_ecc_chunk_cnt(uint32_t page_data_size)
 {
 	return page_data_size / MXS_NAND_CHUNK_DATA_CHUNK_SIZE;
@@ -2218,6 +2245,8 @@ static int mxs_nand_probe(struct device_d *dev)
 	if (err)
 		goto err2;
 
+	mtd_set_ooblayout(mtd, &mxs_nand_ooblayout_ops);
+
 	mxs_nand_scan_bbt(chip);
 
 	err = add_mtd_nand_device(mtd, "nand");
-- 
2.25.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 4/4] imx-bbu-nand-fcb: Inform user if the barebox partition is too small
  2021-03-30  6:50 [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Stefan Riedmueller
  2021-03-30  6:50 ` [PATCH 2/4] nandtest: Fix status print for NAND which size exceeds 4 GB Stefan Riedmueller
  2021-03-30  6:50 ` [PATCH 3/4] mtd: nand_msx: Implement ooblayout ops Stefan Riedmueller
@ 2021-03-30  6:50 ` Stefan Riedmueller
  2021-04-01  8:26 ` [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Stefan Riedmueller @ 2021-03-30  6:50 UTC (permalink / raw)
  To: barebox

Show an error message and return an error code if the barebox partition
is too small. This can easily happen when having large erasoblocks since
all four FCB copies need a separate eraseblock.

Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
---
 common/imx-bbu-nand-fcb.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c
index 0e008c6bc2c0..4e680a0a51e7 100644
--- a/common/imx-bbu-nand-fcb.c
+++ b/common/imx-bbu-nand-fcb.c
@@ -501,7 +501,8 @@ static int imx_bbu_firmware_start_block(struct mtd_info *mtd, int num)
  * @num: The slot number (0 or 1)
  *
  * This returns the start page for a firmware slot, to be written into the
- * Firmwaren_startingPage field in the FCB.
+ * Firmwaren_startingPage field in the FCB or a negative error code in case
+ * of a failure.
  */
 static int imx_bbu_firmware_fcb_start_page(struct mtd_info *mtd, int num)
 {
@@ -512,6 +513,11 @@ static int imx_bbu_firmware_fcb_start_page(struct mtd_info *mtd, int num)
 
 	blocksleft = imx_bbu_firmware_max_blocks(mtd);
 
+	if (blocksleft <= 0) {
+		pr_err("partition size too small for both firmwares\n");
+		return -ENOMEM;
+	}
+
 	/*
 	 * The ROM only checks for a bad block when advancing the read position,
 	 * but not if the initial block is good, hence we cannot directly point
@@ -1258,7 +1264,15 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat
 		free(fcb);
 		fcb = xzalloc(sizeof(*fcb));
 		fcb->Firmware1_startingPage = imx_bbu_firmware_fcb_start_page(mtd, !used);
+		if (fcb->Firmware1_startingPage < 0) {
+			ret = fcb->Firmware1_startingPage;
+			goto out;
+		}
 		fcb->Firmware2_startingPage = imx_bbu_firmware_fcb_start_page(mtd, used);
+		if (fcb->Firmware2_startingPage < 0) {
+			ret = fcb->Firmware2_startingPage;
+			goto out;
+		}
 		fcb->PagesInFirmware1 = fw_size / mtd->writesize;
 		fcb->PagesInFirmware2 = fcb->PagesInFirmware1;
 
-- 
2.25.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest
  2021-03-30  6:50 [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Stefan Riedmueller
                   ` (2 preceding siblings ...)
  2021-03-30  6:50 ` [PATCH 4/4] imx-bbu-nand-fcb: Inform user if the barebox partition is too small Stefan Riedmueller
@ 2021-04-01  8:26 ` Sascha Hauer
  3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2021-04-01  8:26 UTC (permalink / raw)
  To: Stefan Riedmueller; +Cc: barebox

On Tue, Mar 30, 2021 at 08:50:37AM +0200, Stefan Riedmueller wrote:
> NAND_ECC_HW is no longer optional so remove the dependency from
> nandtest. Otherwise nandtest won't be build for HW ECC boards.
> 
> Signed-off-by: Stefan Riedmueller <s.riedmueller@phytec.de>
> ---
>  commands/Kconfig | 1 -
>  1 file changed, 1 deletion(-)

Applied all to master, thanks

Sascha

> 
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 6d84c956e576..8e8b5a926fbb 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -1884,7 +1884,6 @@ config CMD_NANDTEST
>  	tristate
>  	depends on NAND
>  	depends on PARTITION
> -	depends on NAND_ECC_HW || NAND_ECC_SOFT
>  	prompt "nandtest"
>  	help
>  	  NAND flash memory test
> -- 
> 2.25.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
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] 5+ messages in thread

end of thread, other threads:[~2021-04-01  8:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-30  6:50 [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Stefan Riedmueller
2021-03-30  6:50 ` [PATCH 2/4] nandtest: Fix status print for NAND which size exceeds 4 GB Stefan Riedmueller
2021-03-30  6:50 ` [PATCH 3/4] mtd: nand_msx: Implement ooblayout ops Stefan Riedmueller
2021-03-30  6:50 ` [PATCH 4/4] imx-bbu-nand-fcb: Inform user if the barebox partition is too small Stefan Riedmueller
2021-04-01  8:26 ` [PATCH 1/4] commands: Kconfig: Remove HW ECC dependency from nandtest Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox