2 * U-Boot command for OneNAND support
4 * Copyright (C) 2005-2007 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
15 #include <linux/mtd/compat.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/onenand.h>
21 extern struct mtd_info onenand_mtd;
22 extern struct onenand_chip onenand_chip;
24 int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
31 printf("Usage:\n%s\n", cmdtp->usage);
35 if (strncmp(argv[1], "open", 4) == 0) {
39 printf("%s\n", onenand_mtd.name);
44 if (strncmp(argv[1], "erase", 5) == 0) {
45 struct erase_info instr = {
52 if (strncmp(argv[2], "block", 5) == 0) {
53 start = simple_strtoul(argv[3], NULL, 10);
54 endtail = strchr(argv[3], '-');
55 end = simple_strtoul(endtail + 1, NULL, 10);
57 start = simple_strtoul(argv[2], NULL, 10);
58 end = simple_strtoul(argv[3], NULL, 10);
60 start >>= onenand_chip.erase_shift;
61 end >>= onenand_chip.erase_shift;
62 /* Don't include the end block */
69 printf("Erase block from %lu to %lu\n", start, end);
71 for (block = start; block <= end; block++) {
72 instr.addr = block << onenand_chip.erase_shift;
73 instr.len = 1 << onenand_chip.erase_shift;
74 ret = onenand_erase(&onenand_mtd, &instr);
76 printf("erase failed %lu\n", block);
84 if (strncmp(argv[1], "read", 4) == 0) {
85 ulong addr = simple_strtoul(argv[2], NULL, 16);
86 ulong ofs = simple_strtoul(argv[3], NULL, 16);
87 size_t len = simple_strtoul(argv[4], NULL, 16);
89 int oob = strncmp(argv[1], "read.oob", 8) ? 0 : 1;
92 onenand_read_oob(&onenand_mtd, ofs, len,
93 &retlen, (u_char *) addr);
95 onenand_read(&onenand_mtd, ofs, len, &retlen,
102 if (strncmp(argv[1], "write", 5) == 0) {
103 ulong addr = simple_strtoul(argv[2], NULL, 16);
104 ulong ofs = simple_strtoul(argv[3], NULL, 16);
105 size_t len = simple_strtoul(argv[4], NULL, 16);
108 onenand_write(&onenand_mtd, ofs, len, &retlen,
115 if (strncmp(argv[1], "block", 5) == 0) {
116 ulong addr = simple_strtoul(argv[2], NULL, 16);
117 ulong block = simple_strtoul(argv[3], NULL, 10);
118 ulong page = simple_strtoul(argv[4], NULL, 10);
119 size_t len = simple_strtol(argv[5], NULL, 10);
122 int oob = strncmp(argv[1], "block.oob", 9) ? 0 : 1;
124 ofs = block << onenand_chip.erase_shift;
126 ofs += page << onenand_chip.page_shift;
136 onenand_read_oob(&onenand_mtd, ofs, len,
137 &retlen, (u_char *) addr);
139 onenand_read(&onenand_mtd, ofs, len, &retlen,
151 onenand, 6, 1, do_onenand,
152 "onenand - OneNAND sub-system\n",
153 "info - show available OneNAND devices\n"
154 "onenand read[.oob] addr ofs len - read data at ofs with len to addr\n"
155 "onenand write addr ofs len - write data at ofs with len from addr\n"
156 "onenand erase saddr eaddr - erase block start addr to end addr\n"
157 "onenand block[.oob] addr block [page] [len] - "
158 "read data with (block [, page]) to addr"