boardc.docx
《boardc.docx》由会员分享,可在线阅读,更多相关《boardc.docx(16页珍藏版)》请在冰豆网上搜索。
![boardc.docx](https://file1.bdocx.com/fileroot1/2023-4/16/8b252c57-167a-4b65-b26f-163108732fb2/8b252c57-167a-4b65-b26f-163108732fb21.gif)
boardc
/*
*(C)Copyright2002
*WolfgangDenk,DENXSoftwareEngineering,wd@denx.de.
*
*(C)Copyright2002
*SysgoReal-TimeSolutions,GmbH<>
*MariusGroeger
*
*SeefileCREDITSforlistofpeoplewhocontributedtothis
*project.
*
*Thisprogramisfreesoftware;youcanredistributeitand/or
*modifyitunderthetermsoftheGNUGeneralPublicLicenseas
*publishedbytheFreeSoftwareFoundation;eitherversion2of
*theLicense,or(atyouroption)anylaterversion.
*
*Thisprogramisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe
*GNUGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense
*alongwiththisprogram;ifnot,writetotheFreeSoftware
*Foundation,Inc.,59TemplePlace,Suite330,Boston,
*MA02111-1307USA
*/
#include
#include
#include
#include
#include
#include
#ifdefCONFIG_DRIVER_SMC91111//添加驱动支持
#include"../drivers/smc91111.h"
#endif
#ifdefCONFIG_DRIVER_LAN91C96
#include"../drivers/lan91c96.h"
#endif
#if(CONFIG_COMMANDS&CFG_CMD_NAND)//命令选项&NAND设置
voidnand_init(void);
#endif
ulongmonitor_flash_len;
#ifdefCONFIG_HAS_DATAFLASH
externintAT91F_DataflashInit(void);
externvoiddataflash_print_info(void);
#endif
#ifndefCONFIG_IDENT_STRING
#defineCONFIG_IDENT_STRING""
#endif
constcharversion_string[]=
U_BOOT_VERSION"("__DATE__"-"__TIME__")"CONFIG_IDENT_STRING;
#ifdefCONFIG_DRIVER_CS8900//添加驱动
externvoidcs8900_get_enetaddr(uchar*addr);
#endif
#ifdefCONFIG_DRIVER_RTL8019
externvoidrtl8019_get_enetaddr(uchar*addr);
#endif
/*
*BeginandEndofmemoryareaformalloc(),andcurrent"brk"
*/
staticulongmem_malloc_start=0;//MEM显示内存状态
staticulongmem_malloc_end=0;//存储器分配malloc...
staticulongmem_malloc_brk=0;
static
voidmem_malloc_init(ulongdest_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);
}
void*sbrk(ptrdiff_tincrement)/*本函数用于扩展堆空间,用incriment来指定扩展的大小*/
{
ulongold=mem_malloc_brk;
ulongnew=old+increment;
if((newmem_malloc_end)){
return(NULL);
}
mem_malloc_brk=new;
return((void*)old);
}
/************************************************************************
*InitUtilities*
************************************************************************
*Someofthiscodeshouldbemovedintothecorefunctions,
*ordroppedcompletely,
*butlet'sgetitworking(again)first...
*/
/*获取环境变量,把波特率值赋给全局gd,若获取为空值,则赋给默认115200*/
staticintinit_baudrate(void)
{
DECLARE_GLOBAL_DATA_PTR;
uchartmp[64];/*longenoughforenvironmentvariables*/
/*把环境变量获取到tmp中,i为得到的环境变量的长度*/
inti=getenv_r("baudrate",tmp,sizeof(tmp));
/*如果获得了env,则把它赋给gd,否则把115200赋给gd*/
gd->bd->bi_baudrate=gd->baudrate=(i>0)
/*此函数把字符串转换为ulong型*/
?
(int)simple_strtoul(tmp,NULL,10)
:
CONFIG_BAUDRATE;
return(0);
}
staticintdisplay_banner(void)
{
printf("\n\n%s\n\n",version_string);
printf("U-Bootcode:
%08lX->%08lXBSS:
->%08lX\n",
_armboot_start,_bss_start,_bss_end);
#ifdefCONFIG_MODEM_SUPPORT
puts("ModemSupportenabled\n");
#endif
#ifdefCONFIG_USE_IRQ
printf("IRQStack:
%08lx\n",IRQ_STACK_START);
printf("FIQStack:
%08lx\n",FIQ_STACK_START);
#endif
return(0);
}
/*
*WARNING:
thiscodelooks"cleaner"thanthePowerPCversion,but
*hasthedisadvantagethatyoueithergetnothing,oreverything.
*OnPowerPC,youmightsee"DRAM:
"beforethesystemhangs-which
*givesasimpleyetclearindicationwhichpartofthe
*initializationiffailing.
*/
staticintdisplay_dram_config(void)
{
DECLARE_GLOBAL_DATA_PTR;
inti;
puts("RAMConfiguration:
\n");
for(i=0;iprintf("Bank#%d:
%08lx",i,gd->bd->bi_dram[i].start);
print_size(gd->bd->bi_dram[i].size,"\n");
}
return(0);
}
staticvoiddisplay_flash_config(ulongsize)
{
puts("Flash:
");
print_size(size,"\n");
}
/*
*Breathesomelifeintotheboard...
*
*Initializeaserialportasconsole,andcarryoutsomehardware
*tests.
*
*ThefirstpartofinitializationisrunningfromFlashmemory;
*itsmainpurposeistoinitializetheRAMsothatwe
*canrelocatethemonitorcodetoRAM.
*/
/*
*Allattemptstocomeupwitha"common"initializationsequence
*thatworksforallboardsandarchitecturesfailed:
someofthe
*requirementsarejust_too_different.Togetridoftheresulting
*messofboarddependent#ifdef'edcodewenowmakethewhole
*initializationsequenceconfigurabletotheuser.
*
*Therequirementsforanynewinitalizationfunctionissimple:
it
*receivesapointertothe"globaldata"structureasit'sonly
*argument,andreturnsanintegerreturncode,where0means
*"continue"and!
=0means"fatalerror,hangthesystem".
*/
typedefint(init_fnc_t)(void);
init_fnc_t*init_sequence[]={
cpu_init,/*basiccpudependentsetup基本处理器相关配置*/
board_init,/*basicboarddependentsetup基本的开发板相关配置*/
interrupt_init,/*setupexceptions初始化例外处理*/
env_init,/*initializeenvironment初始化环境变量*/
init_baudrate,/*initialzebaudratesettings初始化波特率设置*/
serial_init,/*serialcommunicationssetup串口通讯设置*/
console_init_f,/*stage1initofconsole控制台初始化阶段1*/
display_banner,/*saythatwearehere打印u-boot信息*/
dram_init,/*configureavailableRAMbanks配置可用的RAM*/
display_dram_config,//显示RAM的配置大小
#ifdefined(CONFIG_VCMA9)
checkboard,
#endif
NULL,
};
/*start_armboot是U-Boot执行的第一个C语言函数,完成系统初始化工作,进入主循环,处理用户输入的命令。
*/
voidstart_armboot(void)
{
DECLARE_GLOBAL_DATA_PTR;
ulongsize;
init_fnc_t**init_fnc_ptr;
char*s;
#ifdefined(CONFIG_VFD)||defined(CONFIG_LCD)
unsignedlongaddr;
#endif
/*Pointeriswritablesinceweallocatedaregisterforit*/
/*****************全局数据结构的初始化*******************/
/*gd_t结构的初始化:
*/
gd=(gd_t*)(_armboot_start-CFG_MALLOC_LEN-sizeof(gd_t));
/*compileroptimizationbarrierneededforGCC>=3.4*/
__asm____volatile__("":
:
:
"memory");
memset((void*)gd,0,sizeof(gd_t));//用0填充全局数据表gd
gd->bd=(bd_t*)((char*)gd-sizeof(bd_t));//bd_t结构的初始化:
memset(gd->bd,0,sizeof(bd_t));//用0填充(初始化)*gd->bd
monitor_flash_len=_bss_start-_armboot_start;//取u-boot的长度
/****************调用通用初始化函数***********/
/*顺序执行init_sequence数组中的初始化函数*/
for(init_fnc_ptr=init_sequence;*init_fnc_ptr;++init_fnc_ptr){
if((*init_fnc_ptr)()!
=0){
hang();//打印错误信息并死锁
}
}
/*init_sequence[]是init_fnc_t函数指针数组,这个数组包含了众多初始化函数,比如cpu_init,board_init等。
*/
/*configureavailableFLASHbanks*/ /*配置可用的Flash*/
size=flash_init();//初始化flash
display_flash_config(size);//显示flash大小
#ifdefCONFIG_VFD
#ifndefPAGE_SIZE
#definePAGE_SIZE4096
#endif
/*
*reservememoryforVFDdisplay(alwaysfullpages)为VFD显示预留内存(整个页面)
*/
/*bss_endisdefinedintheboard-specificlinkerscript*//*_armboot_start在u-boot.lds链接脚本中定义*/
addr=(_bss_end+(PAGE_SIZE-1))&~(PAGE_SIZE-1);
size=vfd_setmem(addr);
gd->fb_base=addr;
#endif/*CONFIG_VFD*///进入下一个界面
#ifdefCONFIG_LCD
#ifndefPAGE_SIZE
#definePAGE_SIZE4096
#endif
/*
*reservememoryforLCDdisplay(alwaysfullpages)
*/
/*bss_endisdefinedintheboard-specificlinkerscript*/
addr=(_bss_end+(PAGE_SIZE-1))&~(PAGE_SIZE-1);
size=lcd_setmem(addr);
gd->fb_base=addr;
#endif/*CONFIG_LCD*/
/*内存分配的初始化(全局数据结构的初始化)*/
/*armboot_startisdefinedintheboard-specificlinkerscript*/
mem_malloc_init(_armboot_start-CFG_MALLOC_LEN);/*将CFG_MALLOC_LEN区域用memset清0(直接往目的地址写0)*/
/****************初始化具体设备*************/
#if(CONFIG_COMMANDS&CFG_CMD_NAND)
puts("NAND:
");
nand_init();/*goinittheNANDnand初始化*/
#endif
#ifdefCONFIG_HAS_DATAFLASH
AT91F_DataflashInit();
dataflash_print_info();
#endif
/*initializeenvironment初始化环境*/
env_relocate();//函数作用将环境变量从flash到RAM的拷贝
#ifdefCONFIG_VFD
/*mustdothisaftertheframebufferisallocated配置环境变量,重新定位*/
drv_vfd_init();
#endif/*CONFIG_VFD*/
/*IPAddress*/ /*从环境变量中获取IP地址*/
gd->bd->bi_ip_addr=getenv_IPaddr("ipaddr");
/*MACAddress*//*以太网接口MAC地址*/
{
inti;
ulongreg;
char*s,*e;
uchartmp[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;
}
}
devices_init();/*getthedeviceslistgoing.*//*获取列表中的设备(外围设备初始化)*/
jumptable_init();//跳转表初始化
console_init_r();/*fullyinitconsoleasadevice*//*完整地初始化控制台设备*/
#ifdefined(CONFIG_MISC_INIT_R)
/*miscellaneousplatformdependentinitialisations其他平台由初始化决定*/
misc_init_r();
#endif
/*enableexceptions*//*启用异常处理*/
enable_interrupts();
/*Performnetworkcardinitialisationifnecessary*/
#ifdefCONFIG_DRIVER_CS8900
cs8900_get_enetaddr(gd->bd->bi_enetaddr);
#endif
#ifdefined(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*/
/*Initializefromenvironment*//*通过环境变量初始化*/
if((s=getenv("loadaddr"))!
=NULL){
load_addr=simple_strtoul(s,NULL,16);
}
#if(CONFIG_COMMANDS&CFG_CMD_NET)
if((s=getenv("bootfile"))!
=NULL){
copy_filename(BootFile,s,