tools/firmware-utils/src/srec2bin.c
//=============================================================================
//       MAIN LOGIC, READS IN LINE AND OUTPUTS BINARY
//=============================================================================
MAIN LOGIC, READS IN LINE AND OUTPUTS BINARY
MAIN LOGIC READS IN LINE AND OUTPUTS BINARY
int srec2bin(int argc,char *argv[],int verbose)
{
    int i,rlen,sts;
    FILE *fp;
    char ac;
    char buff[256];
    bit32u TAG_BIG     = 0xDEADBE42;
    bit32u TAG_LITTLE  = 0xFEEDFA42;
    bit32u Tag;
    if(argc < 3)
    {
      printf("\nError: <srec2bin <srec input file> <bin output file>\n\n");
      return(0);
    }
    if (argc > 3) BigEndian=TRUE; else BigEndian=FALSE;
    if (BigEndian)
        Tag = TAG_BIG;
    else
        Tag = TAG_LITTLE;
    if (verbose)
       printf("\nEndian: %s, Tag is 0x%8X\n",(BigEndian)?"BIG":"LITTLE", Tag);
    fp = fopen(argv[1],"rt");
    if (fp==NULL)
    {
      printf("\nError: Opening input file, %s.", argv[1]);
      return(0);
    }
    fOut = fopen( argv[2], "wb");
    if (fOut==NULL)
    {
      printf("\nError: Opening Output file, %s.", argv[2]);
      if(fp) fclose(fp);
      return(0);
    }
    RecStart = FALSE;
    AddressCurrent = 0xFFFFFFFFL;
    dumpfTell("Tag", Tag);
    binOut32(Tag);
    inputline=0;
    sts=TRUE;
    rlen = readline(fp,buff,sizeof buff);
    while( (sts) && (rlen != -1))
    {
        if (strlen(buff))
        {
            sts &= srecLine(buff);
            WaitDisplay();
        }
       rlen = readline(fp,buff,sizeof buff);
    }
    binRecEnd();
    if(fp) fclose(fp);
    if(fOut) fclose(fOut);
    return(1);
}
int srec2bin ( int argc , char * argv [ ] , int verbose ) { int i , rlen , sts ; FILE * fp ; char ac ; char buff [ 256 ] ; bit32u TAG_BIG = 0xDEADBE42 ; bit32u TAG_LITTLE = 0xFEEDFA42 ; bit32u Tag ; if ( argc < 3 ) { printf ( " \n \n \n " ) ; return ( 0 ) ; } if ( argc > 3 ) BigEndian = TRUE ; else BigEndian = FALSE ; if ( BigEndian ) Tag = TAG_BIG ; else Tag = TAG_LITTLE ; if ( verbose ) printf ( " \n \n " , ( BigEndian ) ? " " : " " , Tag ) ; fp = fopen ( argv [ 1 ] , " " ) ; if ( fp == NULL ) { printf ( " \n " , argv [ 1 ] ) ; return ( 0 ) ; } fOut = fopen ( argv [ 2 ] , " " ) ; if ( fOut == NULL ) { printf ( " \n " , argv [ 2 ] ) ; if ( fp ) fclose ( fp ) ; return ( 0 ) ; } RecStart = FALSE ; AddressCurrent = 0xFFFFFFFFL ; dumpfTell ( " " , Tag ) ; binOut32 ( Tag ) ; inputline = 0 ; sts = TRUE ; rlen = readline ( fp , buff , sizeof buff ) ; while ( ( sts ) && ( rlen != -1 ) ) { if ( strlen ( buff ) ) { sts &= srecLine ( buff ) ; WaitDisplay ( ) ; } rlen = readline ( fp , buff , sizeof buff ) ; } binRecEnd ( ) ; if ( fp ) fclose ( fp ) ; if ( fOut ) fclose ( fOut ) ; return ( 1 ) ; }
MAIN LOGIC, READS IN LINE AND OUTPUTS BINARY
MAIN LOGIC READS IN LINE AND OUTPUTS BINARY
// Setup Tag  //  printf("PC: 0x%08X, Length 0x%08X, Tag 0x%08X\n", ProgramStart, RecLength, TAG_LITTLE);