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