kwbimage.h 5.5 KB

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