xref: /openbmc/u-boot/include/s_record.h (revision 4a5b6a35)
1*4a5b6a35Swdenk /*
2*4a5b6a35Swdenk  * (C) Copyright 2000
3*4a5b6a35Swdenk  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4*4a5b6a35Swdenk  *
5*4a5b6a35Swdenk  * See file CREDITS for list of people who contributed to this
6*4a5b6a35Swdenk  * project.
7*4a5b6a35Swdenk  *
8*4a5b6a35Swdenk  * This program is free software; you can redistribute it and/or
9*4a5b6a35Swdenk  * modify it under the terms of the GNU General Public License as
10*4a5b6a35Swdenk  * published by the Free Software Foundation; either version 2 of
11*4a5b6a35Swdenk  * the License, or (at your option) any later version.
12*4a5b6a35Swdenk  *
13*4a5b6a35Swdenk  * This program is distributed in the hope that it will be useful,
14*4a5b6a35Swdenk  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15*4a5b6a35Swdenk  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16*4a5b6a35Swdenk  * GNU General Public License for more details.
17*4a5b6a35Swdenk  *
18*4a5b6a35Swdenk  * You should have received a copy of the GNU General Public License
19*4a5b6a35Swdenk  * along with this program; if not, write to the Free Software
20*4a5b6a35Swdenk  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21*4a5b6a35Swdenk  * MA 02111-1307 USA
22*4a5b6a35Swdenk  */
23*4a5b6a35Swdenk 
24*4a5b6a35Swdenk /*--------------------------------------------------------------------------
25*4a5b6a35Swdenk  *
26*4a5b6a35Swdenk  * Motorola S-Record Format:
27*4a5b6a35Swdenk  *
28*4a5b6a35Swdenk  * Motorola S-Records are an industry-standard format for
29*4a5b6a35Swdenk  * transmitting binary files to target systems and PROM
30*4a5b6a35Swdenk  * programmers. LSI Logic have extended this standard to include
31*4a5b6a35Swdenk  * an S4-record containing an address and a symbol.
32*4a5b6a35Swdenk  *
33*4a5b6a35Swdenk  * The extended S-record standard is as follows:
34*4a5b6a35Swdenk  *
35*4a5b6a35Swdenk  * S<type><length><address><data....><checksum>
36*4a5b6a35Swdenk  * S4<length><address><name>,<checksum>
37*4a5b6a35Swdenk  *
38*4a5b6a35Swdenk  * Where:
39*4a5b6a35Swdenk  *
40*4a5b6a35Swdenk  * type
41*4a5b6a35Swdenk  *     is the record type. Where:
42*4a5b6a35Swdenk  *
43*4a5b6a35Swdenk  *     0  starting record (optional)
44*4a5b6a35Swdenk  *     1  data record with 16-bit address
45*4a5b6a35Swdenk  *     2  data record with 24-bit address
46*4a5b6a35Swdenk  *     3  data record with 32-bit address
47*4a5b6a35Swdenk  *     4  symbol record (LSI extension)
48*4a5b6a35Swdenk  *     5  number of data records in preceeding block
49*4a5b6a35Swdenk  *     6  unused
50*4a5b6a35Swdenk  *     7  ending record for S3 records
51*4a5b6a35Swdenk  *     8  ending record for S2 records
52*4a5b6a35Swdenk  *     9  ending record for S1 records
53*4a5b6a35Swdenk  *
54*4a5b6a35Swdenk  * length
55*4a5b6a35Swdenk  *     is two hex characters. This defines the length of the
56*4a5b6a35Swdenk  *     record in bytes (not characters). It includes the address
57*4a5b6a35Swdenk  *     field, the data field, and the checksum field.
58*4a5b6a35Swdenk  *
59*4a5b6a35Swdenk  * address
60*4a5b6a35Swdenk  *     is 4, 6, or 8 characters. Corresponding to a 16-, 24-, or
61*4a5b6a35Swdenk  *     32-bit address. The address field for S4 records is
62*4a5b6a35Swdenk  *     always 32 bits.
63*4a5b6a35Swdenk  *
64*4a5b6a35Swdenk  * data
65*4a5b6a35Swdenk  *
66*4a5b6a35Swdenk  *     Are the data bytes. Each pair of hex characters represent
67*4a5b6a35Swdenk  *     one byte in memory.
68*4a5b6a35Swdenk  *
69*4a5b6a35Swdenk  * name
70*4a5b6a35Swdenk  *     Is the symbol name. The symbol is terminated by a ','.
71*4a5b6a35Swdenk  *
72*4a5b6a35Swdenk  * checksum
73*4a5b6a35Swdenk  *     Is the one's complement of the 8-bit checksum.
74*4a5b6a35Swdenk  *
75*4a5b6a35Swdenk  * Example
76*4a5b6a35Swdenk  *
77*4a5b6a35Swdenk  * S0030000FC
78*4a5b6a35Swdenk  * .
79*4a5b6a35Swdenk  * .
80*4a5b6a35Swdenk  * S325000004403C0880018D08DD900000000011000026000000003C0880012508DC50C50000B401
81*4a5b6a35Swdenk  * S32500000460C50100B8C50200BCC50300C0C50400C4C50500C8C50600CCC50700D0C50800D4FA
82*4a5b6a35Swdenk  * S32500000480C50900D8C50A00DCC50B00E0C50C00E4C50D00E8C50E00ECC50F00F0C51000F49A
83*4a5b6a35Swdenk  * S325000004A0C51100F8C51200FCC5130100C5140104C5150108C516010CC5170110C518011434
84*4a5b6a35Swdenk  * .
85*4a5b6a35Swdenk  * .
86*4a5b6a35Swdenk  * S70500000000FA
87*4a5b6a35Swdenk  *
88*4a5b6a35Swdenk  * The S0 record starts the file. The S3 records contain the
89*4a5b6a35Swdenk  * data. The S7 record contains the entry address and terminates
90*4a5b6a35Swdenk  * the download.
91*4a5b6a35Swdenk  *
92*4a5b6a35Swdenk  *--------------------------------------------------------------------------
93*4a5b6a35Swdenk  */
94*4a5b6a35Swdenk 
95*4a5b6a35Swdenk #define SREC_START	0	/* Start Record (module name)		    */
96*4a5b6a35Swdenk #define SREC_DATA2	1	/* Data  Record with 2 byte address	    */
97*4a5b6a35Swdenk #define SREC_DATA3	2	/* Data  Record with 3 byte address	    */
98*4a5b6a35Swdenk #define SREC_DATA4	3	/* Data  Record with 4 byte address	    */
99*4a5b6a35Swdenk #define SREC_COUNT	5	/* Count Record (previously transmitted)    */
100*4a5b6a35Swdenk #define SREC_END4 	7	/* End   Record with 4 byte start address   */
101*4a5b6a35Swdenk #define SREC_END3 	8	/* End   Record with 3 byte start address   */
102*4a5b6a35Swdenk #define SREC_END2 	9	/* End   Record with 2 byte start address   */
103*4a5b6a35Swdenk #define SREC_EMPTY	10	/* Empty Record without any data	    */
104*4a5b6a35Swdenk 
105*4a5b6a35Swdenk #define SREC_REC_OK  SREC_EMPTY /* last code without error condition	    */
106*4a5b6a35Swdenk 
107*4a5b6a35Swdenk #define SREC_E_BADTYPE	-1	/* no valid S-Record		            */
108*4a5b6a35Swdenk #define SREC_E_NOSREC	-2	/* line format differs from s-record	    */
109*4a5b6a35Swdenk #define SREC_E_BADCHKS	-3	/* checksum error in an s-record line	    */
110*4a5b6a35Swdenk 
111*4a5b6a35Swdenk #define SREC_MAXRECLEN	(512 + 4)   /* max ASCII record length		    */
112*4a5b6a35Swdenk #define SREC_MAXBINLEN	255	    /* resulting binary length		    */
113*4a5b6a35Swdenk 
114*4a5b6a35Swdenk int srec_decode (char *input, int *count, ulong *addr, char *data);
115