2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 //-----------------------------------------------------------------------
18 // winhost script translation tool under Linux for Danube
19 //-----------------------------------------------------------------------
20 //Author: Qi-Ming.Wu@infineon.com
21 //Created: 29-October-2004
22 //-----------------------------------------------------------------------
29 #define _IFXMIPS_ADSL_APP
31 #define u32 unsigned int
32 #define u16 unsigned short
33 #define u8 unsigned char
34 #define IFXMIPS_MEI_DEV "/dev/ifxmips/mei"
43 #include <sys/types.h>
44 #include <sys/ioctl.h>
49 #include <asm/ifxmips/ifxmips.h>
50 #include <asm/ifxmips/ifxmips_mei_app_ioctl.h>
51 #include <asm/ifxmips/ifxmips_mei_app.h>
52 #include <asm/ifxmips/ifxmips_mei_ioctl.h>
53 #include <asm/ifxmips/ifxmips_mei.h>
56 /*============================definitions======================*/
66 typedef unsigned short UINT16;
67 typedef unsigned long UINT32;
71 /*=============================================================*/
74 /*=============================global variables================*/
86 /*=============================================================*/
91 void display_version()
93 printf("translate version1.0\nby Wu Qi Ming\nQi-Ming.Wu@infineon.com\n");
100 printf("Usage:translate [options] [parameter] ...\n");
101 printf("options:\n");
102 printf("-h --help Display help information\n");
103 printf("-v --version Display version information\n");
104 printf("-f --file Specify the script file\n");
105 printf("-e --execute Execute the specified script file\n");
106 //printf("-c --check Check the script file\n");
111 print the content in buf excluding the command "echo" itself.
120 if((buf[i]!=0)&&(buf[i]!=32))
122 sscanf(buf+i,"%s",&msg);
123 if(strcmp(msg,"echo")==0)
131 if(buf[i]!=0&&(buf[i]!=10))
143 static void makeCMV(u8 opcode, u8 group, u16 address, u16 index, int size, u16 * data)
146 memset(Message, 0, 16*2);
147 Message[0]= (opcode<<4) + (size&0xf);
148 if(opcode == H2D_DEBUG_WRITE_DM)
149 Message[1]= (group&0x7f);
151 Message[1]= (((index==0)?0:1)<<7) + (group&0x7f);
154 if((opcode == H2D_CMV_WRITE)||(opcode == H2D_DEBUG_WRITE_DM))
155 memcpy(Message+4, data, size*2);
162 UINT16 CMV_read(char* str_group,int address,int index)
165 if(strcmp(str_group,"optn")==0)
167 else if(strcmp(str_group,"cnfg")==0)
169 else if(strcmp(str_group,"cntl")==0)
171 else if(strcmp(str_group,"stat")==0)
173 else if(strcmp(str_group,"rate")==0)
175 else if(strcmp(str_group,"plam")==0)
177 else if(strcmp(str_group,"info")==0)
179 else if(strcmp(str_group,"test")==0)
183 printf("wrong group type!\ncheck script file please!\n");
188 makeCMV(H2D_CMV_READ, group, address, index, 1, NULL);
189 if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
190 printf("cr read %d %d %d fail",group,address,index);
201 int CMV_write(char* str_group,int address,int index,UINT16 value)
204 if(strcmp(str_group,"optn")==0)
206 else if(strcmp(str_group,"cnfg")==0)
208 else if(strcmp(str_group,"cntl")==0)
210 else if(strcmp(str_group,"stat")==0)
212 else if(strcmp(str_group,"rate")==0)
214 else if(strcmp(str_group,"plam")==0)
216 else if(strcmp(str_group,"info")==0)
218 else if(strcmp(str_group,"test")==0)
222 printf("wrong group type!\ncheck script file please!\n");
227 makeCMV(H2D_CMV_WRITE, group, address, index, 1, &value);
228 if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
229 printf("cw %d %d %d fail",group,address,index);
239 void execute_script()
242 char str_command[20]={0};
243 char str_group[20]={0};
244 char str_value[128]={0};
245 char op1[40],op2[40];
249 if(!script_file) return;
251 while(fgets(buf,128,script_file))/*scan one line into buffer, 128 bytes at most*/
253 if(sscanf(buf,"%s",&str_command)==0) continue;
254 /*if the line is empty, then go on to the next*/
255 if(strcmp(str_command,"cr")==0)/*cr command*/
257 sscanf(buf,"%s %s %d %d %s",&str_command,\
262 if(strncmp(str_value,"$",1)!=0)
264 printf("error:cr parameter type mismatch!\n");
267 n=strtoul(str_value+1,NULL,0);
268 var16[n]=CMV_read(str_group,address,index);
269 printf("read %s %d %d, value=%04x\n",str_group, address, index,var16[n]);
271 else if(strcmp(str_command,"cw")==0)/*cw command*/
273 sscanf(buf,"%s %s %d %d %s",&str_command,\
278 n=strtoul(str_value+1,NULL,0);
279 if(strncmp(str_value,"$",1)==0)
283 else if(strncmp(str_value,"#",1)==0)
285 value=strtoul(str_value+1,NULL,0);
289 value=strtoul(str_value,NULL,0);
291 if(CMV_write(str_group,address,index,value)<0)
297 else if(strcmp(str_command,"mw")==0)/*mr command*/
300 sscanf(buf,"%s %s %s",&str_command,\
304 n=strtoul(str_value+1,NULL,0);
305 address=strtoul(op1,NULL,0);
306 if(strncmp(str_value,"$",1)==0)
310 else if(strncmp(str_value,"#",1)==0)
312 value=strtoul(str_value+1,NULL,0);
316 value=strtoul(str_value,NULL,0);
320 makeCMV(H2D_DEBUG_WRITE_DM, 0x0, address>>16, (address)&(0xffff), 1, &value);
321 if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
322 printf("mw %08x fail",address);
329 else if(strcmp(str_command,"mr")==0)/*mr command*/
332 sscanf(buf,"%s %s %s",&str_command,\
335 address=strtoul(op1,NULL,0);
336 n=strtoul(str_value+1,NULL,0);
337 if(strncmp(str_value,"$",1)!=0)
339 printf("error:mr parameter type mismatch!\n");
342 makeCMV(H2D_DEBUG_READ_DM, 0x0, address>>16, (address)&(0xffff), 1, NULL);
343 if(ioctl(fd, IFXMIPS_MEI_CMV_WINHOST, &Message)<0){
344 printf("mw %08x fail",address);
353 else if(strcmp(str_command,"meiw")==0)/*meiw command*/
356 sscanf(buf,"%s %s %s",&str_command,\
359 regrdwr.iAddress=strtoul(op1,NULL,0)+IFXMIPS_MEI_BASE_ADDR;
362 if(strncmp(op2,"#",1)==0) regrdwr.iData=strtoul(op1+1,NULL,0);
363 else if(strncmp(op2,"$",1)==0) regrdwr.iData=var16[strtoul(op2+1,NULL,0)];
364 else if(strncmp(op2,"@",1)==0) regrdwr.iData=var32[strtoul(op2+1,NULL,0)];
365 else regrdwr.iData=strtoul(op1,NULL,0);
366 //printf("address=%08x\n", regrdwr.iAddress);
367 if(ioctl(fd, IFXMIPS_MEI_CMV_WRITE, ®rdwr)<0){
368 printf("meiw fail\n");
374 else if(strcmp(str_command,"meir")==0)/*meir command*/
377 sscanf(buf,"%s %s %s",&str_command,\
380 regrdwr.iAddress=strtoul(op1,NULL,0)+IFXMIPS_MEI_BASE_ADDR;
381 if(ioctl(fd, IFXMIPS_MEI_CMV_READ, ®rdwr)<0){
382 printf("meir fail\n");
385 if(strncmp(op2,"$",1)==0) var16[strtoul(op2+1,NULL,0)]=regrdwr.iData;
386 else if(strncmp(op2,"@",1)==0) var32[strtoul(op2+1,NULL,0)]=regrdwr.iData;
389 printf("meir grammar error!\n");
396 else if(strcmp(str_command,"lst")==0)/*lst command*/
399 sscanf(buf,"%s %s",&str_command,\
402 if(strncmp(str_value,"$",1)==0)
404 n=strtoul(str_value+1,NULL,0);
405 printf("$%d=0x%04x\n",n,var16[n]);
408 else if(strncmp(str_value,"@",1)==0)
410 n=strtoul(str_value+1,NULL,0);
411 printf("$%d=0x%08x\n",n,var32[n]);
416 printf("lst grammar error!\n");
421 else if(strcmp(str_command,"echo")==0)/*echo command*/
425 else if(strcmp(str_command,"mov")==0)/*mov command*/
427 sscanf(buf,"%s %s %s",&str_command,\
430 if(strncmp(op1,"$",1)==0)
432 if(strncmp(op2,"$",1)==0)
434 var16[strtoul(op1+1,NULL,0)]=var16[strtoul(op2+1,NULL,0)];
436 else if(strncmp(op2,"@",1)==0)
438 var16[strtoul(op1+1,NULL,0)]= var32[strtoul(op2+1,NULL,0)];
441 else if(strncmp(op2,"#",1)==0)
443 var16[strtoul(op1+1,NULL,0)]=strtoul(op2+1,NULL,0);
447 var16[strtoul(op1+1,NULL,0)]=strtoul(op2,NULL,0);
451 else if(strncmp(op1,"@",1)==0)
453 if(strncmp(op2,"$",1)==0)
455 var32[strtoul(op1+1,NULL,0)]=var16[strtoul(op2+1,NULL,0)];
457 else if(strncmp(op2,"@",1)==0)
459 var32[strtoul(op1+1,NULL,0)]= var32[strtoul(op2+1,NULL,0)];
462 else if(strncmp(op2,"#",1)==0)
464 var32[strtoul(op1+1,NULL,0)]=strtoul(op2+1,NULL,0);
469 printf("grammar error!\n");
477 else if(strcmp(str_command,"or")==0)/*or command*/
479 sscanf(buf,"%s %s %s",&str_command,\
482 if(strncmp(op1,"$",1)==0)
484 if(strncmp(op2,"$",1)==0)
486 var16[strtoul(op1+1,NULL,0)]|=var16[strtoul(op2+1,NULL,0)];
488 else if(strncmp(op2,"@",1)==0)
490 var16[strtoul(op1+1,NULL,0)]|= var32[strtoul(op2+1,NULL,0)];
493 else if(strncmp(op2,"#",1)==0)
495 var16[strtoul(op1+1,NULL,0)]|=strtoul(op2+1,NULL,0);
498 else if(strncmp(op1,"@",1)==0)
500 if(strncmp(op2,"$",1)==0)
502 var32[strtoul(op1+1,NULL,0)]|=var16[strtoul(op2+1,NULL,0)];
504 else if(strncmp(op2,"@",1)==0)
506 var32[strtoul(op1+1,NULL,0)]|= var32[strtoul(op2+1,NULL,0)];
509 else if(strncmp(op2,"#",1)==0)
511 var32[strtoul(op1+1,NULL,0)]|=strtoul(op2+1,NULL,0);
516 printf("grammar error!\n");
521 else if(strcmp(str_command,"and")==0)/*and command*/
523 sscanf(buf,"%s %s %s",&str_command,\
526 if(strncmp(op1,"$",1)==0)
528 if(strncmp(op2,"$",1)==0)
530 var16[strtoul(op1+1,NULL,0)]&=var16[strtoul(op2+1,NULL,0)];
532 else if(strncmp(op2,"@",1)==0)
534 var16[strtoul(op1+1,NULL,0)]&= var32[strtoul(op2+1,NULL,0)];
537 else if(strncmp(op2,"#",1)==0)
539 var16[strtoul(op1+1,NULL,0)]&=strtoul(op2+1,NULL,0);
542 else if(strncmp(op1,"@",1)==0)
544 if(strncmp(op2,"$",1)==0)
546 var32[strtoul(op1+1,NULL,0)]&=var16[strtoul(op2+1,NULL,0)];
548 else if(strncmp(op2,"@",1)==0)
550 var32[strtoul(op1+1,NULL,0)]&= var32[strtoul(op2+1,NULL,0)];
553 else if(strncmp(op2,"#",1)==0)
555 var32[strtoul(op1+1,NULL,0)]&=strtoul(op2+1,NULL,0);
560 printf("grammar error!\n");
564 else if(strcmp(str_command,"not")==0)/*not command*/
566 sscanf(buf,"%s %s",&str_command,\
568 if(strncmp(op1,"$",1)==0)
570 var16[strtoul(op1+1,NULL,0)]=~var16[strtoul(op1+1,NULL,0)];
572 else if(strncmp(op1,"@",1)==0)
574 var32[strtoul(op1+1,NULL,0)]=~var32[strtoul(op1+1,NULL,0)];
578 printf("grammar error!\n");
582 else if(strcmp(str_command,"shl")==0)/*shl command*/
584 sscanf(buf,"%s %s %s",&str_command,\
587 if(strncmp(op1,"$",1)==0)
589 if(strncmp(op2,"$",1)==0)
591 var16[strtoul(op1+1,NULL,0)]<<=var16[strtoul(op2+1,NULL,0)];
593 else if(strncmp(op2,"@",1)==0)
595 var16[strtoul(op1+1,NULL,0)]<<= var32[strtoul(op2+1,NULL,0)];
598 else if(strncmp(op2,"#",1)==0)
600 var16[strtoul(op1+1,NULL,0)]<<=strtoul(op2+1,NULL,0);
603 else if(strncmp(op1,"@",1)==0)
605 if(strncmp(op2,"$",1)==0)
607 var32[strtoul(op1+1,NULL,0)]<<=var16[strtoul(op2+1,NULL,0)];
609 else if(strncmp(op2,"@",1)==0)
611 var32[strtoul(op1+1,NULL,0)]<<= var32[strtoul(op2+1,NULL,0)];
614 else if(strncmp(op2,"#",1)==0)
616 var32[strtoul(op1+1,NULL,0)]<<=strtoul(op2+1,NULL,0);
621 printf("grammar error!\n");
626 else if(strcmp(str_command,"shr")==0)/*shr command*/
628 sscanf(buf,"%s %s %s",&str_command,\
631 if(strncmp(op1,"$",1)==0)
633 if(strncmp(op2,"$",1)==0)
635 var16[strtoul(op1+1,NULL,0)]>>=var16[strtoul(op2+1,NULL,0)];
637 else if(strncmp(op2,"@",1)==0)
639 var16[strtoul(op1+1,NULL,0)]>>= var32[strtoul(op2+1,NULL,0)];
642 else if(strncmp(op2,"#",1)==0)
644 var16[strtoul(op1+1,NULL,0)]>>=strtoul(op2+1,NULL,0);
647 else if(strncmp(op1,"@",1)==0)
649 if(strncmp(op2,"$",1)==0)
651 var32[strtoul(op1+1,NULL,0)]>>=var16[strtoul(op2+1,NULL,0)];
653 else if(strncmp(op2,"@",1)==0)
655 var32[strtoul(op1+1,NULL,0)]>>= var32[strtoul(op2+1,NULL,0)];
658 else if(strncmp(op2,"#",1)==0)
660 var32[strtoul(op1+1,NULL,0)]>>=strtoul(op2+1,NULL,0);
665 printf("grammar error!\n");
670 else if(strcmp(str_command,"add")==0)/*add command*/
672 sscanf(buf,"%s %s %s",&str_command,\
675 if(strncmp(op1,"$",1)==0)
677 if(strncmp(op2,"$",1)==0)
679 var16[strtoul(op1+1,NULL,0)]+=var16[strtoul(op2+1,NULL,0)];
681 else if(strncmp(op2,"@",1)==0)
683 var16[strtoul(op1+1,NULL,0)]+= var32[strtoul(op2+1,NULL,0)];
686 else if(strncmp(op2,"#",1)==0)
688 var16[strtoul(op1+1,NULL,0)]+=strtoul(op2+1,NULL,0);
691 else if(strncmp(op1,"@",1)==0)
693 if(strncmp(op2,"$",1)==0)
695 var32[strtoul(op1+1,NULL,0)]+=var16[strtoul(op2+1,NULL,0)];
697 else if(strncmp(op2,"@",1)==0)
699 var32[strtoul(op1+1,NULL,0)]+= var32[strtoul(op2+1,NULL,0)];
702 else if(strncmp(op2,"#",1)==0)
704 var32[strtoul(op1+1,NULL,0)]+=strtoul(op2+1,NULL,0);
709 printf("grammar error!\n");
713 else if(strcmp(str_command,"sub")==0)/*sub command*/
715 sscanf(buf,"%s %s %s",&str_command,\
718 if(strncmp(op1,"$",1)==0)
720 if(strncmp(op2,"$",1)==0)
722 var16[strtoul(op1+1,NULL,0)]-=var16[strtoul(op2+1,NULL,0)];
724 else if(strncmp(op2,"@",1)==0)
726 var16[strtoul(op1+1,NULL,0)]-= var32[strtoul(op2+1,NULL,0)];
729 else if(strncmp(op2,"#",1)==0)
731 var16[strtoul(op1+1,NULL,0)]-=strtoul(op2+1,NULL,0);
734 else if(strncmp(op1,"@",1)==0)
736 if(strncmp(op2,"$",1)==0)
738 var32[strtoul(op1+1,NULL,0)]-=var16[strtoul(op2+1,NULL,0)];
740 else if(strncmp(op2,"@",1)==0)
742 var32[strtoul(op1+1,NULL,0)]-= var32[strtoul(op2+1,NULL,0)];
745 else if(strncmp(op2,"#",1)==0)
747 var32[strtoul(op1+1,NULL,0)]-=strtoul(op2+1,NULL,0);
752 printf("grammar error!\n");
757 memset(str_command,0,20);
763 int main (int argc, char** argv) {
766 fd=open(IFXMIPS_MEI_DEV, O_RDWR);
768 printf("\n\n autoboot open device fail\n");
774 static struct option long_options[] ={
781 c = getopt_long(argc,argv, "hvf:e",
782 long_options, &option_index);
784 //printf("c=%d option_index=%d\n",c,option_index);
789 printf("translate:please specify parameters\n");
790 func=&translate_help;
796 ERROR: translate_help();
805 func=&translate_help;
810 func=&display_version;
824 func=&translate_help;
827 func=&display_version;
830 FILE: if(!optarg) goto ERROR;
831 script_file=fopen((char*)optarg,"r");
832 if(!script_file) perror("fopen");
835 EXECUTE: func=&execute_script;
841 if(script_file) fclose(script_file);