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 onenand_print_device_info(onenand_chip.device_id, 1);
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);
61 start -= (unsigned long)onenand_chip.base;
62 end -= (unsigned long)onenand_chip.base;
64 start >>= onenand_chip.erase_shift;
65 end >>= onenand_chip.erase_shift;
66 /* Don't include the end block */
73 printf("Erase block from %d to %d\n", start, end);
75 for (block = start; block <= end; block++) {
76 instr.addr = block << onenand_chip.erase_shift;
77 instr.len = 1 << onenand_chip.erase_shift;
78 ret = onenand_erase(&onenand_mtd, &instr);
80 printf("erase failed %d\n", block);
88 if (strncmp(argv[1], "read", 4) == 0) {
89 ulong addr = simple_strtoul(argv[2], NULL, 16);
90 ulong ofs = simple_strtoul(argv[3], NULL, 16);
91 size_t len = simple_strtoul(argv[4], NULL, 16);
93 int oob = strncmp(argv[1], "read.oob", 8) ? 0 : 1;
95 ofs -= (unsigned long)onenand_chip.base;
98 onenand_read_oob(&onenand_mtd, ofs, len,
99 &retlen, (u_char *) addr);
101 onenand_read(&onenand_mtd, ofs, len, &retlen,
108 if (strncmp(argv[1], "write", 5) == 0) {
109 ulong addr = simple_strtoul(argv[2], NULL, 16);
110 ulong ofs = simple_strtoul(argv[3], NULL, 16);
111 size_t len = simple_strtoul(argv[4], NULL, 16);
114 ofs -= (unsigned long)onenand_chip.base;
116 onenand_write(&onenand_mtd, ofs, len, &retlen,
123 if (strncmp(argv[1], "block", 5) == 0) {
124 ulong addr = simple_strtoul(argv[2], NULL, 16);
125 ulong block = simple_strtoul(argv[3], NULL, 10);
126 ulong page = simple_strtoul(argv[4], NULL, 10);
127 size_t len = simple_strtol(argv[5], NULL, 10);
130 int oob = strncmp(argv[1], "block.oob", 9) ? 0 : 1;
132 ofs = block << onenand_chip.erase_shift;
134 ofs += page << onenand_chip.page_shift;
144 onenand_read_oob(&onenand_mtd, ofs, len,
145 &retlen, (u_char *) addr);
147 onenand_read(&onenand_mtd, ofs, len, &retlen,
159 onenand, 6, 1, do_onenand,
160 "onenand - OneNAND sub-system\n",
161 "info - show available OneNAND devices\n"
162 "onenand read[.oob] addr ofs len - read data at ofs with len to addr\n"
163 "onenand write addr ofs len - write data at ofs with len from addr\n"
164 "onenand erase saddr eaddr - erase block start addr to end addr\n"
165 "onenand block[.oob] addr block [page] [len] - "
166 "read data with (block [, page]) to addr"
169 #endif /* CONFIG_CMD_ONENAND */