Commit b616d9b0 authored by Scott Wood's avatar Scott Wood

nand: Embed mtd_info in struct nand_chip

nand_info[] is now an array of pointers, with the actual mtd_info
instance embedded in struct nand_chip.

This is in preparation for syncing the NAND code with Linux 4.6,
which makes the same change to struct nand_chip.  It's in a separate
commit due to the large amount of changes required to accommodate the
change to nand_info[].
Signed-off-by: 's avatarScott Wood <oss@buserror.net>
parent 151c06ec
...@@ -259,7 +259,7 @@ static int load_devicetree(void) ...@@ -259,7 +259,7 @@ static int load_devicetree(void)
} }
#ifdef CONFIG_NAND #ifdef CONFIG_NAND
dtbsize = 0x20000; dtbsize = 0x20000;
rc = nand_read_skip_bad(&nand_info[0], 0x40000, (size_t *)&dtbsize, rc = nand_read_skip_bad(nand_info[0], 0x40000, (size_t *)&dtbsize,
NULL, 0x20000, (u_char *)dtbaddr); NULL, 0x20000, (u_char *)dtbaddr);
#else #else
char *dtbname = getenv("dtb"); char *dtbname = getenv("dtb");
......
...@@ -212,7 +212,7 @@ void lcd_show_board_info(void) ...@@ -212,7 +212,7 @@ void lcd_show_board_info(void)
dram_size += gd->bd->bi_dram[i].size; dram_size += gd->bd->bi_dram[i].size;
nand_size = 0; nand_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
lcd_printf (" %ld MB SDRAM, %ld MB NAND\n", lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
dram_size >> 20, dram_size >> 20,
nand_size >> 20 ); nand_size >> 20 );
......
...@@ -191,7 +191,7 @@ void lcd_show_board_info(void) ...@@ -191,7 +191,7 @@ void lcd_show_board_info(void)
dram_size += gd->bd->bi_dram[i].size; dram_size += gd->bd->bi_dram[i].size;
nand_size = 0; nand_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
#ifndef CONFIG_SYS_NO_FLASH #ifndef CONFIG_SYS_NO_FLASH
flash_size = 0; flash_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
......
...@@ -272,7 +272,7 @@ void lcd_show_board_info(void) ...@@ -272,7 +272,7 @@ void lcd_show_board_info(void)
dram_size += gd->bd->bi_dram[i].size; dram_size += gd->bd->bi_dram[i].size;
nand_size = 0; nand_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
lcd_printf (" %ld MB SDRAM, %ld MB NAND\n", lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
dram_size >> 20, dram_size >> 20,
nand_size >> 20 ); nand_size >> 20 );
......
...@@ -124,7 +124,7 @@ void lcd_show_board_info(void) ...@@ -124,7 +124,7 @@ void lcd_show_board_info(void)
dram_size += gd->bd->bi_dram[i].size; dram_size += gd->bd->bi_dram[i].size;
nand_size = 0; nand_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
lcd_printf(" %ld MB SDRAM, %ld MB NAND\n", lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
dram_size >> 20, dram_size >> 20,
nand_size >> 20); nand_size >> 20);
......
...@@ -151,7 +151,7 @@ void lcd_show_board_info(void) ...@@ -151,7 +151,7 @@ void lcd_show_board_info(void)
dram_size += gd->bd->bi_dram[i].size; dram_size += gd->bd->bi_dram[i].size;
nand_size = 0; nand_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
lcd_printf (" %ld MB SDRAM, %ld MB NAND\n", lcd_printf (" %ld MB SDRAM, %ld MB NAND\n",
dram_size >> 20, dram_size >> 20,
nand_size >> 20 ); nand_size >> 20 );
......
...@@ -196,7 +196,7 @@ void lcd_show_board_info(void) ...@@ -196,7 +196,7 @@ void lcd_show_board_info(void)
dram_size += gd->bd->bi_dram[i].size; dram_size += gd->bd->bi_dram[i].size;
nand_size = 0; nand_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
lcd_printf(" %ld MB SDRAM, %ld MB NAND\n", lcd_printf(" %ld MB SDRAM, %ld MB NAND\n",
dram_size >> 20, dram_size >> 20,
nand_size >> 20); nand_size >> 20);
......
...@@ -207,7 +207,7 @@ void lcd_show_board_info(void) ...@@ -207,7 +207,7 @@ void lcd_show_board_info(void)
nand_size = 0; nand_size = 0;
#ifdef CONFIG_NAND_ATMEL #ifdef CONFIG_NAND_ATMEL
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
#endif #endif
lcd_printf("%ld MB SDRAM, %lld MB NAND\n", lcd_printf("%ld MB SDRAM, %lld MB NAND\n",
dram_size >> 20, nand_size >> 20); dram_size >> 20, nand_size >> 20);
......
...@@ -191,7 +191,7 @@ void lcd_show_board_info(void) ...@@ -191,7 +191,7 @@ void lcd_show_board_info(void)
nand_size = 0; nand_size = 0;
#ifdef CONFIG_NAND_ATMEL #ifdef CONFIG_NAND_ATMEL
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
#endif #endif
lcd_printf("%ld MB SDRAM, %ld MB NAND\n", lcd_printf("%ld MB SDRAM, %ld MB NAND\n",
dram_size >> 20, nand_size >> 20); dram_size >> 20, nand_size >> 20);
......
...@@ -187,7 +187,7 @@ void lcd_show_board_info(void) ...@@ -187,7 +187,7 @@ void lcd_show_board_info(void)
nand_size = 0; nand_size = 0;
#ifdef CONFIG_NAND_ATMEL #ifdef CONFIG_NAND_ATMEL
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
#endif #endif
lcd_printf("%ld MB SDRAM, %ld MB NAND\n", lcd_printf("%ld MB SDRAM, %ld MB NAND\n",
dram_size >> 20, nand_size >> 20); dram_size >> 20, nand_size >> 20);
......
...@@ -194,7 +194,7 @@ void lcd_show_board_info(void) ...@@ -194,7 +194,7 @@ void lcd_show_board_info(void)
nand_size = 0; nand_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
flash_size = 0; flash_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
......
...@@ -293,7 +293,7 @@ void lcd_show_board_info(void) ...@@ -293,7 +293,7 @@ void lcd_show_board_info(void)
nand_size = 0; nand_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
nand_size += nand_info[i].size; nand_size += nand_info[i]->size;
flash_size = 0; flash_size = 0;
for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++) for (i = 0; i < CONFIG_SYS_MAX_FLASH_BANKS; i++)
......
...@@ -461,7 +461,7 @@ static int do_imls_nand(void) ...@@ -461,7 +461,7 @@ static int do_imls_nand(void)
printf("\n"); printf("\n");
for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) { for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
mtd = &nand_info[nand_dev]; mtd = nand_info[nand_dev];
if (!mtd->name || !mtd->size) if (!mtd->name || !mtd->size)
continue; continue;
......
...@@ -167,7 +167,7 @@ static int mtd_device_validate(u8 type, u8 num, u32 *size) ...@@ -167,7 +167,7 @@ static int mtd_device_validate(u8 type, u8 num, u32 *size)
} else if (type == MTD_DEV_TYPE_NAND) { } else if (type == MTD_DEV_TYPE_NAND) {
#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND) #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
if (num < CONFIG_SYS_MAX_NAND_DEVICE) { if (num < CONFIG_SYS_MAX_NAND_DEVICE) {
*size = nand_info[num].size; *size = nand_info[num]->size;
return 0; return 0;
} }
...@@ -244,7 +244,7 @@ static inline u32 get_part_sector_size_nand(struct mtdids *id) ...@@ -244,7 +244,7 @@ static inline u32 get_part_sector_size_nand(struct mtdids *id)
#if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND) #if defined(CONFIG_JFFS2_NAND) && defined(CONFIG_CMD_NAND)
struct mtd_info *mtd; struct mtd_info *mtd;
mtd = &nand_info[id->num]; mtd = nand_info[id->num];
return mtd->erasesize; return mtd->erasesize;
#else #else
......
...@@ -116,7 +116,7 @@ free_dat: ...@@ -116,7 +116,7 @@ free_dat:
static int set_dev(int dev) static int set_dev(int dev)
{ {
if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
!nand_info[dev].name) { !nand_info[dev]->name) {
puts("No such device\n"); puts("No such device\n");
return -1; return -1;
} }
...@@ -124,12 +124,12 @@ static int set_dev(int dev) ...@@ -124,12 +124,12 @@ static int set_dev(int dev)
if (nand_curr_device == dev) if (nand_curr_device == dev)
return 0; return 0;
printf("Device %d: %s", dev, nand_info[dev].name); printf("Device %d: %s", dev, nand_info[dev]->name);
puts("... is now current device\n"); puts("... is now current device\n");
nand_curr_device = dev; nand_curr_device = dev;
#ifdef CONFIG_SYS_NAND_SELECT_DEVICE #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
board_nand_select_device(nand_info[dev].priv, dev); board_nand_select_device(nand_info[dev]->priv, dev);
#endif #endif
return 0; return 0;
...@@ -189,7 +189,7 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[]) ...@@ -189,7 +189,7 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
{ {
int ret; int ret;
uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)]; uint32_t oob_buf[ENV_OFFSET_SIZE/sizeof(uint32_t)];
struct mtd_info *mtd = &nand_info[0]; struct mtd_info *mtd = nand_info[0];
char *cmd = argv[1]; char *cmd = argv[1];
if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !mtd->name) { if (CONFIG_SYS_MAX_NAND_DEVICE == 0 || !mtd->name) {
...@@ -216,7 +216,7 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[]) ...@@ -216,7 +216,7 @@ int do_nand_env_oob(cmd_tbl_t *cmdtp, int argc, char *const argv[])
/* We don't care about size, or maxsize. */ /* We don't care about size, or maxsize. */
if (mtd_arg_off(argv[2], &idx, &addr, &maxsize, &maxsize, if (mtd_arg_off(argv[2], &idx, &addr, &maxsize, &maxsize,
MTD_DEV_TYPE_NAND, nand_info[idx].size)) { MTD_DEV_TYPE_NAND, nand_info[idx]->size)) {
puts("Offset or partition name expected\n"); puts("Offset or partition name expected\n");
return 1; return 1;
} }
...@@ -284,7 +284,7 @@ usage: ...@@ -284,7 +284,7 @@ usage:
static void nand_print_and_set_info(int idx) static void nand_print_and_set_info(int idx)
{ {
struct mtd_info *mtd = &nand_info[idx]; struct mtd_info *mtd = nand_info[idx];
struct nand_chip *chip = mtd->priv; struct nand_chip *chip = mtd->priv;
printf("Device %d: ", idx); printf("Device %d: ", idx);
...@@ -349,7 +349,7 @@ static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev) ...@@ -349,7 +349,7 @@ static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev)
/* We grab the nand info object here fresh because this is usually /* We grab the nand info object here fresh because this is usually
* called after arg_off_size() which can change the value of dev. * called after arg_off_size() which can change the value of dev.
*/ */
struct mtd_info *mtd = &nand_info[dev]; struct mtd_info *mtd = nand_info[dev];
loff_t maxoffset = offset + *size; loff_t maxoffset = offset + *size;
int badblocks = 0; int badblocks = 0;
...@@ -399,7 +399,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -399,7 +399,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
putc('\n'); putc('\n');
for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) {
if (nand_info[i].name) if (nand_info[i]->name)
nand_print_and_set_info(i); nand_print_and_set_info(i);
} }
return 0; return 0;
...@@ -434,11 +434,11 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -434,11 +434,11 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* for another device is to be used. * for another device is to be used.
*/ */
if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE ||
!nand_info[dev].name) { !nand_info[dev]->name) {
puts("\nno devices available\n"); puts("\nno devices available\n");
return 1; return 1;
} }
mtd = &nand_info[dev]; mtd = nand_info[dev];
if (strcmp(cmd, "bad") == 0) { if (strcmp(cmd, "bad") == 0) {
printf("\nDevice %d bad blocks:\n", dev); printf("\nDevice %d bad blocks:\n", dev);
...@@ -497,13 +497,13 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -497,13 +497,13 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
/* skip first two or three arguments, look for offset and size */ /* skip first two or three arguments, look for offset and size */
if (mtd_arg_off_size(argc - o, argv + o, &dev, &off, &size, if (mtd_arg_off_size(argc - o, argv + o, &dev, &off, &size,
&maxsize, MTD_DEV_TYPE_NAND, &maxsize, MTD_DEV_TYPE_NAND,
nand_info[dev].size) != 0) nand_info[dev]->size) != 0)
return 1; return 1;
if (set_dev(dev)) if (set_dev(dev))
return 1; return 1;
mtd = &nand_info[dev]; mtd = nand_info[dev];
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.offset = off; opts.offset = off;
...@@ -562,13 +562,13 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -562,13 +562,13 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (mtd_arg_off(argv[3], &dev, &off, &size, &maxsize, if (mtd_arg_off(argv[3], &dev, &off, &size, &maxsize,
MTD_DEV_TYPE_NAND, MTD_DEV_TYPE_NAND,
nand_info[dev].size)) nand_info[dev]->size))
return 1; return 1;
if (set_dev(dev)) if (set_dev(dev))
return 1; return 1;
mtd = &nand_info[dev]; mtd = nand_info[dev];
if (argc > 4 && !str2long(argv[4], &pagecount)) { if (argc > 4 && !str2long(argv[4], &pagecount)) {
printf("'%s' is not a number\n", argv[4]); printf("'%s' is not a number\n", argv[4]);
...@@ -585,7 +585,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -585,7 +585,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (mtd_arg_off_size(argc - 3, argv + 3, &dev, &off, if (mtd_arg_off_size(argc - 3, argv + 3, &dev, &off,
&size, &maxsize, &size, &maxsize,
MTD_DEV_TYPE_NAND, MTD_DEV_TYPE_NAND,
nand_info[dev].size) != 0) nand_info[dev]->size) != 0)
return 1; return 1;
if (set_dev(dev)) if (set_dev(dev))
...@@ -597,7 +597,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -597,7 +597,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
rwsize = size; rwsize = size;
} }
mtd = &nand_info[dev]; mtd = nand_info[dev];
if (!s || !strcmp(s, ".jffs2") || if (!s || !strcmp(s, ".jffs2") ||
!strcmp(s, ".e") || !strcmp(s, ".i")) { !strcmp(s, ".e") || !strcmp(s, ".i")) {
...@@ -728,13 +728,13 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) ...@@ -728,13 +728,13 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &off, &size, if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &off, &size,
&maxsize, MTD_DEV_TYPE_NAND, &maxsize, MTD_DEV_TYPE_NAND,
nand_info[dev].size) < 0) nand_info[dev]->size) < 0)
return 1; return 1;
if (set_dev(dev)) if (set_dev(dev))
return 1; return 1;
if (!nand_unlock(&nand_info[dev], off, size, allexcept)) { if (!nand_unlock(nand_info[dev], off, size, allexcept)) {
puts("NAND flash successfully unlocked\n"); puts("NAND flash successfully unlocked\n");
} else { } else {
puts("Error unlocking NAND flash, " puts("Error unlocking NAND flash, "
...@@ -915,7 +915,7 @@ static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc, ...@@ -915,7 +915,7 @@ static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc,
addr = simple_strtoul(argv[1], NULL, 16); addr = simple_strtoul(argv[1], NULL, 16);
else else
addr = CONFIG_SYS_LOAD_ADDR; addr = CONFIG_SYS_LOAD_ADDR;
return nand_load_image(cmdtp, &nand_info[dev->id->num], return nand_load_image(cmdtp, nand_info[dev->id->num],
part->offset, addr, argv[0]); part->offset, addr, argv[0]);
} }
} }
...@@ -958,14 +958,14 @@ usage: ...@@ -958,14 +958,14 @@ usage:
idx = simple_strtoul(boot_device, NULL, 16); idx = simple_strtoul(boot_device, NULL, 16);
if (idx < 0 || idx >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[idx].name) { if (idx < 0 || idx >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[idx]->name) {
printf("\n** Device %d not available\n", idx); printf("\n** Device %d not available\n", idx);
bootstage_error(BOOTSTAGE_ID_NAND_AVAILABLE); bootstage_error(BOOTSTAGE_ID_NAND_AVAILABLE);
return 1; return 1;
} }
bootstage_mark(BOOTSTAGE_ID_NAND_AVAILABLE); bootstage_mark(BOOTSTAGE_ID_NAND_AVAILABLE);
return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]); return nand_load_image(cmdtp, nand_info[idx], offset, addr, argv[0]);
} }
U_BOOT_CMD(nboot, 4, 1, do_nandboot, U_BOOT_CMD(nboot, 4, 1, do_nandboot,
......
...@@ -132,15 +132,15 @@ static int writeenv(size_t offset, u_char *buf) ...@@ -132,15 +132,15 @@ static int writeenv(size_t offset, u_char *buf)
size_t blocksize, len; size_t blocksize, len;
u_char *char_ptr; u_char *char_ptr;
blocksize = nand_info[0].erasesize; blocksize = nand_info[0]->erasesize;
len = min(blocksize, (size_t)CONFIG_ENV_SIZE); len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
while (amount_saved < CONFIG_ENV_SIZE && offset < end) { while (amount_saved < CONFIG_ENV_SIZE && offset < end) {
if (nand_block_isbad(&nand_info[0], offset)) { if (nand_block_isbad(nand_info[0], offset)) {
offset += blocksize; offset += blocksize;
} else { } else {
char_ptr = &buf[amount_saved]; char_ptr = &buf[amount_saved];
if (nand_write(&nand_info[0], offset, &len, char_ptr)) if (nand_write(nand_info[0], offset, &len, char_ptr))
return 1; return 1;
offset += blocksize; offset += blocksize;
...@@ -164,7 +164,7 @@ static int erase_and_write_env(const struct env_location *location, ...@@ -164,7 +164,7 @@ static int erase_and_write_env(const struct env_location *location,
int ret = 0; int ret = 0;
printf("Erasing %s...\n", location->name); printf("Erasing %s...\n", location->name);
if (nand_erase_opts(&nand_info[0], &location->erase_opts)) if (nand_erase_opts(nand_info[0], &location->erase_opts))
return 1; return 1;
printf("Writing to %s... ", location->name); printf("Writing to %s... ", location->name);
...@@ -247,20 +247,20 @@ static int readenv(size_t offset, u_char *buf) ...@@ -247,20 +247,20 @@ static int readenv(size_t offset, u_char *buf)
size_t blocksize, len; size_t blocksize, len;
u_char *char_ptr; u_char *char_ptr;
blocksize = nand_info[0].erasesize; blocksize = nand_info[0]->erasesize;
if (!blocksize) if (!blocksize)
return 1; return 1;
len = min(blocksize, (size_t)CONFIG_ENV_SIZE); len = min(blocksize, (size_t)CONFIG_ENV_SIZE);
while (amount_loaded < CONFIG_ENV_SIZE && offset < end) { while (amount_loaded < CONFIG_ENV_SIZE && offset < end) {
if (nand_block_isbad(&nand_info[0], offset)) { if (nand_block_isbad(nand_info[0], offset)) {
offset += blocksize; offset += blocksize;
} else { } else {
char_ptr = &buf[amount_loaded]; char_ptr = &buf[amount_loaded];
if (nand_read_skip_bad(&nand_info[0], offset, if (nand_read_skip_bad(nand_info[0], offset,
&len, NULL, &len, NULL,
nand_info[0].size, char_ptr)) nand_info[0]->size, char_ptr))
return 1; return 1;
offset += blocksize; offset += blocksize;
...@@ -387,7 +387,7 @@ void env_relocate_spec(void) ...@@ -387,7 +387,7 @@ void env_relocate_spec(void)
ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE); ALLOC_CACHE_ALIGN_BUFFER(char, buf, CONFIG_ENV_SIZE);
#if defined(CONFIG_ENV_OFFSET_OOB) #if defined(CONFIG_ENV_OFFSET_OOB)
ret = get_nand_env_oob(&nand_info[0], &nand_env_oob_offset); ret = get_nand_env_oob(nand_info[0], &nand_env_oob_offset);
/* /*
* If unable to read environment offset from NAND OOB then fall through * If unable to read environment offset from NAND OOB then fall through
* to the normal environment reading code below * to the normal environment reading code below
......
...@@ -62,7 +62,7 @@ static int fb_nand_lookup(const char *partname, char *response, ...@@ -62,7 +62,7 @@ static int fb_nand_lookup(const char *partname, char *response,
return -EINVAL; return -EINVAL;
} }
*mtd = &nand_info[dev->id->num]; *mtd = nand_info[dev->id->num];
return 0; return 0;
} }
......
...@@ -45,9 +45,9 @@ static int splash_sf_read_raw(u32 bmp_load_addr, int offset, size_t read_size) ...@@ -45,9 +45,9 @@ static int splash_sf_read_raw(u32 bmp_load_addr, int offset, size_t read_size)
#ifdef CONFIG_CMD_NAND #ifdef CONFIG_CMD_NAND
static int splash_nand_read_raw(u32 bmp_load_addr, int offset, size_t read_size) static int splash_nand_read_raw(u32 bmp_load_addr, int offset, size_t read_size)
{ {
return nand_read_skip_bad(&nand_info[nand_curr_device], offset, return nand_read_skip_bad(nand_info[nand_curr_device], offset,
&read_size, NULL, &read_size, NULL,
nand_info[nand_curr_device].size, nand_info[nand_curr_device]->size,
(u_char *)bmp_load_addr); (u_char *)bmp_load_addr);
} }
#else #else
......
...@@ -136,15 +136,8 @@ Configuration Options: ...@@ -136,15 +136,8 @@ Configuration Options:
Example of new init to be added to the end of an existing driver Example of new init to be added to the end of an existing driver
init: init:
/*
* devnum is the device number to be used in nand commands
* and in mtd->name. Must be less than
* CONFIG_SYS_NAND_MAX_DEVICE.
*/
mtd = &nand_info[devnum];
/* chip is struct nand_chip, and is now provided by the driver. */ /* chip is struct nand_chip, and is now provided by the driver. */
mtd->priv = &chip; mtd = &chip.mtd;
/* /*
* Fill in appropriate values if this driver uses these fields, * Fill in appropriate values if this driver uses these fields,
...@@ -165,7 +158,11 @@ Configuration Options: ...@@ -165,7 +158,11 @@ Configuration Options:
if (nand_scan_tail(mtd)) if (nand_scan_tail(mtd))
error out error out
if (nand_register(devnum)) /*
* devnum is the device number to be used in nand commands
* and in mtd->name. Must be less than CONFIG_SYS_NAND_MAX_DEVICE.
*/
if (nand_register(devnum, mtd))
error out error out
In addition to providing more flexibility to the driver, it reduces In addition to providing more flexibility to the driver, it reduces
......
...@@ -39,12 +39,12 @@ static int nand_block_op(enum dfu_op op, struct dfu_entity *dfu, ...@@ -39,12 +39,12 @@ static int nand_block_op(enum dfu_op op, struct dfu_entity *dfu,
if (nand_curr_device < 0 || if (nand_curr_device < 0 ||
nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE || nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
!nand_info[nand_curr_device].name) { !nand_info[nand_curr_device]->name) {
printf("%s: invalid nand device\n", __func__); printf("%s: invalid nand device\n", __func__);
return -1; return -1;
} }
mtd = &nand_info[nand_curr_device]; mtd = nand_info[nand_curr_device];
if (op == DFU_OP_READ) { if (op == DFU_OP_READ) {
ret = nand_read_skip_bad(mtd, start, &count, &actual, ret = nand_read_skip_bad(mtd, start, &count, &actual,
...@@ -147,12 +147,12 @@ static int dfu_flush_medium_nand(struct dfu_entity *dfu) ...@@ -147,12 +147,12 @@ static int dfu_flush_medium_nand(struct dfu_entity *dfu)
if (nand_curr_device < 0 || if (nand_curr_device < 0 ||
nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE || nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
!nand_info[nand_curr_device].name) { !nand_info[nand_curr_device]->name) {
printf("%s: invalid nand device\n", __func__); printf("%s: invalid nand device\n", __func__);
return -1; return -1;
} }
mtd = &nand_info[nand_curr_device]; mtd = nand_info[nand_curr_device];
memset(&opts, 0, sizeof(opts)); memset(&opts, 0, sizeof(opts));
opts.offset = dfu->data.nand.start + dfu->offset + opts.offset = dfu->data.nand.start + dfu->offset +
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include <linux/mtd/nand_ecc.h> #include <linux/mtd/nand_ecc.h>
static int nand_ecc_pos[] = CONFIG_SYS_NAND_ECCPOS; static int nand_ecc_pos[] = CONFIG_SYS_NAND_ECCPOS;
struct mtd_info nand_info[1]; static struct mtd_info *mtd;
static struct nand_chip nand_chip; static struct nand_chip nand_chip;
#define ECCSTEPS (CONFIG_SYS_NAND_PAGE_SIZE / \ #define ECCSTEPS (CONFIG_SYS_NAND_PAGE_SIZE / \
...@@ -30,12 +30,12 @@ static struct nand_chip nand_chip; ...@@ -30,12 +30,12 @@ static struct nand_chip nand_chip;
static int nand_command(int block, int page, uint32_t offs, static int nand_command(int block, int page, uint32_t offs,
u8 cmd) u8 cmd)
{ {
struct nand_chip *this = nand_info[0].priv; struct nand_chip *this = mtd->priv;
int page_addr = page + block * CONFIG_SYS_NAND_PAGE_COUNT; int page_addr = page + block * CONFIG_SYS_NAND_PAGE_COUNT;
void (*hwctrl)(struct mtd_info *mtd, int cmd, void (*hwctrl)(struct mtd_info *mtd, int cmd,
unsigned int ctrl) = this->cmd_ctrl; unsigned int ctrl) = this->cmd_ctrl;
while (!this->dev_ready(&nand_info[0])) while (!this->dev_ready(mtd))