wdenk | c8434db | 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 | 6d3c6d1 | 2005-04-03 22:35:21 +0000 | [diff] [blame] | 6 | * |
| 7 | * Added 16-bit nand support |
| 8 | * (C) 2004 Texas Instruments |
wdenk | c8434db | 2003-03-26 06:55:25 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 12 | |
| 13 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 14 | /* |
| 15 | * |
| 16 | * New NAND support |
| 17 | * |
| 18 | */ |
| 19 | #include <common.h> |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 20 | #include <linux/mtd/mtd.h> |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 21 | |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 22 | #if defined(CONFIG_CMD_NAND) |
Bartlomiej Sieka | 582f1a3 | 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 | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 28 | #include <jffs2/jffs2.h> |
| 29 | #include <nand.h> |
| 30 | |
Ladislav Michl | 9d0928d | 2009-04-21 02:26:31 +0200 | [diff] [blame] | 31 | #if defined(CONFIG_CMD_MTDPARTS) |
Stefan Roese | 198b23e | 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, |
Wolfgang Denk | 74e0dde | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 37 | u8 *part_num, struct part_info **part); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 38 | #endif |
| 39 | |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 40 | static int nand_dump(nand_info_t *nand, ulong off, int only_oob) |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 41 | { |
| 42 | int i; |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 43 | u_char *datbuf, *oobbuf, *p; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 44 | |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 45 | datbuf = malloc(nand->writesize + nand->oobsize); |
| 46 | oobbuf = malloc(nand->oobsize); |
| 47 | if (!datbuf || !oobbuf) { |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 48 | puts("No memory for page buffer\n"); |
| 49 | return 1; |
| 50 | } |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 51 | off &= ~(nand->writesize - 1); |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 52 | loff_t addr = (loff_t) off; |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 53 | struct mtd_oob_ops ops; |
| 54 | memset(&ops, 0, sizeof(ops)); |
| 55 | ops.datbuf = datbuf; |
| 56 | ops.oobbuf = oobbuf; /* must exist, but oob data will be appended to ops.datbuf */ |
| 57 | ops.len = nand->writesize; |
| 58 | ops.ooblen = nand->oobsize; |
| 59 | ops.mode = MTD_OOB_RAW; |
| 60 | i = nand->read_oob(nand, addr, &ops); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 61 | if (i < 0) { |
Stefan Roese | 3167d07 | 2008-07-10 10:10:54 +0200 | [diff] [blame] | 62 | printf("Error (%d) reading page %08lx\n", i, off); |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 63 | free(datbuf); |
| 64 | free(oobbuf); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 65 | return 1; |
| 66 | } |
Stefan Roese | 3167d07 | 2008-07-10 10:10:54 +0200 | [diff] [blame] | 67 | printf("Page %08lx dump:\n", off); |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 68 | i = nand->writesize >> 4; |
| 69 | p = datbuf; |
Wolfgang Denk | 74e0dde | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 70 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 71 | while (i--) { |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 72 | if (!only_oob) |
| 73 | printf("\t%02x %02x %02x %02x %02x %02x %02x %02x" |
| 74 | " %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], |
Scott Wood | cc5f339 | 2008-06-12 13:20:16 -0500 | [diff] [blame] | 76 | p[8], p[9], p[10], p[11], p[12], p[13], p[14], |
| 77 | p[15]); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 78 | p += 16; |
| 79 | } |
| 80 | puts("OOB:\n"); |
| 81 | i = nand->oobsize >> 3; |
| 82 | while (i--) { |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 83 | printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 84 | p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 85 | p += 8; |
| 86 | } |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 87 | free(datbuf); |
| 88 | free(oobbuf); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | /* ------------------------------------------------------------------------- */ |
| 94 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 95 | static inline int str2long(char *p, ulong *num) |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 96 | { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 97 | char *endptr; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 98 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 99 | *num = simple_strtoul(p, &endptr, 16); |
| 100 | return (*p != '\0' && *endptr == '\0') ? 1 : 0; |
| 101 | } |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 102 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 103 | static int |
Wolfgang Denk | 9a11ccd | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 104 | arg_off_size(int argc, char *argv[], nand_info_t *nand, ulong *off, size_t *size) |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 105 | { |
| 106 | int idx = nand_curr_device; |
Ladislav Michl | 9d0928d | 2009-04-21 02:26:31 +0200 | [diff] [blame] | 107 | #if defined(CONFIG_CMD_MTDPARTS) |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 108 | struct mtd_device *dev; |
| 109 | struct part_info *part; |
| 110 | u8 pnum; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 111 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 112 | if (argc >= 1 && !(str2long(argv[0], off))) { |
| 113 | if ((mtdparts_init() == 0) && |
| 114 | (find_dev_and_part(argv[0], &dev, &pnum, &part) == 0)) { |
| 115 | if (dev->id->type != MTD_DEV_TYPE_NAND) { |
| 116 | puts("not a NAND device\n"); |
| 117 | return -1; |
| 118 | } |
| 119 | *off = part->offset; |
| 120 | if (argc >= 2) { |
Wolfgang Denk | 7f79454 | 2008-04-30 17:46:26 +0200 | [diff] [blame] | 121 | if (!(str2long(argv[1], (ulong *)size))) { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 122 | printf("'%s' is not a number\n", argv[1]); |
| 123 | return -1; |
| 124 | } |
| 125 | if (*size > part->size) |
| 126 | *size = part->size; |
| 127 | } else { |
| 128 | *size = part->size; |
| 129 | } |
| 130 | idx = dev->id->num; |
| 131 | *nand = nand_info[idx]; |
| 132 | goto out; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 133 | } |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 134 | } |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 135 | #endif |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 136 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 137 | if (argc >= 1) { |
| 138 | if (!(str2long(argv[0], off))) { |
| 139 | printf("'%s' is not a number\n", argv[0]); |
| 140 | return -1; |
| 141 | } |
| 142 | } else { |
| 143 | *off = 0; |
| 144 | } |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 145 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 146 | if (argc >= 2) { |
Wolfgang Denk | 9a11ccd | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 147 | if (!(str2long(argv[1], (ulong *)size))) { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 148 | printf("'%s' is not a number\n", argv[1]); |
| 149 | return -1; |
| 150 | } |
| 151 | } else { |
| 152 | *size = nand->size - *off; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 153 | } |
| 154 | |
Ladislav Michl | 9d0928d | 2009-04-21 02:26:31 +0200 | [diff] [blame] | 155 | #if defined(CONFIG_CMD_MTDPARTS) |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 156 | out: |
| 157 | #endif |
| 158 | printf("device %d ", idx); |
| 159 | if (*size == nand->size) |
| 160 | puts("whole chip\n"); |
| 161 | else |
Mike Frysinger | d38f4a6 | 2009-01-18 19:46:06 -0500 | [diff] [blame] | 162 | printf("offset 0x%lx, size 0x%zx\n", *off, *size); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 163 | return 0; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Nishanth Menon | b20f840 | 2008-12-13 09:43:06 -0600 | [diff] [blame] | 166 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
| 167 | static void print_status(ulong start, ulong end, ulong erasesize, int status) |
| 168 | { |
| 169 | printf("%08lx - %08lx: %08lx blocks %s%s%s\n", |
| 170 | start, |
| 171 | end - 1, |
| 172 | (end - start) / erasesize, |
| 173 | ((status & NAND_LOCK_STATUS_TIGHT) ? "TIGHT " : ""), |
| 174 | ((status & NAND_LOCK_STATUS_LOCK) ? "LOCK " : ""), |
| 175 | ((status & NAND_LOCK_STATUS_UNLOCK) ? "UNLOCK " : "")); |
| 176 | } |
| 177 | |
| 178 | static void do_nand_status(nand_info_t *nand) |
| 179 | { |
| 180 | ulong block_start = 0; |
| 181 | ulong off; |
| 182 | int last_status = -1; |
| 183 | |
| 184 | struct nand_chip *nand_chip = nand->priv; |
| 185 | /* check the WP bit */ |
| 186 | nand_chip->cmdfunc(nand, NAND_CMD_STATUS, -1, -1); |
| 187 | printf("device is %swrite protected\n", |
| 188 | (nand_chip->read_byte(nand) & 0x80 ? |
| 189 | "NOT " : "")); |
| 190 | |
| 191 | for (off = 0; off < nand->size; off += nand->erasesize) { |
| 192 | int s = nand_get_lock_status(nand, off); |
| 193 | |
| 194 | /* print message only if status has changed */ |
| 195 | if (s != last_status && off != 0) { |
| 196 | print_status(block_start, off, nand->erasesize, |
| 197 | last_status); |
| 198 | block_start = off; |
| 199 | } |
| 200 | last_status = s; |
| 201 | } |
| 202 | /* Print the last block info */ |
| 203 | print_status(block_start, off, nand->erasesize, last_status); |
| 204 | } |
| 205 | #endif |
| 206 | |
Wolfgang Grandegger | b325d7e | 2009-02-11 18:38:20 +0100 | [diff] [blame] | 207 | static void nand_print_info(int idx) |
| 208 | { |
| 209 | nand_info_t *nand = &nand_info[idx]; |
| 210 | struct nand_chip *chip = nand->priv; |
| 211 | printf("Device %d: ", idx); |
| 212 | if (chip->numchips > 1) |
| 213 | printf("%dx ", chip->numchips); |
| 214 | printf("%s, sector size %u KiB\n", |
| 215 | nand->name, nand->erasesize >> 10); |
| 216 | } |
| 217 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 218 | int do_nand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 219 | { |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 220 | int i, dev, ret = 0; |
Wolfgang Denk | 9a11ccd | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 221 | ulong addr, off; |
| 222 | size_t size; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 223 | char *cmd, *s; |
| 224 | nand_info_t *nand; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 225 | #ifdef CONFIG_SYS_NAND_QUIET |
| 226 | int quiet = CONFIG_SYS_NAND_QUIET; |
Matthias Fuchs | d42fff2 | 2007-09-12 12:36:53 +0200 | [diff] [blame] | 227 | #else |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 228 | int quiet = 0; |
Matthias Fuchs | d42fff2 | 2007-09-12 12:36:53 +0200 | [diff] [blame] | 229 | #endif |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 230 | const char *quiet_str = getenv("quiet"); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 231 | |
| 232 | /* at least two arguments please */ |
| 233 | if (argc < 2) |
| 234 | goto usage; |
| 235 | |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 236 | if (quiet_str) |
| 237 | quiet = simple_strtoul(quiet_str, NULL, 0) != 0; |
| 238 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 239 | cmd = argv[1]; |
| 240 | |
| 241 | if (strcmp(cmd, "info") == 0) { |
| 242 | |
| 243 | putc('\n'); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 244 | for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++) { |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 245 | if (nand_info[i].name) |
Wolfgang Grandegger | b325d7e | 2009-02-11 18:38:20 +0100 | [diff] [blame] | 246 | nand_print_info(i); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 247 | } |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | if (strcmp(cmd, "device") == 0) { |
| 252 | |
| 253 | if (argc < 3) { |
Wolfgang Grandegger | b325d7e | 2009-02-11 18:38:20 +0100 | [diff] [blame] | 254 | putc('\n'); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 255 | if ((nand_curr_device < 0) || |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 256 | (nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE)) |
Wolfgang Grandegger | b325d7e | 2009-02-11 18:38:20 +0100 | [diff] [blame] | 257 | puts("no devices available\n"); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 258 | else |
Wolfgang Grandegger | b325d7e | 2009-02-11 18:38:20 +0100 | [diff] [blame] | 259 | nand_print_info(nand_curr_device); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 260 | return 0; |
| 261 | } |
| 262 | dev = (int)simple_strtoul(argv[2], NULL, 10); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 263 | if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[dev].name) { |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 264 | puts("No such device\n"); |
| 265 | return 1; |
| 266 | } |
| 267 | printf("Device %d: %s", dev, nand_info[dev].name); |
| 268 | puts("... is now current device\n"); |
| 269 | nand_curr_device = dev; |
Stefan Roese | 3cdd3fd | 2006-10-20 14:28:52 +0200 | [diff] [blame] | 270 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 271 | #ifdef CONFIG_SYS_NAND_SELECT_DEVICE |
Stefan Roese | 3cdd3fd | 2006-10-20 14:28:52 +0200 | [diff] [blame] | 272 | /* |
| 273 | * Select the chip in the board/cpu specific driver |
| 274 | */ |
| 275 | board_nand_select_device(nand_info[dev].priv, dev); |
| 276 | #endif |
| 277 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 278 | return 0; |
| 279 | } |
| 280 | |
| 281 | if (strcmp(cmd, "bad") != 0 && strcmp(cmd, "erase") != 0 && |
William Juul | bfb8332 | 2007-11-14 14:28:11 +0100 | [diff] [blame] | 282 | strncmp(cmd, "dump", 4) != 0 && |
| 283 | strncmp(cmd, "read", 4) != 0 && strncmp(cmd, "write", 5) != 0 && |
| 284 | strcmp(cmd, "scrub") != 0 && strcmp(cmd, "markbad") != 0 && |
| 285 | strcmp(cmd, "biterr") != 0 && |
| 286 | strcmp(cmd, "lock") != 0 && strcmp(cmd, "unlock") != 0 ) |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 287 | goto usage; |
| 288 | |
| 289 | /* the following commands operate on the current device */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 290 | if (nand_curr_device < 0 || nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE || |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 291 | !nand_info[nand_curr_device].name) { |
| 292 | puts("\nno devices available\n"); |
| 293 | return 1; |
| 294 | } |
| 295 | nand = &nand_info[nand_curr_device]; |
| 296 | |
| 297 | if (strcmp(cmd, "bad") == 0) { |
| 298 | printf("\nDevice %d bad blocks:\n", nand_curr_device); |
| 299 | for (off = 0; off < nand->size; off += nand->erasesize) |
| 300 | if (nand_block_isbad(nand, off)) |
Stefan Roese | 3167d07 | 2008-07-10 10:10:54 +0200 | [diff] [blame] | 301 | printf(" %08lx\n", off); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 302 | return 0; |
| 303 | } |
| 304 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 305 | /* |
| 306 | * Syntax is: |
| 307 | * 0 1 2 3 4 |
| 308 | * nand erase [clean] [off size] |
| 309 | */ |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 310 | if (strcmp(cmd, "erase") == 0 || strcmp(cmd, "scrub") == 0) { |
| 311 | nand_erase_options_t opts; |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 312 | /* "clean" at index 2 means request to write cleanmarker */ |
William Juul | bfb8332 | 2007-11-14 14:28:11 +0100 | [diff] [blame] | 313 | int clean = argc > 2 && !strcmp("clean", argv[2]); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 314 | int o = clean ? 3 : 2; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 315 | int scrub = !strcmp(cmd, "scrub"); |
| 316 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 317 | printf("\nNAND %s: ", scrub ? "scrub" : "erase"); |
| 318 | /* skip first two or three arguments, look for offset and size */ |
| 319 | if (arg_off_size(argc - o, argv + o, nand, &off, &size) != 0) |
| 320 | return 1; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 321 | |
| 322 | memset(&opts, 0, sizeof(opts)); |
| 323 | opts.offset = off; |
| 324 | opts.length = size; |
| 325 | opts.jffs2 = clean; |
| 326 | opts.quiet = quiet; |
| 327 | |
| 328 | if (scrub) { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 329 | puts("Warning: " |
| 330 | "scrub option will erase all factory set " |
| 331 | "bad blocks!\n" |
| 332 | " " |
| 333 | "There is no reliable way to recover them.\n" |
| 334 | " " |
| 335 | "Use this command only for testing purposes " |
| 336 | "if you\n" |
| 337 | " " |
| 338 | "are sure of what you are doing!\n" |
| 339 | "\nReally scrub this NAND flash? <y/N>\n"); |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 340 | |
| 341 | if (getc() == 'y' && getc() == '\r') { |
| 342 | opts.scrub = 1; |
| 343 | } else { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 344 | puts("scrub aborted\n"); |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 345 | return -1; |
| 346 | } |
| 347 | } |
| 348 | ret = nand_erase_opts(nand, &opts); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 349 | printf("%s\n", ret ? "ERROR" : "OK"); |
| 350 | |
| 351 | return ret == 0 ? 0 : 1; |
| 352 | } |
| 353 | |
| 354 | if (strncmp(cmd, "dump", 4) == 0) { |
| 355 | if (argc < 3) |
| 356 | goto usage; |
| 357 | |
| 358 | s = strchr(cmd, '.'); |
| 359 | off = (int)simple_strtoul(argv[2], NULL, 16); |
| 360 | |
| 361 | if (s != NULL && strcmp(s, ".oob") == 0) |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 362 | ret = nand_dump(nand, off, 1); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 363 | else |
William Juul | e7ebe6e | 2007-12-14 16:33:45 +0100 | [diff] [blame] | 364 | ret = nand_dump(nand, off, 0); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 365 | |
| 366 | return ret == 0 ? 1 : 0; |
| 367 | |
| 368 | } |
| 369 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 370 | if (strncmp(cmd, "read", 4) == 0 || strncmp(cmd, "write", 5) == 0) { |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 371 | int read; |
| 372 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 373 | if (argc < 4) |
| 374 | goto usage; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 375 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 376 | addr = (ulong)simple_strtoul(argv[2], NULL, 16); |
| 377 | |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 378 | read = strncmp(cmd, "read", 4) == 0; /* 1 = read, 0 = write */ |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 379 | printf("\nNAND %s: ", read ? "read" : "write"); |
| 380 | if (arg_off_size(argc - 3, argv + 3, nand, &off, &size) != 0) |
| 381 | return 1; |
William Juul | b76ec38 | 2007-11-08 10:39:53 +0100 | [diff] [blame] | 382 | |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 383 | s = strchr(cmd, '.'); |
Scott Wood | 12b1c95 | 2008-06-12 13:13:23 -0500 | [diff] [blame] | 384 | if (!s || !strcmp(s, ".jffs2") || |
| 385 | !strcmp(s, ".e") || !strcmp(s, ".i")) { |
Scott Wood | cc5f339 | 2008-06-12 13:20:16 -0500 | [diff] [blame] | 386 | if (read) |
| 387 | ret = nand_read_skip_bad(nand, off, &size, |
Wolfgang Denk | 74e0dde | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 388 | (u_char *)addr); |
Scott Wood | cc5f339 | 2008-06-12 13:20:16 -0500 | [diff] [blame] | 389 | else |
| 390 | ret = nand_write_skip_bad(nand, off, &size, |
Wolfgang Denk | 74e0dde | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 391 | (u_char *)addr); |
Mike Frysinger | 9a2cbb9 | 2009-04-12 22:29:20 -0400 | [diff] [blame] | 392 | } else if (!strcmp(s, ".oob")) { |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 393 | /* out-of-band data */ |
| 394 | mtd_oob_ops_t ops = { |
| 395 | .oobbuf = (u8 *)addr, |
| 396 | .ooblen = size, |
| 397 | .mode = MTD_OOB_RAW |
| 398 | }; |
| 399 | |
Harald Welte | 5a39510 | 2007-12-19 14:12:53 +0100 | [diff] [blame] | 400 | if (read) |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 401 | ret = nand->read_oob(nand, off, &ops); |
Harald Welte | 5a39510 | 2007-12-19 14:12:53 +0100 | [diff] [blame] | 402 | else |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 403 | ret = nand->write_oob(nand, off, &ops); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 404 | } else { |
Scott Wood | 12b1c95 | 2008-06-12 13:13:23 -0500 | [diff] [blame] | 405 | printf("Unknown nand command suffix '%s'.\n", s); |
| 406 | return 1; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 407 | } |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 408 | |
Mike Frysinger | d38f4a6 | 2009-01-18 19:46:06 -0500 | [diff] [blame] | 409 | printf(" %zu bytes %s: %s\n", size, |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 410 | read ? "read" : "written", ret ? "ERROR" : "OK"); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 411 | |
| 412 | return ret == 0 ? 0 : 1; |
| 413 | } |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 414 | |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 415 | if (strcmp(cmd, "markbad") == 0) { |
Wolfgang Denk | 7a15ca1 | 2009-05-24 17:34:33 +0200 | [diff] [blame] | 416 | argc -= 2; |
| 417 | argv += 2; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 418 | |
Wolfgang Denk | 7a15ca1 | 2009-05-24 17:34:33 +0200 | [diff] [blame] | 419 | if (argc <= 0) |
| 420 | goto usage; |
| 421 | |
| 422 | while (argc > 0) { |
| 423 | addr = simple_strtoul(*argv, NULL, 16); |
| 424 | |
| 425 | if (nand->block_markbad(nand, addr)) { |
| 426 | printf("block 0x%08lx NOT marked " |
| 427 | "as bad! ERROR %d\n", |
| 428 | addr, ret); |
| 429 | ret = 1; |
| 430 | } else { |
| 431 | printf("block 0x%08lx successfully " |
| 432 | "marked as bad\n", |
| 433 | addr); |
| 434 | } |
| 435 | --argc; |
| 436 | ++argv; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 437 | } |
Wolfgang Denk | 7a15ca1 | 2009-05-24 17:34:33 +0200 | [diff] [blame] | 438 | return ret; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 439 | } |
Scott Wood | cc5f339 | 2008-06-12 13:20:16 -0500 | [diff] [blame] | 440 | |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 441 | if (strcmp(cmd, "biterr") == 0) { |
| 442 | /* todo */ |
| 443 | return 1; |
| 444 | } |
| 445 | |
Nishanth Menon | b20f840 | 2008-12-13 09:43:06 -0600 | [diff] [blame] | 446 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 447 | if (strcmp(cmd, "lock") == 0) { |
Nishanth Menon | b20f840 | 2008-12-13 09:43:06 -0600 | [diff] [blame] | 448 | int tight = 0; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 449 | int status = 0; |
| 450 | if (argc == 3) { |
| 451 | if (!strcmp("tight", argv[2])) |
| 452 | tight = 1; |
| 453 | if (!strcmp("status", argv[2])) |
| 454 | status = 1; |
| 455 | } |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 456 | if (status) { |
Nishanth Menon | b20f840 | 2008-12-13 09:43:06 -0600 | [diff] [blame] | 457 | do_nand_status(nand); |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 458 | } else { |
William Juul | 9e9c2c1 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 459 | if (!nand_lock(nand, tight)) { |
| 460 | puts("NAND flash successfully locked\n"); |
| 461 | } else { |
| 462 | puts("Error locking NAND flash\n"); |
| 463 | return 1; |
| 464 | } |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 465 | } |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | if (strcmp(cmd, "unlock") == 0) { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 470 | if (arg_off_size(argc - 2, argv + 2, nand, &off, &size) < 0) |
| 471 | return 1; |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 472 | |
William Juul | 9e9c2c1 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 473 | if (!nand_unlock(nand, off, size)) { |
| 474 | puts("NAND flash successfully unlocked\n"); |
| 475 | } else { |
| 476 | puts("Error unlocking NAND flash, " |
William Juul | bfb8332 | 2007-11-14 14:28:11 +0100 | [diff] [blame] | 477 | "write and erase will probably fail\n"); |
William Juul | 9e9c2c1 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 478 | return 1; |
| 479 | } |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 480 | return 0; |
| 481 | } |
Nishanth Menon | b20f840 | 2008-12-13 09:43:06 -0600 | [diff] [blame] | 482 | #endif |
Stefan Roese | d351b2b | 2006-10-10 12:36:02 +0200 | [diff] [blame] | 483 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 484 | usage: |
Peter Tyser | ddb3af9 | 2009-01-27 18:03:10 -0600 | [diff] [blame] | 485 | cmd_usage(cmdtp); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 486 | return 1; |
| 487 | } |
| 488 | |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 489 | U_BOOT_CMD(nand, CONFIG_SYS_MAXARGS, 1, do_nand, |
| 490 | "NAND sub-system", |
| 491 | "info - show available NAND devices\n" |
| 492 | "nand device [dev] - show or set current device\n" |
| 493 | "nand read - addr off|partition size\n" |
| 494 | "nand write - addr off|partition size\n" |
| 495 | " read/write 'size' bytes starting at offset 'off'\n" |
| 496 | " to/from memory address 'addr', skipping bad blocks.\n" |
| 497 | "nand erase [clean] [off size] - erase 'size' bytes from\n" |
| 498 | " offset 'off' (entire device if not specified)\n" |
| 499 | "nand bad - show bad blocks\n" |
| 500 | "nand dump[.oob] off - dump page\n" |
| 501 | "nand scrub - really clean NAND erasing bad blocks (UNSAFE)\n" |
| 502 | "nand markbad off [...] - mark bad block(s) at offset (UNSAFE)\n" |
| 503 | "nand biterr off - make a bit error at offset (UNSAFE)" |
Nishanth Menon | b20f840 | 2008-12-13 09:43:06 -0600 | [diff] [blame] | 504 | #ifdef CONFIG_CMD_NAND_LOCK_UNLOCK |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 505 | "\n" |
| 506 | "nand lock [tight] [status]\n" |
| 507 | " bring nand to lock state or display locked pages\n" |
| 508 | "nand unlock [offset] [size] - unlock section" |
Nishanth Menon | b20f840 | 2008-12-13 09:43:06 -0600 | [diff] [blame] | 509 | #endif |
| 510 | ); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 511 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 512 | static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand, |
Wolfgang Denk | 74e0dde | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 513 | ulong offset, ulong addr, char *cmd) |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 514 | { |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 515 | int r; |
Thomas Knobloch | e84b777 | 2007-07-06 14:58:39 +0200 | [diff] [blame] | 516 | char *ep, *s; |
Wolfgang Denk | 9a11ccd | 2008-04-28 12:08:18 +0200 | [diff] [blame] | 517 | size_t cnt; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 518 | image_header_t *hdr; |
Marian Balakowicz | e6bdd34 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 519 | #if defined(CONFIG_FIT) |
Marian Balakowicz | cefb402 | 2008-06-06 23:07:40 +0200 | [diff] [blame] | 520 | const void *fit_hdr = NULL; |
Marian Balakowicz | e6bdd34 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 521 | #endif |
Thomas Knobloch | e84b777 | 2007-07-06 14:58:39 +0200 | [diff] [blame] | 522 | |
| 523 | s = strchr(cmd, '.'); |
| 524 | if (s != NULL && |
Scott Wood | d1c1f9c | 2009-03-17 12:06:04 -0500 | [diff] [blame] | 525 | (strcmp(s, ".jffs2") && strcmp(s, ".e") && strcmp(s, ".i"))) { |
Scott Wood | 12b1c95 | 2008-06-12 13:13:23 -0500 | [diff] [blame] | 526 | printf("Unknown nand load suffix '%s'\n", s); |
| 527 | show_boot_progress(-53); |
| 528 | return 1; |
| 529 | } |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 530 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 531 | printf("\nLoading from %s, offset 0x%lx\n", nand->name, offset); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 532 | |
William Juul | 52c0796 | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 533 | cnt = nand->writesize; |
Ladislav Michl | aaee2a3 | 2009-03-13 14:38:19 +0100 | [diff] [blame] | 534 | r = nand_read_skip_bad(nand, offset, &cnt, (u_char *) addr); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 535 | if (r) { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 536 | puts("** Read error\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 537 | show_boot_progress (-56); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 538 | return 1; |
| 539 | } |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 540 | show_boot_progress (56); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 541 | |
Marian Balakowicz | d7c88a4 | 2008-02-29 14:58:34 +0100 | [diff] [blame] | 542 | switch (genimg_get_format ((void *)addr)) { |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 543 | case IMAGE_FORMAT_LEGACY: |
| 544 | hdr = (image_header_t *)addr; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 545 | |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 546 | show_boot_progress (57); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 547 | image_print_contents (hdr); |
| 548 | |
| 549 | cnt = image_get_image_size (hdr); |
| 550 | break; |
| 551 | #if defined(CONFIG_FIT) |
| 552 | case IMAGE_FORMAT_FIT: |
Marian Balakowicz | e6bdd34 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 553 | fit_hdr = (const void *)addr; |
Marian Balakowicz | e6bdd34 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 554 | puts ("Fit image detected...\n"); |
| 555 | |
| 556 | cnt = fit_get_size (fit_hdr); |
| 557 | break; |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 558 | #endif |
| 559 | default: |
Marian Balakowicz | e6bdd34 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 560 | show_boot_progress (-57); |
Marian Balakowicz | dbdd16a | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 561 | puts ("** Unknown image type\n"); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 562 | return 1; |
| 563 | } |
William Juul | bfb8332 | 2007-11-14 14:28:11 +0100 | [diff] [blame] | 564 | show_boot_progress (57); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 565 | |
Ladislav Michl | aaee2a3 | 2009-03-13 14:38:19 +0100 | [diff] [blame] | 566 | r = nand_read_skip_bad(nand, offset, &cnt, (u_char *) addr); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 567 | if (r) { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 568 | puts("** Read error\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 569 | show_boot_progress (-58); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 570 | return 1; |
| 571 | } |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 572 | show_boot_progress (58); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 573 | |
Marian Balakowicz | e6bdd34 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 574 | #if defined(CONFIG_FIT) |
| 575 | /* This cannot be done earlier, we need complete FIT image in RAM first */ |
Marian Balakowicz | cefb402 | 2008-06-06 23:07:40 +0200 | [diff] [blame] | 576 | if (genimg_get_format ((void *)addr) == IMAGE_FORMAT_FIT) { |
| 577 | if (!fit_check_format (fit_hdr)) { |
| 578 | show_boot_progress (-150); |
| 579 | puts ("** Bad FIT image format\n"); |
| 580 | return 1; |
| 581 | } |
| 582 | show_boot_progress (151); |
| 583 | fit_print_contents (fit_hdr); |
| 584 | } |
Marian Balakowicz | e6bdd34 | 2008-03-12 10:33:01 +0100 | [diff] [blame] | 585 | #endif |
| 586 | |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 587 | /* Loading ok, update default load address */ |
| 588 | |
| 589 | load_addr = addr; |
| 590 | |
| 591 | /* Check if we should attempt an auto-start */ |
| 592 | if (((ep = getenv("autostart")) != NULL) && (strcmp(ep, "yes") == 0)) { |
| 593 | char *local_args[2]; |
| 594 | extern int do_bootm(cmd_tbl_t *, int, int, char *[]); |
| 595 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 596 | local_args[0] = cmd; |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 597 | local_args[1] = NULL; |
| 598 | |
| 599 | printf("Automatic boot of image at addr 0x%08lx ...\n", addr); |
| 600 | |
| 601 | do_bootm(cmdtp, 0, 1, local_args); |
| 602 | return 1; |
| 603 | } |
| 604 | return 0; |
| 605 | } |
| 606 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 607 | int do_nandboot(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 608 | { |
| 609 | char *boot_device = NULL; |
| 610 | int idx; |
| 611 | ulong addr, offset = 0; |
Ladislav Michl | 9d0928d | 2009-04-21 02:26:31 +0200 | [diff] [blame] | 612 | #if defined(CONFIG_CMD_MTDPARTS) |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 613 | struct mtd_device *dev; |
| 614 | struct part_info *part; |
| 615 | u8 pnum; |
| 616 | |
| 617 | if (argc >= 2) { |
| 618 | char *p = (argc == 2) ? argv[1] : argv[2]; |
| 619 | if (!(str2long(p, &addr)) && (mtdparts_init() == 0) && |
| 620 | (find_dev_and_part(p, &dev, &pnum, &part) == 0)) { |
| 621 | if (dev->id->type != MTD_DEV_TYPE_NAND) { |
| 622 | puts("Not a NAND device\n"); |
| 623 | return 1; |
| 624 | } |
| 625 | if (argc > 3) |
| 626 | goto usage; |
| 627 | if (argc == 3) |
Thomas Knobloch | e84b777 | 2007-07-06 14:58:39 +0200 | [diff] [blame] | 628 | addr = simple_strtoul(argv[1], NULL, 16); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 629 | else |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 630 | addr = CONFIG_SYS_LOAD_ADDR; |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 631 | return nand_load_image(cmdtp, &nand_info[dev->id->num], |
Wolfgang Denk | 74e0dde | 2008-08-14 14:41:06 +0200 | [diff] [blame] | 632 | part->offset, addr, argv[0]); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 633 | } |
| 634 | } |
| 635 | #endif |
| 636 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 637 | show_boot_progress(52); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 638 | switch (argc) { |
| 639 | case 1: |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 640 | addr = CONFIG_SYS_LOAD_ADDR; |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 641 | boot_device = getenv("bootdevice"); |
| 642 | break; |
| 643 | case 2: |
| 644 | addr = simple_strtoul(argv[1], NULL, 16); |
| 645 | boot_device = getenv("bootdevice"); |
| 646 | break; |
| 647 | case 3: |
| 648 | addr = simple_strtoul(argv[1], NULL, 16); |
| 649 | boot_device = argv[2]; |
| 650 | break; |
| 651 | case 4: |
| 652 | addr = simple_strtoul(argv[1], NULL, 16); |
| 653 | boot_device = argv[2]; |
| 654 | offset = simple_strtoul(argv[3], NULL, 16); |
| 655 | break; |
| 656 | default: |
Ladislav Michl | 9d0928d | 2009-04-21 02:26:31 +0200 | [diff] [blame] | 657 | #if defined(CONFIG_CMD_MTDPARTS) |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 658 | usage: |
| 659 | #endif |
Peter Tyser | ddb3af9 | 2009-01-27 18:03:10 -0600 | [diff] [blame] | 660 | cmd_usage(cmdtp); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 661 | show_boot_progress(-53); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 662 | return 1; |
| 663 | } |
| 664 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 665 | show_boot_progress(53); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 666 | if (!boot_device) { |
| 667 | puts("\n** No boot device **\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 668 | show_boot_progress(-54); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 669 | return 1; |
| 670 | } |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 671 | show_boot_progress(54); |
Bartlomiej Sieka | 582f1a3 | 2006-03-05 18:57:33 +0100 | [diff] [blame] | 672 | |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 673 | idx = simple_strtoul(boot_device, NULL, 16); |
| 674 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 675 | if (idx < 0 || idx >= CONFIG_SYS_MAX_NAND_DEVICE || !nand_info[idx].name) { |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 676 | printf("\n** Device %d not available\n", idx); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 677 | show_boot_progress(-55); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 678 | return 1; |
| 679 | } |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 680 | show_boot_progress(55); |
Stefan Roese | 198b23e | 2006-10-28 15:55:52 +0200 | [diff] [blame] | 681 | |
| 682 | return nand_load_image(cmdtp, &nand_info[idx], offset, addr, argv[0]); |
| 683 | } |
| 684 | |
| 685 | U_BOOT_CMD(nboot, 4, 1, do_nandboot, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 686 | "boot from NAND device", |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 687 | "[partition] | [[[loadAddr] dev] offset]" |
| 688 | ); |
Jon Loeliger | d76b5c1 | 2007-07-08 18:02:23 -0500 | [diff] [blame] | 689 | #endif |