EncoreBootImage.h
/*
* File: EncoreBootImage.h
*
* Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
* See included license file for license details.
*/
#if !defined(_EncoreBootImage_h_)
#define _EncoreBootImage_h_
#include <list>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <string.h>
#include "BootImage.h"
#include "rijndael.h"
#include "smart_ptr.h"
#include "AESKey.h"
#include "StExecutableImage.h"
namespace elftosb
{
typedef uint8_t cipher_block_t[16];
typedef uint8_t sha1_digest_t[20];
typedef uint32_t section_id_t;
inline size_t sizeOfCipherBlocks(unsigned count)
{
return sizeof(cipher_block_t) * count;
}
inline size_t numberOfCipherBlocks(size_t s)
{
return (s + sizeof(cipher_block_t) - 1) / sizeof(cipher_block_t);
}
inline size_t sizeInCipherBlocks(size_t s)
{
return (unsigned)sizeOfCipherBlocks(numberOfCipherBlocks(s));
}
inline size_t sizeOfPaddingForCipherBlocks(size_t s)
{
return sizeInCipherBlocks(s) - s;
}
class EncoreBootImage : public BootImage
{
public:
enum
{
ROM_DISPLAY_PROGRESS = (1 << 0),
ROM_VERBOSE_PROGRESS = (1 << 1)
};
enum
{
ROM_IMAGE_HEADER_SIGNATURE =
'STMP',
ROM_IMAGE_HEADER_SIGNATURE2 =
'sgtl',
ROM_BOOT_IMAGE_MAJOR_VERSION = 1,
ROM_BOOT_IMAGE_MINOR_VERSION = 2
};
enum
{
BOOT_IMAGE_MINIMUM_SECTION_ALIGNMENT = sizeof(cipher_block_t)
};
// All of these structures are packed to byte alignment in order to match
// the structure on disk.
#pragma pack(1)
struct boot_image_header_t
{
union
{
sha1_digest_t m_digest;
struct
{
cipher_block_t m_iv;
uint8_t m_extra[4];
};
};
uint8_t m_signature[4];
uint8_t m_majorVersion;
uint8_t m_minorVersion;
uint16_t m_flags;
uint32_t m_imageBlocks;
uint32_t m_firstBootTagBlock;
section_id_t m_firstBootableSectionID;
uint16_t m_keyCount;
uint16_t m_keyDictionaryBlock;
uint16_t m_headerBlocks;
uint16_t m_sectionCount;
uint16_t m_sectionHeaderSize;
uint8_t m_padding0[2];
uint8_t m_signature2[4];
uint64_t m_timestamp;
version_t m_productVersion;
version_t m_componentVersion;
uint16_t m_driveTag;
uint8_t m_padding1[6];
};
struct dek_dictionary_entry_t
{
cipher_block_t m_mac;
aes128_key_t m_dek;
};
struct dek_dictionary_t
{
dek_dictionary_entry_t m_entries[1];
};
enum
{
ROM_SECTION_BOOTABLE = (1 << 0),
ROM_SECTION_CLEARTEXT =
(1 << 1)
};
struct section_header_t
{
uint32_t m_tag;
uint32_t m_offset;
uint32_t m_length;
uint32_t m_flags;
};
struct section_table_t
{
section_header_t m_sections[1];
};
struct boot_command_t
{
uint8_t m_checksum;
uint8_t m_tag;
uint16_t m_flags;
uint32_t m_address;
uint32_t m_count;
uint32_t m_data;
};
#pragma pack()
enum
{
ROM_NOP_CMD = 0x00,
ROM_TAG_CMD = 0x01,
ROM_LOAD_CMD = 0x02,
ROM_FILL_CMD = 0x03,
ROM_JUMP_CMD = 0x04,
ROM_CALL_CMD = 0x05,
ROM_MODE_CMD = 0x06,
ROM_ERASE_CMD = 0x07,
ROM_RESET_CMD = 0x08,
ROM_MEM_ENABLE_CMD = 0x09,
ROM_PROG_CMD = 0x0a
};
enum
{
ROM_LAST_TAG = (1 << 0)
};
enum
{
ROM_LOAD_DCD = (1 << 0)
};
enum
{
ROM_FILL_BYTE = 0,
ROM_FILL_HALF_WORD = 1,
ROM_FILL_WORD = 2
};
enum
{
ROM_HAB_EXEC = (1 << 0),
ROM_JUMP_SP_MASK = (1 << 1)
};
enum
{
ROM_MEM_CTRL_MASK = 0x0f,
ROM_MEM_CTRL_SHIFT = 8
};
enum
{
ROM_MEM_SPACE_MASK = 0x0f,
ROM_MEM_SPACE_SHIFT = 8
};
enum
{
ROM_ERASE_ALL_MASK = (1 << 0),
ROM_ERASE_ALL_UNSECURE_MASK = (1 << 1),
};
enum
{
ROM_PROG_8BYTE_MASK = (1 << 0)
};
enum
{
ROM_MEM_ID_QSPI = 1,
};
enum
{
ROM_MEM_SPACE_IFR = 4,
};
public:
// Forward declaration.
class Section;
class CipherBlockGenerator
{
public:
virtual unsigned getBlockCount() const { return 0; }
virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data) { return 0; }
virtual void debugPrint() const {}
};
class BootCommand : public CipherBlockGenerator
{
public:
static BootCommand *createFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
public:
BootCommand()
: CipherBlockGenerator()
{
}
virtual ~BootCommand() {}
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed) = 0;
virtual uint8_t getTag() const = 0;
virtual void fillCommandHeader(boot_command_t &header) = 0;
virtual uint8_t calculateChecksum(const boot_command_t &header);
virtual unsigned getBlockCount() const;
virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data);
virtual unsigned getDataBlockCount() const { return 0; }
virtual unsigned getDataBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data) { return 0; }
protected:
enum
{
CMD_TAG_FIELD = 1,
CMD_FLAGS_FIELD = 2,
CMD_ADDRESS_FIELD = 4,
CMD_COUNT_FIELD = 8,
CMD_DATA_FIELD = 16
};
void validateHeader(const boot_command_t *modelHeader, const boot_command_t *testHeader, unsigned whichFields);
};
class NopCommand : public BootCommand
{
public:
NopCommand()
: BootCommand()
{
}
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_NOP_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
virtual void debugPrint() const;
};
class TagCommand : public BootCommand
{
public:
TagCommand()
: BootCommand()
{
}
TagCommand(const Section &section);
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_TAG_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
inline void setSectionIdentifier(uint32_t identifier) { m_sectionIdentifier = identifier; }
inline void setSectionLength(uint32_t length) { m_sectionLength = length; }
inline void setSectionFlags(uint32_t flags) { m_sectionFlags = flags; }
inline void setLast(bool isLast) { m_isLast = isLast; }
virtual void debugPrint() const;
protected:
uint32_t m_sectionIdentifier;
uint32_t m_sectionLength;
uint32_t m_sectionFlags;
bool m_isLast;
};
class LoadCommand : public BootCommand
{
public:
LoadCommand();
LoadCommand(uint32_t address, const uint8_t *data, uint32_t length);
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_LOAD_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
inline void setDCD(bool isDCD) { m_loadDCD = isDCD; }
inline void setLoadAddress(uint32_t address) { m_address = address; }
inline uint32_t getLoadAddress() const { return m_address; }
void setData(const uint8_t *data, uint32_t length);
inline uint8_t *getData() { return m_data; }
inline const uint8_t *getData() const { return m_data; }
inline uint32_t getLength() const { return m_length; }
virtual unsigned getDataBlockCount() const;
virtual unsigned getDataBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data);
virtual void debugPrint() const;
protected:
smart_array_ptr<uint8_t> m_data;
uint8_t m_padding[15];
unsigned m_padCount;
uint32_t m_length;
uint32_t m_address;
bool m_loadDCD;
void fillPadding();
uint32_t calculateCRC() const;
};
class FillCommand : public BootCommand
{
public:
FillCommand();
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_FILL_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
inline void setAddress(uint32_t address) { m_address = address; };
inline uint32_t getAddress() const { return m_address; }
inline void setFillCount(uint32_t count) { m_count = count; }
inline uint32_t getFillCount() const { return m_count; }
void setPattern(uint8_t pattern);
void setPattern(uint16_t pattern);
void setPattern(uint32_t pattern);
inline uint32_t getPattern() const { return m_pattern; }
virtual void debugPrint() const;
protected:
uint32_t m_address;
uint32_t m_count;
uint32_t m_pattern;
};
class ModeCommand : public BootCommand
{
public:
ModeCommand()
: BootCommand()
, m_mode(0)
{
}
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_MODE_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
inline void setBootMode(uint32_t mode) { m_mode = mode; }
inline uint32_t getBootMode() const { return m_mode; }
virtual void debugPrint() const;
protected:
uint32_t m_mode;
};
class EraseCommand : public BootCommand
{
public:
EraseCommand()
: BootCommand()
, m_doEraseAll(false)
, m_doEraseAllUnsecure(false)
, m_startAddress(0)
, m_byteCount(0)
, m_memoryId(0)
{
}
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_ERASE_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
void setEraseAll(bool doEraseAll) { m_doEraseAll = doEraseAll; }
bool getEraseAll() const { return m_doEraseAll; }
void setEraseAllUnsecure(bool doEraseAllUnsecure) { m_doEraseAllUnsecure = doEraseAllUnsecure; }
bool getEraseAllUnsecure() const { return m_doEraseAllUnsecure; }
void setAddressRange(uint32_t startAddress, uint32_t count);
void getAddressRange(uint32_t *startAddress, uint32_t *count) const;
void setMemoryId(uint32_t memId) { m_memoryId = memId; }
uint32_t getMemoryId() const { return m_memoryId; }
virtual void debugPrint() const;
protected:
bool m_doEraseAll;
bool m_doEraseAllUnsecure;
uint32_t m_startAddress;
uint32_t m_byteCount;
uint32_t m_memoryId;
};
class ProgramCommand : public BootCommand
{
public:
ProgramCommand()
: BootCommand()
, m_isEightByte(false)
, m_index(0)
, m_dataWord1(0)
, m_dataWord2(0)
, m_memSpace(0)
{
}
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_PROG_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
void setIsEightByte(bool doIt) { m_isEightByte = doIt; }
bool isEightByte() const { return m_isEightByte; }
void setMemSpace(uint32_t id) { m_memSpace = id; }
uint32_t getMemSpace() const { return m_memSpace; }
void setIndex(uint32_t index) { m_index = index; }
uint32_t getIndex() const { return m_index; }
void setDataWord1(uint32_t dataWord) { m_dataWord1 = dataWord; }
uint32_t getDataWord1() const { return m_dataWord1; }
void setDataWord2(uint32_t dataWord) { m_dataWord2 = dataWord; }
uint32_t getDataWord2() const { return m_dataWord2; }
virtual void debugPrint() const;
protected:
bool m_isEightByte;
uint32_t m_index;
uint32_t m_dataWord1;
uint32_t m_dataWord2;
uint32_t m_memSpace;
};
class JumpCommand : public BootCommand
{
public:
JumpCommand()
: BootCommand()
, m_address(0)
, m_argument(0)
, m_isHAB(false)
, m_ivtSize(0)
, m_stackPointer(0)
, m_isStackPointerSet(false)
{
}
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_JUMP_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
inline void setAddress(uint32_t address) { m_address = address; }
inline uint32_t getAddress() const { return m_address; }
inline void setArgument(uint32_t argument) { m_argument = argument; }
inline uint32_t getArgument() const { return m_argument; }
inline void setIsHAB(bool isHAB) { m_isHAB = isHAB; }
inline bool isHAB() const { return m_isHAB; }
inline void setIVTSize(uint32_t ivtSize) { m_ivtSize = ivtSize; }
inline uint32_t getIVTSize() const { return m_ivtSize; }
inline void setStackPointer(uint32_t sp) { m_stackPointer = sp; }
inline uint32_t getStackPointer() { return m_stackPointer; }
inline void setIsStackPointerSet(bool isSP) { m_isStackPointerSet = isSP; }
inline bool IsStackPointerSet() const { return m_isStackPointerSet; }
virtual void debugPrint() const;
protected:
uint32_t m_address;
uint32_t m_argument;
uint32_t m_stackPointer;
bool m_isHAB;
bool m_isStackPointerSet;
uint32_t m_ivtSize;
};
class CallCommand : public JumpCommand
{
public:
CallCommand()
: JumpCommand()
{
}
virtual uint8_t getTag() const { return ROM_CALL_CMD; }
virtual void debugPrint() const;
};
class ResetCommand : public BootCommand
{
public:
ResetCommand()
: BootCommand()
{
}
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_RESET_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
virtual void debugPrint() const;
protected:
};
class MemEnableCommand : public BootCommand
{
public:
MemEnableCommand()
: BootCommand()
, m_startAddress(0)
, m_byteCount(0)
, m_memControllerId(0)
{
}
virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
virtual uint8_t getTag() const { return ROM_MEM_ENABLE_CMD; }
virtual void fillCommandHeader(boot_command_t &header);
void setAddressRange(uint32_t startAddress, uint32_t count);
void getAddressRange(uint32_t *startAddress, uint32_t *count) const;
void setMemControllerId(uint32_t memControllerId) { m_memControllerId = memControllerId; }
uint32_t getMemControllerId() const { return m_memControllerId; }
virtual void debugPrint() const;
protected:
uint32_t m_startAddress;
uint32_t m_byteCount;
uint32_t m_memControllerId;
};
class Section : public CipherBlockGenerator
{
public:
Section()
: CipherBlockGenerator()
, m_identifier(0)
, m_image(0)
, m_alignment(BOOT_IMAGE_MINIMUM_SECTION_ALIGNMENT)
, m_flags(0)
, m_leaveUnencrypted(false)
{
}
Section(uint32_t identifier)
: CipherBlockGenerator()
, m_identifier(identifier)
, m_image(0)
, m_alignment(BOOT_IMAGE_MINIMUM_SECTION_ALIGNMENT)
, m_flags(0)
, m_leaveUnencrypted(false)
{
}
inline void setIdentifier(uint32_t identifier) { m_identifier = identifier; }
inline uint32_t getIdentifier() const { return m_identifier; }
virtual void setFlags(uint32_t flags) { m_flags = flags; }
virtual uint32_t getFlags() const { return m_flags | (m_leaveUnencrypted ? ROM_SECTION_CLEARTEXT : 0); }
virtual void fillSectionHeader(section_header_t &header);
void setImage(EncoreBootImage *image) { m_image = image; }
EncoreBootImage *getImage() const { return m_image; }
void setAlignment(unsigned alignment);
unsigned getAlignment() const { return m_alignment; }
unsigned getPadBlockCountForOffset(unsigned offset);
void setLeaveUnencrypted(unsigned flag) { m_leaveUnencrypted = flag; }
bool getLeaveUnencrypted() const { return m_leaveUnencrypted; }
protected:
uint32_t m_identifier;
EncoreBootImage *m_image;
unsigned m_alignment;
uint32_t m_flags;
bool m_leaveUnencrypted;
};
class BootSection : public Section
{
public:
typedef std::list<BootCommand *> command_list_t;
typedef command_list_t::iterator iterator_t;
typedef command_list_t::const_iterator const_iterator_t;
public:
BootSection()
: Section()
{
}
BootSection(uint32_t identifier)
: Section(identifier)
{
}
virtual ~BootSection();
virtual void fillFromData(const cipher_block_t *blocks, unsigned count);
virtual uint32_t getFlags() const { return Section::getFlags() | ROM_SECTION_BOOTABLE; }
void addCommand(BootCommand *command) { m_commands.push_back(command); }
unsigned getCommandCount() const { return (unsigned)m_commands.size(); }
iterator_t begin() { return m_commands.begin(); }
iterator_t end() { return m_commands.end(); }
const_iterator_t begin() const { return m_commands.begin(); }
const_iterator_t end() const { return m_commands.end(); }
virtual unsigned getBlockCount() const;
virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data);
virtual void debugPrint() const;
protected:
command_list_t m_commands;
protected:
void deleteCommands();
};
class DataSection : public Section
{
public:
DataSection()
: Section()
, m_data()
, m_length(0)
{
}
DataSection(uint32_t identifier)
: Section(identifier)
, m_data()
, m_length(0)
{
}
void setData(const uint8_t *data, unsigned length);
void setDataNoCopy(const uint8_t *data, unsigned length);
virtual unsigned getBlockCount() const;
virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data);
virtual void debugPrint() const;
protected:
smart_array_ptr<uint8_t> m_data;
unsigned m_length;
};
public:
typedef std::list<Section *> section_list_t;
typedef section_list_t::iterator section_iterator_t;
typedef section_list_t::const_iterator const_section_iterator_t;
typedef std::vector<AES128Key> key_list_t;
typedef key_list_t::iterator key_iterator_t;
typedef key_list_t::const_iterator const_key_iterator_t;
public:
EncoreBootImage();
virtual ~EncoreBootImage();
void addSection(Section *newSection);
inline unsigned sectionCount() const { return (unsigned)m_sections.size(); }
inline section_iterator_t beginSection() { return m_sections.begin(); }
inline section_iterator_t endSection() { return m_sections.end(); }
inline const_section_iterator_t beginSection() const { return m_sections.begin(); }
inline const_section_iterator_t endSection() const { return m_sections.end(); }
section_iterator_t findSection(Section *section);
uint32_t getSectionOffset(Section *section);
inline void addKey(const AES128Key &newKey) { m_keys.push_back(newKey); }
inline unsigned keyCount() const { return (unsigned)m_keys.size(); }
inline key_iterator_t beginKeys() { return m_keys.begin(); }
inline key_iterator_t endKeys() { return m_keys.end(); }
inline const_key_iterator_t beginKeys() const { return m_keys.begin(); }
inline const_key_iterator_t endKeys() const { return m_keys.end(); }
inline bool isEncrypted() const { return m_keys.size() != 0; }
virtual void setProductVersion(const version_t &version);
virtual void setComponentVersion(const version_t &version);
inline void setFlags(uint16_t flags) { m_headerFlags = flags; }
inline uint32_t getFlags() const { return m_headerFlags; }
virtual void setDriveTag(uint16_t tag) { m_driveTag = tag; }
uint32_t getImageSize();
virtual std::string getFileExtension() const { return ".sb"; }
virtual void writeToStream(std::ostream &stream);
virtual void debugPrint() const;
protected:
uint16_t m_headerFlags;
version_t m_productVersion;
version_t m_componentVersion;
uint16_t m_driveTag;
section_list_t m_sections;
key_list_t m_keys;
AES128Key m_sessionKey;
void prepareImageHeader(boot_image_header_t &header);
uint64_t getTimestamp();
Section *findFirstBootableSection();
unsigned getPadBlockCountForSection(Section *section, unsigned offset);
};
}; // namespace elftosb
#endif // _EncoreBootImage_h_
elftosb::EncoreBootImage::~EncoreBootImage
virtual ~EncoreBootImage()
Destructor.
Definition: EncoreBootImage.cpp:31
elftosb::EncoreBootImage::ROM_JUMP_CMD
Jump to address command.
Definition: EncoreBootImage.h:268
elftosb::EncoreBootImage::ROM_IMAGE_HEADER_SIGNATURE2
Value for elftosb::EncoreBootImage::boot_image_header_t::m_signature2;.
Definition: EncoreBootImage.h:115
elftosb::EncoreBootImage::m_sessionKey
AES128Key m_sessionKey
Session key we&#39;re using.
Definition: EncoreBootImage.h:1261
elftosb::EncoreBootImage::dek_dictionary_t
The DEK dictionary always follows the image header, in the next cipher block.
Definition: EncoreBootImage.h:194
elftosb::EncoreBootImage::TagCommand::m_sectionLength
uint32_t m_sectionLength
Number of cipher blocks this section occupies.
Definition: EncoreBootImage.h:543
elftosb::EncoreBootImage::ROM_FILL_CMD
Pattern fill command.
Definition: EncoreBootImage.h:267
elftosb::EncoreBootImage::boot_image_header_t::m_firstBootableSectionID
section_id_t m_firstBootableSectionID
ID of section to start booting from.
Definition: EncoreBootImage.h:167
elftosb::EncoreBootImage::LoadCommand::setDCD
void setDCD(bool isDCD)
Sets the load-dcd flag.
Definition: EncoreBootImage.h:571
elftosb::EncoreBootImage::m_headerFlags
uint16_t m_headerFlags
Flags field in the boot image header.
Definition: EncoreBootImage.h:1255
elftosb::EncoreBootImage::TagCommand
Section tag bootloader command.
Definition: EncoreBootImage.h:507
elftosb::EncoreBootImage::ROM_CALL_CMD
Call function command.
Definition: EncoreBootImage.h:269
elftosb::EncoreBootImage::MemEnableCommand::MemEnableCommand
MemEnableCommand()
Default constructor.
Definition: EncoreBootImage.h:941
elftosb::EncoreBootImage::Section
Base class for a section of an Encore boot image.
Definition: EncoreBootImage.h:989
elftosb::EncoreBootImage::boot_image_header_t::m_firstBootTagBlock
uint32_t m_firstBootTagBlock
Offset from start of file to the first boot tag, in blocks.
Definition: EncoreBootImage.h:166
elftosb::EncoreBootImage::DataSection::DataSection
DataSection(uint32_t identifier)
Constructor taking the unique identifier for this section.
Definition: EncoreBootImage.h:1154
elftosb::EncoreBootImage::EncoreBootImage
EncoreBootImage()
Default constructor.
Definition: EncoreBootImage.cpp:23
elftosb::EncoreBootImage::Section::m_alignment
unsigned m_alignment
Alignment requirement for the start of this section.
Definition: EncoreBootImage.h:1064
elftosb::EncoreBootImage::ROM_BOOT_IMAGE_MAJOR_VERSION
Current boot image major version.
Definition: EncoreBootImage.h:117
elftosb::EncoreBootImage::JumpCommand::m_stackPointer
uint32_t m_stackPointer
Stack pointer for "jump sp" command.
Definition: EncoreBootImage.h:880
elftosb::EncoreBootImage::ModeCommand
Change boot mode bootloader command.
Definition: EncoreBootImage.h:663
elftosb::EncoreBootImage::BootCommand::BootCommand
BootCommand()
Default constructor.
Definition: EncoreBootImage.h:394
elftosb::EncoreBootImage::ROM_LOAD_CMD
Load data command.
Definition: EncoreBootImage.h:266
elftosb::EncoreBootImage::boot_image_header_t::m_majorVersion
uint8_t m_majorVersion
Major version for the image format, see ROM_BOOT_IMAGE_MAJOR_VERSION.
Definition: EncoreBootImage.h:162
elftosb::EncoreBootImage::m_keys
key_list_t m_keys
List of key encryption keys. If empty, the image is unencrypted.
Definition: EncoreBootImage.h:1260
elftosb::EncoreBootImage::BootSection
A bootable section of an Encore boot image.
Definition: EncoreBootImage.h:1072
elftosb::EncoreBootImage::ROM_IMAGE_HEADER_SIGNATURE
Signature in elftosb::EncoreBootImage::boot_image_header_t::m_signature.
Definition: EncoreBootImage.h:113
elftosb::EncoreBootImage::ROM_MEM_SPACE_IFR
IFR memory.
Definition: EncoreBootImage.h:340
elftosb::EncoreBootImage::section_list_t
std::list< Section * > section_list_t
List of image sections.
Definition: EncoreBootImage.h:1185
elftosb::EncoreBootImage::ROM_MEM_SPACE_SHIFT
Bit position of mem space ID.
Definition: EncoreBootImage.h:315
elftosb::EncoreBootImage::ROM_RESET_CMD
Reset command.
Definition: EncoreBootImage.h:272
elftosb::EncoreBootImage::ROM_FILL_WORD
Fill with word sized pattern.
Definition: EncoreBootImage.h:294
elftosb::EncoreBootImage::section_header_t::m_tag
uint32_t m_tag
Unique identifier for this section. High bit must be zero.
Definition: EncoreBootImage.h:211
elftosb::EncoreBootImage::CallCommand
Call function bootloader command.
Definition: EncoreBootImage.h:890
elftosb::EncoreBootImage::FillCommand::m_count
uint32_t m_count
Number of bytes to fill.
Definition: EncoreBootImage.h:656
elftosb::EncoreBootImage::ROM_TAG_CMD
Section tag command.
Definition: EncoreBootImage.h:265
elftosb::EncoreBootImage::TagCommand::TagCommand
TagCommand()
Default constructor.
Definition: EncoreBootImage.h:511
elftosb::EncoreBootImage::boot_image_header_t::m_sectionCount
uint16_t m_sectionCount
Number of section headers in this table.
Definition: EncoreBootImage.h:171
smart_array_ptr< uint8_t >
elftosb::EncoreBootImage::Section::m_image
EncoreBootImage * m_image
The image to which this section belongs.
Definition: EncoreBootImage.h:1063
elftosb::EncoreBootImage::LoadCommand::m_length
uint32_t m_length
Number of bytes to load.
Definition: EncoreBootImage.h:606
elftosb::EncoreBootImage::ROM_ERASE_ALL_MASK
Erase all flash instead of just a range.
Definition: EncoreBootImage.h:321
elftosb::EncoreBootImage::m_sections
section_list_t m_sections
Sections contained in this image.
Definition: EncoreBootImage.h:1259
elftosb::EncoreBootImage::boot_image_header_t::m_keyDictionaryBlock
uint16_t m_keyDictionaryBlock
Starting block number for the key dictionary.
Definition: EncoreBootImage.h:169
elftosb::EncoreBootImage::ProgramCommand::m_dataWord2
uint32_t m_dataWord2
Second 4 bytes to write, valid if m_doEightByte is true.
Definition: EncoreBootImage.h:825
elftosb::EncoreBootImage::Section::Section
Section(uint32_t identifier)
Constructor taking the unique identifier for this section.
Definition: EncoreBootImage.h:1004
elftosb::EncoreBootImage::boot_image_header_t::m_padding1
uint8_t m_padding1[6]
Padding to round up to next cipher block.
Definition: EncoreBootImage.h:180
elftosb::EncoreBootImage::boot_image_header_t::m_minorVersion
uint8_t m_minorVersion
Minor version of the boot image format, see ROM_BOOT_IMAGE_MINOR_VERSION.
Definition: EncoreBootImage.h:163
elftosb::EncoreBootImage::boot_command_t::m_count
uint32_t m_count
Number of bytes on which to operate.
Definition: EncoreBootImage.h:255
elftosb::EncoreBootImage::FillCommand::m_pattern
uint32_t m_pattern
Fill pattern.
Definition: EncoreBootImage.h:657
elftosb::EncoreBootImage::key_iterator_t
key_list_t::iterator key_iterator_t
Iterator over KEKs.
Definition: EncoreBootImage.h:1190
elftosb::EncoreBootImage::getImageSize
uint32_t getImageSize()
Calculates the total number of cipher blocks the image consumes.
Definition: EncoreBootImage.cpp:488
elftosb::EncoreBootImage::ResetCommand::ResetCommand
ResetCommand()
Default constructor.
Definition: EncoreBootImage.h:912
elftosb::EncoreBootImage::EraseCommand::EraseCommand
EraseCommand()
Default constructor.
Definition: EncoreBootImage.h:704
elftosb::EncoreBootImage::BootCommand::~BootCommand
virtual ~BootCommand()
Destructor.
Definition: EncoreBootImage.h:400
elftosb::EncoreBootImage::ProgramCommand::m_index
uint32_t m_index
Index to write to.
Definition: EncoreBootImage.h:823
elftosb::EncoreBootImage::Section::m_identifier
uint32_t m_identifier
Unique identifier for this section.
Definition: EncoreBootImage.h:1062
elftosb::EncoreBootImage
Class to manage Encore boot image files.
Definition: EncoreBootImage.h:101
elftosb::EncoreBootImage::const_section_iterator_t
section_list_t::const_iterator const_section_iterator_t
Const iterator over sections.
Definition: EncoreBootImage.h:1187
elftosb::EncoreBootImage::JumpCommand::m_address
uint32_t m_address
Address of the code to execute.
Definition: EncoreBootImage.h:878
elftosb::EncoreBootImage::MemEnableCommand
Memory Enable bootloader command.
Definition: EncoreBootImage.h:937
elftosb::EncoreBootImage::TagCommand::m_isLast
bool m_isLast
Is this the last tag command?
Definition: EncoreBootImage.h:545
elftosb::EncoreBootImage::ROM_FILL_BYTE
Fill with byte sized pattern.
Definition: EncoreBootImage.h:292
elftosb::EncoreBootImage::setDriveTag
virtual void setDriveTag(uint16_t tag)
Specify the drive tag to be set in the output file header.
Definition: EncoreBootImage.h:1239
elftosb::EncoreBootImage::dek_dictionary_entry_t
Entry in elftosb::EncoreBootImage::dek_dictionary_t.
Definition: EncoreBootImage.h:187
elftosb::EncoreBootImage::section_header_t
Information about each section, held in the section table.
Definition: EncoreBootImage.h:209
elftosb::EncoreBootImage::key_list_t
std::vector< AES128Key > key_list_t
List of KEKs.
Definition: EncoreBootImage.h:1189
elftosb::EncoreBootImage::m_driveTag
uint16_t m_driveTag
System drive tag for this boot image.
Definition: EncoreBootImage.h:1258
elftosb::EncoreBootImage::BOOT_IMAGE_MINIMUM_SECTION_ALIGNMENT
Minimum alignment for a section is 16 bytes.
Definition: EncoreBootImage.h:124
elftosb::EncoreBootImage::ROM_ERASE_CMD
Flash erase command.
Definition: EncoreBootImage.h:271
elftosb::EncoreBootImage::DataSection
A non-bootable section of an Encore boot image.
Definition: EncoreBootImage.h:1142
elftosb::EncoreBootImage::ProgramCommand::m_isEightByte
bool m_isEightByte
True if doing 8-byte write.
Definition: EncoreBootImage.h:822
elftosb::EncoreBootImage::ROM_PROG_8BYTE_MASK
Program 8 bytes instead of 4 bytes.
Definition: EncoreBootImage.h:328
elftosb::EncoreBootImage::m_componentVersion
version_t m_componentVersion
Component version.
Definition: EncoreBootImage.h:1257
elftosb::EncoreBootImage::ROM_HAB_EXEC
Changes jump or call command to a HAB jump or call.
Definition: EncoreBootImage.h:300
elftosb::EncoreBootImage::getSectionOffset
uint32_t getSectionOffset(Section *section)
Calculates the starting block number for the given section.
Definition: EncoreBootImage.cpp:430
elftosb::EncoreBootImage::getPadBlockCountForSection
unsigned getPadBlockCountForSection(Section *section, unsigned offset)
Definition: EncoreBootImage.cpp:464
elftosb::EncoreBootImage::isEncrypted
bool isEncrypted() const
The image is encrypted if there is at least one key.
Definition: EncoreBootImage.h:1223
elftosb::EncoreBootImage::m_productVersion
version_t m_productVersion
Product version.
Definition: EncoreBootImage.h:1256
elftosb::EncoreBootImage::dek_dictionary_entry_t::m_dek
aes128_key_t m_dek
AES-128 key with which the image payload is encrypted.
Definition: EncoreBootImage.h:190
elftosb::EncoreBootImage::ROM_FILL_HALF_WORD
Fill with half-word sized pattern.
Definition: EncoreBootImage.h:293
elftosb::EncoreBootImage::CipherBlockGenerator::debugPrint
virtual void debugPrint() const
Print out a string representation of the object.
Definition: EncoreBootImage.h:380
elftosb::EncoreBootImage::CipherBlockGenerator
Base class for objects that produce cipher blocks.
Definition: EncoreBootImage.h:350
elftosb::EncoreBootImage::ROM_DISPLAY_PROGRESS
Print progress reports.
Definition: EncoreBootImage.h:107
elftosb::EncoreBootImage::DataSection::DataSection
DataSection()
Default constructor.
Definition: EncoreBootImage.h:1146
elftosb::EncoreBootImage::ProgramCommand::ProgramCommand
ProgramCommand()
Default constructor.
Definition: EncoreBootImage.h:767
elftosb
Definition: BootImage.h:13
elftosb::EncoreBootImage::ROM_PROG_CMD
Program persistent bits command.
Definition: EncoreBootImage.h:274
elftosb::EncoreBootImage::boot_image_header_t::m_driveTag
uint16_t m_driveTag
Drive tag for the system drive which this boot image belongs to.
Definition: EncoreBootImage.h:179
elftosb::EncoreBootImage::Section::getAlignment
unsigned getAlignment() const
Returns the current alignment, the minimum of which will be 16.
Definition: EncoreBootImage.h:1048
elftosb::EncoreBootImage::EraseCommand
Erase bootloader command.
Definition: EncoreBootImage.h:700
elftosb::EncoreBootImage::boot_image_header_t::m_signature
uint8_t m_signature[4]
&#39;STMP&#39;, see ROM_IMAGE_HEADER_SIGNATURE.
Definition: EncoreBootImage.h:161
elftosb::EncoreBootImage::boot_image_header_t::m_componentVersion
version_t m_componentVersion
Component version.
Definition: EncoreBootImage.h:178
elftosb::EncoreBootImage::boot_command_t
Structure for a Piano bootloader command.
Definition: EncoreBootImage.h:249
elftosb::EncoreBootImage::Section::getFlags
virtual uint32_t getFlags() const
Returns the flags for this section.
Definition: EncoreBootImage.h:1029
elftosb::EncoreBootImage::JumpCommand::m_argument
uint32_t m_argument
Sole argument to pass to code.
Definition: EncoreBootImage.h:879
elftosb::EncoreBootImage::BootCommand
Abstract base class for all bootloader commands.
Definition: EncoreBootImage.h:386
elftosb::EncoreBootImage::ProgramCommand::m_memSpace
uint32_t m_memSpace
ID of memory space, e.g. 1=IFR0.
Definition: EncoreBootImage.h:826
elftosb::EncoreBootImage::ROM_VERBOSE_PROGRESS
Progress reports are verbose.
Definition: EncoreBootImage.h:108
elftosb::EncoreBootImage::const_key_iterator_t
key_list_t::const_iterator const_key_iterator_t
Const iterator over KEKs.
Definition: EncoreBootImage.h:1191
elftosb::EncoreBootImage::boot_image_header_t::m_productVersion
version_t m_productVersion
Product version.
Definition: EncoreBootImage.h:177
elftosb::EncoreBootImage::JumpCommand::m_ivtSize
uint32_t m_ivtSize
Whether this jump call has an initial stack pointer set.
Definition: EncoreBootImage.h:884
elftosb::EncoreBootImage::LoadCommand::m_loadDCD
bool m_loadDCD
Whether to execute the DCD after loading.
Definition: EncoreBootImage.h:608
elftosb::EncoreBootImage::NopCommand
No operation bootloader command.
Definition: EncoreBootImage.h:480
elftosb::EncoreBootImage::dek_dictionary_entry_t::m_mac
cipher_block_t m_mac
CBC-MAC of the header.
Definition: EncoreBootImage.h:189
elftosb::EncoreBootImage::Section::getImage
EncoreBootImage * getImage() const
Returns a pointer to the image that this section belongs to.
Definition: EncoreBootImage.h:1039
elftosb::EncoreBootImage::ROM_LAST_TAG
This tag command is the last one in the image.
Definition: EncoreBootImage.h:280
elftosb::EncoreBootImage::TagCommand::m_sectionIdentifier
uint32_t m_sectionIdentifier
Unique identifier for the section containing this command.
Definition: EncoreBootImage.h:542
elftosb::EncoreBootImage::Section::m_leaveUnencrypted
bool m_leaveUnencrypted
Set to true to prevent this section from being encrypted.
Definition: EncoreBootImage.h:1066
elftosb::EncoreBootImage::boot_image_header_t::m_padding0
uint8_t m_padding0[2]
Padding to align m_timestamp to long word.
Definition: EncoreBootImage.h:173
elftosb::EncoreBootImage::ROM_ERASE_ALL_UNSECURE_MASK
Erase all unsecure (available on some Kinetis parts).
Definition: EncoreBootImage.h:322
elftosb::EncoreBootImage::BootSection::BootSection
BootSection(uint32_t identifier)
Constructor taking the unique identifier for this section.
Definition: EncoreBootImage.h:1087
elftosb::EncoreBootImage::ROM_SECTION_BOOTABLE
The section contains bootloader commands.
Definition: EncoreBootImage.h:202
elftosb::EncoreBootImage::BootSection::m_commands
command_list_t m_commands
Commands held in this section.
Definition: EncoreBootImage.h:1132
elftosb::EncoreBootImage::ROM_MODE_CMD
Change boot mode command.
Definition: EncoreBootImage.h:270
AESKey< 128 >
elftosb::EncoreBootImage::debugPrint
virtual void debugPrint() const
Print out a string representation of the object.
Definition: EncoreBootImage.cpp:513
elftosb::EncoreBootImage::boot_image_header_t::m_keyCount
uint16_t m_keyCount
Number of entries in DEK dictionary.
Definition: EncoreBootImage.h:168
elftosb::EncoreBootImage::Section::getLeaveUnencrypted
bool getLeaveUnencrypted() const
Returns true if the section will remain unencrypted.
Definition: EncoreBootImage.h:1058
elftosb::EncoreBootImage::Section::m_flags
uint32_t m_flags
Section flags set by the user.
Definition: EncoreBootImage.h:1065
elftosb::EncoreBootImage::ROM_MEM_CTRL_SHIFT
Bit position of mem controller ID.
Definition: EncoreBootImage.h:308
elftosb::EncoreBootImage::BootSection::BootSection
BootSection()
Default constructor.
Definition: EncoreBootImage.h:1081
elftosb::EncoreBootImage::addSection
void addSection(Section *newSection)
Definition: EncoreBootImage.cpp:43
elftosb::EncoreBootImage::ROM_MEM_ENABLE_CMD
Memory Enable command.
Definition: EncoreBootImage.h:273
elftosb::EncoreBootImage::Section::Section
Section()
Default constructor.
Definition: EncoreBootImage.h:993
elftosb::EncoreBootImage::LoadCommand::m_padCount
unsigned m_padCount
Number of pad bytes.
Definition: EncoreBootImage.h:605
elftosb::EncoreBootImage::section_table_t
An index of all sections within the boot image.
Definition: EncoreBootImage.h:235
elftosb::EncoreBootImage::ProgramCommand::m_dataWord1
uint32_t m_dataWord1
First 4 bytes to write.
Definition: EncoreBootImage.h:824
elftosb::EncoreBootImage::section_iterator_t
section_list_t::iterator section_iterator_t
Iterator over sections.
Definition: EncoreBootImage.h:1186
elftosb::EncoreBootImage::ROM_MEM_SPACE_MASK
Bit mask for mem space ID.
Definition: EncoreBootImage.h:314
elftosb::BootImage
Abstract base class for all boot image format classes.
Definition: BootImage.h:25
elftosb::EncoreBootImage::BootCommand::getDataBlocks
virtual unsigned getDataBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data)
Returns the contents of up to maxCount data blocks.
Definition: EncoreBootImage.h:459
elftosb::EncoreBootImage::FillCommand
Pattern fill bootloader command.
Definition: EncoreBootImage.h:617
elftosb::EncoreBootImage::ModeCommand::m_mode
uint32_t m_mode
New boot mode.
Definition: EncoreBootImage.h:694
elftosb::EncoreBootImage::ProgramCommand
Program persistent bits bootloader command.
Definition: EncoreBootImage.h:763
elftosb::EncoreBootImage::section_header_t::m_length
uint32_t m_length
Size of section data in blocks.
Definition: EncoreBootImage.h:213
elftosb::EncoreBootImage::LoadCommand::m_data
smart_array_ptr< uint8_t > m_data
Pointer to data to load.
Definition: EncoreBootImage.h:603
elftosb::EncoreBootImage::ROM_JUMP_SP_MASK
Initial stack pointer is specified for jump command.
Definition: EncoreBootImage.h:301
elftosb::EncoreBootImage::boot_image_header_t::m_flags
uint16_t m_flags
Flags or options associated with the entire image.
Definition: EncoreBootImage.h:164
elftosb::EncoreBootImage::FillCommand::m_address
uint32_t m_address
Fill start address.
Definition: EncoreBootImage.h:655
elftosb::EncoreBootImage::ROM_SECTION_CLEARTEXT
The section is unencrypted. Applies only if the rest of the boot image is encrypted.
Definition: EncoreBootImage.h:203
elftosb::EncoreBootImage::JumpCommand
Jump to address bootloader command.
Definition: EncoreBootImage.h:832
elftosb::EncoreBootImage::getTimestamp
uint64_t getTimestamp()
Definition: EncoreBootImage.cpp:394
elftosb::version_t
Same version struct used for 3600 boot image.
Definition: Version.h:16
elftosb::EncoreBootImage::DataSection::m_data
smart_array_ptr< uint8_t > m_data
The section&#39;s contents.
Definition: EncoreBootImage.h:1180
elftosb::EncoreBootImage::ResetCommand
Reset target bootloader command.
Definition: EncoreBootImage.h:908
elftosb::EncoreBootImage::NopCommand::NopCommand
NopCommand()
Default constructor.
Definition: EncoreBootImage.h:484
elftosb::EncoreBootImage::JumpCommand::JumpCommand
JumpCommand()
Default constructor.
Definition: EncoreBootImage.h:836
elftosb::EncoreBootImage::CallCommand::CallCommand
CallCommand()
Default constructor.
Definition: EncoreBootImage.h:894
elftosb::EncoreBootImage::LoadCommand
Load data bootloader command.
Definition: EncoreBootImage.h:551
elftosb::EncoreBootImage::boot_image_header_t::m_signature2
uint8_t m_signature2[4]
Definition: EncoreBootImage.h:174
elftosb::EncoreBootImage::TagCommand::m_sectionFlags
uint32_t m_sectionFlags
Flags pertaining to this section.
Definition: EncoreBootImage.h:544
elftosb::EncoreBootImage::BootSection::getCommandCount
unsigned getCommandCount() const
Returns the number of commands in this section, excluding the tag command.
Definition: EncoreBootImage.h:1112
elftosb::EncoreBootImage::CallCommand::getTag
virtual uint8_t getTag() const
Returns the tag value for this command.
Definition: EncoreBootImage.h:900
elftosb::EncoreBootImage::LoadCommand::m_address
uint32_t m_address
Address to which data will be loaded.
Definition: EncoreBootImage.h:607
elftosb::EncoreBootImage::boot_command_t::m_flags
uint16_t m_flags
Flags for this command.
Definition: EncoreBootImage.h:253
elftosb::EncoreBootImage::section_header_t::m_offset
uint32_t m_offset
Offset to section data from start of image in blocks.
Definition: EncoreBootImage.h:212
elftosb::EncoreBootImage::boot_image_header_t
Header for the entire boot image.
Definition: EncoreBootImage.h:150
elftosb::EncoreBootImage::getFileExtension
virtual std::string getFileExtension() const
Returns the preferred ".sb" extension for Encore boot images.
Definition: EncoreBootImage.h:1244
elftosb::EncoreBootImage::writeToStream
virtual void writeToStream(std::ostream &stream)
Write the boot image to an output stream.
Definition: EncoreBootImage.cpp:84
elftosb::EncoreBootImage::boot_command_t::m_tag
uint8_t m_tag
Tag telling which command this is.
Definition: EncoreBootImage.h:252
elftosb::EncoreBootImage::boot_command_t::m_data
uint32_t m_data
Additional data used by certain commands.
Definition: EncoreBootImage.h:256
elftosb::EncoreBootImage::findFirstBootableSection
Section * findFirstBootableSection()
Definition: EncoreBootImage.cpp:410
elftosb::EncoreBootImage::CipherBlockGenerator::getBlocks
virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data)
Returns the contents of up to maxCount cipher blocks.
Definition: EncoreBootImage.h:376
elftosb::EncoreBootImage::ModeCommand::ModeCommand
ModeCommand()
Default constructor.
Definition: EncoreBootImage.h:667
elftosb::EncoreBootImage::JumpCommand::m_isHAB
bool m_isHAB
Definition: EncoreBootImage.h:881
elftosb::EncoreBootImage::boot_image_header_t::m_sectionHeaderSize
uint16_t m_sectionHeaderSize
Size in blocks of a section header.
Definition: EncoreBootImage.h:172
elftosb::EncoreBootImage::ROM_LOAD_DCD
Execute the DCD after loading completes.
Definition: EncoreBootImage.h:286
elftosb::EncoreBootImage::ROM_MEM_ID_QSPI
External QuadSpi controller.
Definition: EncoreBootImage.h:334
elftosb::EncoreBootImage::boot_image_header_t::m_headerBlocks
uint16_t m_headerBlocks
Size of this header, including this size word, in blocks.
Definition: EncoreBootImage.h:170
elftosb::EncoreBootImage::boot_image_header_t::m_imageBlocks
uint32_t m_imageBlocks
Size of entire image in blocks.
Definition: EncoreBootImage.h:165
elftosb::EncoreBootImage::ROM_BOOT_IMAGE_MINOR_VERSION
Current boot image minor version.
Definition: EncoreBootImage.h:118
elftosb::EncoreBootImage::boot_command_t::m_address
uint32_t m_address
Target address.
Definition: EncoreBootImage.h:254
elftosb::EncoreBootImage::DataSection::m_length
unsigned m_length
Number of bytes of data.
Definition: EncoreBootImage.h:1181
elftosb::EncoreBootImage::section_header_t::m_flags
uint32_t m_flags
Section flags.
Definition: EncoreBootImage.h:214
elftosb::EncoreBootImage::boot_image_header_t::m_timestamp
uint64_t m_timestamp
Timestamp when image was generated in microseconds since 1-1-2000.
Definition: EncoreBootImage.h:176
elftosb::EncoreBootImage::boot_command_t::m_checksum
uint8_t m_checksum
Simple checksum over other command fields.
Definition: EncoreBootImage.h:251
elftosb::EncoreBootImage::ROM_NOP_CMD
A no-op command.
Definition: EncoreBootImage.h:264
elftosb::EncoreBootImage::ROM_MEM_CTRL_MASK
Bit mask for mem controller ID.
Definition: EncoreBootImage.h:307