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.
 
 
 
 
 
 

204 lines
5.3 KiB

  1. /*
  2. * (C) Copyright 2008
  3. * Marvell Semiconductor <www.marvell.com>
  4. * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #ifndef _KWBIMAGE_H_
  9. #define _KWBIMAGE_H_
  10. #include <compiler.h>
  11. #include <stdint.h>
  12. #define KWBIMAGE_MAX_CONFIG ((0x1dc - 0x20)/sizeof(struct reg_config))
  13. #define MAX_TEMPBUF_LEN 32
  14. /* NAND ECC Mode */
  15. #define IBR_HDR_ECC_DEFAULT 0x00
  16. #define IBR_HDR_ECC_FORCED_HAMMING 0x01
  17. #define IBR_HDR_ECC_FORCED_RS 0x02
  18. #define IBR_HDR_ECC_DISABLED 0x03
  19. /* Boot Type - block ID */
  20. #define IBR_HDR_I2C_ID 0x4D
  21. #define IBR_HDR_SPI_ID 0x5A
  22. #define IBR_HDR_NAND_ID 0x8B
  23. #define IBR_HDR_SATA_ID 0x78
  24. #define IBR_HDR_PEX_ID 0x9C
  25. #define IBR_HDR_UART_ID 0x69
  26. #define IBR_DEF_ATTRIB 0x00
  27. #define ALIGN_SUP(x, a) (((x) + (a - 1)) & ~(a - 1))
  28. /* Structure of the main header, version 0 (Kirkwood, Dove) */
  29. struct main_hdr_v0 {
  30. uint8_t blockid; /*0 */
  31. uint8_t nandeccmode; /*1 */
  32. uint16_t nandpagesize; /*2-3 */
  33. uint32_t blocksize; /*4-7 */
  34. uint32_t rsvd1; /*8-11 */
  35. uint32_t srcaddr; /*12-15 */
  36. uint32_t destaddr; /*16-19 */
  37. uint32_t execaddr; /*20-23 */
  38. uint8_t satapiomode; /*24 */
  39. uint8_t rsvd3; /*25 */
  40. uint16_t ddrinitdelay; /*26-27 */
  41. uint16_t rsvd2; /*28-29 */
  42. uint8_t ext; /*30 */
  43. uint8_t checksum; /*31 */
  44. };
  45. struct ext_hdr_v0_reg {
  46. uint32_t raddr;
  47. uint32_t rdata;
  48. };
  49. #define EXT_HDR_V0_REG_COUNT ((0x1dc - 0x20) / sizeof(struct ext_hdr_v0_reg))
  50. struct ext_hdr_v0 {
  51. uint32_t offset;
  52. uint8_t reserved[0x20 - sizeof(uint32_t)];
  53. struct ext_hdr_v0_reg rcfg[EXT_HDR_V0_REG_COUNT];
  54. uint8_t reserved2[7];
  55. uint8_t checksum;
  56. };
  57. struct kwb_header {
  58. struct main_hdr_v0 kwb_hdr;
  59. struct ext_hdr_v0 kwb_exthdr;
  60. };
  61. /* Structure of the main header, version 1 (Armada 370, Armada XP) */
  62. struct main_hdr_v1 {
  63. uint8_t blockid; /* 0 */
  64. uint8_t flags; /* 1 */
  65. uint16_t reserved2; /* 2-3 */
  66. uint32_t blocksize; /* 4-7 */
  67. uint8_t version; /* 8 */
  68. uint8_t headersz_msb; /* 9 */
  69. uint16_t headersz_lsb; /* A-B */
  70. uint32_t srcaddr; /* C-F */
  71. uint32_t destaddr; /* 10-13 */
  72. uint32_t execaddr; /* 14-17 */
  73. uint8_t options; /* 18 */
  74. uint8_t nandblocksize; /* 19 */
  75. uint8_t nandbadblklocation; /* 1A */
  76. uint8_t reserved4; /* 1B */
  77. uint16_t reserved5; /* 1C-1D */
  78. uint8_t ext; /* 1E */
  79. uint8_t checksum; /* 1F */
  80. };
  81. /*
  82. * Main header options
  83. */
  84. #define MAIN_HDR_V1_OPT_BAUD_DEFAULT 0
  85. #define MAIN_HDR_V1_OPT_BAUD_2400 0x1
  86. #define MAIN_HDR_V1_OPT_BAUD_4800 0x2
  87. #define MAIN_HDR_V1_OPT_BAUD_9600 0x3
  88. #define MAIN_HDR_V1_OPT_BAUD_19200 0x4
  89. #define MAIN_HDR_V1_OPT_BAUD_38400 0x5
  90. #define MAIN_HDR_V1_OPT_BAUD_57600 0x6
  91. #define MAIN_HDR_V1_OPT_BAUD_115200 0x7
  92. /*
  93. * Header for the optional headers, version 1 (Armada 370, Armada XP)
  94. */
  95. struct opt_hdr_v1 {
  96. uint8_t headertype;
  97. uint8_t headersz_msb;
  98. uint16_t headersz_lsb;
  99. char data[0];
  100. };
  101. /*
  102. * Public Key data in DER format
  103. */
  104. struct pubkey_der_v1 {
  105. uint8_t key[524];
  106. };
  107. /*
  108. * Signature (RSA 2048)
  109. */
  110. struct sig_v1 {
  111. uint8_t sig[256];
  112. };
  113. /*
  114. * Structure of secure header (Armada 38x)
  115. */
  116. struct secure_hdr_v1 {
  117. uint8_t headertype; /* 0x0 */
  118. uint8_t headersz_msb; /* 0x1 */
  119. uint16_t headersz_lsb; /* 0x2 - 0x3 */
  120. uint32_t reserved1; /* 0x4 - 0x7 */
  121. struct pubkey_der_v1 kak; /* 0x8 - 0x213 */
  122. uint8_t jtag_delay; /* 0x214 */
  123. uint8_t reserved2; /* 0x215 */
  124. uint16_t reserved3; /* 0x216 - 0x217 */
  125. uint32_t boxid; /* 0x218 - 0x21B */
  126. uint32_t flashid; /* 0x21C - 0x21F */
  127. struct sig_v1 hdrsig; /* 0x220 - 0x31F */
  128. struct sig_v1 imgsig; /* 0x320 - 0x41F */
  129. struct pubkey_der_v1 csk[16]; /* 0x420 - 0x24DF */
  130. struct sig_v1 csksig; /* 0x24E0 - 0x25DF */
  131. uint8_t next; /* 0x25E0 */
  132. uint8_t reserved4; /* 0x25E1 */
  133. uint16_t reserved5; /* 0x25E2 - 0x25E3 */
  134. };
  135. /*
  136. * Various values for the opt_hdr_v1->headertype field, describing the
  137. * different types of optional headers. The "secure" header contains
  138. * informations related to secure boot (encryption keys, etc.). The
  139. * "binary" header contains ARM binary code to be executed prior to
  140. * executing the main payload (usually the bootloader). This is
  141. * typically used to execute DDR3 training code. The "register" header
  142. * allows to describe a set of (address, value) tuples that are
  143. * generally used to configure the DRAM controller.
  144. */
  145. #define OPT_HDR_V1_SECURE_TYPE 0x1
  146. #define OPT_HDR_V1_BINARY_TYPE 0x2
  147. #define OPT_HDR_V1_REGISTER_TYPE 0x3
  148. #define KWBHEADER_V1_SIZE(hdr) \
  149. (((hdr)->headersz_msb << 16) | le16_to_cpu((hdr)->headersz_lsb))
  150. enum kwbimage_cmd {
  151. CMD_INVALID,
  152. CMD_BOOT_FROM,
  153. CMD_NAND_ECC_MODE,
  154. CMD_NAND_PAGE_SIZE,
  155. CMD_SATA_PIO_MODE,
  156. CMD_DDR_INIT_DELAY,
  157. CMD_DATA
  158. };
  159. enum kwbimage_cmd_types {
  160. CFG_INVALID = -1,
  161. CFG_COMMAND,
  162. CFG_DATA0,
  163. CFG_DATA1
  164. };
  165. /*
  166. * functions
  167. */
  168. void init_kwb_image_type (void);
  169. /*
  170. * Byte 8 of the image header contains the version number. In the v0
  171. * header, byte 8 was reserved, and always set to 0. In the v1 header,
  172. * byte 8 has been changed to a proper field, set to 1.
  173. */
  174. static inline unsigned int image_version(void *header)
  175. {
  176. unsigned char *ptr = header;
  177. return ptr[8];
  178. }
  179. #endif /* _KWBIMAGE_H_ */