head.S 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * Code that sets up the DRAM registers, calls the
  3. * decompressor to unpack the piggybacked kernel, and jumps.
  4. *
  5. * Copyright (C) 1999 - 2003, Axis Communications AB
  6. */
  7. #define ASSEMBLER_MACROS_ONLY
  8. #include <asm/arch/hwregs/asm/reg_map_asm.h>
  9. #include <asm/arch/hwregs/asm/gio_defs_asm.h>
  10. #include <asm/arch/hwregs/asm/config_defs_asm.h>
  11. #define RAM_INIT_MAGIC 0x56902387
  12. #define COMMAND_LINE_MAGIC 0x87109563
  13. ;; Exported symbols
  14. .globl input_data
  15. .text
  16. start:
  17. di
  18. ;; Start clocks for used blocks.
  19. move.d REG_ADDR(config, regi_config, rw_clk_ctrl), $r1
  20. move.d [$r1], $r0
  21. or.d REG_STATE(config, rw_clk_ctrl, cpu, yes) | \
  22. REG_STATE(config, rw_clk_ctrl, bif, yes) | \
  23. REG_STATE(config, rw_clk_ctrl, fix_io, yes), $r0
  24. move.d $r0, [$r1]
  25. ;; If booting from NAND flash we first have to copy some
  26. ;; data from NAND flash to internal RAM to get the code
  27. ;; that initializes the SDRAM. Lets copy 20 KB. This
  28. ;; code executes at 0x38010000 if booting from NAND and
  29. ;; we are guaranted that at least 0x200 bytes are good so
  30. ;; lets start from there. The first 8192 bytes in the nand
  31. ;; flash is spliced with zeroes and is thus 16384 bytes.
  32. move.d 0x38010200, $r10
  33. move.d 0x14200, $r11 ; Start offset in NAND flash 0x10200 + 16384
  34. move.d 0x5000, $r12 ; Length of copy
  35. ;; Before this code the tools add a partitiontable so the PC
  36. ;; has an offset from the linked address.
  37. offset1:
  38. lapcq ., $r13 ; get PC
  39. add.d first_copy_complete-offset1, $r13
  40. #include "../../lib/nand_init.S"
  41. first_copy_complete:
  42. ;; Initialze the DRAM registers.
  43. cmp.d RAM_INIT_MAGIC, $r8 ; Already initialized?
  44. beq dram_init_finished
  45. nop
  46. #include "../../lib/dram_init.S"
  47. dram_init_finished:
  48. lapcq ., $r13 ; get PC
  49. add.d second_copy_complete-dram_init_finished, $r13
  50. move.d REG_ADDR(config, regi_config, r_bootsel), $r0
  51. move.d [$r0], $r0
  52. and.d REG_MASK(config, r_bootsel, boot_mode), $r0
  53. cmp.d REG_STATE(config, r_bootsel, boot_mode, nand), $r0
  54. bne second_copy_complete ; No NAND boot
  55. nop
  56. ;; Copy 2MB from NAND flash to SDRAM (at 2-4MB into the SDRAM)
  57. move.d 0x40204000, $r10
  58. move.d 0x8000, $r11
  59. move.d 0x200000, $r12
  60. ba copy_nand_to_ram
  61. nop
  62. second_copy_complete:
  63. ;; Initiate the PA port.
  64. move.d CONFIG_ETRAX_DEF_GIO_PA_OUT, $r0
  65. move.d REG_ADDR(gio, regi_gio, rw_pa_dout), $r1
  66. move.d $r0, [$r1]
  67. move.d CONFIG_ETRAX_DEF_GIO_PA_OE, $r0
  68. move.d REG_ADDR(gio, regi_gio, rw_pa_oe), $r1
  69. move.d $r0, [$r1]
  70. ;; Setup the stack to a suitably high address.
  71. ;; We assume 8 MB is the minimum DRAM and put
  72. ;; the SP at the top for now.
  73. move.d 0x40800000, $sp
  74. ;; Figure out where the compressed piggyback image is
  75. ;; in the flash (since we wont try to copy it to DRAM
  76. ;; before unpacking). It is at _edata, but in flash.
  77. ;; Use (_edata - herami) as offset to the current PC.
  78. move.d REG_ADDR(config, regi_config, r_bootsel), $r0
  79. move.d [$r0], $r0
  80. and.d REG_MASK(config, r_bootsel, boot_mode), $r0
  81. cmp.d REG_STATE(config, r_bootsel, boot_mode, nand), $r0
  82. beq hereami2
  83. nop
  84. hereami:
  85. lapcq ., $r5 ; get PC
  86. and.d 0x7fffffff, $r5 ; strip any non-cache bit
  87. move.d $r5, $r0 ; save for later - flash address of 'herami'
  88. add.d _edata, $r5
  89. sub.d hereami, $r5 ; r5 = flash address of '_edata'
  90. move.d hereami, $r1 ; destination
  91. ba 2f
  92. nop
  93. hereami2:
  94. lapcq ., $r5 ; get PC
  95. and.d 0x00ffffff, $r5 ; strip any non-cache bit
  96. move.d $r5, $r6
  97. or.d 0x40200000, $r6
  98. move.d $r6, $r0 ; save for later - flash address of 'herami'
  99. add.d _edata, $r5
  100. sub.d hereami2, $r5 ; r5 = flash address of '_edata'
  101. add.d 0x40200000, $r5
  102. move.d hereami2, $r1 ; destination
  103. 2:
  104. ;; Copy text+data to DRAM
  105. move.d _edata, $r2 ; end destination
  106. 1: move.w [$r0+], $r3
  107. move.w $r3, [$r1+]
  108. cmp.d $r2, $r1
  109. bcs 1b
  110. nop
  111. move.d input_data, $r0 ; for the decompressor
  112. move.d $r5, [$r0] ; for the decompressor
  113. ;; Clear the decompressors BSS (between _edata and _end)
  114. moveq 0, $r0
  115. move.d _edata, $r1
  116. move.d _end, $r2
  117. 1: move.w $r0, [$r1+]
  118. cmp.d $r2, $r1
  119. bcs 1b
  120. nop
  121. ;; Save command line magic and address.
  122. move.d _cmd_line_magic, $r12
  123. move.d $r10, [$r12]
  124. move.d _cmd_line_addr, $r12
  125. move.d $r11, [$r12]
  126. ;; Do the decompression and save compressed size in _inptr
  127. jsr decompress_kernel
  128. nop
  129. ;; Restore command line magic and address.
  130. move.d _cmd_line_magic, $r10
  131. move.d [$r10], $r10
  132. move.d _cmd_line_addr, $r11
  133. move.d [$r11], $r11
  134. ;; Put start address of root partition in r9 so the kernel can use it
  135. ;; when mounting from flash
  136. move.d input_data, $r0
  137. move.d [$r0], $r9 ; flash address of compressed kernel
  138. move.d inptr, $r0
  139. add.d [$r0], $r9 ; size of compressed kernel
  140. cmp.d 0x40200000, $r9
  141. blo enter_kernel
  142. nop
  143. sub.d 0x40200000, $r9
  144. add.d 0x4000, $r9
  145. enter_kernel:
  146. ;; Enter the decompressed kernel
  147. move.d RAM_INIT_MAGIC, $r8 ; Tell kernel that DRAM is initialized
  148. jump 0x40004000 ; kernel is linked to this address
  149. nop
  150. .data
  151. input_data:
  152. .dword 0 ; used by the decompressor
  153. _cmd_line_magic:
  154. .dword 0
  155. _cmd_line_addr:
  156. .dword 0
  157. is_nand_boot:
  158. .dword 0
  159. #include "../../lib/hw_settings.S"