start.S 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  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. #ifndef CONFIG_IDENT_STRING
  17. #define CONFIG_IDENT_STRING ""
  18. #endif
  19. #define _START _start
  20. #define _FAULT _fault
  21. #define SAVE_ALL \
  22. move.w #0x2700,%sr; /* disable intrs */ \
  23. subl #60,%sp; /* space for 15 regs */ \
  24. moveml %d0-%d7/%a0-%a6,%sp@;
  25. #define RESTORE_ALL \
  26. moveml %sp@,%d0-%d7/%a0-%a6; \
  27. addl #60,%sp; /* space for 15 regs */ \
  28. rte;
  29. #if defined(CONFIG_SERIAL_BOOT)
  30. #define ASM_DRAMINIT (asm_dram_init - CONFIG_SYS_TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
  31. #define ASM_DRAMINIT_N (asm_dram_init - TEXT_BASE)
  32. #define ASM_SBF_IMG_HDR (asm_sbf_img_hdr - CONFIG_SYS_TEXT_BASE + CONFIG_SYS_INIT_RAM_ADDR)
  33. #endif
  34. .text
  35. /*
  36. * Vector table. This is used for initial platform startup.
  37. * These vectors are to catch any un-intended traps.
  38. */
  39. _vectors:
  40. #if defined(CONFIG_SERIAL_BOOT)
  41. INITSP: .long 0 /* Initial SP */
  42. #ifdef CONFIG_CF_SBF
  43. INITPC: .long ASM_DRAMINIT /* Initial PC */
  44. #endif
  45. #ifdef CONFIG_SYS_NAND_BOOT
  46. INITPC: .long ASM_DRAMINIT_N /* Initial PC */
  47. #endif
  48. #else
  49. INITSP: .long 0 /* Initial SP */
  50. INITPC: .long _START /* Initial PC */
  51. #endif
  52. vector02: .long _FAULT /* Access Error */
  53. vector03: .long _FAULT /* Address Error */
  54. vector04: .long _FAULT /* Illegal Instruction */
  55. vector05: .long _FAULT /* Reserved */
  56. vector06: .long _FAULT /* Reserved */
  57. vector07: .long _FAULT /* Reserved */
  58. vector08: .long _FAULT /* Privilege Violation */
  59. vector09: .long _FAULT /* Trace */
  60. vector0A: .long _FAULT /* Unimplemented A-Line */
  61. vector0B: .long _FAULT /* Unimplemented F-Line */
  62. vector0C: .long _FAULT /* Debug Interrupt */
  63. vector0D: .long _FAULT /* Reserved */
  64. vector0E: .long _FAULT /* Format Error */
  65. vector0F: .long _FAULT /* Unitialized Int. */
  66. /* Reserved */
  67. vector10_17:
  68. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  69. vector18: .long _FAULT /* Spurious Interrupt */
  70. vector19: .long _FAULT /* Autovector Level 1 */
  71. vector1A: .long _FAULT /* Autovector Level 2 */
  72. vector1B: .long _FAULT /* Autovector Level 3 */
  73. vector1C: .long _FAULT /* Autovector Level 4 */
  74. vector1D: .long _FAULT /* Autovector Level 5 */
  75. vector1E: .long _FAULT /* Autovector Level 6 */
  76. vector1F: .long _FAULT /* Autovector Level 7 */
  77. #if !defined(CONFIG_SERIAL_BOOT)
  78. /* TRAP #0 - #15 */
  79. vector20_2F:
  80. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  81. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  82. /* Reserved */
  83. vector30_3F:
  84. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  85. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  86. vector64_127:
  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. vector128_191:
  96. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  97. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  98. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  99. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  100. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  101. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  102. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  103. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  104. vector192_255:
  105. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  106. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  107. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  108. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  109. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  110. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  111. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  112. .long _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT, _FAULT
  113. #endif
  114. #if defined(CONFIG_SERIAL_BOOT)
  115. /* Image header: chksum 4 bytes, len 4 bytes, img dest 4 bytes */
  116. asm_sbf_img_hdr:
  117. .long 0x00000000 /* checksum, not yet implemented */
  118. .long 0x00040000 /* image length */
  119. .long CONFIG_SYS_TEXT_BASE /* image to be relocated at */
  120. asm_dram_init:
  121. move.w #0x2700,%sr /* Mask off Interrupt */
  122. #ifdef CONFIG_SYS_NAND_BOOT
  123. /* for assembly stack */
  124. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  125. movec %d0, %RAMBAR1
  126. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  127. clr.l %sp@-
  128. #endif
  129. #ifdef CONFIG_CF_SBF
  130. move.l #CONFIG_SYS_INIT_RAM_ADDR, %d0
  131. movec %d0, %VBR
  132. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  133. movec %d0, %RAMBAR1
  134. /* initialize general use internal ram */
  135. move.l #0, %d0
  136. move.l #(ICACHE_STATUS), %a1 /* icache */
  137. move.l #(DCACHE_STATUS), %a2 /* dcache */
  138. move.l %d0, (%a1)
  139. move.l %d0, (%a2)
  140. /* invalidate and disable cache */
  141. move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
  142. movec %d0, %CACR /* Invalidate cache */
  143. move.l #0, %d0
  144. movec %d0, %ACR0
  145. movec %d0, %ACR1
  146. movec %d0, %ACR2
  147. movec %d0, %ACR3
  148. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  149. clr.l %sp@-
  150. /* Must disable global address */
  151. move.l #0xFC008000, %a1
  152. move.l #(CONFIG_SYS_CS0_BASE), (%a1)
  153. move.l #0xFC008008, %a1
  154. move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
  155. move.l #0xFC008004, %a1
  156. move.l #(CONFIG_SYS_CS0_MASK), (%a1)
  157. #endif /* CONFIG_CF_SBF */
  158. #ifdef CONFIG_MCF5441x
  159. /* TC: enable all peripherals,
  160. in the future only enable certain peripherals */
  161. move.l #0xFC04002D, %a1
  162. #if defined(CONFIG_CF_SBF)
  163. move.b #23, (%a1) /* dspi */
  164. #endif
  165. move.b #46, (%a1) /* DDR */
  166. /* slew settings */
  167. move.l #0xEC094060, %a1
  168. move.b #0, (%a1)
  169. /* use vco instead of cpu*2 clock for ddr clock */
  170. move.l #0xEC09001A, %a1
  171. move.w #0xE01D, (%a1)
  172. /* DDR settings */
  173. move.l #0xFC0B8180, %a1
  174. move.l #0x00000000, (%a1)
  175. move.l #0x40000000, (%a1)
  176. move.l #0xFC0B81AC, %a1
  177. move.l #0x01030203, (%a1)
  178. move.l #0xFC0B8000, %a1
  179. move.l #0x01010101, (%a1)+ /* 0x00 */
  180. move.l #0x00000101, (%a1)+ /* 0x04 */
  181. move.l #0x01010100, (%a1)+ /* 0x08 */
  182. move.l #0x01010000, (%a1)+ /* 0x0C */
  183. move.l #0x00010101, (%a1)+ /* 0x10 */
  184. move.l #0xFC0B8018, %a1
  185. move.l #0x00010100, (%a1)+ /* 0x18 */
  186. move.l #0x00000001, (%a1)+ /* 0x1C */
  187. move.l #0x01000001, (%a1)+ /* 0x20 */
  188. move.l #0x00000100, (%a1)+ /* 0x24 */
  189. move.l #0x00010001, (%a1)+ /* 0x28 */
  190. move.l #0x00000200, (%a1)+ /* 0x2C */
  191. move.l #0x01000002, (%a1)+ /* 0x30 */
  192. move.l #0x00000000, (%a1)+ /* 0x34 */
  193. move.l #0x00000100, (%a1)+ /* 0x38 */
  194. move.l #0x02000100, (%a1)+ /* 0x3C */
  195. move.l #0x02000407, (%a1)+ /* 0x40 */
  196. move.l #0x02030007, (%a1)+ /* 0x44 */
  197. move.l #0x02000100, (%a1)+ /* 0x48 */
  198. move.l #0x0A030203, (%a1)+ /* 0x4C */
  199. move.l #0x00020708, (%a1)+ /* 0x50 */
  200. move.l #0x00050008, (%a1)+ /* 0x54 */
  201. move.l #0x04030002, (%a1)+ /* 0x58 */
  202. move.l #0x00000004, (%a1)+ /* 0x5C */
  203. move.l #0x020A0000, (%a1)+ /* 0x60 */
  204. move.l #0x0C00000E, (%a1)+ /* 0x64 */
  205. move.l #0x00002004, (%a1)+ /* 0x68 */
  206. move.l #0x00000000, (%a1)+ /* 0x6C */
  207. move.l #0x00100010, (%a1)+ /* 0x70 */
  208. move.l #0x00100010, (%a1)+ /* 0x74 */
  209. move.l #0x00000000, (%a1)+ /* 0x78 */
  210. move.l #0x07990000, (%a1)+ /* 0x7C */
  211. move.l #0xFC0B80A0, %a1
  212. move.l #0x00000000, (%a1)+ /* 0xA0 */
  213. move.l #0x00C80064, (%a1)+ /* 0xA4 */
  214. move.l #0x44520002, (%a1)+ /* 0xA8 */
  215. move.l #0x00C80023, (%a1)+ /* 0xAC */
  216. move.l #0xFC0B80B4, %a1
  217. move.l #0x0000C350, (%a1) /* 0xB4 */
  218. move.l #0xFC0B80E0, %a1
  219. move.l #0x04000000, (%a1)+ /* 0xE0 */
  220. move.l #0x03000304, (%a1)+ /* 0xE4 */
  221. move.l #0x40040000, (%a1)+ /* 0xE8 */
  222. move.l #0xC0004004, (%a1)+ /* 0xEC */
  223. move.l #0x0642C000, (%a1)+ /* 0xF0 */
  224. move.l #0x00000642, (%a1)+ /* 0xF4 */
  225. move.l #0xFC0B8024, %a1
  226. tpf
  227. move.l #0x01000100, (%a1) /* 0x24 */
  228. move.l #0x2000, %d1
  229. jsr asm_delay
  230. #endif /* CONFIG_MCF5441x */
  231. #ifdef CONFIG_MCF5445x
  232. /* Dram Initialization a1, a2, and d0 */
  233. /* mscr sdram */
  234. move.l #0xFC0A4074, %a1
  235. move.b #(CONFIG_SYS_SDRAM_DRV_STRENGTH), (%a1)
  236. nop
  237. /* SDRAM Chip 0 and 1 */
  238. move.l #0xFC0B8110, %a1
  239. move.l #0xFC0B8114, %a2
  240. /* calculate the size */
  241. move.l #0x13, %d1
  242. move.l #(CONFIG_SYS_SDRAM_SIZE), %d2
  243. #ifdef CONFIG_SYS_SDRAM_BASE1
  244. lsr.l #1, %d2
  245. #endif
  246. dramsz_loop:
  247. lsr.l #1, %d2
  248. add.l #1, %d1
  249. cmp.l #1, %d2
  250. bne dramsz_loop
  251. #ifdef CONFIG_SYS_NAND_BOOT
  252. beq asm_nand_chk_status
  253. #endif
  254. /* SDRAM Chip 0 and 1 */
  255. move.l #(CONFIG_SYS_SDRAM_BASE), (%a1)
  256. or.l %d1, (%a1)
  257. #ifdef CONFIG_SYS_SDRAM_BASE1
  258. move.l #(CONFIG_SYS_SDRAM_BASE1), (%a2)
  259. or.l %d1, (%a2)
  260. #endif
  261. nop
  262. /* dram cfg1 and cfg2 */
  263. move.l #0xFC0B8008, %a1
  264. move.l #(CONFIG_SYS_SDRAM_CFG1), (%a1)
  265. nop
  266. move.l #0xFC0B800C, %a2
  267. move.l #(CONFIG_SYS_SDRAM_CFG2), (%a2)
  268. nop
  269. move.l #0xFC0B8000, %a1 /* Mode */
  270. move.l #0xFC0B8004, %a2 /* Ctrl */
  271. /* Issue PALL */
  272. move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
  273. nop
  274. #ifdef CONFIG_M54455EVB
  275. /* Issue LEMR */
  276. move.l #(CONFIG_SYS_SDRAM_EMOD + 0x408), (%a1)
  277. nop
  278. move.l #(CONFIG_SYS_SDRAM_MODE + 0x300), (%a1)
  279. nop
  280. #endif
  281. move.l #1000, %d1
  282. jsr asm_delay
  283. /* Issue PALL */
  284. move.l #(CONFIG_SYS_SDRAM_CTRL + 2), (%a2)
  285. nop
  286. /* Perform two refresh cycles */
  287. move.l #(CONFIG_SYS_SDRAM_CTRL + 4), %d0
  288. nop
  289. move.l %d0, (%a2)
  290. move.l %d0, (%a2)
  291. nop
  292. #ifdef CONFIG_M54455EVB
  293. move.l #(CONFIG_SYS_SDRAM_MODE + 0x200), (%a1)
  294. nop
  295. #elif defined(CONFIG_M54451EVB)
  296. /* Issue LEMR */
  297. move.l #(CONFIG_SYS_SDRAM_MODE), (%a1)
  298. nop
  299. move.l #(CONFIG_SYS_SDRAM_EMOD), (%a1)
  300. #endif
  301. move.l #500, %d1
  302. jsr asm_delay
  303. move.l #(CONFIG_SYS_SDRAM_CTRL), %d1
  304. and.l #0x7FFFFFFF, %d1
  305. #ifdef CONFIG_M54455EVB
  306. or.l #0x10000C00, %d1
  307. #elif defined(CONFIG_M54451EVB)
  308. or.l #0x10000C00, %d1
  309. #endif
  310. move.l %d1, (%a2)
  311. nop
  312. move.l #2000, %d1
  313. jsr asm_delay
  314. #endif /* CONFIG_MCF5445x */
  315. #ifdef CONFIG_CF_SBF
  316. /*
  317. * DSPI Initialization
  318. * a0 - general, sram - 0x80008000 - 32, see M54455EVB.h
  319. * a1 - dspi status
  320. * a2 - dtfr
  321. * a3 - drfr
  322. * a4 - Dst addr
  323. */
  324. /* Enable pins for DSPI mode - chip-selects are enabled later */
  325. asm_dspi_init:
  326. #ifdef CONFIG_MCF5441x
  327. move.l #0xEC09404E, %a1
  328. move.l #0xEC09404F, %a2
  329. move.b #0xFF, (%a1)
  330. move.b #0x80, (%a2)
  331. #endif
  332. #ifdef CONFIG_MCF5445x
  333. move.l #0xFC0A4063, %a0
  334. move.b #0x7F, (%a0)
  335. #endif
  336. /* Configure DSPI module */
  337. move.l #0xFC05C000, %a0
  338. move.l #0x80FF0C00, (%a0) /* Master, clear TX/RX FIFO */
  339. move.l #0xFC05C00C, %a0
  340. #ifdef CONFIG_MCF5441x
  341. move.l #0x3E000016, (%a0)
  342. #endif
  343. #ifdef CONFIG_MCF5445x
  344. move.l #0x3E000011, (%a0)
  345. #endif
  346. move.l #0xFC05C034, %a2 /* dtfr */
  347. move.l #0xFC05C03B, %a3 /* drfr */
  348. move.l #(ASM_SBF_IMG_HDR + 4), %a1
  349. move.l (%a1)+, %d5
  350. move.l (%a1), %a4
  351. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_SBFHDR_DATA_OFFSET), %a0
  352. move.l #(CONFIG_SYS_SBFHDR_SIZE), %d4
  353. move.l #0xFC05C02C, %a1 /* dspi status */
  354. /* Issue commands and address */
  355. move.l #0x8002000B, %d2 /* Fast Read Cmd */
  356. jsr asm_dspi_wr_status
  357. jsr asm_dspi_rd_status
  358. move.l #0x80020000, %d2 /* Address byte 2 */
  359. jsr asm_dspi_wr_status
  360. jsr asm_dspi_rd_status
  361. move.l #0x80020000, %d2 /* Address byte 1 */
  362. jsr asm_dspi_wr_status
  363. jsr asm_dspi_rd_status
  364. move.l #0x80020000, %d2 /* Address byte 0 */
  365. jsr asm_dspi_wr_status
  366. jsr asm_dspi_rd_status
  367. move.l #0x80020000, %d2 /* Dummy Wr and Rd */
  368. jsr asm_dspi_wr_status
  369. jsr asm_dspi_rd_status
  370. /* Transfer serial boot header to sram */
  371. asm_dspi_rd_loop1:
  372. move.l #0x80020000, %d2
  373. jsr asm_dspi_wr_status
  374. jsr asm_dspi_rd_status
  375. move.b %d1, (%a0) /* read, copy to dst */
  376. add.l #1, %a0 /* inc dst by 1 */
  377. sub.l #1, %d4 /* dec cnt by 1 */
  378. bne asm_dspi_rd_loop1
  379. /* Transfer u-boot from serial flash to memory */
  380. asm_dspi_rd_loop2:
  381. move.l #0x80020000, %d2
  382. jsr asm_dspi_wr_status
  383. jsr asm_dspi_rd_status
  384. move.b %d1, (%a4) /* read, copy to dst */
  385. add.l #1, %a4 /* inc dst by 1 */
  386. sub.l #1, %d5 /* dec cnt by 1 */
  387. bne asm_dspi_rd_loop2
  388. move.l #0x00020000, %d2 /* Terminate */
  389. jsr asm_dspi_wr_status
  390. jsr asm_dspi_rd_status
  391. /* jump to memory and execute */
  392. move.l #(CONFIG_SYS_TEXT_BASE + 0x400), %a0
  393. jmp (%a0)
  394. asm_dspi_wr_status:
  395. move.l (%a1), %d0 /* status */
  396. and.l #0x0000F000, %d0
  397. cmp.l #0x00003000, %d0
  398. bgt asm_dspi_wr_status
  399. move.l %d2, (%a2)
  400. rts
  401. asm_dspi_rd_status:
  402. move.l (%a1), %d0 /* status */
  403. and.l #0x000000F0, %d0
  404. lsr.l #4, %d0
  405. cmp.l #0, %d0
  406. beq asm_dspi_rd_status
  407. move.b (%a3), %d1
  408. rts
  409. #endif /* CONFIG_CF_SBF */
  410. #ifdef CONFIG_SYS_NAND_BOOT
  411. /* copy 4 boot pages to dram as soon as possible */
  412. /* each page is 996 bytes (1056 total with 60 ECC bytes */
  413. move.l #0x00000000, %a1 /* src */
  414. move.l #TEXT_BASE, %a2 /* dst */
  415. move.l #0x3E0, %d0 /* sz in long */
  416. asm_boot_nand_copy:
  417. move.l (%a1)+, (%a2)+
  418. subq.l #1, %d0
  419. bne asm_boot_nand_copy
  420. /* jump to memory and execute */
  421. move.l #(asm_nand_init), %a0
  422. jmp (%a0)
  423. asm_nand_init:
  424. /* exit nand boot-mode */
  425. move.l #0xFC0FFF30, %a1
  426. or.l #0x00000040, %d1
  427. move.l %d1, (%a1)
  428. /* initialize general use internal ram */
  429. move.l #0, %d0
  430. move.l #(CACR_STATUS), %a1 /* CACR */
  431. move.l #(ICACHE_STATUS), %a2 /* icache */
  432. move.l #(DCACHE_STATUS), %a3 /* dcache */
  433. move.l %d0, (%a1)
  434. move.l %d0, (%a2)
  435. move.l %d0, (%a3)
  436. /* invalidate and disable cache */
  437. move.l #0x01004100, %d0 /* Invalidate cache cmd */
  438. movec %d0, %CACR /* Invalidate cache */
  439. move.l #0, %d0
  440. movec %d0, %ACR0
  441. movec %d0, %ACR1
  442. movec %d0, %ACR2
  443. movec %d0, %ACR3
  444. /* Must disable global address */
  445. move.l #0xFC008000, %a1
  446. move.l #(CONFIG_SYS_CS0_BASE), (%a1)
  447. move.l #0xFC008008, %a1
  448. move.l #(CONFIG_SYS_CS0_CTRL), (%a1)
  449. move.l #0xFC008004, %a1
  450. move.l #(CONFIG_SYS_CS0_MASK), (%a1)
  451. /* NAND port configuration */
  452. move.l #0xEC094048, %a1
  453. move.b #0xFD, (%a1)+
  454. move.b #0x5F, (%a1)+
  455. move.b #0x04, (%a1)+
  456. /* reset nand */
  457. move.l #0xFC0FFF38, %a1 /* isr */
  458. move.l #0x000e0000, (%a1)
  459. move.l #0xFC0FFF08, %a2
  460. move.l #0x00000000, (%a2)+ /* car */
  461. move.l #0x11000000, (%a2)+ /* rar */
  462. move.l #0x00000000, (%a2)+ /* rpt */
  463. move.l #0x00000000, (%a2)+ /* rai */
  464. move.l #0xFC0FFF2c, %a2 /* cfg */
  465. move.l #0x00000000, (%a2)+ /* secsz */
  466. move.l #0x000e0681, (%a2)+
  467. move.l #0xFC0FFF04, %a2 /* cmd2 */
  468. move.l #0xFF404001, (%a2)
  469. move.l #0x000e0000, (%a1)
  470. move.l #0x2000, %d1
  471. jsr asm_delay
  472. /* setup nand */
  473. move.l #0xFC0FFF00, %a1
  474. move.l #0x30700000, (%a1)+ /* cmd1 */
  475. move.l #0x007EF000, (%a1)+ /* cmd2 */
  476. move.l #0xFC0FFF2C, %a1
  477. move.l #0x00000841, (%a1)+ /* secsz */
  478. move.l #0x000e0681, (%a1)+ /* cfg */
  479. move.l #100, %d4 /* 100 pages ~200KB */
  480. move.l #4, %d2 /* start at 4 */
  481. move.l #0xFC0FFF04, %a0 /* cmd2 */
  482. move.l #0xFC0FFF0C, %a1 /* rar */
  483. move.l #(TEXT_BASE + 0xF80), %a2 /* dst */
  484. asm_nand_read:
  485. move.l #0x11000000, %d0 /* rar */
  486. or.l %d2, %d0
  487. move.l %d0, (%a1)
  488. add.l #1, %d2
  489. move.l (%a0), %d0 /* cmd2 */
  490. or.l #1, %d0
  491. move.l %d0, (%a0)
  492. move.l #0x200, %d1
  493. jsr asm_delay
  494. asm_nand_chk_status:
  495. move.l #0xFC0FFF38, %a4 /* isr */
  496. move.l (%a4), %d0
  497. and.l #0x40000000, %d0
  498. tst.l %d0
  499. beq asm_nand_chk_status
  500. move.l #0xFC0FFF38, %a4 /* isr */
  501. move.l (%a4), %d0
  502. or.l #0x000E0000, %d0
  503. move.l %d0, (%a4)
  504. move.l #0x200, %d3
  505. move.l #0xFC0FC000, %a3 /* buf 1 */
  506. asm_nand_copy:
  507. move.l (%a3)+, (%a2)+
  508. subq.l #1, %d3
  509. bgt asm_nand_copy
  510. subq.l #1, %d4
  511. bgt asm_nand_read
  512. /* jump to memory and execute */
  513. move.l #(TEXT_BASE + 0x400), %a0
  514. jmp (%a0)
  515. #endif /* CONFIG_SYS_NAND_BOOT */
  516. asm_delay:
  517. nop
  518. subq.l #1, %d1
  519. bne asm_delay
  520. rts
  521. #endif /* CONFIG_CF_SBF || CONFIG_NAND_U_BOOT */
  522. .text
  523. . = 0x400
  524. .globl _start
  525. _start:
  526. #if !defined(CONFIG_SERIAL_BOOT)
  527. nop
  528. nop
  529. move.w #0x2700,%sr /* Mask off Interrupt */
  530. /* Set vector base register at the beginning of the Flash */
  531. move.l #CONFIG_SYS_FLASH_BASE, %d0
  532. movec %d0, %VBR
  533. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  534. movec %d0, %RAMBAR1
  535. /* initialize general use internal ram */
  536. move.l #0, %d0
  537. move.l #(ICACHE_STATUS), %a1 /* icache */
  538. move.l #(DCACHE_STATUS), %a2 /* dcache */
  539. move.l %d0, (%a1)
  540. move.l %d0, (%a2)
  541. /* invalidate and disable cache */
  542. move.l #(CONFIG_SYS_ICACHE_INV + CONFIG_SYS_DCACHE_INV), %d0
  543. movec %d0, %CACR /* Invalidate cache */
  544. move.l #0, %d0
  545. movec %d0, %ACR0
  546. movec %d0, %ACR1
  547. movec %d0, %ACR2
  548. movec %d0, %ACR3
  549. #else
  550. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_RAM_CTRL), %d0
  551. movec %d0, %RAMBAR1
  552. #endif
  553. /* set stackpointer to end of internal ram to get some stackspace for
  554. the first c-code */
  555. move.l #(CONFIG_SYS_INIT_RAM_ADDR + CONFIG_SYS_INIT_SP_OFFSET), %sp
  556. clr.l %sp@-
  557. move.l #__got_start, %a5 /* put relocation table address to a5 */
  558. bsr cpu_init_f /* run low-level CPU init code (from flash) */
  559. bsr board_init_f /* run low-level board init code (from flash) */
  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