boot_mode_menu.c 5.7 KB

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