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