All of lore.kernel.org
 help / color / mirror / Atom feed
From: Grygorii Strashko <grygorii.strashko@ti.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v3 02/17] common: env_nand: use get_nand_dev_by_index()
Date: Fri, 10 Feb 2017 14:22:49 -0600	[thread overview]
Message-ID: <20170210202304.20652-3-grygorii.strashko@ti.com> (raw)
In-Reply-To: <20170210202304.20652-1-grygorii.strashko@ti.com>

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 <grygorii.strashko@ti.com>
---
 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");
-- 
2.10.1.dirty

  parent reply	other threads:[~2017-02-10 20:22 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-10 20:22 [U-Boot] [PATCH v3 00/17] nand: remove direct acces to nand_info array Grygorii Strashko
2017-02-10 20:22 ` [U-Boot] [PATCH v3 01/17] cmd: nand: abstract global variable usage for dm conversion Grygorii Strashko
2017-02-10 20:22 ` Grygorii Strashko [this message]
2017-02-10 20:22 ` [U-Boot] [PATCH v3 03/17] dfu: dfu_nand: use get_nand_dev_by_index() Grygorii Strashko
2017-02-10 20:22 ` [U-Boot] [PATCH v3 04/17] cmd: bootm: " Grygorii Strashko
2017-02-10 20:22 ` [U-Boot] [PATCH v3 05/17] cmd: jffs2: " Grygorii Strashko
2017-02-10 20:22 ` [U-Boot] [PATCH v3 06/17] common: " Grygorii Strashko
2017-02-10 20:22 ` [U-Boot] [PATCH v3 07/17] fs: " Grygorii Strashko
2017-02-10 20:22 ` [U-Boot] [PATCH v3 08/17] cmd: nand: remove direct access to struct mtd_info->priv Grygorii Strashko
2017-02-10 20:22 ` [U-Boot] [PATCH v3 09/17] net: phy: cortina: use get_nand_dev_by_index() Grygorii Strashko
2017-02-10 20:52   ` Joe Hershberger
2017-02-10 20:22 ` [U-Boot] [PATCH v3 10/17] net: fm: " Grygorii Strashko
2017-02-10 20:54   ` Joe Hershberger
2017-02-10 20:22 ` [U-Boot] [PATCH v3 11/17] mtd: nand: drv: " Grygorii Strashko
2017-02-10 20:22 ` [U-Boot] [PATCH v3 12/17] cmd: mvebu: bubt: " Grygorii Strashko
2017-02-10 20:23 ` [U-Boot] [PATCH v3 13/17] board: atmel: " Grygorii Strashko
2017-02-10 20:23 ` [U-Boot] [PATCH v3 14/17] board: ronetix: " Grygorii Strashko
2017-02-10 20:23 ` [U-Boot] [PATCH v3 15/17] board: BuR: " Grygorii Strashko
2017-02-21 11:53   ` Hannes Schmelzer
2017-02-22  4:00     ` Simon Glass
2017-02-10 20:23 ` [U-Boot] [PATCH v3 16/17] board: toradex: " Grygorii Strashko
2017-02-11  1:20   ` Marcel Ziswiler
2017-02-10 20:23 ` [U-Boot] [PATCH v3 17/17] mtd: nand: make nand_info array static Grygorii Strashko

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=20170210202304.20652-3-grygorii.strashko@ti.com \
    --to=grygorii.strashko@ti.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.