head.S 5.0 KB

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