Date:2011-03-02 03:07:47 (9 years 8 months ago)
Author:Xiangfu Liu
Commit:f6850034561f39cd6b0c131756faab57b2bdfb48
Message:increate cmd buf size, some code style cleanup

Files: usbboot/src/command_line.c (10 diffs)
usbboot/src/main.c (4 diffs)

Change Details

usbboot/src/command_line.c
3737{
3838    printf(
3939    " boot boot device and make it in stage2\n"
40    " nprog program NAND flash\n"
4041    " nquery query NAND flash info\n"
4142    " nerase erase NAND flash\n"
4243    " nmark mark a bad block in NAND flash\n"
4344    " nread read NAND flash data with checking bad block and ECC\n"
4445    " nreadraw read NAND flash data without checking bad block and ECC\n"
4546    " nreadoob read NAND flash oob\n"
46    " nprog program NAND flash\n"
4747    " gpios set one GPIO to high level\n"
4848    " gpioc set one GPIO to low level\n"
4949    " load load file data to SDRAM\n"
...... 
8181    if (nand_erase(&nand_in) < 1)
8282        return -1;
8383
84    return 1;
84    return 0;
8585}
8686
8787int handle_nmark(void)
...... 
9393               " 3:flash chip index number\n");
9494        return -1;
9595    }
96
9697    init_nand_in();
9798
9899    nand_in.start = atoi(com_argv[1]);
...... 
105106    (nand_in.cs_map)[atoi(com_argv[3])] = 1;
106107
107108    nand_markbad(&nand_in);
108    return 1;
109    return 0;
109110}
110111
111112int handle_memtest(void)
112113{
113114    unsigned int start, size;
114    if (com_argc != 2 && com_argc != 4)
115    {
115    if (com_argc != 2 && com_argc != 4) {
116116        printf(" Usage: memtest (1) [2] [3]\n"
117117               " 1:device index number\n"
118118               " 2:SDRAM start address\n"
...... 
127127        start = 0;
128128        size = 0;
129129    }
130
130131    debug_memory(atoi(com_argv[1]), start, size);
131    return 1;
132    return 0;
132133}
133134
134135int handle_gpio(int mode)
...... 
142143    }
143144
144145    debug_gpio(atoi(com_argv[2]), mode, atoi(com_argv[1]));
145    return 1;
146    return 0;
146147}
147148
148149int handle_load(void)
149150{
150    if (com_argc<4) {
151    if (com_argc < 4) {
151152        printf(" Usage:"
152153               " load (1) (2) (3) \n"
153154               " 1:SDRAM start address\n"
...... 
158159    }
159160
160161    sdram_in.start=strtoul(com_argv[1], NULL, 0);
161    printf(" start:::::: 0x%x\n", sdram_in.start);
162
163162    sdram_in.dev = atoi(com_argv[3]);
164163    sdram_in.buf = code_buf;
164
165165    sdram_load_file(&sdram_in, com_argv[2]);
166    return 1;
166    return 0;
167167}
168168
169169int command_handle(char *buf)
170170{
171    if(buf[0] == '\n')
171    char *p = strtok(buf, "\n ");
172    if(p == NULL)
172173        return 0;
173174
174175    com_argc = 0;
175    char *p = strtok(buf, "\n ");
176176    strcpy(com_argv[com_argc++], p);
177177
178178    while (p = strtok(NULL, "\n "))
...... 
180180
181181    if (!strcmp("boot", com_argv[0]))
182182        boot(stage1, stage2);
183    else if (!strcmp("nprog", com_argv[0]))
184        nand_prog();
183185    else if (!strcmp("nquery", com_argv[0]))
184186        nand_query();
185187    else if (!strcmp("nerase", com_argv[0]))
...... 
192194        nand_read(NAND_READ_RAW);
193195    else if (!strcmp("nreadoob", com_argv[0]))
194196        nand_read(NAND_READ_OOB);
195    else if (!strcmp("nprog", com_argv[0]))
196        nand_prog();
197197    else if (!strcmp("gpios", com_argv[0]))
198198        handle_gpio(2);
199199    else if (!strcmp("gpioc", com_argv[0]))
...... 
209209    else if (!strcmp("exit", com_argv[0]))
210210        return -1;
211211    else
212        printf(" [%s] Not Support!", com_argv[0]);
212        printf(" type `help` show all commands\n", com_argv[0]);
213213
214214    return 0;
215215}
usbboot/src/main.c
6767
6868int main(int argc, char **argv)
6969{
70    int command = 0;
7170    char *cptr;
72    char com_buf[256] = {0};
7371    char *cmdpt;
72    int command = 0;
73    char cmd_buf[512] = {0};
7474    char *cfgpath = CONFIG_FILE_PATH;
75
7576    stage1 = STAGE1_FILE_PATH;
7677    stage2 = STAGE2_FILE_PATH;
7778
...... 
7980           "(c) 2009 Ingenic Semiconductor Inc., Qi Hardware Inc., Xiangfu Liu, Marek Lindner\n"
8081           "This program is Free Software and comes with ABSOLUTELY NO WARRANTY.\n\n");
8182
82
8383    while(1) {
8484        int c, option_index = 0;
8585        c = getopt_long(argc, argv, "hvc:f:1:2:", opts,
...... 
119119    if (parse_configure(&hand, cfgpath) < 1)
120120        return EXIT_FAILURE;
121121
122#define MAX_COMMANDS 10
122123    if (command) { /* direct run command */
123        char *sub_cmd[10];
124        char *sub_cmd[MAX_COMMANDS];
124125        int i, loop = 0;
125126
126        sub_cmd[loop] = strtok(cmdpt, ";");
127        while (sub_cmd[loop] && loop < 10) {
128            loop++;
129            sub_cmd[loop] = strtok(NULL, ";");
130        }
127        sub_cmd[loop++] = strtok(cmdpt, ";");
128        while (sub_cmd[loop++] = strtok(NULL, ";"))
129            if (loop >= MAX_COMMANDS) {
130                printf(" -c only support 10 commands\n");
131                break;
132            }
131133
132134        for (i = 0; i < loop - 1; i++) {
133135            printf(" Execute command: %s \n", sub_cmd[i]);
...... 
137139    }
138140
139141    while (1) {
140        printf("usbboot :> ");
141        cptr = fgets(com_buf, 256, stdin);
142        if (cptr == NULL)
143            continue;
144
145        if (command_handle(com_buf))
146            break;
142        printf("usbboot# ");
143        cptr = fgets(cmd_buf, sizeof(cmd_buf), stdin);
144        if (cptr != NULL)
145            if (command_handle(cmd_buf))
146                break;
147147    }
148148
149149out:

Archive Download the corresponding diff file



interactive