mirror of
git://projects.qi-hardware.com/xburst-tools.git
synced 2024-11-26 01:35:54 +02:00
cleanup code style, cleanup command process function
This commit is contained in:
parent
0fc6972984
commit
702b54aa47
@ -33,83 +33,26 @@ char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH];
|
|||||||
char * stage1;
|
char * stage1;
|
||||||
char * stage2;
|
char * stage2;
|
||||||
|
|
||||||
static const char COMMAND[][COMMAND_NUM]=
|
|
||||||
{
|
|
||||||
"",
|
|
||||||
"query",
|
|
||||||
"querya",
|
|
||||||
"erase",
|
|
||||||
"read",
|
|
||||||
"prog",
|
|
||||||
"nquery",
|
|
||||||
"nerase",
|
|
||||||
"nread",
|
|
||||||
"nreadraw",
|
|
||||||
"nreadoob", /* index 10 */
|
|
||||||
"nprog",
|
|
||||||
"help",
|
|
||||||
"version",
|
|
||||||
"go",
|
|
||||||
"fconfig",
|
|
||||||
"exit",
|
|
||||||
"readnand",
|
|
||||||
"gpios",
|
|
||||||
"gpioc",
|
|
||||||
"boot", /* index 20 */
|
|
||||||
"list",
|
|
||||||
"select",
|
|
||||||
"unselect",
|
|
||||||
"chip",
|
|
||||||
"unchip",
|
|
||||||
"nmark",
|
|
||||||
"nmake",
|
|
||||||
"load",
|
|
||||||
"memtest",
|
|
||||||
"run"
|
|
||||||
};
|
|
||||||
|
|
||||||
static int handle_help(void)
|
static int handle_help(void)
|
||||||
{
|
{
|
||||||
printf(" command support in current version:\n"
|
printf(
|
||||||
/* " query" */
|
" boot boot device and make it in stage2\n"
|
||||||
/* " querya" */
|
|
||||||
/* " erase" */
|
|
||||||
/* " read" */
|
|
||||||
/* " prog" */
|
|
||||||
" nquery query NAND flash info\n"
|
" nquery query NAND flash info\n"
|
||||||
" nerase erase NAND flash\n"
|
" nerase erase NAND flash\n"
|
||||||
|
" nmark mark a bad block in NAND flash\n"
|
||||||
" nread read NAND flash data with checking bad block and ECC\n"
|
" nread read NAND flash data with checking bad block and ECC\n"
|
||||||
" nreadraw read NAND flash data without checking bad block and ECC\n"
|
" nreadraw read NAND flash data without checking bad block and ECC\n"
|
||||||
" nreadoo read NAND flash oob without checking bad block and ECC\n" /* index 10 */
|
" nreadoob read NAND flash oob\n"
|
||||||
" nprog program NAND flash with data and ECC\n"
|
" nprog program NAND flash\n"
|
||||||
" help print this help\n"
|
|
||||||
" version show current USB Boot software version\n"
|
|
||||||
" go execute program in SDRAM\n"
|
|
||||||
" fconfig set USB Boot config file(not implement)\n"
|
|
||||||
" exit quit from telnet session\n"
|
|
||||||
" readnand read data from nand flash and store to SDRAM\n"
|
|
||||||
" gpios set one GPIO to high level\n"
|
" gpios set one GPIO to high level\n"
|
||||||
" gpioc set one GPIO to low level\n"
|
" gpioc set one GPIO to low level\n"
|
||||||
" boot boot device and make it in stage2\n" /* index 20 */
|
|
||||||
" list show current device number can connect(not implement)\n"
|
|
||||||
/* " select" */
|
|
||||||
/* " unselect" */
|
|
||||||
/* " chip" */
|
|
||||||
/* " unchip" */
|
|
||||||
" nmark mark a bad block in NAND flash\n"
|
|
||||||
" nmake read all data from nand flash and store to file(not implement)\n"
|
|
||||||
" load load file data to SDRAM\n"
|
" load load file data to SDRAM\n"
|
||||||
" memtest do SDRAM test\n"
|
" go execute program in SDRAM\n"
|
||||||
" run run command script in file(implement by -c args)\n"
|
" memtest memory test\n"
|
||||||
" sdprog program SD card(not implement)\n"
|
" help print this help\n"
|
||||||
" sdread read data from SD card(not implement)\n");
|
" exit \n");
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int handle_version(void)
|
return 0;
|
||||||
{
|
|
||||||
printf(" USB Boot Software current version: %s\n", XBURST_TOOLS_VERSION);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* need transfer two para :blk_num ,start_blk */
|
/* need transfer two para :blk_num ,start_blk */
|
||||||
@ -223,90 +166,50 @@ int handle_load(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int command_interpret(char * com_buf)
|
int command_handle(char *buf)
|
||||||
{
|
{
|
||||||
if(com_buf[0] == '\n')
|
if(buf[0] == '\n')
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
com_argc = 0;
|
com_argc = 0;
|
||||||
char *p = strtok(com_buf, "\n ");
|
char *p = strtok(buf, "\n ");
|
||||||
strcpy(com_argv[com_argc++], p);
|
strcpy(com_argv[com_argc++], p);
|
||||||
|
|
||||||
while (p = strtok(NULL, "\n "))
|
while (p = strtok(NULL, "\n "))
|
||||||
strcpy(com_argv[com_argc++], p);
|
strcpy(com_argv[com_argc++], p);
|
||||||
|
|
||||||
int loop = 0;
|
if (!strcmp("boot", com_argv[0]))
|
||||||
for (loop = 1; loop <= COMMAND_NUM; loop++)
|
|
||||||
if (!strcmp(COMMAND[loop], com_argv[0]))
|
|
||||||
return loop;
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int command_handle(char *buf)
|
|
||||||
{
|
|
||||||
int cmd = command_interpret(buf); /* get the command index */
|
|
||||||
|
|
||||||
switch (cmd) {
|
|
||||||
case 0:
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
nand_query();
|
|
||||||
break;
|
|
||||||
case 7:
|
|
||||||
handle_nerase();
|
|
||||||
break;
|
|
||||||
case 8: /* nread */
|
|
||||||
nand_read(NAND_READ);
|
|
||||||
break;
|
|
||||||
case 9: /* nreadraw */
|
|
||||||
nand_read(NAND_READ_RAW);
|
|
||||||
break;
|
|
||||||
case 10: /* nreadoob */
|
|
||||||
nand_read(NAND_READ_OOB);
|
|
||||||
break;
|
|
||||||
case 11:
|
|
||||||
nand_prog();
|
|
||||||
break;
|
|
||||||
case 12:
|
|
||||||
handle_help();
|
|
||||||
break;
|
|
||||||
case 13:
|
|
||||||
handle_version();
|
|
||||||
break;
|
|
||||||
case 14:
|
|
||||||
debug_go();
|
|
||||||
break;
|
|
||||||
case 16: /* exit */
|
|
||||||
printf(" exiting usbboot software\n");
|
|
||||||
return -1; /* return -1 to break the main.c while
|
|
||||||
* then run usb_ingenic_cleanup*/
|
|
||||||
/*case 17:
|
|
||||||
nand_read(NAND_READ_TO_RAM); */
|
|
||||||
break;
|
|
||||||
case 18:
|
|
||||||
handle_gpio(2);
|
|
||||||
break;
|
|
||||||
case 19:
|
|
||||||
handle_gpio(3);
|
|
||||||
break;
|
|
||||||
case 20:
|
|
||||||
boot(stage1, stage2);
|
boot(stage1, stage2);
|
||||||
break;
|
else if (!strcmp("nquery", com_argv[0]))
|
||||||
case 26:
|
nand_query();
|
||||||
|
else if (!strcmp("nerase", com_argv[0]))
|
||||||
|
handle_nerase();
|
||||||
|
else if (!strcmp("nmark", com_argv[0]))
|
||||||
handle_nmark();
|
handle_nmark();
|
||||||
break;
|
else if (!strcmp("nread", com_argv[0]))
|
||||||
case 28:
|
nand_read(NAND_READ);
|
||||||
|
else if (!strcmp("nreadraw", com_argv[0]))
|
||||||
|
nand_read(NAND_READ_RAW);
|
||||||
|
else if (!strcmp("nreadoob", com_argv[0]))
|
||||||
|
nand_read(NAND_READ_OOB);
|
||||||
|
else if (!strcmp("nprog", com_argv[0]))
|
||||||
|
nand_prog();
|
||||||
|
else if (!strcmp("gpios", com_argv[0]))
|
||||||
|
handle_gpio(2);
|
||||||
|
else if (!strcmp("gpioc", com_argv[0]))
|
||||||
|
handle_gpio(3);
|
||||||
|
else if (!strcmp("load", com_argv[0]))
|
||||||
handle_load();
|
handle_load();
|
||||||
break;
|
else if (!strcmp("go", com_argv[0]))
|
||||||
case 29:
|
debug_go();
|
||||||
|
else if (!strcmp("memtest", com_argv[0]))
|
||||||
handle_memtest();
|
handle_memtest();
|
||||||
break;
|
else if (!strcmp("help", com_argv[0]))
|
||||||
case -1:
|
handle_help();
|
||||||
default:
|
else if (!strcmp("exit", com_argv[0]))
|
||||||
printf(" command not support or input error!\n");
|
return -1;
|
||||||
break;
|
else
|
||||||
}
|
printf(" [%s] Not Support!", com_argv[0]);
|
||||||
|
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -120,14 +120,18 @@ int main(int argc, char **argv)
|
|||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
if (command) { /* direct run command */
|
if (command) { /* direct run command */
|
||||||
char *p[10];
|
char *sub_cmd[10];
|
||||||
int i, loop = 0;
|
int i, loop = 0;
|
||||||
p[loop++] = strtok(cmdpt, ";");
|
|
||||||
while(p[loop++] = strtok(NULL, ";"));
|
|
||||||
|
|
||||||
for(i = 0; i < loop - 1 && i < 10; i++) {
|
sub_cmd[loop] = strtok(cmdpt, ";");
|
||||||
printf(" Execute command: %s \n",p[i]);
|
while (sub_cmd[loop] && loop < 10) {
|
||||||
command_handle(p[i]);
|
loop++;
|
||||||
|
sub_cmd[loop] = strtok(NULL, ";");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < loop - 1; i++) {
|
||||||
|
printf(" Execute command: %s \n", sub_cmd[i]);
|
||||||
|
command_handle(sub_cmd[i]);
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -138,11 +142,12 @@ int main(int argc, char **argv)
|
|||||||
if (cptr == NULL)
|
if (cptr == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (command_handle(com_buf) == -1 )
|
if (command_handle(com_buf))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
usb_ingenic_cleanup(&ingenic_dev);
|
usb_ingenic_cleanup(&ingenic_dev);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ enum USB_JZ4740_REQUEST /* add for USB_BOOT */
|
|||||||
VR_NOR_OPS,
|
VR_NOR_OPS,
|
||||||
VR_NAND_OPS,
|
VR_NAND_OPS,
|
||||||
VR_SDRAM_OPS,
|
VR_SDRAM_OPS,
|
||||||
VR_CONFIGRATION
|
VR_CONFIGRATION,
|
||||||
|
VR_OTHER
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __USB_BOOT_H__ */
|
#endif /* __USB_BOOT_H__ */
|
||||||
|
@ -70,6 +70,7 @@ void *memcpy(void *dest, const void *src, size_t count)
|
|||||||
|
|
||||||
while (count--)
|
while (count--)
|
||||||
*tmp++ = *s++;
|
*tmp++ = *s++;
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,7 +423,6 @@ void usbHandleVendorReq(u8 *buf)
|
|||||||
|
|
||||||
void Handshake_PKT()
|
void Handshake_PKT()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (udc_state!=IDLE)
|
if (udc_state!=IDLE)
|
||||||
{
|
{
|
||||||
HW_SendPKT(1, (u8 *)handshake_PKT, sizeof(handshake_PKT));
|
HW_SendPKT(1, (u8 *)handshake_PKT, sizeof(handshake_PKT));
|
||||||
@ -477,20 +477,10 @@ void EP0_Handler ()
|
|||||||
udcReadFifo((u8 *)rx_buf, sizeof(USB_DeviceRequest));
|
udcReadFifo((u8 *)rx_buf, sizeof(USB_DeviceRequest));
|
||||||
usb_setb(USB_REG_CSR0, 0x48);//clear OUTRD bit
|
usb_setb(USB_REG_CSR0, 0x48);//clear OUTRD bit
|
||||||
dreq = (USB_DeviceRequest *)rx_buf;
|
dreq = (USB_DeviceRequest *)rx_buf;
|
||||||
#if 0
|
|
||||||
dprintf("\nbmRequestType:%02x\nbRequest:%02x\n"
|
|
||||||
"wValue:%04x\nwIndex:%04x\n"
|
|
||||||
"wLength:%04x\n",
|
|
||||||
dreq->bmRequestType,
|
|
||||||
dreq->bRequest,
|
|
||||||
dreq->wValue,
|
|
||||||
dreq->wIndex,
|
|
||||||
dreq->wLength);
|
|
||||||
#endif
|
|
||||||
usbHandleDevReq((u8 *)rx_buf);
|
usbHandleDevReq((u8 *)rx_buf);
|
||||||
} else {
|
} else
|
||||||
dprintf("0:R DATA\n");
|
dprintf("0:R DATA\n");
|
||||||
}
|
|
||||||
rx_size = 0;
|
rx_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -615,7 +605,7 @@ void usb_main()
|
|||||||
|
|
||||||
serial_puts("\n Init UDC");
|
serial_puts("\n Init UDC");
|
||||||
USB_Version = USB_HS;
|
USB_Version = USB_HS;
|
||||||
while (1) {
|
|
||||||
|
while (1)
|
||||||
udc4740Proc();
|
udc4740Proc();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user