e91a131b66a9328d8ad83cf50b6ffadec92473f8
[profile/mobile/platform/kernel/u-boot-tm1.git] / arch / arm / lib / board.c
1 /*
2  * (C) Copyright 2002-2006
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * (C) Copyright 2002
6  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7  * Marius Groeger <mgroeger@sysgo.de>
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 /*
29  * To match the U-Boot user interface on ARM platforms to the U-Boot
30  * standard (as on PPC platforms), some messages with debug character
31  * are removed from the default U-Boot build.
32  *
33  * Define DEBUG here if you want additional info as shown below
34  * printed upon startup:
35  *
36  * U-Boot code: 00F00000 -> 00F3C774  BSS: -> 00FC3274
37  * IRQ Stack: 00ebff7c
38  * FIQ Stack: 00ebef7c
39  */
40
41 #include <common.h>
42 #include <command.h>
43 #include <malloc.h>
44 #include <stdio_dev.h>
45 #include <timestamp.h>
46 #include <version.h>
47 #include <net.h>
48 #include <serial.h>
49 #include <nand.h>
50 #include <onenand_uboot.h>
51 #include <mmc.h>
52
53 #ifdef CONFIG_BITBANGMII
54 #include <miiphy.h>
55 #endif
56
57 #ifdef CONFIG_DRIVER_SMC91111
58 #include "../drivers/net/smc91111.h"
59 #endif
60 #ifdef CONFIG_DRIVER_LAN91C96
61 #include "../drivers/net/lan91c96.h"
62 #endif
63
64 DECLARE_GLOBAL_DATA_PTR;
65
66 ulong monitor_flash_len;
67
68 #ifdef CONFIG_HAS_DATAFLASH
69 extern int  AT91F_DataflashInit(void);
70 extern void dataflash_print_info(void);
71 #endif
72
73 #ifndef CONFIG_IDENT_STRING
74 #define CONFIG_IDENT_STRING ""
75 #endif
76
77 const char version_string[] =
78         U_BOOT_VERSION" (" U_BOOT_DATE " - " U_BOOT_TIME ")"CONFIG_IDENT_STRING;
79
80 #ifdef CONFIG_DRIVER_RTL8019
81 extern void rtl8019_get_enetaddr (uchar * addr);
82 #endif
83
84 #if defined(CONFIG_HARD_I2C) || \
85     defined(CONFIG_SOFT_I2C)
86 #include <i2c.h>
87 #endif
88
89
90 /************************************************************************
91  * Coloured LED functionality
92  ************************************************************************
93  * May be supplied by boards if desired
94  */
95 void __attribute__ ((gnu_inline))inline __coloured_LED_init (void) {}
96 void coloured_LED_init (void) __attribute__((weak, alias("__coloured_LED_init")));
97 void __attribute__ ((gnu_inline))inline __red_LED_on (void) {}
98 void red_LED_on (void) __attribute__((weak, alias("__red_LED_on")));
99 void __attribute__ ((gnu_inline))inline __red_LED_off(void) {}
100 void red_LED_off(void) __attribute__((weak, alias("__red_LED_off")));
101 void __attribute__ ((gnu_inline))inline __green_LED_on(void) {}
102 void green_LED_on(void) __attribute__((weak, alias("__green_LED_on")));
103 void __attribute__ ((gnu_inline))inline __green_LED_off(void) {}
104 void green_LED_off(void) __attribute__((weak, alias("__green_LED_off")));
105 void __attribute__ ((gnu_inline))inline __yellow_LED_on(void) {}
106 void yellow_LED_on(void) __attribute__((weak, alias("__yellow_LED_on")));
107 void __attribute__ ((gnu_inline))inline __yellow_LED_off(void) {}
108 void yellow_LED_off(void) __attribute__((weak, alias("__yellow_LED_off")));
109 void __attribute__ ((gnu_inline))inline __blue_LED_on(void) {}
110 void blue_LED_on(void) __attribute__((weak, alias("__blue_LED_on")));
111 void __attribute__ ((gnu_inline))inline __blue_LED_off(void) {}
112 void blue_LED_off(void) __attribute__((weak, alias("__blue_LED_off")));
113
114 extern int boot_pwr_check(void);
115 /************************************************************************
116  * Init Utilities                                                       *
117  ************************************************************************
118  * Some of this code should be moved into the core functions,
119  * or dropped completely,
120  * but let's get it working (again) first...
121  */
122
123 #if defined(CONFIG_ARM_DCC) && !defined(CONFIG_BAUDRATE)
124 #define CONFIG_BAUDRATE 115200
125 #endif
126 static int init_baudrate (void)
127 {
128         char tmp[64];   /* long enough for environment variables */
129         int i = getenv_f("baudrate", tmp, sizeof (tmp));
130
131         gd->baudrate = (i > 0)
132                         ? (int) simple_strtoul (tmp, NULL, 10)
133                         : CONFIG_BAUDRATE;
134
135         return (0);
136 }
137
138 static int display_banner (void)
139 {
140         printf ("\n\n%s\n\n", version_string);
141         debug ("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
142                _TEXT_BASE,
143                _bss_start_ofs+_TEXT_BASE, _bss_end_ofs+_TEXT_BASE);
144 #ifdef CONFIG_MODEM_SUPPORT
145         debug ("Modem Support enabled\n");
146 #endif
147 #ifdef CONFIG_USE_IRQ
148         debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
149         debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
150 #endif
151
152         return (0);
153 }
154
155 /*
156  * WARNING: this code looks "cleaner" than the PowerPC version, but
157  * has the disadvantage that you either get nothing, or everything.
158  * On PowerPC, you might see "DRAM: " before the system hangs - which
159  * gives a simple yet clear indication which part of the
160  * initialization if failing.
161  */
162 static int display_dram_config (void)
163 {
164         int i;
165
166 #ifdef DEBUG
167         puts ("RAM Configuration:\n");
168
169         for(i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
170                 printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
171                 print_size (gd->bd->bi_dram[i].size, "\n");
172         }
173 #else
174         ulong size = 0;
175
176         for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
177                 size += gd->bd->bi_dram[i].size;
178         }
179         puts("DRAM:  ");
180         print_size(size, "\n");
181 #endif
182
183         return (0);
184 }
185
186 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
187 static int init_func_i2c (void)
188 {
189         puts ("I2C:   ");
190         i2c_init (CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE);
191         puts ("ready\n");
192         return (0);
193 }
194 #endif
195
196 #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
197 #include <pci.h>
198 static int arm_pci_init(void)
199 {
200         pci_init();
201         return 0;
202 }
203 #endif /* CONFIG_CMD_PCI || CONFIG_PCI */
204
205 /*
206  * Breathe some life into the board...
207  *
208  * Initialize a serial port as console, and carry out some hardware
209  * tests.
210  *
211  * The first part of initialization is running from Flash memory;
212  * its main purpose is to initialize the RAM so that we
213  * can relocate the monitor code to RAM.
214  */
215
216 /*
217  * All attempts to come up with a "common" initialization sequence
218  * that works for all boards and architectures failed: some of the
219  * requirements are just _too_ different. To get rid of the resulting
220  * mess of board dependent #ifdef'ed code we now make the whole
221  * initialization sequence configurable to the user.
222  *
223  * The requirements for any new initalization function is simple: it
224  * receives a pointer to the "global data" structure as it's only
225  * argument, and returns an integer return code, where 0 means
226  * "continue" and != 0 means "fatal error, hang the system".
227  */
228 typedef int (init_fnc_t) (void);
229
230 int print_cpuinfo (void);
231
232 void __dram_init_banksize(void)
233 {
234         gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
235         gd->bd->bi_dram[0].size =  gd->ram_size;
236 }
237 void dram_init_banksize(void)
238         __attribute__((weak, alias("__dram_init_banksize")));
239
240 init_fnc_t *init_sequence[] = {
241 #if defined(CONFIG_ARCH_CPU_INIT)
242         arch_cpu_init,          /* basic arch cpu dependent setup */
243 #endif
244 #if defined(CONFIG_BOARD_EARLY_INIT_F)
245         board_early_init_f,
246 #endif
247         timer_init,             /* initialize timer */
248 #ifdef CONFIG_FSL_ESDHC
249         get_clocks,
250 #endif
251         env_init,               /* initialize environment */
252         init_baudrate,          /* initialze baudrate settings */
253         serial_init,            /* serial communications setup */
254         console_init_f,         /* stage 1 init of console */
255         display_banner,         /* say that we are here */
256 #if defined(CONFIG_DISPLAY_CPUINFO)
257         print_cpuinfo,          /* display cpu info (and speed) */
258 #endif
259 #if defined(CONFIG_DISPLAY_BOARDINFO)
260         checkboard,             /* display board info */
261 #endif
262 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
263         init_func_i2c,
264 #endif
265         dram_init,              /* configure available RAM banks */
266 #if defined(CONFIG_CMD_PCI) || defined (CONFIG_PCI)
267         arm_pci_init,
268 #endif
269         NULL,
270 };
271
272 void board_init_f (ulong bootflag)
273 {
274         bd_t *bd;
275         init_fnc_t **init_fnc_ptr;
276         gd_t *id;
277         ulong addr, addr_sp;
278
279         /*
280          * Fix me, when DDR size is less than or equal to 256M, uboot may destroy SPRD_SYSDUMP_MAGIC.
281          * Pointer is writable since we allocated a register for it.
282          */
283         gd = (gd_t *) ((CONFIG_SYS_INIT_SP_ADDR) & ~0x07);
284
285         /* compiler optimization barrier needed for GCC >= 3.4 */
286         __asm__ __volatile__("": : :"memory");
287
288         memset ((void*)gd, 0, sizeof (gd_t));
289
290         gd->mon_len = _bss_end_ofs;
291
292         for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
293                 if ((*init_fnc_ptr)() != 0) {
294                         hang ();
295                 }
296         }
297
298         debug ("monitor len: %08lX\n", gd->mon_len);
299         /*
300          * Ram is setup, size stored in gd !!
301          */
302         debug ("ramsize: %08lX\n", gd->ram_size);
303 #if defined(CONFIG_SYS_MEM_TOP_HIDE)
304         /*
305          * Subtract specified amount of memory to hide so that it won't
306          * get "touched" at all by U-Boot. By fixing up gd->ram_size
307          * the Linux kernel should now get passed the now "corrected"
308          * memory size and won't touch it either. This should work
309          * for arch/ppc and arch/powerpc. Only Linux board ports in
310          * arch/powerpc with bootwrapper support, that recalculate the
311          * memory size from the SDRAM controller setup will have to
312          * get fixed.
313          */
314         gd->ram_size -= CONFIG_SYS_MEM_TOP_HIDE;
315 #endif
316
317         addr = CONFIG_SYS_SDRAM_BASE + PHYS_SDRAM_1_SIZE;
318
319 #ifdef CONFIG_LOGBUFFER
320 #ifndef CONFIG_ALT_LB_ADDR
321         /* reserve kernel log buffer */
322         addr -= (LOGBUFF_RESERVE);
323         debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
324 #endif
325 #endif
326
327 #ifdef CONFIG_PRAM
328         /*
329          * reserve protected RAM
330          */
331         i = getenv_r ("pram", (char *)tmp, sizeof (tmp));
332         reg = (i > 0) ? simple_strtoul ((const char *)tmp, NULL, 10) : CONFIG_PRAM;
333         addr -= (reg << 10);            /* size is in kB */
334         debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);
335 #endif /* CONFIG_PRAM */
336
337 #if !(defined(CONFIG_SYS_NO_ICACHE) && defined(CONFIG_SYS_NO_DCACHE))
338         /* reserve TLB table */
339         addr -= (4096 * 4);
340
341         /* round down to next 64 kB limit */
342         addr &= ~(0x10000 - 1);
343
344         gd->tlb_addr = addr;
345         debug ("TLB table at: %08lx\n", addr);
346 #endif
347
348         /* round down to next 4 kB limit */
349         addr &= ~(4096 - 1);
350         debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
351
352 #ifdef CONFIG_VFD
353 #       ifndef PAGE_SIZE
354 #         define PAGE_SIZE 4096
355 #       endif
356         /*
357          * reserve memory for VFD display (always full pages)
358          */
359         addr -= vfd_setmem (addr);
360         gd->fb_base = addr;
361 #endif /* CONFIG_VFD */
362
363 #ifdef CONFIG_LCD
364         /* reserve memory for LCD display (always full pages) */
365         addr = lcd_setmem (addr);
366         gd->fb_base = addr;
367 #endif /* CONFIG_LCD */
368
369         /*
370          * reserve memory for U-Boot code, data & bss
371          * round down to next 4 kB limit
372          */
373         addr -= gd->mon_len;
374         addr &= ~(4096 - 1);
375
376         debug ("Reserving %ldk for U-Boot at: %08lx\n", gd->mon_len >> 10, addr);
377
378 #ifndef CONFIG_PRELOADER
379         /*
380          * reserve memory for malloc() arena
381          */
382         addr_sp = addr - TOTAL_MALLOC_LEN;
383         debug ("Reserving %dk for malloc() at: %08lx\n",
384                         TOTAL_MALLOC_LEN >> 10, addr_sp);
385         /*
386          * (permanently) allocate a Board Info struct
387          * and a permanent copy of the "global" data
388          */
389         addr_sp -= sizeof (bd_t);
390         bd = (bd_t *) addr_sp;
391         gd->bd = bd;
392         debug ("Reserving %zu Bytes for Board Info at: %08lx\n",
393                         sizeof (bd_t), addr_sp);
394         addr_sp -= sizeof (gd_t);
395         id = (gd_t *) addr_sp;
396         debug ("Reserving %zu Bytes for Global Data at: %08lx\n",
397                         sizeof (gd_t), addr_sp);
398
399         /* setup stackpointer for exeptions */
400         gd->irq_sp = addr_sp;
401 #ifdef CONFIG_USE_IRQ
402         addr_sp -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
403         debug ("Reserving %zu Bytes for IRQ stack at: %08lx\n",
404                 CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ, addr_sp);
405 #endif
406         /* leave 3 words for abort-stack    */
407         addr_sp -= 3;
408
409         /* 8-byte alignment for ABI compliance */
410         addr_sp &= ~0x07;
411 #else
412         addr_sp += 128; /* leave 32 words for abort-stack   */
413         gd->irq_sp = addr_sp;
414 #endif
415
416         debug ("New Stack Pointer is: %08lx\n", addr_sp);
417
418 #ifdef CONFIG_POST
419         post_bootmode_init();
420         post_run (NULL, POST_ROM | post_bootmode_get(0));
421 #endif
422
423         gd->bd->bi_baudrate = gd->baudrate;
424         /* Ram ist board specific, so move it to board code ... */
425         dram_init_banksize();
426         display_dram_config();  /* and display it */
427
428         gd->relocaddr = addr;
429         gd->start_addr_sp = addr_sp;
430         gd->reloc_off = addr - _TEXT_BASE;
431         debug ("relocation Offset is: %08lx\n", gd->reloc_off);
432         memcpy (id, (void *)gd, sizeof (gd_t));
433
434         relocate_code (addr_sp, id, addr);
435
436         /* NOTREACHED - relocate_code() does not return */
437 }
438
439 #if !defined(CONFIG_SYS_NO_FLASH)
440 static char *failed = "*** failed ***\n";
441 #endif
442
443 /************************************************************************
444  *
445  * This is the next part if the initialization sequence: we are now
446  * running from RAM and have a "normal" C environment, i. e. global
447  * data can be written, BSS has been cleared, the stack size in not
448  * that critical any more, etc.
449  *
450  ************************************************************************
451  */
452
453 void board_init_r (gd_t *id, ulong dest_addr)
454 {
455         char *s;
456         bd_t *bd;
457         ulong malloc_start;
458 #if !defined(CONFIG_SYS_NO_FLASH)
459         ulong flash_size;
460 #endif
461
462         gd = id;
463         bd = gd->bd;
464
465         gd->flags |= GD_FLG_RELOC;      /* tell others: relocation done */
466
467         monitor_flash_len = _bss_start_ofs;
468         performance_debug("1:");
469         debug ("monitor flash len: %08lX\n", monitor_flash_len);
470         board_init();   /* Setup chipselects */
471
472     boot_pwr_check();
473
474 #ifdef CONFIG_SERIAL_MULTI
475         serial_initialize();
476 #endif
477
478         debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);
479
480 #ifdef CONFIG_LOGBUFFER
481         logbuff_init_ptrs ();
482 #endif
483 #ifdef CONFIG_POST
484         post_output_backlog ();
485 #endif
486
487         /* The Malloc area is immediately below the monitor copy in DRAM */
488         malloc_start = dest_addr - TOTAL_MALLOC_LEN;
489 #ifdef SPRD_EVM_TAG_ON
490                 SPRD_EVM_TAG(4);
491 #endif
492         mem_malloc_init (malloc_start, TOTAL_MALLOC_LEN);
493         performance_debug("2:");
494 #ifdef SPRD_EVM_TAG_ON
495                 SPRD_EVM_TAG(5);
496 #endif
497     boot_pwr_check();
498
499 #if !defined(CONFIG_SYS_NO_FLASH)
500         puts ("FLASH: ");
501
502         if ((flash_size = flash_init ()) > 0) {
503 # ifdef CONFIG_SYS_FLASH_CHECKSUM
504                 print_size (flash_size, "");
505                 /*
506                  * Compute and print flash CRC if flashchecksum is set to 'y'
507                  *
508                  * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
509                  */
510                 s = getenv ("flashchecksum");
511                 if (s && (*s == 'y')) {
512                         printf ("  CRC: %08X",
513                                 crc32 (0, (const unsigned char *) CONFIG_SYS_FLASH_BASE, flash_size)
514                         );
515                 }
516                 putc ('\n');
517 # else  /* !CONFIG_SYS_FLASH_CHECKSUM */
518                 print_size (flash_size, "\n");
519 # endif /* CONFIG_SYS_FLASH_CHECKSUM */
520         } else {
521                 puts (failed);
522                 hang ();
523         }
524 #endif
525     boot_pwr_check();
526
527 #if !defined(CONFIG_EMMC_BOOT)
528 #if defined(CONFIG_CMD_NAND)
529         puts ("NAND:  ");
530         nand_init();            /* go init the NAND */
531 #endif
532 #endif
533
534     boot_pwr_check();
535 #ifdef SPRD_EVM_TAG_ON
536                 SPRD_EVM_TAG(6);
537 #endif
538
539 #if defined(CONFIG_CMD_ONENAND)
540 #if !(defined CONFIG_TIGER && defined CONFIG_EMMC_BOOT)
541         onenand_init();
542 #endif
543 #endif
544
545 #ifdef CONFIG_GENERIC_MMC
546        puts("MMC:   ");
547        mmc_initialize(bd);
548        performance_debug("3:");
549 #endif
550
551 #ifdef CONFIG_HAS_DATAFLASH
552         AT91F_DataflashInit();
553         dataflash_print_info();
554 #endif
555
556 #ifdef CONFIG_EMMC_BOOT
557         mmc_legacy_init(1);
558 #endif
559         /* initialize environment */
560         env_relocate ();
561     boot_pwr_check();
562
563 #ifdef CONFIG_VFD
564         /* must do this after the framebuffer is allocated */
565         drv_vfd_init();
566 #endif /* CONFIG_VFD */
567
568 /*tempaily use for tiger to avoid died as refreshing LCD*/
569
570         /* IP Address */
571         gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
572
573         stdio_init ();  /* get the devices list going. */
574         performance_debug("4:");
575     boot_pwr_check();
576
577         jumptable_init ();
578     boot_pwr_check();
579
580 #if defined(CONFIG_API)
581         /* Initialize API */
582         api_init ();
583 #endif
584     char fake[4]="fak";
585     setenv("splashimage", fake);
586
587         console_init_r ();      /* fully init console as a device */
588     boot_pwr_check();
589
590 #if defined(CONFIG_ARCH_MISC_INIT)
591         /* miscellaneous arch dependent initialisations */
592         arch_misc_init ();
593 #endif
594 #if defined(CONFIG_MISC_INIT_R)
595         /* miscellaneous platform dependent initialisations */
596         misc_init_r ();
597 #endif
598
599          /* set up exceptions */
600         interrupt_init ();
601         /* enable exceptions */
602         enable_interrupts ();
603     boot_pwr_check();
604
605         /* Perform network card initialisation if necessary */
606 #if defined(CONFIG_DRIVER_SMC91111) || defined (CONFIG_DRIVER_LAN91C96)
607         /* XXX: this needs to be moved to board init */
608         if (getenv ("ethaddr")) {
609                 uchar enetaddr[6];
610                 eth_getenv_enetaddr("ethaddr", enetaddr);
611                 smc_set_mac_addr(enetaddr);
612         }
613 #endif /* CONFIG_DRIVER_SMC91111 || CONFIG_DRIVER_LAN91C96 */
614
615         /* Initialize from environment */
616         if ((s = getenv ("loadaddr")) != NULL) {
617                 load_addr = simple_strtoul (s, NULL, 16);
618         }
619 #if defined(CONFIG_CMD_NET)
620         if ((s = getenv ("bootfile")) != NULL) {
621                 copy_filename (BootFile, s, sizeof (BootFile));
622         }
623 #endif
624     boot_pwr_check();
625         //usb_eth_initialize(NULL);
626 #ifdef BOARD_LATE_INIT
627         board_late_init ();
628 #endif
629
630 #ifdef CONFIG_BITBANGMII
631         bb_miiphy_init();
632 #endif
633 #if defined(CONFIG_CMD_NET)
634 #if defined(CONFIG_NET_MULTI)
635         puts ("Net:   ");
636 #endif
637         //eth_initialize(gd->bd);
638
639 #if defined(CONFIG_RESET_PHY_R)
640         debug ("Reset Ethernet PHY\n");
641         reset_phy();
642 #endif
643 #endif
644
645 #ifdef CONFIG_POST
646         post_run (NULL, POST_RAM | post_bootmode_get(0));
647 #endif
648     boot_pwr_check();
649
650 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
651         /*
652          * Export available size of memory for Linux,
653          * taking into account the protected RAM at top of memory
654          */
655         {
656                 ulong pram;
657                 uchar memsz[32];
658 #ifdef CONFIG_PRAM
659                 char *s;
660
661                 if ((s = getenv ("pram")) != NULL) {
662                         pram = simple_strtoul (s, NULL, 10);
663                 } else {
664                         pram = CONFIG_PRAM;
665                 }
666 #else
667                 pram=0;
668 #endif
669 #ifdef CONFIG_LOGBUFFER
670 #ifndef CONFIG_ALT_LB_ADDR
671                 /* Also take the logbuffer into account (pram is in kB) */
672                 pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
673 #endif
674 #endif
675                 sprintf ((char *)memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
676                 setenv ("mem", (char *)memsz);
677         }
678 #endif
679
680 #ifdef SPRD_EVM_TAG_ON
681                 SPRD_EVM_TAG(11);
682 #endif
683     MMU_Init(CONFIG_MMU_TABLE_ADDR);
684
685 #if !defined(CONFIG_FPGA)
686 #ifndef CONFIG_EMMC_BOOT
687     extern int nand_ubi_dev_init(void);
688     nand_ubi_dev_init();
689     performance_debug("5:");
690 #endif
691
692     extern uint32_t sprdbat_get_vbatauxadc_caltype(void);
693     extern void sprdbat_init (void);
694     sprdbat_init();
695
696 #if defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
697         if (sprdbat_get_vbatauxadc_caltype() != 0)
698         {
699             DCDC_Cal_ArmCore();
700             performance_debug("6:");
701         }
702         //DCDC_Cal_All(0);
703 #endif
704 #endif
705
706     board_keypad_init();
707     boot_pwr_check();
708
709     extern int do_cboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
710     do_cboot(NULL, 0, 1, NULL);
711         /* main_loop() can return to retry autoboot, if so just run it again. */
712         for (;;) {
713                 main_loop ();
714         }
715
716         /* NOTREACHED - no way out of command loop except booting */
717 }
718
719 void hang (void)
720 {
721         puts ("### ERROR ### Please RESET the board ###\n");
722         for (;;);
723 }