My_shell模拟实现
2026/6/13 19:14:55
启动前需要通过mcu通讯来判断是进入正常开机还是关机充电。
#include<app/boot_ui.h>#ifdefWITH_PLATFORM_MEDIATEK_COMMON_CHARGER#include<mtk_charger.h>#endif#include<lib/kcmdline.h>#ifdefWITH_PLATFORM_MEDIATEK_COMMON_KEYPAD#include<mtk_key.h>#endif#include<platform/boot_mode.h>#include<platform/mboot_params.h>#include<platform/wdt.h>#include<platform_mtk.h>#include<string.h>#include<trace.h>#include<dev/uart.h>#include<uart_api.h>#include<platform/addressmap.h>#include<platform/gpio.h>#include<gpio_api.h>#defineudelay(x)spin(x)#definemdelay(x)udelay((x)*1000)staticu8 g_boot_mode=NORMAL_BOOT;voidboot_mode_check(void){u8 pl_mode=pl_mode_check();if(pl_mode)g_boot_mode=pl_mode;elseif(recovery_check())g_boot_mode=RECOVERY_BOOT;elseif(fastboot_check())g_boot_mode=FASTBOOT_BOOT;elseif(factory_key_check())g_boot_mode=FACTORY_BOOT;elseif(bootmenu_check())g_boot_mode=boot_menu_select();elseif(kpoc_check())g_boot_mode=KERNEL_POWER_OFF_CHARGING_BOOT;//GPIO INIT(UART_1)mt_set_gpio_mode(GPIO136,GPIO_MODE_07);mt_set_gpio_dir(GPIO136,GPIO_DIR_IN);mt_set_gpio_pull_select(GPIO136,GPIO_PULL_UP);mt_set_gpio_pull_enable(GPIO136,GPIO_PULL_ENABLE);mt_set_gpio_mode(GPIO137,GPIO_MODE_07);mt_set_gpio_dir(GPIO137,GPIO_DIR_OUT);//获取 boot modeuart_init_port(1,115200);charc[10]={0x02,0x02,0x00,0x04,0x11,0x14,0x00,0x00,0x03,0x40};for(inti=0;i<10;i++){uart_putc(1,c[i]);}dprintf(CRITICAL,"------------uart port 1 putc end\n");mdelay(100);constcharc_cmp[15]={0x02,0x02,0x00,0x09,0x11,0x14,0x01,0x00,0x04,0x00,0x00,0x00,0xff,0x09,0x40};for(inti=0;i<15;i++){intret=uart_getc(1,false);dprintf(CRITICAL,"------------uart port 1 getc c[%d] = 0x%x \n",i,ret);//考虑到没有mcu电源板的情况,首字节错误,直接跳出判断if(i==0&&ret!=0x02){dprintf(CRITICAL,"------------uart port 1 getc error \n");break;}if(c_cmp[i]!=ret){//index_i = 12, 0x00:异常开机;0x01:关机充电;0x02:按键开机if(i==12){if(ret==0x00){//异常开机需要怎么处理?dprintf(CRITICAL,"------------uart port 1 c[%d] = 0x%x, abnormal boot \n",i,ret);}elseif(ret==0x01){//关机充电g_boot_mode=KERNEL_POWER_OFF_CHARGING_BOOT;dprintf(CRITICAL,"------------uart port 1 c[%d] = 0x%x, only charging \n",i,ret);}elseif(ret==0x02){//按键开机g_boot_mode=NORMAL_BOOT;dprintf(CRITICAL,"------------uart port 1 c[%d] = 0x%x, normal boot \n",i,ret);}continue;}dprintf(CRITICAL,"------------uart port 1 error c[%d] = 0x%x \n",i,ret);}}dprintf(CRITICAL,"%s zzh g_boot_mode = %d \n",__func__,g_boot_mode);}