srecord: input/file/msbin.h Source File

srecord 1.65.0

Loading...
Searching...
No Matches
msbin.h
Go to the documentation of this file.
1//
2// srecord - manipulate eprom load files
3// Copyright (C) 2009-2011, 2013 Peter Miller
4//
5// Code contribution by David Kozub <zub@linux.fjfi.cvut.cz>
6// Copyright assigned to Peter Miller 27-Jan-2010.
7//
8// This program is free software; you can redistribute it and/or modify it
9// under the terms of the GNU Lesser General Public License as published by
10// the Free Software Foundation; either version 3 of the License, or (at
11// 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 GNU
16// General Public License for more details.
17//
18// You should have received a copy of the GNU Lesser General Public License
19// along with this program. If not, see <http://www.gnu.org/licenses/>.
20//
21
22#ifndef SRECORD_INPUT_FILE_MSBIN_H
23#define SRECORD_INPUT_FILE_MSBIN_H
24
25#include <stdint.h>
26#include <srecord/input/file.h>
27#include <srecord/record.h>
28
29namespace srecord {
30
31/**
32 * The srecord::input_file_binary class is used to represent the parse
33 * state of msbin (Windows CE Binary Image Data Format) input stream.
34 *
35 * See http://msdn.microsoft.com/en-us/library/ms924510.aspx
36 * for a description of the format.
37 */
38 class input_file_msbin:
39 public input_file
40{
41public:
42 /**
43 * The destructor.
44 */
45 virtual ~input_file_msbin();
46
47 /**
48 * The create class method is used to create new dynamically
49 * allocated instances of this class.
50 *
51 * @param file_name
52 * The name of the file to be read.
53 * @returns
54 * smart pointer to new instance
55 */
56 static pointer create(const std::string &file_name);
57
58protected:
59 // See base class for documentation.
60 bool read(record &record);
61
62 // See base class for documentation.
63 const char *get_file_format_name(void) const;
64
65 // See base class for documentation.
66 int format_option_number(void) const;
67
68private:
69 /**
70 * The constructor.
71 *
72 * @param file_name
73 * The name of the file to be read.
74 */
75 input_file_msbin(const std::string &file_name);
76
77 /**
78 * The header_read instance variable is used to remember whether
79 * the file header was read already.
80 */
81 bool header_read;
82
83 /**
84 * The first_record_read instance variable is used to remember
85 * whether we read the header of at least a single record.
86 *
87 * While false, lowest_address and highest_address are not valid.
88 */
89 bool first_record_read;
90
91 /**
92 * The execution_start_record_seen instance variable is used to
93 * remember whether we already read the execution start address
94 * record, which is supposed to be the last record in a file.
95 */
96 bool execution_start_record_seen;
97
98 /**
99 * The last_record_warning instance variable is used to remember
100 * whether a warning about extra records after the execution start
101 * record was already issued.
102 */
103 bool last_record_warning;
104
105 /**
106 * The address instance variable is used to remember the current
107 * address.
108 */
109 record::address_t address;
110
111 /**
112 * The remaining instance variable is used to remember the number
113 * of bytes remaining in this record to be read.
114 */
115 uint32_t remaining;
116
117 /**
118 * The record_checksum instance variable is used to remember the
119 * checksum of the current record, as read from the record header.
120 */
121 uint32_t record_checksum;
122
123 /**
124 * The running_checksum instance variable is used to remember the
125 * checksum of the data read from this record so far.
126 */
127 uint32_t running_checksum;
128
129 /**
130 * The image_start instance variable is used to remember the image
131 * start, the lowest data address in the file, as read from the
132 * file header.
133 */
134 record::address_t image_start;
135
136 /**
137 * The image_length instance variable is used to remember the image
138 * length, as read from the file header.
139 */
140 record::address_t image_length;
141
142 /**
143 * The lowest_address instance variable is used to remember the
144 * lowest address encountered in records read so far.
145 */
146 record::address_t lowest_address;
147
148 /**
149 * The highest_address instance variable is used to remember the
150 * highest address encountered in records read so far.
151 */
152 record::address_t highest_address;
153
154 /**
155 * The read_file_header method is used to read the (optional) magic
156 * and the file header.
157 */
158 void read_file_header(void);
159
160 // Just to be sure we can fit uint32_t in address_t.
161 static_assert(sizeof(record::address_t) >= sizeof(uint32_t));
162
163 /**
164 * The read_dword_le method is used to read a little endian double
165 * word from the input.
166 */
167 uint32_t read_dword_le(void);
168
169 /**
170 * The checksum method is used to calculate the checksum of a given
171 * data block.
172 *
173 * The checksum is additive, so:
174 * checkum([Block1,Block2]) = checksum(Block1) + checksum(Block2)
175 *
176 * @param data
177 * The data to be check-summed.
178 * @param len
179 * The length in bytes of the data to be check-summed.
180 */
181 static uint32_t checksum(const unsigned char *data, size_t len);
182
183 // See base class for documentation.
184 bool is_binary(void) const;
185
186 /**
187 * The default constructor. Do not use.
188 */
189 input_file_msbin();
190
191 /**
192 * The copy constructor. Do not use.
193 */
194 input_file_msbin(const input_file_msbin &);
195
196 /**
197 * The assignment operator. Do not use.
198 */
199 input_file_msbin &operator=(const input_file_msbin &);
200};
201
202};
203
204#endif // SRECORD_INPUT_FILE_MSBIN_H
205// vim: set ts=8 sw=4 et :
srecord::input_file_msbin::~input_file_msbin
virtual ~input_file_msbin()
The destructor.
srecord::input_file_msbin::read
bool read(record &record)
The read method is used to read one record from the input.
srecord::input_file_msbin::create
static pointer create(const std::string &file_name)
The create class method is used to create new dynamically allocated instances of this class.
srecord::input_file_msbin::format_option_number
int format_option_number(void) const
The format_option_number method is used to obtain the option number, which can then be turned into te...
srecord::input_file_msbin::get_file_format_name
const char * get_file_format_name(void) const
The get_file_format_name method is used to find out the name of the file format being read.
srecord::input_file::is_binary
virtual bool is_binary(void) const
The is_binary method is used to to determine whether or not a file format is binary (true) of text (f...
srecord::input_file::input_file
input_file(const std::string &file_name)
The constructor.
srecord::input_file::checksum
int checksum
The checksum instance variable is used record the running checksum.
Definition file.h:287
srecord::input_file::pointer
std::shared_ptr< input_file > pointer
Definition file.h:39
srecord::record
The srecord::record class is used to represent a data record read from a file.
Definition record.h:35
srecord::record::address_t
uint32_t address_t
The type of record addresses.
Definition record.h:58
file.h
srecord
Definition adler16.h:25
record.h