kimagerescue.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. #ifndef CONFIG_SVINTO_SIM
  48. ;; setup port PA and PB default initial directions and data
  49. ;; (so we can flash LEDs, and so that DTR and others are set)
  50. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DIR, $r0
  51. move.b $r0, [R_PORT_PA_DIR]
  52. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r0
  53. move.b $r0, [R_PORT_PA_DATA]
  54. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DIR, $r0
  55. move.b $r0, [R_PORT_PB_DIR]
  56. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r0
  57. move.b $r0, [R_PORT_PB_DATA]
  58. ;; We need to setup the bus registers before we start using the DRAM
  59. #include "../../lib/dram_init.S"
  60. #endif
  61. ;; Setup the stack to a suitably high address.
  62. ;; We assume 8 MB is the minimum DRAM in an eLinux
  63. ;; product and put the sp at the top for now.
  64. move.d 0x40800000, $sp
  65. ;; setup the serial port at 115200 baud
  66. moveq 0, $r0
  67. move.d $r0, [SERXOFF]
  68. move.b 0x99, $r0
  69. move.b $r0, [SERBAUD] ; 115.2kbaud for both transmit
  70. ; and receive
  71. move.b 0x40, $r0 ; rec enable
  72. move.b $r0, [SERRECC]
  73. moveq 0, $r1 ; "timer" to clock out a LED red flash
  74. move.d CODE_START, $r3 ; destination counter
  75. move.d CODE_LENGTH, $r4 ; length
  76. move.d TIMEOUT_VALUE, $r5 ; "timeout" until jump
  77. wait_ser:
  78. addq 1, $r1
  79. subq 1, $r5 ; decrease timeout
  80. beq jump_start ; timed out
  81. nop
  82. #ifndef CONFIG_ETRAX_NO_LEDS
  83. #ifdef CONFIG_ETRAX_PA_LEDS
  84. move.b CONFIG_ETRAX_DEF_R_PORT_PA_DATA, $r2
  85. #endif
  86. #ifdef CONFIG_ETRAX_PB_LEDS
  87. move.b CONFIG_ETRAX_DEF_R_PORT_PB_DATA, $r2
  88. #endif
  89. move.d (1 << CONFIG_ETRAX_LED1R) | (1 << CONFIG_ETRAX_LED2R), $r0
  90. btstq 16, $r1
  91. bpl 1f
  92. nop
  93. or.d $r0, $r2 ; set bit
  94. ba 2f
  95. nop
  96. 1: not $r0 ; clear bit
  97. and.d $r0, $r2
  98. 2:
  99. #ifdef CONFIG_ETRAX_PA_LEDS
  100. move.b $r2, [R_PORT_PA_DATA]
  101. #endif
  102. #ifdef CONFIG_ETRAX_PB_LEDS
  103. move.b $r2, [R_PORT_PB_DATA]
  104. #endif
  105. #endif
  106. ;; check if we got something on the serial port
  107. move.b [SERSTAT], $r0
  108. btstq 0, $r0 ; data_avail
  109. bpl wait_ser
  110. nop
  111. ;; got something - copy the byte and loop
  112. move.b [SERRDAT], $r0
  113. move.b $r0, [$r3+]
  114. move.d TIMEOUT_VALUE, $r5 ; reset "timeout"
  115. subq 1, $r4 ; decrease length
  116. bne wait_ser
  117. nop
  118. jump_start:
  119. ;; jump into downloaded code
  120. jump CODE_START