forked from OpenNuvoton/NUC970_NuWriter_CMD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.c
105 lines (97 loc) · 2.14 KB
/
parse.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "common.h"
#include <unistd.h> /* sleep */
#include <string.h>
int init_xusb(void)
{
int ret=0;
char DDR[256];
char XUSB[256];
int bResult,dlen,xlen;
unsigned char *dbuf=NULL,*xbuf=NULL;
ret=NUC_OpenUsb();
if(ret<0) return -1;
sprintf(DDR,"%s/sys_cfg/%s",Data_Path,DDR_fileName);
dbuf=load_ddr(DDR,&dlen);
if(dbuf==NULL) {
ret=-1;
goto EXIT;
}
bResult=DDRtoDevice(dbuf,dlen);
if(bResult==RUN_ON_XUSB) {
ret=bResult;
goto EXIT;
}
if(bResult<0) {
printf("init_xusb:Burn DDR to Device failed,bResult=%d\n",bResult);
ret=bResult;
goto EXIT;
}
if(DDR_fileName[strlen(DDR_fileName)-7]=='7') {
MSG_DEBUG("load xusb128.bin\n");
sprintf(XUSB,"%s/xusb128.bin",Data_Path);
} else if(DDR_fileName[strlen(DDR_fileName)-7]=='6') {
MSG_DEBUG("load xusb64.bin\n");
sprintf(XUSB,"%s/xusb64.bin",Data_Path);
} else if(DDR_fileName[strlen(DDR_fileName)-7]=='5') {
MSG_DEBUG("load xusb32.bin\n");
sprintf(XUSB,"%s/xusb.bin",Data_Path);
} else {
MSG_DEBUG("load xusb16.bin\n");
sprintf(XUSB,"%s/xusb16.bin",Data_Path);
}
xbuf=load_xusb(XUSB,&xlen);
if(xbuf==NULL) {
printf("Cannot find xusb.bin\n");
ret=-1;
goto EXIT;
}
if(XUSBtoDevice(xbuf,xlen)<0) {
printf("Burn XUSB to Device failed\n");
ret=-1;
goto EXIT;
}
NUC_CloseUsb();
sleep(1);
while(get_device_num_with_vid_pid(ctx,USB_VENDOR_ID, USB_PRODUCT_ID)!=dev_count) {
sleep(1);
}
ret=NUC_OpenUsb();
if(ret<0) return -1;
EXIT:
usleep(100);
return ret;
}
int ParseFlashType(void)
{
int ret;
if((ret=init_xusb())<0) {
printf("initail xusb failed %d\n",ret);
return -1;
}
if(InfoFromDevice()<0) {
printf(" Get information failed for Device\n");
return -1;
}
switch(mode) {
case SDRAM_M:
MSG_DEBUG("ParseFlashType-SDRAM_M\n");
if(UXmodem_SDRAM()<0) return -1;
break;
case NAND_M:
MSG_DEBUG("ParseFlashType-NAND_M\n");
if(UXmodem_NAND()<0) return -1;
break;
case SPI_M:
MSG_DEBUG("ParseFlashType-SPI_M\n");
if(UXmodem_SPI()<0) return -1;
break;
case EMMC_M:
MSG_DEBUG("ParseFlashType-EMMC_M\n");
if(UXmodem_EMMC()<0) return -1;
break;
default:
MSG_DEBUG("Unsupported Flash Type!/n");
return -1;
}
return 0;
}