Date:2011-03-02 02:09:53 (9 years 8 months ago)
Author:Xiangfu Liu
Commit:702b54aa47ea37158226705259ea44a1f412a9bb
Message:cleanup code style, cleanup command process function

Files: usbboot/src/command_line.c (3 diffs)
usbboot/src/main.c (2 diffs)
usbboot/xburst_include/target/usb_boot.h (1 diff)
usbboot/xburst_stage2/udc.c (10 diffs)

Change Details

usbboot/src/command_line.c
3333char * stage1;
3434char * stage2;
3535
36static const char COMMAND[][COMMAND_NUM]=
37{
38    "",
39    "query",
40    "querya",
41    "erase",
42    "read",
43    "prog",
44    "nquery",
45    "nerase",
46    "nread",
47    "nreadraw",
48    "nreadoob", /* index 10 */
49    "nprog",
50    "help",
51    "version",
52    "go",
53    "fconfig",
54    "exit",
55    "readnand",
56    "gpios",
57    "gpioc",
58    "boot", /* index 20 */
59    "list",
60    "select",
61    "unselect",
62    "chip",
63    "unchip",
64    "nmark",
65    "nmake",
66    "load",
67    "memtest",
68    "run"
69};
70
7136static int handle_help(void)
7237{
73    printf(" command support in current version:\n"
74    /* " query" */
75    /* " querya" */
76    /* " erase" */
77    /* " read" */
78    /* " prog" */
38    printf(
39    " boot boot device and make it in stage2\n"
7940    " nquery query NAND flash info\n"
8041    " nerase erase NAND flash\n"
42    " nmark mark a bad block in NAND flash\n"
8143    " nread read NAND flash data with checking bad block and ECC\n"
8244    " nreadraw read NAND flash data without checking bad block and ECC\n"
83    " nreadoo read NAND flash oob without checking bad block and ECC\n" /* index 10 */
84    " nprog program NAND flash with data and ECC\n"
85    " help print this help\n"
86    " version show current USB Boot software version\n"
87    " go execute program in SDRAM\n"
88    " fconfig set USB Boot config file(not implement)\n"
89    " exit quit from telnet session\n"
90    " readnand read data from nand flash and store to SDRAM\n"
45    " nreadoob read NAND flash oob\n"
46    " nprog program NAND flash\n"
9147    " gpios set one GPIO to high level\n"
9248    " gpioc set one GPIO to low level\n"
93    " boot boot device and make it in stage2\n" /* index 20 */
94    " list show current device number can connect(not implement)\n"
95    /* " select" */
96    /* " unselect" */
97    /* " chip" */
98    /* " unchip" */
99    " nmark mark a bad block in NAND flash\n"
100    " nmake read all data from nand flash and store to file(not implement)\n"
10149    " load load file data to SDRAM\n"
102    " memtest do SDRAM test\n"
103    " run run command script in file(implement by -c args)\n"
104    " sdprog program SD card(not implement)\n"
105    " sdread read data from SD card(not implement)\n");
106    return 1;
107}
50    " go execute program in SDRAM\n"
51    " memtest memory test\n"
52    " help print this help\n"
53    " exit \n");
10854
109static int handle_version(void)
110{
111    printf(" USB Boot Software current version: %s\n", XBURST_TOOLS_VERSION);
112    return 1;
55    return 0;
11356}
11457
11558/* need transfer two para :blk_num ,start_blk */
...... 
15598    nand_in.start = atoi(com_argv[1]);
15699    nand_in.dev = atoi(com_argv[2]);
157100
158    if (atoi(com_argv[3])>=MAX_DEV_NUM) {
101    if (atoi(com_argv[3]) >= MAX_DEV_NUM) {
159102        printf(" Flash index number overflow!\n");
160103        return -1;
161104    }
...... 
223166    return 1;
224167}
225168
226int command_interpret(char * com_buf)
169int command_handle(char *buf)
227170{
228    if(com_buf[0] == '\n')
171    if(buf[0] == '\n')
229172        return 0;
230173
231174    com_argc = 0;
232    char *p = strtok(com_buf, "\n ");
175    char *p = strtok(buf, "\n ");
233176    strcpy(com_argv[com_argc++], p);
234177
235    while(p = strtok(NULL, "\n "))
178    while (p = strtok(NULL, "\n "))
236179        strcpy(com_argv[com_argc++], p);
237180
238    int loop = 0;
239    for (loop = 1; loop <= COMMAND_NUM; loop++)
240        if (!strcmp(COMMAND[loop], com_argv[0]))
241            return loop;
242
243    return -1;
244}
245
246int command_handle(char *buf)
247{
248    int cmd = command_interpret(buf); /* get the command index */
249
250    switch (cmd) {
251    case 0:
252        break;
253    case 6:
181    if (!strcmp("boot", com_argv[0]))
182        boot(stage1, stage2);
183    else if (!strcmp("nquery", com_argv[0]))
254184        nand_query();
255        break;
256    case 7:
185    else if (!strcmp("nerase", com_argv[0]))
257186        handle_nerase();
258        break;
259    case 8: /* nread */
187    else if (!strcmp("nmark", com_argv[0]))
188        handle_nmark();
189    else if (!strcmp("nread", com_argv[0]))
260190        nand_read(NAND_READ);
261        break;
262    case 9: /* nreadraw */
191    else if (!strcmp("nreadraw", com_argv[0]))
263192        nand_read(NAND_READ_RAW);
264        break;
265    case 10: /* nreadoob */
193    else if (!strcmp("nreadoob", com_argv[0]))
266194        nand_read(NAND_READ_OOB);
267        break;
268    case 11:
195    else if (!strcmp("nprog", com_argv[0]))
269196        nand_prog();
270        break;
271    case 12:
272        handle_help();
273        break;
274    case 13:
275        handle_version();
276        break;
277    case 14:
278        debug_go();
279        break;
280    case 16: /* exit */
281        printf(" exiting usbboot software\n");
282        return -1; /* return -1 to break the main.c while
283                 * then run usb_ingenic_cleanup*/
284        /*case 17:
285        nand_read(NAND_READ_TO_RAM); */
286        break;
287    case 18:
197    else if (!strcmp("gpios", com_argv[0]))
288198        handle_gpio(2);
289        break;
290    case 19:
199    else if (!strcmp("gpioc", com_argv[0]))
291200        handle_gpio(3);
292        break;
293    case 20:
294        boot(stage1, stage2);
295        break;
296    case 26:
297        handle_nmark();
298        break;
299    case 28:
201    else if (!strcmp("load", com_argv[0]))
300202        handle_load();
301        break;
302    case 29:
203    else if (!strcmp("go", com_argv[0]))
204        debug_go();
205    else if (!strcmp("memtest", com_argv[0]))
303206        handle_memtest();
304        break;
305    case -1:
306    default:
307        printf(" command not support or input error!\n");
308        break;
309    }
207    else if (!strcmp("help", com_argv[0]))
208        handle_help();
209    else if (!strcmp("exit", com_argv[0]))
210        return -1;
211    else
212        printf(" [%s] Not Support!", com_argv[0]);
310213
311    return 1;
214    return 0;
312215}
usbboot/src/main.c
120120        return EXIT_FAILURE;
121121
122122    if (command) { /* direct run command */
123        char *p[10];
123        char *sub_cmd[10];
124124        int i, loop = 0;
125        p[loop++] = strtok(cmdpt, ";");
126        while(p[loop++] = strtok(NULL, ";"));
127125
128        for(i = 0; i < loop - 1 && i < 10; i++) {
129            printf(" Execute command: %s \n",p[i]);
130            command_handle(p[i]);
126        sub_cmd[loop] = strtok(cmdpt, ";");
127        while (sub_cmd[loop] && loop < 10) {
128            loop++;
129            sub_cmd[loop] = strtok(NULL, ";");
130        }
131
132        for (i = 0; i < loop - 1; i++) {
133            printf(" Execute command: %s \n", sub_cmd[i]);
134            command_handle(sub_cmd[i]);
131135        }
132136        goto out;
133137    }
...... 
138142        if (cptr == NULL)
139143            continue;
140144
141        if (command_handle(com_buf) == -1 )
145        if (command_handle(com_buf))
142146            break;
143147    }
144148
145149out:
146150    usb_ingenic_cleanup(&ingenic_dev);
151
147152    return EXIT_SUCCESS;
148153}
usbboot/xburst_include/target/usb_boot.h
4343    VR_NOR_OPS,
4444    VR_NAND_OPS,
4545    VR_SDRAM_OPS,
46    VR_CONFIGRATION
46    VR_CONFIGRATION,
47    VR_OTHER
4748};
4849
4950#endif /* __USB_BOOT_H__ */
usbboot/xburst_stage2/udc.c
7070
7171    while (count--)
7272        *tmp++ = *s++;
73
7374    return dest;
7475}
7576
...... 
286287    jz_writew(USB_REG_INTRINE, 0);
287288    jz_writew(USB_REG_INTROUTE, 0);
288289    jz_writeb(USB_REG_INTRUSBE, 0);
289    jz_writeb(USB_REG_FADDR,0);
290    jz_writeb(USB_REG_POWER,0x60); //High speed
291    jz_writeb(USB_REG_INDEX,0);
292    jz_writeb(USB_REG_CSR0,0xc0);
293    jz_writeb(USB_REG_INDEX,1);
294    jz_writew(USB_REG_INMAXP,512);
295    jz_writew(USB_REG_INCSR,0x2048);
296    jz_writeb(USB_REG_INDEX,1);
297    jz_writew(USB_REG_OUTMAXP,512);
298    jz_writew(USB_REG_OUTCSR,0x0090);
299    jz_writew(USB_REG_INTRINE,0x3); //enable intr
300    jz_writew(USB_REG_INTROUTE,0x2);
301    jz_writeb(USB_REG_INTRUSBE,0x4);
302
303    byte=jz_readb(USB_REG_POWER);
304    if ((byte&0x10)==0) {
305        jz_writeb(USB_REG_INDEX,1);
306        jz_writew(USB_REG_INMAXP,64);
307        jz_writew(USB_REG_INCSR,0x2048);
308        jz_writeb(USB_REG_INDEX,1);
309        jz_writew(USB_REG_OUTMAXP,64);
310        jz_writew(USB_REG_OUTCSR,0x0090);
311        USB_Version=USB_FS;
312        fifosize[1]=64;
313        EP0_init(1,64,1,64);
290    jz_writeb(USB_REG_FADDR, 0);
291    jz_writeb(USB_REG_POWER, 0x60); //High speed
292    jz_writeb(USB_REG_INDEX, 0);
293    jz_writeb(USB_REG_CSR0, 0xc0);
294    jz_writeb(USB_REG_INDEX, 1);
295    jz_writew(USB_REG_INMAXP, 512);
296    jz_writew(USB_REG_INCSR, 0x2048);
297    jz_writeb(USB_REG_INDEX, 1);
298    jz_writew(USB_REG_OUTMAXP, 512);
299    jz_writew(USB_REG_OUTCSR, 0x0090);
300    jz_writew(USB_REG_INTRINE, 0x3); //enable intr
301    jz_writew(USB_REG_INTROUTE, 0x2);
302    jz_writeb(USB_REG_INTRUSBE, 0x4);
303
304    byte = jz_readb(USB_REG_POWER);
305    if ((byte&0x10) == 0) {
306        jz_writeb(USB_REG_INDEX, 1);
307        jz_writew(USB_REG_INMAXP, 64);
308        jz_writew(USB_REG_INCSR, 0x2048);
309        jz_writeb(USB_REG_INDEX, 1);
310        jz_writew(USB_REG_OUTMAXP, 64);
311        jz_writew(USB_REG_OUTCSR, 0x0090);
312        USB_Version = USB_FS;
313        fifosize[1] = 64;
314        EP0_init(1, 64, 1, 64);
314315    } else {
315        jz_writeb(USB_REG_INDEX,1);
316        jz_writew(USB_REG_INMAXP,512);
317        jz_writew(USB_REG_INCSR,0x2048);
318        jz_writeb(USB_REG_INDEX,1);
319        jz_writew(USB_REG_OUTMAXP,512);
320        jz_writew(USB_REG_OUTCSR,0x0090);
321        USB_Version=USB_HS;
322        fifosize[1]=512;
323        EP0_init(1,512,1,512);
316        jz_writeb(USB_REG_INDEX, 1);
317        jz_writew(USB_REG_INMAXP, 512);
318        jz_writew(USB_REG_INCSR, 0x2048);
319        jz_writeb(USB_REG_INDEX, 1);
320        jz_writew(USB_REG_OUTMAXP, 512);
321        jz_writew(USB_REG_OUTCSR, 0x0090);
322        USB_Version = USB_HS;
323        fifosize[1] = 512;
324        EP0_init(1, 512, 1, 512);
324325    }
325326
326327}
...... 
349350                break;
350351            }
351352        dprintf("\nSet ep0state=TX!");
352        ep0state=USB_EP0_TX;
353        ep0state = USB_EP0_TX;
353354
354355        break;
355356    case SET_ADDRESS:
...... 
382383    USB_DeviceRequest *dreq = (USB_DeviceRequest *)buf;
383384    switch (dreq->bRequest) {
384385    case VR_GET_CUP_INFO:
385        ret_state=GET_CUP_INFO_Handle();
386        ret_state = GET_CUP_INFO_Handle();
386387        break;
387388    case VR_SET_DATA_ADDERSS:
388        ret_state=SET_DATA_ADDERSS_Handle(buf);
389        ret_state = SET_DATA_ADDERSS_Handle(buf);
389390        break;
390391    case VR_SET_DATA_LENGTH:
391        ret_state=SET_DATA_LENGTH_Handle(buf);
392        ret_state = SET_DATA_LENGTH_Handle(buf);
392393        break;
393394    case VR_FLUSH_CACHES:
394        ret_state=FLUSH_CACHES_Handle();
395        ret_state = FLUSH_CACHES_Handle();
395396        break;
396397    case VR_PROGRAM_START1:
397        ret_state=PROGRAM_START1_Handle(buf);
398        ret_state = PROGRAM_START1_Handle(buf);
398399        break;
399400    case VR_PROGRAM_START2:
400        ret_state=PROGRAM_START2_Handle(buf);
401        ret_state = PROGRAM_START2_Handle(buf);
401402        break;
402403    case VR_NOR_OPS:
403        ret_state=NOR_OPS_Handle(buf);
404        ret_state = NOR_OPS_Handle(buf);
404405        Bulk_out_size = 0;
405406        break;
406407    case VR_NAND_OPS:
...... 
408409        Bulk_out_size = 0;
409410        break;
410411    case VR_CONFIGRATION:
411        ret_state=CONFIGRATION_Handle(buf);
412        handshake_PKT[3]=(u16)ret_state;
413        HW_SendPKT(1,(u8 *)handshake_PKT,sizeof(handshake_PKT));
412        ret_state = CONFIGRATION_Handle(buf);
413        handshake_PKT[3] = (u16)ret_state;
414        HW_SendPKT(1, (u8 *)handshake_PKT, sizeof(handshake_PKT));
414415        Bulk_out_size = 0;
415416        break;
416417    case VR_SDRAM_OPS:
...... 
422423
423424void Handshake_PKT()
424425{
425
426426    if (udc_state!=IDLE)
427427    {
428        HW_SendPKT(1,(u8 *)handshake_PKT,sizeof(handshake_PKT));
428        HW_SendPKT(1, (u8 *)handshake_PKT, sizeof(handshake_PKT));
429429        udc_state = IDLE;
430430        dprintf("\n Send handshake PKT!");
431431    }
...... 
473473    if (ep0state == USB_EP0_IDLE) {
474474        if (byCSR0 & USB_CSR0_OUTPKTRDY) { //There are datas in fifo
475475            USB_DeviceRequest *dreq;
476            fifo=fifoaddr[0];
476            fifo = fifoaddr[0];
477477            udcReadFifo((u8 *)rx_buf, sizeof(USB_DeviceRequest));
478478            usb_setb(USB_REG_CSR0, 0x48);//clear OUTRD bit
479479            dreq = (USB_DeviceRequest *)rx_buf;
480#if 0
481            dprintf("\nbmRequestType:%02x\nbRequest:%02x\n"
482                "wValue:%04x\nwIndex:%04x\n"
483                "wLength:%04x\n",
484                dreq->bmRequestType,
485                dreq->bRequest,
486                dreq->wValue,
487                dreq->wIndex,
488                dreq->wLength);
489#endif
490480            usbHandleDevReq((u8 *)rx_buf);
491        } else {
481        } else
492482            dprintf("0:R DATA\n");
493        }
483
494484        rx_size = 0;
495485    }
496486
...... 
502492            finished = tx_size;
503493            usb_setb(USB_REG_CSR0, USB_CSR0_INPKTRDY);
504494            usb_setb(USB_REG_CSR0, USB_CSR0_DATAEND); //Set dataend!
505            ep0state=USB_EP0_IDLE;
495            ep0state = USB_EP0_IDLE;
506496        } else {
507497            udcWriteFifo((u8 *)((u32)tx_buf+finished), 64);
508498            usb_setb(USB_REG_CSR0, USB_CSR0_INPKTRDY);
...... 
557547    IntrIn = jz_readw(USB_REG_INTRIN);
558548    IntrOut = jz_readw(USB_REG_INTROUT);
559549
560    if ( IntrUSB == 0 && IntrIn == 0 && IntrOut == 0)
550    if (IntrUSB == 0 && IntrIn == 0 && IntrOut == 0)
561551        return;
562552
563553    if (IntrIn & 2) {
...... 
602592    rx_size = 0;
603593    finished = 0;
604594
605    byte=jz_readb(USB_REG_POWER);
606    if ((byte&0x10)==0) {
607        USB_Version=USB_FS;
608        fifosize[1]=64;
609        EP0_init(1,64,1,64);
595    byte = jz_readb(USB_REG_POWER);
596    if ((byte&0x10) == 0) {
597        USB_Version = USB_FS;
598        fifosize[1] = 64;
599        EP0_init(1, 64, 1, 64);
610600    } else {
611        USB_Version=USB_HS;
612        fifosize[1]=512;
613        EP0_init(1,512,1,512);
601        USB_Version = USB_HS;
602        fifosize[1] = 512;
603        EP0_init(1, 512, 1, 512);
614604    }
615605
616606    serial_puts("\n Init UDC");
617    USB_Version=USB_HS;
618    while (1) {
607    USB_Version = USB_HS;
608
609    while (1)
619610        udc4740Proc();
620    }
621611}

Archive Download the corresponding diff file



interactive