Commit a94a2619397c8e19ef97796e2ca37a274fa64bcd

Authored by Grygorii Strashko
Committed by Tom Rini
1 parent ad92dff28c

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>

Showing 1 changed file with 21 additions and 12 deletions Side-by-side Diff

... ... @@ -130,17 +130,22 @@
130 130 size_t end = offset + CONFIG_ENV_RANGE;
131 131 size_t amount_saved = 0;
132 132 size_t blocksize, len;
  133 + struct mtd_info *mtd;
133 134 u_char *char_ptr;
134 135  
135   - blocksize = nand_info[0]->erasesize;
  136 + mtd = get_nand_dev_by_index(0);
  137 + if (!mtd)
  138 + return 1;
  139 +
  140 + blocksize = mtd->erasesize;
136 141 len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
137 142  
138 143 while (amount_saved < CONFIG_ENV_SIZE && offset < end) {
139   - if (nand_block_isbad(nand_info[0], offset)) {
  144 + if (nand_block_isbad(mtd, offset)) {
140 145 offset += blocksize;
141 146 } else {
142 147 char_ptr = &buf[amount_saved];
143   - if (nand_write(nand_info[0], offset, &len, char_ptr))
  148 + if (nand_write(mtd, offset, &len, char_ptr))
144 149 return 1;
145 150  
146 151 offset += blocksize;
147 152  
148 153  
... ... @@ -161,13 +166,15 @@
161 166 static int erase_and_write_env(const struct env_location *location,
162 167 u_char *env_new)
163 168 {
  169 + struct mtd_info *mtd;
164 170 int ret = 0;
165 171  
166   - if (!nand_info[0])
  172 + mtd = get_nand_dev_by_index(0);
  173 + if (!mtd)
167 174 return 1;
168 175  
169 176 printf("Erasing %s...\n", location->name);
170   - if (nand_erase_opts(nand_info[0], &location->erase_opts))
  177 + if (nand_erase_opts(mtd, &location->erase_opts))
171 178 return 1;
172 179  
173 180 printf("Writing to %s... ", location->name);
174 181  
175 182  
176 183  
177 184  
178 185  
... ... @@ -248,22 +255,24 @@
248 255 size_t end = offset + CONFIG_ENV_RANGE;
249 256 size_t amount_loaded = 0;
250 257 size_t blocksize, len;
  258 + struct mtd_info *mtd;
251 259 u_char *char_ptr;
252 260  
253   - if (!nand_info[0])
  261 + mtd = get_nand_dev_by_index(0);
  262 + if (!mtd)
254 263 return 1;
255 264  
256   - blocksize = nand_info[0]->erasesize;
  265 + blocksize = mtd->erasesize;
257 266 len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
258 267  
259 268 while (amount_loaded < CONFIG_ENV_SIZE && offset < end) {
260   - if (nand_block_isbad(nand_info[0], offset)) {
  269 + if (nand_block_isbad(mtd, offset)) {
261 270 offset += blocksize;
262 271 } else {
263 272 char_ptr = &buf[amount_loaded];
264   - if (nand_read_skip_bad(nand_info[0], offset,
  273 + if (nand_read_skip_bad(mtd, offset,
265 274 &len, NULL,
266   - nand_info[0]->size, char_ptr))
  275 + mtd->size, char_ptr))
267 276 return 1;
268 277  
269 278 offset += blocksize;
270 279  
... ... @@ -390,12 +399,12 @@
390 399 ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
391 400  
392 401 #if defined(CONFIG_ENV_OFFSET_OOB)
  402 + struct mtd_info *mtd = get_nand_dev_by_index(0);
393 403 /*
394 404 * If unable to read environment offset from NAND OOB then fall through
395 405 * to the normal environment reading code below
396 406 */
397   - if (nand_info[0] && !get_nand_env_oob(nand_info[0],
398   - &nand_env_oob_offset)) {
  407 + if (mtd && !get_nand_env_oob(mtd, &nand_env_oob_offset)) {
399 408 printf("Found Environment offset in OOB..\n");
400 409 } else {
401 410 set_default_env("!no env offset in OOB");