10 #include "addressmap.hh"
11 #include "errorstack.hh"
94 uint32_t
size()
const;
100 const QByteArray &
data()
const;
105 bool read(QFile &file,
CRC32 &crc, QString &errorMessage);
107 bool write(QFile &file,
CRC32 &crc, QString &errorMessage)
const;
110 void dump(QTextStream &stream)
const;
127 Image(
const QString &
name, uint8_t altSettings=0);
143 const QString &
name()
const;
147 uint32_t
size()
const;
164 bool isAligned(
unsigned blocksize)
const;
167 bool read(QFile &file,
CRC32 &crc, QString &errorMessage);
169 bool write(QFile &file,
CRC32 &crc, QString &errorMessage)
const;
172 void dump(QTextStream &stream)
const;
178 virtual unsigned char *
data(uint32_t offset);
180 virtual const unsigned char *
data(uint32_t offset)
const;
198 DFUFile(QObject *parent=
nullptr);
201 uint32_t
size()
const;
212 void addImage(
const QString &name, uint8_t altSettings=1);
219 bool isAligned(
unsigned blocksize)
const;
236 void dump(QTextStream &stream)
const;
239 virtual bool isAllocated(uint32_t offset, uint32_t img=0)
const;
242 virtual unsigned char *
data(uint32_t offset, uint32_t img=0);
244 virtual const unsigned char *
data(uint32_t offset, uint32_t img=0)
const;
This class represents a memory map.
Definition: addressmap.hh:14
Implements the CRC32 checksum as used in DFU files.
Definition: crc32.hh:10
Represents a single element within a Image.
Definition: dfufile.hh:78
uint32_t memSize() const
Returns the memory size of the element.
Definition: dfufile.cc:315
void setAddress(uint32_t addr)
Sets the address of the element.
Definition: dfufile.cc:325
bool read(QFile &file, CRC32 &crc, QString &errorMessage)
Reads an element from the given file and updates the CRC.
Definition: dfufile.cc:345
const QByteArray & data() const
Returns a reference to the data.
Definition: dfufile.cc:335
QByteArray _data
The data of the element.
Definition: dfufile.hh:116
bool write(QFile &file, CRC32 &crc, QString &errorMessage) const
Writes an element to the given file and updates the CRC.
Definition: dfufile.cc:373
uint32_t size() const
Returns the size of the element (including headers).
Definition: dfufile.cc:310
void dump(QTextStream &stream) const
Dumps a textual representation of the element.
Definition: dfufile.cc:398
Element & operator=(const Element &other)
Copying assignment.
Definition: dfufile.cc:303
uint32_t _address
The address of the element.
Definition: dfufile.hh:114
bool isAligned(unsigned blocksize) const
Checks if the element address and size is aligned with the given block size.
Definition: dfufile.cc:330
uint32_t address() const
Returns the address of the element.
Definition: dfufile.cc:320
Element()
Empty constructor.
Definition: dfufile.cc:284
Represents a single image within a DFUFile.
Definition: dfufile.hh:121
virtual unsigned char * data(uint32_t offset)
Returns a pointer to the encoded raw data at the specified offset.
Definition: dfufile.cc:662
virtual bool isAllocated(uint32_t offset) const
Returns true if the specified address is allocated.
Definition: dfufile.cc:657
Image()
Default constructor.
Definition: dfufile.cc:442
void setAlternateSettings(uint8_t s)
Sets the alternate settings byte.
Definition: dfufile.cc:496
int numElements() const
Returns the number of elements of this image.
Definition: dfufile.cc:516
bool write(QFile &file, CRC32 &crc, QString &errorMessage) const
Writes this image to the given file and updates the CRC.
Definition: dfufile.cc:603
uint32_t size() const
Returns the total size of the image (including headers).
Definition: dfufile.cc:475
bool read(QFile &file, CRC32 &crc, QString &errorMessage)
Reads an image from the given file and updates the CRC.
Definition: dfufile.cc:562
AddressMap _addressmap
Maps an address range to element index.
Definition: dfufile.hh:193
const Element & element(int i) const
Returns a reference to the i-th element of the image.
Definition: dfufile.cc:521
const QString & name() const
Returns the name of the image.
Definition: dfufile.cc:506
void setName(const QString &name)
Sets the name of the image.
Definition: dfufile.cc:511
bool isAligned(unsigned blocksize) const
Checks if all element addresses and sizes is aligned with the given block size.
Definition: dfufile.cc:554
uint32_t memSize() const
Returns the memory size stored in the image.
Definition: dfufile.cc:483
void remElement(int i)
Removes the i-th element from this image.
Definition: dfufile.cc:548
void sort()
Sorts all elements with respect to their addresses.
Definition: dfufile.cc:631
Image & operator=(const Image &other)
Copying assignment.
Definition: dfufile.cc:466
virtual ~Image()
Destructor.
Definition: dfufile.cc:461
QVector< Element > _elements
The elements of the image.
Definition: dfufile.hh:191
bool isNamed() const
Returns true if the image is named.
Definition: dfufile.cc:501
void dump(QTextStream &stream) const
Prints a textual representation of the image into the given stream.
Definition: dfufile.cc:644
uint8_t alternateSettings() const
Returns the alternate settings byte.
Definition: dfufile.cc:491
QString _name
Optional image name.
Definition: dfufile.hh:189
uint8_t _alternate_settings
Alternate settings byte.
Definition: dfufile.hh:187
void addElement(uint32_t addr, uint32_t size, int index=-1)
Adds an element to the image with the given address and size at the specified index.
Definition: dfufile.cc:531
A collection of images, each consisting of one or more memory sections.
Definition: dfufile.hh:73
bool read(const QString &filename, const ErrorStack &err=ErrorStack())
Reads the specified DFU file.
Definition: dfufile.cc:108
QVector< Image > _images
The list of images.
Definition: dfufile.hh:248
virtual bool isAllocated(uint32_t offset, uint32_t img=0) const
Returns true if the specified address (and image) is allocated.
Definition: dfufile.cc:252
uint32_t memSize() const
Returns the total memory size stored in the DFU file.
Definition: dfufile.cc:61
bool isAligned(unsigned blocksize) const
Checks if all image addresses and sizes is aligned with the given block size.
Definition: dfufile.cc:100
virtual unsigned char * data(uint32_t offset, uint32_t img=0)
Returns a pointer to the encoded raw data at the specified offset.
Definition: dfufile.cc:259
bool write(const QString &filename, const ErrorStack &err=ErrorStack())
Writes to the specified file.
Definition: dfufile.cc:192
void remImage(int i)
Deletes the i-th image from the file.
Definition: dfufile.cc:95
DFUFile(QObject *parent=nullptr)
Constructs an empty DFU file object.
Definition: dfufile.cc:45
void dump(QTextStream &stream) const
Dumps a text representation of the DFU file structure to the specified text stream.
Definition: dfufile.cc:273
void addImage(const QString &name, uint8_t altSettings=1)
Adds a new image to the file.
Definition: dfufile.cc:85
uint32_t size() const
Returns the total size of the DFU file.
Definition: dfufile.cc:52
int numImages() const
Returns the number of images within the DFU file.
Definition: dfufile.cc:70
const Image & image(int i) const
Returns a reference to the i-th image of the file.
Definition: dfufile.cc:75
Implements a stack of error messages to provide a pretty formatted error traceback.
Definition: errorstack.hh:41