summaryrefslogtreecommitdiff
path: root/lib_arm/board.c
blob: 99a2cffb9be7545c5caf4cb60d49737a660764f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
/*
 * (C) Copyright 2002
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * (C) Copyright 2002
 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
 * Marius Groeger <mgroeger@sysgo.de>
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * Copyright (c) 2008 WonderMedia Technologies, Inc.
 *
 * This program is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software Foundation,
 * either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * WonderMedia Technologies, Inc.
 * 10F, 529, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
 */

#include <common.h>
#include <command.h>
#include <malloc.h>
#include <devices.h>
#include <version.h>
#include <net.h>
#include "../version.h"
#include "../common/wmt_display/wmt_display.h"
#include "../common/wmt_display/minivgui.h"
#include "../board/wmt/include/wmt_iomux.h"
#include "../board/wmt/wmt_battery/wmt_battery.h"
#include "../common/wmt_dual_boot/wmt_dual_boot.h"

int bootcmdflag;
int showinfoflag=1;
int g_abort;

#ifdef CONFIG_DRIVER_SMC91111
#include "../drivers/smc91111.h"
#endif
#ifdef CONFIG_DRIVER_LAN91C96
#include "../drivers/lan91c96.h"
#endif

DECLARE_GLOBAL_DATA_PTR;

#include "../define.h"
#define BUILD_ID "BUILDID_"  BUILD_TIME

extern int g_tf_boot;
extern int g_load_script_success;
extern char *CMD_LOAD_SCRIPT;
extern char *CMD_LOAD_USB_SCRIPT;

#define POWERUP_SOURCE_STATUS (0xD8130000 + 0xD0)
#define PWRBTN_BIT           0x01

#if (CONFIG_COMMANDS & CFG_CMD_NAND)
void nand_init(void);
extern ulong nand_probe(ulong physadr);
void nand_init(void)
{
	nand_probe(0xd8009000);
}
#endif

ulong monitor_flash_len;

#ifdef CONFIG_HAS_DATAFLASH
extern int  AT91F_DataflashInit(void);
extern void dataflash_print_info(void);
#endif

#ifndef CONFIG_IDENT_STRING
#define CONFIG_IDENT_STRING ""
#endif

const char version_string[] =
        U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")"CONFIG_IDENT_STRING;

#ifdef CONFIG_DRIVER_CS8900
extern void cs8900_get_enetaddr(uchar *addr);
#endif

#ifdef CONFIG_DRIVER_RTL8019
extern void rtl8019_get_enetaddr(uchar *addr);
#endif

/*
 * Begin and End of memory area for malloc(), and current "brk"
 */
static ulong mem_malloc_start;
static ulong mem_malloc_end;
static ulong mem_malloc_brk;

static
void mem_malloc_init(ulong dest_addr)
{
	mem_malloc_start = dest_addr;
	mem_malloc_end = dest_addr + CFG_MALLOC_LEN;
	mem_malloc_brk = mem_malloc_start;

	memset_32Byte((void *) mem_malloc_start, 0,
	              mem_malloc_end - mem_malloc_start);
}

void *sbrk(ptrdiff_t increment)
{
	ulong old = mem_malloc_brk;
	ulong new = old + increment;

	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
		printf("Out Of Memory!!\n");
		return NULL;
	}

	mem_malloc_brk = new;

	return (void *)old;
}

void raise(void)
{
}

/************************************************************************
 * Init Utilities							*
 ************************************************************************
 * Some of this code should be moved into the core functions,
 * or dropped completely,
 * but let's get it working (again) first...
 */

static int init_baudrate(void)
{
	char *tmp = getenv("baudrate");
	gd->bd->bi_baudrate = gd->baudrate = (tmp != NULL)
	                                     ? (int) simple_strtoul(tmp, NULL, 10)
	                                     : CONFIG_BAUDRATE;

	return 0;
}

static int display_banner(void)
{
	bootcmdflag = 1;
	printf("\n\n%s\n", version_string);
	printf("WonderMedia Technologies, Inc.\n");
	printf("U-Boot Version : %s\n", WMT_U_BOOT_VERSION);
	bootcmdflag = 0;
	printf("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
	       _armboot_start, _bss_start, _bss_end);
	printf("U-Boot BUILD_ID:%s\n", BUILD_ID);
#ifdef CONFIG_MODEM_SUPPORT
	puts("Modem Support enabled\n");
#endif
#ifdef CONFIG_USE_IRQ
	printf("IRQ Stack: %08lx\n", IRQ_STACK_START);
	printf("FIQ Stack: %08lx\n", FIQ_STACK_START);
#endif

	return 0;
}

static void display_flash_config(ulong size)
{
	puts("Flash: ");
	print_size(size, "\n");
}

int end_logoshow_time = 0;
int g_show_logo = 1;

extern int WMTAccessNandEarier(unsigned long long naddr, unsigned int maddr,
                               unsigned int size, int write);
extern int display_show(int format);

void show_logo(void)
{
	//logo sequency in nand: logo1 -- charge animation -- logo2
	char *p_logocmd, *p_logoindex, *p_logo1_size, *p_chargeanim_size, *p_logo2_size;
	char *p_naddr_env, *p_maddr_env;
	unsigned char *p_maddr;
	int logo1_size, chargeanim_size, logo2_size, total_size;
	unsigned int naddr, maddr, backup_img_phy;
	int ret;

	if(g_show_logo == 0)
		return;

	p_logocmd = getenv("logocmd");
	if (p_logocmd) {
		debug("logocmd=\"%s\"\n", p_logocmd);

		ret = show_dualboot_logo(0);
		if(ret == 0)
			return;

		if(!g_tf_boot) {
			if((p_logoindex = getenv("wmt.logo.index"))
			    && (p_logoindex[0] == '1')
			    && (p_logo2_size = getenv("wmt.logosize.logo2"))
			    && (p_naddr_env = getenv("wmt.nfc.mtd.u-boot-logo"))
			    && (p_maddr_env = getenv("wmt.display.logoaddr"))
			    && (p_logo1_size = getenv("wmt.logosize.uboot"))
			    && (p_chargeanim_size = getenv("wmt.logosize.charge"))) {
				logo1_size = simple_strtoul(p_logo1_size, NULL, 0);
				chargeanim_size = simple_strtoul(p_chargeanim_size, NULL, 0);
				logo2_size = simple_strtoul(p_logo2_size, NULL, 0);
				naddr = simple_strtoul(p_naddr_env, NULL, 16);
				maddr = simple_strtoul(p_maddr_env, NULL, 16);
				p_maddr = (unsigned char *)maddr;
				if(logo1_size != 0 && chargeanim_size != 0 && logo2_size != 0) {
					total_size = logo1_size + chargeanim_size + logo2_size;
					REG32_VAL(GPIO_BASE_ADDR + 0x200) &= ~(1 << 11); //PIN_SHARE_SDMMC1_NAND
					ret = WMTAccessNandEarier(naddr, maddr, total_size, 0);
					if(!ret) {
						if(*(p_maddr + logo1_size + chargeanim_size) != 'B') {
							printf("logo2: 0x%x = 0x%x\n", p_maddr + logo1_size + chargeanim_size,
							       *(p_maddr + logo1_size + chargeanim_size));
							printf("Error : logo2 is NOT BMP format\n");
							show_text_to_screen("Can not show logo2. Logo2 is NOT BMP format", 0xFF00);
						} else {
							//arm_memmove(p_maddr, p_maddr + logo1_size + chargeanim_size, logo2_size);
							g_logo_x = -1;
							g_logo_y = -1;
							backup_img_phy = g_img_phy;
							g_img_phy = maddr + logo1_size + chargeanim_size;
							display_show(0);
							g_img_phy = backup_img_phy;
						}
					} else {
						printf("load logo2 fail\n");
						show_text_to_screen("Can not show logo2. Load logo2 fail", 0xFF00);
					}
				} else {
					printf("Error: logo1_size = %d, chargeanim_size = %d, logo2_size = %d\n",
					       logo1_size, chargeanim_size, logo2_size);
					if(logo1_size == 0)
						show_text_to_screen("Can not show logo2. 'wmt.logosize.uboot' is wrong", 0xFF00);
					else if(chargeanim_size == 0)
						show_text_to_screen("Can not show logo2. 'wmt.logosize.charge' is wrong", 0xFF00);
					else
						show_text_to_screen("Can not show logo2. 'wmt.logosize.logo2' is wrong", 0xFF00);
				}
			} else
				run_command(p_logocmd, 0);
		} else {
			if((p_logoindex = getenv("wmt.logo.index"))
			    && (p_logoindex[0] == '1')
			    && (p_maddr_env = getenv("wmt.display.logoaddr"))) {
				maddr = simple_strtoul(p_maddr_env, NULL, 16);
				ret = run_command("mmcinit 1", 0);
				if(ret != -1) {
					char tmp[100] = {0};
					sprintf(tmp, "fatload mmc 1 0x%x u-boot-logo2.bmp", maddr);
					ret = run_command(tmp, 0);
					if(ret != -1)  {
						g_logo_x = -1;
						g_logo_y = -1;
						display_show(0);
					} else {
						printf("TF: load u-boot-logo2.bmp failed\n");
						show_text_to_screen("Can not show logo2. fatload logo2 failed", 0xFF00);
					}
				} else {
					printf("TF: run \"mmcinit 1\" failed for show logo2\n");
					show_text_to_screen("Can not show logo2. 'mmcinit 1' failed", 0xFF00);
				}
			} else
				run_command(p_logocmd, 0);
		}
	} else
		debug("'logocmd' is not found , logocmd will not execute\n");

	wmt_read_ostc(&end_logoshow_time);
	g_show_logo = 0;
}

/*
 * Breathe some life into the board...
 *
 * Initialize a serial port as console, and carry out some hardware
 * tests.
 *
 * The first part of initialization is running from Flash memory;
 * its main purpose is to initialize the RAM so that we
 * can relocate the monitor code to RAM.
 */

/*
 * All attempts to come up with a "common" initialization sequence
 * that works for all boards and architectures failed: some of the
 * requirements are just _too_ different. To get rid of the resulting
 * mess of board dependent #ifdef'ed code we now make the whole
 * initialization sequence configurable to the user.
 *
 * The requirements for any new initalization function is simple: it
 * receives a pointer to the "global data" structure as it's only
 * argument, and returns an integer return code, where 0 means
 * "continue" and != 0 means "fatal error, hang the system".
 */
typedef int (init_fnc_t) (void);

/* {JHT */
#if defined(CONFIG_WMT)
int wmt_post(void);
#endif

init_fnc_t *init_sequence[] = {
	cpu_init,		/* basic cpu dependent setup */
	board_init,		/* basic board dependent setup */
	interrupt_init,		/* set up exceptions */
	//env_init,		/* initialize environment */
	init_baudrate,		/* initialze baudrate settings */
	serial_init,		/* serial communications setup */
	console_init_f,		/* stage 1 init of console */
	display_banner,		/* say that we are here */
	dram_init,		/* configure available RAM banks */
#if defined(CONFIG_VCMA9) || defined(CONFIG_CMC_PU2)
	checkboard,
#endif
	/* {JHT} */
#if defined(CONFIG_WMT)
	wmt_post,
#endif
	NULL,
};

extern int hw_recovery(void);
extern int udc_fastboot_init(void);
extern void udc_fastboot_exit(void);
extern int check_udc_to_pc(int force);
extern int check_mptool(void);
extern int run_fastboot(int backlight_on);
extern int set_charge_current(void);
extern int low_power_detect(void);
extern int play_charge_animation(void);
extern void do_wmt_poweroff(void);
extern int enter_fastboot_by_press_key(void);
extern int enter_fastboot_by_special_file(int in_sdcard);

extern void vt1603_snd_init(void);
static void led_control(const char *name);

#ifdef LOGO_DISPLAY_SPEED_TEST
int start_armboot_time;
#endif

#define HSP3_STATUS (0xD8130000 + 0x3C)
#define REBOOT_BIT 0x10

void start_armboot(void)
{
#ifdef LOGO_DISPLAY_SPEED_TEST
	wmt_read_ostc(&start_armboot_time);
#endif

	ulong size;
	init_fnc_t **init_fnc_ptr;
	char *s;
#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
	unsigned long addr;
#endif
	int ret, skip_play_animation, check_result;

	/* Pointer is writable since we allocated a register for it */
	gd = (gd_t *)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
	/* compiler optimization barrier needed for GCC >= 3.4 */
	__asm__ __volatile__("" : : : "memory");

	memset((void *)gd, 0, sizeof(gd_t));
	gd->bd = (bd_t *)((char *)gd - sizeof(bd_t));
	memset(gd->bd, 0, sizeof(bd_t));

	monitor_flash_len = _bss_start - _armboot_start;

	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
		if ((*init_fnc_ptr)() != 0)
			hang();
	}

	//Detect power key at here. It can quictly skip charging animation if power key is pressed
	if(REG32_VAL(0xD8130054) & BIT24) {
		skip_play_animation = 1;
	} else
		skip_play_animation = 0;

	/* configure available FLASH banks */
	size = flash_init();
	display_flash_config(size);

#ifdef CONFIG_VFD
#	ifndef PAGE_SIZE
#	  define PAGE_SIZE 4096
#	endif
	/*
	 * reserve memory for VFD display (always full pages)
	 */
	/* bss_end is defined in the board-specific linker script */
	addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
	size = vfd_setmem(addr);
	gd->fb_base = addr;
#endif /* CONFIG_VFD */

#ifdef CONFIG_LCD
#	ifndef PAGE_SIZE
#	  define PAGE_SIZE 4096
#	endif
	/*
	 * reserve memory for LCD display (always full pages)
	 */
	/* bss_end is defined in the board-specific linker script */
	addr = (_bss_end + (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
	size = lcd_setmem(addr);
	gd->fb_base = addr;
#endif /* CONFIG_LCD */

	/* armboot_start is defined in the board-specific linker script */
	mem_malloc_init(_armboot_start - CFG_MALLOC_LEN);

#if 0 //(CONFIG_COMMANDS & CFG_CMD_NAND)
	if ((*((volatile unsigned int *)(0xd8110100)) & 0x400E) == 0x4008) {
		puts("nandboot: NAND init:");      /* nand boot*/
		nand_init();		/* go init the NAND */
	}
#endif

#ifdef CONFIG_HAS_DATAFLASH
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

	/* initialize environment */
	env_init();
	env_relocate();

	devices_init();	/* get the devices list going. */

	/* get env to turn on/off uboot message if define/undefine "show_info"
	 * uboot parameter 2013/07/31
	 */
	s = getenv("show_info");
	if (s != NULL) {
		showinfoflag = 1;
		printf("show_info = %s\n", s);
	}

	pmic_init();

	//check power type
	if(REG32_VAL(HSP3_STATUS) & REBOOT_BIT)
		printf("Power on by reset\n");
	else if(REG8_VAL(POWERUP_SOURCE_STATUS) & PWRBTN_BIT)
		printf("Power on by power key\n");
	else
		printf("Power on by adapter\n");

	//********add for vt1603 hp spk always on :av out noisy 2014-4-28
	vt1603_snd_init();
	//*****add end
	if (tstc()) {
		if (getc() == 0xd) {  /* "Enter" key */
			printf("Got 'Enter' key\n");
			g_abort = 1;
		}
	}

	if(g_abort == 0) {
		s = getenv("logocmd");
		if(s != NULL) {
			display_init(0, 0);
			s = getenv("wmt.display.delay");
			if(s != NULL) {
				int displaydelay;
				displaydelay = (int)simple_strtol(s, NULL, 10);
				if(displaydelay > 1000) // limit to 1s
					displaydelay = 1000;
				if(displaydelay > 0)
					mdelay(displaydelay);
			}
		} else
			skip_play_animation = 1;
	}

	udc_fastboot_init();
	led_control(ENV_POWER_LED);
	led_control(ENV_LOGO_LED_CONTROL);

#if (CONFIG_COMMANDS & CFG_CMD_NAND)
	if ((*((volatile unsigned int *)(0xd8110100)) & 0x4008) == 0x4000) {
		puts("NAND init:");      /* sf boot*/
		nand_init();		/* go init the NAND */
	}
#endif

	if(g_abort == 0) {
		if(enter_fastboot_by_press_key() == 0)
			g_abort = 1;
	}

	if(g_abort == 0) {
		if(skip_play_animation == 0) {
			if(((s = getenv(ENV_CHARGE_ANIMATION)) != NULL && !strcmp(s, "0"))
			    || ((s = getenv("wmt_sys_directboot")) != NULL && !strcmp(s, "1"))
			    || ((s = getenv("wmt_sys_restore")) != NULL && !strcmp(s, "1"))
			    || (!wmt_is_dc_plugin() && (REG8_VAL(POWERUP_SOURCE_STATUS) & PWRBTN_BIT))
			    || (REG32_VAL(0xD813003C) & 0x10))  //power by reset
				skip_play_animation = 1;
		}

		if(!(REG32_VAL(HSP3_STATUS) & REBOOT_BIT)
		    && !wmt_is_dc_plugin()
		    && !(REG8_VAL(POWERUP_SOURCE_STATUS) & PWRBTN_BIT)) {
			printf("Adapter is removed\nPower off\n");
			do_wmt_poweroff();
		}

		if(skip_play_animation)
			show_logo();
	}

	hw_recovery();

#ifdef CONFIG_VFD
	/* must do this after the framebuffer is allocated */
	drv_vfd_init();
#endif /* CONFIG_VFD */

//#if 0
	/* IP Address */
	gd->bd->bi_ip_addr = getenv_IPaddr("ipaddr");

	/* MAC Address */
	{
		ulong reg;
		char *s, *e;

		s = getenv("ethaddr");

		for (reg = 0; reg < 6; ++reg) {
			gd->bd->bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0;
			if (s)
				s = (*e) ? e + 1 : e;
		}
	}
//#endif

	if(g_abort == 0) {
		char *p_install_dev;
		if((p_install_dev = getenv("wmt.install.dev")) != NULL && strcmp(p_install_dev, "usb") == 0) {
			if (run_command("usb reset", 0) != -1 ) {
				if(run_command(CMD_LOAD_USB_SCRIPT, 0) != -1) {
					g_load_script_success = 1;
					printf("run \"%s\" success\n", CMD_LOAD_USB_SCRIPT);
					run_command("addfwcenv FirmwareInstall/config", 0);
					skip_play_animation = 1;
				} else {
					g_load_script_success = 0;
					if(enter_fastboot_by_special_file(0) == 0)
						g_abort = 1;
				}
			} else
				g_load_script_success = 0;
		} else {
			if (run_command("mmcinit 0", 0) != -1 ) {
				if(run_command(CMD_LOAD_SCRIPT, 0) != -1) {
					g_load_script_success = 1;
					printf("run \"%s\" success\n", CMD_LOAD_SCRIPT);
					run_command("addfwcenv FirmwareInstall/config", 0);
					skip_play_animation = 1;
				} else {
					g_load_script_success = 0;
					if(enter_fastboot_by_special_file(1) == 0)
						g_abort = 1;
				}
			} else
				g_load_script_success = 0;
		}
	}

	if(g_abort == 0) {
		check_udc_to_pc(1);
		set_charge_current();

		if(skip_play_animation == 0) {
			ret = play_charge_animation();
			//check mptool if play animation fail
			if(ret != 0) {
				check_result = check_mptool();
				if(check_result == 1) {
					udc_fastboot_exit();
					run_fastboot(0);
				}

				if(check_result == 0) {
					if(ret > 0)
						low_power_detect();
				} else
					g_abort = 1;
			}

			g_show_logo = 1;

		} else {
			//check mptool if don't play animation
			if (g_load_script_success != 1) {
				check_result = check_mptool();
				if(check_result == 1) {
					udc_fastboot_exit();
					run_fastboot(0);
				}

				if(check_result == 0)
					low_power_detect();
				else
					g_abort = 1;
			}
		}
	}

	udc_fastboot_exit();

#ifdef CONFIG_CMC_PU2
	load_sernum_ethaddr();
#endif /* CONFIG_CMC_PU2 */

	jumptable_init();

	console_init_r();	/* fully init console as a device */

#if defined(CONFIG_MISC_INIT_R)
	/* miscellaneous platform dependent initialisations */
	misc_init_r();
#endif

	/* enable exceptions */
	enable_interrupts();

	/* Perform network card initialisation if necessary */
#ifdef CONFIG_DRIVER_CS8900
	cs8900_get_enetaddr(gd->bd->bi_enetaddr);
#endif

#if defined(CONFIG_DRIVER_SMC91111) || defined(CONFIG_DRIVER_LAN91C96)
	if (getenv("ethaddr"))
		smc_set_mac_addr(gd->bd->bi_enetaddr);
#endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */

	/* Initialize from environment */
	s = getenv("loadaddr");
	if (s != NULL)
		load_addr = simple_strtoul(s, NULL, 16);
#if (CONFIG_COMMANDS & CFG_CMD_NET)
	s = getenv("bootfile");
	if (s != NULL)
		copy_filename(BootFile, s, sizeof(BootFile));
#endif	/* CFG_CMD_NET */

#ifdef BOARD_LATE_INIT
	board_late_init();
#endif
#if (CONFIG_COMMANDS & CFG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
	puts("Net:   ");
#endif
	eth_initialize(gd->bd);
#endif

	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;)
		main_loop();

	/* NOTREACHED - no way out of command loop except booting */
}

void hang(void)
{
	puts("### ERROR ### Please RESET the board ###\n");
	for (;;)
		;
}

#ifdef CONFIG_MODEM_SUPPORT
/* called from main loop (common/main.c) */
extern void  dbg(const char *fmt, ...);
int mdm_init(void)
{
	char env_str[16];
	char *init_str;
	int i;
	extern char console_buffer[];
	static inline void mdm_readline(char * buf, int bufsiz);
	extern void enable_putc(void);
	extern int hwflow_onoff(int);

	enable_putc(); /* enable serial_putc() */

#ifdef CONFIG_HWFLOW
	init_str = getenv("mdm_flow_control");
	if (init_str && (strcmp(init_str, "rts/cts") == 0))
		hwflow_onoff(1);
	else
		hwflow_onoff(-1);
#endif

	for (i = 1; ; i++) {
		sprintf(env_str, "mdm_init%d", i);
		init_str = getenv(env_str);
		if (init_str != NULL) {
			serial_puts(init_str);
			serial_puts("\n");
			for ( ; ; ) {
				mdm_readline(console_buffer, CFG_CBSIZE);
				dbg("ini%d: [%s]", i, console_buffer);

				if ((strcmp(console_buffer, "OK") == 0) ||
				    (strcmp(console_buffer, "ERROR") == 0)) {
					dbg("ini%d: cmd done", i);
					break;
				} else /* in case we are originating call ... */
					if (strncmp(console_buffer, "CONNECT", 7) == 0) {
						dbg("ini%d: connect", i);
						return 0;
					}
			}
		} else
			break; /* no init string - stop modem init */

		udelay(100000);
	}

	udelay(100000);

	/* final stage - wait for connect */
	for ( ; i > 1; ) {
		/* if 'i' > 1 - wait for connection
					  message from modem */
		mdm_readline(console_buffer, CFG_CBSIZE);
		dbg("ini_f: [%s]", console_buffer);
		if (strncmp(console_buffer, "CONNECT", 7) == 0) {
			dbg("ini_f: connected");
			return 0;
		}
	}

	return 0;
}

/* 'inline' - We have to do it fast */
static inline void mdm_readline(char *buf, int bufsiz)
{
	char c;
	char *p;
	int n;

	n = 0;
	p = buf;
	for ( ; ; ) {
		c = serial_getc();

		/*		dbg("(%c)", c); */

		switch (c) {
		case '\r':
			break;
		case '\n':
			*p = '\0';
			return;

		default:
			if (n++ > bufsiz) {
				*p = '\0';
				return; /* sanity check */
			}
			*p = c;
			p++;
			break;
		}
	}
}
#endif	/* CONFIG_MODEM_SUPPORT */

static void led_control(const char *name)
{
	int ret, is_light;
	struct gpio_param_t led_control_pin;

	ret = parse_gpio_param(name, &led_control_pin);

	if(ret)
		return;

	is_light = led_control_pin.flag;

	if(is_light)
		gpio_direction_output(led_control_pin.gpiono, led_control_pin.act);
	else
		gpio_direction_output(led_control_pin.gpiono, !led_control_pin.act);
}