Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
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 #include "keyblob.h"
16 
17 namespace elftosb
18 {
22 class Operation
23 {
24 public:
25  Operation() {}
26  virtual ~Operation() {}
27 };
28 
32 class LoadOperation : public Operation
33 {
34 public:
36  : Operation()
37  , m_source()
38  , m_target()
39  , m_isDCDLoad(false)
40  {
41  }
42 
43  void setSource(DataSource *source);
44  inline DataSource *getSource() { return m_source; }
45  void setTarget(DataTarget *target);
46  inline DataTarget *getTarget() { return m_target; }
47  inline void setDCDLoad(bool isDCD) { m_isDCDLoad = isDCD; }
48  inline bool isDCDLoad() const { return m_isDCDLoad; }
49 protected:
50  smart_ptr<DataSource> m_source;
51  smart_ptr<DataTarget> m_target;
52  bool m_isDCDLoad;
53 };
54 
59 {
60 public:
61  enum execute_type_t
62  {
63  kJump,
64  kCall
65  };
66 
67 public:
69  : Operation()
70  , m_target()
71  , m_argument(0)
72  , m_type(kCall)
73  , m_isHAB(false)
74  , m_stackPointer(0)
75  , m_isStackPointerSet(false)
76  {
77  }
78 
79  inline void setTarget(DataTarget *target) { m_target = target; }
80  inline DataTarget *getTarget() { return m_target; }
81  inline void setArgument(uint32_t arg) { m_argument = arg; }
82  inline uint32_t getArgument() { return m_argument; }
83  inline void setExecuteType(execute_type_t type) { m_type = type; }
84  inline execute_type_t getExecuteType() { return m_type; }
85  inline void setIsHAB(bool isHAB) { m_isHAB = isHAB; }
86  inline bool isHAB() const { return m_isHAB; }
87  inline void setStackPointer(uint32_t sp) { m_stackPointer = sp; }
88  inline uint32_t getStackPointer() { return m_stackPointer; }
89  inline void setIsStackPointerSet(bool isSet) { m_isStackPointerSet = isSet; }
90  inline bool isStackPonterSet() const { return m_isStackPointerSet; }
91 protected:
92  smart_ptr<DataTarget> m_target;
93  uint32_t m_argument;
94  uint32_t m_stackPointer;
95  execute_type_t m_type;
96  bool m_isHAB;
97  bool m_isStackPointerSet;
98 };
99 
104 {
105 public:
107  : ExecuteOperation()
108  {
109  }
110 };
111 
116 {
117 public:
119  : Operation()
120  , m_bootMode(0)
121  {
122  }
123 
124  inline void setBootMode(uint32_t mode) { m_bootMode = mode; }
125  inline uint32_t getBootMode() const { return m_bootMode; }
126 protected:
127  uint32_t m_bootMode;
128 };
129 
133 class ResetOperation : public Operation
134 {
135 public:
137  : Operation()
138  {
139  }
140 };
141 
146 {
147 public:
149  : Operation()
150  , m_startAddress(0)
151  , m_byteCount(0)
152  {
153  }
154 
155  void setRange(uint32_t start, uint32_t count)
156  {
157  m_startAddress = start;
158  m_byteCount = count;
159  }
160  void getRange(uint32_t *start, uint32_t *count) const;
161 
162 protected:
163  uint32_t m_startAddress;
164  uint32_t m_byteCount;
165 };
166 
171 {
172 public:
175  {
176  }
177 };
178 
183 {
184 public:
187  , m_memoryId(0)
188  {
189  }
190 
191  void setMemoryId(uint32_t memId) { m_memoryId = memId; }
192  uint32_t getMemoryId() const { return m_memoryId; }
193 protected:
194  uint32_t m_memoryId;
195 };
196 
201 {
202 public:
205  {
206  }
207 };
208 
213 {
214 public:
216  : Operation()
217  , m_startAddress(0)
218  , m_byteCount(0)
219  , m_memControllerId(0)
220  {
221  }
222 
223  void setMemControllerId(uint32_t memControllerId) { m_memControllerId = memControllerId; }
224  uint32_t getMemControllerId() const { return m_memControllerId; }
225  void setRange(uint32_t start, uint32_t count)
226  {
227  m_startAddress = start;
228  m_byteCount = count;
229  }
230  void getRange(uint32_t *start, uint32_t *count) const;
231 
232 protected:
233  uint32_t m_startAddress;
234  uint32_t m_byteCount;
235  uint32_t m_memControllerId;
236 };
237 
242 {
243 public:
246  : LoadOperation()
247  , m_memSpace(0)
248  {
249  }
250 
252  ProgramOperation(uint32_t memSpace)
253  : LoadOperation()
254  , m_memSpace(memSpace)
255  {
256  }
257 
258  void setMemorySpace(uint32_t memSpace) { m_memSpace = memSpace; }
259  uint32_t getMemorySpace() const { return m_memSpace; }
260 protected:
261  uint32_t m_memSpace;
262 };
263 
268 {
269 public:
272  : LoadOperation()
273  , m_keyblob()
274  {
275  }
276 
279  : LoadOperation()
280  , m_keyblob(keyblob)
281  {
282  }
283 
284  void setKeyblob(Keyblob *keyblob) { m_keyblob = keyblob; }
285  Keyblob *getKeyblob() { return m_keyblob; }
286 protected:
288 };
289 
294 {
295 public:
298  : LoadOperation()
299  , m_keyblob()
300  {
301  }
302 
305  : LoadOperation()
306  , m_keyblob(keyblob)
307  {
308  }
309 
310  void setKeyblob(Keyblob *keyblob) { m_keyblob = keyblob; }
311  Keyblob *getKeyblob() { return m_keyblob; }
312 protected:
314 };
315 
324 {
325 public:
326  typedef std::vector<Operation *> operation_list_t;
327  typedef operation_list_t::iterator iterator_t;
328  typedef operation_list_t::const_iterator const_iterator_t;
329 
330 public:
334  OperationSequence(Operation *soleElement) { m_operations.push_back(soleElement); }
336  virtual ~OperationSequence();
337 
339 
340  inline iterator_t begin() { return m_operations.begin(); }
341  inline const_iterator_t begin() const { return m_operations.begin(); }
342  inline iterator_t end() { return m_operations.end(); }
343  inline const_iterator_t end() const { return m_operations.end(); }
345 
346  inline Operation *operator[](unsigned index) const { return m_operations[index]; }
348 
349  inline unsigned getCount() const { return m_operations.size(); }
352 
354 
355  inline void append(Operation *op) { m_operations.push_back(op); }
358  void append(const OperationSequence *other);
359 
362  {
363  append(other);
364  return *this;
365  }
367 
368 protected:
369  operation_list_t m_operations;
370 };
371 
372 }; // namespace elftosb
373 
374 #endif // _Operation_h_
EncryptOperation()
Default constructor.
Definition: Operation.h:297
Operation to encrypt data for OTFAD.
Definition: Operation.h:293
Operation to erase the entire external flash memory array.
Definition: Operation.h:182
operation_list_t m_operations
The list of operations.
Definition: Operation.h:369
Abstract base class for data sources.
Definition: apps/elftosb/common/DataSource.h:33
Operation to program persistent bits.
Definition: Operation.h:241
Ordered sequence of operations.
Definition: Operation.h:323
uint32_t m_bootMode
The new boot mode value.
Definition: Operation.h:127
operation_list_t::iterator iterator_t
Iterator over operations.
Definition: Operation.h:327
std::vector< Operation * > operation_list_t
Type for a list of operation objects.
Definition: Operation.h:326
KeywrapOperation()
Default constructor.
Definition: Operation.h:271
ProgramOperation()
Default constructor.
Definition: Operation.h:245
Operation to reset the device.
Definition: Operation.h:133
Operation to execute code at a certain address.
Definition: Operation.h:58
smart_ptr< Keyblob > m_keyblob
Active keyblob during this load.
Definition: Operation.h:287
Operation to enable external memory access.
Definition: Operation.h:212
Operation to erase flash memory.
Definition: Operation.h:145
Operation to wrap and program keys.
Definition: Operation.h:267
Simple, standard smart pointer class.
Definition: apps/elftosb/common/smart_ptr.h:18
Authenticate with HAB and execute the entry point.
Definition: Operation.h:103
Definition: BootImage.h:13
Abstract base class for the target address or range of data.
Definition: apps/elftosb/common/DataTarget.h:34
smart_ptr< Keyblob > m_keyblob
Active keyblob during this load.
Definition: Operation.h:313
operation_list_t::const_iterator const_iterator_t
Const iterator over operations.
Definition: Operation.h:328
Operation to erase the entire flash memory array.
Definition: Operation.h:170
Keyblob specification.
Definition: Keyblob.h:27
Operation to switch boot modes.
Definition: Operation.h:115
ProgramOperation(uint32_t memSpace)
Constructor. Takes a memory space argument.
Definition: Operation.h:252
Operation to erase the entire flash memory array, unsecure version.
Definition: Operation.h:200
Abstract base class for all boot operations.
Definition: Operation.h:22
Load data into memory operation.
Definition: Operation.h:32
EncryptOperation(Keyblob *keyblob)
Constructor. Takes a keyblob argument.
Definition: Operation.h:304
OperationSequence(Operation *soleElement)
Constructor. Makes a one-element sequence from soleElement.
Definition: Operation.h:334
OperationSequence & operator+=(const OperationSequence *other)
Appends other onto this sequence.
Definition: Operation.h:361
OperationSequence()
Default constructor.
Definition: Operation.h:332
KeywrapOperation(Keyblob *keyblob)
Constructor. Takes a keyblob argument.
Definition: Operation.h:278