IVTDataSource.h
/*
* File: DataSource.h
*
* Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
*
* Freescale Semiconductor, Inc.
* Proprietary & Confidential
*
* This source code and the algorithms implemented therein constitute
* confidential information and may comprise trade secrets of Freescale Semiconductor, Inc.
* or its associates, and any use thereof is subject to the terms and
* conditions of the Confidential Disclosure Agreement pursual to which this
* source code was originally received.
*/
#if !defined(_IVTDataSource_h_)
#define _IVTDataSource_h_
#include "DataSource.h"
typedef struct hab_hdr
{
uint8_t tag;
uint8_t len[2];
uint8_t par;
} hab_hdr_t;
typedef void (*hab_image_entry_f)(void);
struct hab_ivt
{
hab_hdr_t hdr;
/*hab_image_entry_f*/ uint32_t entry;
/*const void*/ uint32_t reserved1;
/*const void*/ uint32_t dcd;
/*const void*/ uint32_t boot_data;
/*const void*/ uint32_t self;
/*const void*/ uint32_t csf;
uint32_t reserved2;
};
typedef struct hab_ivt hab_ivt_t;
/*
* Helper macros
*/
#define HAB_CMD_UNS 0xff
#define DEFAULT_IMG_KEY_IDX 2
#define GEN_MASK(width) ((1UL << (width)) - 1)
#define GEN_FIELD(f, width, shift) (((f)&GEN_MASK(width)) << (shift))
#define PACK_UINT32(a, b, c, d) ((((a)&0xFF) << 24) | (((b)&0xFF) << 16) | (((c)&0xFF) << 8) | (((d)&0xFF)))
#define EXPAND_UINT32(w) (uint8_t)((w) >> 24), (uint8_t)((w) >> 16), (uint8_t)((w) >> 8), (uint8_t)(w)
#define HDR(tag, bytes, par) (uint8_t)(tag), (uint8_t)((bytes) >> 8), (uint8_t)(bytes), (uint8_t)(par)
#define HAB_VER(maj, min) \
(GEN_FIELD((maj), HAB_VER_MAJ_WIDTH, HAB_VER_MAJ_SHIFT) | GEN_FIELD((min), HAB_VER_MIN_WIDTH, HAB_VER_MIN_SHIFT))
/*
* CSF header
*/
#define CSF_HDR(bytes, HABVER) HDR(HAB_TAG_CSF, (bytes), HABVER)
/*
* DCD header
*/
#define DCD_HDR(bytes, HABVER) HDR(HAB_TAG_DCD, (bytes), HABVER)
/*
* IVT header (goes in the struct's hab_hdr_t field, not a byte array)
*/
#define IVT_HDR(bytes, HABVER) \
{ \
HAB_TAG_IVT, { (uint8_t)((bytes) >> 8), (uint8_t)(bytes) }, HABVER \
}
#define HAB_TAG_IVT 0xd1
#define HAB_TAG_DCD 0xd2
#define HAB_TAG_CSF 0xd4
#define HAB_TAG_CRT 0xd7
#define HAB_TAG_SIG 0xd8
#define HAB_TAG_EVT 0xdb
#define HAB_TAG_RVT 0xdd
/* Values b0 ... cf reserved for CSF commands. Values e0 ... ef reserved for
* key types.
*
* Available values: 03, 05, 06, 09, 0a, 0c, 0f, 11, 12, 14, 17, 18, 1b, 1d,
* 1e, 21, 22, 24, 27, 28, 2b, 2d, 2e, 30, 33, 35, 36, 39, 3a, 3c, 3f, 41, 42,
* 44, 47, 48, 4b, 4d, 4e, 50, 53, 55, 56, 59, 5a, 5c, 5f, 60, 63, 65, 66, 69,
* 6a, 6c, 6f, 71, 72, 74, 77, 78, 7b, 7d, 7e, 81, 82, 84, 87, 88, 8b, 8d, 8e,
* 90, 93, 95, 96, 99, 9a, 9c, 9f, a0, a3, a5, a6, a9, aa, ac, af, b1, b2, b4,
* b7, b8, bb, bd, be
*
* Custom values: f0, f3, f5, f6, f9, fa, fc, ff
*/
#define HAB_MAJOR_VERSION 4
#define HAB_MINOR_VERSION 0
#define HAB_VER_MAJ_WIDTH 4
#define HAB_VER_MAJ_SHIFT 4
#define HAB_VER_MIN_WIDTH 4
#define HAB_VER_MIN_SHIFT 0
#define HAB_VERSION HAB_VER(HAB_MAJOR_VERSION, HAB_MINOR_VERSION)
#define HAB_BASE_VERSION HAB_VER(HAB_MAJOR_VERSION, 0)
namespace elftosb
{
class IVTDataSource : public DataSource, public DataSource::Segment
{
public:
IVTDataSource();
virtual unsigned getSegmentCount() { return 1; }
virtual DataSource::Segment *getSegmentAt(unsigned index) { return this; }
virtual unsigned getData(unsigned offset, unsigned maxBytes, uint8_t *buffer);
virtual unsigned getLength();
virtual bool hasNaturalLocation();
virtual uint32_t getBaseAddress();
bool setFieldByName(const std::string &name, uint32_t value);
hab_ivt_t &getIVT() { return m_ivt; }
protected:
hab_ivt_t m_ivt;
bool m_isSelfSet;
};
} // elftosb
#endif // _IVTDataSource_h_
hab_ivt::hdr
hab_hdr_t hdr
Definition: IVTDataSource.h:96
elftosb::DataSource
Abstract base class for data sources.
Definition: apps/elftosb/common/DataSource.h:33
hab_hdr_t
Definition: IVTDataSource.h:23
elftosb::IVTDataSource::getSegmentAt
virtual DataSource::Segment * getSegmentAt(unsigned index)
Returns this object, as it is its own segment.
Definition: IVTDataSource.h:229
hab_ivt::entry
uint32_t entry
Definition: IVTDataSource.h:100
elftosb::IVTDataSource::m_isSelfSet
bool m_isSelfSet
True if the IVT self pointer was explicitly set.
Definition: IVTDataSource.h:280
hab_ivt::dcd
uint32_t dcd
Definition: IVTDataSource.h:104
hab_ivt::boot_data
uint32_t boot_data
Definition: IVTDataSource.h:108
hab_hdr_t::par
uint8_t par
Definition: IVTDataSource.h:27
elftosb::IVTDataSource
Data source for an IVT structure used by HAB4.
Definition: IVTDataSource.h:220
elftosb
Definition: BootImage.h:13
hab_ivt::csf
uint32_t csf
Definition: IVTDataSource.h:112
elftosb::IVTDataSource::getIVT
hab_ivt_t & getIVT()
Returns a reference to the IVT structure.
Definition: IVTDataSource.h:275
hab_ivt
Definition: IVTDataSource.h:91
elftosb::DataSource::Segment
Discrete, contiguous part of the source&#39;s data.
Definition: apps/elftosb/common/DataSource.h:42
elftosb::IVTDataSource::getSegmentCount
virtual unsigned getSegmentCount()
There is only one segment.
Definition: IVTDataSource.h:227
hab_ivt::reserved1
uint32_t reserved1
Definition: IVTDataSource.h:102
elftosb::IVTDataSource::m_ivt
hab_ivt_t m_ivt
The IVT structure.
Definition: IVTDataSource.h:279
hab_hdr_t::tag
uint8_t tag
Definition: IVTDataSource.h:25
hab_ivt::reserved2
uint32_t reserved2
Definition: IVTDataSource.h:114