[PATCH] mtd: rawnand: nand_base: Handle algorithm selection

William Zhang william.zhang at broadcom.com
Thu Jan 26 02:14:19 CET 2023


Hi Linus,

On 01/21/2023 03:43 PM, Linus Walleij wrote:
> For BRCMNAND with 1-bit BCH ECC (BCH-1) such as used on the
> D-Link DIR-885L and DIR-890L routers, we need to explicitly
> select the ECC like this in the device tree:
> 
>    nand-ecc-algo = "bch";
>    nand-ecc-strength = <1>;
>    nand-ecc-step-size = <512>;
> 
> This is handled by the Linux kernel but U-Boot core does
> not respect this. Fix it up by parsing the algorithm and
> preserve the behaviour using this property to select
> software BCH as far as possible.

For 1 bit HW ECC, the BRCMNAND driver only uses HAMMING ECC.  The 
brcmnand_setup_dev function should take care of it with just these two 
properties in the device tress without any code changes:
     nand-ecc-strength = <1>;
     nand-ecc-step-size = <512>;
unless these D-Link device has always been using software BCH-1 and 
wants to continue to use software BCH-1.

BTW,  I didn't see this change from master branch of linux nand base 
driver. The "nand-ecc-algo" is only used by the ecc engine code(ecc.c) 
but this code is not in the u-boot obviously. Were you porting this from 
a different version of linux nand driver?

> 
> Signed-off-by: Linus Walleij <linus.walleij at linaro.org>
> ---
>   drivers/mtd/nand/raw/nand_base.c | 13 ++++++++++---
>   1 file changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c
> index 9eba360d55f3..872b58ec5f23 100644
> --- a/drivers/mtd/nand/raw/nand_base.c
> +++ b/drivers/mtd/nand/raw/nand_base.c
> @@ -4487,6 +4487,7 @@ EXPORT_SYMBOL(nand_detect);
>   static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode node)
>   {
>   	int ret, ecc_mode = -1, ecc_strength, ecc_step;
> +	int ecc_algo = NAND_ECC_UNKNOWN;
>   	const char *str;
>   
>   	ret = ofnode_read_s32_default(node, "nand-bus-width", -1);
> @@ -4512,10 +4513,13 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
>   			ecc_mode = NAND_ECC_SOFT_BCH;
>   	}
>   
> -	if (ecc_mode == NAND_ECC_SOFT) {
> -		str = ofnode_read_string(node, "nand-ecc-algo");
> -		if (str && !strcmp(str, "bch"))
> +	str = ofnode_read_string(node, "nand-ecc-algo");
> +	if (str && !strcmp(str, "bch")) {
> +		ecc_algo = NAND_ECC_BCH;
> +		if (ecc_mode == NAND_ECC_SOFT)
>   			ecc_mode = NAND_ECC_SOFT_BCH;
> +	} else if (!strcmp(str, "hamming")) {
> +		ecc_algo = NAND_ECC_HAMMING;
>   	}
>   
>   	ecc_strength = ofnode_read_s32_default(node,
> @@ -4529,6 +4533,9 @@ static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, ofnode nod
>   		return -EINVAL;
>   	}
>   
> +	if (ecc_algo >= 0)
> +		chip->ecc.algo = ecc_algo;
> +
>   	if (ecc_mode >= 0)
>   		chip->ecc.mode = ecc_mode;
>   
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4212 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20230125/96531dee/attachment.bin>


More information about the U-Boot mailing list