Public Types | Public Member Functions | Static Public Member Functions | List of all members
Rose::BinaryAnalysis::SRecord Class Reference


Motorola S-Record.

Motorola S-record is a file format, created by Motorola, that conveys binary information in ASCII hexadecimal text form. This file format may also be known as SRECORD, SREC, S19, S28, S37. It is commonly used for programming microcontrollers, EPROMs, and other types of programmable logic devices. In a typical application, a compiler or assembler converts a program's source code (such as C or assembly language) to machine code and outputs it into a HEX file. The HEX file is then imported by a programmer to "burn" the machine code into a ROM, or is transferred to the target system for loading and execution.

Definition at line 15 of file SRecord.h.

#include <SRecord.h>

Public Types

enum  Type {
  SREC_DATA16 = 1,
  SREC_DATA24 = 2,
  SREC_DATA32 = 3,
  SREC_COUNT16 = 5,
  SREC_COUNT24 = 6,
  SREC_START32 = 7,
  SREC_START24 = 8,
  SREC_START16 = 9,
 Type of S-Record. More...

Public Member Functions

 SRecord ()
 Construct an empty S-Record. More...
size_t encodedSize () const
 Size of encoded S-Record in characters. More...
uint8_t checksum () const
 Compute the checksum for the data. More...
 SRecord (Type type, rose_addr_t addr, const std::vector< uint8_t > data)
 Construct an S-Record with data.
 SRecord (Type type, rose_addr_t addr, const uint8_t *buffer, size_t bufsz)
 Construct an S-Record with data.
Type type () const
 Accessor for the S-Record type.
SRecordtype (Type type)
 Accessor for the S-Record type.
rose_addr_t address () const
 Accessor for the S-Record address.
SRecordaddress (rose_addr_t addr)
 Accessor for the S-Record address.
const std::vector< uint8_t > & data () const
 Accessor for the S-Record data.
std::vector< uint8_t > & data ()
 Accessor for the S-Record data.
SRecorddata (const std::vector< uint8_t > &data)
 Accessor for the S-Record data.
const std::string & error () const
 Accessor for the S-Record error message.
SRecorderror (const std::string &error)
 Accessor for the S-Record error message.

Static Public Member Functions

static SRecord parse (const std::string &)
 Construct an S-Record by parsing a string. More...
static std::vector< SRecordparse (std::istream &)
 Construct S-Records by parsing a file. More...
static size_t addressNBytes (Type)
 Size of address in bytes. More...
static rose_addr_t load (const std::vector< SRecord > &, const MemoryMap::Ptr &, bool createSegments=true, unsigned accessPerms=MemoryMap::READABLE|MemoryMap::WRITABLE|MemoryMap::EXECUTABLE, const std::string &newSegmentNames="S-Records")
 Load S-Records into a memory map. More...
static size_t dump (const MemoryMap::Ptr &, std::ostream &, size_t addrSize=4)
 Dump a memory map as S-Records. More...
void print (std::ostream &) const
 Print an S-Record to a stream.
std::ostream & operator<< (std::ostream &, const SRecord &)
 Print an S-Record to a stream.

Member Enumeration Documentation

Type of S-Record.


Vendor-specific header, usually NUL-terminated ASCII.


Data with 16-bit address.


Data with 24-bit address.


Data with 32-bit address.




16-bit count of data records.


24-bit count of data records.


32-bit starting address.


24-bit starting address.


16-bit starting address.


Not a valid S-Record.

Definition at line 18 of file SRecord.h.

Constructor & Destructor Documentation

Rose::BinaryAnalysis::SRecord::SRecord ( )

Construct an empty S-Record.

Definition at line 41 of file SRecord.h.

Member Function Documentation

static SRecord Rose::BinaryAnalysis::SRecord::parse ( const std::string &  )

Construct an S-Record by parsing a string.

static std::vector<SRecord> Rose::BinaryAnalysis::SRecord::parse ( std::istream &  )

Construct S-Records by parsing a file.

Returns a vector with one element per line of input. Lines that did not contain an S-Record or which had trailing characters other than white space are reported as SRecord objects of type SREC_NONE and an error message.

static size_t Rose::BinaryAnalysis::SRecord::addressNBytes ( Type  )

Size of address in bytes.

The address is encoded in twice as many ASCII characters.

size_t Rose::BinaryAnalysis::SRecord::encodedSize ( ) const

Size of encoded S-Record in characters.

If an error was encountered when parsing this S-Record (!error().empty()) then the size reported by this method will likely be only the size up to the point where the error was encountered.

static rose_addr_t Rose::BinaryAnalysis::SRecord::load ( const std::vector< SRecord > &  ,
const MemoryMap::Ptr ,
bool  createSegments = true,
unsigned  accessPerms = MemoryMap::READABLE|MemoryMap::WRITABLE|MemoryMap::EXECUTABLE,
const std::string &  newSegmentNames = "S-Records" 

Load S-Records into a memory map.

The specified S-Records are loaded into the memory map. If createSegments is true then a minimal number of segments are created to hold the S-Record data, otherwise the destinations must already be mapped or a MemoryMap::NotMapped exception is thrown. When new segments are created they are given access permissions specified by accessPerms and the name specified by newSegmentNames (or "S-Records"). Access permissions are not consulted and do not cause errors when writing S-Record data into the map.

uint8_t Rose::BinaryAnalysis::SRecord::checksum ( ) const

Compute the checksum for the data.

An S-Record checksum is the 1's complement of the sum of address and data bytes modulo 256.

static size_t Rose::BinaryAnalysis::SRecord::dump ( const MemoryMap::Ptr ,
std::ostream &  ,
size_t  addrSize = 4 

Dump a memory map as S-Records.

All data in the specified memory map is dumped to the specified output stream. The addrSize should be 2, 3, or 4 to indicate 16-, 24-, or 32-bit addresses. The output is not prefixed with an SREC_HEADER record nor terminated with SREC_COUNT or SREC_START records. An std::runtime_error is thrown if an address in the memory map cannot be encoded in the specified addrSize number of bytes. Returns the number of records emitted.

The documentation for this class was generated from the following file: