TQ210 —— s5pv210 board.c分析(uboot第二阶段)

/*
 * (C) Copyright 2002-2006
 * 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.
 *
 * 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

/*
 * To match the U-Boot user interface on ARM platforms to the U-Boot
 * standard (as on PPC platforms), some messages with debug character
 * are removed from the default U-Boot build.
 *
 * Define DEBUG here if you want additional info as shown below
 * printed upon startup:
 *
 * U-Boot code: 00F00000 -> 00F3C774  BSS: -> 00FC3274
 * IRQ Stack: 00ebff7c
 * FIQ Stack: 00ebef7c
 */
/*
 * /lib_arm/board.c 主要完成了一些初始化的操作,最重要的是有start_armboot函数
 */
 
#include <common.h>
#include <command.h>
#include <malloc.h>
#include <devices.h>
#include <version.h>
#include <net.h>
#include <asm/io.h>
#include <movi.h>
#include <regs.h>
#include <serial.h>
#include <nand.h>
#include <onenand_uboot.h>

#ifdef CONFIG_GENERIC_MMC
#include <mmc.h>
#endif


#undef DEBUG

#ifdef CONFIG_DRIVER_SMC91111
#include "../drivers/net/smc91111.h"
#endif
#ifdef CONFIG_DRIVER_LAN91C96  /* 关于网卡的定义 */
#include "../drivers/net/lan91c96.h"
#endif

DECLARE_GLOBAL_DATA_PTR;  /* 声明全局数据指针 */

void nand_init (void);  
void onenand_init(void);

ulong monitor_flash_len;

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

#ifndef CONFIG_IDENT_STRING /* 没有定义CONFIG_IDENT_STRING,定义其为空 */
#define CONFIG_IDENT_STRING ""
#endif

const char version_string[] = /* 版本字符串 */
	U_BOOT_VERSION  CONFIG_IDENT_STRING;

#ifdef CONFIG_DRIVER_CS8900 /* 定义了CS8900网卡,获取网络地址 */
extern int cs8900_get_enetaddr (uchar * addr);
#endif

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

#if defined(CONFIG_HARD_I2C) || \
    defined(CONFIG_SOFT_I2C)
#include <i2c.h>
#endif

/*
 * Begin and End of memory area for malloc(), and current "brk"
 * 分配内存
 */
static ulong mem_malloc_start = 0;
static ulong mem_malloc_end = 0;
static ulong mem_malloc_brk = 0;

/* 内存分配初始化 */
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 ((void *) mem_malloc_start, 0,
			mem_malloc_end - mem_malloc_start);
}

/* 所分配内存区的brk指针调整 */
void *sbrk (ptrdiff_t increment)
{
	ulong old = mem_malloc_brk;
	ulong new = old + increment;

	if ((new < mem_malloc_start) || (new > mem_malloc_end)) {
		return (NULL);
	}
	mem_malloc_brk = new;

	return ((void *) old);
}

char *strmhz(char *buf, long hz)
{
	long l, n;
	long m;

	n = hz / 1000000L;
	l = sprintf (buf, "%ld", n);
	m = (hz % 1000000L) / 1000L;
	if (m != 0)
		sprintf (buf + l, ".%03ld", m);
	return (buf);
}


/************************************************************************
 * Coloured LED functionality
 ************************************************************************
 * May be supplied by boards if desired
 */
void __coloured_LED_init (void) {}
void coloured_LED_init (void)
	__attribute__((weak, alias("__coloured_LED_init")));
void  __red_LED_on (void) {}
void  red_LED_on (void)
	__attribute__((weak, alias("__red_LED_on")));
void  __red_LED_off(void) {}
void  red_LED_off(void)	     __attribute__((weak, alias("__red_LED_off")));
void  __green_LED_on(void) {}
void  green_LED_on(void) __attribute__((weak, alias("__green_LED_on")));
void  __green_LED_off(void) {}
void  green_LED_off(void)__attribute__((weak, alias("__green_LED_off")));
void  __yellow_LED_on(void) {}
void  yellow_LED_on(void)__attribute__((weak, alias("__yellow_LED_on")));
void  __yellow_LED_off(void) {}
void  yellow_LED_off(void)__attribute__((weak, alias("__yellow_LED_off")));

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

#if 0
typedef struct global_data {
bd_t        *bd; // 与板子相关的结构,见下面
unsigned long flags; // 指示标志,如设备已经初始化标志等
unsigned long baudrate; // 波特率
unsigned long have_console; /* serial_init() was called */
unsigned long reloc_off; /* Relocation Offset,重定位偏移,一般为0 */
unsigned long env_addr; /* Address   of Environment struct ,存放环境变量结构的地址*/
unsigned long env_valid; /* 环境参数CRC检验有效标志 */
#ifdef CONFIG_VFD   // 我们一般没有配置这个,这个是frame buffer的首地址
unsigned long fb_base; /* base address of frame buffer,显存缓存区 基址*/
#endif

void   **jt;   /* jump table ,保存着些函数的入口地址,在common/Exports.c中进行填充*/
} gd_t;

typedef struct bd_info {
int          bi_baudrate; /* serial console baudrate ,串口波特率 */
unsigned long bi_ip_addr; /* IP Address ,IP地址*/
unsigned char bi_enetaddr[6]; /* Ethernet adress ,以太网MAC地址*/
struct environment_s           *bi_env; /* 环境变量地址指针 */
ulong          bi_arch_number; /* unique id for this board   架构号码*/
ulong          bi_boot_params; /* where this board expects params启动参数 */
struct             /* RAM configuration */
{ 
  ulong start; /* RAM的起始地址 */
  ulong size; /* RAM的大小 */
} bi_dram[CONFIG_NR_DRAM_BANKS];
} bd_t;


#endif
/* 初始化波特率 */
static int init_baudrate (void)
{
	char tmp[64];	/* long enough for environment variables */
	int i = getenv_r ("baudrate", tmp, sizeof (tmp));
	gd->bd->bi_baudrate = gd->baudrate = (i > 0)
			? (int) simple_strtoul (tmp, NULL, 10)
			: CONFIG_BAUDRATE;

	return (0);
}

/* 打开屏幕背光 */
static void open_backlight(void)
{
	unsigned int reg;

	//open backlight. GPF3_5=1
	reg = readl(GPF3CON);
	reg = reg & ~(0xf<<20) | (0x1<<20);
	writel(reg,GPF3CON);

	reg = readl(GPF3PUD);
	reg = reg & ~(0x3<<10) | (0x2<<10);
	writel(reg,GPF3PUD);

	reg = readl(GPF3DAT);
	reg |= (0x1<<5);
	writel(reg,GPF3DAT);
}

/*
 * GPC1_1: GPRS_PWR_EN
 * GPJ0_4: CDMAPWR
 * GPJ0_1: GSM_RST
 * GPJ0_6: GSM_ON_OFF
 */
 /* 打开GPRS */
static void open_gprs(void)
{
	unsigned int i;
	unsigned int reg;

	//step0: init gpio
	reg = readl(GPC1CON);
	reg = reg & ~(0xf<<4) | (0x1<<4);	//set GPC1_1 to output and enable pullup
	writel(reg,GPC1CON);
	reg = readl(GPC1PUD);
	reg = reg & ~(0x3<<2) | (0x2<<2);
	writel(reg,GPC1PUD);

	reg = readl(GPJ0CON);
	reg	= reg & ~(0xf<<4) | (0x1<<4);	//set GPJ0_1 to output and enable pullup
	writel(reg,GPJ0CON);
	reg = readl(GPJ0PUD);
	reg = reg & ~(0x3<<2) | (0x2<<2);
	writel(reg,GPJ0PUD);

	reg = readl(GPJ0CON);
	reg	= reg & ~(0xf<<16) | (0x1<<16);	//set GPJ0_4 to output and enable pullup
	writel(reg,GPJ0CON);
	reg = readl(GPJ0PUD);
	reg = reg & ~(0x3<<8) | (0x2<<8);
	writel(reg,GPJ0PUD);

	reg = readl(GPJ0CON);
	reg	= reg & ~(0xf<<24) | (0x1<<24);	//set GPJ0_6 to low level and enable pullup
	writel(reg,GPJ0CON);
	reg = readl(GPJ0PUD);
	reg = reg & ~(0x3<<12) | (0x2<<12);
	writel(reg,GPJ0PUD);

	reg = readl(GPJ0DAT);
	reg &= ~(0x1<<6);
	writel(reg,GPJ0DAT);

	//step1: disable reset
	reg = readl(GPJ0DAT);
	reg &= ~(0x1<<1);
	writel(reg,GPJ0DAT);

	//step2: enable GPRS power(4.2V to GPRS module)
	reg = readl(GPC1DAT);
	reg |= (0x1<<1);
	writel(reg,GPC1DAT);

	//step3: enable CDMAPWR(4.2V to GC864)
	reg = readl(GPJ0DAT);
	reg |= (0x1<<4);
	writel(reg,GPJ0DAT);

	for(i=0;i<100;i++)
		udelay(1000);

	//step4: power on GC864
	reg = readl(GPJ0DAT);
	reg |= (0x1<<6);
	writel(reg,GPJ0DAT);
	for(i=0;i<1000/*2000*/;i++)
		udelay(1000);
	reg &= ~(0x1<<6);
	writel(reg,GPJ0DAT);
}

/* 一些显示函数。显示IRQ_STACK_START等的地址_armboot_start, _bss_start, _bss_end 这些值 */
static int display_banner (void)
{
	printf("**********************************************************\n");
	printf ("*************   %s   *************\n", version_string);
	printf("******************   blog.youkuaiyun.com/wqx521*****************\n");
	printf("**********************************************************\n");

	debug ("U-Boot code: %08lX -> %08lX  BSS: -> %08lX\n",
	       _armboot_start, _bss_start, _bss_end);
#ifdef CONFIG_MEMORY_UPPER_CODE /* by scsuh */
	debug("\t\bMalloc and Stack is above the U-Boot Code.\n");
#else
	debug("\t\bMalloc and Stack is below the U-Boot Code.\n");
#endif
#ifdef CONFIG_MODEM_SUPPORT
	debug ("Modem Support enabled\n");
#endif
#ifdef CONFIG_USE_IRQ
	debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);
	debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);
#endif
	//open_backlight();//lqm.
	//open_gprs();

	return (0);
}

/*
 * WARNING: this code looks "cleaner" than the PowerPC version, but
 * has the disadvantage that you either get nothing, or everything.
 * On PowerPC, you might see "DRAM: " before the system hangs - which
 * gives a simple yet clear indication which part of the
 * initialization if failing.
 */
 /* 显示内存的配置,打印DRAM的大小 */
static int display_dram_config (void)
{
	int i;

#ifdef DEBUG
	puts ("RAM Configuration:\n");

	for(i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
		printf ("Bank #%d: %08lx ", i, gd->bd->bi_dram[i].start);
		print_size (gd->bd->bi_dram[i].size, "\n");
	}
#else
	ulong size = 0;

	for (i=0; i<CONFIG_NR_DRAM_BANKS; i++) {
		size += gd->bd->bi_dram[i].size;
	}

	puts("DRAM:    ");
	print_size(size, "\n");
#endif

	return (0);
}

#ifndef CFG_NO_FLASH
/* 打印flash大小 */
static void display_flash_config (ulong size)
{
	puts ("Flash:  ");
	print_size (size, "\n");
}
#endif /* CFG_NO_FLASH */

#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
/* 初始化I2C */
static int init_func_i2c (void)
{
	puts ("I2C:   ");
	i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
	puts ("ready\n");
	return (0);
}
#endif

#ifdef CONFIG_SKIP_RELOCATE_UBOOT
/*
 * This routine sets the relocation done flag, because even if
 * relocation is skipped, the flag is used by other generic code.
 */
static int reloc_init(void)
{
	gd->flags |= GD_FLG_RELOC;
	return 0;
}
#endif

/*
 * 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);

int print_cpuinfo (void); /* test-only */

init_fnc_t *init_sequence[] = { /* 定义一个初始化的整型指针数组 */
	cpu_init,		/* basic cpu dependent setup */
#if defined(CONFIG_SKIP_RELOCATE_UBOOT)
	reloc_init,		/* Set the relocation done flag, must
				   do this AFTER cpu_init(), but as soon
				   as possible */
#endif
	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 */
#if defined(CONFIG_DISPLAY_CPUINFO)
	print_cpuinfo,		/* display cpu info (and speed) */
#endif
#if defined(CONFIG_DISPLAY_BOARDINFO)
	checkboard,		/* display board info */
#endif
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
	init_func_i2c,
#endif
	dram_init,		/* configure available RAM banks */
	display_dram_config,
	NULL,
};

/*
 * 功能: 完成uboot第二阶级的一系列的
 * 硬件初始化工作, 然后转入main函数
 * 该函数是C程序的入口函数,从汇编语言跳转到此
 */
void start_armboot (void)
{
	init_fnc_t **init_fnc_ptr; /* 二级指针 */
	char *s;
	int mmc_exist = 0;
#if !defined(CFG_NO_FLASH) || defined (CONFIG_VFD) || defined(CONFIG_LCD)
	ulong size;
#endif

#if defined(CONFIG_VFD) || defined(CONFIG_LCD)
	unsigned long addr;
#endif

#if defined(CONFIG_BOOT_MOVINAND)
	uint *magic = (uint *) (PHYS_SDRAM_1);
#endif

	/* Pointer is writable since we allocated a register for it */
#ifdef CONFIG_MEMORY_UPPER_CODE /* by scsuh */
	ulong gd_base;
    /* 0xc3e00000 + 3*1024*1024 - (0x4000 + 896*1024)- 512*1024 - sizeof(gd_t) */
	gd_base = CFG_UBOOT_BASE + CFG_UBOOT_SIZE - CFG_MALLOC_LEN - CFG_STACK_SIZE - sizeof(gd_t);
#ifdef CONFIG_USE_IRQ
	gd_base -= (CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ);
#endif
	gd = (gd_t*)gd_base;
#else
	/*
     * _armboot_start  为malloc函数预留的数据空间
	 * (gd_t)gd(全局变量表)基址  全信息表gd的数据区
	 * (bt_t)bd(板卡信息表)基址  板卡信息表bd的数据区
     */
	 /* 分配gd_t给 gd ,gd是一个全局静态变量  */
	gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));
#endif

	/* compiler optimization barrier needed for GCC >= 3.4 */
	__asm__ __volatile__("": : :"memory");
    
	/* 初始化gd表 */
	memset ((void*)gd, 0, sizeof (gd_t));
	/*
	 * bd_t 结构体在/include/asm-arm/U-boot.h中定义, 定义板子的一些信息,包括:
     * 波特率,IP地址, 以太网地址, 架构编码,启动参数 ,BANK的起始地址和大小等 
	*/
	/* bd的基址 = gd的基址 - bd的尺寸   初始化bd表 */
	gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));
	memset (gd->bd, 0, sizeof (bd_t));

	/* monitor_flash_len表示从flash中搬来的代码的长度,_bss_start 在u-boot.lds中定位 */
	monitor_flash_len = _bss_start - _armboot_start;

	/* 
	 *各设置的初始化.当返回值不为0时表示初始化失败 ,此时会调用 hang()函数
     *打印一错误提示信息,然后进入死循环 
	 */
	for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {
		if ((*init_fnc_ptr)() != 0) {
			hang ();
		}
	}

#ifndef CFG_NO_FLASH
	/* configure available FLASH banks */
	size = flash_init (); /* 板上flash初始化 */
	display_flash_config (size); /* 打印flash的大小 */
#endif /* CFG_NO_FLASH */

#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 // 未定义
	/* board init may have inited fb_base */
	if (!gd->fb_base) {
#		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 */
#ifdef CONFIG_MEMORY_UPPER_CODE /* by scsuh */
	/* malloc函数使用缓冲区的初始化 */
	mem_malloc_init (CFG_UBOOT_BASE + CFG_UBOOT_SIZE - CFG_MALLOC_LEN - CFG_STACK_SIZE);
#else
	mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);
#endif

//******************************//
// Board Specific
// #if defined(CONFIG_SMDKXXXX)
//******************************//
/* 使用的是TQ210,找到与TQ210相关的,别的不会执行 */
#if defined(CONFIG_SMDK6410)
	#if defined(CONFIG_GENERIC_MMC)
	puts ("SD/MMC:  ");
	mmc_exist = mmc_initialize(gd->bd);
	if (mmc_exist != 0)
	{
		puts ("0 MB\n");
	}
	#else
	#if defined(CONFIG_MMC)
	puts("SD/MMC:  ");

	if (INF_REG3_REG == 0)
		movi_ch = 0;
	else
		movi_ch = 1;

	movi_set_capacity();
	movi_init();
	movi_set_ofs(MOVI_TOTAL_BLKCNT);
	#endif
	#endif

	if (INF_REG3_REG == BOOT_ONENAND) {
	#if defined(CONFIG_CMD_ONENAND)
		puts("OneNAND: ");
		onenand_init();
	#endif
		/*setenv("bootcmd", "onenand read c0008000 80000 380000;bootm c0008000");*/
	} else {
		puts("NAND:    ");
		nand_init();

		if (INF_REG3_REG == 0 || INF_REG3_REG == 7)
			setenv("bootcmd", "movi read kernel c0008000;movi read rootfs c0800000;bootm c0008000");
		else
//			setenv("bootcmd", "nand read c0008000 80000 380000;bootm c0008000");
			setenv("bootcmd","nand read 0x30008000 0x600000 0x500000 ;bootm 0x30008000");	
	}
#endif	/* CONFIG_SMDK6410 */

#if defined(CONFIG_SMDKC100)

	#if defined(CONFIG_GENERIC_MMC)
		puts ("SD/MMC:  ");
		mmc_exist = mmc_initialize(gd->bd);
		if (mmc_exist != 0)
		{
			puts ("0 MB\n");
		}
	#endif

	#if defined(CONFIG_CMD_ONENAND)
		puts("OneNAND: ");
		onenand_init();
	#endif

	#if defined(CONFIG_CMD_NAND)
		puts("NAND:    ");
		nand_init();
	#endif

#endif /* CONFIG_SMDKC100 */

#if defined(CONFIG_GEC210) || defined(CONFIG_TQ210)

	#if defined(CONFIG_GENERIC_MMC) // 定义了
	    // 输出SD/MMC,看mmc是否存在
		puts ("SD/MMC: ");
		///* //lqm masked
		mmc_exist = mmc_initialize(gd->bd);
		if (mmc_exist != 0)
		{
			puts ("0 MB\n");
		}
		//*/
	#endif

	#if defined(CONFIG_MTD_ONENAND) // 未定义
		puts("OneNAND: ");
		onenand_init();
		/*setenv("bootcmd", "onenand read c0008000 80000 380000;bootm c0008000");*/
	#else
		//puts("OneNAND: (FSR layer enabled)\n");
	#endif

	#if defined(CONFIG_CMD_NAND) // 如果定义了命令和NAND命令,则初始化nand(执行)
		puts("NAND:    ");
		nand_init(); // 
	#endif

#endif /* CONFIG_GEC210 */

#if defined(CONFIG_SMDK6440)
	#if defined(CONFIG_GENERIC_MMC)
	puts ("SD/MMC:  ");
	mmc_exist = mmc_initialize(gd->bd);
	if (mmc_exist != 0)
	{
		puts ("0 MB\n");
	}
	#else
	#if defined(CONFIG_MMC)
	if (INF_REG3_REG == 1) {	/* eMMC_4.3 */
		puts("eMMC:    ");
		movi_ch = 1;
		movi_emmc = 1;

		movi_init();
		movi_set_ofs(0);
	} else if (INF_REG3_REG == 7 || INF_REG3_REG == 0) {	/* SD/MMC */
		if (INF_REG3_REG & 0x1)
			movi_ch = 1;
		else
			movi_ch = 0;

		puts("SD/MMC:  ");

		movi_set_capacity();
		movi_init();
		movi_set_ofs(MOVI_TOTAL_BLKCNT);

	} else {

	}
	#endif
	#endif

	if (INF_REG3_REG == 2) {
			/* N/A */
	} else {
		puts("NAND:    ");
		nand_init();
		//setenv("bootcmd", "nand read c0008000 80000 380000;bootm c0008000");
	}
#endif /* CONFIG_SMDK6440 */

#if defined(CONFIG_SMDK6430)
	#if defined(CONFIG_GENERIC_MMC)
	puts ("SD/MMC:  ");
	mmc_exist = mmc_initialize(gd->bd);
	if (mmc_exist != 0)
	{
		puts ("0 MB\n");
	}
	#else
	#if defined(CONFIG_MMC)
	puts("SD/MMC:  ");

	if (INF_REG3_REG == 0)
		movi_ch = 0;
	else
		movi_ch = 1;

	movi_set_capacity();
	movi_init();
	movi_set_ofs(MOVI_TOTAL_BLKCNT);
	#endif
	#endif

	if (INF_REG3_REG == BOOT_ONENAND) {
	#if defined(CONFIG_CMD_ONENAND)
		puts("OneNAND: ");
		onenand_init();
	#endif
		/*setenv("bootcmd", "onenand read c0008000 80000 380000;bootm c0008000");*/
	} else if (INF_REG3_REG == BOOT_NAND) {
		puts("NAND:    ");
		nand_init();
	} else {
	}

	if (INF_REG3_REG == 0 || INF_REG3_REG == 7)
		setenv("bootcmd", "movi read kernel c0008000;movi read rootfs c0800000;bootm c0008000");
	else
		setenv("bootcmd", "nand read c0008000 80000 380000;bootm c0008000");
#endif	/* CONFIG_SMDK6430 */

#if defined(CONFIG_SMDK6442)
	#if defined(CONFIG_GENERIC_MMC)
	puts ("SD/MMC:  ");
	mmc_exist = mmc_initialize(gd->bd);
	if (mmc_exist != 0)
	{
		puts ("0 MB\n");
	}
	#else
	#if defined(CONFIG_MMC)
	puts("SD/MMC:  ");

	movi_set_capacity();
	movi_init();
	movi_set_ofs(MOVI_TOTAL_BLKCNT);

	#endif
	#endif

	#if defined(CONFIG_CMD_ONENAND)
	if (INF_REG3_REG == BOOT_ONENAND) {
		puts("OneNAND: ");
		onenand_init();
		}
	#endif

#endif	/* CONFIG_SMDK6442 */

#if defined(CONFIG_SMDK2416) || defined(CONFIG_SMDK2450)
	#if defined(CONFIG_NAND)
	puts("NAND:    ");
	nand_init();
	#endif

	#if defined(CONFIG_ONENAND)
	puts("OneNAND: ");
	onenand_init();
	#endif

	#if defined(CONFIG_BOOT_MOVINAND)
	puts("SD/MMC:  ");

	if ((0x24564236 == magic[0]) && (0x20764316 == magic[1])) {
		printf("Boot up for burning\n");
	} else {
			movi_init();
			movi_set_ofs(MOVI_TOTAL_BLKCNT);
	}
	#endif
#endif	/* CONFIG_SMDK2416 CONFIG_SMDK2450 */

#ifdef CONFIG_HAS_DATAFLASH // 未定义
	AT91F_DataflashInit();
	dataflash_print_info();
#endif

	/* initialize environment */
	/*  环境的初始化,代码在common/env_common.c中 */
	env_relocate ();

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

#ifdef CONFIG_SERIAL_MULTI
	serial_initialize(); /* 串口初始化 */
#endif

	/* IP Address */
	/* 为全局变量的成员赋值:IP地址 */
	gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

	/* MAC Address */ 
	/* 高处MAC地址 ,并赋给gd的成员变量 */
	{
		int i;
		ulong reg;
		char *s, *e;
		char tmp[64];
		i = getenv_r ("ethaddr", tmp, sizeof (tmp));
		s = (i > 0) ? tmp : NULL;

		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;
		} /* 获取网卡地址 */

#ifdef CONFIG_HAS_ETH1 /* 未定义 */
		i = getenv_r ("eth1addr", tmp, sizeof (tmp));
		s = (i > 0) ? tmp : NULL;

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

	/* /调用相应驱动函数对硬件设备进行初始化 */
	devices_init ();	/* get the devices list going. */

#ifdef CONFIG_CMC_PU2 /* 未定义 */
	load_sernum_ethaddr ();
#endif /* CONFIG_CMC_PU2 */

	jumptable_init ();
#if !defined(CONFIG_SMDK6442)
	console_init_r ();	/* fully init console as a device */
#endif

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

	/* enable exceptions */
	/* 设置cpsr的I和F位以允许中断 */
	enable_interrupts ();

	/* Perform network card initialisation if necessary */
#ifdef CONFIG_DRIVER_TI_EMAC /* 未定义 */
extern void dm644x_eth_set_mac_addr (const u_int8_t *addr);
	if (getenv ("ethaddr")) {
		dm644x_eth_set_mac_addr(gd->bd->bi_enetaddr);
	}
#endif

#ifdef CONFIG_DRIVER_CS8900
    /* 获取网卡的mac地址 */
	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 */
	if ((s = getenv ("loadaddr")) != NULL) {
		load_addr = simple_strtoul (s, NULL, 16);
	}
#if defined(CONFIG_CMD_NET)
	if ((s = getenv ("bootfile")) != NULL) {
		copy_filename (BootFile, s, sizeof (BootFile));
	}
#endif

#ifdef BOARD_LATE_INIT
	board_late_init ();
#endif
#if defined(CONFIG_CMD_NET)
#if defined(CONFIG_NET_MULTI)
	puts ("Net:   ");
#endif
	eth_initialize(gd->bd); /* 网卡初始化 */
#if defined(CONFIG_RESET_PHY_R)
	debug ("Reset Ethernet PHY\n");
	reset_phy();
#endif
#endif

#if defined(CONFIG_CMD_IDE)
	/* 输出IDE:  IDE初始化 */
	puts("IDE:   ");
	ide_init();
#endif


#ifdef CONFIG_MPAD    
	extern int tq210_preboot_init(void);
	tq210_preboot_init(); 
#endif


	/* main_loop() can return to retry autoboot, if so just run it again. */
	for (;;) {
		/* 至此,硬件初始化完成 */
		main_loop (); /* 直接进入main_loop 该函数在common/main.c中 */
	}

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

/* 输出错误信息 */
void hang (void)
{
	puts ("### ERROR ### Please RESET the board ###\n");
	for (;;);
}

#ifdef CONFIG_MODEM_SUPPORT /* 未定义 */
static inline void mdm_readline(char *buf, int bufsiz);

/* 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[];
	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);
		if ((init_str = getenv(env_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 */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值