SBSourceFile.h
/*
* Copyright (c) 2013-14, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if !defined(_SBSourceFile_h_)
#define _SBSourceFile_h_
#include "blfwk/SourceFile.h"
#include "blfwk/StELFFile.h"
#include "blfwk/smart_ptr.h"
#include "blfwk/DataSource.h"
#include "blfwk/DataTarget.h"
namespace blfwk
{
class SBSourceFile : public BinarySourceFile
{
public:
SBSourceFile(const std::string &path);
virtual ~SBSourceFile();
static bool isSBFile(std::istream &stream);
virtual DataSource *createDataSource();
protected:
typedef uint8_t cipher_block_t[16];
typedef uint8_t sha1_digest_t[20];
typedef uint32_t section_id_t;
// All of these structures are packed to byte alignment in order to match
// the structure on disk.
#pragma pack(1)
struct version_t
{
uint16_t m_major;
uint16_t m_pad0;
uint16_t m_minor;
uint16_t m_pad1;
uint16_t m_revision;
uint16_t m_pad2;
};
struct boot_image_header_t
{
union
{
sha1_digest_t m_digest;
struct
{
cipher_block_t m_iv;
uint8_t m_extra[4];
};
};
uint8_t m_signature[4];
uint8_t m_majorVersion;
uint8_t m_minorVersion;
uint16_t m_flags;
uint32_t m_imageBlocks;
uint32_t m_firstBootTagBlock;
section_id_t m_firstBootableSectionID;
uint16_t m_keyCount;
uint16_t m_keyDictionaryBlock;
uint16_t m_headerBlocks;
uint16_t m_sectionCount;
uint16_t m_sectionHeaderSize;
uint8_t m_padding0[2];
uint8_t m_signature2[4];
uint64_t m_timestamp;
version_t m_productVersion;
version_t m_componentVersion;
uint16_t m_driveTag;
uint8_t m_padding1[6];
};
#pragma pack()
public:
class SBFileException : public std::runtime_error
{
public:
SBFileException(const std::string &inMessage)
: std::runtime_error(inMessage)
{
}
};
};
}; // namespace blfwk
#endif // _SBSourceFile_h_
blfwk::SBSourceFile::version_t
Same version struct used for 3600 boot image.
Definition: SBSourceFile.h:77
blfwk::SBSourceFile
SB Format (SB) source file.
Definition: SBSourceFile.h:44
blfwk::SBSourceFile::boot_image_header_t::m_sectionHeaderSize
uint16_t m_sectionHeaderSize
Size in blocks of a section header.
Definition: SBSourceFile.h:128
blfwk
Definition: BlfwkErrors.h:16
blfwk::SBSourceFile::boot_image_header_t::m_flags
uint16_t m_flags
Flags or options associated with the entire image.
Definition: SBSourceFile.h:120
std
STL namespace.
blfwk::SBSourceFile::SBFileException
Simple exception thrown to indicate an error in the input SB file format.
Definition: SBSourceFile.h:145
blfwk::BinarySourceFile
Binary data file.
Definition: src/blfwk/SourceFile.h:165
blfwk::SBSourceFile::boot_image_header_t::m_firstBootableSectionID
section_id_t m_firstBootableSectionID
ID of section to start booting from.
Definition: SBSourceFile.h:123
blfwk::SBSourceFile::boot_image_header_t::m_headerBlocks
uint16_t m_headerBlocks
Size of this header, including this size word, in blocks.
Definition: SBSourceFile.h:126
blfwk::SBSourceFile::boot_image_header_t::m_keyCount
uint16_t m_keyCount
Number of entries in DEK dictionary.
Definition: SBSourceFile.h:124
blfwk::SBSourceFile::isSBFile
static bool isSBFile(std::istream &stream)
Identifies whether the stream contains an SB file.
Definition: SBSourceFile.cpp:51
blfwk::SBSourceFile::boot_image_header_t::m_componentVersion
version_t m_componentVersion
Component version.
Definition: SBSourceFile.h:134
blfwk::SBSourceFile::SBSourceFile
SBSourceFile(const std::string &path)
Default constructor.
Definition: SBSourceFile.cpp:42
blfwk::SBSourceFile::section_id_t
uint32_t section_id_t
Unique identifier type for a section.
Definition: SBSourceFile.h:70
blfwk::SBSourceFile::boot_image_header_t::m_majorVersion
uint8_t m_majorVersion
Major version for the image format, see #ROM_BOOT_IMAGE_MAJOR_VERSION.
Definition: SBSourceFile.h:118
blfwk::SBSourceFile::boot_image_header_t::m_driveTag
uint16_t m_driveTag
Drive tag for the system drive which this boot image belongs to.
Definition: SBSourceFile.h:135
blfwk::SBSourceFile::~SBSourceFile
virtual ~SBSourceFile()
Destructor.
Definition: SBSourceFile.cpp:47
blfwk::SBSourceFile::boot_image_header_t::m_imageBlocks
uint32_t m_imageBlocks
Size of entire image in blocks.
Definition: SBSourceFile.h:121
blfwk::SBSourceFile::boot_image_header_t::m_sectionCount
uint16_t m_sectionCount
Number of section headers in this table.
Definition: SBSourceFile.h:127
blfwk::SBSourceFile::SBFileException::SBFileException
SBFileException(const std::string &inMessage)
Default constructor.
Definition: SBSourceFile.h:149
blfwk::SBSourceFile::boot_image_header_t::m_firstBootTagBlock
uint32_t m_firstBootTagBlock
Offset from start of file to the first boot tag, in blocks.
Definition: SBSourceFile.h:122
blfwk::SBSourceFile::createDataSource
virtual DataSource * createDataSource()
Creates an unmapped data source from the entire file.
Definition: SBSourceFile.cpp:99
blfwk::DataSource
Abstract base class for data sources.
Definition: src/blfwk/DataSource.h:56
blfwk::SBSourceFile::boot_image_header_t::m_productVersion
version_t m_productVersion
Product version.
Definition: SBSourceFile.h:133
blfwk::SBSourceFile::cipher_block_t
uint8_t cipher_block_t[16]
An AES-128 cipher block is 16 bytes.
Definition: SBSourceFile.h:64
blfwk::SBSourceFile::boot_image_header_t::m_keyDictionaryBlock
uint16_t m_keyDictionaryBlock
Starting block number for the key dictionary.
Definition: SBSourceFile.h:125
blfwk::SBSourceFile::sha1_digest_t
uint8_t sha1_digest_t[20]
A SHA-1 digest is 160 bits, or 20 bytes.
Definition: SBSourceFile.h:67
blfwk::SBSourceFile::boot_image_header_t::m_minorVersion
uint8_t m_minorVersion
Minor version of the boot image format, see #ROM_BOOT_IMAGE_MINOR_VERSION.
Definition: SBSourceFile.h:119
blfwk::SBSourceFile::boot_image_header_t
Header for the entire boot image.
Definition: SBSourceFile.h:106