/* ************************************************************************************************************ * * function * * name : * * parmeters : * * return : * * note : * * ************************************************************************************************************ */ int check_android_misc(void) { int mode; int pmu_value; u32 misc_offset = 0; char misc_args[2048]; char misc_fill[2048]; char boot_commond[128]; static struct bootloader_message *misc_message; if(uboot_spare_head.boot_data.work_mode != WORK_MODE_BOOT) { return 0; } if(gd->force_shell) { char delaytime[8]; sprintf(delaytime, "%d", 3); setenv("bootdelay", delaytime); } //if enter debug mode,set loglevel = 8 check_debug_mode(); memset(boot_commond, 0x0, 128); strcpy(boot_commond, getenv("bootcmd")); printf("base bootcmd=%s\n", boot_commond); //判断存储介质 if((uboot_spare_head.boot_data.storage_type == 1) || (uboot_spare_head.boot_data.storage_type == 2)) { sunxi_str_replace(boot_commond, "setargs_nand", "setargs_mmc"); printf("bootcmd set setargs_mmc\n"); } else { printf("bootcmd set setargs_nand\n"); } misc_message = (struct bootloader_message *)misc_args; memset(misc_args, 0x0, 2048); memset(misc_fill, 0xff, 2048); mode = detect_other_boot_mode(); if(mode == ANDROID_NULL_MODE) { pmu_value = axp_probe_pre_sys_mode(); if(pmu_value == PMU_PRE_FASTBOOT_MODE) { puts("PMU : ready to enter fastboot mode\n"); strcpy(misc_message->command, "bootloader"); } else if(pmu_value == PMU_PRE_RECOVERY_MODE) { puts("PMU : ready to enter recovery mode\n"); strcpy(misc_message->command, "boot-recovery"); } else { misc_offset = sunxi_partition_get_offset_byname("misc"); debug("misc_offset = %x\n",misc_offset); if(!misc_offset) { printf("no misc partition is found\n"); } else { printf("misc partition found\n"); sunxi_flash_read(misc_offset, 2048/512, misc_args); //read misc partition data } } } else if(mode == ANDROID_RECOVERY_MODE) { strcpy(misc_message->command, "boot-recovery"); } else if( mode == ANDROID_FASTBOOT_MODE) { strcpy(misc_message->command, "bootloader"); } //最终统一判断命令 if(!loglel_change_flag) //add by young,if you want to enter debug_mode ,so do enter boot_normal { if(!strcmp(misc_message->command, "efex")) { /* there is a recovery command */ puts("find efex cmd\n"); sunxi_flash_write(misc_offset, 2048/512, misc_fill); sunxi_board_run_fel(); return 0; } if(!strcmp(misc_message->command, "boot-resignature")) { puts("find boot-resignature cmd\n"); sunxi_flash_write(misc_offset, 2048/512, misc_fill); sunxi_oem_op_lock(SUNXI_LOCKING, NULL, 1); } else if(!strcmp(misc_message->command, "boot-recovery")) { if(!strcmp(misc_message->recovery, "sysrecovery")) { puts("recovery detected, will sprite recovery\n"); strncpy(boot_commond, "sprite_recovery", sizeof("sprite_recovery")); sunxi_flash_write(misc_offset, 2048/512, misc_fill); } else { puts("Recovery detected, will boot recovery\n"); sunxi_str_replace(boot_commond, "boot_normal", "boot_recovery"); } /* android recovery will clean the misc */ } else if(!strcmp(misc_message->command, "bootloader")) { puts("Fastboot detected, will boot fastboot\n"); sunxi_str_replace(boot_commond, "boot_normal", "boot_fastboot"); if(misc_offset) sunxi_flash_write(misc_offset, 2048/512, misc_fill); } else if(!strcmp(misc_message->command, "usb-recovery")) { puts("Recovery detected, will usb recovery\n"); sunxi_str_replace(boot_commond, "boot_normal", "boot_recovery"); } } if(!strcmp(misc_message->command ,"debug_mode")) { puts("debug_mode detected ,will enter debug_mode"); if(!change_to_debug_mode()) { check_debug_mode(); } sunxi_flash_write(misc_offset,2048/512,misc_fill); } setenv("bootcmd", boot_commond); printf("to be run cmd=%s\n", boot_commond); return 0; }
int check_update_key(void) { int ret; int fel_key_max; int power_plug_count = 0; int new_power_status = 0; int old_power_status = 0; int time_tick = 0 ; int fel_key_mode = 0; int user_mode_used = 0; gd->key_pressd_value = 0; if(uboot_spare_head.boot_data.work_mode != WORK_MODE_BOOT) { return 0; } old_power_status = axp_probe_power_source(); sunxi_key_init(); //detect user_mode exist script_parser_fetch("platform", "user_mode_used", &user_mode_used, 1); if(user_mode_used) { printf("user_mode found\n"); fel_key_mode = 2; } //detect fel_key exist else { ret = script_parser_fetch("fel_key", "fel_key_max", &fel_key_max, 1); if(ret) { printf("fel key old mode\n"); fel_key_mode = 1; } else { printf("fel key new mode\n"); } } printf("run key detect\n"); sunxi_key_read(); __msdelay(10); if(!fel_key_mode) { int key_value; int fel_key_max, fel_key_min; time_tick = 0; key_value = sunxi_key_read(); //读取按键信息 if(key_value < 0) //没有按键按下 { printf("no key found\n"); return 0; } gd->key_pressd_value = key_value; ret = script_parser_fetch("fel_key", "fel_key_max", &fel_key_max, 1); if(ret) { printf("fel key max not found\n"); return 0; } ret = script_parser_fetch("fel_key", "fel_key_min", &fel_key_min, 1); if(ret) { printf("fel key min not found\n"); return 0; } if((key_value <= fel_key_max) && (key_value >= fel_key_min)) { printf("fel key detected\n"); return 1; } printf("fel key value %d is not in the range from %d to %d\n", key_value, fel_key_min, fel_key_max); //old_usb_plug_status = usb_probe_vbus_type(); //add by guoyingyang while(sunxi_key_read() > 0) //press key and not loosen { time_tick++; new_power_status = axp_probe_power_source(); __msdelay(KEY_DELAY_EACH_TIME); if(new_power_status != old_power_status) { power_plug_count++; old_power_status = new_power_status; } if(power_plug_count == 3) { change_to_debug_mode(); break; } if(time_tick > KEY_MAX_COUNT_GO_ON) { printf("time out\n"); break; } } return 0; } else if(fel_key_mode == 1) { int count; int value_old, value_new, value_cnt; int new_key, new_key_flag; time_tick = 0; count = 0; value_cnt = 0; new_key = 0; new_key_flag = 0; ret = sunxi_key_read(); //读取按键信息 if(ret < 0) //没有按键按下 { printf("no key found\n"); return 0; } else { value_old = ret; } gd->key_pressd_value = ret; while(1) { time_tick ++; ret = axp_probe_key(); //获取power按键信息 new_power_status = axp_probe_power_source(); //detect vbus status printf("new_power_status = %d \n",new_power_status); if(ret > 0) //检测到POWER按键按下 { count ++; } if(new_power_status != old_power_status) { debug("=======flag change========\n"); power_plug_count ++; old_power_status = new_power_status; } __msdelay(KEY_DELAY_EACH_TIME); ret = sunxi_key_read(); //读取按键信息 if(ret < 0) //没有按键按下 { printf("key not pressed anymore\n"); if(count == 1) { if(new_key >= 2) { printf("1\n"); printf("force to debug mode\n"); return -1; } } return 0; } else { value_new = ret; if(value_old == value_new) { value_cnt ++; if(new_key_flag == 1) { new_key ++; new_key_flag ++; } else if(!new_key_flag) { new_key_flag ++; } } else { new_key_flag = 0; value_old = value_new; } } if(count == 3) { printf("you can unclench the key to update now\n"); return -1; } if((!count) && (power_plug_count == 3)) { change_to_debug_mode(); return 0; } if((!count) && (time_tick >= KEY_MAX_COUNT_GO_ON)) { printf("timeout, but no power key found\n"); return 0; } } } else { int user_key_value; user_key_value = sunxi_key_read(); //读取按键信息 if(user_key_value < 0) //没有按键按下 { printf("no user_key found\n"); } else { gd->key_pressd_value = user_key_value; } return 0; } }
int check_android_misc(void) { int mode; int pmu_value; u32 misc_offset = 0; char misc_args[2048]; char misc_fill[2048]; char boot_commond[128]; static struct bootloader_message *misc_message; if(uboot_spare_head.boot_data.work_mode != WORK_MODE_BOOT) { return 0; } if(gd->force_shell) { char delaytime[8]; sprintf(delaytime, "%d", 3); setenv("bootdelay", delaytime); } //if enter debug mode,set loglevel = 8 check_debug_mode(); memset(boot_commond, 0x0, 128); strcpy(boot_commond, getenv("bootcmd")); printf("base bootcmd=%s\n", boot_commond); //判断存储介质 if((uboot_spare_head.boot_data.storage_type == 1) || (uboot_spare_head.boot_data.storage_type == 2)) { sunxi_str_replace(boot_commond, "setargs_nand", "setargs_mmc"); printf("bootcmd set setargs_mmc\n"); } else { printf("bootcmd set setargs_nand\n"); } //判断是否存在按键进入其它模式 misc_message = (struct bootloader_message *)misc_args; memset(misc_args, 0x0, 2048); memset(misc_fill, 0xff, 2048); mode = detect_other_boot_mode(); misc_offset = sunxi_partition_get_offset_byname("misc"); //先判断上一次系统是否有写入数据到pmu寄存器 pmu_value = axp_probe_pre_sys_mode(); if(pmu_value == PMU_PRE_FASTBOOT_MODE) { puts("PMU : ready to enter fastboot mode\n"); strcpy(misc_message->command, "bootloader"); } else if(pmu_value == PMU_PRE_RECOVERY_MODE) { puts("PMU : ready to enter recovery mode\n"); strcpy(misc_message->command, "boot-recovery"); } //get the part --"misc" else { debug("misc_offset = %x\n",misc_offset); if(!misc_offset) { printf("no misc partition is found\n"); } else { printf("misc partition found\n"); sunxi_flash_read(misc_offset, 2048/512, misc_args); //read misc partition data } } if((misc_message->command[0] == 0x00) ||(misc_message->command[0] == 0xff)) { printf("misc_message->command = %x \n",misc_message->command[0]); if(mode == USER_SELECT_MODE) //说明探测阶段有按键按下 { printf("enter user_select_mode\n"); #if 0 //如果misc分区没有上次系统写入数据,并且检测到有按键按下,那么进入图片显示菜单 user_select_current_status = FASTBOOT_MODE; show_user_select_menu_ui(); //显示当前模式的ui while(status != POWERON_KEY_PRESSED)//图片显示菜单 { status = sunxi_probe_key_pressed(); if(( status == KEY_PRESSED)) { debug("key_ststus = 0x%x\n ",status); user_mode_status_update(status); //更新菜单的选项 show_user_select_menu_ui(); //显示当前模式的ui } } if(user_select_current_status == RECOVERY_MODE ) { printf("misc_message->command = boot-recovery\n"); strcpy(misc_message->command, "boot-recovery"); } else if(user_select_current_status == FASTBOOT_MODE) { printf("misc_message->command = bootloader\n"); strcpy(misc_message->command, "bootloader"); } #endif } else if(mode == ANDROID_RECOVERY_MODE) { strcpy(misc_message->command, "boot-recovery"); } else if( mode == ANDROID_FASTBOOT_MODE) { strcpy(misc_message->command, "bootloader"); } } //最终统一判断命令 if(!loglel_change_flag) //add by young,if you want to enter debug_mode ,so do enter boot_normal { if(!strcmp(misc_message->command, "efex")) { /* there is a recovery command */ puts("find efex cmd\n"); sunxi_flash_write(misc_offset, 2048/512, misc_fill); sunxi_board_run_fel(); return 0; } if(!strcmp(misc_message->command, "boot-resignature")) { puts("find boot-resignature cmd\n"); sunxi_flash_write(misc_offset, 2048/512, misc_fill); sunxi_oem_op_lock(SUNXI_LOCKING, NULL, 1); } else if(!strcmp(misc_message->command, "boot-recovery")) { puts("Recovery detected, will boot recovery\n"); sunxi_str_replace(boot_commond, "boot_normal", "boot_recovery"); /* android recovery will clean the misc */ } else if(!strcmp(misc_message->command, "bootloader")) { puts("Fastboot detected, will boot fastboot\n"); sunxi_str_replace(boot_commond, "boot_normal", "boot_fastboot"); if(misc_offset) sunxi_flash_write(misc_offset, 2048/512, misc_fill); } else if(!strcmp(misc_message->command, "usb-recovery")) { puts("Recovery detected, will usb recovery\n"); sunxi_str_replace(boot_commond, "boot_normal", "boot_recovery"); } } if(!strcmp(misc_message->command ,"debug_mode")) { puts("debug_mode detected ,will enter debug_mode"); if(!change_to_debug_mode()) { check_debug_mode(); } sunxi_flash_write(misc_offset,2048/512,misc_fill); } setenv("bootcmd", boot_commond); printf("to be run cmd=%s\n", boot_commond); #if 0 misc_message = (struct bootloader_message *)misc_args; if(mode == ANDROID_NULL_MODE) { misc_offset = sunxi_partition_get_offset_byname("misc"); if(!misc_offset) { int pmu_value; puts("no misc partition is found\n"); pmu_value = axp_probe_pre_sys_mode(); if(pmu_value == PMU_PRE_FASTBOOT_MODE) { puts("ready to enter fastboot mode\n"); setenv("bootcmd", "run boot_fastboot"); return 0; } else { printf("to be run cmd=%s\n", boot_commond); setenv("bootcmd", boot_commond); return 0; } } memset(misc_fill, 0xff, 2048); #ifdef DEBUG tick_printf("misc_offset : %d\n", (int )misc_offset); #endif sunxi_flash_read(misc_offset, 2048/512, misc_args); } else if(mode == ANDROID_RECOVERY_MODE) { strcpy(misc_message->command, "boot-recovery"); } else if(mode == ANDROID_FASTBOOT_MODE) { strcpy(misc_message->command, "bootloader"); } #ifdef DEBUG { uint *dump_value; dump_value = *(uint *)misc_message->command; if(dump_value != 0xffffffff) printf("misc.command : %s\n", misc_message->command); else printf("misc.command : NULL\n"); dump_value = *(uint *)misc_message->status; if(dump_value != 0xffffffff) printf("misc.status : %s\n", misc_message->status); else printf("misc.status : NULL\n"); dump_value = *(uint *)misc_message->recovery; if(dump_value != 0xffffffff) printf("misc.recovery : %s\n", misc_message->recovery); else printf("misc.recovery : NULL\n"); } #endif //判断命令 if(!strcmp(misc_message->command, "efex")) { /* there is a recovery command */ puts("find efex cmd\n"); sunxi_flash_write(misc_offset, 2048/512, misc_fill); sunxi_board_run_fel(); return 0; } if(!strcmp(misc_message->command, "boot-resignature")) { puts("find boot-resignature cmd\n"); sunxi_flash_write(misc_offset, 2048/512, misc_fill); sunxi_oem_op_lock(SUNXI_LOCKING, NULL, 1); } else if(!strcmp(misc_message->command, "boot-recovery")) { puts("Recovery detected, will boot recovery\n"); sunxi_str_replace(boot_commond, "boot_normal", "boot_recovery"); /* android recovery will clean the misc */ } else if(!strcmp(misc_message->command, "bootloader")) { puts("Fastboot detected, will boot fastboot\n"); sunxi_str_replace(boot_commond, "boot_normal", "boot_fastboot"); if(misc_offset) sunxi_flash_write(misc_offset, 2048/512, misc_fill); } setenv("bootcmd", boot_commond); printf("to be run cmd=%s\n", boot_commond); #endif return 0; }