From patchwork Fri Feb 10 20:22:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grygorii Strashko X-Patchwork-Id: 726720 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 3vKmgS45mVz9s82 for ; Sat, 11 Feb 2017 07:26:28 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A63114BA35; Fri, 10 Feb 2017 21:25:08 +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 p2uTCkmqIRZl; Fri, 10 Feb 2017 21:25:08 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 92A01B38D9; Fri, 10 Feb 2017 21:24:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 122754AD1F for ; Fri, 10 Feb 2017 21:24:38 +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 gfL_0kJkzlUS for ; Fri, 10 Feb 2017 21:24:37 +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 fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by theia.denx.de (Postfix) with ESMTPS id 12D44B3895 for ; Fri, 10 Feb 2017 21:24:16 +0100 (CET) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id v1AKNB3d027833; Fri, 10 Feb 2017 14:23:11 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v1AKN6bB003987; Fri, 10 Feb 2017 14:23:06 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.294.0; Fri, 10 Feb 2017 14:23:05 -0600 Received: from legion.dal.design.ti.com (legion.dal.design.ti.com [128.247.22.53]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v1AKN5Gb013384; Fri, 10 Feb 2017 14:23:05 -0600 Received: from localhost (uda0226610.am.dhcp.ti.com [128.247.83.96]) by legion.dal.design.ti.com (8.11.7p1+Sun/8.11.7) with ESMTP id v1AKN5313520; Fri, 10 Feb 2017 14:23:05 -0600 (CST) From: Grygorii Strashko To: Lokesh Vutla , Lukasz Majewski , Tom Rini , Scott Wood , Joe Hershberger , Simon Glass Date: Fri, 10 Feb 2017 14:22:49 -0600 Message-ID: <20170210202304.20652-3-grygorii.strashko@ti.com> X-Mailer: git-send-email 2.10.1.dirty In-Reply-To: <20170210202304.20652-1-grygorii.strashko@ti.com> References: <20170210202304.20652-1-grygorii.strashko@ti.com> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v3 02/17] common: env_nand: use get_nand_dev_by_index() 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" As part of preparation for nand DM conversion the new API has been introduced to remove direct access to nand_info array. So, use it here instead of accessing to nand_info array directly. Signed-off-by: Grygorii Strashko --- common/env_nand.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/common/env_nand.c b/common/env_nand.c index 2e28171..133ecfb 100644 --- a/common/env_nand.c +++ b/common/env_nand.c @@ -130,17 +130,22 @@ static int writeenv(size_t offset, u_char *buf) size_t end = offset + CONFIG_ENV_RANGE; size_t amount_saved = 0; size_t blocksize, len; + struct mtd_info *mtd; u_char *char_ptr; - blocksize = nand_info[0]->erasesize; + mtd = get_nand_dev_by_index(0); + if (!mtd) + return 1; + + blocksize = mtd->erasesize; len = min(blocksize, (size_t)CONFIG_ENV_SIZE); while (amount_saved < CONFIG_ENV_SIZE && offset < end) { - if (nand_block_isbad(nand_info[0], offset)) { + if (nand_block_isbad(mtd, offset)) { offset += blocksize; } else { char_ptr = &buf[amount_saved]; - if (nand_write(nand_info[0], offset, &len, char_ptr)) + if (nand_write(mtd, offset, &len, char_ptr)) return 1; offset += blocksize; @@ -161,13 +166,15 @@ struct env_location { static int erase_and_write_env(const struct env_location *location, u_char *env_new) { + struct mtd_info *mtd; int ret = 0; - if (!nand_info[0]) + mtd = get_nand_dev_by_index(0); + if (!mtd) return 1; printf("Erasing %s...\n", location->name); - if (nand_erase_opts(nand_info[0], &location->erase_opts)) + if (nand_erase_opts(mtd, &location->erase_opts)) return 1; printf("Writing to %s... ", location->name); @@ -248,22 +255,24 @@ static int readenv(size_t offset, u_char *buf) size_t end = offset + CONFIG_ENV_RANGE; size_t amount_loaded = 0; size_t blocksize, len; + struct mtd_info *mtd; u_char *char_ptr; - if (!nand_info[0]) + mtd = get_nand_dev_by_index(0); + if (!mtd) return 1; - blocksize = nand_info[0]->erasesize; + blocksize = mtd->erasesize; len = min(blocksize, (size_t)CONFIG_ENV_SIZE); while (amount_loaded < CONFIG_ENV_SIZE && offset < end) { - if (nand_block_isbad(nand_info[0], offset)) { + if (nand_block_isbad(mtd, offset)) { offset += blocksize; } else { char_ptr = &buf[amount_loaded]; - if (nand_read_skip_bad(nand_info[0], offset, + if (nand_read_skip_bad(mtd, offset, &len, NULL, - nand_info[0]->size, char_ptr)) + mtd->size, char_ptr)) return 1; offset += blocksize; @@ -390,12 +399,12 @@ void env_relocate_spec(void) ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); #if defined(CONFIG_ENV_OFFSET_OOB) + struct mtd_info *mtd = get_nand_dev_by_index(0); /* * If unable to read environment offset from NAND OOB then fall through * to the normal environment reading code below */ - if (nand_info[0] && !get_nand_env_oob(nand_info[0], - &nand_env_oob_offset)) { + if (mtd && !get_nand_env_oob(mtd, &nand_env_oob_offset)) { printf("Found Environment offset in OOB..\n"); } else { set_default_env("!no env offset in OOB");