public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function
Date: Thu, 21 Jan 2016 07:05:31 +0100	[thread overview]
Message-ID: <56A0752B.3050507@denx.de> (raw)
In-Reply-To: <20160117031218.GC28493@localhost.localdomain>

Hello Ladislav,

Am 17.01.2016 um 04:12 schrieb Ladislav Michl:
> From: Thomas Gleixner <tglx@linutronix.de>
>
> To support UBI in SPL we need a simple NAND read function. Add one to
> nand_spl_simple and keep it as simple as it goes.
>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
> Acked-by: Scott Wood <oss@buserror.net>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> ---
> Changes in v3:
> - Rename nand_spl_read_flash to nand_spl_read_block and optimize it.
>
>   drivers/mtd/nand/nand_spl_simple.c | 62 ++++++++++++++++++++++++++++++++++++++
>   include/nand.h                     |  1 +
>   2 files changed, 63 insertions(+)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko
>
> diff --git a/drivers/mtd/nand/nand_spl_simple.c b/drivers/mtd/nand/nand_spl_simple.c
> index e69f662..cf80903 100644
> --- a/drivers/mtd/nand/nand_spl_simple.c
> +++ b/drivers/mtd/nand/nand_spl_simple.c
> @@ -209,6 +209,68 @@ static int nand_read_page(int block, int page, void *dst)
>   }
>   #endif
>
> +#ifdef CONFIG_SPL_UBI
> +/*
> + * Temporary storage for non NAND page aligned and non NAND page sized
> + * reads. Note: This does not support runtime detected FLASH yet, but
> + * that should be reasonably easy to fix by making the buffer large
> + * enough :)
> + */
> +static u8 scratch_buf[CONFIG_SYS_NAND_PAGE_SIZE];
> +
> +/**
> + * nand_spl_read_block - Read data from physical eraseblock into a buffer
> + * @block:	Number of the physical eraseblock
> + * @offset:	Data offset from the start of @peb
> + * @len:	Data size to read
> + * @dst:	Address of the destination buffer
> + *
> + * This could be further optimized if we'd have a subpage read
> + * function in the simple code. On NAND which allows subpage reads
> + * this would spare quite some time to readout e.g. the VID header of
> + * UBI.
> + *
> + * Notes:
> + *	@offset + @len are not allowed to be larger than a physical
> + *	erase block. No sanity check done for simplicity reasons.
> + *
> + * To support runtime detected flash this needs to be extended by
> + * information about the actual flash geometry, but thats beyond the
> + * scope of this effort and for most applications where fast boot is
> + * required it is not an issue anyway.
> + */
> +int nand_spl_read_block(int block, int offset, int len, void *dst)
> +{
> +	int page, read;
> +
> +	/* Calculate the page number */
> +	page = offset / CONFIG_SYS_NAND_PAGE_SIZE;
> +
> +	/* Offset to the start of a flash page */
> +	offset = offset % CONFIG_SYS_NAND_PAGE_SIZE;
> +
> +	while (len) {
> +		/*
> +		 * Non page aligned reads go to the scratch buffer.
> +		 * Page aligned reads go directly to the destination.
> +		 */
> +		if (offset || len < CONFIG_SYS_NAND_PAGE_SIZE) {
> +			nand_read_page(block, page, scratch_buf);
> +			read = min(len, CONFIG_SYS_NAND_PAGE_SIZE - offset);
> +			memcpy(dst, scratch_buf + offset, read);
> +			offset = 0;
> +		} else {
> +			nand_read_page(block, page, dst);
> +			read = CONFIG_SYS_NAND_PAGE_SIZE;
> +		}
> +		page++;
> +		len -= read;
> +		dst += read;
> +	}
> +	return 0;
> +}
> +#endif
> +
>   int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst)
>   {
>   	unsigned int block, lastblock;
> diff --git a/include/nand.h b/include/nand.h
> index d2a53ab..2f9a1ec 100644
> --- a/include/nand.h
> +++ b/include/nand.h
> @@ -124,6 +124,7 @@ int nand_unlock(nand_info_t *meminfo, loff_t start, size_t length,
>   int nand_get_lock_status(nand_info_t *meminfo, loff_t offset);
>
>   int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
> +int nand_spl_read_block(int block, int offset, int len, void *dst);
>   void nand_deselect(void);
>
>   #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
>

-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

  reply	other threads:[~2016-01-21  6:05 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-17  3:09 [U-Boot] [PATCHv4 0/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-17  3:11 ` [U-Boot] [PATCHv4 1/7] mtd: Sort subsystem directories aplhabeticaly in Makefile Ladislav Michl
2016-01-21  6:04   ` Heiko Schocher
2016-01-17  3:12 ` [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function Ladislav Michl
2016-01-21  6:05   ` Heiko Schocher [this message]
2016-01-17  3:13 ` [U-Boot] [PATCHv4 3/7] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-17  3:13 ` [U-Boot] [PATCHv4 4/7] spl: support loading from UBI volumes Ladislav Michl
2016-01-21  6:06   ` Heiko Schocher
2016-01-17  3:15 ` [U-Boot] [PATCHv5 5/7] spl: zImage support in Falcon mode Ladislav Michl
2016-01-21  6:07   ` Heiko Schocher
2016-01-17  3:16 ` [U-Boot] [PATCHv7 6/7] igep00x0: UBIize Ladislav Michl
2016-01-21  6:07   ` Heiko Schocher
2016-01-22 22:35     ` Enric Balletbo Serra
2016-01-24 13:44       ` Ladislav Michl
2016-01-25  6:39       ` Heiko Schocher
2016-01-25  7:26         ` Enric Balletbo Serra
2016-01-25  8:13           ` Heiko Schocher
2016-01-25 15:56           ` Ladislav Michl
2016-01-25 16:56             ` Enric Balletbo Serra
2016-04-13  5:19               ` Heiko Schocher
2016-04-13 11:39                 ` Enric Balletbo Serra
2016-04-19 10:15                   ` Enric Balletbo Serra
2016-06-04 20:48             ` [U-Boot] [RFC] runtime mtdparts_default; was: " Ladislav Michl
2016-01-25 15:13         ` [U-Boot] [PATCHv7 6/7] " Tom Rini
2016-01-25 15:35           ` Heiko Schocher
2016-01-17  3:16 ` [U-Boot] [PATCHv4 7/7] igep00x0: Falcon mode Ladislav Michl
2016-01-21  6:08   ` Heiko Schocher
2016-01-22 22:38     ` Enric Balletbo Serra

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=56A0752B.3050507@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /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