summaryrefslogtreecommitdiff
path: root/common/env_nand.c
diff options
context:
space:
mode:
authorGrygorii Strashko <grygorii.strashko@ti.com>2017-06-27 00:12:52 (GMT)
committerTom Rini <trini@konsulko.com>2017-07-12 02:41:44 (GMT)
commita94a2619397c8e19ef97796e2ca37a274fa64bcd (patch)
tree33b0c01f0008d67478614e3047fa43b50d1e48d3 /common/env_nand.c
parentad92dff28c26b127391692e4d675a463ee4a4215 (diff)
downloadu-boot-fsl-qoriq-a94a2619397c8e19ef97796e2ca37a274fa64bcd.tar.xz
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 <grygorii.strashko@ti.com>
Diffstat (limited to 'common/env_nand.c')
-rw-r--r--common/env_nand.c33
1 files 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");