mxsimage.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Freescale i.MX28 SB image generator
  4. *
  5. * Copyright (C) 2012 Marek Vasut <marex@denx.de>
  6. */
  7. #ifndef __MXSSB_H__
  8. #define __MXSSB_H__
  9. #include <stdint.h>
  10. #include <arpa/inet.h>
  11. #define SB_BLOCK_SIZE 16
  12. #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y))
  13. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  14. struct sb_boot_image_version {
  15. uint16_t major;
  16. uint16_t pad0;
  17. uint16_t minor;
  18. uint16_t pad1;
  19. uint16_t revision;
  20. uint16_t pad2;
  21. };
  22. struct sb_boot_image_header {
  23. union {
  24. /* SHA1 of the header. */
  25. uint8_t digest[20];
  26. struct {
  27. /* CBC-MAC initialization vector. */
  28. uint8_t iv[16];
  29. uint8_t extra[4];
  30. };
  31. };
  32. /* 'STMP' */
  33. uint8_t signature1[4];
  34. /* Major version of the image format. */
  35. uint8_t major_version;
  36. /* Minor version of the image format. */
  37. uint8_t minor_version;
  38. /* Flags associated with the image. */
  39. uint16_t flags;
  40. /* Size of the image in 16b blocks. */
  41. uint32_t image_blocks;
  42. /* Offset of the first tag in 16b blocks. */
  43. uint32_t first_boot_tag_block;
  44. /* ID of the section to boot from. */
  45. uint32_t first_boot_section_id;
  46. /* Amount of crypto keys. */
  47. uint16_t key_count;
  48. /* Offset to the key dictionary in 16b blocks. */
  49. uint16_t key_dictionary_block;
  50. /* Size of this header in 16b blocks. */
  51. uint16_t header_blocks;
  52. /* Amount of section headers. */
  53. uint16_t section_count;
  54. /* Section header size in 16b blocks. */
  55. uint16_t section_header_size;
  56. /* Padding to align timestamp to uint64_t. */
  57. uint8_t padding0[2];
  58. /* 'sgtl' (since v1.1) */
  59. uint8_t signature2[4];
  60. /* Image generation date, in microseconds since 1.1.2000 . */
  61. uint64_t timestamp_us;
  62. /* Product version. */
  63. struct sb_boot_image_version
  64. product_version;
  65. /* Component version. */
  66. struct sb_boot_image_version
  67. component_version;
  68. /* Drive tag for the system drive. (since v1.1) */
  69. uint16_t drive_tag;
  70. /* Padding. */
  71. uint8_t padding1[6];
  72. };
  73. #define SB_VERSION_MAJOR 1
  74. #define SB_VERSION_MINOR 1
  75. /* Enable to HTLLC boot report. */
  76. #define SB_IMAGE_FLAG_DISPLAY_PROGRESS (1 << 0)
  77. #define SB_IMAGE_FLAGS_MASK SB_IMAGE_FLAG_DISPLAY_PROGRESS
  78. struct sb_key_dictionary_key {
  79. /* The CBC-MAC of image and sections header. */
  80. uint8_t cbc_mac[SB_BLOCK_SIZE];
  81. /* The AES key encrypted by image key (zero). */
  82. uint8_t key[SB_BLOCK_SIZE];
  83. };
  84. struct sb_ivt_header {
  85. uint32_t header;
  86. uint32_t entry;
  87. uint32_t reserved1;
  88. uint32_t dcd;
  89. uint32_t boot_data;
  90. uint32_t self;
  91. uint32_t csf;
  92. uint32_t reserved2;
  93. };
  94. #define SB_HAB_IVT_TAG 0xd1UL
  95. #define SB_HAB_DCD_TAG 0xd2UL
  96. #define SB_HAB_VERSION 0x40UL
  97. /*
  98. * The "size" field in the IVT header is not naturally aligned,
  99. * use this macro to fill first 4 bytes of the IVT header without
  100. * causing issues on some systems (esp. M68k, PPC, MIPS-BE, ARM-BE).
  101. */
  102. static inline uint32_t sb_hab_ivt_header(void)
  103. {
  104. uint32_t ret = 0;
  105. ret |= SB_HAB_IVT_TAG << 24;
  106. ret |= sizeof(struct sb_ivt_header) << 16;
  107. ret |= SB_HAB_VERSION;
  108. return htonl(ret);
  109. }
  110. struct sb_sections_header {
  111. /* Section number. */
  112. uint32_t section_number;
  113. /* Offset of this sections first instruction after "TAG". */
  114. uint32_t section_offset;
  115. /* Size of the section in 16b blocks. */
  116. uint32_t section_size;
  117. /* Section flags. */
  118. uint32_t section_flags;
  119. };
  120. #define SB_SECTION_FLAG_BOOTABLE (1 << 0)
  121. struct sb_command {
  122. struct {
  123. uint8_t checksum;
  124. uint8_t tag;
  125. uint16_t flags;
  126. #define ROM_TAG_CMD_FLAG_ROM_LAST_TAG 0x1
  127. #define ROM_LOAD_CMD_FLAG_DCD_LOAD 0x1 /* MX28 only */
  128. #define ROM_JUMP_CMD_FLAG_HAB 0x1 /* MX28 only */
  129. #define ROM_CALL_CMD_FLAG_HAB 0x1 /* MX28 only */
  130. } header;
  131. union {
  132. struct {
  133. uint32_t reserved[3];
  134. } nop;
  135. struct {
  136. uint32_t section_number;
  137. uint32_t section_length;
  138. uint32_t section_flags;
  139. } tag;
  140. struct {
  141. uint32_t address;
  142. uint32_t count;
  143. uint32_t crc32;
  144. } load;
  145. struct {
  146. uint32_t address;
  147. uint32_t count;
  148. uint32_t pattern;
  149. } fill;
  150. struct {
  151. uint32_t address;
  152. uint32_t reserved;
  153. /* Passed in register r0 before JUMP */
  154. uint32_t argument;
  155. } jump;
  156. struct {
  157. uint32_t address;
  158. uint32_t reserved;
  159. /* Passed in register r0 before CALL */
  160. uint32_t argument;
  161. } call;
  162. struct {
  163. uint32_t reserved1;
  164. uint32_t reserved2;
  165. uint32_t mode;
  166. } mode;
  167. };
  168. };
  169. /*
  170. * Most of the mode names are same or at least similar
  171. * on i.MX23 and i.MX28, but some of the mode names
  172. * differ. The "name" field represents the mode name
  173. * on i.MX28 as seen in Table 12-2 of the datasheet.
  174. * The "altname" field represents the differently named
  175. * fields on i.MX23 as seen in Table 35-3 of the
  176. * datasheet.
  177. */
  178. static const struct {
  179. const char *name;
  180. const char *altname;
  181. const uint8_t mode;
  182. } modetable[] = {
  183. { "USB", NULL, 0x00 },
  184. { "I2C", NULL, 0x01 },
  185. { "SPI2_FLASH", "SPI1_FLASH", 0x02 },
  186. { "SPI3_FLASH", "SPI2_FLASH", 0x03 },
  187. { "NAND_BCH", NULL, 0x04 },
  188. { "JTAG", NULL, 0x06 },
  189. { "SPI3_EEPROM", "SPI2_EEPROM", 0x08 },
  190. { "SD_SSP0", NULL, 0x09 },
  191. { "SD_SSP1", NULL, 0x0A }
  192. };
  193. enum sb_tag {
  194. ROM_NOP_CMD = 0x00,
  195. ROM_TAG_CMD = 0x01,
  196. ROM_LOAD_CMD = 0x02,
  197. ROM_FILL_CMD = 0x03,
  198. ROM_JUMP_CMD = 0x04,
  199. ROM_CALL_CMD = 0x05,
  200. ROM_MODE_CMD = 0x06
  201. };
  202. struct sb_source_entry {
  203. uint8_t tag;
  204. uint32_t address;
  205. uint32_t flags;
  206. char *filename;
  207. };
  208. #endif /* __MXSSB_H__ */