Guest User

Untitled

a guest
Apr 27th, 2012
67
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/bootloader/rk27xx.c b/bootloader/rk27xx.c
  2. index dfba970..390c6f0 100644
  3. --- a/bootloader/rk27xx.c
  4. +++ b/bootloader/rk27xx.c
  5. @@ -19,11 +19,59 @@
  6. #include "crc32-rkw.h"
  7. #include "rkw-loader.h"
  8.  
  9. +/* beginning of DRAM */
  10. #define DRAM_ORIG 0x60000000
  11. +
  12. +/* bootloader code runs from 0x60700000
  13. + * so we cannot load more code to not overwrite ourself
  14. + */
  15. #define LOAD_SIZE 0x700000
  16.  
  17. extern void show_logo( void );
  18.  
  19. +/* This function setup bare minimum
  20. + * and jumps to rom in order to activate
  21. + * hardcoded rkusb mode
  22. + */
  23. +static void enter_rkusb(void)
  24. +{
  25. + asm volatile (
  26. + /* turn off cache */
  27. + "ldr r0, =0xefff0000 \n"
  28. + "ldrh r1, [r0] \n"
  29. + "strh r1, [r0] \n"
  30. +
  31. + /* turn off interrupts */
  32. + "mrs r0, cpsr \n"
  33. + "bic r0, r0, #0x1f \n"
  34. + "orr r0, r0, #0xd3 \n"
  35. + "msr cpsr, r0 \n"
  36. +
  37. + /* disable iram remap */
  38. + "mov r0, #0x18000000 \n"
  39. + "add r0, r0, #0x1c000 \n"
  40. + "mov r1, #0 \n"
  41. + "str r1, [r0, #4] \n"
  42. +
  43. + /* setup stacks in unmapped
  44. + * iram just as rom will do
  45. + */
  46. + "msr cpsr, #0xd2 \n"
  47. + "ldr r1, =0x18200274 \n"
  48. + "add r1, r1, #0x200 \n"
  49. + "mov sp, r1 \n"
  50. + "msr cpsr, #0xd3 \n"
  51. + "add r1, r1, #0x400 \n"
  52. + "mov sp, r1 \n"
  53. +
  54. + /* jump to main() in rom
  55. + * just before dfu handler
  56. + */
  57. + "ldr r0, =0xec0 \n"
  58. + "bx r0 \n"
  59. + );
  60. +}
  61. +
  62. void main(void) NORETURN_ATTR;
  63. void main(void)
  64. {
  65. @@ -87,23 +135,53 @@ void main(void)
  66. printf(rkw_strerror(ret));
  67. lcd_update();
  68. sleep(5*HZ);
  69. - power_off();
  70. +
  71. + /* if we boot rockbox we shutdown on error
  72. + * if we boot OF we fall back to rkusb mode on error
  73. + */
  74. + if (boot == rb)
  75. + {
  76. + power_off();
  77. + }
  78. + else
  79. + {
  80. + /* give visual feedback what we are doing */
  81. + printf("Entering rockchip USB mode...");
  82. + lcd_update();
  83. +
  84. + enter_rkusb();
  85. + }
  86. }
  87. else
  88. {
  89. + /* print 'Loading OK' */
  90. printf(rkw_strerror(0));
  91. sleep(HZ);
  92. }
  93.  
  94. + /* jump to entrypoint */
  95. kernel_entry = (void*) loadbuffer;
  96. commit_discard_idcache();
  97.  
  98. printf("Executing");
  99. kernel_entry();
  100.  
  101. + /* this should never be reached actually */
  102. printf("ERR: Failed to boot");
  103. sleep(5*HZ);
  104. - power_off();
  105. +
  106. + if (boot = rb)
  107. + {
  108. + power_off();
  109. + }
  110. + else
  111. + {
  112. + /* give visual feedback what we are doing */
  113. + printf("Entering rockchip USB mode...");
  114. + lcd_update();
  115. +
  116. + enter_rkusb();
  117. + }
  118.  
  119. /* hang */
  120. while(1);
RAW Paste Data