s_record.h 4.0 KB

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