00001
00002
00003
00004 #include <stdlib.h>
00005 #include <flash.h>
00006 #include <myconfig.h>
00007
00008 static unsigned int code_program_sst16[]=
00009 tgt_compile(\
00010 "1:li v0,0xbfc05554;\n" \
00011 "li v1,0xaa\n" \
00012 "sh v1,0x5556(v0);\n" \
00013 "li v1,0x55;\n" \
00014 "sh v1,(v0);\n" \
00015 "li v1,0xa0\n" \
00016 "sh v1,0x5556(v0);\n" \
00017 "lh v0,(a0);\n" \
00018 "sh v0,(a1);\n" \
00019 "2:\n" \
00020 "lh v0,(a1);\n" \
00021 "lh v1,(a1);\n" \
00022 "bne v0,v1,2b;\n" \
00023 "nop;\n" \
00024 "addiu a0,2;\n" \
00025 "addiu a1,2;\n" \
00026 "addiu a2,-2;\n" \
00027 "bnez a2,1b;\n" \
00028 "nop;\n" \
00029 "li ra,0xff200200 ;\n" \
00030 "jr ra ;\n" \
00031 "nop;\n" \
00032 );
00033
00034 static unsigned int code_erase_sst16[]=
00035 tgt_compile(\
00036 "1:mtc0 v0, $31;\n" \
00037 "li v0,0xff200000;\n" \
00038 "sw v1,0x1fc(v0);\n" \
00039 "li v0,0xbfc05554;\n" \
00040 "li v1,0xaa;\n" \
00041 "sh v1,0x5556(v0);\n" \
00042 "li v1,0x55;\n" \
00043 "sh v1,0(v0);\n" \
00044 "li v1,0x80;\n" \
00045 "sh v1,0x5556(v0);\n" \
00046 "li v1,0xaa;\n" \
00047 "sh v1,0x5556(v0);\n" \
00048 "li v1,0x55;\n" \
00049 "sh v1,0(v0);\n" \
00050 "li v1,0x10;\n" \
00051 "sh v1,0x5556(v0);\n" \
00052 "li v0,0xff200000;\n" \
00053 "lw v1,0x1fc(v0);\n" \
00054 "mfc0 v0, $31;\n" \
00055 "b 1b;\n" \
00056 "nop;\n"
00057 );
00058
00059 static unsigned int code_program_sst8[]=
00060 tgt_compile(\
00061 "1:li v0,0xbfc02aaa;\n" \
00062 "li v1,0xaa\n" \
00063 "sb v1,0x2aab(v0);\n" \
00064 "li v1,0x55;\n" \
00065 "sb v1,(v0);\n" \
00066 "li v1,0xa0\n" \
00067 "sb v1,0x2aab(v0);\n" \
00068 "lb v0,(a0);\n" \
00069 "sb v0,(a1);\n" \
00070 "2:\n" \
00071 "lb v0,(a1);\n" \
00072 "lb v1,(a1);\n" \
00073 "bne v0,v1,2b;\n" \
00074 "nop;\n" \
00075 "addiu a0,1;\n" \
00076 "addiu a1,1;\n" \
00077 "addiu a2,-1;\n" \
00078 "bnez a2,1b;\n" \
00079 "nop;\n" \
00080 "li ra,0xff200200 ;\n" \
00081 "jr ra ;\n" \
00082 "nop;\n" \
00083 );
00084
00085 static unsigned int code_erase_sst8[]=
00086 tgt_compile(\
00087 "1:mtc0 v0, $31;\n" \
00088 "li v0,0xff200000;\n" \
00089 "sw v1,0x1fc(v0);\n" \
00090 "li v0,0xbfc02aaa;\n" \
00091 "li v1,0xaa;\n" \
00092 "sb v1,0x2aab(v0);\n" \
00093 "li v1,0x55;\n" \
00094 "sb v1,0(v0);\n" \
00095 "li v1,0x80;\n" \
00096 "sb v1,0x2aab(v0);\n" \
00097 "li v1,0xaa;\n" \
00098 "sb v1,0x2aab(v0);\n" \
00099 "li v1,0x55;\n" \
00100 "sb v1,0(v0);\n" \
00101 "li v1,0x10;\n" \
00102 "sb v1,0x2aab(v0);\n" \
00103 "li v0,0xff200000;\n" \
00104 "lw v1,0x1fc(v0);\n" \
00105 "mfc0 v0, $31;\n" \
00106 "b 1b;\n" \
00107 "nop;\n"
00108 );
00109
00110
00111
00112 static struct flash_function
00113 flash_functions[]
00114 ={
00115 {"sst16",code_program_sst16,sizeof(code_program_sst16),code_erase_sst16},
00116 {"sst8",code_program_sst8,sizeof(code_program_sst8),code_erase_sst8},
00117 {0}
00118 };
00119
00120 struct flash_function *flash_func_head;
00121 struct flash_function *flash_func_tail;
00122 extern struct flash_function begin_flash_func;
00123 extern struct flash_function end_flash_func;
00124
00125 static void init_flash_func(void) __attribute__ ((constructor));
00126 static void init_flash_func(void)
00127 {
00128 int i;
00129 struct flash_function *pflash;
00130 flash_func_head = flash_functions;
00131 flash_func_tail = flash_functions;
00132
00133 for(pflash = flash_functions + 1; pflash->name; pflash++)
00134 {
00135 flash_func_tail->next = pflash;
00136 flash_func_tail = pflash;
00137 }
00138
00139 for(pflash = &begin_flash_func + 1; pflash != &end_flash_func; pflash++)
00140 {
00141 flash_func_tail->next = pflash;
00142 flash_func_tail = pflash;
00143 }
00144
00145 }
00146
00147 char *dupstr (int);
00148
00149
00150
00151
00152 static char * flash_complete (text, state)
00153 const char *text;
00154 int state;
00155 {
00156 static int list_index, len;
00157 char *name;
00158 static struct flash_function *pflash;
00159
00160
00161
00162
00163 if (!state)
00164 {
00165 pflash = flash_func_head;
00166 len = strlen (text);
00167 }
00168
00169
00170
00171
00172
00173
00174 while (pflash && (name = pflash->name))
00175 {
00176 pflash = pflash->next;
00177
00178 if (strncmp (name, text, len) == 0)
00179 return (dupstr(name));
00180 }
00181
00182
00183 return ((char *)NULL);
00184
00185 }
00186
00187
00188 static char *config_flash_type = "sst8";
00189
00190 myconfig_init1("flash.type",config_flash_type,CONFIG_S,"flash type",flash_complete);
00191
00192 int cmd_program(int argc,char **argv)
00193 {
00194 char *type;
00195 struct flash_function *pflash;
00196 int context_reg[dMIPS32_NUM_DEBUG_REGISTERS];
00197 if(!(type=config_flash_type))
00198 goto unfind;
00199 for(pflash=flash_func_head;pflash;pflash=pflash->next)
00200 if(!strcmp(pflash->name,type))break;
00201 if(!pflash)goto unfind;
00202
00203 if(pflash->init) pflash->init(pflash);
00204
00205 context_save(context_reg);
00206
00207 jtag_putmem(pflash->program,help_addr,pflash->program_code_size);
00208
00209 {
00210 unsigned int miro_inst_2[]=
00211 tgt_compile(\
00212 "bal 1f;\n" \
00213 "nop;\n" \
00214 ".space 16 \n" \
00215 "1:\n" \
00216 "lw v0,(ra);\n" \
00217 "lw a0,4(ra);\n" \
00218 "lw a1,8(ra);\n" \
00219 "lw a2,12(ra);\n" \
00220 "jr v0;\n" \
00221 "nop ;\n" \
00222 );
00223 miro_inst_2[2]=help_addr;
00224 miro_inst_2[3]=strtoul(argv[1],0,0);
00225 miro_inst_2[4]=strtoul(argv[2],0,0);
00226 miro_inst_2[5]=strtoul(argv[3],0,0);
00227 fMIPS32_ExecuteDebugModule(miro_inst_2,sizeof(miro_inst_2),1);
00228 }
00229
00230 context_restore(context_reg);
00231
00232
00233 return 0;
00234 unfind:
00235 printf("unfind flash,doest not setevn flash,or unsuppoted flashtype.\nmaybe run setenv flash sst8\n");
00236 return -1;
00237 }
00238
00239 int cmd_erase(int argc,char **argv)
00240 {
00241 char *type;
00242 struct flash_function *pflash;
00243
00244 if(!(type=config_flash_type))
00245 goto unfind;
00246 for(pflash=flash_func_head;pflash;pflash=pflash->next)
00247 if(!strcmp(pflash->name,type))break;
00248 if(!pflash)goto unfind;
00249
00250 if(pflash->init) pflash->init(pflash);
00251 fMIPS32_ExecuteDebugModule(pflash->erase,0x8000,1);
00252 return 0;
00253 unfind:
00254 printf("unfind flash,doest not setevn flash,or unsuppoted flashtype.\nmaybe run setenv flash sst8\n");
00255 return -1;
00256
00257 }
00258
00259 int cmd_erase_area(int argc,char **argv)
00260 {
00261 char *type;
00262 struct flash_function *pflash;
00263 unsigned int start_addr,end_addr,sector_size;
00264
00265 if(argc != 4) return -1;
00266
00267 if(!(type=config_flash_type))
00268 goto unfind;
00269 for(pflash=flash_func_head;pflash;pflash=pflash->next)
00270 if(!strcmp(pflash->name,type))break;
00271 if(!pflash)goto unfind;
00272 if(!pflash->erase_area)goto unsupport;
00273 if(pflash->init) pflash->init(pflash);
00274 start_addr = strtoul(argv[1],0,0);
00275 end_addr = strtoul(argv[2],0,0);
00276 sector_size = strtoul(argv[3],0,0);
00277 ui_datamem[0] = start_addr;
00278 ui_datamem[1] = end_addr;
00279 ui_datamem[2] = sector_size;
00280 fMIPS32_ExecuteDebugModule(pflash->erase_area,0x8000,1);
00281 return 0;
00282 unfind:
00283 printf("unfind flash,doest not setevn flash,or unsuppoted flashtype.\nmaybe run setenv flash sst8\n");
00284 return -1;
00285 unsupport:
00286 printf("unsupport erase flash area\n");
00287 return -2;
00288 }
00289
00290 mycmd_init(program,cmd_program,"program ramaddr flashaddr size ","program address,\tenv: flash");
00291 mycmd_init(erase,cmd_erase,"erase","erase whole chip,\tenv: flash");
00292 mycmd_init(erase_area,cmd_erase_area,"erase_area start end sectorsize","erase sectors,\tenv: flash");
00293