Fork of the vendor (Boundary Devices) u-boot for Reform 2, with minor tweaks. The goal is to migrate to mainstream u-boot or barebox ASAP. The main impediment so far is the 4GB RAM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

232 lines
5.2 KiB

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