1 /*
2  * File:  BootImageGenerator.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_BootImageGenerator_h_)
8 #define _BootImageGenerator_h_
9 
10 #include "OutputSection.h"
11 #include "BootImage.h"
12 #include "OptionContext.h"
13 
14 namespace elftosb
15 {
16 
17 /*!
18  * \brief Abstract base class for generators of specific boot image formats.
19  *
20  * Subclasses implement a concrete generator for a certain boot image format, but
21  * they all have the same interface.
22  *
23  * After creating an instance of a subclass the user adds OutputSection objects
24  * to the generator. These objects describe discrete sections within the resulting
25  * boot image file. If the format does not support multiple sections then only
26  * the first will be used.
27  *
28  * Options that are common to all boot image formats are handled by methods
29  * defined in this class. These are the current common options:
30  *        - productVersion
31  *        - componentVersion
32  *        - driveTag
33  */
34 class BootImageGenerator
35 {
36 public:
37           //! \brief Constructor.
BootImageGenerator()38           BootImageGenerator() {}
39 
40           //! \brief Destructor.
~BootImageGenerator()41           virtual ~BootImageGenerator() {}
42 
43           //! \brief Add another section to the output.
addOutputSection(OutputSection * section)44           void addOutputSection(OutputSection * section) { m_sections.push_back(section); }
45 
46           //! \brief Set the global option context.
setOptionContext(OptionContext * context)47           void setOptionContext(OptionContext * context) { m_options = context; }
48 
49           //! \brief Pure virtual method to generate the output BootImage from input sections.
50           virtual BootImage * generate()=0;
51 
52 protected:
53           //! Type for a list of model output sections.
54           typedef std::vector<OutputSection*> section_vector_t;
55 
56           section_vector_t m_sections;  //!< Requested output sections.
57           OptionContext * m_options;    //!< Global option context.
58 
59     //! \brief Handle common product and component version options.
60     void processVersionOptions(BootImage * image);
61 
62           //! \brief Handle the common option which sets the system drive tag.
63           void processDriveTagOption(BootImage * image);
64 };
65 
66 }; // namespace elftosb
67 
68 #endif // _BootImageGenerator_h_
69 
70