Chinaunix首页 | 论坛 | 博客
  • 博客访问: 496929
  • 博文数量: 174
  • 博客积分: 2502
  • 博客等级: 少校
  • 技术积分: 1923
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-28 09:47
文章分类

全部博文(174)

文章存档

2011年(8)

2010年(16)

2009年(68)

2008年(82)

我的朋友

分类: 嵌入式

2009-08-31 12:37:30

   1 // MPC8349E-mITX ltib U-Boot lib_ppc/board.c     --- by starby
   2 /*
   3  * (C) Copyright 2000-2004
   4  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   5  *
   6  * Copyright (C) Freescale Semiconductor, Inc. 2006. All rights reserved.
   7  *
   8  * See file CREDITS for list of people who contributed to this
   9  * project.
  10  *
  11  * This program is free software; you can redistribute it and/or
  12  * modify it under the terms of the GNU General Public License as
  13  * published by the Free Software Foundation; either version 2 of
  14  * the License, or (at your option) any later version.
  15  *
  16  * This program is distributed in the hope that it will be useful,
  17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  * GNU General Public License for more details.
  20  *
  21  * You should have received a copy of the GNU General Public License
  22  * along with this program; if not, write to the Free Software
  23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24  * MA 02111-1307 USA
  25  */
  26
  27 #include
  28 #include
  29 #include
  30 #include
  31 #include
  32 #ifdef CONFIG_8xx
  33 #include
  34 #endif
  35 #ifdef CONFIG_5xx
  36 #include
  37 #endif
  38 #ifdef CONFIG_MPC5xxx
  39 #include
  40 #endif
  41 #if (CONFIG_COMMANDS & CFG_CMD_IDE)
  42 #include
  43 #endif
  44 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
  45 #include
  46 #endif
  47 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
  48 #include
  49 #endif
  50 #ifdef CONFIG_STATUS_LED
  51 #include
  52 #endif
  53 #include
  54 #include
  55 #ifdef CFG_ALLOC_DPRAM
  56 #if !defined(CONFIG_CPM2)
  57 #include
  58 #endif
  59 #endif
  60 #include
  61 #if defined(CONFIG_BAB7xx)
  62 #include
  63 #endif
  64 #include
  65 #if defined(CONFIG_POST)
  66 #include
  67 #endif
  68 #if defined(CONFIG_LOGBUFFER)
  69 #include
  70 #endif
  71 #if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500)
  72 #include
  73 #endif
  74 #ifdef CONFIG_PS2KBD
  75 #include
  76 #endif
  77
  78 #if (CONFIG_COMMANDS & CFG_CMD_DOC)
  79 void doc_init (void);
  80 #endif
  81 #if defined(CONFIG_HARD_I2C) || \    
  82     defined(CONFIG_SOFT_I2C)
  83 #include
  84 #endif
  85 #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  86 void nand_init (void);
  87 #endif
  88
  89 static char *failed = "*** failed ***\n";    // 启动失败,打印错误提示
  90
  91 #if defined(CONFIG_OXC) || defined(CONFIG_PCU_E) || defined(CONFIG_RMU)
  92 extern flash_info_t flash_info[];
  93 #endif
  94
  95 #include
  96
  97 #if defined(CFG_ENV_IS_EMBEDDED)
  98 #define TOTAL_MALLOC_LEN    CFG_MALLOC_LEN
  99 #elif ( ((CFG_ENV_ADDR+CFG_ENV_SIZE) < CFG_MONITOR_BASE) || \
 100     (CFG_ENV_ADDR >= (CFG_MONITOR_BASE + CFG_MONITOR_LEN)) ) || \
 101       defined(CFG_ENV_IS_IN_NVRAM)
 102 #define    TOTAL_MALLOC_LEN    (CFG_MALLOC_LEN + CFG_ENV_SIZE)
 103 #else
 104 #define    TOTAL_MALLOC_LEN    CFG_MALLOC_LEN
 105 #endif
 106
 107 extern ulong __init_end;
 108 extern ulong _end;
 109 ulong monitor_flash_len;
 110
 111 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
 112 #include
 113 #endif
 114
 115 /*
 116  * Begin and End of memory area for malloc(), and current "brk"
 117  */               // malloc用于用户程序进行分配内存
 118 static    ulong    mem_malloc_start = 0;
 119 static    ulong    mem_malloc_end     = 0;
 120 static    ulong    mem_malloc_brk     = 0;
 121
 122 /************************************************************************
 123  * Utilities                                *
 124  ************************************************************************
 125  */
 126
 127 /*
 128  * The Malloc area is immediately below the monitor copy in DRAM
 129  */
 130 static void mem_malloc_init (void)        // 内存分配初始函数
 131 {
 132     DECLARE_GLOBAL_DATA_PTR;            // 声明全局数据结构体指针gd为通用寄存器r29
 133
 134     ulong dest_addr = CFG_MONITOR_BASE + gd->reloc_off;    // U-Boot镜像在RAM中的起始地址dest_addr
 135
 136     mem_malloc_end = dest_addr;
 137     mem_malloc_start = dest_addr - TOTAL_MALLOC_LEN;     // RAM中MALLOC区起始地址
 138     mem_malloc_brk = mem_malloc_start;
 139
 140     memset ((void *) mem_malloc_start,
 141         0,
 142         mem_malloc_end - mem_malloc_start); // 分配一个长度为TOTAL_MALLOC_LEN大小的内存空间
 143 }
 144
 145 void *sbrk (ptrdiff_t increment)    // 所分配内存区的brk指针调整
 146 {
 147     ulong old = mem_malloc_brk;
 148     ulong new = old + increment;
 149
 150     if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
 151         return (NULL);
 152     }
 153     mem_malloc_brk = new;
 154     return ((void *) old);
 155 }
 156
 157 char *strmhz (char *buf, long hz)    // Hz转成MHz,存入buf
 158 {
 159     long l, n;
 160     long m;
 161
 162     n = hz / 1000000L;
 163     l = sprintf (buf, "%ld", n);
 164     m = (hz % 1000000L) / 1000L;
 165     if (m != 0)
 166         sprintf (buf + l, ".%03ld", m);
 167     return (buf);
 168 }
 169
 170 /*
 171  * All attempts to come up with a "common" initialization sequence
 172  * that works for all boards and architectures failed: some of the
 173  * requirements are just _too_ different. To get rid of the resulting
 174  * mess of board dependend #ifdef'ed code we now make the whole
 175  * initialization sequence configurable to the user.
 176  *
 177  * The requirements for any new initalization function is simple: it
 178  * receives a pointer to the "global data" structure as it's only
 179  * argument, and returns an integer return code, where 0 means
 180  * "continue" and != 0 means "fatal error, hang the system".
 181  */
 182 typedef int (init_fnc_t) (void);        // 函数类型声明
 183
 184 /************************************************************************
 185  * Init Utilities                            *
 186  ************************************************************************
 187  * Some of this code should be moved into the core functions,
 188  * but let's get it working (again) first...
 189  */
 190 // 一系列初始化函数
 191 static int init_baudrate (void)         // 初始化波特率
 192 {
 193     DECLARE_GLOBAL_DATA_PTR;
 194
 195     uchar tmp[64];    /* long enough for environment variables */
 196     int i = getenv_r ("baudrate", tmp, sizeof (tmp));
 197
 198     gd->baudrate = (i > 0)
 199             ? (int) simple_strtoul (tmp, NULL, 10)
 200             : CONFIG_BAUDRATE;
 201     return (0);
 202 }
 203
 204 /***********************************************************************/
 205
 206 static int init_func_ram (void)            // 初始化RAM: DDR、 SDRAM等
 207 {
 208     DECLARE_GLOBAL_DATA_PTR;
 209
 210 #ifdef    CONFIG_BOARD_TYPES
 211     int board_type = gd->board_type;
 212 #else
 213     int board_type = 0;    /* use dummy arg */
 214 #endif
 215     puts ("DRAM:  ");                    // 显示RAM配置,打印出DRAM大小
 216
 217     if ((gd->ram_size = initdram (board_type)) > 0) {
 218         print_size (gd->ram_size, "\n");
 219         return (0);
 220     }
 221     puts (failed);
 222     return (1);
 223 }
 224
 225 /***********************************************************************/
 226
 227 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
 228 static int init_func_i2c (void)        // i2c初始化
 229 {
 230     puts ("I2C:   ");
 231     i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
 232     puts ("ready\n");
 233     return (0);
 234 }
 235 #endif
 236
 237 /***********************************************************************/
 238
 239 #if defined(CONFIG_WATCHDOG)
 240 static int init_func_watchdog_init (void)    // 看门狗初始化,一般是禁止看门狗
 241 {
 242     puts ("       Watchdog enabled\n");
 243     WATCHDOG_RESET ();
 244     return (0);
 245 }
 246 # define INIT_FUNC_WATCHDOG_INIT    init_func_watchdog_init,
 247
 248 static int init_func_watchdog_reset (void)
 249 {
 250     WATCHDOG_RESET ();
 251     return (0);
 252 }
 253 # define INIT_FUNC_WATCHDOG_RESET    init_func_watchdog_reset,
 254 #else
 255 # define INIT_FUNC_WATCHDOG_INIT    /* undef */
 256 # define INIT_FUNC_WATCHDOG_RESET    /* undef */
 257 #endif /* CONFIG_WATCHDOG */
 258
 259 /************************************************************************
 260  * Initialization sequence                        *
 261  ************************************************************************
 262  */
 263 // 函数指针数组init_sequence: 调用一系列初始化函数
 264 init_fnc_t *init_sequence[] = {
 265
 266 #if defined(CONFIG_BOARD_EARLY_INIT_F)  // 是否调用board_early_init_f
 267     board_early_init_f,
 268 #endif
 269
 270 #if !defined(CONFIG_8xx_CPUCLK_DEFAULT)
 271     get_clocks,        /* get CPU and bus clocks (etc.) */ // 读IMMR,获取时钟信息
 272 #if defined(CONFIG_TQM8xxL) && !defined(CONFIG_TQM866M)
 273     adjust_sdram_tbs_8xx,
 274 #endif
 275     init_timebase,                    // 初始化时间基寄存器
 276 #endif
 277 #ifdef CFG_ALLOC_DPRAM
 278 #if !defined(CONFIG_CPM2)
 279     dpram_init,
 280 #endif
 281 #endif
 282 #if defined(CONFIG_BOARD_POSTCLK_INIT)
 283     board_postclk_init,
 284 #endif
 285     env_init,
 286 #if defined(CONFIG_8xx_CPUCLK_DEFAULT)
 287     get_clocks_866,        /* get CPU and bus clocks according to the environment variable */
 288     sdram_adjust_866,    /* adjust sdram refresh rate according to the new clock */
 289     init_timebase,
 290 #endif
 291     init_baudrate,            // 初始化全局数据结构体中波特率设置
 292     serial_init,            //
 293     console_init_f,            // 初始化全局数据结构体中终端标志位
 294     display_options,        // 显示U-Boot版本及编译信息
 295 #if defined(CONFIG_8260)
 296     prt_8260_rsr,
 297     prt_8260_clks,
 298 #endif /* CONFIG_8260 */
 299
 300 #if defined(CONFIG_MPC83XX)
 301     print_clock_conf,        // 显示各种时钟频率信息
 302 #endif
 303     checkcpu,                // 检测显示CPU信息
 304 #if defined(CONFIG_MPC5xxx)
 305     prt_mpc5xxx_clks,
 306 #endif /* CONFIG_MPC5xxx */
 307 #if defined(CONFIG_MPC8220)
 308     prt_mpc8220_clks,
 309 #endif
 310     checkboard,                // 显示目标板信息,并初始化UPM表
 311     INIT_FUNC_WATCHDOG_INIT
 312 #if defined(CONFIG_MISC_INIT_F)
 313     misc_init_f,
 314 #endif
 315     INIT_FUNC_WATCHDOG_RESET
 316 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
 317     init_func_i2c,            // i2c初始化
 318 #endif
 319 #if defined(CONFIG_DTT)        /* Digital Thermometers and Thermostats */
 320     dtt_init,
 321 #endif
 322 #ifdef CONFIG_POST
 323     post_init_f,
 324 #endif
 325     INIT_FUNC_WATCHDOG_RESET
 326     init_func_ram,            // RAM初始化,并显示DRAM大小信息
 327 #if defined(CFG_DRAM_TEST)
 328     testdram,                // 测试DRAM,比较耗时,一般不编译
 329 #endif /* CFG_DRAM_TEST */
 330     INIT_FUNC_WATCHDOG_RESET
 331
 332     NULL,            /* Terminate this list */
 333 };
 334
 335 /************************************************************************
 336  *
 337  * This is the first part of the initialization sequence that is
 338  * implemented in C, but still running from ROM.
 339  *
 340  * The main purpose is to provide a (serial) console interface as
 341  * soon as possible (so we can see any error messages), and to
 342  * initialize the RAM so that we can relocate the monitor code to
 343  * RAM.
 344  *
 345  * Be aware of the restrictions: global data is read-only, BSS is not
 346  * initialized, and stack space is limited to a few kB.
 347  *
 348  ************************************************************************
 349  */
 350
 351 void board_init_f (ulong bootflag)    // 参数是启动类型
 352 {
 353     DECLARE_GLOBAL_DATA_PTR;        // 声明全局数据结构体指针gd为r29
 354
 355     bd_t *bd;                // 板子信息结构体指针
 356     ulong len, addr, addr_sp;
 357     gd_t *id;                // 全局数据结构体指针
 358     init_fnc_t **init_fnc_ptr;
 359 #ifdef CONFIG_PRAM
 360     int i;
 361     ulong reg;
 362     uchar tmp[64];        /* long enough for environment variables */
 363 #endif
 364
 365     /* Pointer is writable since we allocated a register for it */
 366     gd = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);    // 此时指向dcache中的全局数据结构体
 367     /* compiler optimization barrier needed for GCC >= 3.4 */
 368     __asm__ __volatile__("": : :"memory");        // 内存屏障,保证后面的操作执行之前,前面的操作已经完成
 369
 370 #if !defined(CONFIG_CPM2)
 371     /* Clear initial global data */
 372     memset ((void *) gd, 0, sizeof (gd_t));
 373 #endif
 374     // 顺序调用init_sequence数组中的函数进行初始化,返回值不为0即进入死循环
 375     for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
 376         if ((*init_fnc_ptr) () != 0) {
 377             hang ();
 378         }
 379     }
 380
 381     /*
 382      * Now that we have DRAM mapped and working, we can
 383      * relocate the code and continue running from DRAM.
 384      *
 385      * Reserve memory at end of RAM for (top down in that order):
 386      *  - kernel log buffer
 387      *  - protected RAM
 388      *  - LCD framebuffer
 389      *  - monitor code
 390      *  - board info struct
 391      */
 392     len = (ulong)&_end - CFG_MONITOR_BASE;     // 根据u-boot.lds,此计算的是U-Boot整个镜像的大小
 393
 394 #ifndef    CONFIG_VERY_BIG_RAM
 395     addr = CFG_SDRAM_BASE + gd->ram_size;     // CFG_SDRAM_BASE是基址,gd->ram_size为RAM大小。此时指向RAM的最高端地址
 396 #else
 397     /* only allow stack below 256M */         // 否则只利用256M以下的空间
 398     addr = CFG_SDRAM_BASE +
 399            (gd->ram_size > 256 << 20) ? 256 << 20 : gd->ram_size;
 400 #endif
 401
 402 #ifdef CONFIG_LOGBUFFER                        // 如果定义为其在RAM最高端预留空间
 403     /* reserve kernel log buffer */
 404     addr -= (LOGBUFF_RESERVE);
 405     debug ("Reserving %dk for kernel logbuffer at %08lx\n", LOGBUFF_LEN, addr);
 406 #endif
 407
 408 #ifdef CONFIG_PRAM
 409     /*
 410      * reserve protected RAM
 411      */
 412     i = getenv_r ("pram", tmp, sizeof (tmp));
 413     reg = (i > 0) ? simple_strtoul (tmp, NULL, 10) : CONFIG_PRAM;
 414     addr -= (reg << 10);        /* size is in kB */
 415     debug ("Reserving %ldk for protected RAM at %08lx\n", reg, addr);    // 若在头文件中#define DEBUG 则打印
 416 #endif /* CONFIG_PRAM */
 417
 418     /* round down to next 4 kB limit */
 419     addr &= ~(4096 - 1);        // 舍入到下一个4kB的地址,低12bit地址位为0
 420     debug ("Top of RAM usable for U-Boot at: %08lx\n", addr);
 421
 422 #ifdef CONFIG_LCD
 423     /* reserve memory for LCD display (always full pages) */
 424     addr = lcd_setmem (addr);
 425     gd->fb_base = addr;
 426 #endif /* CONFIG_LCD */
 427
 428 #if defined(CONFIG_VIDEO) && defined(CONFIG_8xx)
 429     /* reserve memory for video display (always full pages) */
 430     addr = video_setmem (addr);
 431     gd->fb_base = addr;
 432 #endif /* CONFIG_VIDEO  */
 433
 434     /*
 435      * reserve memory for U-Boot code, data & bss
 436      * round down to next 4 kB limit
 437      */
 438     addr -= len;            // len为U-Boot整个镜像的长度,即为U-Boot搬运预留空间    
 439     addr &= ~(4096 - 1);    // 舍入到下一个4kB的地址,低12bit地址位为0
 440
 441     debug ("Reserving %ldk for U-Boot at: %08lx\n", len >> 10, addr);    // #define DEBUG显示U-Boot镜像大小,搬运地址
 442
 443 #ifdef CONFIG_AMIGAONEG3SE
 444     gd->relocaddr = addr;
 445 #endif
 446
 447     /*
 448      * reserve memory for malloc() arena
 449      */
 450     addr_sp = addr - TOTAL_MALLOC_LEN;        // 在RAM中为MALLOC()预留TOTAL_MALLOC_LEN大小的内存区
 451     debug ("Reserving %dk for malloc() at: %08lx\n",
 452             TOTAL_MALLOC_LEN >> 10, addr_sp);        // 显示MALLOC区大小,及地址
 453
 454     /*
 455      * (permanently) allocate a Board Info struct
 456      * and a permanent copy of the "global" data
 457      */
 458     addr_sp -= sizeof (bd_t);        // 为板子信息结构体bd_t预留内存区
 459     bd = (bd_t *) addr_sp;            // 板子信息结构体指针bd指向起始地址
 460     gd->bd = bd;                    // 在全局数据结构体中存储bd指针
 461     debug ("Reserving %d Bytes for Board Info at: %08lx\n",
 462             sizeof (bd_t), addr_sp);    // 显示bd_t大小及地址
 463     addr_sp -= sizeof (gd_t);        // 为全局数据结构体gd_t预留内存区
 464     id = (gd_t *) addr_sp;            // 全局数据结构体指针id指向起始地址
 465     debug ("Reserving %d Bytes for Global Data at: %08lx\n",
 466             sizeof (gd_t), addr_sp); // 显示gd_t大小及地址
 467
 468     /*
 469      * Finally, we set up a new (bigger) stack.
 470      *
 471      * Leave some safety gap for SP, force alignment on 16 byte boundary
 472      * Clear initial stack frame
 473      */
 474     addr_sp -= 16;                    // 预留安全空间
 475     addr_sp &= ~0xF;                // 保证16字节对齐
 476     *((ulong *) addr_sp)-- = 0;        // 栈向下增长
 477     *((ulong *) addr_sp)-- = 0;
 478     debug ("Stack Pointer at: %08lx\n", addr_sp);    // 显示栈顶指针addr_sp
 479
 480     /*
 481      * Save local variables to board info struct
 482      */
 483
 484     bd->bi_memstart  = CFG_SDRAM_BASE;    /* start of  DRAM memory    */
 485     bd->bi_memsize   = gd->ram_size;    /* size  of  DRAM memory in bytes */
 486
 487 #ifdef CONFIG_IP860
 488     bd->bi_sramstart = SRAM_BASE;    /* start of  SRAM memory    */
 489     bd->bi_sramsize  = SRAM_SIZE;    /* size  of  SRAM memory    */
 490 #elif defined CONFIG_MPC8220
 491     bd->bi_sramstart = CFG_SRAM_BASE;    /* start of  SRAM memory    */
 492     bd->bi_sramsize  = CFG_SRAM_SIZE;    /* size  of  SRAM memory    */
 493 #else
 494     bd->bi_sramstart = 0;        /* FIXME */ /* start of  SRAM memory    */
 495     bd->bi_sramsize  = 0;        /* FIXME */ /* size  of  SRAM memory    */
 496 #endif
 497
 498 #if defined(CONFIG_8xx) || defined(CONFIG_8260) || defined(CONFIG_5xx) || \
 499     defined(CONFIG_E500)
 500     bd->bi_immr_base = CFG_IMMR;    /* base  of IMMR register     */
 501 #endif
 502 #if defined(CONFIG_MPC5xxx)
 503     bd->bi_mbar_base = CFG_MBAR;    /* base of internal registers */
 504 #endif
 505 #if defined(CONFIG_MPC83XX)
 506     bd->bi_immrbar = CFG_IMMRBAR;    // 在板子信息结构体中存储IMMR存储映射寄存器基址
 507 #endif
 508 #if defined(CONFIG_MPC8220)
 509     bd->bi_mbar_base = CFG_MBAR;    /* base of internal registers */
 510     bd->bi_inpfreq   = gd->inp_clk;
 511     bd->bi_pcifreq   = gd->pci_clk;
 512     bd->bi_vcofreq   = gd->vco_clk;
 513     bd->bi_pevfreq   = gd->pev_clk;
 514     bd->bi_flbfreq   = gd->flb_clk;
 515
 516     /* store bootparam to sram (backward compatible), here? */
 517     {
 518     u32 *sram = (u32 *)CFG_SRAM_BASE;
 519     *sram++ = gd->ram_size;
 520     *sram++ = gd->bus_clk;
 521     *sram++ = gd->inp_clk;
 522     *sram++ = gd->cpu_clk;
 523     *sram++ = gd->vco_clk;
 524     *sram++ = gd->flb_clk;
 525     *sram++ = 0xb8c3ba11;  /* boot signature */
 526     }
 527 #endif
 528     bd->bi_bootflags = bootflag;    /* boot / reboot flag (for LynxOS)  */ // 启动类型
 529
 530     WATCHDOG_RESET ();
 531     bd->bi_intfreq = gd->cpu_clk;    /* Internal Freq, in Hz */
 532     bd->bi_busfreq = gd->bus_clk;    /* Bus Freq,      in Hz */
 533 #if defined(CONFIG_CPM2)
 534     bd->bi_cpmfreq = gd->cpm_clk;
 535     bd->bi_brgfreq = gd->brg_clk;
 536     bd->bi_sccfreq = gd->scc_clk;
 537     bd->bi_vco     = gd->vco_out;
 538 #endif /* CONFIG_CPM2 */
 539 #if defined(CONFIG_MPC5xxx)
 540     bd->bi_ipbfreq = gd->ipb_clk;
 541     bd->bi_pcifreq = gd->pci_clk;
 542 #endif /* CONFIG_MPC5xxx */
 543     bd->bi_baudrate = gd->baudrate;    /* Console Baudrate  波特率   */
 544
 545 #ifdef CFG_EXTBDINFO
 546     strncpy (bd->bi_s_version, "1.2", sizeof (bd->bi_s_version));
 547     strncpy (bd->bi_r_version, U_BOOT_VERSION, sizeof (bd->bi_r_version));
 548
 549     bd->bi_procfreq = gd->cpu_clk;    /* Processor Speed, In Hz */
 550     bd->bi_plb_busfreq = gd->bus_clk;
 551 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
 552     bd->bi_pci_busfreq = get_PCI_freq ();
 553     bd->bi_opbfreq = get_OPB_freq ();
 554 #elif defined(CONFIG_XILINX_ML300)
 555     bd->bi_pci_busfreq = get_PCI_freq ();
 556 #endif
 557 #endif
 558
 559     debug ("New Stack Pointer is: %08lx\n", addr_sp); // 显示用户栈顶指针addr_sp
 560
 561     WATCHDOG_RESET ();
 562
 563 #ifdef CONFIG_POST
 564     post_bootmode_init();
 565     post_run (NULL, POST_ROM | post_bootmode_get(0));
 566 #endif
 567
 568     WATCHDOG_RESET();
 569
 570     memcpy (id, (void *)gd, sizeof (gd_t));        // 将dcache中的全局数据结构体复制到RAM中
 571
 572     relocate_code (addr_sp, id, addr);            // 调用start.S中的relocate_code
 573     // addr_sp为RAM中栈顶指针, id为RAM中全局数据结构体地址,addr为RAM中U-Boot镜像搬运的地址
 574
 575     puts("*** Failed To Relocated code to sdram ***\n"); // relocate_code 不应该返回
 576
 577     hang();            // 挂起
 578
 579     /* NOTREACHED - relocate_code() does not return */
 580 }
 581
 582 #ifdef CONFIG_PCI_SLAVE    
 583 void change_to_slave(void)
 584 {
 585     volatile immap_t *immr = (immap_t *)CFG_IMMR;
 586     volatile ccsr_pcix_t *pci = &immr->im_pcix;
 587
 588     pci->cfg_addr = 0x80000044;
 589     pci->cfg_data = 0x01000080;
 590     return;
 591 }
 592 #endif
 593
 594
 595 /************************************************************************
 596  *
 597  * This is the next part if the initialization sequence: we are now
 598  * running from RAM and have a "normal" C environment, i. e. global
 599  * data can be written, BSS has been cleared, the stack size in not
 600  * that critical any more, etc.
 601  *
 602  ************************************************************************
 603  */
 604
 605 void board_init_r (gd_t *id, ulong dest_addr)    // U-Boot的stage2初始化
 606 {                                    // id指向RAM中的全局数据结构, dest_addr为RAM中U-Boot镜像起始地址
 607     DECLARE_GLOBAL_DATA_PTR;        // 声明全局数据结构体指针gd为r29            
 608     cmd_tbl_t *cmdtp;
 609     char *s, *e;
 610     bd_t *bd;
 611     int i;
 612     extern void malloc_bin_reloc (void);
 613 #ifndef CFG_ENV_IS_NOWHERE        /* Store EVV in memeory only */
 614     extern char * env_name_spec;
 615 #endif
 616
 617 #ifndef CFG_NO_FLASH        /* Flash is not usable now */
 618     ulong flash_size;
 619 #endif
 620
 621     gd = id;        /* initialize RAM version of global data */
 622     bd = gd->bd;    // RAM中的gd_t、bd_t指针
 623
 624     gd->flags |= GD_FLG_RELOC;    /* tell others: relocation done */
 625
 626     debug ("Now running in RAM - U-Boot at: %08lx\n", dest_addr);    // debug --> printf
 627
 628     WATCHDOG_RESET ();
 629
 630 #if defined(CONFIG_BOARD_EARLY_INIT_R)        // 调用board_early_init_r
 631     board_early_init_r ();
 632 #endif
 633
 634     gd->reloc_off = dest_addr - CFG_MONITOR_BASE;        // 计算U-Boot代码搬运前后的距离
 635
 636     monitor_flash_len = (ulong)&__init_end - dest_addr; // 计算U-Boot镜像长度,此不包含镜像最后的BSS段
 637
 638 #ifdef CONFIG_SERIAL_MULTI
 639     serial_initialize();
 640 #endif
 641
 642     /*
 643      * We have to relocate the command table manually
 644      */
 645     for (cmdtp = &__u_boot_cmd_start; cmdtp !=  &__u_boot_cmd_end; cmdtp++) { // cmdtp指向flash中的u-boot命令存储位置 (u-boot.lds)
 646         ulong addr;        
 647         addr = (ulong) (cmdtp->cmd) + gd->reloc_off;        // 计算cmdtp->cmd在RAM的绝对位置addr
 648 #if 0
 649         printf ("Command \"%s\": 0x%08lx => 0x%08lx\n",
 650                 cmdtp->name, (ulong) (cmdtp->cmd), addr);
 651 #endif
 652         cmdtp->cmd =
 653             (int (*)(struct cmd_tbl_s *, int, int, char *[]))addr; // flash中u-boot命令项cmdtp->cmd指向RAM中的cmdtp->cmd
 654
 655         addr = (ulong)(cmdtp->name) + gd->reloc_off;
 656         cmdtp->name = (char *)addr;                // 类似更改flash中Monitor Command Table中name项指针指向RAM
 657
 658         if (cmdtp->usage) {        
 659             addr = (ulong)(cmdtp->usage) + gd->reloc_off;
 660             cmdtp->usage = (char *)addr;        // 类似更改flash中Monitor Command Table中name项指针指向RAM
 661         }
 662 #ifdef    CFG_LONGHELP        // 更详细的帮助,占用内存空间,一般不启用
 663         if (cmdtp->help) {
 664             addr = (ulong)(cmdtp->help) + gd->reloc_off;
 665             cmdtp->help = (char *)addr;
 666         }
 667 #endif
 668     }
 669     /* there are some other pointer constants we must deal with */
 670 #ifndef CFG_ENV_IS_NOWHERE
 671     env_name_spec += gd->reloc_off;
 672 #endif
 673
 674     WATCHDOG_RESET ();
 675
 676 #ifdef CONFIG_LOGBUFFER
 677     logbuff_init_ptrs ();
 678 #endif
 679 #ifdef CONFIG_POST
 680     post_output_backlog ();
 681     post_reloc ();
 682 #endif
 683
 684     WATCHDOG_RESET();
 685
 686 #if defined(CONFIG_IP860) || defined(CONFIG_PCU_E) || defined (CONFIG_FLAGADM)
 687     icache_enable ();    /* it's time to enable the instruction cache */
 688 #endif
 689
 690 #if defined(CFG_INIT_RAM_LOCK) && defined(CONFIG_E500)
 691     unlock_ram_in_cache();    /* it's time to unlock D-cache in e500 */
 692 #endif
 693
 694 #if defined(CONFIG_BAB7xx) || defined(CONFIG_CPC45)
 695     /*
 696      * Do PCI configuration on BAB7xx and CPC45 _before_ the flash
 697      * gets initialised, because we need the ISA resp. PCI_to_LOCAL bus
 698      * bridge there.
 699      */
 700     pci_init ();
 701 #endif
 702 #if defined(CONFIG_BAB7xx)
 703     /*
 704      * Initialise the ISA bridge
 705      */
 706     initialise_w83c553f ();
 707 #endif
 708
 709     asm ("sync ; isync");            // 保证指令顺序
 710
 711     /*
 712      * Setup trap handlers
 713      */
 714     trap_init (dest_addr);            // 从dest_addr复制异常向量到RAM低端地址: 此处异常向量前缀为0x000
 715                                     // dest_addr为U-Boot镜像的RAM起始地址
 716
 717 #if !defined(CFG_NO_FLASH)
 718     puts ("FLASH: ");                // Flash信息
 719
 720     if ((flash_size = flash_init ()) > 0) {        // 定义在drivers/cfi_flash.c,进行板上NOR Flash初始化
 721 # ifdef CFG_FLASH_CHECKSUM            // 校验数据完整性
 722         print_size (flash_size, "");
 723         /*
 724          * Compute and print flash CRC if flashchecksum is set to 'y'
 725          *
 726          * NOTE: Maybe we should add some WATCHDOG_RESET()? XXX
 727          */
 728         s = getenv ("flashchecksum");    // 获取flashchecksum环境变量值
 729         if (s && (*s == 'y')) {
 730             printf ("  CRC: %08lX",
 731                 crc32 (0, (const unsigned char *) CFG_FLASH_BASE, flash_size)
 732             );
 733         }
 734         putc ('\n');
 735 # else    /* !CFG_FLASH_CHECKSUM */
 736         print_size (flash_size, "\n");        // Flash大小信息
 737 # endif /* CFG_FLASH_CHECKSUM */
 738     } else {
 739         puts (failed);
 740         hang ();
 741     }
 742
 743     bd->bi_flashstart = CFG_FLASH_BASE;    /* update start of FLASH memory    */
 744     bd->bi_flashsize = flash_size;    /* size of FLASH memory (final value) */
 745 # if defined(CONFIG_PCU_E) || defined(CONFIG_OXC) || defined(CONFIG_RMU)
 746     /* flash mapped at end of memory map */
 747     bd->bi_flashoffset = TEXT_BASE + flash_size;
 748 # elif CFG_MONITOR_BASE == CFG_FLASH_BASE
 749     bd->bi_flashoffset = monitor_flash_len;    /* reserved area for startup monitor  */
 750 # else
 751     bd->bi_flashoffset = 0;
 752 # endif
 753 #else    /* CFG_NO_FLASH */  // Flash 不可用
 754
 755     bd->bi_flashsize = 0;
 756     bd->bi_flashstart = 0;
 757     bd->bi_flashoffset = 0;
 758 #endif /* !CFG_NO_FLASH */
 759
 760     WATCHDOG_RESET ();
 761
 762     /* initialize higher level parts of CPU like time base and timers */
 763     cpu_init_r ();        // CPU的第二阶段初始化
 764
 765     WATCHDOG_RESET ();
 766
 767     /* initialize malloc() area */        // RAM中malloc区域初始化
 768     mem_malloc_init ();
 769     malloc_bin_reloc ();
 770
 771 #ifdef CONFIG_SPI
 772 # if !defined(CFG_ENV_IS_IN_EEPROM)
 773     spi_init_f ();
 774 # endif
 775     spi_init_r ();
 776 #endif
 777
 778     /* relocate environment function pointers etc. */
 779     env_relocate ();            // 定义在common/env_common.c中,重置默认的环境变量函数指针
 780
 781     /*
 782      * Fill in missing fields of bd_info.
 783      * We do this here, where we have "normal" access to the
 784      * environment; we used to do this still running from ROM,
 785      * where had to use getenv_r(), which can be pretty slow when
 786      * the environment is in EEPROM.
 787      */
 788
 789 #if defined(CFG_EXTBDINFO)
 790 #if defined(CONFIG_405GP) || defined(CONFIG_405EP)
 791 #if defined(CONFIG_I2CFAST)
 792     /*
 793      * set bi_iic_fast for linux taking environment variable
 794      * "i2cfast" into account
 795      */
 796     {
 797         char *s = getenv ("i2cfast");
 798         if (s && ((*s == 'y') || (*s == 'Y'))) {
 799             bd->bi_iic_fast[0] = 1;
 800             bd->bi_iic_fast[1] = 1;
 801         } else {
 802             bd->bi_iic_fast[0] = 0;
 803             bd->bi_iic_fast[1] = 0;
 804         }
 805     }
 806 #else
 807     bd->bi_iic_fast[0] = 0;
 808     bd->bi_iic_fast[1] = 0;
 809 #endif    /* CONFIG_I2CFAST */
 810 #endif    /* CONFIG_405GP, CONFIG_405EP */
 811 #endif    /* CFG_EXTBDINFO */
 812
 813     s = getenv ("ethaddr");            // 获取eth0 MAC地址
 814 #if defined (CONFIG_MBX) || defined (CONFIG_RPXCLASSIC) || defined(CONFIG_IAD210)
 815     if (s == NULL)
 816         board_get_enetaddr (bd->bi_enetaddr);
 817     else
 818 #endif
 819         for (i = 0; i < 6; ++i) {
 820             bd->bi_enetaddr[i] = s ? simple_strtoul (s, &e, 16) : 0; // simple_strtoul转为16进制UL
 821             if (s)
 822                 s = (*e) ? e + 1 : e;
 823         }
 824 #ifdef    CONFIG_HERMES
 825     if ((gd->board_type >> 16) == 2)
 826         bd->bi_ethspeed = gd->board_type & 0xFFFF;
 827     else
 828         bd->bi_ethspeed = 0xFFFF;
 829 #endif
 830
 831 #ifdef CONFIG_NX823
 832     load_sernum_ethaddr ();
 833 #endif
 834
 835 #ifdef CONFIG_HAS_ETH1        // 第二个网卡
 836     /* handle the 2nd ethernet address */
 837
 838     s = getenv ("eth1addr");        // 获取eth1 MAC地址
 839
 840     for (i = 0; i < 6; ++i) {
 841         bd->bi_enet1addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
 842         if (s)
 843             s = (*e) ? e + 1 : e;
 844     }
 845 #endif
 846 #ifdef CONFIG_HAS_ETH2
 847     /* handle the 3rd ethernet address */
 848
 849     s = getenv ("eth2addr");
 850 #if defined(CONFIG_XPEDITE1K)
 851     if (s == NULL)
 852         board_get_enetaddr(bd->bi_enet2addr);
 853     else
 854 #endif
 855     for (i = 0; i < 6; ++i) {
 856         bd->bi_enet2addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
 857         if (s)
 858             s = (*e) ? e + 1 : e;
 859     }
 860 #endif
 861
 862 #ifdef CONFIG_HAS_ETH3
 863     /* handle 4th ethernet address */
 864     s = getenv("eth3addr");
 865 #if defined(CONFIG_XPEDITE1K)
 866     if (s == NULL)
 867         board_get_enetaddr(bd->bi_enet3addr);
 868     else
 869 #endif
 870     for (i = 0; i < 6; ++i) {
 871         bd->bi_enet3addr[i] = s ? simple_strtoul (s, &e, 16) : 0;
 872         if (s)
 873             s = (*e) ? e + 1 : e;
 874     }
 875 #endif
 876
 877 #if defined(CONFIG_TQM8xxL) || defined(CONFIG_TQM8260) || \
 878     defined(CONFIG_CCM) || defined(CONFIG_KUP4K) || defined(CONFIG_KUP4X)
 879     load_sernum_ethaddr ();
 880 #endif
 881     /* IP Address */
 882     bd->bi_ip_addr = getenv_IPaddr ("ipaddr");
 883
 884     WATCHDOG_RESET ();
 885
 886 #if defined(CONFIG_PCI) && !defined(CONFIG_BAB7xx) && !defined(CONFIG_CPC45)
 887     /*
 888      * Do pci configuration
 889      */
 890     pci_init ();
 891 #endif
 892
 893 /** leave this here (after malloc(), environment and PCI are working) **/
 894     /* Initialize devices */
 895     devices_init ();        // 定义在common/devices.c中,设备初始化,如I2C等
 896
 897     /* Initialize the jump table for applications */
 898     jumptable_init ();        // 定义在common/exports.c中,常用函数跳转表初始化,如malloc,udelay等
 899
 900     /* Initialize the console (after the relocation and devices init) */
 901     console_init_r ();        // 控制台初始化第二阶段
 902
 903 #if defined(CONFIG_CCM)        || \
 904     defined(CONFIG_COGENT)    || \
 905     defined(CONFIG_CPCI405)    || \
 906     defined(CONFIG_EVB64260)    || \
 907     defined(CONFIG_KUP4K)    || \
 908     defined(CONFIG_KUP4X)    || \
 909     defined(CONFIG_LWMON)    || \
 910     defined(CONFIG_PCU_E)    || \
 911     defined(CONFIG_W7O)        || \
 912     defined(CONFIG_MISC_INIT_R)
 913     /* miscellaneous platform dependent initialisations */
 914     misc_init_r ();            // 外围初始化
 915 #endif
 916
 917 #ifdef    CONFIG_HERMES
 918     if (bd->bi_ethspeed != 0xFFFF)
 919         hermes_start_lxt980 ((int) bd->bi_ethspeed);
 920 #endif
 921
 922 #if (CONFIG_COMMANDS & CFG_CMD_NET) && ( \        // 若定义了CONFIG_COMMANDS及CFG_CMD_NET (!!)
 923     defined(CONFIG_CCM)        || \
 924     defined(CONFIG_ELPT860)    || \
 925     defined(CONFIG_EP8260)    || \
 926     defined(CONFIG_IP860)    || \
 927     defined(CONFIG_IVML24)    || \
 928     defined(CONFIG_IVMS8)    || \
 929     defined(CONFIG_MPC8260ADS)    || \
 930     defined(CONFIG_MPC8266ADS)    || \
 931     defined(CONFIG_MPC8560ADS)    || \
 932     defined(CONFIG_PCU_E)    || \
 933     defined(CONFIG_RPXSUPER)    || \
 934     defined(CONFIG_STXGP3)    || \
 935     defined(CONFIG_SPD823TS)    || \
 936     defined(CONFIG_MPC8349ITX)    || \
 937     defined(CONFIG_RESET_PHY_R)    )
 938
 939     WATCHDOG_RESET ();
 940     debug ("Reset Ethernet PHY\n");
 941     reset_phy ();
 942 #endif
 943
 944 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
 945     WATCHDOG_RESET ();
 946     puts ("KGDB:  ");
 947     kgdb_init ();
 948 #endif
 949
 950     debug ("U-Boot relocated to %08lx\n", dest_addr);
 951
 952     /*
 953      * Enable Interrupts
 954      */
 955     interrupt_init ();    // 定义在lib_ppc/interrupts.c, 中断使能
 956
 957     /* Must happen after interrupts are initialized since
 958      * an irq handler gets installed
 959      */
 960 #ifdef CONFIG_SERIAL_SOFTWARE_FIFO
 961     serial_buffered_init();
 962 #endif
 963
 964 #ifdef CONFIG_STATUS_LED
 965     status_led_set (STATUS_LED_BOOT, STATUS_LED_BLINKING);
 966 #endif
 967
 968     udelay (20);
 969
 970     set_timer (0);
 971
 972     /* Initialize from environment */
 973     if ((s = getenv ("loadaddr")) != NULL) {        // 获取环境变量值loadaddr
 974         load_addr = simple_strtoul (s, NULL, 16);
 975     }
 976 #if (CONFIG_COMMANDS & CFG_CMD_NET)
 977     if ((s = getenv ("bootfile")) != NULL) {
 978         copy_filename (BootFile, s, sizeof (BootFile));    // 将启动文件名复制给BootFile字符串
 979     }
 980 #endif /* CFG_CMD_NET */
 981
 982     WATCHDOG_RESET ();
 983
 984 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)        // SCSI命令初始化
 985     WATCHDOG_RESET ();
 986     puts ("SCSI:  ");
 987     scsi_init ();
 988 #endif
 989
 990 #if (CONFIG_COMMANDS & CFG_CMD_DOC)            // Disk-On-Chip Support
 991     WATCHDOG_RESET ();
 992     puts ("DOC:   ");
 993     doc_init ();
 994 #endif
 995
 996 #if (CONFIG_COMMANDS & CFG_CMD_NAND)        // NAND Flash 初始化
 997     WATCHDOG_RESET ();
 998     puts ("NAND:  ");
 999     nand_init();        /* go init the NAND */
1000 #endif
1001
1002 #if (CONFIG_COMMANDS & CFG_CMD_NET) && defined(CONFIG_NET_MULTI)    // 若定义CONFIG_NET_MULTI及CFG_CMD_NET (!!!)
1003     WATCHDOG_RESET ();
1004     puts ("Net:   ");
1005     eth_initialize (bd);        // 定义在net/eth.c中,参数是板子信息结构体指针,初始化板上网卡,网络支持
1006 #endif
1007
1008 #ifdef CONFIG_POST
1009     post_run (NULL, POST_RAM | post_bootmode_get(0));
1010 #endif
1011
1012 #if defined CONFIG_MPC8349ITX        // MPC8349ITX版本信息
1013     char bd_ver;
1014     if ((i2c_read(0x21, 0, 0, &bd_ver, sizeof(bd_ver)) == 0) ||
1015         (i2c_read(0x39, 0, 0, &bd_ver, sizeof(bd_ver)) == 0))
1016
1017     printf ("Board Revision:\trev %d.%d\n", (bd_ver & 0x02)>>1, (bd_ver & 0x01));
1018
1019     if ((bd_ver & 0x03) < 2)
1020     {
1021         cf_reg_offset = 0x0001;
1022         cf_alt_offset = 0x0201;
1023     }
1024     else
1025     {
1026         cf_reg_offset = 0x0000;
1027         cf_alt_offset = 0x0200;
1028     }
1029
1030 #endif
1031
1032
1033 #if (CONFIG_COMMANDS & CFG_CMD_PCMCIA) && !(CONFIG_COMMANDS & CFG_CMD_IDE)
1034     WATCHDOG_RESET ();
1035     puts ("PCMCIA:");
1036     pcmcia_init ();
1037 #endif
1038
1039 #if (CONFIG_COMMANDS & CFG_CMD_IDE)        // IDE 硬盘初始化
1040     WATCHDOG_RESET ();
1041 # ifdef    CONFIG_IDE_8xx_PCCARD
1042     puts ("PCMCIA:");
1043 # else
1044     puts ("IDE:   ");
1045 #endif
1046     char data;
1047
1048     if ((i2c_read(0x21, 0, 0, &data, sizeof(data)) == 0) ||
1049         (i2c_read(0x39, 0, 0, &data, sizeof(data)) == 0))
1050
1051     if((data & 0x08)>>0x3)
1052         puts("Disable\n");
1053     else
1054         ide_init ();
1055
1056 #endif /* CFG_CMD_IDE */
1057
1058 #ifdef CONFIG_LAST_STAGE_INIT
1059     WATCHDOG_RESET ();
1060     /*
1061      * Some parts can be only initialized if all others (like
1062      * Interrupts) are up and running (i.e. the PC-style ISA
1063      * keyboard).
1064      */
1065     last_stage_init ();
1066 #endif
1067
1068 #if (CONFIG_COMMANDS & CFG_CMD_BEDBUG)
1069     WATCHDOG_RESET ();
1070     bedbug_init ();
1071 #endif
1072
1073 #if defined(CONFIG_PRAM) || defined(CONFIG_LOGBUFFER)
1074     /*
1075      * Export available size of memory for Linux,
1076      * taking into account the protected RAM at top of memory
1077      */
1078     {
1079         ulong pram;
1080         uchar memsz[32];
1081 #ifdef CONFIG_PRAM
1082         char *s;
1083
1084         if ((s = getenv ("pram")) != NULL) {
1085             pram = simple_strtoul (s, NULL, 10);
1086         } else {
1087             pram = CONFIG_PRAM;
1088         }
1089 #else
1090         pram=0;
1091 #endif
1092 #ifdef CONFIG_LOGBUFFER
1093         /* Also take the logbuffer into account (pram is in kB) */
1094         pram += (LOGBUFF_LEN+LOGBUFF_OVERHEAD)/1024;
1095 #endif
1096         sprintf (memsz, "%ldk", (bd->bi_memsize / 1024) - pram);
1097         setenv ("mem", memsz);
1098     }
1099 #endif
1100
1101 #ifdef CONFIG_PS2KBD
1102     puts ("PS/2:  ");
1103     kbd_init();
1104 #endif
1105
1106 #ifdef CONFIG_MODEM_SUPPORT
1107  {
1108      extern int do_mdm_init;
1109      do_mdm_init = gd->do_mdm_init;
1110  }
1111 #endif
1112
1113 #ifdef CFG_I2C_RTC_ADDR            // I2C RTC ds1339实时时钟
1114     char ds1339_data[17];
1115     if (i2c_read(CFG_I2C_RTC_ADDR, 0, 1, ds1339_data, sizeof(ds1339_data)) == 0)
1116     {
1117     /* Check that status register bits 6-2 are zero */
1118         if (ds1339_data[0x0f] & 0x7c)
1119             ds1339_data[0x0f] &= ~0x7c;
1120
1121         /* Check for a valid day register value */
1122         if (ds1339_data[0x03] & 0xf8)
1123             ds1339_data[0x03] &= ~0xf8;
1124         if (ds1339_data[0x03] == 0)
1125             ds1339_data[0x03] = 1;
1126
1127         /* Check for a valid date register value */
1128         if (ds1339_data[0x04] & 0xc0)
1129             ds1339_data[0x04] &= ~0xc0;
1130         if ((ds1339_data[0x04] == 0) || ((ds1339_data[0x04] & 0x0f) > 9) || (ds1339_data[0x04] >= 0x32))
1131             ds1339_data[0x04]=1;
1132
1133         /* Check for a valid month register value */
1134         if (ds1339_data[0x05] & 0x60)
1135             ds1339_data[0x05] &= ~0xc0;
1136         if ((ds1339_data[0x05] == 0) ||
1137             ((ds1339_data[0x05] & 0x0f) > 9) || ((ds1339_data[0x05] >= 0x13) && (ds1339_data[0x05] <= 0x19)))
1138             ds1339_data[0x05]=1;
1139
1140         /* Enable Oscillator and rate select */
1141         ds1339_data[0x0e]=0x1c;
1142
1143         i2c_write (CFG_I2C_RTC_ADDR, 0, 1, &ds1339_data, sizeof(ds1339_data));
1144     }
1145     else
1146     {
1147         /* Enable Oscillator and rate select */
1148         ds1339_data[0x0e]=0x1c;
1149         i2c_write (CFG_I2C_RTC_ADDR, 0xe, 1, &ds1339_data[0x0e], 1);
1150     }
1151 #endif
1152
1153
1154 #if defined (CONFIG_MPC8349ITX) && defined (CONFIG_MPC8349ITX_FCC_TEST)
1155     char exp_data, chip;
1156
1157     if (i2c_read(0x20, 0, 0, &exp_data, sizeof(exp_data)) == 0)
1158         chip = 0x20;
1159     else if (i2c_read(0x38, 0, 0, &exp_data, sizeof(exp_data)) == 0)
1160         chip = 0x38;
1161     else printf ("Probing PCF8574%c (U8) failed.\n", (chip==0x20)? "":"A");
1162
1163     printf ("LED0 and LED1 are flashing.\n Hit any key to exit ... \n");
1164     while (!tstc())
1165     {
1166         i2c_read(chip, 0, 0, &exp_data, sizeof(exp_data));
1167
1168         (exp_data & 0x01)? (exp_data &= ~0x01):(exp_data |= 0x01);
1169         i2c_write (chip, 0, 0, &exp_data, 1);
1170
1171         (exp_data & 0x02)? (exp_data &= ~0x02):(exp_data |= 0x02);
1172         i2c_write (chip, 0, 0, &exp_data, 1);
1173
1174         udelay(100000);
1175     }
1176
1177     /* consume input */
1178     (void) getc();
1179
1180     /* printf ("LED0 is %s.\n",
1181         (exp_data & 0x01)? "OFF" : "ON");
1182
1183     printf ("LED1 is %s.\n",
1184         (exp_data & 0x02)? "OFF" : "ON"); */
1185
1186 #endif
1187     /* Initialization complete - start the monitor */
1188
1189     /* main_loop() can return to retry autoboot, if so just run it again. */
1190     for (;;) {
1191         WATCHDOG_RESET ();
1192
1193 #ifdef CONFIG_PCI_SLAVE
1194         change_to_slave();
1195 #endif
1196         main_loop ();            // 进入U-Boot命令行状态
1197     }
1198
1199     /* NOTREACHED - no way out of command loop except booting */
1200 }
1201
1202 void hang (void)
1203 {
1204     puts ("### ERROR ### Please RESET the board ###\n");
1205 #ifdef CONFIG_SHOW_BOOT_PROGRESS
1206     show_boot_progress(-30);
1207 #endif
1208     for (;;);
1209 }
1210
1211 #ifdef CONFIG_MODEM_SUPPORT
1212 /* called from main loop (common/main.c) */
1213 extern void  dbg(const char *fmt, ...);
1214 int mdm_init (void)
1215 {
1216     char env_str[16];
1217     char *init_str;
1218     int i;
1219     extern char console_buffer[];
1220     static inline void mdm_readline(char *buf, int bufsiz);
1221     extern void enable_putc(void);
1222     extern int hwflow_onoff(int);
1223
1224     enable_putc(); /* enable serial_putc() */
1225
1226 #ifdef CONFIG_HWFLOW
1227     init_str = getenv("mdm_flow_control");
1228     if (init_str && (strcmp(init_str, "rts/cts") == 0))
1229         hwflow_onoff (1);
1230     else
1231         hwflow_onoff(-1);
1232 #endif
1233
1234     for (i = 1;;i++) {
1235         sprintf(env_str, "mdm_init%d", i);
1236         if ((init_str = getenv(env_str)) != NULL) {
1237             serial_puts(init_str);
1238             serial_puts("\n");
1239             for(;;) {
1240                 mdm_readline(console_buffer, CFG_CBSIZE);
1241                 dbg("ini%d: [%s]", i, console_buffer);
1242
1243                 if ((strcmp(console_buffer, "OK") == 0) ||
1244                     (strcmp(console_buffer, "ERROR") == 0)) {
1245                     dbg("ini%d: cmd done", i);
1246                     break;
1247                 } else /* in case we are originating call ... */
1248                     if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1249                         dbg("ini%d: connect", i);
1250                         return 0;
1251                     }
1252             }
1253         } else
1254             break; /* no init string - stop modem init */
1255
1256         udelay(100000);
1257     }
1258
1259     udelay(100000);
1260
1261     /* final stage - wait for connect */
1262     for(;i > 1;) { /* if 'i' > 1 - wait for connection
1263                   message from modem */
1264         mdm_readline(console_buffer, CFG_CBSIZE);
1265         dbg("ini_f: [%s]", console_buffer);
1266         if (strncmp(console_buffer, "CONNECT", 7) == 0) {
1267             dbg("ini_f: connected");
1268             return 0;
1269         }
1270     }
1271
1272     return 0;
1273 }
1274
1275 /* 'inline' - We have to do it fast */
1276 static inline void mdm_readline(char *buf, int bufsiz)
1277 {
1278     char c;
1279     char *p;
1280     int n;
1281
1282     n = 0;
1283     p = buf;
1284     for(;;) {
1285         c = serial_getc();
1286
1287         /*        dbg("(%c)", c); */
1288
1289         switch(c) {
1290         case '\r':
1291             break;
1292         case '\n':
1293             *p = '\0';
1294             return;
1295
1296         default:
1297             if(n++ > bufsiz) {
1298                 *p = '\0';
1299                 return; /* sanity check */
1300             }
1301             *p = c;
1302             p++;
1303             break;
1304         }
1305     }
1306 }
1307 #endif
1308
1309 #if 0 /* We could use plain global data, but the resulting code is bigger */
1310 /*
1311  * Pointer to initial global data area
1312  *
1313  * Here we initialize it.
1314  */
1315 #undef    XTRN_DECLARE_GLOBAL_DATA_PTR
1316 #define XTRN_DECLARE_GLOBAL_DATA_PTR    /* empty = allocate here */
1317 DECLARE_GLOBAL_DATA_PTR = (gd_t *) (CFG_INIT_RAM_ADDR + CFG_GBL_DATA_OFFSET);
1318 #endif  /* 0 */
1319
1320 /************************************************************************/

阅读(1427) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~