[U-Boot] [U-Boot, v4, 1/16] nand: sunxi: Fix modulo by zero error
Leon Woestenberg
leon at sidebranch.com
Wed Jan 25 02:30:29 CET 2017
Hello Maxime, Jagan,
[as I was not subscribed to the u-boot mailing list from this email
address yet, I could not properly reply, nor do I have my
git-send-patch setup yet.]
I tried the patch series and reproduced the sunxi-spl-with-ecc.bin
flow on an A13 Olinuxino board with NAND.
I think the fix for the modulo by 0 must also be applied to the
nand_read_buffer() function as follows:
diff --git a/drivers/mtd/nand/sunxi_nand_spl.c
b/drivers/mtd/nand/sunxi_nand_spl.c
index 24c5dcc..f7d31bc 100644
--- a/drivers/mtd/nand/sunxi_nand_spl.c
+++ b/drivers/mtd/nand/sunxi_nand_spl.c
@@ -486,17 +486,24 @@ static int nand_detect_config(struct nfc_config
*conf, u32 offs, void *dest)
static int nand_read_buffer(struct nfc_config *conf, uint32_t offs,
unsigned int size, void *dest)
{
- int first_seed, page, ret;
+ int first_seed = 0, page, ret;
size = ALIGN(size, conf->page_size);
page = offs / conf->page_size;
- first_seed = page % conf->nseeds;
+ if (conf->randomize)
+ first_seed = page % conf->nseeds;
With that fix, I could boot U-Boot through the U-Boot SPL, fully from
NAND on an A13-Olinuxino-WiFi board with 8192/640.
Regards,
Leon.
> From patchwork Mon Jan 23 13:46:43 2017
> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Subject: [U-Boot,v4,1/16] nand: sunxi: Fix modulo by zero error
> From: Maxime Ripard <maxime.ripard at free-electrons.com>
> X-Patchwork-Id: 718570
> X-Patchwork-Delegate: jagannadh.teki at gmail.com
> Message-Id: <57745204e0a659bdcce05f77a5681fa0ab60690b.1485179128.git-series.maxime.ripard at free-electrons.com>
> To: Jagan Teki <jagan at openedev.com>,
> Scott Wood <oss at buserror.net>
> Cc: Thomas Petazzoni <thomas.petazzoni at free-electrons.com>,
> Alexander Kaplan <alex at nextthing.co>,
> Maxime Ripard <maxime.ripard at free-electrons.com>, u-boot at lists.denx.de
> Date: Mon, 23 Jan 2017 14:46:43 +0100
>
> When trying to autodetect the ECC and randomization configurations, the
> driver starts with a randomization disabled and no seeds.
>
> In this case, the number of seeds is obviously 0, and the randomize boolean
> is set to false.
>
> However, the logic that retrieves the seed for a given page offset will
> blindly use the number of seeds, without testing if the randomization is
> enabled, basically doing a modulo by 0.
>
> As it turns out, the libgcc in the common toolchain returns 0 here, which
> was our expected value in such a case, and why we would not detect it.
> However, U-Boot's libgcc will for some reason return from the function
> instead, resulting in an error to load the U-Boot binary in the SPL.
>
> Signed-off-by: Maxime Ripard <maxime.ripard at free-electrons.com>
> Acked-by: Boris Brezillon <boris.brezillon at free-electrons.com>
> Acked-by: Scott Wood <oss at buserror.net>
> ---
> drivers/mtd/nand/sunxi_nand_spl.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mtd/nand/sunxi_nand_spl.c b/drivers/mtd/nand/sunxi_nand_spl.c
> index 1ef7366d4c42..eed4472bdc34 100644
> --- a/drivers/mtd/nand/sunxi_nand_spl.c
> +++ b/drivers/mtd/nand/sunxi_nand_spl.c
> @@ -245,7 +245,7 @@ static int nand_read_page(const struct nfc_config *conf, u32 offs,
> {
> dma_addr_t dst = (dma_addr_t)dest;
> int nsectors = len / conf->ecc_size;
> - u16 rand_seed;
> + u16 rand_seed = 0;
> u32 val;
> int page;
>
> @@ -258,8 +258,9 @@ static int nand_read_page(const struct nfc_config *conf, u32 offs,
> /* clear ecc status */
> writel(0, SUNXI_NFC_BASE + NFC_ECC_ST);
>
> - /* Choose correct seed */
> - rand_seed = random_seed[page % conf->nseeds];
> + /* Choose correct seed if randomized */
> + if (conf->randomize)
> + rand_seed = random_seed[page % conf->nseeds];
>
> writel((rand_seed << 16) | (conf->ecc_strength << 12) |
> (conf->randomize ? NFC_ECC_RANDOM_EN : 0) |
>
More information about the U-Boot
mailing list