Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
elftosbTool Class Reference

Class that encapsulates the elftosb tool. More...

+ Collaboration diagram for elftosbTool:

Classes

struct  FamilyNameTableEntry
 A structure describing an entry in the table of chip family names. More...
 

Public Member Functions

 elftosbTool (int argc, char *argv[])
 
 ~elftosbTool ()
 
bool lookupFamilyName (const char *name, chip_family_t *family)
 Searches the family name table. More...
 
int processOptions ()
 
void printUsage (Options &options)
 
int run ()
 Core of the tool. More...
 
void checkArguments ()
 Validate arguments that can be checked.

Exceptions
std::runtime_errorThrown if an argument value fails to pass validation.

 
void setVerboseLogging ()
 Turns on verbose logging.
 
uint32_t parseIntValue (const char *value)
 Returns the integer value for a string. More...
 
void overrideVariable (const char *optarg)
 Parses the -D option to override a constant value.
 
void overrideOption (const char *optarg)
 
void convert ()
 Do the conversion.

Exceptions
std::runtime_errorThis exception is thrown if the conversion controller does not produce a boot image, or if the output file cannot be opened. Other errors internal to the conversion controller may also produce this exception.

 
void addCryptoKeys (elftosb::EncoreBootImage *encoreImage)
 
void generateKeyFile (const std::string &path)
 Opens the file at path and writes a random key file. More...
 
void dumpKey (const AESKey< 128 > &key)
 Write the value of each byte of the key to the log.
 
void readBootImage ()
 Opens and reads the boot image identified on the command line. More...
 
void extractSection (EncoreBootImage::Section *section)
 Dumps the contents of a section to stdout. More...
 
bool compareDigests (const sha1_digest_t &a, const sha1_digest_t &b)
 Compares two SHA-1 digests and returns whether they are equal. More...
 
void dumpImageHeader (const EncoreBootImage::boot_image_header_t &header)
 
void dumpSectionHeader (const EncoreBootImage::section_header_t &header)
 
void logHexArray (Logger::log_level_t level, const uint8_t *bytes, unsigned count)
 Log an array of bytes as hex.
 

Protected Types

enum  chip_family_t {
  k37xxFamily,
  kMX28Family,
  kKinetisFamily
}
 Supported chip families. More...
 

Protected Attributes

int m_argc
 Number of command line arguments.
 
char ** m_argv
 String value for each command line argument.
 
StdoutLoggerm_logger
 Singleton logger instance.
 
string_vector_t m_keyFilePaths
 Paths to OTP key files.
 
string_vector_t m_positionalArgs
 Arguments coming after explicit options.
 
bool m_isVerbose
 Whether the verbose flag was turned on.
 
bool m_useDefaultKey
 Include a default (zero) crypto key.
 
const char * m_commandFilePath
 Path to the elftosb command file.
 
const char * m_outputFilePath
 Path to the output .sb file.
 
const char * m_searchPath
 Optional search path for input files.
 
elftosb::version_t m_productVersion
 Product version specified on command line.
 
elftosb::version_t m_componentVersion
 Component version specified on command line.
 
bool m_productVersionSpecified
 True if the product version was specified on the command line.
 
bool m_componentVersionSpecified
 True if the component version was specified on the command line.
 
chip_family_t m_family
 Chip family that the output file is formatted for.
 
elftosb::ConversionController m_controller
 Our conversion controller instance.
 
bool m_doElftoSB
 True if generating SB file.
 
bool m_doKeygen
 Whether to generate the key file.
 
int m_keyCount
 Number of keys to generate.
 
bool m_doExtract
 True if extract mode is on.
 
int32_t m_sectionIndex
 Index of section to extract.
 
bool m_extractBinary
 True if extraction output is binary, false for hex.
 
smart_ptr< EncoreBootImageReaderm_reader
 Boot image reader object.
 

Static Protected Attributes

static const FamilyNameTableEntry kFamilyNameTable []
 Table that maps from family name strings to chip family constants. More...
 

Detailed Description

Class that encapsulates the elftosb tool.

A single global logger instance is created during object construction. It is never freed because we need it up to the last possible minute, when an exception could be thrown.


Class Documentation

struct elftosbTool::FamilyNameTableEntry

A structure describing an entry in the table of chip family names.

Class Members
chip_family_t family
const char *const name

Member Enumeration Documentation

Supported chip families.

Enumerator
k37xxFamily 

37xx series.

kMX28Family 

Catskills series.

kKinetisFamily 

Kinetis devices.

Constructor & Destructor Documentation

elftosbTool::elftosbTool ( int  argc,
char *  argv[] 
)
inline

Constructor.

Creates the singleton logger instance.

elftosbTool::~elftosbTool ( )
inline

Destructor.

Member Function Documentation

bool elftosbTool::compareDigests ( const sha1_digest_t &  a,
const sha1_digest_t &  b 
)
inline

Compares two SHA-1 digests and returns whether they are equal.

Return values
trueThe two digests are equal.
falseThe a and b digests are different from each other.
void elftosbTool::extractSection ( EncoreBootImage::Section section)
inline

Dumps the contents of a section to stdout.

If m_extractBinary is true then the contents are written as raw binary to stdout. Otherwise the data is formatted using logHexArray().

void elftosbTool::generateKeyFile ( const std::string &  path)
inline

Opens the file at path and writes a random key file.

Each key file will have m_keyCount number of keys written into it, each on a line by itself.

bool elftosbTool::lookupFamilyName ( const char *  name,
chip_family_t family 
)
inline

Searches the family name table.

Return values
trueThe name was found in the table, and family is valid.
falseNo matching family name was found. The family argument is not modified.
uint32_t elftosbTool::parseIntValue ( const char *  value)
inline

Returns the integer value for a string.

Metric multiplier prefixes are supported.

void elftosbTool::printUsage ( Options options)
inline

Prints help for the tool.

int elftosbTool::processOptions ( )
inline

Reads the command line options passed into the constructor.

This method can return a return code to its caller, which will cause the tool to exit immediately with that return code value. Normally, though, it will return -1 to signal that the tool should continue to execute and all options were processed successfully.

The Options class is used to parse command line options. See #k_optionsDefinition for the list of options and #k_usageText for the descriptive help for each option.

Return values
-1The options were processed successfully. Let the tool run normally.
Returns
A zero or positive result is a return code value that should be returned from the tool as it exits immediately.
void elftosbTool::readBootImage ( )
inline

Opens and reads the boot image identified on the command line.

Precondition
At least one position argument must be present.
int elftosbTool::run ( )
inline

Core of the tool.

Calls processOptions() to handle command line options before performing the real work the tool does.

Member Data Documentation

const elftosbTool::FamilyNameTableEntry elftosbTool::kFamilyNameTable
staticprotected
Initial value:
= { { "37xx", k37xxFamily },
{ "377x", k37xxFamily },
{ "378x", k37xxFamily },
{ "mx23", k37xxFamily },
{ "imx23", k37xxFamily },
{ "i.mx23", k37xxFamily },
{ "mx28", kMX28Family },
{ "imx28", kMX28Family },
{ "i.mx28", kMX28Family },
{ "kinetis", kKinetisFamily },
{ NULL, k37xxFamily } }

Table that maps from family name strings to chip family constants.


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