Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
apps/elftosb/common/DataTarget.h
1 /*
2  * File: DataTarget.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_DataTarget_h_)
8 #define _DataTarget_h_
9 
10 #include "stdafx.h"
11 #include "DataSource.h"
12 
13 namespace elftosb
14 {
15 // Forward declaration
16 class DataSource;
17 
35 {
36 public:
39  struct AddressRange
40  {
41  uint32_t m_begin;
42  uint32_t m_end;
43  };
44 
45 public:
48  : m_source(0)
49  {
50  }
51 
53  virtual ~DataTarget() {}
55  virtual bool isBounded() { return false; }
56  virtual uint32_t getBeginAddress() { return 0; }
57  virtual uint32_t getEndAddress() { return 0; }
60 
61  inline void setSource(DataSource *source) { m_source = source; }
62  inline DataSource *getSource() const { return m_source; }
63 protected:
65 };
66 
75 {
76 public:
78  ConstantDataTarget(uint32_t start)
79  : DataTarget()
80  , m_begin(start)
81  , m_end(0)
82  , m_hasEnd(false)
83  {
84  }
85 
87  ConstantDataTarget(uint32_t start, uint32_t end)
88  : DataTarget()
89  , m_begin(start)
90  , m_end(end)
91  , m_hasEnd(true)
92  {
93  }
94 
96  virtual bool isBounded() { return m_hasEnd; }
97  virtual uint32_t getBeginAddress() { return m_begin; }
98  virtual uint32_t getEndAddress() { return m_end; }
101 
102 protected:
103  uint32_t m_begin;
104  uint32_t m_end;
105  bool m_hasEnd;
106 };
107 
116 {
117 public:
120  : DataTarget()
121  {
122  }
123 
125  virtual bool isBounded() { return true; }
128 };
129 
130 }; // namespace elftosb
131 
132 #endif // _DataTarget_h_
Abstract base class for data sources.
Definition: apps/elftosb/common/DataSource.h:33
uint32_t m_begin
Start address.
Definition: apps/elftosb/common/DataTarget.h:103
ConstantDataTarget(uint32_t start)
Constructor taking only a begin address.
Definition: apps/elftosb/common/DataTarget.h:78
Target with a constant values for the addresses.
Definition: apps/elftosb/common/DataTarget.h:74
NaturalDataTarget()
Default constructor.
Definition: apps/elftosb/common/DataTarget.h:119
DataTarget()
Default constructor.
Definition: apps/elftosb/common/DataTarget.h:47
virtual bool isBounded()
Whether the target is just a single address or has an end to it.
Definition: apps/elftosb/common/DataTarget.h:55
Definition: BootImage.h:13
virtual DataTarget::AddressRange getRangeForSegment(DataSource &source, DataSource::Segment &segment)=0
Return the address range for a segment of a data source.
Abstract base class for the target address or range of data.
Definition: apps/elftosb/common/DataTarget.h:34
Target address that is the "natural" location of whatever the source data is.
Definition: apps/elftosb/common/DataTarget.h:115
Simple structure that describes an addressed region of memory.
Definition: apps/elftosb/common/DataTarget.h:39
DataSource * m_source
Corresponding data source for this target.
Definition: apps/elftosb/common/DataTarget.h:64
virtual ~DataTarget()
Destructor.
Definition: apps/elftosb/common/DataTarget.h:53
ConstantDataTarget(uint32_t start, uint32_t end)
Constructor taking both begin and end addresses.
Definition: apps/elftosb/common/DataTarget.h:87
Discrete, contiguous part of the source's data.
Definition: apps/elftosb/common/DataSource.h:42
uint32_t m_end
End address.
Definition: apps/elftosb/common/DataTarget.h:104
bool m_hasEnd
Was an end address specified?
Definition: apps/elftosb/common/DataTarget.h:105
virtual bool isBounded()
The target is bounded if an end address was specified.
Definition: apps/elftosb/common/DataTarget.h:96
virtual bool isBounded()
Natural data targets are bounded by their source's segment lengths.
Definition: apps/elftosb/common/DataTarget.h:125