bootrom.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Boot ROM Entry Points and such
  3. */
  4. /* These Blackfins all have a Boot ROM that is not reusable (at all):
  5. * BF531 / BF532 / BF533
  6. * BF538 / BF539
  7. * BF561
  8. * So there is nothing for us to export ;(
  9. *
  10. * These Blackfins started to roll with the idea that the Boot ROM can
  11. * provide useful functions, but still only a few (and not really useful):
  12. * BF534 / BF536 / BF537
  13. *
  14. * Looking forward, Boot ROM's on newer Blackfins have quite a few
  15. * nice entry points that are usable at runtime and beyond. We'll
  16. * only define known legacy parts (listed above) and otherwise just
  17. * assume it's a newer part.
  18. *
  19. * These entry points are accomplished by placing a small jump table at
  20. * the start of the Boot ROM. This way the addresses are fixed forever.
  21. */
  22. #ifndef __BFIN_PERIPHERAL_BOOTROM__
  23. #define __BFIN_PERIPHERAL_BOOTROM__
  24. /* All Blackfin's have the Boot ROM entry point at the same address */
  25. #define _BOOTROM_RESET 0xEF000000
  26. #if defined(__ADSPBF531__) || defined(__ADSPBF532__) || defined(__ADSPBF533__) || \
  27. defined(__ADSPBF538__) || defined(__ADSPBF539__) || \
  28. defined(__ADSPBF561__)
  29. /* Nothing to export */
  30. #elif defined(__ADSPBF534__) || defined(__ADSPBF536__) || defined(__ADSPBF537__)
  31. /* The BF537 family */
  32. #define _BOOTROM_FINAL_INIT 0xEF000002
  33. /* reserved 0xEF000004 */
  34. #define _BOOTROM_DO_MEMORY_DMA 0xEF000006
  35. #define _BOOTROM_BOOT_DXE_FLASH 0xEF000008
  36. #define _BOOTROM_BOOT_DXE_SPI 0xEF00000A
  37. #define _BOOTROM_BOOT_DXE_TWI 0xEF00000C
  38. /* reserved 0xEF00000E */
  39. #define _BOOTROM_GET_DXE_ADDRESS_FLASH 0xEF000010
  40. #define _BOOTROM_GET_DXE_ADDRESS_SPI 0xEF000012
  41. #define _BOOTROM_GET_DXE_ADDRESS_TWI 0xEF000014
  42. /* reserved 0xEF000016 */
  43. /* reserved 0xEF000018 */
  44. /* Glue to newer Boot ROMs */
  45. #define _BOOTROM_MDMA _BOOTROM_DO_MEMORY_DMA
  46. #define _BOOTROM_MEMBOOT _BOOTROM_BOOT_DXE_FLASH
  47. #define _BOOTROM_SPIBOOT _BOOTROM_BOOT_DXE_FLASH
  48. #define _BOOTROM_TWIBOOT _BOOTROM_BOOT_DXE_TWI
  49. #else
  50. /* All the newer Boot ROMs */
  51. #define _BOOTROM_FINAL_INIT 0xEF000002
  52. #define _BOOTROM_PDMA 0xEF000004
  53. #define _BOOTROM_MDMA 0xEF000006
  54. #define _BOOTROM_MEMBOOT 0xEF000008
  55. #define _BOOTROM_SPIBOOT 0xEF00000A
  56. #define _BOOTROM_TWIBOOT 0xEF00000C
  57. /* reserved 0xEF00000E */
  58. /* reserved 0xEF000010 */
  59. /* reserved 0xEF000012 */
  60. /* reserved 0xEF000014 */
  61. /* reserved 0xEF000016 */
  62. #define _BOOTROM_OTP_COMMAND 0xEF000018
  63. #define _BOOTROM_OTP_READ 0xEF00001A
  64. #define _BOOTROM_OTP_WRITE 0xEF00001C
  65. #define _BOOTROM_ECC_TABLE 0xEF00001E
  66. #define _BOOTROM_BOOTKERNEL 0xEF000020
  67. #define _BOOTROM_GETPORT 0xEF000022
  68. #define _BOOTROM_NMI 0xEF000024
  69. #define _BOOTROM_HWERROR 0xEF000026
  70. #define _BOOTROM_EXCEPTION 0xEF000028
  71. #define _BOOTROM_CRC32 0xEF000030
  72. #define _BOOTROM_CRC32POLY 0xEF000032
  73. #define _BOOTROM_CRC32CALLBACK 0xEF000034
  74. #define _BOOTROM_CRC32INITCODE 0xEF000036
  75. #define _BOOTROM_SYSCONTROL 0xEF000038
  76. #define _BOOTROM_REV 0xEF000040
  77. #define _BOOTROM_SESR 0xEF001000
  78. #define BOOTROM_FOLLOWS_C_ABI 1
  79. #define BOOTROM_CAPS_ADI_BOOT_STRUCTS 1
  80. #endif
  81. #ifndef BOOTROM_FOLLOWS_C_ABI
  82. #define BOOTROM_FOLLOWS_C_ABI 0
  83. #endif
  84. #ifndef BOOTROM_CAPS_ADI_BOOT_STRUCTS
  85. #define BOOTROM_CAPS_ADI_BOOT_STRUCTS 0
  86. #endif
  87. /* Possible syscontrol action flags */
  88. #define SYSCTRL_READ 0x00000000 /* read registers */
  89. #define SYSCTRL_WRITE 0x00000001 /* write registers */
  90. #define SYSCTRL_SYSRESET 0x00000002 /* perform system reset */
  91. #define SYSCTRL_CORERESET 0x00000004 /* perform core reset */
  92. #define SYSCTRL_SOFTRESET 0x00000006 /* perform core and system reset */
  93. #define SYSCTRL_VRCTL 0x00000010 /* read/write VR_CTL register */
  94. #define SYSCTRL_EXTVOLTAGE 0x00000020 /* VDDINT supplied externally */
  95. #define SYSCTRL_INTVOLTAGE 0x00000000 /* VDDINT generated by on-chip regulator */
  96. #define SYSCTRL_OTPVOLTAGE 0x00000040 /* For Factory Purposes Only */
  97. #define SYSCTRL_PLLCTL 0x00000100 /* read/write PLL_CTL register */
  98. #define SYSCTRL_PLLDIV 0x00000200 /* read/write PLL_DIV register */
  99. #define SYSCTRL_LOCKCNT 0x00000400 /* read/write PLL_LOCKCNT register */
  100. #define SYSCTRL_PLLSTAT 0x00000800 /* read/write PLL_STAT register */
  101. #ifndef __ASSEMBLY__
  102. #if BOOTROM_FOLLOWS_C_ABI
  103. # define BOOTROM_CALLED_FUNC_ATTR
  104. #else
  105. # define BOOTROM_CALLED_FUNC_ATTR __attribute__((saveall))
  106. #endif
  107. /* Structures for the syscontrol() function */
  108. typedef struct ADI_SYSCTRL_VALUES {
  109. uint16_t uwVrCtl;
  110. uint16_t uwPllCtl;
  111. uint16_t uwPllDiv;
  112. uint16_t uwPllLockCnt;
  113. uint16_t uwPllStat;
  114. } ADI_SYSCTRL_VALUES;
  115. #ifndef _BOOTROM_SYSCONTROL
  116. #define _BOOTROM_SYSCONTROL 0
  117. #endif
  118. static uint32_t (* const bfrom_SysControl)(uint32_t action_flags, ADI_SYSCTRL_VALUES *power_settings, void *reserved) = (void *)_BOOTROM_SYSCONTROL;
  119. /* We need a dedicated function since we need to screw with the stack pointer
  120. * when resetting. The on-chip ROM will save/restore registers on the stack
  121. * when doing a system reset, so the stack cannot be outside of the chip.
  122. */
  123. __attribute__((__noreturn__))
  124. static inline void bfrom_SoftReset(void *new_stack)
  125. {
  126. while (1)
  127. __asm__ __volatile__(
  128. "sp = %[stack];"
  129. "jump (%[bfrom_syscontrol]);"
  130. : : [bfrom_syscontrol] "p"(bfrom_SysControl),
  131. "q0"(SYSCTRL_SOFTRESET),
  132. "q1"(0),
  133. "q2"(NULL),
  134. [stack] "p"(new_stack)
  135. );
  136. }
  137. /* Structures for working with LDRs and boot rom callbacks */
  138. typedef struct ADI_BOOT_HEADER {
  139. int32_t dBlockCode;
  140. void *pTargetAddress;
  141. int32_t dByteCount;
  142. int32_t dArgument;
  143. } ADI_BOOT_HEADER;
  144. typedef struct ADI_BOOT_BUFFER {
  145. void *pSource;
  146. int32_t dByteCount;
  147. } ADI_BOOT_BUFFER;
  148. typedef struct ADI_BOOT_DATA {
  149. void *pSource;
  150. void *pDestination;
  151. int16_t *pControlRegister;
  152. int16_t *pDmaControlRegister;
  153. int32_t dControlValue;
  154. int32_t dByteCount;
  155. int32_t dFlags;
  156. int16_t uwDataWidth;
  157. int16_t uwSrcModifyMult;
  158. int16_t uwDstModifyMult;
  159. int16_t uwHwait;
  160. int16_t uwSsel;
  161. int16_t uwUserShort;
  162. int32_t dUserLong;
  163. int32_t dReserved2;
  164. void *pErrorFunction;
  165. void *pLoadFunction;
  166. void *pCallBackFunction;
  167. ADI_BOOT_HEADER *pHeader;
  168. void *pTempBuffer;
  169. void *pTempCurrent;
  170. int32_t dTempByteCount;
  171. int32_t dBlockCount;
  172. int32_t dClock;
  173. void *pLogBuffer;
  174. void *pLogCurrent;
  175. int32_t dLogByteCount;
  176. } ADI_BOOT_DATA;
  177. typedef void ADI_BOOT_HOOK_FUNC (ADI_BOOT_DATA *);
  178. #ifndef _BOOTROM_MEMBOOT
  179. #define _BOOTROM_MEMBOOT 0
  180. #endif
  181. static uint32_t (* const bfrom_MemBoot)(void *pBootStream, int32_t dFlags, int32_t dBlockCount, ADI_BOOT_HOOK_FUNC *pCallHook) = (void *)_BOOTROM_MEMBOOT;
  182. #ifndef _BOOTROM_TWIBOOT
  183. #define _BOOTROM_TWIBOOT 0
  184. #endif
  185. static uint32_t (* const bfrom_TwiBoot)(int32_t dTwiAddress, int32_t dFlags, int32_t dBlockCount, ADI_BOOT_HOOK_FUNC *pCallHook) = (void *)_BOOTROM_TWIBOOT;
  186. #ifndef _BOOTROM_SPIBOOT
  187. #define _BOOTROM_SPIBOOT 0
  188. #endif
  189. static uint32_t (* const bfrom_SpiBoot)(int32_t dSpiAddress, int32_t dFlags, int32_t dBlockCount, ADI_BOOT_HOOK_FUNC *pCallHook) = (void *)_BOOTROM_SPIBOOT;
  190. #ifndef _BOOTROM_OTPBOOT
  191. #define _BOOTROM_OTPBOOT 0
  192. #endif
  193. static uint32_t (* const bfrom_OtpBoot)(int32_t dOtpAddress, int32_t dFlags, int32_t dBlockCount, ADI_BOOT_HOOK_FUNC *pCallHook) = (void *)_BOOTROM_OTPBOOT;
  194. #ifndef _BOOTROM_NANDBOOT
  195. #define _BOOTROM_NANDBOOT 0
  196. #endif
  197. static uint32_t (* const bfrom_NandBoot)(int32_t dNandAddress, int32_t dFlags, int32_t dBlockCount, ADI_BOOT_HOOK_FUNC *pCallHook) = (void *)_BOOTROM_NANDBOOT;
  198. #endif /* __ASSEMBLY__ */
  199. /* Bit defines for ADI_BOOT_DATA->dFlags */
  200. #define BFLAG_DMACODE_MASK 0x0000000F
  201. #define BFLAG_SAFE 0x00000010
  202. #define BFLAG_AUX 0x00000020
  203. #define BFLAG_FILL 0x00000100
  204. #define BFLAG_QUICKBOOT 0x00000200
  205. #define BFLAG_CALLBACK 0x00000400
  206. #define BFLAG_INIT 0x00000800
  207. #define BFLAG_IGNORE 0x00001000
  208. #define BFLAG_INDIRECT 0x00002000
  209. #define BFLAG_FIRST 0x00004000
  210. #define BFLAG_FINAL 0x00008000
  211. #define BFLAG_HOOK 0x00400000
  212. #define BFLAG_HDRINDIRECT 0x00800000
  213. #define BFLAG_TYPE_MASK 0x00300000
  214. #define BFLAG_TYPE_1 0x00000000
  215. #define BFLAG_TYPE_2 0x00100000
  216. #define BFLAG_TYPE_3 0x00200000
  217. #define BFLAG_TYPE_4 0x00300000
  218. #define BFLAG_FASTREAD 0x00400000
  219. #define BFLAG_NOAUTO 0x01000000
  220. #define BFLAG_PERIPHERAL 0x02000000
  221. #define BFLAG_SLAVE 0x04000000
  222. #define BFLAG_WAKEUP 0x08000000
  223. #define BFLAG_NEXTDXE 0x10000000
  224. #define BFLAG_RETURN 0x20000000
  225. #define BFLAG_RESET 0x40000000
  226. #define BFLAG_NONRESTORE 0x80000000
  227. #endif