00001
00002
00003
00004
00005 int cmd_fput(int argc,char **argv)
00006 {
00007 unsigned long download_addr;
00008 struct stat statbuf;
00009 unsigned int size;
00010 unsigned int checksum,i;
00011 char *buf;
00012 int fd;
00013 int context_reg[dMIPS32_NUM_DEBUG_REGISTERS];
00014 if(stat(argv[1],&statbuf)!=0)
00015 {
00016 printf("error read file %s\n",argv[1]);
00017 exit(-1);
00018 }
00019 printf("open file %s,size %d\n",argv[1],statbuf.st_size);
00020 size = (statbuf.st_size + 3) & ~3;
00021 buf=malloc(size);
00022 if(!buf)printf("error allocate memory\n");
00023 fd=open(argv[1],O_RDONLY);
00024 read(fd,(buf),statbuf.st_size);
00025 close(fd);
00026 download_addr=strtoul(argv[2],0,0);
00027 context_save(context_reg);
00028
00029
00030 {
00031 unsigned int code_inst_download[]=
00032 tgt_compile(\
00033 "li v0,0xff20fe04;\n" \
00034 "move a3,a2;\n" \
00035 "1:lw v1,0(v0);\n" \
00036 "subu a2,v1;\n" \
00037 "sw v1,0(a0);\n" \
00038 "lw v1,0(a0);\n" \
00039 "subu a3,v1;\n" \
00040 "addiu a1,-4;\n" \
00041 "bnez a1,1b;\n" \
00042 "addiu a0,a0,4;\n" \
00043 "nop\n" \
00044 "nop\n" \
00045 "nop\n" \
00046 "li ra,0xff200200 ;\n" \
00047 "jr ra ;\n" \
00048 "nop;\n" \
00049 );
00050
00051
00052 jtag_putmem(code_inst_download,help_addr,sizeof(code_inst_download));
00053 }
00054
00055 for(i=0,checksum=0;i<((statbuf.st_size+3)&~3);i+=4)
00056 {
00057 checksum += *(unsigned int *)(buf+i);
00058 }
00059 printf("checksum should be %x\n",checksum);
00060
00061 {
00062 unsigned int miro_inst_2[]=
00063 tgt_compile(\
00064 "bal 1f;\n" \
00065 "nop;\n" \
00066 "param:\n" \
00067 ".space 16 \n" \
00068 "1:\n" \
00069 "lw v0,(ra);\n" \
00070 "lw a0,4(ra);\n" \
00071 "lw a1,8(ra);\n" \
00072 "lw a2,12(ra);\n" \
00073 "jr v0;\n" \
00074 "nop ;\n" \
00075 );
00076 miro_inst_2[2]=help_addr;
00077 miro_inst_2[3]=download_addr;
00078 miro_inst_2[4]=size;
00079 miro_inst_2[5]=checksum;
00080 fMIPS32_ExecuteDebugModule(miro_inst_2,sizeof(miro_inst_2),1);
00081 }
00082
00083 wait_address(0xff20fe04,0,1);
00084 fMIPS32_Transfer(buf,size);
00085 wait_address(0xff200200,0,1);
00086
00087 ui_datamem[0]=-1;
00088 ui_datamem[1]=-1;
00089 tgt_exec(\
00090 "1:lui v0,0xff20;\n" \
00091 "sw a2,0(v0);sw a3,4(v0);nop;\n" ,16);
00092 printf("transfer checksum %s\n",ui_datamem[0]?"error":"ok");
00093 printf("mem checksum %s\n",ui_datamem[1]?"error":"ok");
00094
00095 context_restore(context_reg);
00096
00097
00098 free(buf);
00099
00100 return 0;
00101 }
00102
00103 int cmd_fputflash(int argc,char **argv)
00104 {
00105 unsigned long download_addr;
00106 struct stat statbuf;
00107 unsigned int size;
00108 char *buf;
00109 int fd;
00110 int context_reg[dMIPS32_NUM_DEBUG_REGISTERS];
00111 if(stat(argv[1],&statbuf)!=0)
00112 {
00113 printf("error read file %s\n",argv[1]);
00114 exit(-1);
00115 }
00116 printf("open file %s,size %d\n",argv[1],statbuf.st_size);
00117 size = (statbuf.st_size + 3) & ~3;
00118 buf=malloc(size);
00119 if(!buf)printf("error allocate memory\n");
00120 fd=open(argv[1],O_RDONLY);
00121 read(fd,(buf),statbuf.st_size);
00122 close(fd);
00123 download_addr=strtoul(argv[2],0,0);
00124
00125 context_save(context_reg);
00126
00127
00128 {
00129 unsigned int code_inst_download[]=
00130 tgt_compile(\
00131 "li t0,0xff20fe04;\n" \
00132 "1:\n" \
00133 "lw t1,(t0);\n" \
00134 "li t2,1;\n" \
00135 "2:\n" \
00136 "li v0,0xbfc05554;\n" \
00137 "li v1,0xaa\n" \
00138 "sh v1,0x5556(v0);\n" \
00139 "li v1,0x55;\n" \
00140 "sh v1,(v0);\n" \
00141 "li v1,0xa0\n" \
00142 "sh v1,0x5556(v0);\n" \
00143 "sh t1,(a0);\n" \
00144 "3:\n" \
00145 "lh v0,(a0);\n" \
00146 "lh v1,(a0);\n" \
00147 "bne v0,v1,3b;\n" \
00148 "nop;\n" \
00149 "srl t1,16;\n" \
00150 "addiu a0,2;\n" \
00151 "bnez t2,2b;\n" \
00152 "addiu t2,-1;\n" \
00153 "addiu a1,-4;\n" \
00154 "bnez a1,1b;\n" \
00155 "nop;\n" \
00156 "nop;\n" \
00157 "nop;\n" \
00158 "li ra,0xff200200 ;\n" \
00159 "jr ra ;\n" \
00160 "nop;\n" \
00161 );
00162
00163
00164 jtag_putmem(code_inst_download,help_addr,sizeof(code_inst_download));
00165
00166 }
00167
00168
00169 {
00170 unsigned int miro_inst_2[]=
00171 tgt_compile(\
00172 "bal 1f;\n" \
00173 "nop;\n" \
00174 "param:\n" \
00175 ".space 12 \n" \
00176 "1:\n" \
00177 "lw v0,(ra);\n" \
00178 "lw a0,4(ra);\n" \
00179 "lw a1,8(ra);\n" \
00180 "jr v0;\n" \
00181 "nop ;\n" \
00182 );
00183 miro_inst_2[2]=help_addr;
00184 miro_inst_2[3]=download_addr;
00185 miro_inst_2[4]=size;
00186 fMIPS32_ExecuteDebugModule(miro_inst_2,0x8000,3);
00187 }
00188
00189 wait_address(0xff20fe04,0,1);
00190 fMIPS32_Transfer(buf,size);
00191 wait_address(0xff200200,0,1);
00192
00193 context_restore(context_reg);
00194
00195 free(buf);
00196
00197
00198 return 0;
00199 }
00200 mycmd_init(fput,cmd_fput,"fput","fput filename address");
00201 mycmd_init(fputflash,cmd_fputflash,"fputflash","fputflash filename address");