start.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * Copyright (C) 2003 Josef Baumgartner <josef.baumgartner@telex.de>
  3. * Based on code from Bernhard Kuhn <bkuhn@metrowerks.com>
  4. *
  5. * Copyright 2010-2012 Freescale Semiconductor, Inc.
  6. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  7. *
  8. * SPDX-License-Identifier: GPL-2.0+
  9. */
  10. #include <common.h>
  11. #include <asm-offsets.h>
  12. #include <config.h>
  13. #include <timestamp.h>
  14. #include "version.h"
  15. #include <asm/cache.h>
  16. #define _START _start
  17. #define _FAULT _fault
  18. #define SAVE_ALL \
  19. move.w #0x2700,%sr; /* disable intrs */ \
  20. subl #60,%sp; /* space for 15 regs */ \
  21. moveml %d0-%d7/%a0-%a6,%sp@;
  22. #define RESTORE_ALL \
  23. moveml %sp@,%d0-%d7/%a0-%a6; \
  24. addl #60,%sp; /* space for 15 regs */ \
  25. rte;
  26. #if defined(CONFIG_SERIAL_BOOT)
  27. #define ASM_DRAMINIT (asm_dram_init - CONFIG_SYS_TEXT_BASE + \
  28. CONFIG_SYS_INIT_RAM_ADDR)
  29. #define ASM_DRAMINIT_N (asm_dram_init - CONFIG_SYS_TEXT_BASE)
  30. #define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - CONFIG_SYS_TEXT_BASE + \
  31. CONFIG_SYS_INIT_RAM_ADDR)
  32. #endif
  33. .text
  34. /*
  35. * Vector table. This is used for initial platform startup.
  36. * These vectors are to catch any un-intended traps.
  37. */
  38. _vectors:
  39. #if defined(CONFIG_SERIAL_BOOT)
  40. INITSP: .long 0 /* Initial SP */
  41. #ifdef CONFIG_CF_SBF
  42. INITPC: .long ASM_DRAMINIT /* Initial PC */
  43. #endif
  44. #ifdef CONFIG_SYS_NAND_BOOT
  45. INITPC: .long ASM_DRAMINIT_N /* Initial PC */
  46. #endif
  47. #else
  48. INITSP: .long 0 /* Initial SP */
  49. INITPC: .long _START /* Initial PC */
  50. #endif
  51. vector02_0F:
  52. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  53. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  54. /* Reserved */
  55. vector10_17:
  56. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  57. vector18_1F:
  58. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  59. #if !defined(CONFIG_SERIAL_BOOT)
  60. /* TRAP #0 - #15 */
  61. vector20_2F:
  62. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  63. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  64. /* Reserved */
  65. vector30_3F:
  66. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  67. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  68. vector64_127:
  69. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  70. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  71. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  72. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  73. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  74. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  75. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  76. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  77. vector128_191:
  78. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  79. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  80. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  81. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  82. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  83. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  84. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  85. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  86. vector192_255:
  87. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  88. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  89. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  90. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  91. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  92. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  93. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  94. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  95. #endif
  96. #if defined(CONFIG_SERIAL_BOOT)
  97. /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */
  98. asm_sbf_img_hdr:
  99. .long 0x00000000 /* checksum, not yet implemented */
  100. .long 0x00040000 /* image length */
  101. .long CONFIG_SYS_TEXT_BASE /* image to be relocated at */
  102. asm_dram_init:
  103. move.w #0x2700,%sr /* Mask off Interrupt */
  104. #ifdef CONFIG_SYS_NAND_BOOT
  105. /* for assembly stack */
  106. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  107. movec %d0, %RAMBAR1
  108. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  109. clr.l %sp@-
  110. #endif
  111. #ifdef CONFIG_CF_SBF
  112. move.l #CONFIG_SYS_INIT_RAM_ADDR, %d0
  113. movec %d0, %VBR
  114. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  115. movec %d0, %RAMBAR1
  116. /* initialize general use internal ram */
  117. move.l #0, %d0
  118. move.l #(ICACHE_STATUS), %a1 /* icache */
  119. move.l #(DCACHE_STATUS), %a2 /* dcache */
  120. move.l %d0, (%a1)
  121. move.l %d0, (%a2)
  122. /* invalidate and disable cache */
  123. move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
  124. movec %d0, %CACR /* Invalidate cache */
  125. move.l #0, %d0
  126. movec %d0, %ACR0
  127. movec %d0, %ACR1
  128. movec %d0, %ACR2
  129. movec %d0, %ACR3
  130. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  131. clr.l %sp@-
  132. /* Must disable global address */
  133. move.l #0xFC008000, %a1
  134. move.l #(CONFIG_SYS_CS0_BASE), (%a1)
  135. move.l #0xFC008008, %a1
  136. move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
  137. move.l #0xFC008004, %a1
  138. move.l #(CONFIG_SYS_CS0_MASK), (%a1)
  139. #endif /* CONFIG_CF_SBF */
  140. #ifdef CONFIG_MCF5441x
  141. /* TC: enable all peripherals,
  142. in the future only enable certain peripherals */
  143. move.l #0xFC04002D, %a1
  144. #if defined(CONFIG_CF_SBF)
  145. move.b #23, (%a1) /* dspi */
  146. #endif
  147. move.b #46, (%a1) /* DDR */
  148. /* slew settings */
  149. move.l #0xEC094060, %a1
  150. move.b #0, (%a1)
  151. /* use vco instead of cpu*2 clock for ddr clock */
  152. move.l #0xEC09001A, %a1
  153. move.w #0xE01D, (%a1)
  154. /* DDR settings */
  155. move.l #0xFC0B8180, %a1
  156. move.l #0x00000000, (%a1)
  157. move.l #0x40000000, (%a1)
  158. move.l #0xFC0B81AC, %a1
  159. move.l #0x01030203, (%a1)
  160. move.l #0xFC0B8000, %a1
  161. move.l #0x01010101, (%a1)+ /* 0x00 */
  162. move.l #0x00000101, (%a1)+ /* 0x04 */
  163. move.l #0x01010100, (%a1)+ /* 0x08 */
  164. move.l #0x01010000, (%a1)+ /* 0x0C */
  165. move.l #0x00010101, (%a1)+ /* 0x10 */
  166. move.l #0xFC0B8018, %a1
  167. move.l #0x00010100, (%a1)+ /* 0x18 */
  168. move.l #0x00000001, (%a1)+ /* 0x1C */
  169. move.l #0x01000001, (%a1)+ /* 0x20 */
  170. move.l #0x00000100, (%a1)+ /* 0x24 */
  171. move.l #0x00010001, (%a1)+ /* 0x28 */
  172. move.l #0x00000200, (%a1)+ /* 0x2C */
  173. move.l #0x01000002, (%a1)+ /* 0x30 */
  174. move.l #0x00000000, (%a1)+ /* 0x34 */
  175. move.l #0x00000100, (%a1)+ /* 0x38 */
  176. move.l #0x02000100, (%a1)+ /* 0x3C */
  177. move.l #0x02000407, (%a1)+ /* 0x40 */
  178. move.l #0x02030007, (%a1)+ /* 0x44 */
  179. move.l #0x02000100, (%a1)+ /* 0x48 */
  180. move.l #0x0A030203, (%a1)+ /* 0x4C */
  181. move.l #0x00020708, (%a1)+ /* 0x50 */
  182. move.l #0x00050008, (%a1)+ /* 0x54 */
  183. move.l #0x04030002, (%a1)+ /* 0x58 */
  184. move.l #0x00000004, (%a1)+ /* 0x5C */
  185. move.l #0x020A0000, (%a1)+ /* 0x60 */
  186. move.l #0x0C00000E, (%a1)+ /* 0x64 */
  187. move.l #0x00002004, (%a1)+ /* 0x68 */
  188. move.l #0x00000000, (%a1)+ /* 0x6C */
  189. move.l #0x00100010, (%a1)+ /* 0x70 */
  190. move.l #0x00100010, (%a1)+ /* 0x74 */
  191. move.l #0x00000000, (%a1)+ /* 0x78 */
  192. move.l #0x07990000, (%a1)+ /* 0x7C */
  193. move.l #0xFC0B80A0, %a1
  194. move.l #0x00000000, (%a1)+ /* 0xA0 */
  195. move.l #0x00C80064, (%a1)+ /* 0xA4 */
  196. move.l #0x44520002, (%a1)+ /* 0xA8 */
  197. move.l #0x00C80023, (%a1)+ /* 0xAC */
  198. move.l #0xFC0B80B4, %a1
  199. move.l #0x0000C350, (%a1) /* 0xB4 */
  200. move.l #0xFC0B80E0, %a1
  201. move.l #0x04000000, (%a1)+ /* 0xE0 */
  202. move.l #0x03000304, (%a1)+ /* 0xE4 */
  203. move.l #0x40040000, (%a1)+ /* 0xE8 */
  204. move.l #0xC0004004, (%a1)+ /* 0xEC */
  205. move.l #0x0642C000, (%a1)+ /* 0xF0 */
  206. move.l #0x00000642, (%a1)+ /* 0xF4 */
  207. move.l #0xFC0B8024, %a1
  208. tpf
  209. move.l #0x01000100, (%a1) /* 0x24 */
  210. move.l #0x2000, %d1
  211. jsr asm_delay
  212. #endif /* CONFIG_MCF5441x */
  213. #ifdef CONFIG_MCF5445x
  214. /* Dram Initialization a1, a2, and d0 */
  215. /* mscr sdram */
  216. move.l #0xFC0A4074, %a1
  217. move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1)
  218. nop
  219. /* SDRAM Chip 0 and 1 */
  220. move.l #0xFC0B8110, %a1
  221. move.l #0xFC0B8114, %a2
  222. /* calculate the size */
  223. move.l #0x13, %d1
  224. move.l #(CONFIG_SYS_SDRAM_SIZE), %d2
  225. #ifdef CONFIG_SYS_SDRAM_BASE1
  226. lsr.l #1, %d2
  227. #endif
  228. dramsz_loop:
  229. lsr.l #1, %d2
  230. add.l #1, %d1
  231. cmp.l #1, %d2
  232. bne dramsz_loop
  233. #ifdef CONFIG_SYS_NAND_BOOT
  234. beq asm_nand_chk_status
  235. #endif
  236. /* SDRAM Chip 0 and 1 */
  237. move.l #(CONFIG_SYS_SDRAM_BASE), (%a1)
  238. or.l %d1, (%a1)
  239. #ifdef CONFIG_SYS_SDRAM_BASE1
  240. move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2)
  241. or.l %d1, (%a2)
  242. #endif
  243. nop
  244. /* dram cfg1 and cfg2 */
  245. move.l #0xFC0B8008, %a1
  246. move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1)
  247. nop
  248. move.l #0xFC0B800C, %a2
  249. move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2)
  250. nop
  251. move.l #0xFC0B8000, %a1 /* Mode */
  252. move.l #0xFC0B8004, %a2 /* Ctrl */
  253. /* Issue PALL */
  254. move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
  255. nop
  256. #ifdef CONFIG_M54455EVB
  257. /* Issue LEMR */
  258. move.l #(CONFIG_SYS_SDRAM_EMOD + 0x408), (%a1)
  259. nop
  260. move.l #(CONFIG_SYS_SDRAM_MODE + 0x300), (%a1)
  261. nop
  262. #endif
  263. move.l #1000, %d1
  264. jsr asm_delay
  265. /* Issue PALL */
  266. move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
  267. nop
  268. /* Perform two refresh cycles */
  269. move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0
  270. nop
  271. move.l %d0, (%a2)
  272. move.l %d0, (%a2)
  273. nop
  274. #ifdef CONFIG_M54455EVB
  275. move.l #(CONFIG_SYS_SDRAM_MODE + 0x200), (%a1)
  276. nop
  277. #elif defined(CONFIG_M54451EVB)
  278. /* Issue LEMR */
  279. move.l #(CONFIG_SYS_SDRAM_MODE), (%a1)
  280. nop
  281. move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1)
  282. #endif
  283. move.l #500, %d1
  284. jsr asm_delay
  285. move.l #(CONFIG_SYS_SDRAM_CTRL), %d1
  286. and.l #0x7FFFFFFF, %d1
  287. #ifdef CONFIG_M54455EVB
  288. or.l #0x10000C00, %d1
  289. #elif defined(CONFIG_M54451EVB)
  290. or.l #0x10000C00, %d1
  291. #endif
  292. move.l %d1, (%a2)
  293. nop
  294. move.l #2000, %d1
  295. jsr asm_delay
  296. #endif /* CONFIG_MCF5445x */
  297. #ifdef CONFIG_CF_SBF
  298. /*
  299. * DSPI Initialization
  300. * a0 - general, sram - 0x80008000 - 32, see M54455EVB.h
  301. * a1 - dspi status
  302. * a2 - dtfr
  303. * a3 - drfr
  304. * a4 - Dst addr
  305. */
  306. /* Enable pins for DSPI mode - chip-selects are enabled later */
  307. asm_dspi_init:
  308. #ifdef CONFIG_MCF5441x
  309. move.l #0xEC09404E, %a1
  310. move.l #0xEC09404F, %a2
  311. move.b #0xFF, (%a1)
  312. move.b #0x80, (%a2)
  313. #endif
  314. #ifdef CONFIG_MCF5445x
  315. move.l #0xFC0A4063, %a0
  316. move.b #0x7F, (%a0)
  317. #endif
  318. /* Configure DSPI module */
  319. move.l #0xFC05C000, %a0
  320. move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
  321. move.l #0xFC05C00C, %a0
  322. #ifdef CONFIG_MCF5441x
  323. move.l #0x3E000016, (%a0)
  324. #endif
  325. #ifdef CONFIG_MCF5445x
  326. move.l #0x3E000011, (%a0)
  327. #endif
  328. move.l #0xFC05C034, %a2 /* dtfr */
  329. move.l #0xFC05C03B, %a3 /* drfr */
  330. move.l #(ASM_SBF_IMG_HDR + 4), %a1
  331. move.l (%a1)+, %d5
  332. move.l (%a1), %a4
  333. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0
  334. move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4
  335. move.l #0xFC05C02C, %a1 /* dspi status */
  336. /* Issue commands and address */
  337. move.l #0x8002000B, %d2 /* Fast Read Cmd */
  338. jsr asm_dspi_wr_status
  339. jsr asm_dspi_rd_status
  340. move.l #0x80020000, %d2 /* Address byte 2 */
  341. jsr asm_dspi_wr_status
  342. jsr asm_dspi_rd_status
  343. move.l #0x80020000, %d2 /* Address byte 1 */
  344. jsr asm_dspi_wr_status
  345. jsr asm_dspi_rd_status
  346. move.l #0x80020000, %d2 /* Address byte 0 */
  347. jsr asm_dspi_wr_status
  348. jsr asm_dspi_rd_status
  349. move.l #0x80020000, %d2 /* Dummy Wr and Rd */
  350. jsr asm_dspi_wr_status
  351. jsr asm_dspi_rd_status
  352. /* Transfer serial boot header to sram */
  353. asm_dspi_rd_loop1:
  354. move.l #0x80020000, %d2
  355. jsr asm_dspi_wr_status
  356. jsr asm_dspi_rd_status
  357. move.b %d1, (%a0) /* read, copy to dst */
  358. add.l #1, %a0 /* inc dst by 1 */
  359. sub.l #1, %d4 /* dec cnt by 1 */
  360. bne asm_dspi_rd_loop1
  361. /* Transfer u-boot from serial flash to memory */
  362. asm_dspi_rd_loop2:
  363. move.l #0x80020000, %d2
  364. jsr asm_dspi_wr_status
  365. jsr asm_dspi_rd_status
  366. move.b %d1, (%a4) /* read, copy to dst */
  367. add.l #1, %a4 /* inc dst by 1 */
  368. sub.l #1, %d5 /* dec cnt by 1 */
  369. bne asm_dspi_rd_loop2
  370. move.l #0x00020000, %d2 /* Terminate */
  371. jsr asm_dspi_wr_status
  372. jsr asm_dspi_rd_status
  373. /* jump to memory and execute */
  374. move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
  375. jmp (%a0)
  376. asm_dspi_wr_status:
  377. move.l (%a1), %d0 /* status */
  378. and.l #0x0000F000, %d0
  379. cmp.l #0x00003000, %d0
  380. bgt asm_dspi_wr_status
  381. move.l %d2, (%a2)
  382. rts
  383. asm_dspi_rd_status:
  384. move.l (%a1), %d0 /* status */
  385. and.l #0x000000F0, %d0
  386. lsr.l #4, %d0
  387. cmp.l #0, %d0
  388. beq asm_dspi_rd_status
  389. move.b (%a3), %d1
  390. rts
  391. #endif /* CONFIG_CF_SBF */
  392. #ifdef CONFIG_SYS_NAND_BOOT
  393. /* copy 4 boot pages to dram as soon as possible */
  394. /* each page is 996 bytes (1056 total with 60 ECC bytes */
  395. move.l #0x00000000, %a1 /* src */
  396. move.l #CONFIG_SYS_TEXT_BASE, %a2 /* dst */
  397. move.l #0x3E0, %d0 /* sz in long */
  398. asm_boot_nand_copy:
  399. move.l (%a1)+, (%a2)+
  400. subq.l #1, %d0
  401. bne asm_boot_nand_copy
  402. /* jump to memory and execute */
  403. move.l #(asm_nand_init), %a0
  404. jmp (%a0)
  405. asm_nand_init:
  406. /* exit nand boot-mode */
  407. move.l #0xFC0FFF30, %a1
  408. or.l #0x00000040, %d1
  409. move.l %d1, (%a1)
  410. /* initialize general use internal ram */
  411. move.l #0, %d0
  412. move.l #(CACR_STATUS), %a1 /* CACR */
  413. move.l #(ICACHE_STATUS), %a2 /* icache */
  414. move.l #(DCACHE_STATUS), %a3 /* dcache */
  415. move.l %d0, (%a1)
  416. move.l %d0, (%a2)
  417. move.l %d0, (%a3)
  418. /* invalidate and disable cache */
  419. move.l #0x01004100, %d0 /* Invalidate cache cmd */
  420. movec %d0, %CACR /* Invalidate cache */
  421. move.l #0, %d0
  422. movec %d0, %ACR0
  423. movec %d0, %ACR1
  424. movec %d0, %ACR2
  425. movec %d0, %ACR3
  426. /* Must disable global address */
  427. move.l #0xFC008000, %a1
  428. move.l #(CONFIG_SYS_CS0_BASE), (%a1)
  429. move.l #0xFC008008, %a1
  430. move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
  431. move.l #0xFC008004, %a1
  432. move.l #(CONFIG_SYS_CS0_MASK), (%a1)
  433. /* NAND port configuration */
  434. move.l #0xEC094048, %a1
  435. move.b #0xFD, (%a1)+
  436. move.b #0x5F, (%a1)+
  437. move.b #0x04, (%a1)+
  438. /* reset nand */
  439. move.l #0xFC0FFF38, %a1 /* isr */
  440. move.l #0x000e0000, (%a1)
  441. move.l #0xFC0FFF08, %a2
  442. move.l #0x00000000, (%a2)+ /* car */
  443. move.l #0x11000000, (%a2)+ /* rar */
  444. move.l #0x00000000, (%a2)+ /* rpt */
  445. move.l #0x00000000, (%a2)+ /* rai */
  446. move.l #0xFC0FFF2c, %a2 /* cfg */
  447. move.l #0x00000000, (%a2)+ /* secsz */
  448. move.l #0x000e0681, (%a2)+
  449. move.l #0xFC0FFF04, %a2 /* cmd2 */
  450. move.l #0xFF404001, (%a2)
  451. move.l #0x000e0000, (%a1)
  452. move.l #0x2000, %d1
  453. jsr asm_delay
  454. /* setup nand */
  455. move.l #0xFC0FFF00, %a1
  456. move.l #0x30700000, (%a1)+ /* cmd1 */
  457. move.l #0x007EF000, (%a1)+ /* cmd2 */
  458. move.l #0xFC0FFF2C, %a1
  459. move.l #0x00000841, (%a1)+ /* secsz */
  460. move.l #0x000e0681, (%a1)+ /* cfg */
  461. move.l #100, %d4 /* 100 pages ~200KB */
  462. move.l #4, %d2 /* start at 4 */
  463. move.l #0xFC0FFF04, %a0 /* cmd2 */
  464. move.l #0xFC0FFF0C, %a1 /* rar */
  465. move.l #(CONFIG_SYS_TEXT_BASE + 0xF80), %a2
  466. asm_nand_read:
  467. move.l #0x11000000, %d0 /* rar */
  468. or.l %d2, %d0
  469. move.l %d0, (%a1)
  470. add.l #1, %d2
  471. move.l (%a0), %d0 /* cmd2 */
  472. or.l #1, %d0
  473. move.l %d0, (%a0)
  474. move.l #0x200, %d1
  475. jsr asm_delay
  476. asm_nand_chk_status:
  477. move.l #0xFC0FFF38, %a4 /* isr */
  478. move.l (%a4), %d0
  479. and.l #0x40000000, %d0
  480. tst.l %d0
  481. beq asm_nand_chk_status
  482. move.l #0xFC0FFF38, %a4 /* isr */
  483. move.l (%a4), %d0
  484. or.l #0x000E0000, %d0
  485. move.l %d0, (%a4)
  486. move.l #0x200, %d3
  487. move.l #0xFC0FC000, %a3 /* buf 1 */
  488. asm_nand_copy:
  489. move.l (%a3)+, (%a2)+
  490. subq.l #1, %d3
  491. bgt asm_nand_copy
  492. subq.l #1, %d4
  493. bgt asm_nand_read
  494. /* jump to memory and execute */
  495. move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
  496. jmp (%a0)
  497. #endif /* CONFIG_SYS_NAND_BOOT */
  498. asm_delay:
  499. nop
  500. subq.l #1, %d1
  501. bne asm_delay
  502. rts
  503. #endif /* CONFIG_CF_SBF || CONFIG_NAND_U_BOOT */
  504. .text
  505. . = 0x400
  506. .globl _start
  507. _start:
  508. #if !defined(CONFIG_SERIAL_BOOT)
  509. nop
  510. nop
  511. move.w #0x2700,%sr /* Mask off Interrupt */
  512. /* Set vector base register at the beginning of the Flash */
  513. move.l #CONFIG_SYS_FLASH_BASE, %d0
  514. movec %d0, %VBR
  515. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  516. movec %d0, %RAMBAR1
  517. /* initialize general use internal ram */
  518. move.l #0, %d0
  519. move.l #(ICACHE_STATUS), %a1 /* icache */
  520. move.l #(DCACHE_STATUS), %a2 /* dcache */
  521. move.l %d0, (%a1)
  522. move.l %d0, (%a2)
  523. /* invalidate and disable cache */
  524. move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
  525. movec %d0, %CACR /* Invalidate cache */
  526. move.l #0, %d0
  527. movec %d0, %ACR0
  528. movec %d0, %ACR1
  529. movec %d0, %ACR2
  530. movec %d0, %ACR3
  531. #else
  532. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  533. movec %d0, %RAMBAR1
  534. #endif
  535. /* put relocation table address to a5 */
  536. move.l #__got_start, %a5
  537. /* setup stack initially on top of internal static ram */
  538. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_SIZE), %sp
  539. /*
  540. * if configured, malloc_f arena will be reserved first,
  541. * then (and always) gd struct space will be reserved
  542. */
  543. move.l %sp, -(%sp)
  544. move.l #board_init_f_alloc_reserve, %a1
  545. jsr (%a1)
  546. /* update stack and frame-pointers */
  547. move.l %d0, %sp
  548. move.l %sp, %fp
  549. /* initialize reserved area */
  550. move.l %d0, -(%sp)
  551. move.l #board_init_f_init_reserve, %a1
  552. jsr (%a1)
  553. /* run low-level CPU init code (from flash) */
  554. move.l #cpu_init_f, %a1
  555. jsr (%a1)
  556. /* run low-level board init code (from flash) */
  557. clr.l %sp@-
  558. move.l #board_init_f, %a1
  559. jsr (%a1)
  560. /* board_init_f() does not return */
  561. /******************************************************************************/
  562. /*
  563. * void relocate_code (addr_sp, gd, addr_moni)
  564. *
  565. * This "function" does not return, instead it continues in RAM
  566. * after relocating the monitor code.
  567. *
  568. * r3 = dest
  569. * r4 = src
  570. * r5 = length in bytes
  571. * r6 = cachelinesize
  572. */
  573. .globl relocate_code
  574. relocate_code:
  575. link.w %a6,#0
  576. move.l 8(%a6), %sp /* set new stack pointer */
  577. move.l 12(%a6), %d0 /* Save copy of Global Data pointer */
  578. move.l 16(%a6), %a0 /* Save copy of Destination Address */
  579. move.l #CONFIG_SYS_MONITOR_BASE, %a1
  580. move.l #__init_end, %a2
  581. move.l %a0, %a3
  582. /* copy the code to RAM */
  583. 1:
  584. move.l (%a1)+, (%a3)+
  585. cmp.l %a1,%a2
  586. bgt.s 1b
  587. /*
  588. * We are done. Do not return, instead branch to second part of board
  589. * initialization, now running from RAM.
  590. */
  591. move.l %a0, %a1
  592. add.l #(in_ram - CONFIG_SYS_MONITOR_BASE), %a1
  593. jmp (%a1)
  594. in_ram:
  595. clear_bss:
  596. /*
  597. * Now clear BSS segment
  598. */
  599. move.l %a0, %a1
  600. add.l #(_sbss - CONFIG_SYS_MONITOR_BASE),%a1
  601. move.l %a0, %d1
  602. add.l #(_ebss - CONFIG_SYS_MONITOR_BASE),%d1
  603. 6:
  604. clr.l (%a1)+
  605. cmp.l %a1,%d1
  606. bgt.s 6b
  607. /*
  608. * fix got table in RAM
  609. */
  610. move.l %a0, %a1
  611. add.l #(__got_start - CONFIG_SYS_MONITOR_BASE),%a1
  612. move.l %a1,%a5 /* fix got pointer register a5 */
  613. move.l %a0, %a2
  614. add.l #(__got_end - CONFIG_SYS_MONITOR_BASE),%a2
  615. 7:
  616. move.l (%a1),%d1
  617. sub.l #_start,%d1
  618. add.l %a0,%d1
  619. move.l %d1,(%a1)+
  620. cmp.l %a2, %a1
  621. bne 7b
  622. /* calculate relative jump to board_init_r in ram */
  623. move.l %a0, %a1
  624. add.l #(board_init_r - CONFIG_SYS_MONITOR_BASE), %a1
  625. /* set parameters for board_init_r */
  626. move.l %a0,-(%sp) /* dest_addr */
  627. move.l %d0,-(%sp) /* gd */
  628. jsr (%a1)
  629. /******************************************************************************/
  630. /* exception code */
  631. .globl _fault
  632. _fault:
  633. bra _fault
  634. .globl _exc_handler
  635. _exc_handler:
  636. SAVE_ALL
  637. movel %sp,%sp@-
  638. bsr exc_handler
  639. addql #4,%sp
  640. RESTORE_ALL
  641. .globl _int_handler
  642. _int_handler:
  643. SAVE_ALL
  644. movel %sp,%sp@-
  645. bsr int_handler
  646. addql #4,%sp
  647. RESTORE_ALL
  648. /******************************************************************************/
  649. .globl version_string
  650. version_string:
  651. .ascii U_BOOT_VERSION_STRING, "\0"
  652. .align 4