wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Driver for NAND support, Rick Bronson |
| 3 | * borrowed heavily from: |
| 4 | * (c) 1999 Machine Vision Holdings, Inc. |
| 5 | * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org> |
wdenk | 384cc68 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 6 | * |
| 7 | * Added 16-bit nand support |
| 8 | * (C) 2004 Texas Instruments |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 12 | |
| 13 | |
| 14 | #ifndef CFG_NAND_LEGACY |
| 15 | /* |
| 16 | * |
| 17 | * New NAND support |
| 18 | * |
| 19 | */ |
| 20 | #include <common.h> |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 21 | #include <linux/mtd/mtd.h> |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 22 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 23 | #if defined(CONFIG_CMD_NAND) |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 24 | |
| 25 | #include <command.h> |
| 26 | #include <watchdog.h> |
| 27 | #include <malloc.h> |
| 28 | #include <asm/byteorder.h> |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 29 | #include <jffs2/jffs2.h> |
| 30 | #include <nand.h> |
| 31 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 32 | #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE) |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 33 | |
| 34 | /* parition handling routines */ |
| 35 | int mtdparts_init(void); |
| 36 | int id_parse(const char *id, const char **ret_id, u8 *dev_type, u8 *dev_num); |
| 37 | int find_dev_and_part(const char *id, struct mtd_device **dev, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 38 | u8 *part_num, struct part_info **part); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 39 | #endif |
| 40 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 41 | static int nand_dump_oob(nand_info_t *nand, ulong off) |
| 42 | { |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static int nand_dump(nand_info_t *nand, ulong off) |
| 47 | { |
| 48 | int i; |
| 49 | u_char *buf, *p; |
| 50 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 51 | buf = malloc(nand->writesize + nand->oobsize); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 52 | if (!buf) { |
| 53 | puts("No memory for page buffer\n"); |
| 54 | return 1; |
| 55 | } |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 56 | off &= ~(nand->writesize - 1); |
| 57 | #if 0 |
| 58 | i = nand_read_raw(nand, buf, off, nand->writesize, nand->oobsize); |
| 59 | #else |
| 60 | size_t dummy; |
| 61 | loff_t addr = (loff_t) off; |
| 62 | i = nand->read(nand, addr, nand->writesize, &dummy, buf); |
| 63 | #endif |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 64 | if (i < 0) { |
Stefan Roese | e870690 | 2008-07-10 10:10:54 +0200 | [diff] [blame] | 65 | printf("Error (%d) reading page %08lx\n", i, off); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 66 | free(buf); |
| 67 | return 1; |
| 68 | } |
Stefan Roese | e870690 | 2008-07-10 10:10:54 +0200 | [diff] [blame] | 69 | printf("Page %08lx dump:\n", off); |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 70 | i = nand->writesize >> 4; p = buf; |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 71 | while (i--) { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 72 | printf("\t%02x %02x %02x %02x %02x %02x %02x %02x" |
| 73 | " %02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 74 | p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], |
| 75 | p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 76 | p += 16; |
| 77 | } |
| 78 | puts("OOB:\n"); |
| 79 | i = nand->oobsize >> 3; |
| 80 | while (i--) { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 81 | printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 82 | p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 83 | p += 8; |
| 84 | } |
| 85 | free(buf); |
| 86 | |
| 87 | return 0; |
| 88 | } |
| 89 | |
| 90 | /* ------------------------------------------------------------------------- */ |
| 91 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 92 | static inline int str2long(char *p, ulong *num) |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 93 | { |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 94 | char *endptr; |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 95 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 96 | *num = simple_strtoul(p, &endptr, 16); |
| 97 | return (*p != '\0' && *endptr == '\0') ? 1 : 0; |
| 98 | } |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 99 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 100 | static int |
Wolfgang Denk | 4ca79f4 | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 101 | arg_off_size(int argc, char *argv[], nand_info_t *nand, ulong *off, size_t *size) |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 102 | { |
| 103 | int idx = nand_curr_device; |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 104 | #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE) |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 105 | struct mtd_device *dev; |
| 106 | struct part_info *part; |
| 107 | u8 pnum; |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 108 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 109 | if (argc >= 1 && !(str2long(argv[0], off))) { |
| 110 | if ((mtdparts_init() == 0) && |
| 111 | (find_dev_and_part(argv[0], &dev, &pnum, &part) == 0)) { |
| 112 | if (dev->id->type != MTD_DEV_TYPE_NAND) { |
| 113 | puts("not a NAND device\n"); |
| 114 | return -1; |
| 115 | } |
| 116 | *off = part->offset; |
| 117 | if (argc >= 2) { |
Wolfgang Denk | 42ffcec | 2008-04-30 17:46:26 +0200 | [diff] [blame] | 118 | if (!(str2long(argv[1], (ulong *)size))) { |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 119 | printf("'%s' is not a number\n", argv[1]); |
| 120 | return -1; |
| 121 | } |
| 122 | if (*size > part->size) |
| 123 | *size = part->size; |
| 124 | } else { |
| 125 | *size = part->size; |
| 126 | } |
| 127 | idx = dev->id->num; |
| 128 | *nand = nand_info[idx]; |
| 129 | goto out; |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 130 | } |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 131 | } |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 132 | #endif |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 133 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 134 | if (argc >= 1) { |
| 135 | if (!(str2long(argv[0], off))) { |
| 136 | printf("'%s' is not a number\n", argv[0]); |
| 137 | return -1; |
| 138 | } |
| 139 | } else { |
| 140 | *off = 0; |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 141 | } |
| 142 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 143 | if (argc >= 2) { |
Wolfgang Denk | 4ca79f4 | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 144 | if (!(str2long(argv[1], (ulong *)size))) { |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 145 | printf("'%s' is not a number\n", argv[1]); |
| 146 | return -1; |
| 147 | } |
| 148 | } else { |
| 149 | *size = nand->size - *off; |
| 150 | } |
| 151 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 152 | #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE) |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 153 | out: |
| 154 | #endif |
| 155 | printf("device %d ", idx); |
| 156 | if (*size == nand->size) |
| 157 | puts("whole chip\n"); |
| 158 | else |
Stefan Roese | e870690 | 2008-07-10 10:10:54 +0200 | [diff] [blame] | 159 | printf("offset 0x%lx, size 0x%x\n", *off, *size); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 160 | return 0; |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 164 | { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 165 | int i, dev, ret = 0; |
Wolfgang Denk | 4ca79f4 | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 166 | ulong addr, off; |
| 167 | size_t size; |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 168 | char *cmd, *s; |
| 169 | nand_info_t *nand; |
Matthias Fuchs | c750d2e | 2007-09-12 12:36:53 +0200 | [diff] [blame] | 170 | #ifdef CFG_NAND_QUIET |
| 171 | int quiet = CFG_NAND_QUIET; |
| 172 | #else |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 173 | int quiet = 0; |
Matthias Fuchs | c750d2e | 2007-09-12 12:36:53 +0200 | [diff] [blame] | 174 | #endif |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 175 | const char *quiet_str = getenv("quiet"); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 176 | |
| 177 | /* at least two arguments please */ |
| 178 | if (argc < 2) |
| 179 | goto usage; |
| 180 | |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 181 | if (quiet_str) |
| 182 | quiet = simple_strtoul(quiet_str, NULL, 0) != 0; |
| 183 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 184 | cmd = argv[1]; |
| 185 | |
| 186 | if (strcmp(cmd, "info") == 0) { |
| 187 | |
| 188 | putc('\n'); |
| 189 | for (i = 0; i < CFG_MAX_NAND_DEVICE; i++) { |
| 190 | if (nand_info[i].name) |
Stefan Roese | e870690 | 2008-07-10 10:10:54 +0200 | [diff] [blame] | 191 | printf("Device %d: %s, sector size %u KiB\n", |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 192 | i, nand_info[i].name, |
| 193 | nand_info[i].erasesize >> 10); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 194 | } |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | if (strcmp(cmd, "device") == 0) { |
| 199 | |
| 200 | if (argc < 3) { |
| 201 | if ((nand_curr_device < 0) || |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 202 | (nand_curr_device >= CFG_MAX_NAND_DEVICE)) |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 203 | puts("\nno devices available\n"); |
| 204 | else |
| 205 | printf("\nDevice %d: %s\n", nand_curr_device, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 206 | nand_info[nand_curr_device].name); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
| 210 | if (dev < 0 || dev >= CFG_MAX_NAND_DEVICE || !nand_info[dev].name) { |
| 211 | puts("No such device\n"); |
| 212 | return 1; |
| 213 | } |
| 214 | printf("Device %d: %s", dev, nand_info[dev].name); |
| 215 | puts("... is now current device\n"); |
| 216 | nand_curr_device = dev; |
Stefan Roese | 43a2b0e | 2006-10-20 14:28:52 +0200 | [diff] [blame] | 217 | |
| 218 | #ifdef CFG_NAND_SELECT_DEVICE |
| 219 | /* |
| 220 | * Select the chip in the board/cpu specific driver |
| 221 | */ |
| 222 | board_nand_select_device(nand_info[dev].priv, dev); |
| 223 | #endif |
| 224 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 && |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 229 | strncmp(cmd, "dump", 4) != 0 && |
| 230 | strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 && |
| 231 | strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 && |
| 232 | strcmp(cmd, "biterr") != 0 && |
| 233 | strcmp(cmd, "lock") != 0 && strcmp(cmd, "unlock") != 0 ) |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 234 | goto usage; |
| 235 | |
| 236 | /* the following commands operate on the current device */ |
| 237 | if (nand_curr_device < 0 || nand_curr_device >= CFG_MAX_NAND_DEVICE || |
| 238 | !nand_info[nand_curr_device].name) { |
| 239 | puts("\nno devices available\n"); |
| 240 | return 1; |
| 241 | } |
| 242 | nand = &nand_info[nand_curr_device]; |
| 243 | |
| 244 | if (strcmp(cmd, "bad") == 0) { |
| 245 | printf("\nDevice %d bad blocks:\n", nand_curr_device); |
| 246 | for (off = 0; off < nand->size; off += nand->erasesize) |
| 247 | if (nand_block_isbad(nand, off)) |
Stefan Roese | e870690 | 2008-07-10 10:10:54 +0200 | [diff] [blame] | 248 | printf(" %08lx\n", off); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 249 | return 0; |
| 250 | } |
| 251 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 252 | /* |
| 253 | * Syntax is: |
| 254 | * 0 1 2 3 4 |
| 255 | * nand erase [clean] [off size] |
| 256 | */ |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 257 | if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) { |
| 258 | nand_erase_options_t opts; |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 259 | /* "clean" at index 2 means request to write cleanmarker */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 260 | int clean = !strcmp("clean", argv[2]); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 261 | int o = clean ? 3 : 2; |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 262 | int scrub = !strcmp(cmd, "scrub"); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 263 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 264 | printf("\nNAND %s: ", scrub ? "scrub" : "erase"); |
| 265 | /* skip first two or three arguments, look for offset and size */ |
| 266 | if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0) |
| 267 | return 1; |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 268 | |
| 269 | memset(&opts, 0, sizeof(opts)); |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 270 | |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 271 | opts.offset = off; |
| 272 | opts.length = size; |
| 273 | opts.jffs2 = clean; |
| 274 | opts.quiet = quiet; |
| 275 | |
| 276 | if (scrub) { |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 277 | puts("Warning: " |
| 278 | "scrub option will erase all factory set " |
| 279 | "bad blocks!\n" |
| 280 | " " |
| 281 | "There is no reliable way to recover them.\n" |
| 282 | " " |
| 283 | "Use this command only for testing purposes " |
| 284 | "if you\n" |
| 285 | " " |
| 286 | "are sure of what you are doing!\n" |
| 287 | "\nReally scrub this NAND flash? <y/N>\n"); |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 288 | |
| 289 | if (getc() == 'y' && getc() == '\r') { |
| 290 | opts.scrub = 1; |
| 291 | } else { |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 292 | puts("scrub aborted\n"); |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 293 | return -1; |
| 294 | } |
| 295 | } |
| 296 | ret = nand_erase_opts(nand, &opts); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 297 | printf("%s\n", ret ? "ERROR" : "OK"); |
| 298 | |
| 299 | return ret == 0 ? 0 : 1; |
| 300 | } |
| 301 | |
| 302 | if (strncmp(cmd, "dump", 4) == 0) { |
| 303 | if (argc < 3) |
| 304 | goto usage; |
| 305 | |
| 306 | s = strchr(cmd, '.'); |
| 307 | off = (int)simple_strtoul(argv[2], NULL, 16); |
| 308 | |
| 309 | if (s != NULL && strcmp(s, ".oob") == 0) |
| 310 | ret = nand_dump_oob(nand, off); |
| 311 | else |
| 312 | ret = nand_dump(nand, off); |
| 313 | |
| 314 | return ret == 0 ? 1 : 0; |
| 315 | |
| 316 | } |
| 317 | |
| 318 | /* read write */ |
| 319 | if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) { |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 320 | int read; |
| 321 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 322 | if (argc < 4) |
| 323 | goto usage; |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 324 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 325 | addr = (ulong)simple_strtoul(argv[2], NULL, 16); |
| 326 | |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 327 | read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */ |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 328 | printf("\nNAND %s: ", read ? "read" : "write"); |
| 329 | if (arg_off_size(argc - 3, argv + 3, nand, &off, &size) != 0) |
| 330 | return 1; |
William Juul | 4cbb651 | 2007-11-08 10:39:53 +0100 | [diff] [blame^] | 331 | |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 332 | s = strchr(cmd, '.'); |
| 333 | if (s != NULL && |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 334 | (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i"))) { |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 335 | if (read) { |
| 336 | /* read */ |
| 337 | nand_read_options_t opts; |
| 338 | memset(&opts, 0, sizeof(opts)); |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 339 | opts.buffer = (u_char*) addr; |
| 340 | opts.length = size; |
| 341 | opts.offset = off; |
| 342 | opts.quiet = quiet; |
| 343 | // ret = nand_read_opts(nand, &opts); |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 344 | } else { |
| 345 | /* write */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 346 | mtd_oob_ops_t opts; |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 347 | memset(&opts, 0, sizeof(opts)); |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 348 | opts.datbuf = (u_char*) addr; |
| 349 | opts.len = size; |
| 350 | opts.ooblen = 64; |
| 351 | opts.mode = MTD_OOB_AUTO; |
| 352 | ret = nand_write_opts(nand, off, &opts); |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 353 | } |
Harald Welte | 62d4f43 | 2007-12-19 14:12:53 +0100 | [diff] [blame] | 354 | } else if (s != NULL && !strcmp(s, ".oob")) { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 355 | /* out-of-band data */ |
| 356 | mtd_oob_ops_t ops = { |
| 357 | .oobbuf = (u8 *)addr, |
| 358 | .ooblen = size, |
| 359 | .mode = MTD_OOB_RAW |
| 360 | }; |
| 361 | |
Harald Welte | 62d4f43 | 2007-12-19 14:12:53 +0100 | [diff] [blame] | 362 | if (read) |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 363 | ret = nand->read_oob(nand, off, &ops); |
Harald Welte | 62d4f43 | 2007-12-19 14:12:53 +0100 | [diff] [blame] | 364 | else |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 365 | ret = nand->write_oob(nand, off, &ops); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 366 | } else { |
| 367 | if (read) |
| 368 | ret = nand_read(nand, off, &size, (u_char *)addr); |
| 369 | else |
| 370 | ret = nand_write(nand, off, &size, (u_char *)addr); |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 371 | } |
| 372 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 373 | printf(" %d bytes %s: %s\n", size, |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 374 | read ? "read" : "written", ret ? "ERROR" : "OK"); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 375 | |
| 376 | return ret == 0 ? 0 : 1; |
| 377 | } |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 378 | |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 379 | if (strcmp(cmd, "markbad") == 0) { |
| 380 | addr = (ulong)simple_strtoul(argv[2], NULL, 16); |
| 381 | |
| 382 | int ret = nand->block_markbad(nand, addr); |
| 383 | if (ret == 0) { |
| 384 | printf("block 0x%08lx successfully marked as bad\n", |
| 385 | (ulong) addr); |
| 386 | return 0; |
| 387 | } else { |
| 388 | printf("block 0x%08lx NOT marked as bad! ERROR %d\n", |
| 389 | (ulong) addr, ret); |
| 390 | } |
| 391 | return 1; |
| 392 | } |
| 393 | if (strcmp(cmd, "biterr") == 0) { |
| 394 | /* todo */ |
| 395 | return 1; |
| 396 | } |
| 397 | |
| 398 | if (strcmp(cmd, "lock") == 0) { |
| 399 | int tight = 0; |
| 400 | int status = 0; |
| 401 | if (argc == 3) { |
| 402 | if (!strcmp("tight", argv[2])) |
| 403 | tight = 1; |
| 404 | if (!strcmp("status", argv[2])) |
| 405 | status = 1; |
| 406 | } |
| 407 | |
| 408 | if (status) { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 409 | // ulong block_start = 0; |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 410 | ulong off; |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 411 | // int last_status = -1; |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 412 | |
| 413 | struct nand_chip *nand_chip = nand->priv; |
| 414 | /* check the WP bit */ |
| 415 | nand_chip->cmdfunc (nand, NAND_CMD_STATUS, -1, -1); |
| 416 | printf("device is %swrite protected\n", |
| 417 | (nand_chip->read_byte(nand) & 0x80 ? |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 418 | "NOT " : "" ) ); |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 419 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 420 | for (off = 0; off < nand->size; off += nand->writesize) { |
| 421 | // int s = nand_get_lock_status(nand, off); |
| 422 | // |
| 423 | // /* print message only if status has changed |
| 424 | // * or at end of chip |
| 425 | // */ |
| 426 | // if (off == nand->size - nand->writesize |
| 427 | // || (s != last_status && off != 0)) { |
| 428 | // |
| 429 | // printf("%08lx - %08lx: %8d pages %s%s%s\n", |
| 430 | // block_start, |
| 431 | // off-1, |
| 432 | // (off-block_start)/nand->writesize, |
| 433 | // ((last_status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""), |
| 434 | // ((last_status & NAND_LOCK_STATUS_LOCK) ? "LOCK " : ""), |
| 435 | // ((last_status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : "")); |
| 436 | // } |
| 437 | // |
| 438 | // last_status = s; |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 439 | } |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 440 | } else { |
| 441 | // if (!nand_lock(nand, tight)) { |
| 442 | // puts("NAND flash successfully locked\n"); |
| 443 | // } else { |
| 444 | // puts("Error locking NAND flash\n"); |
| 445 | // return 1; |
| 446 | // } |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 447 | } |
| 448 | return 0; |
| 449 | } |
| 450 | |
| 451 | if (strcmp(cmd, "unlock") == 0) { |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 452 | if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0) |
| 453 | return 1; |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 454 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 455 | // if (!nand_unlock(nand, off, size)) { |
| 456 | // puts("NAND flash successfully unlocked\n"); |
| 457 | // } else { |
| 458 | // puts("Error unlocking NAND flash, " |
| 459 | // "write and erase will probably fail\n"); |
| 460 | // return 1; |
| 461 | // } |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 462 | return 0; |
| 463 | } |
| 464 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 465 | usage: |
| 466 | printf("Usage:\n%s\n", cmdtp->usage); |
| 467 | return 1; |
| 468 | } |
| 469 | |
| 470 | U_BOOT_CMD(nand, 5, 1, do_nand, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 471 | "nand - NAND sub-system\n", |
| 472 | "info - show available NAND devices\n" |
| 473 | "nand device [dev] - show or set current device\n" |
| 474 | "nand read[.jffs2] - addr off|partition size\n" |
| 475 | "nand write[.jffs2] - addr off|partition size\n" |
| 476 | " read/write 'size' bytes starting at offset 'off'\n" |
| 477 | " to/from memory address 'addr'\n" |
| 478 | "nand erase [clean] [off size] - erase 'size' bytes from\n" |
| 479 | " offset 'off' (entire device if not specified)\n" |
| 480 | "nand bad - show bad blocks\n" |
| 481 | "nand dump[.oob] off - dump page\n" |
| 482 | "nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n" |
| 483 | "nand markbad off - mark bad block at offset (UNSAFE)\n" |
| 484 | "nand biterr off - make a bit error at offset (UNSAFE)\n" |
| 485 | "nand lock [tight] [status]\n" |
| 486 | " bring nand to lock state or display locked pages\n" |
| 487 | "nand unlock [offset] [size] - unlock section\n"); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 488 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 489 | static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 490 | ulong offset, ulong addr, char *cmd) |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 491 | { |
| 492 | int r; |
Thomas Knobloch | 10e0389 | 2007-07-06 14:58:39 +0200 | [diff] [blame] | 493 | char *ep, *s; |
Wolfgang Denk | 4ca79f4 | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 494 | size_t cnt; |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 495 | image_header_t *hdr; |
Thomas Knobloch | 10e0389 | 2007-07-06 14:58:39 +0200 | [diff] [blame] | 496 | int jffs2 = 0; |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 497 | #if defined(CONFIG_FIT) |
Marian Balakowicz | 3bab76a | 2008-06-06 23:07:40 +0200 | [diff] [blame] | 498 | const void *fit_hdr = NULL; |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 499 | #endif |
Thomas Knobloch | 10e0389 | 2007-07-06 14:58:39 +0200 | [diff] [blame] | 500 | |
| 501 | s = strchr(cmd, '.'); |
| 502 | if (s != NULL && |
| 503 | (!strcmp(s, ".jffs2") || !strcmp(s, ".e") || !strcmp(s, ".i"))) |
| 504 | jffs2 = 1; |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 505 | |
| 506 | printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset); |
| 507 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 508 | cnt = nand->writesize; |
| 509 | r = nand_read(nand, offset, &cnt, (u_char *) addr); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 510 | if (r) { |
| 511 | puts("** Read error\n"); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 512 | show_boot_progress (-56); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 513 | return 1; |
| 514 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 515 | show_boot_progress (56); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 516 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 517 | switch (genimg_get_format ((void *)addr)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 518 | case IMAGE_FORMAT_LEGACY: |
| 519 | hdr = (image_header_t *)addr; |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 520 | |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 521 | show_boot_progress (57); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 522 | image_print_contents (hdr); |
| 523 | |
| 524 | cnt = image_get_image_size (hdr); |
| 525 | break; |
| 526 | #if defined(CONFIG_FIT) |
| 527 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 528 | fit_hdr = (const void *)addr; |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 529 | puts ("Fit image detected...\n"); |
| 530 | |
| 531 | cnt = fit_get_size (fit_hdr); |
| 532 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 533 | #endif |
| 534 | default: |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 535 | show_boot_progress (-57); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 536 | puts ("** Unknown image type\n"); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 537 | return 1; |
| 538 | } |
| 539 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 540 | r = nand_read(nand, offset, &cnt, (u_char *) addr); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 541 | if (r) { |
| 542 | puts("** Read error\n"); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 543 | show_boot_progress (-58); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 544 | return 1; |
| 545 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 546 | show_boot_progress (58); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 547 | |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 548 | #if defined(CONFIG_FIT) |
| 549 | /* This cannot be done earlier, we need complete FIT image in RAM first */ |
Marian Balakowicz | 3bab76a | 2008-06-06 23:07:40 +0200 | [diff] [blame] | 550 | if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) { |
| 551 | if (!fit_check_format (fit_hdr)) { |
| 552 | show_boot_progress (-150); |
| 553 | puts ("** Bad FIT image format\n"); |
| 554 | return 1; |
| 555 | } |
| 556 | show_boot_progress (151); |
| 557 | fit_print_contents (fit_hdr); |
| 558 | } |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 559 | #endif |
| 560 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 561 | /* Loading ok, update default load address */ |
| 562 | |
| 563 | load_addr = addr; |
| 564 | |
| 565 | /* Check if we should attempt an auto-start */ |
| 566 | if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) { |
| 567 | char *local_args[2]; |
| 568 | extern int do_bootm(cmd_tbl_t *, int, int, char *[]); |
| 569 | |
| 570 | local_args[0] = cmd; |
| 571 | local_args[1] = NULL; |
| 572 | |
| 573 | printf("Automatic boot of image at addr 0x%08lx ...\n", addr); |
| 574 | |
| 575 | do_bootm(cmdtp, 0, 1, local_args); |
| 576 | return 1; |
| 577 | } |
| 578 | return 0; |
| 579 | } |
| 580 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 581 | int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 582 | { |
| 583 | char *boot_device = NULL; |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 584 | int idx; |
| 585 | ulong addr, offset = 0; |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 586 | #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE) |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 587 | struct mtd_device *dev; |
| 588 | struct part_info *part; |
| 589 | u8 pnum; |
| 590 | |
| 591 | if (argc >= 2) { |
| 592 | char *p = (argc == 2) ? argv[1] : argv[2]; |
| 593 | if (!(str2long(p, &addr)) && (mtdparts_init() == 0) && |
| 594 | (find_dev_and_part(p, &dev, &pnum, &part) == 0)) { |
| 595 | if (dev->id->type != MTD_DEV_TYPE_NAND) { |
| 596 | puts("Not a NAND device\n"); |
| 597 | return 1; |
| 598 | } |
| 599 | if (argc > 3) |
| 600 | goto usage; |
| 601 | if (argc == 3) |
Thomas Knobloch | 10e0389 | 2007-07-06 14:58:39 +0200 | [diff] [blame] | 602 | addr = simple_strtoul(argv[1], NULL, 16); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 603 | else |
| 604 | addr = CFG_LOAD_ADDR; |
| 605 | return nand_load_image(cmdtp, &nand_info[dev->id->num], |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 606 | part->offset, addr, argv[0]); |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | #endif |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 610 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 611 | show_boot_progress(52); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 612 | switch (argc) { |
| 613 | case 1: |
| 614 | addr = CFG_LOAD_ADDR; |
| 615 | boot_device = getenv("bootdevice"); |
| 616 | break; |
| 617 | case 2: |
| 618 | addr = simple_strtoul(argv[1], NULL, 16); |
| 619 | boot_device = getenv("bootdevice"); |
| 620 | break; |
| 621 | case 3: |
| 622 | addr = simple_strtoul(argv[1], NULL, 16); |
| 623 | boot_device = argv[2]; |
| 624 | break; |
| 625 | case 4: |
| 626 | addr = simple_strtoul(argv[1], NULL, 16); |
| 627 | boot_device = argv[2]; |
| 628 | offset = simple_strtoul(argv[3], NULL, 16); |
| 629 | break; |
| 630 | default: |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 631 | #if defined(CONFIG_CMD_JFFS2) && defined(CONFIG_JFFS2_CMDLINE) |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 632 | usage: |
| 633 | #endif |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 634 | printf("Usage:\n%s\n", cmdtp->usage); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 635 | show_boot_progress(-53); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 636 | return 1; |
| 637 | } |
| 638 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 639 | show_boot_progress(53); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 640 | if (!boot_device) { |
| 641 | puts("\n** No boot device **\n"); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 642 | show_boot_progress(-54); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 643 | return 1; |
| 644 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 645 | show_boot_progress(54); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 646 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 647 | idx = simple_strtoul(boot_device, NULL, 16); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 648 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 649 | if (idx < 0 || idx >= CFG_MAX_NAND_DEVICE || !nand_info[idx].name) { |
| 650 | printf("\n** Device %d not available\n", idx); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 651 | show_boot_progress(-55); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 652 | return 1; |
| 653 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 654 | show_boot_progress(55); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 655 | |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 656 | return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | U_BOOT_CMD(nboot, 4, 1, do_nandboot, |
Stefan Roese | 856f054 | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 660 | "nboot - boot from NAND device\n", |
Thomas Knobloch | 10e0389 | 2007-07-06 14:58:39 +0200 | [diff] [blame] | 661 | "[.jffs2] [partition] | [[[loadAddr] dev] offset]\n"); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 662 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 663 | #endif |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 664 | |
| 665 | #else /* CFG_NAND_LEGACY */ |
| 666 | /* |
| 667 | * |
| 668 | * Legacy NAND support - to be phased out |
| 669 | * |
| 670 | */ |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 671 | #include <command.h> |
| 672 | #include <malloc.h> |
| 673 | #include <asm/io.h> |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 674 | #include <watchdog.h> |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 675 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 676 | #ifdef CONFIG_show_boot_progress |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 677 | # include <status_led.h> |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 678 | # define show_boot_progress(arg) show_boot_progress(arg) |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 679 | #else |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 680 | # define show_boot_progress(arg) |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 681 | #endif |
| 682 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 683 | #if defined(CONFIG_CMD_NAND) |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 684 | #include <linux/mtd/nand_legacy.h> |
| 685 | #if 0 |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 686 | #include <linux/mtd/nand_ids.h> |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 687 | #include <jffs2/jffs2.h> |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 688 | #endif |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 689 | |
wdenk | 1f4bb37 | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 690 | #ifdef CONFIG_OMAP1510 |
| 691 | void archflashwp(void *archdata, int wp); |
| 692 | #endif |
| 693 | |
| 694 | #define ROUND_DOWN(value,boundary) ((value) & (~((boundary)-1))) |
| 695 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 696 | #undef NAND_DEBUG |
| 697 | #undef PSYCHO_DEBUG |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 698 | |
| 699 | /* ****************** WARNING ********************* |
| 700 | * When ALLOW_ERASE_BAD_DEBUG is non-zero the erase command will |
| 701 | * erase (or at least attempt to erase) blocks that are marked |
| 702 | * bad. This can be very handy if you are _sure_ that the block |
| 703 | * is OK, say because you marked a good block bad to test bad |
| 704 | * block handling and you are done testing, or if you have |
| 705 | * accidentally marked blocks bad. |
| 706 | * |
| 707 | * Erasing factory marked bad blocks is a _bad_ idea. If the |
| 708 | * erase succeeds there is no reliable way to find them again, |
| 709 | * and attempting to program or erase bad blocks can affect |
| 710 | * the data in _other_ (good) blocks. |
| 711 | */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 712 | #define ALLOW_ERASE_BAD_DEBUG 0 |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 713 | |
| 714 | #define CONFIG_MTD_NAND_ECC /* enable ECC */ |
wdenk | 1f4bb37 | 2003-07-27 00:21:01 +0000 | [diff] [blame] | 715 | #define CONFIG_MTD_NAND_ECC_JFFS2 |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 716 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 717 | /* bits for nand_legacy_rw() `cmd'; or together as needed */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 718 | #define NANDRW_READ 0x01 |
| 719 | #define NANDRW_WRITE 0x00 |
| 720 | #define NANDRW_JFFS2 0x02 |
| 721 | #define NANDRW_JFFS2_SKIP 0x04 |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 722 | |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 723 | /* |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 724 | * Imports from nand_legacy.c |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 725 | */ |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 726 | extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE]; |
| 727 | extern int curr_device; |
| 728 | extern int nand_legacy_erase(struct nand_chip *nand, size_t ofs, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 729 | size_t len, int clean); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 730 | extern int nand_legacy_rw(struct nand_chip *nand, int cmd, size_t start, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 731 | size_t len, size_t *retlen, u_char *buf); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 732 | extern void nand_print(struct nand_chip *nand); |
| 733 | extern void nand_print_bad(struct nand_chip *nand); |
| 734 | extern int nand_read_oob(struct nand_chip *nand, size_t ofs, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 735 | size_t len, size_t *retlen, u_char *buf); |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 736 | extern int nand_write_oob(struct nand_chip *nand, size_t ofs, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 737 | size_t len, size_t *retlen, const u_char *buf); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 738 | |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 739 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 740 | int do_nand (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 741 | { |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 742 | int rcode = 0; |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 743 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 744 | switch (argc) { |
| 745 | case 0: |
| 746 | case 1: |
| 747 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 748 | return 1; |
| 749 | case 2: |
| 750 | if (strcmp (argv[1], "info") == 0) { |
| 751 | int i; |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 752 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 753 | putc ('\n'); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 754 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 755 | for (i = 0; i < CFG_MAX_NAND_DEVICE; ++i) { |
| 756 | if (nand_dev_desc[i].ChipID == |
| 757 | NAND_ChipID_UNKNOWN) |
| 758 | continue; /* list only known devices */ |
| 759 | printf ("Device %d: ", i); |
| 760 | nand_print (&nand_dev_desc[i]); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 761 | } |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 762 | return 0; |
| 763 | |
| 764 | } else if (strcmp (argv[1], "device") == 0) { |
| 765 | if ((curr_device < 0) |
| 766 | || (curr_device >= CFG_MAX_NAND_DEVICE)) { |
| 767 | puts ("\nno devices available\n"); |
| 768 | return 1; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 769 | } |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 770 | printf ("\nDevice %d: ", curr_device); |
| 771 | nand_print (&nand_dev_desc[curr_device]); |
| 772 | return 0; |
| 773 | |
| 774 | } else if (strcmp (argv[1], "bad") == 0) { |
| 775 | if ((curr_device < 0) |
| 776 | || (curr_device >= CFG_MAX_NAND_DEVICE)) { |
| 777 | puts ("\nno devices available\n"); |
| 778 | return 1; |
| 779 | } |
| 780 | printf ("\nDevice %d bad blocks:\n", curr_device); |
| 781 | nand_print_bad (&nand_dev_desc[curr_device]); |
| 782 | return 0; |
| 783 | |
| 784 | } |
| 785 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 786 | return 1; |
| 787 | case 3: |
| 788 | if (strcmp (argv[1], "device") == 0) { |
| 789 | int dev = (int) simple_strtoul (argv[2], NULL, 10); |
| 790 | |
| 791 | printf ("\nDevice %d: ", dev); |
| 792 | if (dev >= CFG_MAX_NAND_DEVICE) { |
| 793 | puts ("unknown device\n"); |
| 794 | return 1; |
| 795 | } |
| 796 | nand_print (&nand_dev_desc[dev]); |
| 797 | /*nand_print (dev); */ |
| 798 | |
| 799 | if (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN) { |
| 800 | return 1; |
| 801 | } |
| 802 | |
| 803 | curr_device = dev; |
| 804 | |
| 805 | puts ("... is now current device\n"); |
| 806 | |
| 807 | return 0; |
| 808 | } else if (strcmp (argv[1], "erase") == 0 |
| 809 | && strcmp (argv[2], "clean") == 0) { |
| 810 | struct nand_chip *nand = &nand_dev_desc[curr_device]; |
| 811 | ulong off = 0; |
| 812 | ulong size = nand->totlen; |
| 813 | int ret; |
| 814 | |
| 815 | printf ("\nNAND erase: device %d offset %ld, size %ld ... ", curr_device, off, size); |
| 816 | |
| 817 | ret = nand_legacy_erase (nand, off, size, 1); |
| 818 | |
| 819 | printf ("%s\n", ret ? "ERROR" : "OK"); |
| 820 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 821 | return ret; |
| 822 | } |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 823 | |
| 824 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 825 | return 1; |
| 826 | default: |
| 827 | /* at least 4 args */ |
| 828 | |
| 829 | if (strncmp (argv[1], "read", 4) == 0 || |
| 830 | strncmp (argv[1], "write", 5) == 0) { |
Wolfgang Denk | c71abba | 2008-04-28 14:55:12 +0200 | [diff] [blame] | 831 | ulong addr = simple_strtoul (argv[2], NULL, 16); |
| 832 | off_t off = simple_strtoul (argv[3], NULL, 16); |
| 833 | size_t size = simple_strtoul (argv[4], NULL, 16); |
| 834 | int cmd = (strncmp (argv[1], "read", 4) == 0) ? |
| 835 | NANDRW_READ : NANDRW_WRITE; |
| 836 | size_t total; |
| 837 | int ret; |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 838 | char *cmdtail = strchr (argv[1], '.'); |
| 839 | |
| 840 | if (cmdtail && !strncmp (cmdtail, ".oob", 2)) { |
| 841 | /* read out-of-band data */ |
| 842 | if (cmd & NANDRW_READ) { |
| 843 | ret = nand_read_oob (nand_dev_desc + curr_device, |
Wolfgang Denk | 4ca79f4 | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 844 | off, size, &total, |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 845 | (u_char *) addr); |
| 846 | } else { |
| 847 | ret = nand_write_oob (nand_dev_desc + curr_device, |
Wolfgang Denk | 4ca79f4 | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 848 | off, size, &total, |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 849 | (u_char *) addr); |
| 850 | } |
| 851 | return ret; |
| 852 | } else if (cmdtail && !strncmp (cmdtail, ".jffs2", 2)) |
| 853 | cmd |= NANDRW_JFFS2; /* skip bad blocks */ |
| 854 | else if (cmdtail && !strncmp (cmdtail, ".jffs2s", 2)) { |
| 855 | cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */ |
| 856 | if (cmd & NANDRW_READ) |
| 857 | cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */ |
| 858 | } |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 859 | #ifdef SXNI855T |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 860 | /* need ".e" same as ".j" for compatibility with older units */ |
| 861 | else if (cmdtail && !strcmp (cmdtail, ".e")) |
| 862 | cmd |= NANDRW_JFFS2; /* skip bad blocks */ |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 863 | #endif |
stroese | a842a6d | 2004-12-16 17:45:46 +0000 | [diff] [blame] | 864 | #ifdef CFG_NAND_SKIP_BAD_DOT_I |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 865 | /* need ".i" same as ".jffs2s" for compatibility with older units (esd) */ |
| 866 | /* ".i" for image -> read skips bad block (no 0xff) */ |
| 867 | else if (cmdtail && !strcmp (cmdtail, ".i")) { |
| 868 | cmd |= NANDRW_JFFS2; /* skip bad blocks (on read too) */ |
| 869 | if (cmd & NANDRW_READ) |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 870 | cmd |= NANDRW_JFFS2_SKIP; /* skip bad blocks (on read too) */ |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 871 | } |
stroese | a842a6d | 2004-12-16 17:45:46 +0000 | [diff] [blame] | 872 | #endif /* CFG_NAND_SKIP_BAD_DOT_I */ |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 873 | else if (cmdtail) { |
| 874 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 875 | return 1; |
| 876 | } |
| 877 | |
Wolfgang Denk | 9b55a25 | 2008-07-11 01:16:00 +0200 | [diff] [blame] | 878 | printf ("\nNAND %s: device %d offset %ld, size %lu ...\n", |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 879 | (cmd & NANDRW_READ) ? "read" : "write", |
Wolfgang Denk | 9b55a25 | 2008-07-11 01:16:00 +0200 | [diff] [blame] | 880 | curr_device, off, (ulong)size); |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 881 | |
| 882 | ret = nand_legacy_rw (nand_dev_desc + curr_device, |
| 883 | cmd, off, size, |
Wolfgang Denk | 4ca79f4 | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 884 | &total, |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 885 | (u_char *) addr); |
| 886 | |
| 887 | printf (" %d bytes %s: %s\n", total, |
| 888 | (cmd & NANDRW_READ) ? "read" : "written", |
| 889 | ret ? "ERROR" : "OK"); |
| 890 | |
| 891 | return ret; |
| 892 | } else if (strcmp (argv[1], "erase") == 0 && |
| 893 | (argc == 4 || strcmp ("clean", argv[2]) == 0)) { |
| 894 | int clean = argc == 5; |
| 895 | ulong off = |
| 896 | simple_strtoul (argv[2 + clean], NULL, 16); |
| 897 | ulong size = |
| 898 | simple_strtoul (argv[3 + clean], NULL, 16); |
| 899 | int ret; |
| 900 | |
| 901 | printf ("\nNAND erase: device %d offset %ld, size %ld ...\n", |
| 902 | curr_device, off, size); |
| 903 | |
| 904 | ret = nand_legacy_erase (nand_dev_desc + curr_device, |
| 905 | off, size, clean); |
| 906 | |
| 907 | printf ("%s\n", ret ? "ERROR" : "OK"); |
| 908 | |
| 909 | return ret; |
| 910 | } else { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 911 | printf ("Usage:\n%s\n", cmdtp->usage); |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 912 | rcode = 1; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 913 | } |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 914 | |
Wolfgang Denk | dd520bf | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 915 | return rcode; |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 916 | } |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 917 | } |
| 918 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 919 | U_BOOT_CMD( |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 920 | nand, 5, 1, do_nand, |
Stefan Roese | 2255b2d | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 921 | "nand - legacy NAND sub-system\n", |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 922 | "info - show available NAND devices\n" |
| 923 | "nand device [dev] - show or set current device\n" |
wdenk | a3d991b | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 924 | "nand read[.jffs2[s]] addr off size\n" |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 925 | "nand write[.jffs2] addr off size - read/write `size' bytes starting\n" |
| 926 | " at offset `off' to/from memory address `addr'\n" |
| 927 | "nand erase [clean] [off size] - erase `size' bytes from\n" |
| 928 | " offset `off' (entire device if not specified)\n" |
| 929 | "nand bad - show bad blocks\n" |
| 930 | "nand read.oob addr off size - read out-of-band data\n" |
| 931 | "nand write.oob addr off size - read out-of-band data\n" |
| 932 | ); |
| 933 | |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 934 | int do_nandboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 935 | { |
| 936 | char *boot_device = NULL; |
| 937 | char *ep; |
| 938 | int dev; |
| 939 | ulong cnt; |
| 940 | ulong addr; |
| 941 | ulong offset = 0; |
| 942 | image_header_t *hdr; |
| 943 | int rcode = 0; |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 944 | #if defined(CONFIG_FIT) |
Marian Balakowicz | 3bab76a | 2008-06-06 23:07:40 +0200 | [diff] [blame] | 945 | const void *fit_hdr = NULL; |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 946 | #endif |
| 947 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 948 | show_boot_progress (52); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 949 | switch (argc) { |
| 950 | case 1: |
| 951 | addr = CFG_LOAD_ADDR; |
| 952 | boot_device = getenv ("bootdevice"); |
| 953 | break; |
| 954 | case 2: |
| 955 | addr = simple_strtoul(argv[1], NULL, 16); |
| 956 | boot_device = getenv ("bootdevice"); |
| 957 | break; |
| 958 | case 3: |
| 959 | addr = simple_strtoul(argv[1], NULL, 16); |
| 960 | boot_device = argv[2]; |
| 961 | break; |
| 962 | case 4: |
| 963 | addr = simple_strtoul(argv[1], NULL, 16); |
| 964 | boot_device = argv[2]; |
| 965 | offset = simple_strtoul(argv[3], NULL, 16); |
| 966 | break; |
| 967 | default: |
| 968 | printf ("Usage:\n%s\n", cmdtp->usage); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 969 | show_boot_progress (-53); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 970 | return 1; |
| 971 | } |
| 972 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 973 | show_boot_progress (53); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 974 | if (!boot_device) { |
| 975 | puts ("\n** No boot device **\n"); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 976 | show_boot_progress (-54); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 977 | return 1; |
| 978 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 979 | show_boot_progress (54); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 980 | |
| 981 | dev = simple_strtoul(boot_device, &ep, 16); |
| 982 | |
| 983 | if ((dev >= CFG_MAX_NAND_DEVICE) || |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 984 | (nand_dev_desc[dev].ChipID == NAND_ChipID_UNKNOWN)) { |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 985 | printf ("\n** Device %d not available\n", dev); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 986 | show_boot_progress (-55); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 987 | return 1; |
| 988 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 989 | show_boot_progress (55); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 990 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 991 | printf ("\nLoading from device %d: %s at 0x%lx (offset 0x%lx)\n", |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 992 | dev, nand_dev_desc[dev].name, nand_dev_desc[dev].IO_ADDR, |
| 993 | offset); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 994 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 995 | if (nand_legacy_rw (nand_dev_desc + dev, NANDRW_READ, offset, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 996 | SECTORSIZE, NULL, (u_char *)addr)) { |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 997 | printf ("** Read error on %d\n", dev); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 998 | show_boot_progress (-56); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 999 | return 1; |
| 1000 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 1001 | show_boot_progress (56); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1002 | |
Marian Balakowicz | 9a4daad | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 1003 | switch (genimg_get_format ((void *)addr)) { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1004 | case IMAGE_FORMAT_LEGACY: |
| 1005 | hdr = (image_header_t *)addr; |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1006 | image_print_contents (hdr); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1007 | |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1008 | cnt = image_get_image_size (hdr); |
| 1009 | cnt -= SECTORSIZE; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1010 | break; |
| 1011 | #if defined(CONFIG_FIT) |
| 1012 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1013 | fit_hdr = (const void *)addr; |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1014 | puts ("Fit image detected...\n"); |
| 1015 | |
| 1016 | cnt = fit_get_size (fit_hdr); |
| 1017 | break; |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1018 | #endif |
| 1019 | default: |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1020 | show_boot_progress (-57); |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 1021 | puts ("** Unknown image type\n"); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1022 | return 1; |
| 1023 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 1024 | show_boot_progress (57); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1025 | |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 1026 | if (nand_legacy_rw (nand_dev_desc + dev, NANDRW_READ, |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 1027 | offset + SECTORSIZE, cnt, NULL, |
| 1028 | (u_char *)(addr+SECTORSIZE))) { |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1029 | printf ("** Read error on %d\n", dev); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 1030 | show_boot_progress (-58); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1031 | return 1; |
| 1032 | } |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 1033 | show_boot_progress (58); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1034 | |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1035 | #if defined(CONFIG_FIT) |
| 1036 | /* This cannot be done earlier, we need complete FIT image in RAM first */ |
Marian Balakowicz | 3bab76a | 2008-06-06 23:07:40 +0200 | [diff] [blame] | 1037 | if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) { |
| 1038 | if (!fit_check_format (fit_hdr)) { |
| 1039 | show_boot_progress (-150); |
| 1040 | puts ("** Bad FIT image format\n"); |
| 1041 | return 1; |
| 1042 | } |
| 1043 | show_boot_progress (151); |
| 1044 | fit_print_contents (fit_hdr); |
| 1045 | } |
Marian Balakowicz | 09475f7 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 1046 | #endif |
| 1047 | |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1048 | /* Loading ok, update default load address */ |
| 1049 | |
| 1050 | load_addr = addr; |
| 1051 | |
| 1052 | /* Check if we should attempt an auto-start */ |
| 1053 | if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) { |
| 1054 | char *local_args[2]; |
| 1055 | extern int do_bootm (cmd_tbl_t *, int, int, char *[]); |
| 1056 | |
| 1057 | local_args[0] = argv[0]; |
| 1058 | local_args[1] = NULL; |
| 1059 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 1060 | printf ("Automatic boot of image at addr 0x%08lx ...\n", addr); |
wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 1061 | |
| 1062 | do_bootm (cmdtp, 0, 1, local_args); |
| 1063 | rcode = 1; |
| 1064 | } |
| 1065 | return rcode; |
| 1066 | } |
| 1067 | |
wdenk | 0d49839 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 1068 | U_BOOT_CMD( |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 1069 | nboot, 4, 1, do_nandboot, |
wdenk | b0fce99 | 2003-06-29 21:03:46 +0000 | [diff] [blame] | 1070 | "nboot - boot from NAND device\n", |
| 1071 | "loadAddr dev\n" |
| 1072 | ); |
| 1073 | |
Jon Loeliger | c76fe47 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 1074 | #endif |
Bartlomiej Sieka | addb2e1 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 1075 | |
| 1076 | #endif /* CFG_NAND_LEGACY */ |