1
0
mirror of git://projects.qi-hardware.com/xburst-tools.git synced 2024-11-01 08:22:47 +02:00

cleanup code style, cleanup command process function

This commit is contained in:
Xiangfu Liu 2011-03-02 09:09:53 +08:00
parent 0fc6972984
commit 702b54aa47
4 changed files with 120 additions and 221 deletions

View File

@ -33,83 +33,26 @@ char com_argv[MAX_ARGC][MAX_COMMAND_LENGTH];
char * stage1;
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)
{
printf(" command support in current version:\n"
/* " query" */
/* " querya" */
/* " erase" */
/* " read" */
/* " prog" */
printf(
" boot boot device and make it in stage2\n"
" nquery query NAND flash info\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"
" 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 */
" nprog program NAND flash with data and ECC\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"
" nreadoob read NAND flash oob\n"
" nprog program NAND flash\n"
" gpios set one GPIO to high 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"
" memtest do SDRAM test\n"
" run run command script in file(implement by -c args)\n"
" sdprog program SD card(not implement)\n"
" sdread read data from SD card(not implement)\n");
return 1;
}
" go execute program in SDRAM\n"
" memtest memory test\n"
" help print this help\n"
" exit \n");
static int handle_version(void)
{
printf(" USB Boot Software current version: %s\n", XBURST_TOOLS_VERSION);
return 1;
return 0;
}
/* need transfer two para :blk_num ,start_blk */
@ -155,7 +98,7 @@ int handle_nmark(void)
nand_in.start = atoi(com_argv[1]);
nand_in.dev = atoi(com_argv[2]);
if (atoi(com_argv[3])>=MAX_DEV_NUM) {
if (atoi(com_argv[3]) >= MAX_DEV_NUM) {
printf(" Flash index number overflow!\n");
return -1;
}
@ -223,90 +166,50 @@ int handle_load(void)
return 1;
}
int command_interpret(char * com_buf)
int command_handle(char *buf)
{
if(com_buf[0] == '\n')
if(buf[0] == '\n')
return 0;
com_argc = 0;
char *p = strtok(com_buf, "\n ");
char *p = strtok(buf, "\n ");
strcpy(com_argv[com_argc++], p);
while(p = strtok(NULL, "\n "))
while (p = strtok(NULL, "\n "))
strcpy(com_argv[com_argc++], p);
int loop = 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:
if (!strcmp("boot", com_argv[0]))
boot(stage1, stage2);
break;
case 26:
else if (!strcmp("nquery", com_argv[0]))
nand_query();
else if (!strcmp("nerase", com_argv[0]))
handle_nerase();
else if (!strcmp("nmark", com_argv[0]))
handle_nmark();
break;
case 28:
else if (!strcmp("nread", com_argv[0]))
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();
break;
case 29:
else if (!strcmp("go", com_argv[0]))
debug_go();
else if (!strcmp("memtest", com_argv[0]))
handle_memtest();
break;
case -1:
default:
printf(" command not support or input error!\n");
break;
}
else if (!strcmp("help", com_argv[0]))
handle_help();
else if (!strcmp("exit", com_argv[0]))
return -1;
else
printf(" [%s] Not Support!", com_argv[0]);
return 1;
return 0;
}

View File

@ -120,14 +120,18 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
if (command) { /* direct run command */
char *p[10];
char *sub_cmd[10];
int i, loop = 0;
p[loop++] = strtok(cmdpt, ";");
while(p[loop++] = strtok(NULL, ";"));
for(i = 0; i < loop - 1 && i < 10; i++) {
printf(" Execute command: %s \n",p[i]);
command_handle(p[i]);
sub_cmd[loop] = strtok(cmdpt, ";");
while (sub_cmd[loop] && loop < 10) {
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;
}
@ -138,11 +142,12 @@ int main(int argc, char **argv)
if (cptr == NULL)
continue;
if (command_handle(com_buf) == -1 )
if (command_handle(com_buf))
break;
}
out:
usb_ingenic_cleanup(&ingenic_dev);
return EXIT_SUCCESS;
}

View File

@ -43,7 +43,8 @@ enum USB_JZ4740_REQUEST /* add for USB_BOOT */
VR_NOR_OPS,
VR_NAND_OPS,
VR_SDRAM_OPS,
VR_CONFIGRATION
VR_CONFIGRATION,
VR_OTHER
};
#endif /* __USB_BOOT_H__ */

View File

@ -70,6 +70,7 @@ void *memcpy(void *dest, const void *src, size_t count)
while (count--)
*tmp++ = *s++;
return dest;
}
@ -286,41 +287,41 @@ static void udc_reset(void)
jz_writew(USB_REG_INTRINE, 0);
jz_writew(USB_REG_INTROUTE, 0);
jz_writeb(USB_REG_INTRUSBE, 0);
jz_writeb(USB_REG_FADDR,0);
jz_writeb(USB_REG_POWER,0x60); //High speed
jz_writeb(USB_REG_INDEX,0);
jz_writeb(USB_REG_CSR0,0xc0);
jz_writeb(USB_REG_INDEX,1);
jz_writew(USB_REG_INMAXP,512);
jz_writew(USB_REG_INCSR,0x2048);
jz_writeb(USB_REG_INDEX,1);
jz_writew(USB_REG_OUTMAXP,512);
jz_writew(USB_REG_OUTCSR,0x0090);
jz_writew(USB_REG_INTRINE,0x3); //enable intr
jz_writew(USB_REG_INTROUTE,0x2);
jz_writeb(USB_REG_INTRUSBE,0x4);
jz_writeb(USB_REG_FADDR, 0);
jz_writeb(USB_REG_POWER, 0x60); //High speed
jz_writeb(USB_REG_INDEX, 0);
jz_writeb(USB_REG_CSR0, 0xc0);
jz_writeb(USB_REG_INDEX, 1);
jz_writew(USB_REG_INMAXP, 512);
jz_writew(USB_REG_INCSR, 0x2048);
jz_writeb(USB_REG_INDEX, 1);
jz_writew(USB_REG_OUTMAXP, 512);
jz_writew(USB_REG_OUTCSR, 0x0090);
jz_writew(USB_REG_INTRINE, 0x3); //enable intr
jz_writew(USB_REG_INTROUTE, 0x2);
jz_writeb(USB_REG_INTRUSBE, 0x4);
byte=jz_readb(USB_REG_POWER);
if ((byte&0x10)==0) {
jz_writeb(USB_REG_INDEX,1);
jz_writew(USB_REG_INMAXP,64);
jz_writew(USB_REG_INCSR,0x2048);
jz_writeb(USB_REG_INDEX,1);
jz_writew(USB_REG_OUTMAXP,64);
jz_writew(USB_REG_OUTCSR,0x0090);
USB_Version=USB_FS;
fifosize[1]=64;
EP0_init(1,64,1,64);
byte = jz_readb(USB_REG_POWER);
if ((byte&0x10) == 0) {
jz_writeb(USB_REG_INDEX, 1);
jz_writew(USB_REG_INMAXP, 64);
jz_writew(USB_REG_INCSR, 0x2048);
jz_writeb(USB_REG_INDEX, 1);
jz_writew(USB_REG_OUTMAXP, 64);
jz_writew(USB_REG_OUTCSR, 0x0090);
USB_Version = USB_FS;
fifosize[1] = 64;
EP0_init(1, 64, 1, 64);
} else {
jz_writeb(USB_REG_INDEX,1);
jz_writew(USB_REG_INMAXP,512);
jz_writew(USB_REG_INCSR,0x2048);
jz_writeb(USB_REG_INDEX,1);
jz_writew(USB_REG_OUTMAXP,512);
jz_writew(USB_REG_OUTCSR,0x0090);
USB_Version=USB_HS;
fifosize[1]=512;
EP0_init(1,512,1,512);
jz_writeb(USB_REG_INDEX, 1);
jz_writew(USB_REG_INMAXP, 512);
jz_writew(USB_REG_INCSR, 0x2048);
jz_writeb(USB_REG_INDEX, 1);
jz_writew(USB_REG_OUTMAXP, 512);
jz_writew(USB_REG_OUTCSR, 0x0090);
USB_Version = USB_HS;
fifosize[1] = 512;
EP0_init(1, 512, 1, 512);
}
}
@ -349,7 +350,7 @@ void usbHandleStandDevReq(u8 *buf)
break;
}
dprintf("\nSet ep0state=TX!");
ep0state=USB_EP0_TX;
ep0state = USB_EP0_TX;
break;
case SET_ADDRESS:
@ -382,25 +383,25 @@ void usbHandleVendorReq(u8 *buf)
USB_DeviceRequest *dreq = (USB_DeviceRequest *)buf;
switch (dreq->bRequest) {
case VR_GET_CUP_INFO:
ret_state=GET_CUP_INFO_Handle();
ret_state = GET_CUP_INFO_Handle();
break;
case VR_SET_DATA_ADDERSS:
ret_state=SET_DATA_ADDERSS_Handle(buf);
ret_state = SET_DATA_ADDERSS_Handle(buf);
break;
case VR_SET_DATA_LENGTH:
ret_state=SET_DATA_LENGTH_Handle(buf);
ret_state = SET_DATA_LENGTH_Handle(buf);
break;
case VR_FLUSH_CACHES:
ret_state=FLUSH_CACHES_Handle();
ret_state = FLUSH_CACHES_Handle();
break;
case VR_PROGRAM_START1:
ret_state=PROGRAM_START1_Handle(buf);
ret_state = PROGRAM_START1_Handle(buf);
break;
case VR_PROGRAM_START2:
ret_state=PROGRAM_START2_Handle(buf);
ret_state = PROGRAM_START2_Handle(buf);
break;
case VR_NOR_OPS:
ret_state=NOR_OPS_Handle(buf);
ret_state = NOR_OPS_Handle(buf);
Bulk_out_size = 0;
break;
case VR_NAND_OPS:
@ -408,9 +409,9 @@ void usbHandleVendorReq(u8 *buf)
Bulk_out_size = 0;
break;
case VR_CONFIGRATION:
ret_state=CONFIGRATION_Handle(buf);
handshake_PKT[3]=(u16)ret_state;
HW_SendPKT(1,(u8 *)handshake_PKT,sizeof(handshake_PKT));
ret_state = CONFIGRATION_Handle(buf);
handshake_PKT[3] = (u16)ret_state;
HW_SendPKT(1, (u8 *)handshake_PKT, sizeof(handshake_PKT));
Bulk_out_size = 0;
break;
case VR_SDRAM_OPS:
@ -422,10 +423,9 @@ void usbHandleVendorReq(u8 *buf)
void Handshake_PKT()
{
if (udc_state!=IDLE)
{
HW_SendPKT(1,(u8 *)handshake_PKT,sizeof(handshake_PKT));
HW_SendPKT(1, (u8 *)handshake_PKT, sizeof(handshake_PKT));
udc_state = IDLE;
dprintf("\n Send handshake PKT!");
}
@ -473,24 +473,14 @@ void EP0_Handler ()
if (ep0state == USB_EP0_IDLE) {
if (byCSR0 & USB_CSR0_OUTPKTRDY) { //There are datas in fifo
USB_DeviceRequest *dreq;
fifo=fifoaddr[0];
fifo = fifoaddr[0];
udcReadFifo((u8 *)rx_buf, sizeof(USB_DeviceRequest));
usb_setb(USB_REG_CSR0, 0x48);//clear OUTRD bit
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);
} else {
} else
dprintf("0:R DATA\n");
}
rx_size = 0;
}
@ -502,7 +492,7 @@ void EP0_Handler ()
finished = tx_size;
usb_setb(USB_REG_CSR0, USB_CSR0_INPKTRDY);
usb_setb(USB_REG_CSR0, USB_CSR0_DATAEND); //Set dataend!
ep0state=USB_EP0_IDLE;
ep0state = USB_EP0_IDLE;
} else {
udcWriteFifo((u8 *)((u32)tx_buf+finished), 64);
usb_setb(USB_REG_CSR0, USB_CSR0_INPKTRDY);
@ -557,7 +547,7 @@ void udc4740Proc ()
IntrIn = jz_readw(USB_REG_INTRIN);
IntrOut = jz_readw(USB_REG_INTROUT);
if ( IntrUSB == 0 && IntrIn == 0 && IntrOut == 0)
if (IntrUSB == 0 && IntrIn == 0 && IntrOut == 0)
return;
if (IntrIn & 2) {
@ -602,20 +592,20 @@ void usb_main()
rx_size = 0;
finished = 0;
byte=jz_readb(USB_REG_POWER);
if ((byte&0x10)==0) {
USB_Version=USB_FS;
fifosize[1]=64;
EP0_init(1,64,1,64);
byte = jz_readb(USB_REG_POWER);
if ((byte&0x10) == 0) {
USB_Version = USB_FS;
fifosize[1] = 64;
EP0_init(1, 64, 1, 64);
} else {
USB_Version=USB_HS;
fifosize[1]=512;
EP0_init(1,512,1,512);
USB_Version = USB_HS;
fifosize[1] = 512;
EP0_init(1, 512, 1, 512);
}
serial_puts("\n Init UDC");
USB_Version=USB_HS;
while (1) {
USB_Version = USB_HS;
while (1)
udc4740Proc();
}
}