kimagerescue.S 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Rescue code to be prepended on a kimage and copied to the
  3. * rescue serial port.
  4. * This is called from the rescue code, it will copy received data to
  5. * 4004000 and after a timeout jump to it.
  6. */
  7. #define ASSEMBLER_MACROS_ONLY
  8. #include <arch/sv_addr_ag.h>
  9. #define CODE_START 0x40004000
  10. #define CODE_LENGTH 784
  11. #define TIMEOUT_VALUE 1000
  12. #ifdef CONFIG_ETRAX_RESCUE_SER0
  13. #define SERXOFF R_SERIAL0_XOFF
  14. #define SERBAUD R_SERIAL0_BAUD
  15. #define SERRECC R_SERIAL0_REC_CTRL
  16. #define SERRDAT R_SERIAL0_REC_DATA
  17. #define SERSTAT R_SERIAL0_STATUS
  18. #endif
  19. #ifdef CONFIG_ETRAX_RESCUE_SER1
  20. #define SERXOFF R_SERIAL1_XOFF
  21. #define SERBAUD R_SERIAL1_BAUD
  22. #define SERRECC R_SERIAL1_REC_CTRL
  23. #define SERRDAT R_SERIAL1_REC_DATA
  24. #define SERSTAT R_SERIAL1_STATUS
  25. #endif
  26. #ifdef CONFIG_ETRAX_RESCUE_SER2
  27. #define SERXOFF R_SERIAL2_XOFF
  28. #define SERBAUD R_SERIAL2_BAUD
  29. #define SERRECC R_SERIAL2_REC_CTRL
  30. #define SERRDAT R_SERIAL2_REC_DATA
  31. #define SERSTAT R_SERIAL2_STATUS
  32. #endif
  33. #ifdef CONFIG_ETRAX_RESCUE_SER3
  34. #define SERXOFF R_SERIAL3_XOFF
  35. #define SERBAUD R_SERIAL3_BAUD
  36. #define SERRECC R_SERIAL3_REC_CTRL
  37. #define SERRDAT R_SERIAL3_REC_DATA
  38. #define SERSTAT R_SERIAL3_STATUS
  39. #endif
  40. .text
  41. ;; This is the entry point of the rescue code
  42. ;; 0x80000000 if loaded in flash (as it should be)
  43. ;; since etrax actually starts at address 2 when booting from flash, we
  44. ;; put a nop (2 bytes) here first so we dont accidentally skip the di
  45. nop
  46. di
  47. ;; setup port PA and PB default initial directions and data
  48. ;; (so we can flash LEDs, and so that DTR and others are set)
  49. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DIR, $r0
  50. move.b $r0, [R_PORT_PA_DIR]
  51. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r0
  52. move.b $r0, [R_PORT_PA_DATA]
  53. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DIR, $r0
  54. move.b $r0, [R_PORT_PB_DIR]
  55. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r0
  56. move.b $r0, [R_PORT_PB_DATA]
  57. ;; We need to setup the bus registers before we start using the DRAM
  58. #include "../../lib/dram_init.S"
  59. ;; Setup the stack to a suitably high address.
  60. ;; We assume 8 MB is the minimum DRAM in an eLinux
  61. ;; product and put the sp at the top for now.
  62. move.d 0x40800000, $sp
  63. ;; setup the serial port at 115200 baud
  64. moveq 0, $r0
  65. move.d $r0, [SERXOFF]
  66. move.b 0x99, $r0
  67. move.b $r0, [SERBAUD] ; 115.2kbaud for both transmit
  68. ; and receive
  69. move.b 0x40, $r0 ; rec enable
  70. move.b $r0, [SERRECC]
  71. moveq 0, $r1 ; "timer" to clock out a LED red flash
  72. move.d CODE_START, $r3 ; destination counter
  73. move.d CODE_LENGTH, $r4 ; length
  74. move.d TIMEOUT_VALUE, $r5 ; "timeout" until jump
  75. wait_ser:
  76. addq 1, $r1
  77. subq 1, $r5 ; decrease timeout
  78. beq jump_start ; timed out
  79. nop
  80. #ifndef CONFIG_ETRAX_NO_LEDS
  81. #ifdef CONFIG_ETRAX_PA_LEDS
  82. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r2
  83. #endif
  84. #ifdef CONFIG_ETRAX_PB_LEDS
  85. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r2
  86. #endif
  87. move.d (1 << CONFIG_ETRAX_LED1R) | (1 << CONFIG_ETRAX_LED2R), $r0
  88. btstq 16, $r1
  89. bpl 1f
  90. nop
  91. or.d $r0, $r2 ; set bit
  92. ba 2f
  93. nop
  94. 1: not $r0 ; clear bit
  95. and.d $r0, $r2
  96. 2:
  97. #ifdef CONFIG_ETRAX_PA_LEDS
  98. move.b $r2, [R_PORT_PA_DATA]
  99. #endif
  100. #ifdef CONFIG_ETRAX_PB_LEDS
  101. move.b $r2, [R_PORT_PB_DATA]
  102. #endif
  103. #endif
  104. ;; check if we got something on the serial port
  105. move.b [SERSTAT], $r0
  106. btstq 0, $r0 ; data_avail
  107. bpl wait_ser
  108. nop
  109. ;; got something - copy the byte and loop
  110. move.b [SERRDAT], $r0
  111. move.b $r0, [$r3+]
  112. move.d TIMEOUT_VALUE, $r5 ; reset "timeout"
  113. subq 1, $r4 ; decrease length
  114. bne wait_ser
  115. nop
  116. jump_start:
  117. ;; jump into downloaded code
  118. jump CODE_START