public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCHv2 1/3] nand_spl_simple: Add a simple flash read function
Date: Mon, 4 Jan 2016 16:54:42 +0100	[thread overview]
Message-ID: <20160104155431.GB4376@localhost.localdomain> (raw)
In-Reply-To: <20160104155242.GA4376@localhost.localdomain>

From: Thomas Gleixner <tglx@linutronix.de>

To support UBI in SPL we need a simple flash read function. Add one to
nand_spl_simple and keep it as simple as it goes.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/mtd/nand/nand_spl_simple.c | 64 ++++++++++++++++++++++++++++++++++++++
 include/nand.h                     |  1 +
 2 files changed, 65 insertions(+)

diff --git a/drivers/mtd/nand/nand_spl_simple.c b/drivers/mtd/nand/nand_spl_simple.c
index e69f662..2e1af53 100644
--- a/drivers/mtd/nand/nand_spl_simple.c
+++ b/drivers/mtd/nand/nand_spl_simple.c
@@ -209,6 +209,70 @@ 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_flash - Read data from flash into a buffer
+ * @pnum:	Number of the physical eraseblock
+ * @offset:	Data offset from the start of @pnum
+ * @len:	Data size to read
+ * @dest:	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 its a non issue anyway.
+ */
+int nand_spl_read_flash(u32 pnum, u32 offset, u32 len, void *dest)
+{
+	u32 offs, page, read, toread = len;
+
+	/* Calculate the page number */
+	page = offset / CONFIG_SYS_NAND_PAGE_SIZE;
+
+	/* Offset to the start of a flash page */
+	offs = offset % CONFIG_SYS_NAND_PAGE_SIZE;
+
+	while (toread) {
+		/*
+		 * Non page aligned reads go to the scratch buffer.
+		 * Page aligned reads go directly to the destination.
+		 */
+		if (offs || toread < CONFIG_SYS_NAND_PAGE_SIZE) {
+			nand_read_page(pnum, page, scratch_buf);
+			read = min(len, toread);
+			read = min(read, CONFIG_SYS_NAND_PAGE_SIZE - offs);
+			memcpy(dest, scratch_buf + offs, read);
+			offs = 0;
+		} else {
+			nand_read_page(pnum, page, dest);
+			read = CONFIG_SYS_NAND_PAGE_SIZE;
+		}
+		page++;
+		toread -= read;
+		dest += 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..b8bc952 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_flash(u32 pnum, u32 offset, u32 len, void *dest);
 void nand_deselect(void);
 
 #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
-- 
2.1.4

  reply	other threads:[~2016-01-04 15:54 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-04 15:52 [U-Boot] [PATCHv2 0/3] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-04 15:54 ` Ladislav Michl [this message]
2016-01-04 17:19   ` [U-Boot] [PATCHv2 1/3] nand_spl_simple: Add a simple flash read function Marek Vasut
2016-01-04 17:58     ` Ladislav Michl
2016-01-04 18:38       ` Marek Vasut
2016-01-04 18:23   ` Scott Wood
2016-01-04 18:38     ` Ladislav Michl
2016-01-04 18:44       ` Scott Wood
2016-01-04 21:17       ` Ladislav Michl
2016-01-04 21:45         ` Scott Wood
2016-01-04 22:40           ` Marek Vasut
2016-01-04 22:42             ` Scott Wood
2016-01-04 22:52               ` Marek Vasut
2016-01-04 15:56 ` [U-Boot] [PATCHv2 2/3] spl: Lightweight UBI and UBI fastmap support Ladislav Michl
2016-01-06 16:52   ` Ladislav Michl
2016-01-06 17:09     ` Marek Vasut
2016-01-04 15:57 ` [U-Boot] [PATCHv2 3/3] igep00x0: UBIize Ladislav Michl
2016-01-07 10:47 ` [U-Boot] [PATCHv2 0/3] spl: Lightweight UBI and UBI fastmap support Heiko Schocher
2016-01-10 14:00   ` Ladislav Michl
2016-01-11  5:50     ` Heiko Schocher

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=20160104155431.GB4376@localhost.localdomain \
    --to=ladis@linux-mips.org \
    --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