start.S 20 KB

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