Exemple #1
0
static int error_handler(u32 boot_mode)
{
	DBG("error_handler\n");

	if (ctl_num == 1)
		return usb_boot();

	if (retry_times) {
		retry_times--;

		switch(boot_mode)
		{
		case SD_BOOT:
			sd_boot(0);
			break;
		case EMMC_BOOT:
			emmc_boot();
			break;
		}
		return 0;
	}else {
		retry_times = 1;
		return sd_boot(1);
	}
}
int main(int argc, char **argv)
{
	void *data;
	unsigned sz;
	struct stat s;
	int fd;
	int ret;
	struct libusb_context       *ctx = NULL;
	struct libusb_device_handle *usb = NULL;

	if (argc != 3) {
		printf("usage: %s <xloader> <rootfs>\n", argv[0]);
		return 0;
	}
	argv++;
	fd = open(argv[0], O_RDONLY);
	if (fd < 0 || fstat(fd, &s)) {
		printf("cannot open '%s'\n", argv[0]);
		return -1;
	}
	data = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
	if (data == MAP_FAILED) {
		printf("cannot mmap '%s'\n", argv[0]);
		return -1;
	}
	sz = s.st_size;
	close(fd);
	argv++;
	if (libusb_init(&ctx)) {
		printf("cannot initialize libusb\n");
		return -1;
	}
	printf(HFORMAT, HOST_FORMAT);
	printf("waiting for OMAP44xx device...\n");
	while (1) {
		if (!usb)
			usb = libusb_open_device_with_vid_pid(
				ctx, 0x0451, 0xD010);
		if (!usb)
			usb = libusb_open_device_with_vid_pid(
				ctx, 0x0451, 0xD00F);
		if (usb) {
			libusb_detach_kernel_driver(usb, 0);
			ret = libusb_set_configuration(usb, 1);
			if (ret)
				break;
			ret = libusb_claim_interface(usb, 0);
			if (ret)
				break;
			ret = usb_boot(usb, data, sz, argv[0]);
			break;
		}
		usleep(250000);
	}
	libusb_release_interface(usb, 0);
	libusb_close(usb);
	libusb_exit(ctx);
	return ret;
}
Exemple #3
0
int main(int argc, char **argv)
{
	void *data, *data2;
	unsigned sz, sz2;
	usb_handle *usb;
	int once = 1;

	if (argc < 2) {
		fprintf(stderr,"usage: usbboot [ <2ndstage> ] <image>\n");
		return 0;
	}

	if (argc < 3) {
		fprintf(stderr,"using built-in 2ndstage.bin\n");
		data = aboot_data;
		sz = aboot_size;
	} else {
		data = load_file(argv[1], &sz);
		if (data == 0) {
			fprintf(stderr,"cannot load '%s'\n", argv[1]);
			return -1;
		}
		argc--;
		argv++;
	}
	
	data2 = load_file(argv[1], &sz2);
	if (data2 == 0) {
		fprintf(stderr,"cannot load '%s'\n", argv[1]);
		return -1;
	}

	for (;;) {
		usb = usb_open(match_omap4_bootloader);
		if (usb)
			return usb_boot(usb, data, sz, data2, sz2);
		if (once) {
			once = 0;
			fprintf(stderr,"waiting for OMAP44xx device...\n");
		}
		usleep(250);
	}
	
	return -1;    
}
Exemple #4
0
int main(int argc, char **argv)
{
	void *data;
	unsigned sz;
	struct stat s;
	int fd;
	struct usb_handle *usb;
	int once;

	if (argc != 3) {
		printf("usage: %s <xloader> <rootfs>\n", argv[0]);
		return 0;
	}
	argv++;
	fd = open(argv[0], O_RDONLY);
	if (fd < 0 || fstat(fd, &s)) {
		printf("cannot open '%s'\n", argv[0]);
		return -1;
	}
	data = mmap(NULL, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
	if (data == MAP_FAILED) {
		printf("cannot mmap '%s'\n", argv[0]);
		return -1;
	}
	sz = s.st_size;
	close(fd);
	argv++;
	printf(HFORMAT, HOST_FORMAT);
	for (once = 1;;) {
		usb = usb_open(match_omap4_bootloader);
		if (usb)
			return usb_boot(usb, data, sz, argv[0]);
		if (once) {
			once = 0;
			printf("waiting for OMAP44xx device...\n");
		}
		usleep(250000);
	}
	return -1;
}
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;
}
Exemple #6
0
int main(int argc, char **argv)
{
	usb_handle usb;
	int once = 1, i;
	int r;
	struct usb_load_chunk chunks[USBBOOT_MAX_CHUNKS], *current;
	char *p;
	char *aboot_cmdline = "--aboot=";
	int aboot_cmdline_sz = strlen(aboot_cmdline);

	memset(chunks, 0, sizeof(chunks));

	chunks[ 0 ].data = aboot_data;
	chunks[ 0 ].size = aboot_size;

	if (argc < 2) {
		fprintf(stderr,"usage: usbboot [ <2ndstage> ] <image>\n");
		return 0;
	}

	for (i = 1, current = chunks + 1;
	     i < argc && current - chunks < USBBOOT_MAX_CHUNKS;
	     i ++) {

		/* check if argument is 2nd stage bootloader name */
		if (strcmp(argv[i], "-a") == 0) {
			chunks[0].data = load_file(argv[i + 1], &chunks[0].size);
			i++;
			if (chunks[0].data == NULL)
				break;
			continue;
		}

		if (strncmp(argv[i], aboot_cmdline, aboot_cmdline_sz) == 0) {
			chunks[0].data = load_file(argv[i] + aboot_cmdline_sz, &chunks[0].size);
			if (chunks[0].data == NULL)
				break;
			continue;
		}
			
		p = strchr(argv[i], '=');
		if (p == NULL)
			p = strchr(argv[i], ':');
		if (p == NULL) {
			current->address = 0x82000000;
			fprintf(stderr, "Warning: using %x for '%s'\n", current->address, argv[i]);
			p = argv[i];
		}
		else {
			*p = '\0';
			current->address = strtoul(argv[i], NULL, 0);
			p++;	/* skip the ':' or '=' */
		}
		current->data = load_file(p, &current->size);
		if (current->data == NULL)
			break;
		current ++;
	}

	r = linux_usb_init();
	CHECK_ERROR(r);

	for (i = 0; i < USBBOOT_MAX_CHUNKS; i ++) {
		if (i && !chunks[i].address)
			break;
		printf("Chunk %d:\n", i);
		printf("\taddress = 0x%08X\n", chunks[i].address);
		printf("\tdata    = %p\n", chunks[i].data);
		printf("\tsize    = %d\n", chunks[i].size);
	}

	for (;;) {
		r = linux_usb_open(0x0451, 0xd010, &usb);
		if (r == 0 && usb) {
			r = usb_boot(usb, chunks);
			linux_usb_close(usb);
			break;
		}
		if (once) {
			once = 0;
			fprintf(stderr,"waiting for OMAP44xx device...\n");
		}
		usleep(250);
	}

	linux_usb_fini();

	return r;    
}
Exemple #7
0
int sd_boot(num)
{
	u8 *resp;
	u32 ret = 0;
	u32 clk_set = 0, clkrt = 0;

	DBG("sd_boot\n");

	current_boot = SD_BOOT;
	ctl_num = num;

	if (ctl_num == 1)
		REG_CPM_CLKGR &= ~(1 << 11);

	sd_init();
	clk_set = jz_extal / 2;
	while (200000 < clk_set) {
		clkrt++;
		clk_set >>= 1;
	}

	if (clkrt > 7) {
		clkrt = 7;
	}

	REG_MSC_CLKRT(ctl_num) = clkrt;
	REG_MSC_LPM(ctl_num) = 1;

	/* cmd12 reset when we reading or writing from the card, send this cmd */
	resp = mmc_cmd(12, 0, 0x41, MSC_CMDAT_RESPONSE_R1);

	resp = mmc_cmd(0, 0, 0x80, MSC_CMDAT_RESPONSE_NONE);
	resp = mmc_cmd(8, 0x1aa, 0x1, MSC_CMDAT_RESPONSE_R1);

	resp = mmc_cmd(55, 0, 0x1, MSC_CMDAT_RESPONSE_R1);

	if (resp[0] & 0x20){
		if (resp[5] == 0x37){
			resp = mmc_cmd(41, 0x40ff8000, 0x3, MSC_CMDAT_RESPONSE_R3);
			if (resp[5] == 0x3f)
				ret = sd_found();
			else
				ret = mmc_found();
		} else {
			ret = mmc_found();
		}
	} else {
		ret = mmc_found();
	}

	if (ret)
		return error_handler(current_boot);

	ret = mmc_block_read(SPL_SIZE + redundancy_size, (u32 *)start_addr);	//SDRAM ADDR

	if(!ret)
	{
		if (!(REG32(start_addr) == 0x4d53504c)) {
			if (ctl_num == 0)
				return sd_boot(1);
			if (ctl_num == 1)
				return usb_boot();
		} else {
			return xfer_d2i(start_addr + jump_offset, SPL_SIZE);
		}
	} else {
		return error_handler(current_boot);
	}
}
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;
}