- int first = strtoul(args[1], NULL, 0);
- int last = strtoul(args[2], NULL, 0);
-
- if ((retval = nand_erase(p, first, last)) == ERROR_OK)
+ unsigned long offset;
+ unsigned long length;
+
+ /* erase specified part of the chip; or else everything */
+ if (argc == 3) {
+ unsigned long size = p->erase_size * p->num_blocks;
+
+ COMMAND_PARSE_NUMBER(ulong, args[1], offset);
+ if ((offset % p->erase_size) != 0 || offset >= size)
+ return ERROR_INVALID_ARGUMENTS;
+
+ COMMAND_PARSE_NUMBER(ulong, args[2], length);
+ if ((length == 0) || (length % p->erase_size) != 0
+ || (length + offset) > size)
+ return ERROR_INVALID_ARGUMENTS;
+
+ offset /= p->erase_size;
+ length /= p->erase_size;
+ } else {
+ offset = 0;
+ length = p->num_blocks;
+ }
+
+ retval = nand_erase(p, offset, offset + length - 1);
+ if (retval == ERROR_OK)