From: "Chee, Tien Fong" <tienfong.chee@altera.com>
To: dinesh.maniyam@altera.com, u-boot@lists.denx.de
Cc: Marek Vasut <marex@denx.de>,
Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>,
Dario Binacchi <dario.binacchi@amarulasolutions.com>,
Michael Trimarchi <michael@amarulasolutions.com>,
Tom Rini <trini@konsulko.com>, david regan <dregan@broadcom.com>,
Anand Gore <anand.gore@broadcom.com>,
William Zhang <william.zhang@broadcom.com>,
Tien Fong <tien.fong.chee@altera.com>,
Kok Kiang <kok.kiang.hea@altera.com>,
Boon Khai <boon.khai.ng@altera.com>,
Alif <alif.zakuan.yuslaimi@altera.com>
Subject: Re: [PATCH] nand: denali: enable SoC64 SPL NAND boot with proper Kconfig selection
Date: Wed, 19 Nov 2025 11:30:46 +0800 [thread overview]
Message-ID: <610e4623-90e3-40c4-be65-66c19bf6d7d5@altera.com> (raw)
In-Reply-To: <20251104171902.15039-1-dinesh.maniyam@altera.com>
Hi Dinesh,
On 5/11/2025 1:19 am, dinesh.maniyam@altera.com wrote:
> From: Dinesh Maniyam<dinesh.maniyam@altera.com>
>
> Add SoC64-specific NAND SPL load support in denali_spl.c and update the
> related Kconfig dependencies.
>
> This patch introduces new helper functions to enable NAND boot support
> for SoCFPGA SoC64 devices using the Denali NAND controller during the
> SPL stage:
>
> - nand_get_mtd(): safely retrieves the active NAND device instance.
> - nand_spl_load_image(): supports image loading with page alignment and
> bad block skipping using nand_read_skip_bad().
> - Includes nand_util.c for required NAND utility helpers.
> - Wrapped under IS_ENABLED(CONFIG_TARGET_SOCFPGA_SOC64) to limit
> inclusion to SoC64 targets.
>
> In addition, the SPL_NAND_DENALI Kconfig entry has been updated to:
> - Select required NAND SPL components (BASE, DRIVERS, IDENT, INIT, ECC).
> - Exclude NAND_DENALI_SPARE_AREA_SKIP_BYTES from SoC64 builds, as SoC64
> NAND handling no longer uses this configuration.
>
> These changes collectively enable functional NAND SPL image loading
> support for SoCFPGA SoC64 devices with Denali NAND.
>
> Signed-off-by: Dinesh Maniyam<dinesh.maniyam@altera.com>
> ---
> drivers/mtd/nand/raw/Kconfig | 7 ++-
> drivers/mtd/nand/raw/denali_spl.c | 73 +++++++++++++++++++++++++++++++
> 2 files changed, 79 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/nand/raw/Kconfig b/drivers/mtd/nand/raw/Kconfig
> index 754b99bf3eb..5e567ca4993 100644
> --- a/drivers/mtd/nand/raw/Kconfig
> +++ b/drivers/mtd/nand/raw/Kconfig
> @@ -781,6 +781,11 @@ config SPL_NAND_CADENCE
>
> config SPL_NAND_DENALI
> bool "Support Denali NAND controller for SPL"
> + select SPL_NAND_BASE
> + select SPL_NAND_DRIVERS
> + select SPL_NAND_IDENT
> + select SPL_NAND_INIT
> + select SPL_NAND_ECC
Are these strictly required for all Denali users?
If these are only needed for SoC64, it would be better to move them into:
arch/arm/Kconfig under SOCFPGA / SOC64, or the SoC64 defconfig
> depends on SPL_NAND_SUPPORT
> help
> This is a small implementation of the Denali NAND controller
> @@ -788,7 +793,7 @@ config SPL_NAND_DENALI
>
> config NAND_DENALI_SPARE_AREA_SKIP_BYTES
> int "Number of bytes skipped in OOB area"
> - depends on SPL_NAND_DENALI
> + depends on SPL_NAND_DENALI && !TARGET_SOCFPGA_SOC64
This should not be added here in the common Kconfig.
If SoC64 does not require this option, simply disable it in:
SoC64 defconfig, or arch/arm/Kconfig under SOCFPGA
The common Denali code should not embed SoCFPGA-specific constraints.
> range 0 63
> help
> This option specifies the number of bytes to skip from the beginning
> diff --git a/drivers/mtd/nand/raw/denali_spl.c b/drivers/mtd/nand/raw/denali_spl.c
> index b1e2c9d8161..78cdab51a5a 100644
> --- a/drivers/mtd/nand/raw/denali_spl.c
> +++ b/drivers/mtd/nand/raw/denali_spl.c
> @@ -5,13 +5,84 @@
> */
>
> #include <config.h>
> +#include <hang.h>
> #include <log.h>
> +#include <malloc.h>
> +#include <memalign.h>
> +#include <nand.h>
> +#include <system-constants.h>
> #include <asm/io.h>
> #include <asm/unaligned.h>
> #include <linux/delay.h>
> #include <linux/mtd/rawnand.h>
> #include "denali.h"
>
> +/* Only compile this code for SoCFPGA SoC64 targets */
> +#if IS_ENABLED(CONFIG_TARGET_SOCFPGA_SOC64)
Cannot add the platform specific change here in the common driver.
The Denali SPL driver is shared across platforms, so we should not add
SoCFPGA-specific logic here.
The function:
int nand_spl_load_image(...)
should be moved to platform-specific code, e.g.:
arch/arm/mach-socfpga/misc_soc64.c
Similarly, helper functions such as:
nand_get_mtd()
nand_spl_load_image()
#include "nand_util.c"
> +
> +struct mtd_info *nand_get_mtd(void)
> +{
> + struct mtd_info *mtd;
> +
> + mtd = get_nand_dev_by_index(nand_curr_device);
> + if (!mtd)
> + hang();
> +
> + return mtd;
> +}
> +
> +int nand_spl_load_image(u32 offset, u32 len, void *dst)
> +{
> + size_t count = len, actual = 0, page_align_overhead = 0;
> + u32 page_align_offset = 0;
> + u8 *page_buffer;
> + int err = 0;
> + struct mtd_info *mtd;
> +
> + if (!len || !dst)
> + return -EINVAL;
> +
> + mtd = nand_get_mtd();
> +
> + if ((offset & (mtd->writesize - 1)) != 0) {
> + page_buffer = malloc_cache_aligned(mtd->writesize);
> + if (!page_buffer) {
> + debug("Error: allocating buffer\n");
> + return -ENOMEM;
> + }
> +
> + page_align_overhead = offset % mtd->writesize;
> + page_align_offset = (offset / mtd->writesize) * mtd->writesize;
> + count = mtd->writesize;
> +
> + err = nand_read_skip_bad(mtd, page_align_offset, &count,
> + &actual, mtd->size, page_buffer);
> +
> + if (err)
> + return err;
> +
> + count -= page_align_overhead;
> + count = min((size_t)len, count);
> + memcpy(dst, page_buffer + page_align_overhead, count);
> + free(page_buffer);
> +
> + len -= count;
> + if (!len)
> + return err;
> +
> + offset += count;
> + dst += count;
> + count = len;
> + }
> +
> + return nand_read_skip_bad(mtd, offset, &count, &actual, mtd->size, dst);
> +}
> +
> +void nand_deselect(void) {}
> +#include "nand_util.c"
> +
> +#else
> +
> #define DENALI_MAP01 (1 << 26) /* read/write pages in PIO */
> #define DENALI_MAP10 (2 << 26) /* high-level control plane */
>
> @@ -240,3 +311,5 @@ unsigned int nand_page_size(void)
> }
>
> void nand_deselect(void) {}
> +#endif
> +
Thanks.
Tien Fong
next prev parent reply other threads:[~2025-11-19 3:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 17:19 [PATCH] nand: denali: enable SoC64 SPL NAND boot with proper Kconfig selection dinesh.maniyam
2025-11-19 3:30 ` Chee, Tien Fong [this message]
2025-11-20 5:06 ` Maniyam, Dinesh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=610e4623-90e3-40c4-be65-66c19bf6d7d5@altera.com \
--to=tienfong.chee@altera.com \
--cc=alif.zakuan.yuslaimi@altera.com \
--cc=anand.gore@broadcom.com \
--cc=boon.khai.ng@altera.com \
--cc=dario.binacchi@amarulasolutions.com \
--cc=dinesh.maniyam@altera.com \
--cc=dregan@broadcom.com \
--cc=kok.kiang.hea@altera.com \
--cc=marex@denx.de \
--cc=michael@amarulasolutions.com \
--cc=simon.k.r.goldschmidt@gmail.com \
--cc=tien.fong.chee@altera.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=william.zhang@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox