Re: [PATCH 0/3] mtd: nand: atmel: legacy: fix boot on USB-A9G20

2023-03-19 Thread Wolfram Sang
Hi Sam,

> It is only a few weeks ago I argued that there was no users of the older
> at91sam* boards, and then you prove me wrong here.

At your service ;)

> I will try to remember that you may be able to test should someone
> decide to move the barebox support for qil_a9g20 to DT and add PBL
> support in the process.

I am still new to at91 and barebox, but AFAICS the PBL support is only
for MCI currently? I have an USB-A9G20-C01 and this one does not have SD
exposed. The later version A9G20-LPW has it, but I don't own such a
device, sadly. I really like the Calao USB form factor.

Happy hacking,

   Wolfram



signature.asc
Description: PGP signature


Re: [PATCH 0/3] mtd: nand: atmel: legacy: fix boot on USB-A9G20

2023-03-19 Thread Sam Ravnborg
Hi Wolfram.

On Sun, Mar 19, 2023 at 04:49:06PM +0100, Wolfram Sang wrote:
> While trying to unbrick my Calao USB-A9G20, barebox couldn't read the
> NAND BB tables unlike the binary-only barebox from 2013. The first two
> patches fix that. The third one is a cleanup.

It is only a few weeks ago I argued that there was no users of the older
at91sam* boards, and then you prove me wrong here.

I will try to remember that you may be able to test should someone
decide to move the barebox support for qil_a9g20 to DT and add PBL
support in the process.

Sam



[PATCH 3/3] mtd: nand: atmel: legacy: remove superfluous code

2023-03-19 Thread Wolfram Sang
54bcca always populates 'ecc_mode' but forgot to remove the
code which overwrote the previously hardcoded 'NAND_ECC_SOFT'
when needed. This is obsolete now.

Fixes: 54bcca ("mtd: atmel_nand: retrieve ecc_mode from pdata")
Signed-off-by: Wolfram Sang 
---
 drivers/mtd/nand/atmel/legacy.c | 9 -
 1 file changed, 9 deletions(-)

diff --git a/drivers/mtd/nand/atmel/legacy.c b/drivers/mtd/nand/atmel/legacy.c
index 184cf465e3..cf402549b8 100644
--- a/drivers/mtd/nand/atmel/legacy.c
+++ b/drivers/mtd/nand/atmel/legacy.c
@@ -1242,21 +1242,12 @@ static int __init atmel_nand_probe(struct device *dev)
nand_chip->ecc.strength = pdata->ecc_strength ? : 1;
nand_chip->ecc.size = 1 << (pdata->ecc_size_shift ? : 9);
 
-   if (pdata->ecc_mode == NAND_ECC_HW) {
-   nand_chip->ecc.mode = NAND_ECC_HW;
-   }
-
if (pdata->ecc_mode == NAND_ECC_SOFT) {
nand_chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
}
 
nand_chip->legacy.chip_delay = 40;  /* 40us command delay 
time */
 
-   if (IS_ENABLED(CONFIG_NAND_ECC_BCH) &&
-   pdata->ecc_mode == NAND_ECC_SOFT_BCH) {
-   nand_chip->ecc.mode = NAND_ECC_SOFT_BCH;
-   }
-
if (host->board->bus_width_16) {/* 16-bit bus width */
nand_chip->options |= NAND_BUSWIDTH_16;
nand_chip->legacy.read_buf = atmel_read_buf16;
-- 
2.35.1




[PATCH 1/3] mtd: nand: atmel: legacy: add 'algo' to use

2023-03-19 Thread Wolfram Sang
Fixes "WARNING: Unsupported ECC algorithm!" on my USB-A9G20.

Fixes: b6bcd96de5 ("mtd: nand: Update to Linux-5.9")
Signed-off-by: Wolfram Sang 
---

Or maybe we should make HAMMING the default fallback in nand_base.c?

 drivers/mtd/nand/atmel/legacy.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/mtd/nand/atmel/legacy.c b/drivers/mtd/nand/atmel/legacy.c
index 44cd4d07e8..ea1fd64ad8 100644
--- a/drivers/mtd/nand/atmel/legacy.c
+++ b/drivers/mtd/nand/atmel/legacy.c
@@ -1246,6 +1246,10 @@ static int __init atmel_nand_probe(struct device *dev)
nand_chip->ecc.mode = NAND_ECC_HW;
}
 
+   if (pdata->ecc_mode == NAND_ECC_SOFT) {
+   nand_chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
+   }
+
nand_chip->legacy.chip_delay = 40;  /* 40us command delay 
time */
 
if (IS_ENABLED(CONFIG_NAND_ECC_BCH) &&
-- 
2.35.1




[PATCH 0/3] mtd: nand: atmel: legacy: fix boot on USB-A9G20

2023-03-19 Thread Wolfram Sang
While trying to unbrick my Calao USB-A9G20, barebox couldn't read the
NAND BB tables unlike the binary-only barebox from 2013. The first two
patches fix that. The third one is a cleanup.

Happy hacking!


Wolfram Sang (3):
  mtd: nand: atmel: legacy: add 'algo' to use
  mtd: nand: atmel: legacy: use proper ecc_shift
  mtd: nand: atmel: legacy: remove superfluous code

 drivers/mtd/nand/atmel/legacy.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

-- 
2.35.1




[PATCH 2/3] mtd: nand: atmel: legacy: use proper ecc_shift

2023-03-19 Thread Wolfram Sang
The logic of the ternary operator is broken because '1 << x' is always
true even if 'x' is 0. Convert the logic to really use either the pdata
value or a sane default. Fixes "WARNING: Total number of ECC bytes
exceeded oobsize" on my USB-A9G20.

Fixes: babffbb193 ("mtd: atmel_nand: Add per board ECC setup")
Signed-off-by: Wolfram Sang 
---

The other option is to revert babffbb193. I don't see any user. The code
was obviously not enough tested as well.

 drivers/mtd/nand/atmel/legacy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/atmel/legacy.c b/drivers/mtd/nand/atmel/legacy.c
index ea1fd64ad8..184cf465e3 100644
--- a/drivers/mtd/nand/atmel/legacy.c
+++ b/drivers/mtd/nand/atmel/legacy.c
@@ -1240,7 +1240,7 @@ static int __init atmel_nand_probe(struct device *dev)
 
nand_chip->ecc.mode = pdata->ecc_mode;
nand_chip->ecc.strength = pdata->ecc_strength ? : 1;
-   nand_chip->ecc.size = 1 << pdata->ecc_size_shift ? : 512;
+   nand_chip->ecc.size = 1 << (pdata->ecc_size_shift ? : 9);
 
if (pdata->ecc_mode == NAND_ECC_HW) {
nand_chip->ecc.mode = NAND_ECC_HW;
-- 
2.35.1




[PATCH] commands: edit: fix typo in Kconfig help text

2023-03-19 Thread Wolfram Sang
Signed-off-by: Wolfram Sang 
---
 commands/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index ec15f4e543..27769950d9 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1383,7 +1383,7 @@ config CMD_EDIT
depends on CONSOLE_FULL || CONSOLE_SIMPLE
prompt "edit"
help
- A  small fill-screen editor.
+ A small full-screen editor.
 
  Usage: edit FILE
 
-- 
2.35.1




[PATCH] commands: nand: add missing parameters to help

2023-03-19 Thread Wolfram Sang
Signed-off-by: Wolfram Sang 
---
 commands/Kconfig | 4 +++-
 commands/nand.c  | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/commands/Kconfig b/commands/Kconfig
index 27769950d9..76dfca2dfd 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -1950,12 +1950,14 @@ config CMD_NAND
help
  NAND flash handling
 
- Usage: nand [-adb] NANDDEV
+ Usage: nand [-adbgi] NANDDEV
 
  Options:
  -aregister a bad block aware device ontop of a 
normal NAND device
  -dderegister a bad block aware device
  -b OFFS   mark block at OFFSet as bad
+ -g OFFS   mark block at OFFSet as good
+ -iinfo. Show information about bad blocks
 
 config CMD_NANDTEST
tristate
diff --git a/commands/nand.c b/commands/nand.c
index 67e43eba30..d07444aee0 100644
--- a/commands/nand.c
+++ b/commands/nand.c
@@ -165,7 +165,7 @@ BAREBOX_CMD_HELP_END
 BAREBOX_CMD_START(nand)
.cmd= do_nand,
BAREBOX_CMD_DESC("NAND flash handling")
-   BAREBOX_CMD_OPTS("[-adb] NANDDEV")
+   BAREBOX_CMD_OPTS("[-adbgi] NANDDEV")
BAREBOX_CMD_GROUP(CMD_GRP_HWMANIP)
BAREBOX_CMD_HELP(cmd_nand_help)
 BAREBOX_CMD_END
-- 
2.35.1