00001 #include <stdio.h>
00002 #include <stdlib.h>
00003
00004 #define CONST_START_ADRESS 0x2500
00005 #define CODE_START_ADRESS 0x2590
00006 #define TAILLE_MEMOIRE_CONST (CODE_START_ADRESS-CONST_START_ADRESS)
00007 #define INPUT_PATH "./bootloader_ascii.txt"
00008 #define OUTPUT_PATH "./bootloader_raw.txt"
00009
00010 char convert(char c){
00011
00012 if (c >=48 && c <= 57)
00013 return (c-48);
00014 else return (c-55);
00015
00016 }
00017
00018 int main (void){
00019
00020 FILE *fich_in,*fich_out;
00021 int cpt_octet=0,i,retour;
00022 char start_const[]="@2500";
00023 char start_boot[]="@2590";
00024 char IT_timer[]="@FFFA";
00025 char value0,value1,result;
00026 char chaine[16],lsb[3],msb[3];
00027
00028 printf("-----Welcome to \"Convert bootloader file\" (CAIRN 2009)-----\n\n");
00029 printf("This software convert output file from bootloader node\ncompilation to a node's loadable file.\n\n");
00030
00031 printf("input file : \"");
00032 printf(INPUT_PATH);
00033 printf("\"\n");
00034
00035 printf("output file : \"");
00036 printf(OUTPUT_PATH);
00037 printf("\"\n\n");
00038
00039 fich_in = fopen(INPUT_PATH,"r");
00040 fich_out = fopen(OUTPUT_PATH,"w");
00041
00042 if( fich_in != 0 && fich_out != 0 ){
00043
00044
00045 do{
00046 retour = fscanf(fich_in,"%s",chaine);
00047
00048 }while( retour != EOF && strcmp(chaine,start_const) != 0 );
00049
00050
00051 if(retour != EOF && strcmp(chaine,start_const) == 0){
00052
00053 while( fscanf(fich_in, "%s",chaine) == 1 && strcmp(chaine,start_boot) != 0){
00054
00055 value0 = convert(chaine[0]);
00056 value1 = convert(chaine[1]);
00057 result = (value0 << 4) | value1;
00058 fprintf(fich_out,"%c",result);
00059 cpt_octet++;
00060 }
00061
00062 result = 0xFF;
00063 for (i=0;i<TAILLE_MEMOIRE_CONST-cpt_octet;i++)
00064 fprintf(fich_out,"%c",result);
00065
00066 while( fscanf(fich_in, "%s",chaine) == 1 && chaine[0] != '@'){
00067
00068 value0 = convert(chaine[0]);
00069 value1 = convert(chaine[1]);
00070 result = (value0 << 4) | value1;
00071 fprintf(fich_out,"%c",result);
00072
00073 }
00074
00075 retour = 1;
00076
00077 while( retour == 1 && strcmp(chaine,IT_timer) != 0){
00078 fscanf(fich_in, "%s",chaine);
00079 printf("passe ici\n");
00080 }
00081
00082 fscanf(fich_in, "%s",lsb);
00083 fscanf(fich_in, "%s",msb);
00084 printf("adresse IT TIMER : 0x%s%s (a reporter dans reprogrammation.h)\n\n",msb,lsb);
00085
00086 fclose(fich_in);
00087 fclose(fich_out);
00088 return(0);
00089 }
00090 else {
00091 printf("error : wrong input file\n");
00092 return(-1);
00093 }
00094 }
00095 else{
00096
00097 printf("error : no input file (bootloader_ascii.txt)\n");
00098 return(-1);
00099
00100 }
00101 }
00102