Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
IVTDataSource.h
1 /*
2  * File: DataSource.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  *
6  * Freescale Semiconductor, Inc.
7  * Proprietary & Confidential
8  *
9  * This source code and the algorithms implemented therein constitute
10  * confidential information and may comprise trade secrets of Freescale Semiconductor, Inc.
11  * or its associates, and any use thereof is subject to the terms and
12  * conditions of the Confidential Disclosure Agreement pursual to which this
13  * source code was originally received.
14  */
15 #if !defined(_IVTDataSource_h_)
16 #define _IVTDataSource_h_
17 
18 #include "DataSource.h"
19 
23 typedef struct hab_hdr
24 {
25  uint8_t tag;
26  uint8_t len[2];
27  uint8_t par;
28 } hab_hdr_t;
29 
37 typedef void (*hab_image_entry_f)(void);
38 
91 struct hab_ivt
92 {
100  /*hab_image_entry_f*/ uint32_t entry;
102  /*const void*/ uint32_t reserved1;
104  /*const void*/ uint32_t dcd;
108  /*const void*/ uint32_t boot_data;
110  /*const void*/ uint32_t self;
112  /*const void*/ uint32_t csf;
114  uint32_t reserved2;
115 };
116 
120 typedef struct hab_ivt hab_ivt_t;
121 
122 /*
123  * Helper macros
124  */
125 #define HAB_CMD_UNS 0xff
126 
127 #define DEFAULT_IMG_KEY_IDX 2
128 
129 #define GEN_MASK(width) ((1UL << (width)) - 1)
130 
131 #define GEN_FIELD(f, width, shift) (((f)&GEN_MASK(width)) << (shift))
132 
133 #define PACK_UINT32(a, b, c, d) ((((a)&0xFF) << 24) | (((b)&0xFF) << 16) | (((c)&0xFF) << 8) | (((d)&0xFF)))
134 
135 #define EXPAND_UINT32(w) (uint8_t)((w) >> 24), (uint8_t)((w) >> 16), (uint8_t)((w) >> 8), (uint8_t)(w)
136 
137 #define HDR(tag, bytes, par) (uint8_t)(tag), (uint8_t)((bytes) >> 8), (uint8_t)(bytes), (uint8_t)(par)
138 
139 #define HAB_VER(maj, min) \
140  (GEN_FIELD((maj), HAB_VER_MAJ_WIDTH, HAB_VER_MAJ_SHIFT) | GEN_FIELD((min), HAB_VER_MIN_WIDTH, HAB_VER_MIN_SHIFT))
141 
142 /*
143  * CSF header
144  */
145 
146 #define CSF_HDR(bytes, HABVER) HDR(HAB_TAG_CSF, (bytes), HABVER)
147 
148 /*
149  * DCD header
150  */
151 
152 #define DCD_HDR(bytes, HABVER) HDR(HAB_TAG_DCD, (bytes), HABVER)
153 
154 /*
155  * IVT header (goes in the struct's hab_hdr_t field, not a byte array)
156  */
157 #define IVT_HDR(bytes, HABVER) \
158  { \
159  HAB_TAG_IVT, { (uint8_t)((bytes) >> 8), (uint8_t)(bytes) }, HABVER \
160  }
161 
169 #define HAB_TAG_IVT 0xd1
170 #define HAB_TAG_DCD 0xd2
171 #define HAB_TAG_CSF 0xd4
172 #define HAB_TAG_CRT 0xd7
173 #define HAB_TAG_SIG 0xd8
174 #define HAB_TAG_EVT 0xdb
175 #define HAB_TAG_RVT 0xdd
176  /* Values b0 ... cf reserved for CSF commands. Values e0 ... ef reserved for
177  * key types.
178  *
179  * Available values: 03, 05, 06, 09, 0a, 0c, 0f, 11, 12, 14, 17, 18, 1b, 1d,
180  * 1e, 21, 22, 24, 27, 28, 2b, 2d, 2e, 30, 33, 35, 36, 39, 3a, 3c, 3f, 41, 42,
181  * 44, 47, 48, 4b, 4d, 4e, 50, 53, 55, 56, 59, 5a, 5c, 5f, 60, 63, 65, 66, 69,
182  * 6a, 6c, 6f, 71, 72, 74, 77, 78, 7b, 7d, 7e, 81, 82, 84, 87, 88, 8b, 8d, 8e,
183  * 90, 93, 95, 96, 99, 9a, 9c, 9f, a0, a3, a5, a6, a9, aa, ac, af, b1, b2, b4,
184  * b7, b8, bb, bd, be
185  *
186  * Custom values: f0, f3, f5, f6, f9, fa, fc, ff
187  */
188 
192 #define HAB_MAJOR_VERSION 4
193 #define HAB_MINOR_VERSION 0
194 #define HAB_VER_MAJ_WIDTH 4
195 #define HAB_VER_MAJ_SHIFT 4
196 #define HAB_VER_MIN_WIDTH 4
197 #define HAB_VER_MIN_SHIFT 0
199 #define HAB_VERSION HAB_VER(HAB_MAJOR_VERSION, HAB_MINOR_VERSION)
200 
201 #define HAB_BASE_VERSION HAB_VER(HAB_MAJOR_VERSION, 0)
202 
205 namespace elftosb
206 {
221 {
222 public:
224  IVTDataSource();
225 
227  virtual unsigned getSegmentCount() { return 1; }
229  virtual DataSource::Segment *getSegmentAt(unsigned index) { return this; }
231 
232 
235  virtual unsigned getData(unsigned offset, unsigned maxBytes, uint8_t *buffer);
236 
238  virtual unsigned getLength();
239 
241  virtual bool hasNaturalLocation();
242 
244  virtual uint32_t getBaseAddress();
245 
247 
249 
250 
272  bool setFieldByName(const std::string &name, uint32_t value);
273 
275  hab_ivt_t &getIVT() { return m_ivt; }
277 
278 protected:
279  hab_ivt_t m_ivt;
280  bool m_isSelfSet;
281 };
282 
283 } // elftosb
284 
285 #endif // _IVTDataSource_h_
hab_hdr_t hdr
Definition: IVTDataSource.h:96
Abstract base class for data sources.
Definition: apps/elftosb/common/DataSource.h:33
Definition: IVTDataSource.h:23
virtual DataSource::Segment * getSegmentAt(unsigned index)
Returns this object, as it is its own segment.
Definition: IVTDataSource.h:229
uint32_t entry
Definition: IVTDataSource.h:100
bool m_isSelfSet
True if the IVT self pointer was explicitly set.
Definition: IVTDataSource.h:280
uint32_t dcd
Definition: IVTDataSource.h:104
uint32_t boot_data
Definition: IVTDataSource.h:108
uint8_t par
Definition: IVTDataSource.h:27
Data source for an IVT structure used by HAB4.
Definition: IVTDataSource.h:220
Definition: BootImage.h:13
uint32_t csf
Definition: IVTDataSource.h:112
hab_ivt_t & getIVT()
Returns a reference to the IVT structure.
Definition: IVTDataSource.h:275
Definition: IVTDataSource.h:91
Discrete, contiguous part of the source&#39;s data.
Definition: apps/elftosb/common/DataSource.h:42
virtual unsigned getSegmentCount()
There is only one segment.
Definition: IVTDataSource.h:227
uint32_t reserved1
Definition: IVTDataSource.h:102
hab_ivt_t m_ivt
The IVT structure.
Definition: IVTDataSource.h:279
uint8_t tag
Definition: IVTDataSource.h:25
uint32_t reserved2
Definition: IVTDataSource.h:114