From patchwork Sun Jan 17 03:12:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ladislav Michl X-Patchwork-Id: 569210 X-Patchwork-Delegate: hs@denx.de 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 51B1214032F for ; Sun, 17 Jan 2016 14:12:31 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CF108A768D; Sun, 17 Jan 2016 04:12:29 +0100 (CET) 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 a9R38TdGY4Sj; Sun, 17 Jan 2016 04:12:29 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 308B9A756B; Sun, 17 Jan 2016 04:12:29 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4CEA3A756B for ; Sun, 17 Jan 2016 04:12:25 +0100 (CET) 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 4VchlJRs1hhn for ; Sun, 17 Jan 2016 04:12:25 +0100 (CET) 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 cvs.linux-mips.org (eddie.linux-mips.org [148.251.95.138]) by theia.denx.de (Postfix) with ESMTP id 1B4D8A7553 for ; Sun, 17 Jan 2016 04:12:23 +0100 (CET) Received: (from localhost user: 'ladis' uid#1021 fake: STDIN (ladis@eddie.linux-mips.org)) by eddie.linux-mips.org id S27006150AbcAQDMXPHvwD (ORCPT ); Sun, 17 Jan 2016 04:12:23 +0100 Date: Sun, 17 Jan 2016 04:12:18 +0100 From: Ladislav Michl To: u-boot@lists.denx.de Message-ID: <20160117031218.GC28493@localhost.localdomain> References: <20160117030929.GA28493@localhost.localdomain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20160117030929.GA28493@localhost.localdomain> User-Agent: Mutt/1.5.23 (2014-03-12) Cc: Scott Wood , Tom Rini , Richard Weinberger Subject: [U-Boot] [PATCHv4 2/7] nand_spl_simple: Add a simple NAND read function X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Thomas Gleixner 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 Signed-off-by: Ladislav Michl Acked-by: Scott Wood Reviewed-by: Tom Rini Reviewed-by: Heiko Schocher --- 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(+) 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