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 #ifdef CONFIG_CMD_ONENAND
17 #include <linux/mtd/compat.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/onenand.h>
23 extern struct mtd_info onenand_mtd;
24 extern struct onenand_chip onenand_chip;
26 int do_onenand(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
33 printf("Usage:\n%s\n", cmdtp->usage);
37 if (strncmp(argv[1], "open", 4) == 0) {
41 printf("%s\n", onenand_mtd.name);
46 if (strncmp(argv[1], "erase", 5) == 0) {
47 struct erase_info instr = {
54 if (strncmp(argv[2], "block", 5) == 0) {
55 start = simple_strtoul(argv[3], NULL, 10);
56 endtail = strchr(argv[3], '-');
57 end = simple_strtoul(endtail + 1, NULL, 10);
59 start = simple_strtoul(argv[2], NULL, 10);
60 end = simple_strtoul(argv[3], NULL, 10);
62 start >>= onenand_chip.erase_shift;
63 end >>= onenand_chip.erase_shift;
64 /* Don't include the end block */
71 printf("Erase block from %lu to %lu\n", start, end);
73 for (block = start; block <= end; block++) {
74 instr.addr = block << onenand_chip.erase_shift;
75 instr.len = 1 << onenand_chip.erase_shift;
76 ret = onenand_erase(&onenand_mtd, &instr);
78 printf("erase failed %lu\n", block);
86 if (strncmp(argv[1], "read", 4) == 0) {
87 ulong addr = simple_strtoul(argv[2], NULL, 16);
88 ulong ofs = simple_strtoul(argv[3], NULL, 16);
89 size_t len = simple_strtoul(argv[4], NULL, 16);
91 int oob = strncmp(argv[1], "read.oob", 8) ? 0 : 1;
94 onenand_read_oob(&onenand_mtd, ofs, len,
95 &retlen, (u_char *) addr);
97 onenand_read(&onenand_mtd, ofs, len, &retlen,
104 if (strncmp(argv[1], "write", 5) == 0) {
105 ulong addr = simple_strtoul(argv[2], NULL, 16);
106 ulong ofs = simple_strtoul(argv[3], NULL, 16);
107 size_t len = simple_strtoul(argv[4], NULL, 16);
110 onenand_write(&onenand_mtd, ofs, len, &retlen,
117 if (strncmp(argv[1], "block", 5) == 0) {
118 ulong addr = simple_strtoul(argv[2], NULL, 16);
119 ulong block = simple_strtoul(argv[3], NULL, 10);
120 ulong page = simple_strtoul(argv[4], NULL, 10);
121 size_t len = simple_strtol(argv[5], NULL, 10);
124 int oob = strncmp(argv[1], "block.oob", 9) ? 0 : 1;
126 ofs = block << onenand_chip.erase_shift;
128 ofs += page << onenand_chip.page_shift;
138 onenand_read_oob(&onenand_mtd, ofs, len,
139 &retlen, (u_char *) addr);
141 onenand_read(&onenand_mtd, ofs, len, &retlen,
153 onenand, 6, 1, do_onenand,
154 "onenand - OneNAND sub-system\n",
155 "info - show available OneNAND devices\n"
156 "onenand read[.oob] addr ofs len - read data at ofs with len to addr\n"
157 "onenand write addr ofs len - write data at ofs with len from addr\n"
158 "onenand erase saddr eaddr - erase block start addr to end addr\n"
159 "onenand block[.oob] addr block [page] [len] - "
160 "read data with (block [, page]) to addr"
163 #endif /* CONFIG_CMD_ONENAND */