Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
elftosb::EncoreBootImage::LoadCommand Class Reference

Load data bootloader command. More...

#include <EncoreBootImage.h>

+ Inheritance diagram for elftosb::EncoreBootImage::LoadCommand:
+ Collaboration diagram for elftosb::EncoreBootImage::LoadCommand:

Public Member Functions

 LoadCommand ()
 Default constructor. More...
 
 LoadCommand (uint32_t address, const uint8_t *data, uint32_t length)
 Constructor.
 
virtual void initFromData (const cipher_block_t *blocks, unsigned count, unsigned *consumed)
 Read the command contents from raw data. More...
 
virtual void debugPrint () const
 Print out a string representation of the object.
 
Header
virtual uint8_t getTag () const
 Returns the tag value for this command.
 
virtual void fillCommandHeader (boot_command_t &header)
 Constructs the header for this boot command. More...
 
void setDCD (bool isDCD)
 Sets the load-dcd flag.
 
Address
void setLoadAddress (uint32_t address)
 
uint32_t getLoadAddress () const
 
Load data
void setData (const uint8_t *data, uint32_t length)
 Set the data for the command to load. More...
 
uint8_t * getData ()
 
const uint8_t * getData () const
 
uint32_t getLength () const
 
Data blocks
virtual unsigned getDataBlockCount () const
 Returns the number of data cipher blocks that follow this command. More...
 
virtual unsigned getDataBlocks (unsigned offset, unsigned maxCount, cipher_block_t *data)
 Returns the contents of up to maxCount data blocks. More...
 
- Public Member Functions inherited from elftosb::EncoreBootImage::BootCommand
 BootCommand ()
 Default constructor.
 
virtual ~BootCommand ()
 Destructor.
 
virtual uint8_t calculateChecksum (const boot_command_t &header)
 Calculates the checksum for the given command header. More...
 
virtual unsigned getBlockCount () const
 Returns the total number of cipher blocks. More...
 
virtual unsigned getBlocks (unsigned offset, unsigned maxCount, cipher_block_t *data)
 Returns the contents of up to maxCount cipher blocks. More...
 
Cipher blocks

Protected Member Functions

void fillPadding ()
 
uint32_t calculateCRC () const
 
- Protected Member Functions inherited from elftosb::EncoreBootImage::BootCommand
void validateHeader (const boot_command_t *modelHeader, const boot_command_t *testHeader, unsigned whichFields)
 

Protected Attributes

smart_array_ptr< uint8_t > m_data
 Pointer to data to load.
 
uint8_t m_padding [15]
 Up to 15 pad bytes may be required.
 
unsigned m_padCount
 Number of pad bytes.
 
uint32_t m_length
 Number of bytes to load.
 
uint32_t m_address
 Address to which data will be loaded.
 
bool m_loadDCD
 Whether to execute the DCD after loading.
 

Additional Inherited Members

- Static Public Member Functions inherited from elftosb::EncoreBootImage::BootCommand
static BootCommandcreateFromData (const cipher_block_t *blocks, unsigned count, unsigned *consumed)
 Creates the correct subclass of BootCommand for the given raw data. More...
 
- Protected Types inherited from elftosb::EncoreBootImage::BootCommand
enum  {
  CMD_TAG_FIELD = 1,
  CMD_FLAGS_FIELD = 2,
  CMD_ADDRESS_FIELD = 4,
  CMD_COUNT_FIELD = 8,
  CMD_DATA_FIELD = 16
}
 The flag bit values for the whichFields parameter of validateHeader().
 

Detailed Description

Load data bootloader command.

Constructor & Destructor Documentation

EncoreBootImage::LoadCommand::LoadCommand ( )

Default constructor.

All fields are set to zero.

Member Function Documentation

uint32_t EncoreBootImage::LoadCommand::calculateCRC ( ) const
protected

A CRC-32 is calculated over the load data, including any pad bytes that are required in the last data cipher block. Including the pad bytes in the CRC makes it vastly easier for the ROM to calculate the CRC for validation.

void EncoreBootImage::LoadCommand::fillCommandHeader ( boot_command_t header)
virtual

Constructs the header for this boot command.

The only thing unique in the load command header is the elftosb::EncoreBootImage::boot_command_t::m_data. It contains a CRC-32 over the load data, plus any bytes of padding in the last data cipher block.

Implements elftosb::EncoreBootImage::BootCommand.

void EncoreBootImage::LoadCommand::fillPadding ( )
protected

Fills m_padding with random bytes that may be used to fill up the last data cipher block.

unsigned EncoreBootImage::LoadCommand::getDataBlockCount ( ) const
virtual

Returns the number of data cipher blocks that follow this command.

Returns
The number of cipher blocks required to hold the load data, rounded up as necessary.

Reimplemented from elftosb::EncoreBootImage::BootCommand.

unsigned EncoreBootImage::LoadCommand::getDataBlocks ( unsigned  offset,
unsigned  maxCount,
cipher_block_t *  data 
)
virtual

Returns the contents of up to maxCount data blocks.

Up to maxCount data blocks are copied into the buffer pointed to by the data argument. This is only a request for maxCount blocks. A return value of 0 indicates that no more blocks are available. The index of the first block to copy is held in the offset argument. If there are pad bytes needed to fill out the last data block, they will be filled with random data in order to add to the "whiteness" of the data on both sides of encryption.

Parameters
offsetStarting block number to copy. Zero means the first available block.
maxCountUp to this number of blocks may be copied into data. Must be 1 or greater.
dataBuffer for outgoing data blocks. Must have enough room to hold maxCount blocks.
Returns
The number of data blocks copied into data.
Return values
0No more blocks are available and nothing was written to data.
Exceptions
std::out_of_rangeThrown when offset is invalid.

Reimplemented from elftosb::EncoreBootImage::BootCommand.

void EncoreBootImage::LoadCommand::initFromData ( const cipher_block_t *  blocks,
unsigned  count,
unsigned *  consumed 
)
virtual

Read the command contents from raw data.

Parameters
blocksPointer to the raw data blocks.
countNumber of blocks pointed to by blocks.
[out]consumedOn exit, this points to the number of cipher blocks that were occupied by the command. Should be at least 1 for every command. This must not be NULL on entry!
Exceptions
std::runtime_errorThis exception is thrown if the actual CRC of the load data does not match the CRC stored in the command header. Also thrown if the count parameter is less than the number of data blocks needed for the length specified in the command header or if header fields are invalid.

Implements elftosb::EncoreBootImage::BootCommand.

void EncoreBootImage::LoadCommand::setData ( const uint8_t *  data,
uint32_t  length 
)

Set the data for the command to load.

A local copy of the load data is made. This copy will be disposed of when this object is destroyed. This means the caller is free to deallocate data after this call returns. It also means the caller can pass a pointer into the middle of a buffer for data and not worry about ownership issues.


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