]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - tools/elftosb/common/Operation.h
merged tx6dl-devel into denx master branch
[karo-tx-uboot.git] / tools / elftosb / common / Operation.h
1 /*
2  * File:        Operation.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_Operation_h_)
8 #define _Operation_h_
9
10 #include "stdafx.h"
11 #include <vector>
12 #include "DataSource.h"
13 #include "DataTarget.h"
14 #include "smart_ptr.h"
15
16 namespace elftosb
17 {
18
19 /*!
20  * \brief Abstract base class for all boot operations.
21  */
22 class Operation
23 {
24 public:
25         Operation() {}
26         virtual ~Operation() {}
27 };
28
29 /*!
30  * \brief Load data into memory operation.
31  */
32 class LoadOperation : public Operation
33 {
34 public:
35         LoadOperation() : Operation(), m_source(), m_target() {}
36         
37         void setSource(DataSource * source);
38         inline DataSource * getSource() { return m_source; }
39         
40         void setTarget(DataTarget * target);
41         inline DataTarget * getTarget() { return m_target; }
42         
43         inline void setDCDLoad(bool isDCD) { m_isDCDLoad = isDCD; }
44         inline bool isDCDLoad() const { return m_isDCDLoad; }
45         
46 protected:
47         smart_ptr<DataSource> m_source;
48         smart_ptr<DataTarget> m_target;
49         bool m_isDCDLoad;
50 };
51
52 /*!
53  * \brief Operation to execute code at a certain address.
54  */
55 class ExecuteOperation : public Operation
56 {
57 public:
58         enum execute_type_t
59         {
60                 kJump,
61                 kCall
62         };
63         
64 public:
65         ExecuteOperation() : Operation(), m_target(), m_argument(0), m_type(kCall), m_isHAB(false) {}
66
67         inline void setTarget(DataTarget * target) { m_target = target; }
68         inline DataTarget * getTarget() { return m_target; }
69         
70         inline void setArgument(uint32_t arg) { m_argument = arg; }
71         inline uint32_t getArgument() { return m_argument; }
72         
73         inline void setExecuteType(execute_type_t type) { m_type = type; }
74         inline execute_type_t getExecuteType() { return m_type; }
75         
76         inline void setIsHAB(bool isHAB) { m_isHAB = isHAB; }
77         inline bool isHAB() const { return m_isHAB; }
78         
79 protected:
80         smart_ptr<DataTarget> m_target;
81         uint32_t m_argument;
82         execute_type_t m_type;
83         bool m_isHAB;
84 };
85
86 /*!
87  * \brief Authenticate with HAB and execute the entry point.
88  */
89 class HABExecuteOperation : public ExecuteOperation
90 {
91 public:
92         HABExecuteOperation() : ExecuteOperation() {}
93 };
94
95 /*!
96  * \brief Operation to switch boot modes.
97  */
98 class BootModeOperation : public Operation
99 {
100 public:
101         BootModeOperation() : Operation() {}
102         
103         inline void setBootMode(uint32_t mode) { m_bootMode = mode; }
104         inline uint32_t getBootMode() const { return m_bootMode; }
105
106 protected:
107         uint32_t m_bootMode;    //!< The new boot mode value.
108 };
109
110 /*!
111  * \brief Ordered sequence of operations.
112  *
113  * The operation objects owned by the sequence are \e not deleted when the
114  * sequence is destroyed. The owner of the sequence must manually delete
115  * the operation objects.
116  */
117 class OperationSequence
118 {
119 public:
120         typedef std::vector<Operation*> operation_list_t;       //!< Type for a list of operation objects.
121         typedef operation_list_t::iterator iterator_t;  //!< Iterator over operations.
122         typedef operation_list_t::const_iterator const_iterator_t;      //!< Const iterator over operations.
123
124 public:
125         //! \brief Default constructor.
126         OperationSequence() {}
127         
128         //! \brief Constructor. Makes a one-element sequence from \a soleElement.
129         OperationSequence(Operation * soleElement) { m_operations.push_back(soleElement); }
130         
131         //! \brief Destructor.
132         virtual ~OperationSequence();
133         
134         //! \name Iterators
135         //@{
136         inline iterator_t begin() { return m_operations.begin(); }
137         inline const_iterator_t begin() const { return m_operations.begin(); }
138         inline iterator_t end() { return m_operations.end(); }
139         inline const_iterator_t end() const { return m_operations.end(); }
140         //@}
141         
142         inline Operation * operator [] (unsigned index) const { return m_operations[index]; }
143         
144         //! \name Status
145         //@{
146         //! \brief Returns the number of operations in the sequence.
147         inline unsigned getCount() const { return m_operations.size(); }
148         //@}
149         
150         //! \name Operations
151         //@{
152         //! \brief Append one operation object to the sequence.
153         inline void append(Operation * op) { m_operations.push_back(op); }
154         
155         //! \brief Append the contents of \a other onto this sequence.
156         void append(const OperationSequence * other);
157         
158         //! \brief Appends \a other onto this sequence.
159         OperationSequence & operator += (const OperationSequence * other) { append(other); return *this; }
160         //@}
161
162 protected:
163         operation_list_t m_operations;  //!< The list of operations.
164 };
165
166 }; // namespace elftosb
167
168 #endif // _Operation_h_