Date:2010-06-15 16:37:36 (13 years 9 months ago)
Author:Xiangfu Liu
Commit:c1873f1c5e89d8b1631652fdec135a641f7f7e42
Message:[usbboot] fix if there is space at the end of command casue error

Files: usbboot/src/cmd.c (2 diffs)
usbboot/src/command_line.c (2 diffs)
usbboot/src/main.c (3 diffs)

Change Details

usbboot/src/cmd.c
568568        " \t-e:\twith oob and ecc\n";
569569
570570    if (com_argc != 6) {
571        printf(" not enough argument.\n");
571        printf(" arguments count error.\n");
572572        printf("%s", help);
573573        return 0;
574574    }
...... 
578578    nand_in.start = atoi(com_argv[1]);
579579    image_file = com_argv[2];
580580    nand_in.dev = atoi(com_argv[3]);
581
581582    (nand_in.cs_map)[atoi(com_argv[4])] = 1;
582583    if (!strcmp(com_argv[5], "-e"))
583584        nand_in.option = OOB_ECC;
usbboot/src/command_line.c
223223
224224int command_interpret(char * com_buf)
225225{
226    char *buf = com_buf;
227    int k, L, i = 0, j = 0;
228
229    L = (int)strlen(buf);
230    buf[L]=' ';
231
232    if (buf[0] == '\n')
226    if(com_buf[0] == '\n')
233227        return 0;
234228
235    for (k = 0; k <= L; k++) {
236        if (*buf == ' ' || *buf == '\n') {
237            while ( *(++buf) == ' ' );
238            com_argv[i][j] = '\0';
239            i++;
240            if (i > MAX_ARGC)
241                return COMMAND_NUM + 1;
242            j = 0;
243            continue;
244        } else {
245            com_argv[i][j] = *buf;
246            j++;
247            if (j > MAX_COMMAND_LENGTH)
248                return COMMAND_NUM + 1;
249        }
250        buf++;
251    }
229    com_argc = 0;
230    char *p = strtok(com_buf, "\n ");
231    strcpy(com_argv[com_argc++], p);
232
233    while(p = strtok(NULL, "\n "))
234        strcpy(com_argv[com_argc++], p);
252235
253    com_argc = i;
236    int loop = 0;
237    for (loop = 1; loop <= COMMAND_NUM; loop++)
238        if (!strcmp(COMMAND[loop], com_argv[0]))
239            return loop;
254240
255    for (i = 1; i <= COMMAND_NUM; i++)
256        if (!strcmp(COMMAND[i], com_argv[0]))
257            return i;
258    return COMMAND_NUM + 1;
241    return -1;
259242}
260243
261244int command_handle(char *buf)
...... 
317300    case 29:
318301        handle_memtest();
319302        break;
303    case -1:
320304    default:
321305        printf(" command not support or input error!\n");
322306        break;
usbboot/src/main.c
11/*
22 * Copyright(C) 2009 Qi Hardware Inc.,
3 * Authors: Xiangfu Liu <xiangfu@qi-hardware.com>
3 * Authors: Xiangfu Liu <xiangfu@sharism.com>
44 *
55 * This program is free software: you can redistribute it and/or modify
66 * it under the terms of the GNU General Public License as published by
...... 
3737           " -h --help\t\t\tPrint this help message\n"
3838           " -v --version\t\t\tPrint the version number\n"
3939           " -c --command\t\t\tDirect run the commands, split by ';'\n"
40           " -f --configure\t\t\tconfigure file path\n"
40           " \t\t\tNOTICE: the max commands count is 10!\n"
41           " -f --configure\t\tconfigure file path\n"
4142           " <run without options to enter commands via usbboot prompt>\n\n"
42           "Report bugs to <xiangfu@qi-hardware.com>.\n"
43           "Report bugs to <xiangfu@sharism.cc>.\n"
4344        );
4445}
4546
...... 
107108        return EXIT_FAILURE;
108109
109110    if (command) { /* direct run command */
110        char *delim=";";
111        char *p;
112        p = strtok(cmdpt, delim);
113        strcpy(com_buf, p);
114        printf(" Execute command: %s \n",com_buf);
115        command_handle(com_buf);
116
117        while((p = strtok(NULL,delim))) {
118            strcpy(com_buf, p);
119            printf(" Execute command: %s \n",com_buf);
120            command_handle(com_buf);
111        char *p[10];
112        int i, loop = 0;
113        p[loop++] = strtok(cmdpt, ";");
114        while(p[loop++] = strtok(NULL, ";"));
115
116        for(i = 0; i < loop - 1 && i < 10; i++) {
117            printf(" Execute command: %s \n",p[i]);
118            command_handle(p[i]);
121119        }
122120        goto out;
123121    }

Archive Download the corresponding diff file



interactive