Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
EncoreBootImage.h
1 /*
2  * File: EncoreBootImage.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_EncoreBootImage_h_)
8 #define _EncoreBootImage_h_
9 
10 #include <list>
11 #include <vector>
12 #include <string>
13 #include <iostream>
14 #include <fstream>
15 #include <string.h>
16 #include "BootImage.h"
17 #include "rijndael.h"
18 #include "smart_ptr.h"
19 #include "AESKey.h"
20 #include "StExecutableImage.h"
21 
22 namespace elftosb
23 {
25 typedef uint8_t cipher_block_t[16];
26 
28 typedef uint8_t sha1_digest_t[20];
29 
31 typedef uint32_t section_id_t;
32 
34 inline size_t sizeOfCipherBlocks(unsigned count)
35 {
36  return sizeof(cipher_block_t) * count;
37 }
38 
41 inline size_t numberOfCipherBlocks(size_t s)
42 {
43  return (s + sizeof(cipher_block_t) - 1) / sizeof(cipher_block_t);
44 }
45 
48 inline size_t sizeInCipherBlocks(size_t s)
49 {
50  return (unsigned)sizeOfCipherBlocks(numberOfCipherBlocks(s));
51 }
52 
57 inline size_t sizeOfPaddingForCipherBlocks(size_t s)
58 {
59  return sizeInCipherBlocks(s) - s;
60 }
61 
102 {
103 public:
105  enum
106  {
107  ROM_DISPLAY_PROGRESS = (1 << 0),
109  };
110 
111  enum
112  {
114  'STMP',
116  'sgtl',
119  };
120 
121  enum
122  {
124  BOOT_IMAGE_MINIMUM_SECTION_ALIGNMENT = sizeof(cipher_block_t)
125  };
126 
127 // All of these structures are packed to byte alignment in order to match
128 // the structure on disk.
129 #pragma pack(1)
130 
151  {
152  union
153  {
154  sha1_digest_t m_digest;
155  struct
156  {
157  cipher_block_t m_iv;
158  uint8_t m_extra[4];
159  };
160  };
161  uint8_t m_signature[4];
162  uint8_t m_majorVersion;
163  uint8_t m_minorVersion;
164  uint16_t m_flags;
165  uint32_t m_imageBlocks;
168  uint16_t m_keyCount;
170  uint16_t m_headerBlocks;
171  uint16_t m_sectionCount;
173  uint8_t m_padding0[2];
174  uint8_t m_signature2[4];
175  uint64_t m_timestamp;
179  uint16_t m_driveTag;
180  uint8_t m_padding1[6];
181  };
182 
188  {
189  cipher_block_t m_mac;
190  aes128_key_t m_dek;
191  };
192 
195  {
196  dek_dictionary_entry_t m_entries[1];
197  };
198 
200  enum
201  {
202  ROM_SECTION_BOOTABLE = (1 << 0),
204  (1 << 1)
205  };
206 
210  {
211  uint32_t m_tag;
212  uint32_t m_offset;
213  uint32_t m_length;
214  uint32_t m_flags;
215  };
216 
236  {
238  };
239 
250  {
251  uint8_t m_checksum;
252  uint8_t m_tag;
253  uint16_t m_flags;
254  uint32_t m_address;
255  uint32_t m_count;
256  uint32_t m_data;
257  };
258 
259 #pragma pack()
260 
262  enum
263  {
264  ROM_NOP_CMD = 0x00,
265  ROM_TAG_CMD = 0x01,
266  ROM_LOAD_CMD = 0x02,
267  ROM_FILL_CMD = 0x03,
268  ROM_JUMP_CMD = 0x04,
269  ROM_CALL_CMD = 0x05,
270  ROM_MODE_CMD = 0x06,
271  ROM_ERASE_CMD = 0x07,
272  ROM_RESET_CMD = 0x08,
274  ROM_PROG_CMD = 0x0a
275  };
276 
278  enum
279  {
280  ROM_LAST_TAG = (1 << 0)
281  };
282 
284  enum
285  {
286  ROM_LOAD_DCD = (1 << 0)
287  };
288 
290  enum
291  {
295  };
296 
298  enum
299  {
300  ROM_HAB_EXEC = (1 << 0),
301  ROM_JUMP_SP_MASK = (1 << 1)
302  };
303 
305  enum
306  {
309  };
310 
312  enum
313  {
316  };
317 
319  enum
320  {
321  ROM_ERASE_ALL_MASK = (1 << 0),
323  };
324 
326  enum
327  {
329  };
330 
332  enum
333  {
335  };
336 
338  enum
339  {
341  };
342 
343 public:
344  // Forward declaration.
345  class Section;
346 
351  {
352  public:
354 
355  virtual unsigned getBlockCount() const { return 0; }
376  virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data) { return 0; }
378 
380  virtual void debugPrint() const {}
381  };
382 
387  {
388  public:
390  static BootCommand *createFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
391 
392  public:
396  {
397  }
398 
400  virtual ~BootCommand() {}
413  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed) = 0;
414 
416 
417  virtual uint8_t getTag() const = 0;
419 
421  virtual void fillCommandHeader(boot_command_t &header) = 0;
422 
424  virtual uint8_t calculateChecksum(const boot_command_t &header);
426 
428 
429  virtual unsigned getBlockCount() const;
431 
433  virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data);
435 
437 
438  virtual unsigned getDataBlockCount() const { return 0; }
459  virtual unsigned getDataBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data) { return 0; }
461 
462  protected:
464  enum
465  {
466  CMD_TAG_FIELD = 1,
467  CMD_FLAGS_FIELD = 2,
468  CMD_ADDRESS_FIELD = 4,
469  CMD_COUNT_FIELD = 8,
470  CMD_DATA_FIELD = 16
471  };
472 
474  void validateHeader(const boot_command_t *modelHeader, const boot_command_t *testHeader, unsigned whichFields);
475  };
476 
480  class NopCommand : public BootCommand
481  {
482  public:
485  : BootCommand()
486  {
487  }
488 
490  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
491 
493 
494  virtual uint8_t getTag() const { return ROM_NOP_CMD; }
497  virtual void fillCommandHeader(boot_command_t &header);
499 
501  virtual void debugPrint() const;
502  };
503 
507  class TagCommand : public BootCommand
508  {
509  public:
512  : BootCommand()
513  {
514  }
515 
517  TagCommand(const Section &section);
518 
520  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
521 
523 
524  virtual uint8_t getTag() const { return ROM_TAG_CMD; }
527  virtual void fillCommandHeader(boot_command_t &header);
529 
531 
532  inline void setSectionIdentifier(uint32_t identifier) { m_sectionIdentifier = identifier; }
533  inline void setSectionLength(uint32_t length) { m_sectionLength = length; }
534  inline void setSectionFlags(uint32_t flags) { m_sectionFlags = flags; }
535  inline void setLast(bool isLast) { m_isLast = isLast; }
537 
539  virtual void debugPrint() const;
540 
541  protected:
543  uint32_t m_sectionLength;
544  uint32_t m_sectionFlags;
545  bool m_isLast;
546  };
547 
551  class LoadCommand : public BootCommand
552  {
553  public:
555  LoadCommand();
556 
558  LoadCommand(uint32_t address, const uint8_t *data, uint32_t length);
559 
561  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
562 
564 
565  virtual uint8_t getTag() const { return ROM_LOAD_CMD; }
568  virtual void fillCommandHeader(boot_command_t &header);
569 
571  inline void setDCD(bool isDCD) { m_loadDCD = isDCD; }
573 
575 
576  inline void setLoadAddress(uint32_t address) { m_address = address; }
577  inline uint32_t getLoadAddress() const { return m_address; }
579 
581 
582  void setData(const uint8_t *data, uint32_t length);
584 
585  inline uint8_t *getData() { return m_data; }
586  inline const uint8_t *getData() const { return m_data; }
587  inline uint32_t getLength() const { return m_length; }
589 
591 
592  virtual unsigned getDataBlockCount() const;
594 
596  virtual unsigned getDataBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data);
598 
600  virtual void debugPrint() const;
601 
602  protected:
604  uint8_t m_padding[15];
605  unsigned m_padCount;
606  uint32_t m_length;
607  uint32_t m_address;
608  bool m_loadDCD;
609 
610  void fillPadding();
611  uint32_t calculateCRC() const;
612  };
613 
617  class FillCommand : public BootCommand
618  {
619  public:
621  FillCommand();
622 
624  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
625 
627 
628  virtual uint8_t getTag() const { return ROM_FILL_CMD; }
631  virtual void fillCommandHeader(boot_command_t &header);
633 
635 
636  inline void setAddress(uint32_t address) { m_address = address; };
637  inline uint32_t getAddress() const { return m_address; }
638  inline void setFillCount(uint32_t count) { m_count = count; }
639  inline uint32_t getFillCount() const { return m_count; }
641 
643 
644  void setPattern(uint8_t pattern);
645  void setPattern(uint16_t pattern);
646  void setPattern(uint32_t pattern);
647 
648  inline uint32_t getPattern() const { return m_pattern; }
650 
652  virtual void debugPrint() const;
653 
654  protected:
655  uint32_t m_address;
656  uint32_t m_count;
657  uint32_t m_pattern;
658  };
659 
663  class ModeCommand : public BootCommand
664  {
665  public:
668  : BootCommand()
669  , m_mode(0)
670  {
671  }
672 
674  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
675 
677 
678  virtual uint8_t getTag() const { return ROM_MODE_CMD; }
681  virtual void fillCommandHeader(boot_command_t &header);
683 
685 
686  inline void setBootMode(uint32_t mode) { m_mode = mode; }
687  inline uint32_t getBootMode() const { return m_mode; }
689 
691  virtual void debugPrint() const;
692 
693  protected:
694  uint32_t m_mode;
695  };
696 
700  class EraseCommand : public BootCommand
701  {
702  public:
705  : BootCommand()
706  , m_doEraseAll(false)
707  , m_doEraseAllUnsecure(false)
708  , m_startAddress(0)
709  , m_byteCount(0)
710  , m_memoryId(0)
711  {
712  }
713 
715  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
716 
718 
719  virtual uint8_t getTag() const { return ROM_ERASE_CMD; }
722  virtual void fillCommandHeader(boot_command_t &header);
724 
726 
727  void setEraseAll(bool doEraseAll) { m_doEraseAll = doEraseAll; }
728  bool getEraseAll() const { return m_doEraseAll; }
730 
732 
733  void setEraseAllUnsecure(bool doEraseAllUnsecure) { m_doEraseAllUnsecure = doEraseAllUnsecure; }
734  bool getEraseAllUnsecure() const { return m_doEraseAllUnsecure; }
736 
738 
739  void setAddressRange(uint32_t startAddress, uint32_t count);
740  void getAddressRange(uint32_t *startAddress, uint32_t *count) const;
742 
744 
745  void setMemoryId(uint32_t memId) { m_memoryId = memId; }
746  uint32_t getMemoryId() const { return m_memoryId; }
748 
750  virtual void debugPrint() const;
751 
752  protected:
753  bool m_doEraseAll;
754  bool m_doEraseAllUnsecure;
755  uint32_t m_startAddress;
756  uint32_t m_byteCount;
757  uint32_t m_memoryId;
758  };
759 
764  {
765  public:
768  : BootCommand()
769  , m_isEightByte(false)
770  , m_index(0)
771  , m_dataWord1(0)
772  , m_dataWord2(0)
773  , m_memSpace(0)
774  {
775  }
776 
778  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
779 
781 
782  virtual uint8_t getTag() const { return ROM_PROG_CMD; }
785  virtual void fillCommandHeader(boot_command_t &header);
787 
789 
790  void setIsEightByte(bool doIt) { m_isEightByte = doIt; }
791  bool isEightByte() const { return m_isEightByte; }
793 
795 
796  void setMemSpace(uint32_t id) { m_memSpace = id; }
797  uint32_t getMemSpace() const { return m_memSpace; }
799 
801 
802  void setIndex(uint32_t index) { m_index = index; }
803  uint32_t getIndex() const { return m_index; }
805 
807 
808  void setDataWord1(uint32_t dataWord) { m_dataWord1 = dataWord; }
809  uint32_t getDataWord1() const { return m_dataWord1; }
811 
813 
814  void setDataWord2(uint32_t dataWord) { m_dataWord2 = dataWord; }
815  uint32_t getDataWord2() const { return m_dataWord2; }
817 
819  virtual void debugPrint() const;
820 
821  protected:
823  uint32_t m_index;
824  uint32_t m_dataWord1;
825  uint32_t m_dataWord2;
826  uint32_t m_memSpace;
827  };
828 
832  class JumpCommand : public BootCommand
833  {
834  public:
837  : BootCommand()
838  , m_address(0)
839  , m_argument(0)
840  , m_isHAB(false)
841  , m_ivtSize(0)
842  , m_stackPointer(0)
843  , m_isStackPointerSet(false)
844  {
845  }
846 
848  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
849 
851 
852  virtual uint8_t getTag() const { return ROM_JUMP_CMD; }
855  virtual void fillCommandHeader(boot_command_t &header);
857 
859 
860  inline void setAddress(uint32_t address) { m_address = address; }
861  inline uint32_t getAddress() const { return m_address; }
862  inline void setArgument(uint32_t argument) { m_argument = argument; }
863  inline uint32_t getArgument() const { return m_argument; }
864  inline void setIsHAB(bool isHAB) { m_isHAB = isHAB; }
865  inline bool isHAB() const { return m_isHAB; }
866  inline void setIVTSize(uint32_t ivtSize) { m_ivtSize = ivtSize; }
867  inline uint32_t getIVTSize() const { return m_ivtSize; }
868  inline void setStackPointer(uint32_t sp) { m_stackPointer = sp; }
869  inline uint32_t getStackPointer() { return m_stackPointer; }
870  inline void setIsStackPointerSet(bool isSP) { m_isStackPointerSet = isSP; }
871  inline bool IsStackPointerSet() const { return m_isStackPointerSet; }
873 
875  virtual void debugPrint() const;
876 
877  protected:
878  uint32_t m_address;
879  uint32_t m_argument;
880  uint32_t m_stackPointer;
881  bool m_isHAB;
882  bool m_isStackPointerSet;
884  uint32_t m_ivtSize;
885  };
886 
890  class CallCommand : public JumpCommand
891  {
892  public:
895  : JumpCommand()
896  {
897  }
898 
900  virtual uint8_t getTag() const { return ROM_CALL_CMD; }
902  virtual void debugPrint() const;
903  };
904 
908  class ResetCommand : public BootCommand
909  {
910  public:
913  : BootCommand()
914  {
915  }
916 
918  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
919 
921 
922  virtual uint8_t getTag() const { return ROM_RESET_CMD; }
925  virtual void fillCommandHeader(boot_command_t &header);
927 
929  virtual void debugPrint() const;
930 
931  protected:
932  };
933 
938  {
939  public:
942  : BootCommand()
943  , m_startAddress(0)
944  , m_byteCount(0)
945  , m_memControllerId(0)
946  {
947  }
948 
950  virtual void initFromData(const cipher_block_t *blocks, unsigned count, unsigned *consumed);
951 
953 
954  virtual uint8_t getTag() const { return ROM_MEM_ENABLE_CMD; }
957  virtual void fillCommandHeader(boot_command_t &header);
959 
961 
962  void setAddressRange(uint32_t startAddress, uint32_t count);
963  void getAddressRange(uint32_t *startAddress, uint32_t *count) const;
965 
967 
968  void setMemControllerId(uint32_t memControllerId) { m_memControllerId = memControllerId; }
969  uint32_t getMemControllerId() const { return m_memControllerId; }
971 
973  virtual void debugPrint() const;
974 
975  protected:
976  uint32_t m_startAddress;
977  uint32_t m_byteCount;
978  uint32_t m_memControllerId;
979  };
980 
990  {
991  public:
995  , m_identifier(0)
996  , m_image(0)
998  , m_flags(0)
999  , m_leaveUnencrypted(false)
1000  {
1001  }
1002 
1004  Section(uint32_t identifier)
1006  , m_identifier(identifier)
1007  , m_image(0)
1009  , m_flags(0)
1010  , m_leaveUnencrypted(false)
1011  {
1012  }
1013 
1015 
1016  inline void setIdentifier(uint32_t identifier) { m_identifier = identifier; }
1017  inline uint32_t getIdentifier() const { return m_identifier; }
1019 
1021 
1022  virtual void setFlags(uint32_t flags) { m_flags = flags; }
1029  virtual uint32_t getFlags() const { return m_flags | (m_leaveUnencrypted ? ROM_SECTION_CLEARTEXT : 0); }
1031  virtual void fillSectionHeader(section_header_t &header);
1033 
1035 
1036  void setImage(EncoreBootImage *image) { m_image = image; }
1039  EncoreBootImage *getImage() const { return m_image; }
1041 
1043 
1044  void setAlignment(unsigned alignment);
1046 
1048  unsigned getAlignment() const { return m_alignment; }
1050  unsigned getPadBlockCountForOffset(unsigned offset);
1052 
1054 
1055  void setLeaveUnencrypted(unsigned flag) { m_leaveUnencrypted = flag; }
1058  bool getLeaveUnencrypted() const { return m_leaveUnencrypted; }
1060 
1061  protected:
1062  uint32_t m_identifier;
1064  unsigned m_alignment;
1065  uint32_t m_flags;
1067  };
1068 
1072  class BootSection : public Section
1073  {
1074  public:
1075  typedef std::list<BootCommand *> command_list_t;
1076  typedef command_list_t::iterator iterator_t;
1077  typedef command_list_t::const_iterator const_iterator_t;
1078 
1079  public:
1082  : Section()
1083  {
1084  }
1085 
1087  BootSection(uint32_t identifier)
1088  : Section(identifier)
1089  {
1090  }
1091 
1093  virtual ~BootSection();
1094 
1096  virtual void fillFromData(const cipher_block_t *blocks, unsigned count);
1097 
1099 
1100  virtual uint32_t getFlags() const { return Section::getFlags() | ROM_SECTION_BOOTABLE; }
1103 
1105 
1106  void addCommand(BootCommand *command) { m_commands.push_back(command); }
1112  unsigned getCommandCount() const { return (unsigned)m_commands.size(); }
1113  iterator_t begin() { return m_commands.begin(); }
1114  iterator_t end() { return m_commands.end(); }
1115  const_iterator_t begin() const { return m_commands.begin(); }
1116  const_iterator_t end() const { return m_commands.end(); }
1118 
1120 
1121  virtual unsigned getBlockCount() const;
1123 
1125  virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data);
1127 
1129  virtual void debugPrint() const;
1130 
1131  protected:
1132  command_list_t m_commands;
1133 
1134  protected:
1136  void deleteCommands();
1137  };
1138 
1142  class DataSection : public Section
1143  {
1144  public:
1147  : Section()
1148  , m_data()
1149  , m_length(0)
1150  {
1151  }
1152 
1154  DataSection(uint32_t identifier)
1155  : Section(identifier)
1156  , m_data()
1157  , m_length(0)
1158  {
1159  }
1160 
1162  void setData(const uint8_t *data, unsigned length);
1163 
1165  void setDataNoCopy(const uint8_t *data, unsigned length);
1166 
1168 
1169  virtual unsigned getBlockCount() const;
1171 
1173  virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data);
1175 
1177  virtual void debugPrint() const;
1178 
1179  protected:
1181  unsigned m_length;
1182  };
1183 
1184 public:
1185  typedef std::list<Section *> section_list_t;
1186  typedef section_list_t::iterator section_iterator_t;
1187  typedef section_list_t::const_iterator const_section_iterator_t;
1188 
1189  typedef std::vector<AES128Key> key_list_t;
1190  typedef key_list_t::iterator key_iterator_t;
1191  typedef key_list_t::const_iterator const_key_iterator_t;
1192 
1193 public:
1195  EncoreBootImage();
1196 
1198  virtual ~EncoreBootImage();
1199 
1201 
1202  void addSection(Section *newSection);
1203  inline unsigned sectionCount() const { return (unsigned)m_sections.size(); }
1204  inline section_iterator_t beginSection() { return m_sections.begin(); }
1205  inline section_iterator_t endSection() { return m_sections.end(); }
1206  inline const_section_iterator_t beginSection() const { return m_sections.begin(); }
1207  inline const_section_iterator_t endSection() const { return m_sections.end(); }
1208  section_iterator_t findSection(Section *section);
1209 
1211  uint32_t getSectionOffset(Section *section);
1213 
1215 
1216  inline void addKey(const AES128Key &newKey) { m_keys.push_back(newKey); }
1217  inline unsigned keyCount() const { return (unsigned)m_keys.size(); }
1218  inline key_iterator_t beginKeys() { return m_keys.begin(); }
1219  inline key_iterator_t endKeys() { return m_keys.end(); }
1220  inline const_key_iterator_t beginKeys() const { return m_keys.begin(); }
1221  inline const_key_iterator_t endKeys() const { return m_keys.end(); }
1223  inline bool isEncrypted() const { return m_keys.size() != 0; }
1225 
1227 
1228  virtual void setProductVersion(const version_t &version);
1229  virtual void setComponentVersion(const version_t &version);
1231 
1233 
1234  inline void setFlags(uint16_t flags) { m_headerFlags = flags; }
1235  inline uint32_t getFlags() const { return m_headerFlags; }
1237 
1239  virtual void setDriveTag(uint16_t tag) { m_driveTag = tag; }
1241  uint32_t getImageSize();
1242 
1244  virtual std::string getFileExtension() const { return ".sb"; }
1246 
1247  virtual void writeToStream(std::ostream &stream);
1250 
1252  virtual void debugPrint() const;
1253 
1254 protected:
1255  uint16_t m_headerFlags;
1258  uint16_t m_driveTag;
1259  section_list_t m_sections;
1260  key_list_t m_keys;
1262 
1263  void prepareImageHeader(boot_image_header_t &header);
1264  uint64_t getTimestamp();
1266  unsigned getPadBlockCountForSection(Section *section, unsigned offset);
1267 };
1268 
1269 }; // namespace elftosb
1270 
1271 #endif // _EncoreBootImage_h_
virtual ~EncoreBootImage()
Destructor.
Definition: EncoreBootImage.cpp:31
Jump to address command.
Definition: EncoreBootImage.h:268
Value for elftosb::EncoreBootImage::boot_image_header_t::m_signature2;.
Definition: EncoreBootImage.h:115
AES128Key m_sessionKey
Session key we&#39;re using.
Definition: EncoreBootImage.h:1261
The DEK dictionary always follows the image header, in the next cipher block.
Definition: EncoreBootImage.h:194
uint32_t m_sectionLength
Number of cipher blocks this section occupies.
Definition: EncoreBootImage.h:543
Pattern fill command.
Definition: EncoreBootImage.h:267
section_id_t m_firstBootableSectionID
ID of section to start booting from.
Definition: EncoreBootImage.h:167
void setDCD(bool isDCD)
Sets the load-dcd flag.
Definition: EncoreBootImage.h:571
uint16_t m_headerFlags
Flags field in the boot image header.
Definition: EncoreBootImage.h:1255
Section tag bootloader command.
Definition: EncoreBootImage.h:507
Call function command.
Definition: EncoreBootImage.h:269
MemEnableCommand()
Default constructor.
Definition: EncoreBootImage.h:941
Base class for a section of an Encore boot image.
Definition: EncoreBootImage.h:989
uint32_t m_firstBootTagBlock
Offset from start of file to the first boot tag, in blocks.
Definition: EncoreBootImage.h:166
DataSection(uint32_t identifier)
Constructor taking the unique identifier for this section.
Definition: EncoreBootImage.h:1154
EncoreBootImage()
Default constructor.
Definition: EncoreBootImage.cpp:23
unsigned m_alignment
Alignment requirement for the start of this section.
Definition: EncoreBootImage.h:1064
Current boot image major version.
Definition: EncoreBootImage.h:117
uint32_t m_stackPointer
Stack pointer for "jump sp" command.
Definition: EncoreBootImage.h:880
Change boot mode bootloader command.
Definition: EncoreBootImage.h:663
BootCommand()
Default constructor.
Definition: EncoreBootImage.h:394
Load data command.
Definition: EncoreBootImage.h:266
uint8_t m_majorVersion
Major version for the image format, see ROM_BOOT_IMAGE_MAJOR_VERSION.
Definition: EncoreBootImage.h:162
key_list_t m_keys
List of key encryption keys. If empty, the image is unencrypted.
Definition: EncoreBootImage.h:1260
A bootable section of an Encore boot image.
Definition: EncoreBootImage.h:1072
Signature in elftosb::EncoreBootImage::boot_image_header_t::m_signature.
Definition: EncoreBootImage.h:113
IFR memory.
Definition: EncoreBootImage.h:340
std::list< Section * > section_list_t
List of image sections.
Definition: EncoreBootImage.h:1185
Bit position of mem space ID.
Definition: EncoreBootImage.h:315
Reset command.
Definition: EncoreBootImage.h:272
Fill with word sized pattern.
Definition: EncoreBootImage.h:294
uint32_t m_tag
Unique identifier for this section. High bit must be zero.
Definition: EncoreBootImage.h:211
Call function bootloader command.
Definition: EncoreBootImage.h:890
uint32_t m_count
Number of bytes to fill.
Definition: EncoreBootImage.h:656
Section tag command.
Definition: EncoreBootImage.h:265
TagCommand()
Default constructor.
Definition: EncoreBootImage.h:511
uint16_t m_sectionCount
Number of section headers in this table.
Definition: EncoreBootImage.h:171
EncoreBootImage * m_image
The image to which this section belongs.
Definition: EncoreBootImage.h:1063
uint32_t m_length
Number of bytes to load.
Definition: EncoreBootImage.h:606
Erase all flash instead of just a range.
Definition: EncoreBootImage.h:321
section_list_t m_sections
Sections contained in this image.
Definition: EncoreBootImage.h:1259
uint16_t m_keyDictionaryBlock
Starting block number for the key dictionary.
Definition: EncoreBootImage.h:169
uint32_t m_dataWord2
Second 4 bytes to write, valid if m_doEightByte is true.
Definition: EncoreBootImage.h:825
Section(uint32_t identifier)
Constructor taking the unique identifier for this section.
Definition: EncoreBootImage.h:1004
uint8_t m_padding1[6]
Padding to round up to next cipher block.
Definition: EncoreBootImage.h:180
uint8_t m_minorVersion
Minor version of the boot image format, see ROM_BOOT_IMAGE_MINOR_VERSION.
Definition: EncoreBootImage.h:163
uint32_t m_count
Number of bytes on which to operate.
Definition: EncoreBootImage.h:255
uint32_t m_pattern
Fill pattern.
Definition: EncoreBootImage.h:657
key_list_t::iterator key_iterator_t
Iterator over KEKs.
Definition: EncoreBootImage.h:1190
uint32_t getImageSize()
Calculates the total number of cipher blocks the image consumes.
Definition: EncoreBootImage.cpp:488
ResetCommand()
Default constructor.
Definition: EncoreBootImage.h:912
EraseCommand()
Default constructor.
Definition: EncoreBootImage.h:704
virtual ~BootCommand()
Destructor.
Definition: EncoreBootImage.h:400
uint32_t m_index
Index to write to.
Definition: EncoreBootImage.h:823
uint32_t m_identifier
Unique identifier for this section.
Definition: EncoreBootImage.h:1062
Class to manage Encore boot image files.
Definition: EncoreBootImage.h:101
section_list_t::const_iterator const_section_iterator_t
Const iterator over sections.
Definition: EncoreBootImage.h:1187
uint32_t m_address
Address of the code to execute.
Definition: EncoreBootImage.h:878
Memory Enable bootloader command.
Definition: EncoreBootImage.h:937
bool m_isLast
Is this the last tag command?
Definition: EncoreBootImage.h:545
Fill with byte sized pattern.
Definition: EncoreBootImage.h:292
virtual void setDriveTag(uint16_t tag)
Specify the drive tag to be set in the output file header.
Definition: EncoreBootImage.h:1239
Entry in elftosb::EncoreBootImage::dek_dictionary_t.
Definition: EncoreBootImage.h:187
Information about each section, held in the section table.
Definition: EncoreBootImage.h:209
std::vector< AES128Key > key_list_t
List of KEKs.
Definition: EncoreBootImage.h:1189
uint16_t m_driveTag
System drive tag for this boot image.
Definition: EncoreBootImage.h:1258
Minimum alignment for a section is 16 bytes.
Definition: EncoreBootImage.h:124
Flash erase command.
Definition: EncoreBootImage.h:271
A non-bootable section of an Encore boot image.
Definition: EncoreBootImage.h:1142
bool m_isEightByte
True if doing 8-byte write.
Definition: EncoreBootImage.h:822
Program 8 bytes instead of 4 bytes.
Definition: EncoreBootImage.h:328
version_t m_componentVersion
Component version.
Definition: EncoreBootImage.h:1257
Changes jump or call command to a HAB jump or call.
Definition: EncoreBootImage.h:300
uint32_t getSectionOffset(Section *section)
Calculates the starting block number for the given section.
Definition: EncoreBootImage.cpp:430
unsigned getPadBlockCountForSection(Section *section, unsigned offset)
Definition: EncoreBootImage.cpp:464
bool isEncrypted() const
The image is encrypted if there is at least one key.
Definition: EncoreBootImage.h:1223
version_t m_productVersion
Product version.
Definition: EncoreBootImage.h:1256
aes128_key_t m_dek
AES-128 key with which the image payload is encrypted.
Definition: EncoreBootImage.h:190
Fill with half-word sized pattern.
Definition: EncoreBootImage.h:293
virtual void debugPrint() const
Print out a string representation of the object.
Definition: EncoreBootImage.h:380
Base class for objects that produce cipher blocks.
Definition: EncoreBootImage.h:350
Print progress reports.
Definition: EncoreBootImage.h:107
DataSection()
Default constructor.
Definition: EncoreBootImage.h:1146
ProgramCommand()
Default constructor.
Definition: EncoreBootImage.h:767
Definition: BootImage.h:13
Program persistent bits command.
Definition: EncoreBootImage.h:274
uint16_t m_driveTag
Drive tag for the system drive which this boot image belongs to.
Definition: EncoreBootImage.h:179
unsigned getAlignment() const
Returns the current alignment, the minimum of which will be 16.
Definition: EncoreBootImage.h:1048
Erase bootloader command.
Definition: EncoreBootImage.h:700
uint8_t m_signature[4]
&#39;STMP&#39;, see ROM_IMAGE_HEADER_SIGNATURE.
Definition: EncoreBootImage.h:161
version_t m_componentVersion
Component version.
Definition: EncoreBootImage.h:178
Structure for a Piano bootloader command.
Definition: EncoreBootImage.h:249
virtual uint32_t getFlags() const
Returns the flags for this section.
Definition: EncoreBootImage.h:1029
uint32_t m_argument
Sole argument to pass to code.
Definition: EncoreBootImage.h:879
Abstract base class for all bootloader commands.
Definition: EncoreBootImage.h:386
uint32_t m_memSpace
ID of memory space, e.g. 1=IFR0.
Definition: EncoreBootImage.h:826
Progress reports are verbose.
Definition: EncoreBootImage.h:108
key_list_t::const_iterator const_key_iterator_t
Const iterator over KEKs.
Definition: EncoreBootImage.h:1191
version_t m_productVersion
Product version.
Definition: EncoreBootImage.h:177
uint32_t m_ivtSize
Whether this jump call has an initial stack pointer set.
Definition: EncoreBootImage.h:884
bool m_loadDCD
Whether to execute the DCD after loading.
Definition: EncoreBootImage.h:608
No operation bootloader command.
Definition: EncoreBootImage.h:480
cipher_block_t m_mac
CBC-MAC of the header.
Definition: EncoreBootImage.h:189
EncoreBootImage * getImage() const
Returns a pointer to the image that this section belongs to.
Definition: EncoreBootImage.h:1039
This tag command is the last one in the image.
Definition: EncoreBootImage.h:280
uint32_t m_sectionIdentifier
Unique identifier for the section containing this command.
Definition: EncoreBootImage.h:542
bool m_leaveUnencrypted
Set to true to prevent this section from being encrypted.
Definition: EncoreBootImage.h:1066
uint8_t m_padding0[2]
Padding to align m_timestamp to long word.
Definition: EncoreBootImage.h:173
Erase all unsecure (available on some Kinetis parts).
Definition: EncoreBootImage.h:322
BootSection(uint32_t identifier)
Constructor taking the unique identifier for this section.
Definition: EncoreBootImage.h:1087
The section contains bootloader commands.
Definition: EncoreBootImage.h:202
command_list_t m_commands
Commands held in this section.
Definition: EncoreBootImage.h:1132
Change boot mode command.
Definition: EncoreBootImage.h:270
virtual void debugPrint() const
Print out a string representation of the object.
Definition: EncoreBootImage.cpp:513
uint16_t m_keyCount
Number of entries in DEK dictionary.
Definition: EncoreBootImage.h:168
bool getLeaveUnencrypted() const
Returns true if the section will remain unencrypted.
Definition: EncoreBootImage.h:1058
uint32_t m_flags
Section flags set by the user.
Definition: EncoreBootImage.h:1065
Bit position of mem controller ID.
Definition: EncoreBootImage.h:308
BootSection()
Default constructor.
Definition: EncoreBootImage.h:1081
void addSection(Section *newSection)
Definition: EncoreBootImage.cpp:43
Memory Enable command.
Definition: EncoreBootImage.h:273
Section()
Default constructor.
Definition: EncoreBootImage.h:993
unsigned m_padCount
Number of pad bytes.
Definition: EncoreBootImage.h:605
An index of all sections within the boot image.
Definition: EncoreBootImage.h:235
uint32_t m_dataWord1
First 4 bytes to write.
Definition: EncoreBootImage.h:824
section_list_t::iterator section_iterator_t
Iterator over sections.
Definition: EncoreBootImage.h:1186
Bit mask for mem space ID.
Definition: EncoreBootImage.h:314
Abstract base class for all boot image format classes.
Definition: BootImage.h:25
virtual unsigned getDataBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data)
Returns the contents of up to maxCount data blocks.
Definition: EncoreBootImage.h:459
Pattern fill bootloader command.
Definition: EncoreBootImage.h:617
uint32_t m_mode
New boot mode.
Definition: EncoreBootImage.h:694
Program persistent bits bootloader command.
Definition: EncoreBootImage.h:763
uint32_t m_length
Size of section data in blocks.
Definition: EncoreBootImage.h:213
smart_array_ptr< uint8_t > m_data
Pointer to data to load.
Definition: EncoreBootImage.h:603
Initial stack pointer is specified for jump command.
Definition: EncoreBootImage.h:301
uint16_t m_flags
Flags or options associated with the entire image.
Definition: EncoreBootImage.h:164
uint32_t m_address
Fill start address.
Definition: EncoreBootImage.h:655
The section is unencrypted. Applies only if the rest of the boot image is encrypted.
Definition: EncoreBootImage.h:203
Jump to address bootloader command.
Definition: EncoreBootImage.h:832
uint64_t getTimestamp()
Definition: EncoreBootImage.cpp:394
Same version struct used for 3600 boot image.
Definition: Version.h:16
smart_array_ptr< uint8_t > m_data
The section&#39;s contents.
Definition: EncoreBootImage.h:1180
Reset target bootloader command.
Definition: EncoreBootImage.h:908
NopCommand()
Default constructor.
Definition: EncoreBootImage.h:484
JumpCommand()
Default constructor.
Definition: EncoreBootImage.h:836
CallCommand()
Default constructor.
Definition: EncoreBootImage.h:894
Load data bootloader command.
Definition: EncoreBootImage.h:551
uint8_t m_signature2[4]
Definition: EncoreBootImage.h:174
uint32_t m_sectionFlags
Flags pertaining to this section.
Definition: EncoreBootImage.h:544
unsigned getCommandCount() const
Returns the number of commands in this section, excluding the tag command.
Definition: EncoreBootImage.h:1112
virtual uint8_t getTag() const
Returns the tag value for this command.
Definition: EncoreBootImage.h:900
uint32_t m_address
Address to which data will be loaded.
Definition: EncoreBootImage.h:607
uint16_t m_flags
Flags for this command.
Definition: EncoreBootImage.h:253
uint32_t m_offset
Offset to section data from start of image in blocks.
Definition: EncoreBootImage.h:212
Header for the entire boot image.
Definition: EncoreBootImage.h:150
virtual std::string getFileExtension() const
Returns the preferred ".sb" extension for Encore boot images.
Definition: EncoreBootImage.h:1244
virtual void writeToStream(std::ostream &stream)
Write the boot image to an output stream.
Definition: EncoreBootImage.cpp:84
uint8_t m_tag
Tag telling which command this is.
Definition: EncoreBootImage.h:252
uint32_t m_data
Additional data used by certain commands.
Definition: EncoreBootImage.h:256
Section * findFirstBootableSection()
Definition: EncoreBootImage.cpp:410
virtual unsigned getBlocks(unsigned offset, unsigned maxCount, cipher_block_t *data)
Returns the contents of up to maxCount cipher blocks.
Definition: EncoreBootImage.h:376
ModeCommand()
Default constructor.
Definition: EncoreBootImage.h:667
bool m_isHAB
Definition: EncoreBootImage.h:881
uint16_t m_sectionHeaderSize
Size in blocks of a section header.
Definition: EncoreBootImage.h:172
Execute the DCD after loading completes.
Definition: EncoreBootImage.h:286
External QuadSpi controller.
Definition: EncoreBootImage.h:334
uint16_t m_headerBlocks
Size of this header, including this size word, in blocks.
Definition: EncoreBootImage.h:170
uint32_t m_imageBlocks
Size of entire image in blocks.
Definition: EncoreBootImage.h:165
Current boot image minor version.
Definition: EncoreBootImage.h:118
uint32_t m_address
Target address.
Definition: EncoreBootImage.h:254
unsigned m_length
Number of bytes of data.
Definition: EncoreBootImage.h:1181
uint32_t m_flags
Section flags.
Definition: EncoreBootImage.h:214
uint64_t m_timestamp
Timestamp when image was generated in microseconds since 1-1-2000.
Definition: EncoreBootImage.h:176
uint8_t m_checksum
Simple checksum over other command fields.
Definition: EncoreBootImage.h:251
A no-op command.
Definition: EncoreBootImage.h:264
Bit mask for mem controller ID.
Definition: EncoreBootImage.h:307