Example #1
0
void keypress_test(void)
{
  /*following is test code to test ADC & key pad*/
  int i;
	int count = sizeof(g_key_K1_info)/sizeof(struct adckey_info);
	int nKeyVal = 0;
	int nCnt = 0;
  printf("waiting for keypress test..\npress key \'sw3\' 3 times please...\n");
	saradc_enable();	
	while(nCnt < 3)
	{
		udelay(KEY_DELAY_US);
		nKeyVal = get_adc_sample(4);
		if(nKeyVal > 1000)
			continue;
		for(i = 0; i < count; i++){
			int v = g_key_K1_info[i].value;
			if(nKeyVal >= v && nKeyVal <= (v + g_key_K1_info[i].tolerance)){
				printf("key:%s pressed.\n",g_key_K1_info[i].key);
				break;
			}
		}
		if(i >= count)
			printf("unknown key pressed. keyvalue=%d\n",nKeyVal);
		nCnt++;
		for(i = 0; i < 100; i++)
			udelay(KEY_DELAY_US);
	}
	saradc_disable();
}
Example #2
0
/*following is test code to test ADC & key pad*/
static int do_adc(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	if(argc > 2)
		goto usage;
	
	u32 nDelay = 0xffff;
	int nKeyVal = 0;
	int nCnt = 0;
	char *endp;
	int nMaxCnt;
	int adc_chan = 0; //m8 adc channel 0;m6 adc channel 4
	if(2 == argc)
		nMaxCnt	= simple_strtoul(argv[1], &endp, 10);
	else
		nMaxCnt = 10;

	saradc_enable();
	while(nCnt < nMaxCnt)
	{
		udelay(nDelay);
		nKeyVal = get_adc_sample(adc_chan);
		if(nKeyVal > 1021)
			continue;
		
		printf("SARADC CH-4 Get key : %d [%d]\n", nKeyVal,(100*nKeyVal)/1024);
		nCnt++;
	}
	saradc_disable();

	return 0;
	
usage:
	return cmd_usage(cmdtp);
}
int switch_boot_mode(void)
{
    saradc_enable();
    run_command ("bl off", 1);
    if(get_source_key())
        aml_autoscript();
    switch(reboot_mode)
    {
    case AMLOGIC_NORMAL_BOOT:
    {
        printf("AMLOGIC_NORMAL_BOOT...\n");
        run_command ("osd open 24 1376 768 1;nand info; nand read ${loadaddr} ${logoaddr} ${logosize}; bmp display ${loadaddr} 0 0", 0);
        run_command ("bl on", 1);
        return  1;
    }
    case AMLOGIC_FACTORY_RESET_REBOOT:
    {
        printf("AMLOGIC_FACTORY_RESET_REBOOT...\n");
        run_command ("osd open 24 1376 768 1;nand info; nand read ${loadaddr} ${logoaddr} ${logosize}; bmp display ${loadaddr} 0 0", 0);
        run_command ("bl on", 1);
        run_command("run recoveryboot", 0);
        break;
    }
    case AMLOGIC_UPDATE_REBOOT:
    {
        printf("AMLOGIC_UPDATE_REBOOT...\n");
        run_command ("osd open 24 1376 768 1;nand info; nand read ${loadaddr} ${logoaddr} ${logosize}; bmp display ${loadaddr} 0 0", 0);
        run_command ("bl on", 1);
        run_command("run recoveryboot", 0);
        break;
    }
    default:
    {
        printf("default boot......\n");
        unsigned long standby = simple_strtoul (getenv ("factory_standby"), NULL, 16);
        if(standby == 1) {
            printf("reset uboot for entering standby\n");
            reboot_mode = AMLOGIC_COOL_REBOOT;
            run_command("reset", 0);
        }
        else
        {
            run_command ("osd open 24 1376 768 1;nand info; nand read ${loadaddr} ${logoaddr} ${logosize}; bmp display ${loadaddr} 0 0", 0);
            run_command ("bl on", 1);
        }
        break;
    }
    }
}
int switch_boot_mode(void)
{
    unsigned long hold_time = 50000, polling_time = 10000, tmp;

    printf("ENTER U-BOOT SWITCH MODE !!!!\n");

    saradc_enable();

    //added by pengtj for added fool idle
    get_key();
    get_key();
    #ifdef ADD_FOR_MBX_C03
    set_power_pin();
    #endif

    while(hold_time > 0)
    {
        udelay(polling_time);
        tmp = get_key();
        printf("get_key(): %d\n", tmp);
        if(!tmp)  break;
        hold_time -= polling_time;
    }

	logo_display();
    if (reboot_mode == AMLOGIC_FACTORY_RESET_REBOOT )
    {
    	  printf("Recovery Start from upgrade apk...\n");
	#ifdef CONFIG_UPGRADE
		into_recovery();
	#else
        run_command ("run recoveryboot", 0);
	#endif
        hang();

    }
    else if(hold_time > 0)
    {
        printf("Normal Start...\n");
#ifdef POWER_KEY_LEAD_START_UP
       int temp=0;
	int bootdelay=0;
	printf("Please input power key ! \n ");
	gpio_direction_input(INPUT_KEY_VALUE);
	printf("\b\b\b\0");
	while(1)
	{
	       temp=gpio_get_value(INPUT_KEY_VALUE);
		if(temp<1)
			break;
	       udelay(10000);
	};
    #endif
        return  1;
    }
    else
    {
       	printf("Recovery Start...\n");
       	//aml_autoscript();
	#ifdef CONFIG_UPGRADE
		into_recovery();
	#else
        run_command ("run recoveryboot", 0);
	#endif
        hang();
    }
}
Example #5
0
int switch_boot_mode(void)
{
 //   unsigned long hold_time = 50000, polling_time = 10000, tmp;
    unsigned long upgrade_step;
	int ret=0;
	act8942_init(&act8942_pdata);
	//act8942_dump();
	
	upgrade_step = simple_strtoul (getenv ("upgrade_step"), NULL, 16);
	printf("upgrade_step = %d\n", upgrade_step);
	
	saradc_enable();
	
#ifdef ENABLE_FONT_RESOURCE
	RegisterFont(DEFAULT_FONT);
#endif
	ret=isVolAKeyPress();
	if(ret==1)
		aml_autoscript();
	
	powerkey_hold(0);
#ifdef CONFIG_AML_TINY_USBTOOL
	usb_boot(1);
#endif
	
	if(upgrade_step == 2)
	{
		switch(reboot_mode)
		{
			case AMLOGIC_NORMAL_BOOT:
			{
				ret=keypress_to_upgrade();
				if(ret==0)
					return 0;
				printf("AMLOGIC_NORMAL_BOOT...\n");
				power_up();
				logo_display();
				return	1;
			}
			case AMLOGIC_FACTORY_RESET_REBOOT:
			{
				printf("AMLOGIC_FACTORY_RESET_REBOOT...\n");
				power_up();
				logo_display();
				run_command ("nand read ${recovery_name} ${loadaddr} 0 ${recovery_size}", 0);
				run_command ("bootm", 0);
				break;
			}
			case AMLOGIC_UPDATE_REBOOT:
			{
				printf("AMLOGIC_UPDATE_REBOOT...\n");
				power_up();
				logo_display();
				run_command ("set upgrade_step 0", 0);
				run_command ("save", 0);
				upgrade_step = 0;
				break;
			}
			default:
			{
				printf("AMLOGIC_CHARGING_REBOOT...\n");
				if(is_ac_connected)
				{
					power_up();
#ifdef CONFIG_BATTERY_CHARGING
					//battery_charging();
#endif
					logo_display();
				}
				else
				{
					powerkey_hold(0);
#ifdef CONFIG_BATTERY_CHARGING
					if(get_powerkey_hold_count())
					{
						  logo_display();
						if(get_battery_percentage() < 10)
						{
							power_low_display();
							sdelay(2);
							power_down();
							printf("Low Power!!!\nPower Down!\n");
							hang();
						}
#else
					if(powerkey_hold(1000))
					{
#endif
						logo_display();
						power_up();
						printf("Power Up!\n");
					}
					else
					{
						power_down();
						printf("Power Down!\n");
						hang();
					}
				}
				break;
			}
		}
	}
	else
	{
		power_up();
		printf("Upgrade step %d...\n", upgrade_step);
	}

	if(upgrade_step == 0)
	{
#ifdef CONFIG_AML_TINY_USBTOOL
		usb_boot(1);
#endif

		display_messge("upgrade step 1! Don't Power Off!");
		if(upgrade_bootloader())
		{
			run_command ("set upgrade_step 1", 0);
			run_command ("save", 0);
			run_command ("reset", 0);
			hang();
		}
		else
		{
			printf("### ERROR:	u-boot write failed!!!\n");
			return	-1;
		}
	}
	else if(upgrade_step == 1)
	{
		display_messge("upgrade step 2! Don't Power Off!");
		run_command ("defenv", 0);
		run_command ("set upgrade_step 2", 0);
		run_command ("save", 0);
		
		into_recovery();
	}


	//added by Elvis for added fool idle
	/*get_key();
	get_key();
	
	while(hold_time > 0)
	{
		udelay(polling_time);
		tmp = get_key();
		printf("get_key(): %d\n", tmp);
		if(!tmp)  break;
		hold_time -= polling_time;
	}

	if(hold_time > 0)
	{
		printf("Normal Start...\n");
		return	1;
	}
	else
	{
		display_messge("upgrading... please wait");
		if(upgrade_bootloader())
		{
			run_command ("set upgrade_step 1", 0);
			run_command ("save", 0);
			run_command ("reset", 0);
			hang();
		}
		run_command ("set upgrade_step 2", 0);
		run_command ("save", 0);
		into_recovery();
	}

*/
		ret=keypress_to_upgrade();
		return ret;

//return	0;
}
int switch_boot_mode(void)
{
    unsigned long hold_time = 50000, polling_time = 10000, tmp;
    unsigned long upgrade_step;

    upgrade_step = simple_strtoul (getenv ("upgrade_step"), NULL, 16);
    printf("upgrade_step = %d    !!!!!!!!!!!!!!!!!!\n", upgrade_step);

    saradc_enable();

#ifdef	CONFIG_UBI_SUPPORT
    powerkey_hold(0);
    run_command ("ubi part system", 0);
    powerkey_hold(0);
    run_command ("ubifsmount system", 0);
    //run_command ("ubifsls", 0);
#endif

    if(upgrade_step == 3)
    {
        switch(reboot_mode)
        {
            case AMLOGIC_NORMAL_BOOT:
            {
                printf("AMLOGIC_NORMAL_BOOT...\n");
                power_hold();
		//green led on red led off
		green_powerkey_led_on();
		red_powerkey_led_off();
		SET_MPEG_REG_MASK(VPP_MISC, VPP_POST_FG_OSD2 | VPP_PRE_FG_OSD2);
                logo_display();
                return  1;
            }
            case AMLOGIC_FACTORY_RESET_REBOOT:
            {
                printf("AMLOGIC_FACTORY_RESET_REBOOT...\n");
                power_hold();
		//green led on red led off
		green_powerkey_led_on();
		red_powerkey_led_off();
		SET_MPEG_REG_MASK(VPP_MISC, VPP_POST_FG_OSD2 | VPP_PRE_FG_OSD2);
                logo_display();
                run_command ("nand read ${recovery_name} ${loadaddr} 0 ${recovery_size}", 0);
				run_command ("bootm", 0);
                break;
            }
            case AMLOGIC_UPDATE_REBOOT:
            {
                printf("AMLOGIC_UPDATE_REBOOT...\n");
                power_hold();
		//green led on red led off
		green_powerkey_led_on();
		red_powerkey_led_off();
		SET_MPEG_REG_MASK(VPP_MISC, VPP_POST_FG_OSD2 | VPP_PRE_FG_OSD2);
                logo_display();
                run_command ("set upgrade_step 0", 0);
                run_command ("save", 0);
                upgrade_step = 0;
                break;
            }
	    case AMLOGIC_CHARGING_REBOOT:
	    {
                printf("AMLOGIC_POWERDOWN... \n");
                if(is_ac_connected)
                { 
                    power_unhold();
		    hang();
                }
	    	}
            default:
            {
                printf("Default.... \n");
                if(is_ac_connected)
                { 
                    power_hold();
#ifdef CONFIG_BATTERY_CHARGING
			battery_charging();
#endif
                }
                else
                {
                    powerkey_hold(0);
                    if(get_powerkey_hold_count())
                    {
#ifdef CONFIG_BATTERY_CHARGING
                        if(get_battery_percentage() < 10)
                        {
                            power_low_display();
                            sdelay(2);
                            power_unhold();
                            printf("Low Power!!!\nPower Down!\n");
                            hang();
                        }
#endif
                        power_hold();
                        printf("Power Up!\n");
                    }
                    else
                    {
                        power_unhold();
                        printf("Power Down!\n");
                        hang();
                    }
                }
		//green led on red led off
		green_powerkey_led_on();
		red_powerkey_led_off();
		SET_MPEG_REG_MASK(VPP_MISC, VPP_POST_FG_OSD2 | VPP_PRE_FG_OSD2);


                logo_display();
                break;
            }
        }
    }
    else
    {
        power_hold();
        printf("Upgrade step %d...\n", upgrade_step);

	green_powerkey_led_on();
	red_powerkey_led_off();
	SET_MPEG_REG_MASK(VPP_MISC, VPP_POST_FG_OSD2 | VPP_PRE_FG_OSD2);
        logo_display();
    }

    if(upgrade_step == 0)
    {
        if(upgrade_bootloader())
        {
            run_command ("set upgrade_step 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        else
        {
            printf("### ERROR:  u-boot write failed!!!\n");
            return  -1;
        }
    }
    else if((upgrade_step >0) && (upgrade_step < 3))
    {
        if(upgrade_step == 1)
        {
            if(upgrade_env())
            {
                run_command ("set upgrade_step 2", 0);
                run_command ("save", 0);
                run_command ("reset", 0);
                hang();
            }
            else
            {
                run_command ("defenv", 0);
                run_command ("save", 0);
            }
        }
        run_command ("set upgrade_step 3", 0);
        run_command ("save", 0);
        //upgrade_partition();
        into_recovery();
    }

    //added by Elvis for added fool idle
    get_key();
    get_key();
    
    while(hold_time > 0)
    {
        udelay(polling_time);
        tmp = get_key();
        printf("get_key(): %d\n", tmp);
        if(!tmp)  break;
        hold_time -= polling_time;
    }

    if(hold_time > 0)
    {
        aml_autoscript();
        printf("Normal Start...\n");
        return  1;
    }
    else
    {
        if(upgrade_bootloader())
        {
            run_command ("set upgrade_step 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        if(upgrade_env())
        {
            run_command ("set upgrade_step 2", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        run_command ("set upgrade_step 3", 0);
        run_command ("save", 0);
#ifndef	CONFIG_UBI_SUPPORT
        //upgrade_partition();
#endif
        into_recovery();
    }
}
Example #7
0
int switch_boot_mode(void)
{
    unsigned long hold_time = 3000, polling_time = 10000, tmp;
    unsigned long upgrade_step;

    upgrade_step = simple_strtoul (getenv ("upgrade_step"), NULL, 16);
    printf("upgrade_step = %d    !!!!!!!!!!!!!!!!!!\n", upgrade_step);

#ifdef CONFIG_SARADC
    saradc_enable();
#endif

#ifdef ENABLE_FONT_RESOURCE
		RegisterFont(DEFAULT_FONT);
#endif
		//aml_autoscript();
		//logo_display();
		//return 1;

    if(upgrade_step == 3)
    {
		switch(reboot_mode)
        {
            case AMLOGIC_NORMAL_BOOT:
            {
                printf("AMLOGIC_NORMAL_BOOT...\n");
                printf("reboot_mode is %d...\n", reboot_mode);
                power_hold();
                logo_display();
                return  1;
            }
            case AMLOGIC_FACTORY_RESET_REBOOT:
            {
                printf("AMLOGIC_FACTORY_RESET_REBOOT...\n");
                power_hold();
                logo_display();
                run_command ("nand read ${recovery_name} ${loadaddr} 0 ${recovery_size}", 0);
				run_command ("bootm", 0);;
                break;
            }
            case AMLOGIC_UPDATE_REBOOT:
            {
                printf("AMLOGIC_UPDATE_REBOOT...\n");
                power_hold();
                logo_display();
                run_command ("set upgrade_step 0", 0);
                run_command ("save", 0);
                upgrade_step = 0;
                break;
            }
            default:
            {
                printf("Default.... \n");
                power_hold();
                logo_display();
            	break;
            }
        }
    }
    else
    {
        power_hold();
        printf("Upgrade step %d...\n", upgrade_step);
    }

    if(upgrade_step == 0)
    {
        display_messge("upgrade step 1! Don't Power Off!");
		if(upgrade_bootloader())
        {
            run_command ("set upgrade_step 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        else
        {
            printf("### ERROR:  u-boot write failed!!!\n");
            //return  -1;
        }
    }
    else if((upgrade_step >0) && (upgrade_step < 3))
    {
        if(upgrade_step == 1)
        {
            display_messge("upgrade step 2! Don't Power Off!");
            if(upgrade_env())
            {
                run_command ("set upgrade_step 2", 0);
                run_command ("save", 0);
                run_command ("reset", 0);
                hang();
            }
            else
            {
                run_command ("defenv", 0);
                run_command ("save", 0);
            }
        }
		display_messge("upgrade step 3! Don't Power Off!");
        run_command ("set upgrade_step 3", 0);
        run_command ("save", 0);
        //upgrade_partition();
        into_recovery();
    }

	powerkey_hold(0);
    if(!powerkey_hold(hold_time))
    {
    	//aml_autoscript();
    	if(upgrade_step == 0)
    	{
        	logo_display();
	        run_command ("set upgrade_step 3", 0);
	        run_command ("save", 0);
    	}
    	printf("Normal Start...\n");	
    	return 1;
    }
    else
    {
		display_messge("upgrading... please wait");
		if(upgrade_bootloader())
        {
            run_command ("set upgrade_step 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        if(upgrade_env())
        {
            run_command ("set upgrade_step 2", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        run_command ("set upgrade_step 3", 0);
        run_command ("save", 0);
#ifndef	CONFIG_UBI_SUPPORT
        //upgrade_partition();
#endif
        into_recovery();
    }
}
Example #8
0
File: pwr_op.c Project: xtra72/s805
unsigned int g9tv_ref_wakeup(unsigned int flags)
{
    int delay_cnt   = 0;
    int power_status = 1;
    int prev_status;
    int battery_voltage;
    int ret = FLAG_WAKEUP_PWRKEY;
    int low_bat_cnt = 0;

#ifdef CONFIG_IR_REMOTE_WAKEUP
    //backup the remote config (on arm)
    backup_remote_register();
    //set the ir_remote to 32k mode at ARC
    init_custom_trigger();
#endif

#ifdef	CONFIG_SARADC_WAKEUP_FOR_ARC
	saradc_enable();
#endif	



    do {
        if ((flags == 0x87654321) && (!power_status)) {      // suspend from uboot
            ret = FLAG_WAKEUP_PWROFF;
            exit_reason = -1;
            break;
        }


#ifdef CONFIG_IR_REMOTE_WAKEUP
		if(readl(P_AO_RTI_STATUS_REG2) == 0x4853ffff){
			break;
		}
		if(remote_detect_key()){
			exit_reason = 6;
			break;
		}
#endif

#ifdef	CONFIG_SARADC_WAKEUP_FOR_ARC
		if(1 == adc_detect_key()){
			exit_reason = 6;
			break;
		}
#endif	


	    if((readl(P_AO_RTC_ADDR1) >> 12) & 0x1) {
            exit_reason = 7;
			ret = FLAG_WAKEUP_ALARM;
            break;
        }

#ifdef CONFIG_BT_WAKEUP
        if(readl(P_PREG_PAD_GPIO0_I)&(0x1<<16)){
			exit_reason = 8;
            ret = FLAG_WAKEUP_BT;
			break;
		}
#endif
#ifdef CONFIG_WIFI_WAKEUP
			if ((flags != 0x87654321) &&(readl(P_AO_GPIO_O_EN_N)&(0x1<<22)))
			if(readl(P_PREG_PAD_GPIO0_I)&(0x1<<21)){
				exit_reason = 9;
				ret = FLAG_WAKEUP_WIFI;
				break;
			}
#endif

    } while (!(readl(0xc8100088) & (1<<8)));            // power key

	writel(1<<8,0xc810008c);
	writel(gpio_sel0, 0xc8100084);
	writel(gpio_mask,0xc8100080);

#ifdef CONFIG_IR_REMOTE_WAKEUP
	resume_remote_register();
#endif

    return ret;
}
Example #9
0
int switch_boot_mode(void)
{
    unsigned long hold_time = 50000, polling_time = 10000, tmp;
    unsigned long tag;
	#ifdef CONFIG_EFUSE
		char *barg_addr;
		char *r_efus;
		char addr[20];
		char bootargs[384];
	#endif
	
    tag = simple_strtoul (getenv ("tag"), NULL, 16);
    printf("tag = %d    !!!!!!!!!!!!!!!!!!\n", tag);

    if(tag == 3)
    {
        switch(get_kernel_cmd())
        {
            case SYSTEM_REBOOT:
            {
                printf("SYSTEM_REBOOT...\n");
                return  1;
            }
            default:
            {
                printf("NORMAL_BOOT...\n");
                break;
            }
        }
    }
    else
    {
        printf("Upgrade step %d...\n", tag);
    }

    if(tag == 0)
    {
        if(upgrade_bootloader())
        {
            run_command ("set tag 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        else
        {
            printf("### ERROR:  u-boot write failed!!!\n");
            return  -1;
        }
    }
    else if((tag >0) && (tag < 3))
    {
        if(tag == 1)
        {
            if(upgrade_env())
            {
                run_command ("set tag 2", 0);
                run_command ("save", 0);
                run_command ("reset", 0);
                hang();
            }
            else
            {
                run_command ("defenv", 0);
                run_command ("save", 0);
            }
        }
        run_command ("set tag 3", 0);
        
        #ifdef CONFIG_EFUSE
			//r_addr = getenv ("ethaddr");
			if(efuse_chk_written(2)){
				r_efus = efuse_read_usr(2);
				memset(addr,0,sizeof(addr));
				sprintf(addr,"%02x:%02x:%02x:%02x:%02x:%02x",r_efus[0],r_efus[1],r_efus[2],r_efus[3],r_efus[4],r_efus[5]);
				printf("efuse mac is : %s \n", addr);
				//setenv ("ethaddr", addr);
				barg_addr = getenv ("bootargs");
				sprintf(bootargs,"set bootargs '%s mac=%s'",barg_addr,addr);
				run_command (bootargs, 0);
			}
		#endif
        run_command ("save", 0);
        
        upgrade_partition();
        return  1;
    }

    saradc_enable();

    //added by Elvis for added fool idle
    get_key();
    get_key();
    
    while(hold_time > 0)
    {
        udelay(polling_time);
        tmp = get_key();
        printf("get_key(): %d\n", tmp);
        if(!tmp)  break;
        hold_time -= polling_time;
    }

    if(hold_time > 0)
    {
        printf("Normal Start...\n");
        return  1;
    }
    else
    {
        if(upgrade_bootloader())
        {
            run_command ("set tag 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        if(upgrade_env())
        {
            run_command ("set tag 2", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        run_command ("set tag 3", 0);
        run_command ("save", 0);
        upgrade_partition();
    }
}
Example #10
0
int switch_boot_mode(void)
{
    unsigned long hold_time = 50000, polling_time = 10000, tmp;
#ifdef CONFIG_SWITCH_BOOT_MODE
    printf("ENTER U-BOOT SWITCH MODE !!!!\n");
#else
    unsigned long tag;
	#ifdef CONFIG_EFUSE
		char *barg_addr;
		char *r_efus;
		char addr[20];
		char bootargs[384];
	#endif
	
    tag = simple_strtoul (getenv ("tag"), NULL, 16);
    printf("tag = %d    !!!!!!!!!!!!!!!!!!\n", tag);

    if(tag == 3)
    {
        switch(get_kernel_cmd())
        {
            case SYSTEM_REBOOT:
            {
                printf("SYSTEM_REBOOT...\n");
                return  1;
            }
            default:
            {
                printf("NORMAL_BOOT...\n");
                break;
            }
        }
    }
    else
    {
        printf("Upgrade step %d...\n", tag);
    }

    if(tag == 0)
    {
        if(upgrade_bootloader())
        {
            run_command ("set tag 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        else
        {
            printf("### ERROR:  u-boot write failed!!!\n");
            return  -1;
        }
    }
    else if((tag >0) && (tag < 3))
    {
        if(tag == 1)
        {
            if(upgrade_env())
            {
                run_command ("set tag 2", 0);
                run_command ("save", 0);
                run_command ("reset", 0);
                hang();
            }
            else
            {
                run_command ("defenv", 0);
                run_command ("save", 0);
            }
        }
        run_command ("set tag 3", 0);
        
        #ifdef CONFIG_EFUSE
			//r_addr = getenv ("ethaddr");
			if(efuse_chk_written(2)){
				r_efus = efuse_read_usr(2);
				memset(addr,0,sizeof(addr));
				sprintf(addr,"%02x:%02x:%02x:%02x:%02x:%02x",r_efus[0],r_efus[1],r_efus[2],r_efus[3],r_efus[4],r_efus[5]);
				printf("efuse mac is : %s \n", addr);
				//setenv ("ethaddr", addr);
				barg_addr = getenv ("bootargs");
				sprintf(bootargs,"set bootargs '%s mac=%s'",barg_addr,addr);
				run_command (bootargs, 0);
			}
		#endif
        run_command ("save", 0);
        
        upgrade_partition();
        return  1;
    }
#endif
	
		//add by steven for version info
		char verubt[64],verrec[64];
		char *r_verubt,*r_verrec;
		const char* pVer = 0x82000020;
		const unsigned int* pMark = 0x8200005c;
		
		r_verubt = getenv("verubt");
		r_verrec = getenv("verrec");
		sprintf(verubt,"%s(%s.%s)",U_BOOT_VERSION,U_BOOT_DATE,U_BOOT_TIME);
		
		run_command("sf probe 0;sf read 82000000 40000 1000;",0);
		if(*pMark==0xbc690000)
		{
			sprintf(verrec,"%s",pVer);
		}
				
		if(strcmp(r_verubt,verubt) || strcmp(r_verrec,verrec)){
			setenv("verubt",verubt);
			if(*pMark==0xbc690000){
				setenv("verrec",verrec);
			}
			run_command("sav",0);
		}
		//end: add by steven for version info
		
		
#ifdef CONFIG_EFUSE //add by steven for mac in efuse.
		char *barg_addr;
		char *r_efus,*r_emac;
		char addr[20];
		
		r_emac = getenv ("emac");		
		if((efuse_chk_written(2)) && (strcmp(r_emac,"efuse")==0)){
			r_efus = efuse_read_usr(2);
			memset(addr,0,sizeof(addr));
			sprintf(addr,"%02x:%02x:%02x:%02x:%02x:%02x",r_efus[0],r_efus[1],r_efus[2],r_efus[3],r_efus[4],r_efus[5]);
			printf("efuse mac is : %s \n", addr);
			setenv ("ethaddr", addr);
			run_command("sav",0);
		}
#endif
		
    saradc_enable();

    //added by Elvis for added fool idle
    get_key();
    get_key();
    
    while(hold_time > 0)
    {
        udelay(polling_time);
        tmp = get_key();
        printf("get_key(): %d\n", tmp);
        if(!tmp)  break;
        hold_time -= polling_time;
    }

    if(hold_time > 0)
    {
        printf("Normal Start...\n");
        return  1;
    }
    else
    {
#ifdef CONFIG_RECOVERY
       	printf("Recovery Start...\n");
        run_command ("run recoveryboot", 0);
        hang();
#else
        if(upgrade_bootloader())
        {
            run_command ("set tag 1", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        if(upgrade_env())
        {
            run_command ("set tag 2", 0);
            run_command ("save", 0);
            run_command ("reset", 0);
            hang();
        }
        run_command ("set tag 3", 0);
        run_command ("save", 0);
        upgrade_partition();
#endif
    }
}
Example #11
0
static unsigned int detect_key(unsigned int suspend_from)
{
	int exit_reason = 0;
	unsigned int time_out = readl(AO_DEBUG_REG2);
	unsigned time_out_ms = time_out*100;
	unsigned char adc_key_cnt = 0;
	unsigned *irq = (unsigned *)WAKEUP_SRC_IRQ_ADDR_BASE;
	/* unsigned *wakeup_en = (unsigned *)SECURE_TASK_RESPONSE_WAKEUP_EN; */

	/* start timer and enable adc*/
	reset_ao_timera();
	saradc_enable();
	/* setup wakeup resources*/
	/*auto suspend: timerA 10ms resolution*/
	if (time_out_ms != 0)
		wakeup_timer_setup();
	saradc_enable();
	reset_ao_timera();
	init_remote();
#ifdef CONFIG_CEC_WAKEUP
	if (hdmi_cec_func_config & 0x1) {
		remote_cec_hw_reset();
		cec_node_init();
	}
#endif

	/* *wakeup_en = 1;*/
	do {
#ifdef CONFIG_CEC_WAKEUP
		if (irq[IRQ_AO_CEC] == IRQ_AO_CEC_NUM) {
			irq[IRQ_AO_CEC] = 0xFFFFFFFF;
//			if (suspend_from == SYS_POWEROFF)
//				continue;
			if (cec_msg.log_addr) {
				if (hdmi_cec_func_config & 0x1) {
					cec_handler();
					if (cec_msg.cec_power == 0x1) {
						/*cec power key*/
						exit_reason = CEC_WAKEUP;
						break;
					}
				}
			} else if (hdmi_cec_func_config & 0x1)
				cec_node_init();
		}
#endif
		if (irq[IRQ_TIMERA] == IRQ_TIMERA_NUM) {
			irq[IRQ_TIMERA] = 0xFFFFFFFF;
			/*uart_puts("timera ...\n");*/
			if (time_out_ms != 0)
				time_out_ms--;
			if (time_out_ms == 0) {
				wakeup_timer_clear();
				exit_reason = AUTO_WAKEUP;
			}
		}
		if (irq[IRQ_AO_TIMERA] == IRQ_AO_TIMERA_NUM) {
			irq[IRQ_AO_TIMERA] = 0xFFFFFFFF;
			if (check_adc_key_resume()) {
				adc_key_cnt++;
				/*using variable 'adc_key_cnt' to eliminate the dithering of the key*/
				if (2 == adc_key_cnt)
					exit_reason = POWER_KEY_WAKEUP;
			} else {
				adc_key_cnt = 0;
			}
		}
		if (irq[IRQ_AO_IR_DEC] == IRQ_AO_IR_DEC_NUM) {
			irq[IRQ_AO_IR_DEC] = 0xFFFFFFFF;
				if (remote_detect_key())
					exit_reason = REMOTE_WAKEUP;
		}
		if (irq[IRQ_ETH_PHY] == IRQ_ETH_PHY_NUM) {
			irq[IRQ_ETH_PHY] = 0xFFFFFFFF;
			exit_reason = ETH_PHY_WAKEUP;
		}
		if (exit_reason)
			break;
		else
			asm volatile("wfi");
	} while (1);
	restore_ao_timer();
	saradc_disable();
	return exit_reason;
}
Example #12
0
int switch_boot_mode(void)
{
    unsigned long hold_time = 50000, polling_time = 10000, tmp;
    unsigned long upgrade_step;
    
    clrbits_le32(P_PREG_PAD_GPIO2_EN_N, (1<<25));     // VCC5V_EN GPIOD_9
    setbits_le32(P_PREG_PAD_GPIO2_O, (1<<25));

	get_osd_size();
	
#ifdef CONFIG_PMU_ACT8942
	act8942_init(&act8942_pdata);
	//act8942_dump();
#endif

	upgrade_step = simple_strtoul (getenv ("upgrade_step"), NULL, 16);
	printf("upgrade_step = %d\n", upgrade_step);
	
	saradc_enable();
	
#ifdef ENABLE_FONT_RESOURCE
	RegisterFont(DEFAULT_FONT);
#endif
	aml_autoscript();
	powerkey_hold(0);
	u32 reboot_mode_current = reboot_mode;//cvt
    reboot_mode_clear();//cvt
#ifdef	CONFIG_AML_TINY_USBTOOL		//cvt
extern int usb_boot(int clk_cfg, int time_out);
	if((reboot_mode_current == MESON_USB_BURNER_REBOOT) || get_burner_key())
	{
		usb_boot(1, 200000);
	}
#endif

	if(upgrade_step == 2)
	{
		switch(reboot_mode_current)
		{
			case AMLOGIC_NORMAL_BOOT:
			{
				printf("AMLOGIC_NORMAL_BOOT...\n");
				power_up();
				logo_display();
				return	1;
			}
			case AMLOGIC_FACTORY_RESET_REBOOT:
			{
				printf("AMLOGIC_FACTORY_RESET_REBOOT...\n");
				power_up();
				logo_display();
				run_command ("nand read ${recovery_name} ${loadaddr} 0 ${recovery_size}", 0);
				run_command ("bootm", 0);
				break;
			}
			case AMLOGIC_UPDATE_REBOOT:
			{
				printf("AMLOGIC_UPDATE_REBOOT...\n");
				power_up();
				logo_display();
				run_command ("set upgrade_step 0", 0);
				run_command ("save", 0);
				upgrade_step = 0;
				break;
			}
			default:
			{
				printf("AMLOGIC_CHARGING_REBOOT...\n");
				if(is_ac_connected)
				{
					power_up();
#ifdef CONFIG_BATTERY_CHARGING
					battery_charging();
#endif
					logo_display();
				}
				else
				{
					powerkey_hold(0);
#ifdef CONFIG_BATTERY_CHARGING
					if(get_powerkey_hold_count())
					{
						  logo_display();
						if(get_battery_percentage() < 10)
						{
							power_low_display();
							sdelay(2);
							power_down();
							printf("Low Power!!!\nPower Down!\n");
							hang();
						}
						logo_display();
						power_up();
						printf("Power Up!\n");
					}
#else
					if(powerkey_hold(1000))
					{
						logo_display();
						power_up();
						printf("Power Up!\n");
					}
#endif
					else
					{
						power_down();
						printf("Power Down!\n");
						hang();
					}
				}
				break;
			}
		}
	}
	else
	{
		power_up();
		printf("Upgrade step %d...\n", upgrade_step);
	}

	if(upgrade_step == 0)
	{
		display_messge("upgrade step 1! Don't Power Off!");
		if(upgrade_bootloader())
		{
			run_command ("set upgrade_step 1", 0);
			run_command ("save", 0);
			run_command ("reset", 0);
			hang();
		}
		else
		{
			printf("### ERROR:	u-boot write failed!!!\n");
			return	-1;
		}
	}
	else if(upgrade_step == 1)
	{
		display_messge("upgrade step 2! Don't Power Off!");
		run_command ("set upgrade_step 2", 0);
		run_command ("save", 0);
		into_recovery();
	}


	//added by Elvis for added fool idle
	get_key();
	get_key();
	
	while(hold_time > 0)
	{
		udelay(polling_time);
		tmp = get_key();
		printf("get_key(): %d\n", tmp);
		if(!tmp)  break;
		hold_time -= polling_time;
	}

	if(hold_time > 0)
	{
		printf("Normal Start...\n");
		
		char *recovery_command;
		recovery_command = getenv("recovery_command");
		if (strcmp(recovery_command, "--usb_burning") == 0){
				run_command ("set recovery_command", 0);
		}	
		
		run_command ("save", 0);
		return	1;
	}
	else
	{
		display_messge("upgrading... please wait");
		if(upgrade_bootloader())
		{
			run_command ("set upgrade_step 1", 0);
			run_command ("save", 0);
			run_command ("reset", 0);
			hang();
		}
		run_command ("set upgrade_step 2", 0);
		run_command ("save", 0);
		into_recovery();
	}


return	0;
}