[U-Boot] [PATCH v3 02/17] common: env_nand: use get_nand_dev_by_index()

Grygorii Strashko grygorii.strashko at ti.com
Fri Feb 10 20:22:49 UTC 2017


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 at 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



More information about the U-Boot mailing list