ConversionController.h
/*
* File: ConversionController.h
*
* Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
* See included license file for license details.
*/
#if !defined(_ConversionController_h_)
#define _ConversionController_h_
#include <iostream>
#include <fstream>
#include <string>
#include <stdexcept>
#include "smart_ptr.h"
#include "ElftosbLexer.h"
#include "ElftosbAST.h"
#include "EvalContext.h"
#include "Value.h"
#include "SourceFile.h"
#include "Operation.h"
#include "DataSource.h"
#include "DataTarget.h"
#include "OutputSection.h"
#include "BootImage.h"
#include "OptionDictionary.h"
#include "BootImageGenerator.h"
#include "Keyblob.h"
namespace elftosb
{
class ConversionController : public OptionDictionary, public EvalContext::SourceFileManager
{
public:
ConversionController();
virtual ~ConversionController();
void setCommandFilePath(const std::string &path);
void addExternalFilePath(const std::string &path);
void run();
BootImage *generateOutput(BootImageGenerator *generator);
virtual bool hasSourceFile(const std::string &name);
virtual SourceFile *getSourceFile(const std::string &name);
virtual SourceFile *getDefaultSourceFile();
inline EvalContext &getEvalContext() { return m_context; }
protected:
void parseCommandFile();
void processOptions(ListASTNode *options);
void processConstants(ListASTNode *constants);
void processSources(ListASTNode *sources);
void processKeyblob(ExprASTNode *idExpr, ListASTNode *entires);
void processSections(ListASTNode *sections);
OutputSection *convertDataSection(DataSectionContentsASTNode *dataSection,
uint32_t sectionID,
OptionDictionary *optionsDict);
OperationSequence *convertStatementList(ListASTNode *statements);
OperationSequence *convertOneStatement(StatementASTNode *statement);
OperationSequence *convertLoadStatement(LoadStatementASTNode *statement);
OperationSequence *convertCallStatement(CallStatementASTNode *statement);
OperationSequence *convertFromStatement(FromStatementASTNode *statement);
OperationSequence *convertModeStatement(ModeStatementASTNode *statement);
OperationSequence *convertResetStatement(ResetStatementASTNode *statement);
OperationSequence *convertIfStatement(IfStatementASTNode *statement);
OperationSequence *convertEraseStatement(EraseStatementASTNode *statement);
OperationSequence *convertMemEnableStatement(MemEnableStatementASTNode *statement);
OperationSequence *convertKeywrapStatement(KeywrapStatementASTNode *statement);
OperationSequence *convertEncryptStatement(EncryptStatementASTNode *statement);
void handleMessageStatement(MessageStatementASTNode *statement);
Value *convertAssignmentNodeToValue(ASTNode *node, std::string &ident);
SourceFile *getSourceFromName(std::string *sourceName, int line);
DataSource *createSourceFromNode(ASTNode *dataNode);
DataTarget *createTargetFromNode(ASTNode *targetNode);
std::string *substituteVariables(const std::string *message);
DataSource *createIVTDataSource(IVTConstASTNode *ivtNode);
void testLexer(ElftosbLexer &lexer);
void printIntConstExpr(const std::string &ident, IntConstExprASTNode *expr);
protected:
typedef std::map<std::string, SourceFile *> source_map_t;
typedef std::vector<std::string> path_vector_t;
typedef std::vector<OutputSection *> section_vector_t;
typedef std::vector<std::string> source_name_vector_t;
typedef std::vector<Keyblob *> keyblob_vector_t;
smart_ptr<std::string> m_commandFilePath;
smart_ptr<CommandFileASTNode> m_ast;
EvalContext m_context;
source_map_t m_sources;
path_vector_t m_externPaths;
SourceFile *m_defaultSource;
section_vector_t m_outputSections;
source_name_vector_t m_failedSources;
keyblob_vector_t m_keyblobs;
Keyblob *m_keywrapKeyblob;
Keyblob *m_encryptKeyblob;
};
extern bool g_enableHABSupport;
}; // namespace elftosb
#endif // _ConversionController_h_
elftosb::ConversionController::m_ast
smart_ptr< CommandFileASTNode > m_ast
Root of the abstract syntax tree.
Definition: ConversionController.h:144
elftosb::DataSource
Abstract base class for data sources.
Definition: apps/elftosb/common/DataSource.h:33
elftosb::ConversionController::convertOneStatement
OperationSequence * convertOneStatement(StatementASTNode *statement)
Definition: ConversionController.cpp:714
elftosb::ConversionController::convertKeywrapStatement
OperationSequence * convertKeywrapStatement(KeywrapStatementASTNode *statement)
Definition: ConversionController.cpp:1042
elftosb::OperationSequence
Ordered sequence of operations.
Definition: Operation.h:323
elftosb::ConversionController::processConstants
void processConstants(ListASTNode *constants)
Definition: ConversionController.cpp:269
elftosb::ConversionController::getDefaultSourceFile
virtual SourceFile * getDefaultSourceFile()
Returns the default source file, or NULL if none is set.
Definition: ConversionController.cpp:88
elftosb::IntConstExprASTNode
Definition: ElftosbAST.h:329
elftosb::ConversionController::processOptions
void processOptions(ListASTNode *options)
Definition: ConversionController.cpp:236
elftosb::EncryptStatementASTNode
Definition: ElftosbAST.h:1420
elftosb::ConversionController::convertIfStatement
OperationSequence * convertIfStatement(IfStatementASTNode *statement)
Definition: ConversionController.cpp:1180
elftosb::StatementASTNode
Definition: ElftosbAST.h:882
elftosb::ConversionController::handleMessageStatement
void handleMessageStatement(MessageStatementASTNode *statement)
Definition: ConversionController.cpp:1403
elftosb::ConversionController::keyblob_vector_t
std::vector< Keyblob * > keyblob_vector_t
List of keyblobs.
Definition: ConversionController.h:141
elftosb::IVTConstASTNode
Node for a constant IVT structure as used by HAB4.
Definition: ElftosbAST.h:691
elftosb::ConversionController::createTargetFromNode
DataTarget * createTargetFromNode(ASTNode *targetNode)
Definition: ConversionController.cpp:1737
smart_ptr< std::string >
elftosb::ConversionController::generateOutput
BootImage * generateOutput(BootImageGenerator *generator)
Uses a BootImageGenerator object to create the final output boot image.
Definition: ConversionController.cpp:1536
elftosb::ConversionController::hasSourceFile
virtual bool hasSourceFile(const std::string &name)
Returns true if a source file with the name name exists.
Definition: ConversionController.cpp:73
elftosb::FromStatementASTNode
Definition: ElftosbAST.h:1394
elftosb::ConversionController::setCommandFilePath
void setCommandFilePath(const std::string &path)
Specify the command file that controls the conversion process.
Definition: ConversionController.cpp:60
elftosb::IfStatementASTNode
Definition: ElftosbAST.h:900
elftosb::ConversionController::section_vector_t
std::vector< OutputSection * > section_vector_t
List of output sections.
Definition: ConversionController.h:139
elftosb::ConversionController::m_externPaths
path_vector_t m_externPaths
Paths provided on the command line by the user.
Definition: ConversionController.h:147
elftosb::ConversionController::path_vector_t
std::vector< std::string > path_vector_t
List of file paths.
Definition: ConversionController.h:138
elftosb::OptionDictionary
Concrete implementation of OptionContext.
Definition: OptionDictionary.h:27
elftosb::ConversionController::convertModeStatement
OperationSequence * convertModeStatement(ModeStatementASTNode *statement)
Definition: ConversionController.cpp:1127
elftosb::ConversionController::convertDataSection
OutputSection * convertDataSection(DataSectionContentsASTNode *dataSection, uint32_t sectionID, OptionDictionary *optionsDict)
Definition: ConversionController.cpp:590
elftosb::ConversionController::run
void run()
Process input files.
Definition: ConversionController.cpp:115
elftosb::ConversionController::m_defaultSource
SourceFile * m_defaultSource
Source to use when one isn&#39;t provided.
Definition: ConversionController.h:148
elftosb::EvalContext
Context for evaluating AST tree and expressions.
Definition: EvalContext.h:28
smart_ptr
Simple, standard smart pointer class.
Definition: apps/elftosb/common/smart_ptr.h:18
elftosb::MessageStatementASTNode
Statement to print a message to the elftosb user.
Definition: ElftosbAST.h:1003
elftosb::ConversionController::testLexer
void testLexer(ElftosbLexer &lexer)
Definition: ConversionController.cpp:1885
elftosb::ConversionController::m_outputSections
section_vector_t m_outputSections
List of output sections the user wants.
Definition: ConversionController.h:149
elftosb::ConversionController::parseCommandFile
void parseCommandFile()
Definition: ConversionController.cpp:176
elftosb::ConversionController::m_failedSources
source_name_vector_t m_failedSources
List of sources that failed to open successfully.
Definition: ConversionController.h:150
elftosb::ConversionController::processSources
void processSources(ListASTNode *sources)
Definition: ConversionController.cpp:302
elftosb::ConversionController::convertEncryptStatement
OperationSequence * convertEncryptStatement(EncryptStatementASTNode *statement)
Definition: ConversionController.cpp:1084
elftosb::ConversionController::m_keyblobs
keyblob_vector_t m_keyblobs
List of keyblobs the user defines.
Definition: ConversionController.h:151
elftosb
Definition: BootImage.h:13
elftosb::ConversionController::source_map_t
std::map< std::string, SourceFile * > source_map_t
Map from source name to object.
Definition: ConversionController.h:137
elftosb::SourceFile
Abstract base class for a source file containing executable code.
Definition: apps/elftosb/common/SourceFile.h:33
elftosb::KeywrapStatementASTNode
Definition: ElftosbAST.h:1448
elftosb::EvalContext::SourceFileManager
Abstract interface for a manager of source files.
Definition: EvalContext.h:34
elftosb::DataTarget
Abstract base class for the target address or range of data.
Definition: apps/elftosb/common/DataTarget.h:34
elftosb::Value
Abstract base class for values of arbitrary types.
Definition: apps/elftosb/common/Value.h:20
elftosb::ConversionController::convertFromStatement
OperationSequence * convertFromStatement(FromStatementASTNode *statement)
Definition: ConversionController.cpp:1003
elftosb::ConversionController::convertResetStatement
OperationSequence * convertResetStatement(ResetStatementASTNode *statement)
Creates a Reset Operation object and returns an OperationSequence containing it.
Definition: ConversionController.cpp:1167
elftosb::CallStatementASTNode
AST node for a call statement.
Definition: ElftosbAST.h:1080
elftosb::ConversionController::convertAssignmentNodeToValue
Value * convertAssignmentNodeToValue(ASTNode *node, std::string &ident)
Definition: ConversionController.cpp:625
elftosb::EraseStatementASTNode
Statement to insert a ROM_ERASE_CMD command.
Definition: ElftosbAST.h:960
elftosb::ConversionController::ConversionController
ConversionController()
Default constructor.
Definition: ConversionController.cpp:36
elftosb::ConversionController::convertStatementList
OperationSequence * convertStatementList(ListASTNode *statements)
Definition: ConversionController.cpp:684
elftosb::DataSectionContentsASTNode
Node representing a raw binary section definition.
Definition: ElftosbAST.h:836
elftosb::ConversionController::convertCallStatement
OperationSequence * convertCallStatement(CallStatementASTNode *statement)
Definition: ConversionController.cpp:914
elftosb::Keyblob
Keyblob specification.
Definition: Keyblob.h:27
elftosb::ConversionController
Manages the entire elftosb file conversion process.
Definition: ConversionController.h:48
elftosb::ConversionController::getSourceFile
virtual SourceFile * getSourceFile(const std::string &name)
Gets the requested source file.
Definition: ConversionController.cpp:78
elftosb::ConversionController::getEvalContext
EvalContext & getEvalContext()
Returns a reference to the context used for expression evaluation.
Definition: ConversionController.h:88
elftosb::ConversionController::addExternalFilePath
void addExternalFilePath(const std::string &path)
Specify the path of a file provided by the user from outside the command file.
Definition: ConversionController.cpp:68
elftosb::ConversionController::processKeyblob
void processKeyblob(ExprASTNode *idExpr, ListASTNode *entires)
Definition: ConversionController.cpp:420
elftosb::ConversionController::source_name_vector_t
std::vector< std::string > source_name_vector_t
List of source names.
Definition: ConversionController.h:140
elftosb::ConversionController::m_context
EvalContext m_context
Evaluation context for expressions.
Definition: ConversionController.h:145
elftosb::BootImage
Abstract base class for all boot image format classes.
Definition: BootImage.h:25
elftosb::ConversionController::m_encryptKeyblob
Keyblob * m_encryptKeyblob
Keyblob used for OTFAD encryption.
Definition: ConversionController.h:153
elftosb::MemEnableStatementASTNode
Statement to insert a ROM_MEM_ENABLE_CMD command.
Definition: ElftosbAST.h:1160
elftosb::ExprASTNode
Abstract base class for all expression AST nodes.
Definition: ElftosbAST.h:231
elftosb::ModeStatementASTNode
Statement to insert a ROM_MODE_CMD command.
Definition: ElftosbAST.h:932
elftosb::ConversionController::m_keywrapKeyblob
Keyblob * m_keywrapKeyblob
Keyblob used for keywrapping.
Definition: ConversionController.h:152
elftosb::ConversionController::m_commandFilePath
smart_ptr< std::string > m_commandFilePath
Path to command file.
Definition: ConversionController.h:143
elftosb::ConversionController::createSourceFromNode
DataSource * createSourceFromNode(ASTNode *dataNode)
Definition: ConversionController.cpp:1568
elftosb::ConversionController::convertLoadStatement
OperationSequence * convertLoadStatement(LoadStatementASTNode *statement)
Definition: ConversionController.cpp:810
elftosb::BootImageGenerator
Abstract base class for generators of specific boot image formats.
Definition: BootImageGenerator.h:33
elftosb::ConversionController::~ConversionController
virtual ~ConversionController()
Destructor.
Definition: ConversionController.cpp:47
elftosb::LoadStatementASTNode
AST node for a load statement.
Definition: ElftosbAST.h:1040
elftosb::ListASTNode
AST node that contains other AST nodes.
Definition: ElftosbAST.h:107
elftosb::ResetStatementASTNode
Statement to insert a ROM_RESET_CMD command.
Definition: ElftosbAST.h:1138
elftosb::OutputSection
Base class for data model of sections of the output file.
Definition: OutputSection.h:20
elftosb::ConversionController::m_sources
source_map_t m_sources
Map of source names to file objects.
Definition: ConversionController.h:146
elftosb::ConversionController::getSourceFromName
SourceFile * getSourceFromName(std::string *sourceName, int line)
Definition: ConversionController.cpp:1841
elftosb::ConversionController::printIntConstExpr
void printIntConstExpr(const std::string &ident, IntConstExprASTNode *expr)
Definition: ConversionController.cpp:1917
elftosb::ConversionController::substituteVariables
std::string * substituteVariables(const std::string *message)
Definition: ConversionController.cpp:1449
elftosb::ASTNode
The base class for all AST node classes.
Definition: ElftosbAST.h:33
elftosb::ElftosbLexer
Lexical scanner class for elftosb command files.
Definition: ElftosbLexer.h:62