Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
SBSourceFile.h
1 /*
2  * Copyright (c) 2013-14, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #if !defined(_SBSourceFile_h_)
31 #define _SBSourceFile_h_
32 
33 #include "blfwk/SourceFile.h"
34 #include "blfwk/StELFFile.h"
35 #include "blfwk/smart_ptr.h"
36 #include "blfwk/DataSource.h"
37 #include "blfwk/DataTarget.h"
38 
39 namespace blfwk
40 {
45 {
46 public:
48  SBSourceFile(const std::string &path);
49 
51  virtual ~SBSourceFile();
52 
54  static bool isSBFile(std::istream &stream);
55 
57 
58  virtual DataSource *createDataSource();
61 
62 protected:
64  typedef uint8_t cipher_block_t[16];
65 
67  typedef uint8_t sha1_digest_t[20];
68 
70  typedef uint32_t section_id_t;
71 
72 // All of these structures are packed to byte alignment in order to match
73 // the structure on disk.
74 #pragma pack(1)
75 
77  struct version_t
78  {
79  uint16_t m_major;
80  uint16_t m_pad0;
81  uint16_t m_minor;
82  uint16_t m_pad1;
83  uint16_t m_revision;
84  uint16_t m_pad2;
85  };
86 
107  {
108  union
109  {
110  sha1_digest_t m_digest;
111  struct
112  {
113  cipher_block_t m_iv;
114  uint8_t m_extra[4];
115  };
116  };
117  uint8_t m_signature[4];
118  uint8_t m_majorVersion;
119  uint8_t m_minorVersion;
120  uint16_t m_flags;
121  uint32_t m_imageBlocks;
124  uint16_t m_keyCount;
126  uint16_t m_headerBlocks;
127  uint16_t m_sectionCount;
129  uint8_t m_padding0[2];
130  uint8_t m_signature2[4];
131  uint64_t m_timestamp;
135  uint16_t m_driveTag;
136  uint8_t m_padding1[6];
137  };
138 
139 #pragma pack()
140 
141 public:
145  class SBFileException : public std::runtime_error
146  {
147  public:
149  SBFileException(const std::string &inMessage)
150  : std::runtime_error(inMessage)
151  {
152  }
153  };
154 };
155 
156 }; // namespace blfwk
157 
158 #endif // _SBSourceFile_h_
Same version struct used for 3600 boot image.
Definition: SBSourceFile.h:77
SB Format (SB) source file.
Definition: SBSourceFile.h:44
uint16_t m_sectionHeaderSize
Size in blocks of a section header.
Definition: SBSourceFile.h:128
Definition: BlfwkErrors.h:16
uint16_t m_flags
Flags or options associated with the entire image.
Definition: SBSourceFile.h:120
STL namespace.
Simple exception thrown to indicate an error in the input SB file format.
Definition: SBSourceFile.h:145
Binary data file.
Definition: src/blfwk/SourceFile.h:165
section_id_t m_firstBootableSectionID
ID of section to start booting from.
Definition: SBSourceFile.h:123
uint16_t m_headerBlocks
Size of this header, including this size word, in blocks.
Definition: SBSourceFile.h:126
uint16_t m_keyCount
Number of entries in DEK dictionary.
Definition: SBSourceFile.h:124
static bool isSBFile(std::istream &stream)
Identifies whether the stream contains an SB file.
Definition: SBSourceFile.cpp:51
version_t m_componentVersion
Component version.
Definition: SBSourceFile.h:134
SBSourceFile(const std::string &path)
Default constructor.
Definition: SBSourceFile.cpp:42
uint32_t section_id_t
Unique identifier type for a section.
Definition: SBSourceFile.h:70
uint8_t m_majorVersion
Major version for the image format, see #ROM_BOOT_IMAGE_MAJOR_VERSION.
Definition: SBSourceFile.h:118
uint16_t m_driveTag
Drive tag for the system drive which this boot image belongs to.
Definition: SBSourceFile.h:135
virtual ~SBSourceFile()
Destructor.
Definition: SBSourceFile.cpp:47
uint32_t m_imageBlocks
Size of entire image in blocks.
Definition: SBSourceFile.h:121
uint16_t m_sectionCount
Number of section headers in this table.
Definition: SBSourceFile.h:127
SBFileException(const std::string &inMessage)
Default constructor.
Definition: SBSourceFile.h:149
uint32_t m_firstBootTagBlock
Offset from start of file to the first boot tag, in blocks.
Definition: SBSourceFile.h:122
virtual DataSource * createDataSource()
Creates an unmapped data source from the entire file.
Definition: SBSourceFile.cpp:99
Abstract base class for data sources.
Definition: src/blfwk/DataSource.h:56
version_t m_productVersion
Product version.
Definition: SBSourceFile.h:133
uint8_t cipher_block_t[16]
An AES-128 cipher block is 16 bytes.
Definition: SBSourceFile.h:64
uint16_t m_keyDictionaryBlock
Starting block number for the key dictionary.
Definition: SBSourceFile.h:125
uint8_t sha1_digest_t[20]
A SHA-1 digest is 160 bits, or 20 bytes.
Definition: SBSourceFile.h:67
uint8_t m_minorVersion
Minor version of the boot image format, see #ROM_BOOT_IMAGE_MINOR_VERSION.
Definition: SBSourceFile.h:119
Header for the entire boot image.
Definition: SBSourceFile.h:106