1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-11-22 12:21:34 +02:00

[usbboot] fix if there is space at the end of command casue error

This commit is contained in:
Xiangfu Liu 2010-06-15 22:37:36 +08:00
parent 3272119164
commit c1873f1c5e
3 changed files with 26 additions and 43 deletions

View File

@ -568,7 +568,7 @@ int nand_prog(void)
" \t-e:\twith oob and ecc\n"; " \t-e:\twith oob and ecc\n";
if (com_argc != 6) { if (com_argc != 6) {
printf(" not enough argument.\n"); printf(" arguments count error.\n");
printf("%s", help); printf("%s", help);
return 0; return 0;
} }
@ -578,6 +578,7 @@ int nand_prog(void)
nand_in.start = atoi(com_argv[1]); nand_in.start = atoi(com_argv[1]);
image_file = com_argv[2]; image_file = com_argv[2];
nand_in.dev = atoi(com_argv[3]); nand_in.dev = atoi(com_argv[3]);
(nand_in.cs_map)[atoi(com_argv[4])] = 1; (nand_in.cs_map)[atoi(com_argv[4])] = 1;
if (!strcmp(com_argv[5], "-e")) if (!strcmp(com_argv[5], "-e"))
nand_in.option = OOB_ECC; nand_in.option = OOB_ECC;

View File

@ -223,39 +223,22 @@ int handle_load(void)
int command_interpret(char * com_buf) int command_interpret(char * com_buf)
{ {
char *buf = com_buf; if(com_buf[0] == '\n')
int k, L, i = 0, j = 0;
L = (int)strlen(buf);
buf[L]=' ';
if (buf[0] == '\n')
return 0; return 0;
for (k = 0; k <= L; k++) { com_argc = 0;
if (*buf == ' ' || *buf == '\n') { char *p = strtok(com_buf, "\n ");
while ( *(++buf) == ' ' ); strcpy(com_argv[com_argc++], p);
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 = i; while(p = strtok(NULL, "\n "))
strcpy(com_argv[com_argc++], p);
for (i = 1; i <= COMMAND_NUM; i++) int loop = 0;
if (!strcmp(COMMAND[i], com_argv[0])) for (loop = 1; loop <= COMMAND_NUM; loop++)
return i; if (!strcmp(COMMAND[loop], com_argv[0]))
return COMMAND_NUM + 1; return loop;
return -1;
} }
int command_handle(char *buf) int command_handle(char *buf)
@ -317,6 +300,7 @@ int command_handle(char *buf)
case 29: case 29:
handle_memtest(); handle_memtest();
break; break;
case -1:
default: default:
printf(" command not support or input error!\n"); printf(" command not support or input error!\n");
break; break;

View File

@ -1,6 +1,6 @@
/* /*
* Copyright(C) 2009 Qi Hardware Inc., * Copyright(C) 2009 Qi Hardware Inc.,
* Authors: Xiangfu Liu <xiangfu@qi-hardware.com> * Authors: Xiangfu Liu <xiangfu@sharism.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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" " -h --help\t\t\tPrint this help message\n"
" -v --version\t\t\tPrint the version number\n" " -v --version\t\t\tPrint the version number\n"
" -c --command\t\t\tDirect run the commands, split by ';'\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"
" <run without options to enter commands via usbboot prompt>\n\n" " <run without options to enter commands via usbboot prompt>\n\n"
"Report bugs to <xiangfu@qi-hardware.com>.\n" "Report bugs to <xiangfu@sharism.cc>.\n"
); );
} }
@ -107,17 +108,14 @@ int main(int argc, char **argv)
return EXIT_FAILURE; return EXIT_FAILURE;
if (command) { /* direct run command */ if (command) { /* direct run command */
char *delim=";"; char *p[10];
char *p; int i, loop = 0;
p = strtok(cmdpt, delim); p[loop++] = strtok(cmdpt, ";");
strcpy(com_buf, p); while(p[loop++] = strtok(NULL, ";"));
printf(" Execute command: %s \n",com_buf);
command_handle(com_buf);
while((p = strtok(NULL,delim))) { for(i = 0; i < loop - 1 && i < 10; i++) {
strcpy(com_buf, p); printf(" Execute command: %s \n",p[i]);
printf(" Execute command: %s \n",com_buf); command_handle(p[i]);
command_handle(com_buf);
} }
goto out; goto out;
} }