-int main(int argc, char **argv) {
- if(argc == 3 && strcasecmp(argv[1],"unlock")==0) {
- printf("Unlocking %s ...\n",argv[2]);
- return mtd_unlock(argv[2]);
- }
- if(argc == 3 && strcasecmp(argv[1],"erase")==0) {
- printf("Erasing %s ...\n",argv[2]);
- return mtd_erase(argv[2]);
+int main (int argc, char **argv)
+{
+ int ch, i, boot, unlock;
+ char *erase[MAX_ARGS], *device;
+ enum {
+ CMD_ERASE,
+ CMD_WRITE,
+ CMD_UNLOCK
+ } cmd;
+
+ erase[0] = NULL;
+ boot = 0;
+ unlock = 0;
+
+ printf("mtd: Modify data within a Memory Technology Device.\n"
+ "Copyright (C) 2005 Waldemar Brodkorb <wbx@dass-it.de>,\n"
+ " Felix Fietkau <nbd@vd-s.ath.cx>\n"
+ "Documented by Mike Strates [dumpedcore] <mike@dilaudid.net>\n"
+ "mtd has ABSOLUTELY NO WARRANTY and is licensed under the GNU GPL.\n\n");
+
+ while ((ch = getopt(argc, argv, "ure:")) != -1)
+ switch (ch) {
+ case 'u':
+ unlock = 1;
+ break;
+ case 'r':
+ boot = 1;
+ break;
+ case 'e':
+ i = 0;
+ while ((erase[i] != NULL) && ((i + 1) < MAX_ARGS))
+ i++;
+
+ erase[i++] = optarg;
+ erase[i] = NULL;
+ break;
+
+ case '?':
+ default:
+ usage();
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc < 2)
+ usage();
+
+ if ((strcmp(argv[0], "unlock") == 0) && (argc == 2)) {
+ cmd = CMD_UNLOCK;
+ device = argv[1];
+ } else if ((strcmp(argv[0], "erase") == 0) && (argc == 2)) {
+ cmd = CMD_ERASE;
+ device = argv[1];
+ } else if ((strcmp(argv[0], "write") == 0) && (argc == 3)) {
+ cmd = CMD_WRITE;
+ device = argv[2];
+ } else {
+ usage();