boot_mode_menu.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*This file implements MTK boot mode.*/
  2. #include <sys/types.h>
  3. #include <debug.h>
  4. #include <err.h>
  5. #include <reg.h>
  6. #include <video.h>
  7. #include <platform/mt_typedefs.h>
  8. #include <platform/boot_mode.h>
  9. #include <platform/mt_reg_base.h>
  10. #include <platform/mtk_key.h>
  11. #include <platform/mt_gpt.h>
  12. #include <target/cust_key.h>
  13. #include <platform/mtk_wdt.h>
  14. extern int unshield_recovery_detection(void);
  15. extern BOOL recovery_check_command_trigger(void);
  16. extern void boot_mode_menu_select();
  17. extern void mtk_wdt_disable(void);
  18. #define MODULE_NAME "[BOOT_MENU]"
  19. extern void cmdline_append(const char* append_string);
  20. extern bool boot_ftrace;
  21. bool g_boot_menu = false;
  22. void boot_mode_menu_select()
  23. {
  24. int select = 0; // 0=recovery mode, 1=fastboot. 2=normal boot 3=normal boot + ftrace.4=slub debug off
  25. const char* title_msg = "Select Boot Mode:\n[VOLUME_UP to select. VOLUME_DOWN is OK.]\n\n";
  26. video_clean_screen();
  27. video_set_cursor(video_get_rows()/2, 0);
  28. video_printf(title_msg);
  29. video_printf("[Recovery Mode] <<==\n");
  30. #ifdef MTK_FASTBOOT_SUPPORT
  31. video_printf("[Fastboot Mode] \n");
  32. #endif
  33. video_printf("[Normal Boot] \n");
  34. #if !defined(USER_LOAD) || defined(MTK_BUILD_ROOT) || defined(MTK_BUILD_ENHANCE_MENU)
  35. video_printf("[Normal Boot +ftrace] \n");
  36. video_printf("[Normal slub debug off] \n");
  37. #endif
  38. while (1) {
  39. if (mtk_detect_key(MT65XX_MENU_SELECT_KEY)) { //VOL_UP
  40. g_boot_menu = true;
  41. switch (select) {
  42. case 0:
  43. #ifdef MTK_FASTBOOT_SUPPORT
  44. select = 1;
  45. video_set_cursor(video_get_rows()/2, 0);
  46. video_printf(title_msg);
  47. video_printf("[Recovery Mode] \n");
  48. video_printf("[Fastboot Mode] <<==\n");
  49. video_printf("[Normal Boot] \n");
  50. #if !defined(USER_LOAD) || defined(MTK_BUILD_ROOT) || defined(MTK_BUILD_ENHANCE_MENU)
  51. video_printf("[Normal Boot +ftrace] \n");
  52. video_printf("[Normal slub debug off] \n");
  53. #endif
  54. break;
  55. #endif
  56. case 1:
  57. select = 2;
  58. video_set_cursor(video_get_rows()/2, 0);
  59. video_printf(title_msg);
  60. video_printf("[Recovery Mode] \n");
  61. #ifdef MTK_FASTBOOT_SUPPORT
  62. video_printf("[Fastboot Mode] \n");
  63. #endif
  64. video_printf("[Normal Boot] <<==\n");
  65. #if !defined(USER_LOAD) || defined(MTK_BUILD_ROOT) || defined(MTK_BUILD_ENHANCE_MENU)
  66. video_printf("[Normal Boot +ftrace] \n");
  67. video_printf("[Normal slub debug off] \n");
  68. #endif
  69. break;
  70. case 2:
  71. #if defined(USER_LOAD) && !defined(MTK_BUILD_ROOT) && !defined(MTK_BUILD_ENHANCE_MENU)
  72. select = 0;
  73. #else
  74. select = 3;
  75. #endif
  76. video_set_cursor(video_get_rows()/2, 0);
  77. video_printf(title_msg);
  78. #if defined(USER_LOAD) && !defined(MTK_BUILD_ROOT) && !defined(MTK_BUILD_ENHANCE_MENU)
  79. video_printf("[Recovery Mode] <<==\n");
  80. #ifdef MTK_FASTBOOT_SUPPORT
  81. video_printf("[Fastboot Mode] \n");
  82. #endif
  83. video_printf("[Normal Boot] \n");
  84. #else
  85. video_printf("[Recovery Mode] \n");
  86. #ifdef MTK_FASTBOOT_SUPPORT
  87. video_printf("[Fastboot Mode] \n");
  88. #endif
  89. video_printf("[Normal Boot] \n");
  90. video_printf("[Normal Boot +ftrace] <<==\n");
  91. video_printf("[Normal slub debug off] \n");
  92. #endif
  93. break;
  94. #if !defined(USER_LOAD) || defined(MTK_BUILD_ROOT) || defined(MTK_BUILD_ENHANCE_MENU)
  95. case 3:
  96. select = 4;
  97. video_set_cursor(video_get_rows()/2, 0);
  98. video_printf(title_msg);
  99. video_printf("[Recovery Mode] \n");
  100. #ifdef MTK_FASTBOOT_SUPPORT
  101. video_printf("[Fastboot Mode] \n");
  102. #endif
  103. video_printf("[Normal Boot] \n");
  104. video_printf("[Normal Boot +ftrace] \n");
  105. video_printf("[Normal slub debug off] <<==\n");
  106. break;
  107. #endif
  108. #if !defined(USER_LOAD) || defined(MTK_BUILD_ROOT) || defined(MTK_BUILD_ENHANCE_MENU)
  109. case 4:
  110. select = 0;
  111. video_set_cursor(video_get_rows()/2, 0);
  112. video_printf(title_msg);
  113. video_printf("[Recovery Mode] <<==\n");
  114. #ifdef MTK_FASTBOOT_SUPPORT
  115. video_printf("[Fastboot Mode] \n");
  116. #endif
  117. video_printf("[Normal Boot] \n");
  118. video_printf("[Normal Boot +ftrace] \n");
  119. video_printf("[Normal slub debug off] \n");
  120. break;
  121. #endif
  122. default:
  123. break;
  124. }
  125. dprintf(0, "[VOL_UP]Key Detect, current select:%d\n", select);
  126. mdelay(300);
  127. } else if (mtk_detect_key(MT65XX_MENU_OK_KEY)) { //VOL_DOWN,
  128. //use for OK
  129. break;
  130. } else {
  131. //pass
  132. }
  133. }
  134. if (select == 0) {
  135. g_boot_mode = RECOVERY_BOOT;
  136. } else if (select == 1) {
  137. g_boot_mode = FASTBOOT;
  138. } else if (select == 2) {
  139. g_boot_mode = NORMAL_BOOT;
  140. } else if (select == 3) {
  141. boot_ftrace = true;
  142. cmdline_append("androidboot.boot_trace=1");
  143. g_boot_mode = NORMAL_BOOT;
  144. } else if (select == 4) {
  145. cmdline_append("slub_debug=-");
  146. g_boot_mode = NORMAL_BOOT;
  147. } else {
  148. //pass
  149. }
  150. video_set_cursor(video_get_rows()/2 +8, 0);
  151. return;
  152. }
  153. BOOL boot_menu_key_trigger(void)
  154. {
  155. #if 1
  156. //wait
  157. ulong begin = get_timer(0);
  158. dprintf(INFO, "\n%s Check boot menu\n",MODULE_NAME);
  159. dprintf(INFO, "%s Wait 50ms for special keys\n",MODULE_NAME);
  160. //let some case of recovery mode pass.
  161. if (unshield_recovery_detection()) {
  162. return TRUE;
  163. }
  164. while (get_timer(begin)<50) {
  165. if (mtk_detect_key(MT65XX_BOOT_MENU_KEY)) {
  166. mtk_wdt_disable();
  167. boot_mode_menu_select();
  168. mtk_wdt_init();
  169. return TRUE;
  170. }
  171. }
  172. #endif
  173. return FALSE;
  174. }
  175. BOOL boot_menu_detection(void)
  176. {
  177. return boot_menu_key_trigger();
  178. }
  179. int unshield_recovery_detection(void)
  180. {
  181. //because recovery_check_command_trigger's BOOL is different from the BOOL in this file.
  182. //so use code like this type.
  183. return recovery_check_command_trigger()? TRUE:FALSE;
  184. }