boot_mode_menu.c 5.8 KB

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