boot_mode_menu.c 5.8 KB

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