s_record.h 3.3 KB

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