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