每次DDR校验后,要手动修改flash_header.S,好麻烦,所以写了个C程序自动转换,下面是代码,不足之处请指教。
编译:gcc -o ddr_convert main.c
使用:./ddr_convert Elmo.inc
#include
#include
#include
#include
#include
#define FILENAME "Elmo.inc"
int main(int argc,char *argv[])
{
FILE *fp;
char StrLine[1024];
char *ptr;
char reg[11],val[11];
unsigned char item=1;
unsigned int len;
char *file_name=FILENAME;
if(argc>1)
file_name=argv[1];
printf("inc file:%s
",file_name);
if(access(file_name,R_OK)!=0){
printf("file /'%s/' can't be read!
",file_name);
return -1;
}
if((fp = fopen(file_name,"r")) == NULL){
printf("open file /'%s/' error!
",file_name);
return -2;
}
while( fgets(StrLine,1024,fp)){
//printf("%s
", StrLine);
if(0!=strncmp("//", StrLine,2)){
//printf("%s", StrLine);
if(0==strncmp("setmem /32", StrLine,10)){
//printf("%s", StrLine);
ptr = strstr(StrLine, "0x");
strncpy(reg,ptr,10);reg[10]=0;
//printf(" %s", reg);
ptr = strstr(ptr+1, "0x");
strncpy(val,ptr,10);val[10]=0;
//printf(" %s
", val);
if(0==strncmp(reg,"0x020e0" ,7)){
printf("MXC_DCD_ITEM(%d,IOMUXC_BASE_ADDR + 0x%s,%s)
",item++,®[7],val);
}
else if(0==strncmp(reg,"0x021b0" ,7)){
printf("MXC_DCD_ITEM(%d,MMDC_P0_BASE_ADDR + 0x%s,%s)
",item++,®[7],val);
}
else if(0==strncmp(reg,"0x021b4" ,7)){
printf("MXC_DCD_ITEM(%d,MMDC_P1_BASE_ADDR + 0x%s,%s)
",item++,®[7],val);
}else{
printf("get a wrong item...
");
}
}
}
}
item--;
len=item*8+4+4;
//printf("len=0x%x
",len);
len=(len>>8)|((len&0xff)<<8);
printf("0x%x ",len);
len=item*8+4;
//printf("len=0x%x
",len);
len=(len>>8)|((len&0xff)<<8);
printf("0x%x
",len);
fclose(fp);
return 0;
}