OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [orp/] [orp_soc/] [sw/] [utils/] [bin2srec.c] - Diff between revs 1268 and 1289

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 1268 Rev 1289
Line 1... Line 1...
#include <stdio.h>
#include <stdio.h>
 
#include <stdlib.h>
 
 
#define SMARK "S214"
#define SMARK "S214"
#define SADDR 0x000000
#define SADDR 0x000000
#define INIT_ADDR 0x100100
#define INIT_ADDR 0x100100
#define SCHKSUM 0xff
#define SCHKSUM 0xff
 
 
int main(int argc, char **argv)
int main(int argc, char **argv)
{
{
 
 
        FILE  *fd;
        FILE  *fd;
        int c, i, j;
        int c, j;
        unsigned long addr = INIT_ADDR;
        unsigned long addr = INIT_ADDR;
        unsigned char chksum;
        unsigned char chksum;
 
 
        if(argc < 2)
        if(argc < 2) {
                error("no input file specified");
                fprintf(stderr,"no input file specified\n");
 
                exit(1);
 
        }
 
        if(argc > 2) {
 
                fprintf(stderr,"too many input files (more than one) specified\n");
 
                exit(1);
 
        }
 
 
        fd = fopen( argv[1], "r" );
        fd = fopen( argv[1], "r" );
 
        if (fd == NULL) {
 
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
 
                exit(1);
 
        }
 
 
        while (!feof(fd)) {
        while (!feof(fd)) {
                j = 0;
                j = 0;
                chksum = SCHKSUM;
                chksum = SCHKSUM;
                printf("%s%.6lx", SMARK, addr);
                printf("%s%.6lx", SMARK, addr);
                while (j < 16) {
                while (j < 16) {
                        c = fgetc(fd);
                        c = fgetc(fd);
                        if (c == EOF) {
                        if (c == EOF) {
                                c = 0;
                                c = 0;
                        }
                        }
                        printf("%.2lx", c);
                        printf("%.2x", c);
                        chksum -= c;
                        chksum -= c;
                        j++;
                        j++;
                }
                }
 
 
                chksum -= addr & 0xff;
                chksum -= addr & 0xff;
                chksum -= (addr >> 8) & 0xff;
                chksum -= (addr >> 8) & 0xff;
                chksum -= (addr >> 16) & 0xff;
                chksum -= (addr >> 16) & 0xff;
                chksum -= 0x14;
                chksum -= 0x14;
                printf("%.2lx\r\n", chksum);
                printf("%.2x\r\n", chksum);
                addr += 16;
                addr += 16;
        }
        }
        return 0;
        return 0;
}
}
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.