4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
6 * Freescale Semiconductor, Inc.
7 * Proprietary & Confidential
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.
16 #include "IVTDataSource.h"
17 #include "DataTarget.h"
18 #include "EndianUtilities.h"
23 using namespace elftosb;
25 IVTDataSource::IVTDataSource()
27 DataSource::Segment((DataSource&)*this),
30 // Init the IVT structure.
31 memset(&m_ivt, 0, sizeof(m_ivt));
32 hab_hdr_t hdr = IVT_HDR(sizeof(m_ivt), HAB_VERSION);
36 unsigned IVTDataSource::getData(unsigned offset, unsigned maxBytes, uint8_t * buffer)
38 // Bail if the offset is out of range.
39 if (offset >= sizeof(m_ivt))
44 // If we have an associated target, and the IVT self pointer is not set, then
45 // fill in the self pointer from the target address.
46 if (m_target && !m_isSelfSet)
48 m_ivt.self = ENDIAN_HOST_TO_LITTLE_U32(m_target->getBeginAddress());
51 // Truncate max bytes at the end of the IVT.
52 maxBytes = std::min<unsigned>(maxBytes, sizeof(m_ivt) - offset);
54 // Copy into output buffer.
57 memcpy(buffer, (uint8_t *)&m_ivt + offset, maxBytes);
63 unsigned IVTDataSource::getLength()
68 //! The IVT has a natural location if its self pointer was explicitly specified.
70 bool IVTDataSource::hasNaturalLocation()
76 uint32_t IVTDataSource::getBaseAddress()
81 bool IVTDataSource::setFieldByName(const std::string & name, uint32_t value)
85 m_ivt.entry = ENDIAN_HOST_TO_LITTLE_U32(value);
87 else if (name == "dcd")
89 m_ivt.dcd = ENDIAN_HOST_TO_LITTLE_U32(value);
91 else if (name == "boot_data")
93 m_ivt.boot_data = ENDIAN_HOST_TO_LITTLE_U32(value);
95 else if (name == "self")
97 m_ivt.self = ENDIAN_HOST_TO_LITTLE_U32(value);
100 else if (name == "csf")
102 m_ivt.csf = ENDIAN_HOST_TO_LITTLE_U32(value);
106 // Unrecognized field name.