xref: /OK3568_Linux_fs/u-boot/include/s_record.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright 2000
3*4882a593Smuzhiyun  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * SPDX-License-Identifier:	GPL-2.0+
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun /*--------------------------------------------------------------------------
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Motorola S-Record Format:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * Motorola S-Records are an industry-standard format for
13*4882a593Smuzhiyun  * transmitting binary files to target systems and PROM
14*4882a593Smuzhiyun  * programmers. LSI Logic have extended this standard to include
15*4882a593Smuzhiyun  * an S4-record containing an address and a symbol.
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  * The extended S-record standard is as follows:
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * S<type><length><address><data....><checksum>
20*4882a593Smuzhiyun  * S4<length><address><name>,<checksum>
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * Where:
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * type
25*4882a593Smuzhiyun  *     is the record type. Where:
26*4882a593Smuzhiyun  *
27*4882a593Smuzhiyun  *     0  starting record (optional)
28*4882a593Smuzhiyun  *     1  data record with 16-bit address
29*4882a593Smuzhiyun  *     2  data record with 24-bit address
30*4882a593Smuzhiyun  *     3  data record with 32-bit address
31*4882a593Smuzhiyun  *     4  symbol record (LSI extension)
32*4882a593Smuzhiyun  *     5  number of data records in preceding block
33*4882a593Smuzhiyun  *     6  unused
34*4882a593Smuzhiyun  *     7  ending record for S3 records
35*4882a593Smuzhiyun  *     8  ending record for S2 records
36*4882a593Smuzhiyun  *     9  ending record for S1 records
37*4882a593Smuzhiyun  *
38*4882a593Smuzhiyun  * length
39*4882a593Smuzhiyun  *     is two hex characters. This defines the length of the
40*4882a593Smuzhiyun  *     record in bytes (not characters). It includes the address
41*4882a593Smuzhiyun  *     field, the data field, and the checksum field.
42*4882a593Smuzhiyun  *
43*4882a593Smuzhiyun  * address
44*4882a593Smuzhiyun  *     is 4, 6, or 8 characters. Corresponding to a 16-, 24-, or
45*4882a593Smuzhiyun  *     32-bit address. The address field for S4 records is
46*4882a593Smuzhiyun  *     always 32 bits.
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  * data
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  *     Are the data bytes. Each pair of hex characters represent
51*4882a593Smuzhiyun  *     one byte in memory.
52*4882a593Smuzhiyun  *
53*4882a593Smuzhiyun  * name
54*4882a593Smuzhiyun  *     Is the symbol name. The symbol is terminated by a ','.
55*4882a593Smuzhiyun  *
56*4882a593Smuzhiyun  * checksum
57*4882a593Smuzhiyun  *     Is the one's complement of the 8-bit checksum.
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  * Example
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  * S0030000FC
62*4882a593Smuzhiyun  * .
63*4882a593Smuzhiyun  * .
64*4882a593Smuzhiyun  * S325000004403C0880018D08DD900000000011000026000000003C0880012508DC50C50000B401
65*4882a593Smuzhiyun  * S32500000460C50100B8C50200BCC50300C0C50400C4C50500C8C50600CCC50700D0C50800D4FA
66*4882a593Smuzhiyun  * S32500000480C50900D8C50A00DCC50B00E0C50C00E4C50D00E8C50E00ECC50F00F0C51000F49A
67*4882a593Smuzhiyun  * S325000004A0C51100F8C51200FCC5130100C5140104C5150108C516010CC5170110C518011434
68*4882a593Smuzhiyun  * .
69*4882a593Smuzhiyun  * .
70*4882a593Smuzhiyun  * S70500000000FA
71*4882a593Smuzhiyun  *
72*4882a593Smuzhiyun  * The S0 record starts the file. The S3 records contain the
73*4882a593Smuzhiyun  * data. The S7 record contains the entry address and terminates
74*4882a593Smuzhiyun  * the download.
75*4882a593Smuzhiyun  *
76*4882a593Smuzhiyun  *--------------------------------------------------------------------------
77*4882a593Smuzhiyun  */
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun #define SREC_START	0	/* Start Record (module name)		    */
80*4882a593Smuzhiyun #define SREC_DATA2	1	/* Data  Record with 2 byte address	    */
81*4882a593Smuzhiyun #define SREC_DATA3	2	/* Data  Record with 3 byte address	    */
82*4882a593Smuzhiyun #define SREC_DATA4	3	/* Data  Record with 4 byte address	    */
83*4882a593Smuzhiyun #define SREC_COUNT	5	/* Count Record (previously transmitted)    */
84*4882a593Smuzhiyun #define SREC_END4	7	/* End   Record with 4 byte start address   */
85*4882a593Smuzhiyun #define SREC_END3	8	/* End   Record with 3 byte start address   */
86*4882a593Smuzhiyun #define SREC_END2	9	/* End   Record with 2 byte start address   */
87*4882a593Smuzhiyun #define SREC_EMPTY	10	/* Empty Record without any data	    */
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #define SREC_REC_OK  SREC_EMPTY /* last code without error condition	    */
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun #define SREC_E_BADTYPE	-1	/* no valid S-Record		            */
92*4882a593Smuzhiyun #define SREC_E_NOSREC	-2	/* line format differs from s-record	    */
93*4882a593Smuzhiyun #define SREC_E_BADCHKS	-3	/* checksum error in an s-record line	    */
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun #define SREC_MAXRECLEN	(512 + 4)   /* max ASCII record length		    */
96*4882a593Smuzhiyun #define SREC_MAXBINLEN	255	    /* resulting binary length		    */
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun int srec_decode (char *input, int *count, ulong *addr, char *data);
99