boot_menu.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Copyright Statement:
  2. *
  3. * This software/firmware and related documentation ("MediaTek Software") are
  4. * protected under relevant copyright laws. The information contained herein
  5. * is confidential and proprietary to MediaTek Inc. and/or its licensors.
  6. * Without the prior written permission of MediaTek inc. and/or its licensors,
  7. * any reproduction, modification, use or disclosure of MediaTek Software,
  8. * and information contained herein, in whole or in part, shall be strictly prohibited.
  9. */
  10. /* MediaTek Inc. (C) 2019. All rights reserved.
  11. *
  12. * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  13. * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  14. * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
  15. * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  18. * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  19. * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  20. * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
  21. * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
  22. * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
  23. * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
  24. * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
  25. * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
  26. * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  27. * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  28. * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
  29. * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  30. *
  31. * The following software/firmware and/or related documentation ("MediaTek Software")
  32. * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
  33. * applicable license agreements with MediaTek Inc.
  34. */
  35. /*This file implements MTK boot menu.*/
  36. #include <compiler.h>
  37. #include <debug.h>
  38. #include <err.h>
  39. #include <platform/mt_typedefs.h>
  40. #include <platform/boot_mode.h>
  41. #include <platform/mtk_key.h>
  42. #include <platform/mt_gpt.h>
  43. #include <string.h>
  44. #include <sys/types.h>
  45. #include <target/cust_key.h>
  46. #include <video.h>
  47. extern void cmdline_append(const char *append_string);
  48. typedef void (*entry_cb)(void);
  49. struct boot_menu {
  50. u8 boot_mode;
  51. const char *item_text;
  52. entry_cb callback;
  53. };
  54. //register the callback function
  55. void ftrace_cb()
  56. {
  57. cmdline_append("androidboot.boot_trace=1");
  58. }
  59. void kmemleak_cb()
  60. {
  61. cmdline_append("kmemleak=on");
  62. }
  63. void initcall_cb()
  64. {
  65. cmdline_append("initcall_debug=1 log_buf_len=4M");
  66. }
  67. struct boot_menu ui_entry[] = {
  68. {RECOVERY_BOOT, "[Recovery Mode]", NULL},
  69. {FASTBOOT, "[Fastboot Mode]", NULL},
  70. {NORMAL_BOOT, "[Normal Boot]", NULL},
  71. #if !defined(USER_LOAD) || defined(MTK_BUILD_ENHANCE_MENU)
  72. {NORMAL_BOOT, "[Normal Boot +ftrace]", ftrace_cb},
  73. {NORMAL_BOOT, "[Normal kmemleak on]", kmemleak_cb},
  74. {NORMAL_BOOT, "[Normal Boot +initcall]", initcall_cb},
  75. #endif
  76. };
  77. static void update_menu(unsigned int index) {
  78. #define LEN 100
  79. const char* title_msg = "Select Boot Mode:\n[VOLUME_UP to select. VOLUME_DOWN is OK.]\n\n";
  80. char str_buf[LEN];
  81. unsigned int i, length;
  82. video_set_cursor(video_get_rows()/2, 0);
  83. video_printf(title_msg);
  84. for (i = 0; i < countof(ui_entry); i++) {
  85. memset(str_buf, 0, LEN);
  86. length = strlen(ui_entry[i].item_text);
  87. snprintf(str_buf, length+1, "%s", ui_entry[i].item_text);
  88. if (i == index) {
  89. dprintf(0, "Switch to %s mode.\n", str_buf);
  90. sprintf(str_buf+length, " <<==\n");
  91. } else
  92. sprintf(str_buf+length, " \n");
  93. video_printf(str_buf);
  94. }
  95. }
  96. void boot_menu_select() {
  97. //0=recovery mode 1=fastboot 2=normal boot
  98. //3=normal boot + ftrace 4=kmemleak on 5=Boot + initcall
  99. unsigned int select = 0;
  100. video_clean_screen();
  101. update_menu(0);
  102. while (1) {
  103. if (mtk_detect_key(MT65XX_MENU_SELECT_KEY)) { //VOL_UP
  104. select = (select + 1) % countof(ui_entry);
  105. update_menu(select);
  106. mdelay(300);
  107. } else if (mtk_detect_key(MT65XX_MENU_OK_KEY)) { //VOL_DOWN
  108. //use for OK;
  109. break;
  110. }
  111. }
  112. dprintf(0, "Boot mode:%s is selected!\n", ui_entry[select].item_text);
  113. g_boot_mode = ui_entry[select].boot_mode;
  114. if (ui_entry[select].callback)
  115. ui_entry[select].callback();
  116. video_set_cursor(video_get_rows() / 2 + 8, 0);
  117. video_clean_screen();
  118. return;
  119. }