From patchwork Sat Jul 5 09:48:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 367305 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id CAA7714011E for ; Sat, 5 Jul 2014 21:36:11 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EF7AA4B5A5; Sat, 5 Jul 2014 13:36:07 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OHqUHJslYyIN; Sat, 5 Jul 2014 13:36:07 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 011854A04E; Sat, 5 Jul 2014 13:36:03 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7D8704A053 for ; Sat, 5 Jul 2014 12:06:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dKh7mO4oCVRc for ; Sat, 5 Jul 2014 12:06:27 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from Galois.linutronix.de (www.linutronix.de [62.245.132.108]) by theia.denx.de (Postfix) with ESMTPS id 6BA834A04F for ; Sat, 5 Jul 2014 12:06:27 +0200 (CEST) Received: from localhost ([127.0.0.1] helo=[127.0.1.1]) by Galois.linutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1X3MZo-000162-QT; Sat, 05 Jul 2014 11:48:12 +0200 Message-Id: <20140705094729.899996828@linutronix.de> User-Agent: quilt/0.63-1 Date: Sat, 05 Jul 2014 09:48:12 -0000 From: Thomas Gleixner To: u-boot References: <20140705092042.528529053@linutronix.de> MIME-Version: 1.0 Content-Disposition: inline; filename=nand_spl_simple-add-read-function.patch X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1, SHORTCIRCUIT=-0.0001 X-Mailman-Approved-At: Sat, 05 Jul 2014 13:35:59 +0200 Cc: Richard Weinberger Subject: [U-Boot] [patch 1/2] nand_spl_simple: Add a simple flash read function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.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 --- drivers/mtd/nand/nand_spl_simple.c | 64 +++++++++++++++++++++++++++++++++++++ include/nand.h | 1 2 files changed, 65 insertions(+) Index: u-boot/drivers/mtd/nand/nand_spl_simple.c =================================================================== --- u-boot.orig/drivers/mtd/nand/nand_spl_simple.c +++ u-boot/drivers/mtd/nand/nand_spl_simple.c @@ -206,6 +206,70 @@ static int nand_read_page(int block, int } #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; Index: u-boot/include/nand.h =================================================================== --- u-boot.orig/include/nand.h +++ u-boot/include/nand.h @@ -149,6 +149,7 @@ int nand_unlock(nand_info_t *meminfo, lo 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