diff --git a/usbboot/src/cmd.c b/usbboot/src/cmd.c index f931196..410d831 100644 --- a/usbboot/src/cmd.c +++ b/usbboot/src/cmd.c @@ -568,7 +568,7 @@ int nand_prog(void) " \t-e:\twith oob and ecc\n"; if (com_argc != 6) { - printf(" not enough argument.\n"); + printf(" arguments count error.\n"); printf("%s", help); return 0; } @@ -578,6 +578,7 @@ int nand_prog(void) nand_in.start = atoi(com_argv[1]); image_file = com_argv[2]; nand_in.dev = atoi(com_argv[3]); + (nand_in.cs_map)[atoi(com_argv[4])] = 1; if (!strcmp(com_argv[5], "-e")) nand_in.option = OOB_ECC; diff --git a/usbboot/src/command_line.c b/usbboot/src/command_line.c index b2cbb36..7d0d997 100644 --- a/usbboot/src/command_line.c +++ b/usbboot/src/command_line.c @@ -223,39 +223,22 @@ int handle_load(void) int command_interpret(char * com_buf) { - char *buf = com_buf; - int k, L, i = 0, j = 0; - - L = (int)strlen(buf); - buf[L]=' '; - - if (buf[0] == '\n') + if(com_buf[0] == '\n') return 0; - for (k = 0; k <= L; k++) { - if (*buf == ' ' || *buf == '\n') { - while ( *(++buf) == ' ' ); - com_argv[i][j] = '\0'; - i++; - if (i > MAX_ARGC) - return COMMAND_NUM + 1; - j = 0; - continue; - } else { - com_argv[i][j] = *buf; - j++; - if (j > MAX_COMMAND_LENGTH) - return COMMAND_NUM + 1; - } - buf++; - } + com_argc = 0; + char *p = strtok(com_buf, "\n "); + strcpy(com_argv[com_argc++], p); - com_argc = i; + while(p = strtok(NULL, "\n ")) + strcpy(com_argv[com_argc++], p); - for (i = 1; i <= COMMAND_NUM; i++) - if (!strcmp(COMMAND[i], com_argv[0])) - return i; - return COMMAND_NUM + 1; + int loop = 0; + for (loop = 1; loop <= COMMAND_NUM; loop++) + if (!strcmp(COMMAND[loop], com_argv[0])) + return loop; + + return -1; } int command_handle(char *buf) @@ -317,6 +300,7 @@ int command_handle(char *buf) case 29: handle_memtest(); break; + case -1: default: printf(" command not support or input error!\n"); break; diff --git a/usbboot/src/main.c b/usbboot/src/main.c index 7d8807b..a2d7ead 100644 --- a/usbboot/src/main.c +++ b/usbboot/src/main.c @@ -1,6 +1,6 @@ /* * Copyright(C) 2009 Qi Hardware Inc., - * Authors: Xiangfu Liu + * Authors: Xiangfu Liu * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,9 +37,10 @@ static void help(void) " -h --help\t\t\tPrint this help message\n" " -v --version\t\t\tPrint the version number\n" " -c --command\t\t\tDirect run the commands, split by ';'\n" - " -f --configure\t\t\tconfigure file path\n" + " \t\t\tNOTICE: the max commands count is 10!\n" + " -f --configure\t\tconfigure file path\n" " \n\n" - "Report bugs to .\n" + "Report bugs to .\n" ); } @@ -107,17 +108,14 @@ int main(int argc, char **argv) return EXIT_FAILURE; if (command) { /* direct run command */ - char *delim=";"; - char *p; - p = strtok(cmdpt, delim); - strcpy(com_buf, p); - printf(" Execute command: %s \n",com_buf); - command_handle(com_buf); + char *p[10]; + int i, loop = 0; + p[loop++] = strtok(cmdpt, ";"); + while(p[loop++] = strtok(NULL, ";")); - while((p = strtok(NULL,delim))) { - strcpy(com_buf, p); - printf(" Execute command: %s \n",com_buf); - command_handle(com_buf); + for(i = 0; i < loop - 1 && i < 10; i++) { + printf(" Execute command: %s \n",p[i]); + command_handle(p[i]); } goto out; }