From: Grygorii Strashko Date: Tue, 27 Jun 2017 00:12:52 +0000 (-0500) Subject: common: env_nand: use get_nand_dev_by_index() X-Git-Tag: v2017.09-rc1~212 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=a94a2619397c8e19ef97796e2ca37a274fa64bcd;p=u-boot common: env_nand: use get_nand_dev_by_index() 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 --- diff --git a/common/env_nand.c b/common/env_nand.c index 2e28171ae0..133ecfbb8e 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");