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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [orpsocv2/] [sw/] [utils/] [bin2srec.c] - Blame information for rev 522

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 julius
/*$$HEADER*/
2
/******************************************************************************/
3
/*                                                                            */
4
/*                    H E A D E R   I N F O R M A T I O N                     */
5
/*                                                                            */
6
/******************************************************************************/
7
 
8
// Project Name                   : ORPSoC v2
9
// File Name                      : bin2srec.c
10
// Prepared By                    : 
11
// Project Start                  : 
12
 
13
/*$$COPYRIGHT NOTICE*/
14
/******************************************************************************/
15
/*                                                                            */
16
/*                      C O P Y R I G H T   N O T I C E                       */
17
/*                                                                            */
18
/******************************************************************************/
19
/*
20
  This library is free software; you can redistribute it and/or
21
  modify it under the terms of the GNU Lesser General Public
22
  License as published by the Free Software Foundation;
23
  version 2.1 of the License, a copy of which is available from
24
  http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt.
25
 
26
  This library is distributed in the hope that it will be useful,
27
  but WITHOUT ANY WARRANTY; without even the implied warranty of
28
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29
  Lesser General Public License for more details.
30
 
31
  You should have received a copy of the GNU Lesser General Public
32
  License along with this library; if not, write to the Free Software
33
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
34
*/
35
 
36
/*$$DESCRIPTION*/
37
/******************************************************************************/
38
/*                                                                            */
39
/*                           D E S C R I P T I O N                            */
40
/*                                                                            */
41
/******************************************************************************/
42
//
43
// Generates SREC file output to stdout from binary file
44
//
45
 
46
#include <stdio.h>
47
#include <stdlib.h>
48
 
49
#define SMARK "S214"
50
#define SADDR 0x000000
51
#define INIT_ADDR 0x100100
52
#define SCHKSUM 0xff
53
 
54
int main(int argc, char **argv)
55
{
56
 
57
        FILE  *fd;
58
        int c, j;
59
        unsigned long addr = INIT_ADDR;
60
        unsigned char chksum;
61
 
62
        if(argc < 2) {
63
                fprintf(stderr,"no input file specified\n");
64
                exit(1);
65
        }
66
        if(argc > 2) {
67
                fprintf(stderr,"too many input files (more than one) specified\n");
68
                exit(1);
69
        }
70
 
71
        fd = fopen( argv[1], "r" );
72
        if (fd == NULL) {
73
                fprintf(stderr,"failed to open input file: %s\n",argv[1]);
74
                exit(1);
75
        }
76
 
77
        while (!feof(fd)) {
78
                j = 0;
79
                chksum = SCHKSUM;
80
                printf("%s%.6lx", SMARK, addr);
81
                while (j < 16) {
82
                        c = fgetc(fd);
83
                        if (c == EOF) {
84
                                c = 0;
85
                        }
86
                        printf("%.2x", c);
87
                        chksum -= c;
88
                        j++;
89
                }
90
 
91
                chksum -= addr & 0xff;
92
                chksum -= (addr >> 8) & 0xff;
93
                chksum -= (addr >> 16) & 0xff;
94
                chksum -= 0x14;
95
                printf("%.2x\r\n", chksum);
96
                addr += 16;
97
        }
98
        return 0;
99
}

powered by: WebSVN 2.1.0

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