arm linux board,uboot之board.c源码分析

/lib_arm/board.c主要完成了一些初始化的操作,最重要的是有start_armboot函数

_armboot_start地址为多少??

/*

*

* U-Boot code: 00F00000 -> 00F3C774BSS: -> 00FC3274

* IRQ Stack: 00ebff7c

* FIQ Stack: 00ebef7c

*/

#include

#include

#include

#include

#include

#include

#ifdefCONFIG_DRIVER_SMC91111

#include"../drivers/smc91111.h"

#endif

#ifdefCONFIG_DRIVER_LAN91C96应该是关于网卡的定义

#include"../drivers/lan91c96.h"

#endif

DECLARE_GLOBAL_DATA_PTR //声明全局数据指针

#if(CONFIG_COMMANDS & CFG_CMD_NAND)

voidnand_init (void);声明这个方法

#endif

ulong monitor_flash_len;

#ifdefCONFIG_HAS_DATAFLASH

externintAT91F_DataflashInit(void);

externvoid dataflash_print_info(void);

#endif

#ifndefCONFIG_IDENT_STRING如果没有定义,CONFIG_IDENT_STRING就定义为空

#defineCONFIG_IDENT_STRING ""

#endif

constchar version_string[] =版本字符串

U_BOOT_VERSION" (" __DATE__ " - " __TIME__ ")"CONFIG_IDENT_STRING;

#ifdefCONFIG_DRIVER_CS8900如果是CS8900网卡,则声明下面的函数。好像是获取网址的意思

externvoid cs8900_get_enetaddr (uchar * addr);

#endif

#ifdefCONFIG_DRIVER_RTL8019

externvoid rtl8019_get_enetaddr (uchar * addr);

#endif

/*

* Begin and End of memory area for malloc(), and current "brk" malloc用于用户程序进行分配内存

*/

staticulong mem_malloc_start = 0;

staticulong mem_malloc_end = 0;

staticulong mem_malloc_brk = 0;

static

voidmem_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);

真正实现内存分配的函数。分配了一个CFG_MALLOC_LEN大小的内存空间

}

void*sbrk (ptrdiff_t increment)所分配内存区的brk指针调整。

{

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

}

/************************************************************************

* Init Utilities*

************************************************************************

* Some of this code should be moved into the core functions,

* or dropped completely,

* but let's get it working (again) first...

*/

下面就是一系列的初始化操作。

staticint 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);

}

staticint display_banner (void)一些显示函数。显示IRQ_STACK_START等的地址

_armboot_start, _bss_start, _bss_end这些值

{

printf ("\n\n%s\n\n", version_string);

debug ("U-Boot code: %08lX -> %08lXBSS: -> %08lX\n",

_armboot_start, _bss_start, _bss_end);

#ifdefCONFIG_MODEM_SUPPORT

debug ("Modem Support enabled\n");

#endif

#ifdefCONFIG_USE_IRQ

debug ("IRQ Stack: %08lx\n", IRQ_STACK_START);

debug ("FIQ Stack: %08lx\n", FIQ_STACK_START);

#endif

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.

*/

staticint display_dram_config (void)显示内存的配置,打印出DRAM的大小

{

int i;

#ifdefDEBUG

puts ("RAM Configuration:\n");

for(i=0; 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

size += gd->bd->bi_dram[i].size;

}

puts("DRAM:");

print_size(size, "\n");

#endif

return (0);

}

#ifndefCFG_NO_FLASH

staticvoid display_flash_config (ulong size)

{

puts ("Flash: ");

print_size (size, "\n");

}

#endif/* CFG_NO_FLASH */

/*初始化一个串行口作为控制台,同时进行一些硬件测试

* 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.

*/

不存在一个common即通用的初始化序列来为所有的开发板及结构进行初始化。因为不同的体系结构差别还是比较大的。

/*

* 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".

*/通过接受一个指向全局数据的指针作为唯一的参数。

typedefint (init_fnc_t) (void);

intprint_cpuinfo (void); /* test-only */

init_fnc_t *init_sequence[] = {定义一个初始化的整型指针数组

cpu_init,/* basic cpu dependent setup *//cpu/arm920t/cpu.c

这个函数在cpu.c函数中定义了

board_init,/* basic board dependent setup *//board/smdk2410/smdk2410.c

interrupt_init,/* set up exceptions */

env_init,/* initialize environment */tools/env/FW_env.c

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

#ifdefined(CONFIG_DISPLAY_CPUINFO)显示cpu的信息

print_cpuinfo,/* display cpu info (and speed) */

#endif

#ifdefined(CONFIG_DISPLAY_BOARDINFO)显示板的信息

checkboard,/* display board info */

#endif

dram_init,/* configure available RAM banks */

display_dram_config,

NULL,

};

voidstart_armboot (void)

{

init_fnc_t **init_fnc_ptr;定义一个双重整型指针。

char *s;

#ifndefCFG_NO_FLASH

ulong size;

#endif

#ifdefined(CONFIG_VFD) || defined(CONFIG_LCD)

unsigned long addr;

#endif

/* Pointer is writable since we allocated a register for it */

gd = (gd_t*)(_armboot_start - CFG_MALLOC_LEN - sizeof(gd_t));

_armboot_start为0x33f80000,CFG_MALLOC_LEN是堆大小加环境数据区大小,在smdk2410.h中有定义

#define CFG_MALLOC_LEN(CFG_ENV_SIZE + 128*1024)CFG_ENV_SIZE为64K,所以共192K

/* compiler optimization barrier needed for GCC >= 3.4 */

__asm__ __volatile__("": : :"memory");

memset ((void*)gd, 0, sizeof (gd_t));获得一个gd指针,给全局数据变量gd分配内存

gd->bd = (bd_t*)((char*)gd - sizeof(bd_t));

memset (gd->bd, 0, sizeof (bd_t));给板子数据变量分配内存空间

monitor_flash_len = _bss_start - _armboot_start;取整个代码区Uboot的长度

顺序执行init_sequence数组中的初始化函数

for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {

if ((*init_fnc_ptr)() != 0) {

hang ();

}

}

#ifndefCFG_NO_FLASH

/* configure available FLASH banks */从其实现上来看,好像只是配置nor flash

size = flash_init ();

display_flash_config (size);显示flash的信息

#endif/* CFG_NO_FLASH */

#ifdefCONFIG_VFD定义显示类型

#ifndefPAGE_SIZE

#definePAGE_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 */

#ifdefCONFIG_LCD

#ifndefPAGE_SIZE

#definePAGE_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 */

初始化CFG_MALLOC_LEN大小空间

mem_malloc_init (_armboot_start - CFG_MALLOC_LEN);

#if(CONFIG_COMMANDS & CFG_CMD_NAND)

初始化nandflash,这是在nandflash启动的s3c2410移植Uboot的关键,根据flash时序编写函数即可。首先要在include/configs/smdk2410.h中打开CFG_CMD_NAND命令

puts ("NAND:");

nand_init();/* go init the NAND */,这个函数在前面被声明过,现在就可以直接使用了/board/smdk2410/smdk2410.c中没有定义这个函数,需要添加

#endif

#ifdefCONFIG_HAS_DATAFLASH

AT91F_DataflashInit();

dataflash_print_info();

#endif

/* initialize environment */

env_relocate ();初始化环境参数

#ifdefCONFIG_VFD

/* must do this after the framebuffer is allocated */

drv_vfd_init();framebuffer初始化

#endif/* CONFIG_VFD */

/* IP Address */

gd->bd->bi_ip_addr = getenv_IPaddr ("ipaddr");

/* MAC Address */

{

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;

}获取网卡地址

#ifdefCONFIG_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. */调用相应驱动函数对硬件设备进行初始化

#ifdefCONFIG_CMC_PU2

load_sernum_ethaddr ();

#endif/* CONFIG_CMC_PU2 */

jumptable_init ();

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

#ifdefined(CONFIG_MISC_INIT_R)

/* miscellaneous platform dependent initialisations */

misc_init_r ();

#endif

/* enable exceptions */

enable_interrupts ();开中断

/* Perform network card initialisation if necessary */

#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 */

/* Initialize from environment */

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, sizeof (BootFile));

}

#endif/* CFG_CMD_NET */

#ifdefBOARD_LATE_INIT

board_late_init ();

#endif

#if(CONFIG_COMMANDS & CFG_CMD_NET)

#ifdefined(CONFIG_NET_MULTI)

puts ("Net:");

#endif

eth_initialize(gd->bd);

#endif

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

for (;;) {

main_loop ();

}

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

}

voidhang (void)

{

puts ("### ERROR ### Please RESET the board ###\n");

for (;;);

}

.......

后面是modem的配置 不用管

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值